use of com.sun.source.tree.ClassTree in project checker-framework by typetools.
the class InterningVisitor method equalsImplementation.
// **********************************************************************
// Helper methods
// **********************************************************************
/**
* Returns the method that overrides Object.equals, or null.
*
* @param node a class
* @return the class's implementation of equals, or null
*/
private MethodTree equalsImplementation(ClassTree node) {
List<? extends Tree> members = node.getMembers();
for (Tree member : members) {
if (member instanceof MethodTree) {
MethodTree mTree = (MethodTree) member;
ExecutableElement enclosing = TreeUtils.elementFromDeclaration(mTree);
if (overrides(enclosing, Object.class, "equals")) {
return mTree;
}
}
}
return null;
}
use of com.sun.source.tree.ClassTree in project checker-framework by typetools.
the class UpperBoundVisitor method visitAnnotation.
/**
* Warns about LTLengthOf annotations with arguments whose lengths do not match.
*/
@Override
public Void visitAnnotation(AnnotationTree node, Void p) {
AnnotationMirror anno = TreeUtils.annotationFromAnnotationTree(node);
if (atypeFactory.areSameByClass(anno, LTLengthOf.class)) {
List<? extends ExpressionTree> args = node.getArguments();
if (args.size() == 2) {
// If offsets are provided, there must be the same number of them as there are arrays.
List<String> sequences = AnnotationUtils.getElementValueArray(anno, atypeFactory.ltLengthOfValueElement, String.class);
List<String> offsets = AnnotationUtils.getElementValueArray(anno, atypeFactory.ltLengthOfOffsetElement, String.class, Collections.emptyList());
if (sequences.size() != offsets.size() && !offsets.isEmpty()) {
checker.reportError(node, "different.length.sequences.offsets", sequences.size(), offsets.size());
return null;
}
}
} else if (atypeFactory.areSameByClass(anno, HasSubsequence.class)) {
// Check that the arguments to a HasSubsequence annotation are valid JavaExpressions,
// and issue an error if one of them is not.
String seq = atypeFactory.hasSubsequenceSubsequenceValue(anno);
String from = atypeFactory.hasSubsequenceFromValue(anno);
String to = atypeFactory.hasSubsequenceToValue(anno);
// check that each expression is parsable at the declaration of this class
ClassTree enclosingClass = TreePathUtil.enclosingClass(getCurrentPath());
checkEffectivelyFinalAndParsable(seq, enclosingClass, node);
checkEffectivelyFinalAndParsable(from, enclosingClass, node);
checkEffectivelyFinalAndParsable(to, enclosingClass, node);
}
return super.visitAnnotation(node, p);
}
use of com.sun.source.tree.ClassTree in project checker-framework by typetools.
the class TypesIntoElements method store.
/**
* The entry point.
*
* @param processingEnv the environment
* @param atypeFactory the type factory
* @param tree the ClassTree to process
*/
public static void store(ProcessingEnvironment processingEnv, AnnotatedTypeFactory atypeFactory, ClassTree tree) {
Symbol.ClassSymbol csym = (Symbol.ClassSymbol) TreeUtils.elementFromDeclaration(tree);
Types types = processingEnv.getTypeUtils();
storeTypeParameters(processingEnv, types, atypeFactory, tree.getTypeParameters(), csym);
for (Tree mem : tree.getMembers()) {
if (mem.getKind() == Tree.Kind.METHOD) {
storeMethod(processingEnv, types, atypeFactory, (MethodTree) mem);
} else if (mem.getKind() == Tree.Kind.VARIABLE) {
storeVariable(processingEnv, types, atypeFactory, (VariableTree) mem);
} else {
// System.out.println("Unhandled member tree: " + mem);
}
}
}
use of com.sun.source.tree.ClassTree 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;
}
}
use of com.sun.source.tree.ClassTree in project checker-framework by typetools.
the class CFGTranslationPhaseOne method visitBindingPattern17.
/**
* Visit a BindingPatternTree
*
* @param bindingPatternTree a BindingPatternTree, typed as Tree to be backward-compatible
* @param p parameter
* @return the result of visiting the binding pattern tree
*/
public Node visitBindingPattern17(Tree bindingPatternTree, Void p) {
ClassTree enclosingClass = TreePathUtil.enclosingClass(getCurrentPath());
TypeElement classElem = TreeUtils.elementFromDeclaration(enclosingClass);
Node receiver = new ImplicitThisNode(classElem.asType());
VariableTree varTree = TreeUtils.bindingPatternTreeGetVariable(bindingPatternTree);
LocalVariableNode varNode = new LocalVariableNode(varTree, receiver);
extendWithNode(varNode);
return varNode;
}
Aggregations