001    package org.apache.maven.tools.plugin.annotations.scanner.visitors;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner;
023    import org.codehaus.plexus.logging.Logger;
024    import org.objectweb.asm.AnnotationVisitor;
025    import org.objectweb.asm.Attribute;
026    import org.objectweb.asm.FieldVisitor;
027    import org.objectweb.asm.Type;
028    
029    /**
030     * @author Olivier Lamy
031     * @since 3.0
032     */
033    public class MojoFieldVisitor
034        implements FieldVisitor
035    {
036        private Logger logger;
037    
038        private String fieldName;
039    
040        private MojoAnnotationVisitor mojoAnnotationVisitor;
041    
042        private String className;
043    
044        MojoFieldVisitor( Logger logger, String fieldName, String className )
045        {
046            this.logger = logger;
047            this.fieldName = fieldName;
048            this.className = className;
049        }
050    
051        public MojoAnnotationVisitor getMojoAnnotationVisitor()
052        {
053            return mojoAnnotationVisitor;
054        }
055    
056        public String getFieldName()
057        {
058            return fieldName;
059        }
060    
061        public AnnotationVisitor visitAnnotation( String desc, boolean visible )
062        {
063            logger.debug( "MojoFieldVisitor#visitAnnotation:" + desc );
064            String annotationClassName = Type.getType( desc ).getClassName();
065            if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) )
066            {
067                return null;
068            }
069            mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName );
070            return mojoAnnotationVisitor;
071        }
072    
073        public void visitAttribute( Attribute attribute )
074        {
075            // no op
076        }
077    
078        public void visitEnd()
079        {
080            // no op
081        }
082    
083        public String getClassName()
084        {
085            return className;
086        }
087    
088        public void setClassName( String className )
089        {
090            this.className = className;
091        }
092    }