private boolean isNotLoopLocalVar(AssignmentExpressionTree tree) { IdentifierTree idTree = getIdentifierTree(tree.variable()); Tree envTree = semanticModel.getTree(semanticModel.getEnv(idTree.symbol())); Tree loopTree = loopLevel.peek(); return envTree == null || !(envTree.equals(loopTree) || envTree.equals(loopStatement(loopTree))); }
private boolean isNotLoopLocalVar(AssignmentExpressionTree tree) { IdentifierTree idTree = getIdentifierTree(tree.variable()); Tree envTree = semanticModel.getTree(semanticModel.getEnv(idTree.symbol())); Tree loopTree = loopLevel.peek(); return envTree == null || !(envTree.equals(loopTree) || envTree.equals(loopStatement(loopTree))); }
private boolean isNotLoopLocalVar(AssignmentExpressionTree tree) { IdentifierTree idTree = getIdentifierTree(tree.variable()); Tree envTree = semanticModel.getTree(semanticModel.getEnv(idTree.symbol())); Tree loopTree = loopLevel.peek(); if(envTree!= null && (envTree.equals(loopTree) || envTree.equals(loopStatement(loopTree)))) { return false; } return true; }
private void enterSymbol(JavaSymbol symbol, ImportTree tree) { env.namedImports.enter(symbol); //FIXME We add all symbols to named Imports for static methods, but only the first one will be resolved as we don't handle arguments. //FIXME That is why we only add the first symbol so we resolve references at best for now. //add to semantic model only the first symbol. //twice the same import : ignore the duplication JLS8 7.5.1. if (semanticModel.getSymbol(tree) == null && semanticModel.getTree(symbol) == null) { semanticModel.associateSymbol(tree, symbol); } }
private void enterSymbol(JavaSymbol symbol, ImportTree tree) { env.namedImports.enter(symbol); //FIXME We add all symbols to named Imports for static methods, but only the first one will be resolved as we don't handle arguments. //FIXME That is why we only add the first symbol so we resolve references at best for now. //add to semantic model only the first symbol. //twice the same import : ignore the duplication JLS8 7.5.1. if (semanticModel.getSymbol(tree) == null && semanticModel.getTree(symbol) == null) { semanticModel.associateSymbol(tree, symbol); } }
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 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; }