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.FieldVisitor; 029import org.objectweb.asm.Opcodes; 030import org.objectweb.asm.Type; 031 032/** 033 * Visitors for fields. 034 * 035 * @author Olivier Lamy 036 * @since 3.0 037 */ 038public class MojoFieldVisitor 039 extends FieldVisitor implements MojoParameterVisitor 040{ 041 private String fieldName; 042 043 private Map<String, MojoAnnotationVisitor> annotationVisitorMap = new HashMap<>(); 044 045 private String className; 046 047 private final List<String> typeParameters; 048 049 MojoFieldVisitor( String fieldName, String className, List<String> typeParameters ) 050 { 051 super( Opcodes.ASM9 ); 052 this.fieldName = fieldName; 053 this.className = className; 054 this.typeParameters = typeParameters; 055 } 056 057 @Override 058 public Map<String, MojoAnnotationVisitor> getAnnotationVisitorMap() 059 { 060 return annotationVisitorMap; 061 } 062 063 @Override 064 public String getFieldName() 065 { 066 return fieldName; 067 } 068 069 @Override 070 public List<String> getTypeParameters() 071 { 072 return typeParameters; 073 } 074 075 @Override 076 public AnnotationVisitor visitAnnotation( String desc, boolean visible ) 077 { 078 String annotationClassName = Type.getType( desc ).getClassName(); 079 if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) ) 080 { 081 return null; 082 } 083 MojoAnnotationVisitor mojoAnnotationVisitor = new MojoAnnotationVisitor( annotationClassName ); 084 annotationVisitorMap.put( annotationClassName, mojoAnnotationVisitor ); 085 return mojoAnnotationVisitor; 086 } 087 088 @Override 089 public String getClassName() 090 { 091 return className; 092 } 093 094 @Override 095 public boolean isAnnotationOnMethod() 096 { 097 return false; 098 } 099}