001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors; 020 021import java.util.HashMap; 022import java.util.List; 023import java.util.Map; 024 025import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner; 026import org.objectweb.asm.AnnotationVisitor; 027import org.objectweb.asm.MethodVisitor; 028import org.objectweb.asm.Opcodes; 029import org.objectweb.asm.Type; 030 031/** 032 * Method visitor. 033 * 034 * @author Slawomir Jaranowski 035 */ 036public class MojoMethodVisitor extends MethodVisitor implements MojoParameterVisitor { 037 private final String className; 038 private final String fieldName; 039 private final List<String> typeParameters; 040 private Map<String, MojoAnnotationVisitor> annotationVisitorMap = new HashMap<>(); 041 042 public MojoMethodVisitor(String fieldName, String className, List<String> typeParameters) { 043 super(Opcodes.ASM9); 044 this.fieldName = fieldName; 045 this.className = className; 046 this.typeParameters = typeParameters; 047 } 048 049 @Override 050 public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 051 String annotationClassName = Type.getType(desc).getClassName(); 052 if (!MojoAnnotationsScanner.METHOD_LEVEL_ANNOTATIONS.contains(annotationClassName)) { 053 return null; 054 } 055 056 MojoAnnotationVisitor mojoAnnotationVisitor = new MojoAnnotationVisitor(annotationClassName); 057 annotationVisitorMap.put(annotationClassName, mojoAnnotationVisitor); 058 return mojoAnnotationVisitor; 059 } 060 061 @Override 062 public String getFieldName() { 063 return fieldName; 064 } 065 066 @Override 067 public String getClassName() { 068 return className; 069 } 070 071 @Override 072 public List<String> getTypeParameters() { 073 return typeParameters; 074 } 075 076 @Override 077 public Map<String, MojoAnnotationVisitor> getAnnotationVisitorMap() { 078 return annotationVisitorMap; 079 } 080 081 @Override 082 public boolean isAnnotationOnMethod() { 083 return true; 084 } 085}