private boolean isExcluded(@Nullable Symbol currentlyChecking, Symbol symbol) { return !symbol.isVariableSymbol() || symbol.equals(currentlyChecking) || isConstant(symbol); }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking) { return isDynamicString(methodTree, arg, currentlyChecking, false); }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { if (arg.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) arg; IdentifierTree identifier = memberSelectExpressionTree.identifier(); if (ExpressionUtils.isSelectOnThisOrSuper(memberSelectExpressionTree)) { return isIdentifierDynamicString(methodTree, identifier, currentlyChecking, firstLevel); } return !isConstant(identifier.symbol()); } else if (arg.is(Tree.Kind.IDENTIFIER)) { return isIdentifierDynamicString(methodTree, (IdentifierTree) arg, currentlyChecking, firstLevel); } else if (arg.is(Tree.Kind.PLUS)) { BinaryExpressionTree binaryArg = (BinaryExpressionTree) arg; return isDynamicString(methodTree, binaryArg.rightOperand(), currentlyChecking) || isDynamicString(methodTree, binaryArg.leftOperand(), currentlyChecking); } else if (arg.is(Tree.Kind.METHOD_INVOCATION)) { return false; } return !arg.is(Tree.Kind.STRING_LITERAL, Tree.Kind.NULL_LITERAL); }
protected boolean isIdentifierDynamicString(Tree methodTree, IdentifierTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { Symbol symbol = arg.symbol(); if (isExcluded(currentlyChecking, symbol)) { return false; } Tree enclosingBlockTree = getSemanticModel().getTree(getSemanticModel().getEnv(methodTree)); Tree argEnclosingDeclarationTree = getSemanticModel().getTree(getSemanticModel().getEnv(symbol)); if (enclosingBlockTree.equals(argEnclosingDeclarationTree)) { //symbol is a local variable, check it is not a dynamic string. //Check declaration VariableTree declaration = ((Symbol.VariableSymbol) symbol).declaration(); ExpressionTree initializer = declaration.initializer(); if (initializer != null && isDynamicString(methodTree, initializer, currentlyChecking)) { return true; } //check usages by revisiting the enclosing tree. Collection<IdentifierTree> usages = symbol.usages(); LocalVariableDynamicStringVisitor visitor = new LocalVariableDynamicStringVisitor(symbol, usages, methodTree); argEnclosingDeclarationTree.accept(visitor); return visitor.dynamicString; } //arg is not a local variable nor a constant, so it is a parameter or a field. parameterName = arg.name(); return symbol.owner().isMethodSymbol() && !firstLevel; }
protected boolean isIdentifierDynamicString(Tree methodTree, IdentifierTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { Symbol symbol = arg.symbol(); if (isExcluded(currentlyChecking, symbol)) { return false; } boolean isLocalVar = symbol.owner().isMethodSymbol() && !((JavaSymbol.MethodJavaSymbol) symbol.owner()).getParameters().scopeSymbols().contains(symbol); if (isLocalVar) { //symbol is a local variable, check it is not a dynamic string. //Check declaration VariableTree declaration = ((Symbol.VariableSymbol) symbol).declaration(); ExpressionTree initializer = declaration.initializer(); if (initializer != null && isDynamicString(methodTree, initializer, currentlyChecking)) { return true; } //check usages by revisiting the enclosing tree. Collection<IdentifierTree> usages = symbol.usages(); LocalVariableDynamicStringVisitor visitor = new LocalVariableDynamicStringVisitor(symbol, usages, methodTree); Tree argEnclosingDeclarationTree = semanticModel.getTree(semanticModel.getEnv(symbol)); argEnclosingDeclarationTree.accept(visitor); return visitor.dynamicString; } //arg is not a local variable nor a constant, so it is a parameter or a field. parameterName = "\""+arg.name()+"\""; return symbol.owner().isMethodSymbol() && !firstLevel; }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { if (arg.is(Tree.Kind.IDENTIFIER)) { return isIdentifierDynamicString(methodTree, (IdentifierTree) arg, currentlyChecking, firstLevel); } else if (arg.is(Tree.Kind.PLUS)) { BinaryExpressionTree binaryArg = (BinaryExpressionTree) arg; return isDynamicString(methodTree, binaryArg.rightOperand(), currentlyChecking) || isDynamicString(methodTree, binaryArg.leftOperand(), currentlyChecking); } else if (arg.is(Tree.Kind.METHOD_INVOCATION)) { return false; } return !arg.is(Tree.Kind.STRING_LITERAL); }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { if (arg.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) arg; IdentifierTree identifier = memberSelectExpressionTree.identifier(); if (ExpressionUtils.isSelectOnThisOrSuper(memberSelectExpressionTree)) { return isIdentifierDynamicString(methodTree, identifier, currentlyChecking, firstLevel); } return !isConstant(identifier.symbol()); } else if (arg.is(Tree.Kind.IDENTIFIER)) { return isIdentifierDynamicString(methodTree, (IdentifierTree) arg, currentlyChecking, firstLevel); } else if (arg.is(Tree.Kind.PLUS)) { BinaryExpressionTree binaryArg = (BinaryExpressionTree) arg; return isDynamicString(methodTree, binaryArg.rightOperand(), currentlyChecking) || isDynamicString(methodTree, binaryArg.leftOperand(), currentlyChecking); } else if (arg.is(Tree.Kind.METHOD_INVOCATION)) { return false; } return !arg.is(Tree.Kind.STRING_LITERAL, Tree.Kind.NULL_LITERAL); }
protected boolean isIdentifierDynamicString(Tree methodTree, IdentifierTree arg, @Nullable Symbol currentlyChecking, boolean firstLevel) { Symbol symbol = arg.symbol(); if (isExcluded(currentlyChecking, symbol)) { return false; } boolean isLocalVar = symbol.owner().isMethodSymbol() && !((JavaSymbol.MethodJavaSymbol) symbol.owner()).getParameters().scopeSymbols().contains(symbol); if (isLocalVar) { //symbol is a local variable, check it is not a dynamic string. //Check declaration VariableTree declaration = ((Symbol.VariableSymbol) symbol).declaration(); ExpressionTree initializer = declaration.initializer(); if (initializer != null && isDynamicString(methodTree, initializer, currentlyChecking)) { return true; } //check usages by revisiting the enclosing tree. Collection<IdentifierTree> usages = symbol.usages(); LocalVariableDynamicStringVisitor visitor = new LocalVariableDynamicStringVisitor(symbol, usages, methodTree); Tree argEnclosingDeclarationTree = semanticModel.getTree(semanticModel.getEnv(symbol)); argEnclosingDeclarationTree.accept(visitor); return visitor.dynamicString; } //arg is not a local variable nor a constant, so it is a parameter or a field. parameterName = "\""+arg.name()+"\""; return symbol.owner().isMethodSymbol() && !firstLevel; }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking) { return isDynamicString(methodTree, arg, currentlyChecking, false); }
private boolean isExcluded(@Nullable Symbol currentlyChecking, Symbol symbol) { return !symbol.isVariableSymbol() || symbol.equals(currentlyChecking) || isConstant(symbol); }
protected boolean isDynamicString(Tree methodTree, ExpressionTree arg, @Nullable Symbol currentlyChecking) { return isDynamicString(methodTree, arg, currentlyChecking, false); }
private boolean isExcluded(@Nullable Symbol currentlyChecking, Symbol symbol) { return !symbol.isVariableSymbol() || symbol.equals(currentlyChecking) || isConstant(symbol); }
@Override public void visitAssignmentExpression(AssignmentExpressionTree tree) { if (!stopInspection && tree.variable().is(Tree.Kind.IDENTIFIER) && usages.contains(tree.variable())) { dynamicString |= isDynamicString(methodInvocationTree, tree.expression(), currentlyChecking); } super.visitAssignmentExpression(tree); }
@Override public void visitAssignmentExpression(AssignmentExpressionTree tree) { if (!stopInspection && tree.variable().is(Tree.Kind.IDENTIFIER) && usages.contains(tree.variable())) { dynamicString |= isDynamicString(methodInvocationTree, tree.expression(), currentlyChecking); } super.visitAssignmentExpression(tree); }
@Override public void visitAssignmentExpression(AssignmentExpressionTree tree) { if (!stopInspection && tree.variable().is(Tree.Kind.IDENTIFIER) && usages.contains(tree.variable())) { dynamicString |= isDynamicString(methodInvocationTree, tree.expression(), currentlyChecking); } super.visitAssignmentExpression(tree); }