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.ASM9 );
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    @Override
064    public AnnotationVisitor visitAnnotation( String desc, boolean visible )
065    {
066        String annotationClassName = Type.getType( desc ).getClassName();
067        if ( !MojoAnnotationsScanner.FIELD_LEVEL_ANNOTATIONS.contains( annotationClassName ) )
068        {
069            return null;
070        }
071        mojoAnnotationVisitor = new MojoAnnotationVisitor( logger, annotationClassName );
072        return mojoAnnotationVisitor;
073    }
074
075    @Override
076    public void visitAttribute( Attribute attribute )
077    {
078        // no op
079    }
080
081    @Override
082    public void visitEnd()
083    {
084        // no op
085    }
086
087    public String getClassName()
088    {
089        return className;
090    }
091
092    public void setClassName( String className )
093    {
094        this.className = className;
095    }
096}