001package org.apache.maven.tools.plugin.extractor.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
022import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
023import org.codehaus.plexus.logging.Logger;
024import org.objectweb.asm.AnnotationVisitor;
025import org.objectweb.asm.Attribute;
026import org.objectweb.asm.FieldVisitor;
027import org.objectweb.asm.Opcodes;
028import org.objectweb.asm.Type;
029
030/**
031 * @author Olivier Lamy
032 * @since 3.0
033 */
034public class MojoFieldVisitor
035    extends FieldVisitor
036{
037    private Logger logger;
038
039    private String fieldName;
040
041    private MojoAnnotationVisitor mojoAnnotationVisitor;
042
043    private String className;
044
045    MojoFieldVisitor( Logger logger, String fieldName, String className )
046    {
047        super( Opcodes.ASM5 );
048        this.logger = logger;
049        this.fieldName = fieldName;
050        this.className = className;
051    }
052
053    public MojoAnnotationVisitor getMojoAnnotationVisitor()
054    {
055        return mojoAnnotationVisitor;
056    }
057
058    public String getFieldName()
059    {
060        return fieldName;
061    }
062
063    public AnnotationVisitor visitAnnotation( String desc, boolean visible )
064    {
065        String annotationClassName = Type.getType( desc ).getClassName();
066        if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) )
067        {
068            return null;
069        }
070        mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName );
071        return mojoAnnotationVisitor;
072    }
073
074    public void visitAttribute( Attribute attribute )
075    {
076        // no op
077    }
078
079    public void visitEnd()
080    {
081        // no op
082    }
083
084    public String getClassName()
085    {
086        return className;
087    }
088
089    public void setClassName( String className )
090    {
091        this.className = className;
092    }
093}