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

org.checkerframework.javacutil.BasicAnnotationProvider Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java's type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

The newest version!
package org.checkerframework.javacutil;

import com.sun.source.tree.Tree;

import org.checkerframework.checker.nullness.qual.Nullable;

import java.lang.annotation.Annotation;
import java.util.List;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;

/** An AnnotationProvider that is independent of any type hierarchy. */
public class BasicAnnotationProvider implements AnnotationProvider {

    /**
     * Returns the AnnotationMirror, of the given class, used to annotate the element. Returns null
     * if no such annotation exists.
     */
    @Override
    public @Nullable AnnotationMirror getDeclAnnotation(
            Element elt, Class anno) {
        List annotationMirrors = elt.getAnnotationMirrors();

        for (AnnotationMirror am : annotationMirrors) {
            @SuppressWarnings("deprecation") // method intended for use by the hierarchy
            boolean found = AnnotationUtils.areSameByClass(am, anno);
            if (found) {
                return am;
            }
        }

        return null;
    }

    /**
     * {@inheritDoc}
     *
     * 

This implementation always returns null, because it has no access to any type hierarchy. */ @Override public @Nullable AnnotationMirror getAnnotationMirror( Tree tree, Class target) { return null; } /** * {@inheritDoc} * *

This implementation returns true if the {@code @SideEffectFree} annotation is present on * the given method. */ @Override public boolean isSideEffectFree(ExecutableElement methodElement) { List annotationMirrors = methodElement.getAnnotationMirrors(); for (AnnotationMirror am : annotationMirrors) { boolean found = AnnotationUtils.areSameByName( am, "org.checkerframework.dataflow.qual.SideEffectFree"); if (found) { return true; } } return false; } /** * {@inheritDoc} * *

This implementation returns true if the {@code @Deterministic} annotation is present on * the given method. */ @Override public boolean isDeterministic(ExecutableElement methodElement) { List annotationMirrors = methodElement.getAnnotationMirrors(); for (AnnotationMirror am : annotationMirrors) { boolean found = AnnotationUtils.areSameByName( am, "org.checkerframework.dataflow.qual.Deterministic"); if (found) { return true; } } return false; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy