コード例 #1
0
 @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);
 }
コード例 #2
0
    @Override
    public Void visitDeclared(AnnotatedDeclaredType type, ElementKind p) {
      Element elt = type.getElement();
      if (!type.isAnnotated()
          && (
          /*checker.isDefaultAnyType(type) ||*/
          elt != null
              && ElementUtils.isStatic(elt)
              && (elt.getKind() == ElementKind.FIELD
                  || elt.getKind() == ElementKind.LOCAL_VARIABLE
                  || elt.getKind() == ElementKind.EXCEPTION_PARAMETER
                  || elt.getKind() == ElementKind.ENUM_CONSTANT
                  || elt.getKind() == ElementKind.PARAMETER))) {
        type.clearAnnotations();
        Set<AnnotationMirror> set = AnnotationUtils.createAnnotationSet();
        set.add(checker.ANY);
        if (elt != null && ElementUtils.isStatic(elt)) set.add(checker.PEER);

        annotateConstants(type, set);
      }
      return super.visitDeclared(type, p);
    }
コード例 #3
0
  @Override
  public boolean isAssignable(AnnotatedTypeMirror varType, Tree varTree) {
    if (varTree.getKind() == Tree.Kind.VARIABLE || varType.hasAnnotation(ASSIGNABLE)) return true;

    Element varElement = InternalUtils.symbol(varTree);
    if (varElement == null || !varElement.getKind().isField() || ElementUtils.isStatic(varElement))
      return true;

    ExpressionTree expTree = (ExpressionTree) varTree;
    AnnotatedTypeMirror receiver = factory.getReceiver(expTree);

    boolean isAssignable =
        receiver.hasAnnotation(MUTABLE)
            || (receiver.hasAnnotation(ASSIGNS_FIELDS) && TreeUtils.isSelfAccess(expTree));

    return isAssignable;
  }
コード例 #4
0
 @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;
 }