org.checkerframework.checker.index.BaseAnnotatedTypeFactoryForIndexChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checker Show documentation
Show all versions of checker Show documentation
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.
package org.checkerframework.checker.index;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.ExecutableElement;
import org.checkerframework.checker.index.qual.HasSubsequence;
import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory;
import org.checkerframework.common.basetype.BaseTypeChecker;
import org.checkerframework.javacutil.AnnotationUtils;
import org.checkerframework.javacutil.TreeUtils;
/**
* A class for functionality common to multiple type-checkers that are used by the Index Checker.
*/
public abstract class BaseAnnotatedTypeFactoryForIndexChecker extends BaseAnnotatedTypeFactory {
/** The from() element/field of a @HasSubsequence annotation. */
protected final ExecutableElement hasSubsequenceFromElement =
TreeUtils.getMethod(HasSubsequence.class, "from", 0, processingEnv);
/** The to() element/field of a @HasSubsequence annotation. */
protected final ExecutableElement hasSubsequenceToElement =
TreeUtils.getMethod(HasSubsequence.class, "to", 0, processingEnv);
/** The subsequence() element/field of a @HasSubsequence annotation. */
protected final ExecutableElement hasSubsequenceSubsequenceElement =
TreeUtils.getMethod(HasSubsequence.class, "subsequence", 0, processingEnv);
/**
* Creates a new BaseAnnotatedTypeFactoryForIndexChecker.
*
* @param checker the checker
*/
public BaseAnnotatedTypeFactoryForIndexChecker(BaseTypeChecker checker) {
super(checker);
}
/**
* Gets the from() element/field out of a HasSubsequence annotation.
*
* @param anno a HasSubsequence annotation
* @return its from() element/field
*/
public String hasSubsequenceFromValue(AnnotationMirror anno) {
return AnnotationUtils.getElementValue(anno, hasSubsequenceFromElement, String.class);
}
/**
* Gets the to() element/field out of a HasSubsequence annotation.
*
* @param anno a HasSubsequence annotation
* @return its to() element/field
*/
public String hasSubsequenceToValue(AnnotationMirror anno) {
return AnnotationUtils.getElementValue(anno, hasSubsequenceToElement, String.class);
}
/**
* Gets the subsequence() element/field out of a HasSubsequence annotation.
*
* @param anno a HasSubsequence annotation
* @return its subsequence() element/field
*/
public String hasSubsequenceSubsequenceValue(AnnotationMirror anno) {
return AnnotationUtils.getElementValue(anno, hasSubsequenceSubsequenceElement, String.class);
}
}