All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.pmd.lang.java.symbols.AnnotableSymbol Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
/*
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

package net.sourceforge.pmd.lang.java.symbols;

import java.lang.annotation.Annotation;

import org.pcollections.HashTreePSet;
import org.pcollections.PSet;

import net.sourceforge.pmd.lang.java.symbols.SymbolicValue.SymAnnot;

/**
 * A symbol that can have annotations.
 */
public interface AnnotableSymbol extends JElementSymbol {

    /**
     * Return the valid symbolic annotations defined on this symbol.
     * Annotations that could not be converted, eg because
     * they are written with invalid code, are discarded, so
     * this might not match the annotations on a node one to one.
     */
    default PSet getDeclaredAnnotations() {
        return HashTreePSet.empty();
    }


    /**
     * Return an annotation of the given type, if it is present on this declaration.
     * This does not consider inherited annotations.
     */
    default SymbolicValue.SymAnnot getDeclaredAnnotation(Class type) {
        for (SymAnnot a : getDeclaredAnnotations()) {
            if (a.isOfType(type)) {
                return a;
            }
        }
        return null;
    }


    /**
     * Return true if an annotation of the given type is present on this declaration.
     */
    default boolean isAnnotationPresent(Class type) {
        return getDeclaredAnnotation(type) != null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy