View Javadoc

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