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 org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
23  import org.codehaus.plexus.logging.Logger;
24  import org.objectweb.asm.AnnotationVisitor;
25  import org.objectweb.asm.Attribute;
26  import org.objectweb.asm.FieldVisitor;
27  import org.objectweb.asm.Opcodes;
28  import org.objectweb.asm.Type;
29  
30  /**
31   * @author Olivier Lamy
32   * @since 3.0
33   */
34  public class MojoFieldVisitor
35      extends FieldVisitor
36  {
37      private Logger logger;
38  
39      private String fieldName;
40  
41      private MojoAnnotationVisitor mojoAnnotationVisitor;
42  
43      private String className;
44  
45      MojoFieldVisitor( Logger logger, String fieldName, String className )
46      {
47          super( Opcodes.ASM9 );
48          this.logger = logger;
49          this.fieldName = fieldName;
50          this.className = className;
51      }
52  
53      public MojoAnnotationVisitor getMojoAnnotationVisitor()
54      {
55          return mojoAnnotationVisitor;
56      }
57  
58      public String getFieldName()
59      {
60          return fieldName;
61      }
62  
63      @Override
64      public AnnotationVisitor visitAnnotation( String desc, boolean visible )
65      {
66          String annotationClassName = Type.getType( desc ).getClassName();
67          if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) )
68          {
69              return null;
70          }
71          mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName );
72          return mojoAnnotationVisitor;
73      }
74  
75      @Override
76      public void visitAttribute( Attribute attribute )
77      {
78          // no op
79      }
80  
81      @Override
82      public void visitEnd()
83      {
84          // no op
85      }
86  
87      public String getClassName()
88      {
89          return className;
90      }
91  
92      public void setClassName( String className )
93      {
94          this.className = className;
95      }
96  }