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