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