@Override public Void visitBinary(BinaryTree node, AnnotatedTypeMirror p) { if (!p.isAnnotated() && checker.isChecking()) { p.addAnnotation(checker.BOTTOM); } return super.visitBinary(node, p); }
@Override public Void visitTypeCast(TypeCastTree node, AnnotatedTypeMirror p) { if (!p.isAnnotated()) { // check if it is casting "this" if (TreeUtils.skipParens(node.getExpression()).toString().equals("this")) { annotateThis(p); } } return super.visitTypeCast(node, p); }
@Override public Void visitVariable(VariableTree node, AnnotatedTypeMirror p) { typeAnnotator.visit(p); VariableElement varElt = TreeUtils.elementFromDeclaration((VariableTree) node); if (!p.isAnnotated() && ElementUtils.isStatic(varElt)) { p.clearAnnotations(); Set<AnnotationMirror> set = AnnotationUtils.createAnnotationSet(); set.add(checker.ANY); set.add(checker.PEER); annotateConstants(p, set); } return super.visitVariable(node, p); }
@Override public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) { if (!type.isAnnotated()) { // if (type.getKind() == TypeKind.NULL) { type.clearAnnotations(); Set<AnnotationMirror> set = AnnotationUtils.createAnnotationSet(); set.add(checker.BOTTOM); annotateConstants(type, set); // } // else // type.addAnnotation(checker.READONLY); } return super.visitLiteral(tree, type); }
@Override public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) { if (!type.isAnnotated()) { if (factory.getVisitorState().getAssignmentContext().getExplicitAnnotations().size() > 0) { for (AnnotationMirror m : factory.getVisitorState().getAssignmentContext().getExplicitAnnotations()) { type.addAnnotation(m); break; } } // type.atypeFactory.getVisitorState().getAssignmentContext().getExplicitAnnotations().size(); // // System.out.println("Visiting unannotated type~\n\n"); // // AnnotationBuilder builder = // new AnnotationBuilder(processingEnv, // Level.class.getCanonicalName()); // builder.setValue("value", "Public"); // //// type.addAnnotation(builder.build()); // // String regex = null; //// if (tree.getKind() == Tree.Kind.STRING_LITERAL) { //// regex = (String) tree.getValue(); //// } else if (tree.getKind() == Tree.Kind.CHAR_LITERAL) { //// regex = Character.toString((Character) tree.getValue()); //// } //// if (regex != null) { //// if (isRegex(regex)) { //// int groupCount = checker.getGroupCount(regex); //// type.addAnnotation(createRegexAnnotation(groupCount)); //// } else { //// type.addAnnotation(createPartialRegexAnnotation(regex)); //// } //// } } return super.visitLiteral(tree, type); }
@Override public AnnotatedTypeMirror getAnnotatedType(Tree tree) { AnnotatedTypeMirror type = super.getAnnotatedType(tree); if (tree instanceof ExpressionTree) tree = TreeUtils.skipParens((ExpressionTree) tree); Element elt = InternalUtils.symbol(tree); if (!checker.isChecking() /*&& !checker.isDefaultAnyType(type)*/ && type.isAnnotated() && !type.getKind().isPrimitive() && type.getKind() != TypeKind.NULL && (elt == null || !ElementUtils.isStatic(elt))) { // We don't want annotations on the following trees Kind kind = tree.getKind(); if (kind == Kind.METHOD_INVOCATION || kind == Kind.ARRAY_ACCESS || kind == Kind.MEMBER_SELECT || kind == Kind.CONDITIONAL_EXPRESSION) { type = type.getCopy(false); } } return type; }