use of org.checkerframework.framework.stub.AnnotationFileElementTypes in project checker-framework by typetools.
the class AnnotatedTypeFactory method applyFakeOverrides.
/**
* Given a member and its type, returns the type with fake overrides applied to it.
*
* @param receiverType the type of the class that contains member (or a subtype of it)
* @param member a type member, such as a method or field
* @param memberType the type of {@code member}
* @return {@code memberType}, adjusted according to fake overrides
*/
private AnnotatedExecutableType applyFakeOverrides(AnnotatedTypeMirror receiverType, Element member, AnnotatedExecutableType memberType) {
// Currently, handle only methods, not fields. TODO: Handle fields.
if (memberType.getKind() != TypeKind.EXECUTABLE) {
return memberType;
}
AnnotationFileElementTypes afet = stubTypes;
AnnotatedExecutableType methodType = afet.getFakeOverride(member, receiverType);
if (methodType == null) {
methodType = memberType;
}
return methodType;
}
use of org.checkerframework.framework.stub.AnnotationFileElementTypes in project checker-framework by typetools.
the class AnnotatedTypeFactory method setRoot.
/**
* Set the CompilationUnitTree that should be used.
*
* @param root the new compilation unit to use
*/
public void setRoot(@Nullable CompilationUnitTree root) {
if (root != null && wholeProgramInference != null) {
for (Tree typeDecl : root.getTypeDecls()) {
if (typeDecl.getKind() == Tree.Kind.CLASS) {
ClassTree classTree = (ClassTree) typeDecl;
wholeProgramInference.preprocessClassTree(classTree);
}
}
}
this.root = root;
// if this isn't a GenericATF, then it must clear it itself.
if (!(this instanceof GenericAnnotatedTypeFactory)) {
artificialTreeToEnclosingElementMap.clear();
}
if (shouldCache) {
// Clear the caches with trees because once the compilation unit changes,
// the trees may be modified and lose type arguments.
elementToTreeCache.clear();
fromExpressionTreeCache.clear();
fromMemberTreeCache.clear();
fromTypeTreeCache.clear();
classAndMethodTreeCache.clear();
// There is no need to clear the following cache, it is limited by cache size and it
// contents won't change between compilation units.
// elementCache.clear();
}
if (root != null && checker.hasOption("ajava")) {
// Search for an ajava file with annotations for the current source file and the current
// checker. It will be in a directory specified by the "ajava" option in a subdirectory
// corresponding to this file's package. For example, a file in package a.b would be in a
// subdirectory a/b. The filename is ClassName-checker.qualified.name.ajava. If such a file
// exists, read its detailed annotation data, including annotations on private elements.
String packagePrefix = root.getPackageName() != null ? TreeUtils.nameExpressionToString(root.getPackageName()) + "." : "";
// The method getName() returns a path.
String className = root.getSourceFile().getName();
// Extract the basename.
int lastSeparator = className.lastIndexOf(File.separator);
if (lastSeparator != -1) {
className = className.substring(lastSeparator + 1);
}
// Drop the ".java" extension.
if (className.endsWith(".java")) {
className = className.substring(0, className.length() - ".java".length());
}
String qualifiedName = packagePrefix + className;
for (String ajavaLocation : checker.getOption("ajava").split(File.pathSeparator)) {
String ajavaPath = ajavaLocation + File.separator + qualifiedName.replaceAll("\\.", "/") + "-" + checker.getClass().getCanonicalName() + ".ajava";
File ajavaFile = new File(ajavaPath);
if (ajavaFile.exists()) {
currentFileAjavaTypes = new AnnotationFileElementTypes(this);
currentFileAjavaTypes.parseAjavaFileWithTree(ajavaPath, root);
break;
}
}
} else {
currentFileAjavaTypes = null;
}
}
Aggregations