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.ASM5 );
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      public AnnotationVisitor visitAnnotation( String desc, boolean visible )
64      {
65          String annotationClassName = Type.getType( desc ).getClassName();
66          if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) )
67          {
68              return null;
69          }
70          mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName );
71          return mojoAnnotationVisitor;
72      }
73  
74      public void visitAttribute( Attribute attribute )
75      {
76          // no op
77      }
78  
79      public void visitEnd()
80      {
81          // no op
82      }
83  
84      public String getClassName()
85      {
86          return className;
87      }
88  
89      public void setClassName( String className )
90      {
91          this.className = className;
92      }
93  }