private SymbolicValue createIdentifierSymbolicValue(IdentifierTree identifier) {
   final Type type = identifier.symbol().type();
   if (type != null && type.is("java.lang.Boolean")) {
     if ("TRUE".equals(identifier.name())) {
       return SymbolicValue.TRUE_LITERAL;
     } else if ("FALSE".equals(identifier.name())) {
       return SymbolicValue.FALSE_LITERAL;
     }
   }
   return createDefaultSymbolicValue();
 }
 private void addBoxingIssue(Tree tree, Symbol classSymbol, Tree boxingArg) {
   if (boxingArg.is(Tree.Kind.IDENTIFIER)) {
     IdentifierTree identifier = (IdentifierTree) boxingArg;
     reportIssue(tree, "Remove the boxing of \"" + identifier.name() + "\".");
   } else {
     reportIssue(tree, "Remove the boxing to \"" + classSymbol.name() + "\".");
   }
 }
 private void checkIdentifier(IdentifierTree identifierTree) {
   if (loopCounters.contains(identifierTree.name())) {
     context.addIssue(
         identifierTree,
         ruleKey,
         "Refactor the code in order to not assign to this loop counter from within the loop body.");
   }
 }
 private void addUnboxingIssue(ExpressionTree expressionTree, ExpressionTree expression) {
   if (expression.is(Tree.Kind.IDENTIFIER)) {
     IdentifierTree identifier = (IdentifierTree) expression;
     reportIssue(expressionTree, "Remove the unboxing of \"" + identifier.name() + "\".");
   } else {
     String name = expression.symbolType().name();
     reportIssue(expressionTree, "Remove the unboxing from \"" + name + "\".");
   }
 }
Esempio n. 5
0
 public boolean isAnnotatedOverride() {
   for (AnnotationTree annotationTree : modifiers.annotations()) {
     if (annotationTree.annotationType().is(Tree.Kind.IDENTIFIER)) {
       IdentifierTree identifier = (IdentifierTree) annotationTree.annotationType();
       if (Override.class.getSimpleName().equals(identifier.name())) {
         return true;
       }
     }
   }
   return false;
 }
Esempio n. 6
0
 @Override
 public void visitClass(ClassTree tree) {
   String className = "";
   IdentifierTree simpleName = tree.simpleName();
   if (simpleName != null) {
     className = simpleName.name();
   }
   String key = getClassKey(className);
   currentClassKey.push(key);
   parent.push(tree);
   anonymousInnerClassCounter.push(0);
   resourcesCache.put(key, currentFile);
   handleSuppressWarning(tree);
   super.visitClass(tree);
   currentClassKey.pop();
   parent.pop();
   anonymousInnerClassCounter.pop();
 }
  private static String concatenate(ExpressionTree tree) {
    Deque<String> pieces = new LinkedList<>();
    ExpressionTree expr = tree;
    while (expr.is(Tree.Kind.MEMBER_SELECT)) {
      MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr;
      pieces.push(mse.identifier().name());
      pieces.push(".");
      expr = mse.expression();
    }
    if (expr.is(Tree.Kind.IDENTIFIER)) {
      IdentifierTree idt = (IdentifierTree) expr;
      pieces.push(idt.name());
    }

    StringBuilder sb = new StringBuilder();
    for (String piece : pieces) {
      sb.append(piece);
    }
    return sb.toString();
  }
  private boolean isQualifiedExcludedType(Tree tree) {
    if (!tree.is(Kind.MEMBER_SELECT)) {
      return false;
    }
    Deque<String> pieces = new LinkedList<>();
    ExpressionTree expr = (MemberSelectExpressionTree) tree;
    while (expr.is(Tree.Kind.MEMBER_SELECT)) {
      MemberSelectExpressionTree mse = (MemberSelectExpressionTree) expr;
      pieces.push(mse.identifier().name());
      pieces.push(".");
      expr = mse.expression();
    }
    if (expr.is(Tree.Kind.IDENTIFIER)) {
      IdentifierTree idt = (IdentifierTree) expr;
      pieces.push(idt.name());
    }

    StringBuilder sb = new StringBuilder();
    for (String piece : pieces) {
      sb.append(piece);
    }
    return Iterables.contains(exceptions, sb.toString());
  }
Esempio n. 9
0
 @Override
 public void visitIdentifier(IdentifierTree tree) {
   site = resolve.findIdent(env, tree.name(), Symbol.TYP | Symbol.PCK);
   associateReference(tree, site);
 }