View Javadoc
1   package org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.HashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
27  import org.objectweb.asm.AnnotationVisitor;
28  import org.objectweb.asm.FieldVisitor;
29  import org.objectweb.asm.Opcodes;
30  import org.objectweb.asm.Type;
31  
32  /**
33   * Visitors for fields.
34   *
35   * @author Olivier Lamy
36   * @since 3.0
37   */
38  public class MojoFieldVisitor
39      extends FieldVisitor implements MojoParameterVisitor
40  {
41      private String fieldName;
42  
43      private Map<String, MojoAnnotationVisitor> annotationVisitorMap = new HashMap<>();
44  
45      private String className;
46  
47      private final List<String> typeParameters;
48  
49      MojoFieldVisitor( String fieldName, String className, List<String> typeParameters )
50      {
51          super( Opcodes.ASM9 );
52          this.fieldName = fieldName;
53          this.className = className;
54          this.typeParameters = typeParameters;
55      }
56  
57      @Override
58      public Map<String, MojoAnnotationVisitor> getAnnotationVisitorMap()
59      {
60          return annotationVisitorMap;
61      }
62  
63      @Override
64      public String getFieldName()
65      {
66          return fieldName;
67      }
68  
69      @Override
70      public List<String> getTypeParameters()
71      {
72          return typeParameters;
73      }
74  
75      @Override
76      public AnnotationVisitor visitAnnotation( String desc, boolean visible )
77      {
78          String annotationClassName = Type.getType( desc ).getClassName();
79          if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) )
80          {
81              return null;
82          }
83          MojoAnnotationVisitor mojoAnnotationVisitor = new MojoAnnotationVisitor( annotationClassName );
84          annotationVisitorMap.put( annotationClassName, mojoAnnotationVisitor );
85          return mojoAnnotationVisitor;
86      }
87  
88      @Override
89      public String getClassName()
90      {
91          return className;
92      }
93  
94      @Override
95      public boolean isAnnotationOnMethod()
96      {
97          return false;
98      }
99  }