private HashSet<String> makeNamesUnique(HashSet<String> excludedNames, MethodDeclaration methodDeclaration, ASTRewrite rewrite, TextEditGroup group) { HashSet<String> newNames= new HashSet<>(); excludedNames.addAll(ASTNodes.getVisibleLocalVariablesInScope(methodDeclaration)); List<SimpleName> simpleNamesInMethod= getNamesInMethod(methodDeclaration); List<String> namesInMethod= new ArrayList<>(); for (SimpleName name : simpleNamesInMethod) { namesInMethod.add(name.getIdentifier()); } for (int i= 0; i < simpleNamesInMethod.size(); i++) { SimpleName name= simpleNamesInMethod.get(i); String identifier= namesInMethod.get(i); HashSet<String> allNamesToExclude= getNamesToExclude(excludedNames, namesInMethod, i); if (allNamesToExclude.contains(identifier)) { String newIdentifier= createName(identifier, allNamesToExclude); excludedNames.add(newIdentifier); newNames.add(newIdentifier); SimpleName[] references= LinkedNodeFinder.findByNode(name.getRoot(), name); for (SimpleName ref : references) { rewrite.set(ref, SimpleName.IDENTIFIER_PROPERTY, newIdentifier, group); } } } return newNames; }
private HashSet<String> makeNamesUnique(HashSet<String> excludedNames, MethodDeclaration methodDeclaration, ASTRewrite rewrite, TextEditGroup group) { HashSet<String> newNames = new HashSet<>(); excludedNames.addAll(ASTNodes.getVisibleLocalVariablesInScope(methodDeclaration)); List<SimpleName> simpleNamesInMethod = getNamesInMethod(methodDeclaration); List<String> namesInMethod = new ArrayList<>(); for (SimpleName name : simpleNamesInMethod) { namesInMethod.add(name.getIdentifier()); } for (int i = 0; i < simpleNamesInMethod.size(); i++) { SimpleName name = simpleNamesInMethod.get(i); String identifier = namesInMethod.get(i); HashSet<String> allNamesToExclude = getNamesToExclude(excludedNames, namesInMethod, i); if (allNamesToExclude.contains(identifier)) { String newIdentifier = createName(identifier, allNamesToExclude); excludedNames.add(newIdentifier); newNames.add(newIdentifier); SimpleName[] references = LinkedNodeFinder.findByNode(name.getRoot(), name); for (SimpleName ref : references) { rewrite.set(ref, SimpleName.IDENTIFIER_PROPERTY, newIdentifier, group); } } } return newNames; }
private HashSet<String> makeNamesUnique(HashSet<String> excludedNames, MethodDeclaration methodDeclaration, ASTRewrite rewrite, TextEditGroup group) { HashSet<String> newNames= new HashSet<>(); excludedNames.addAll(ASTNodes.getVisibleLocalVariablesInScope(methodDeclaration)); List<SimpleName> simpleNamesInMethod= getNamesInMethod(methodDeclaration); List<String> namesInMethod= new ArrayList<>(); for (SimpleName name : simpleNamesInMethod) { namesInMethod.add(name.getIdentifier()); } for (int i= 0; i < simpleNamesInMethod.size(); i++) { SimpleName name= simpleNamesInMethod.get(i); String identifier= namesInMethod.get(i); HashSet<String> allNamesToExclude= getNamesToExclude(excludedNames, namesInMethod, i); if (allNamesToExclude.contains(identifier)) { String newIdentifier= createName(identifier, allNamesToExclude); excludedNames.add(newIdentifier); newNames.add(newIdentifier); SimpleName[] references= LinkedNodeFinder.findByNode(name.getRoot(), name); for (SimpleName ref : references) { rewrite.set(ref, SimpleName.IDENTIFIER_PROPERTY, newIdentifier, group); } } } return newNames; }
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= fContext.getASTRoot(); AST ast= astRoot.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); AbstractTypeDeclaration decl= findTypeDeclaration(astRoot.types(), fOldName); if (decl != null) { ASTNode[] sameNodes= LinkedNodeFinder.findByNode(astRoot, decl.getName()); for (int i= 0; i < sameNodes.length; i++) { rewrite.replace(sameNodes[i], ast.newSimpleName(fNewName), null); } } return rewrite; }
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= fContext.getASTRoot(); AST ast= astRoot.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); AbstractTypeDeclaration decl= findTypeDeclaration(astRoot.types(), fOldName); if (decl != null) { ASTNode[] sameNodes= LinkedNodeFinder.findByNode(astRoot, decl.getName()); for (int i= 0; i < sameNodes.length; i++) { rewrite.replace(sameNodes[i], ast.newSimpleName(fNewName), null); } } return rewrite; }
protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= fContext.getASTRoot(); AST ast= astRoot.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); AbstractTypeDeclaration decl= findTypeDeclaration(astRoot.types(), fOldName); if (decl != null) { ASTNode[] sameNodes= LinkedNodeFinder.findByNode(astRoot, decl.getName()); for (int i= 0; i < sameNodes.length; i++) { rewrite.replace(sameNodes[i], ast.newSimpleName(fNewName), null); } } return rewrite; }
@Override protected ASTRewrite getRewrite() throws CoreException { CompilationUnit astRoot= fContext.getASTRoot(); AST ast= astRoot.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); AbstractTypeDeclaration decl= findTypeDeclaration(astRoot.types(), fOldName); if (decl != null) { ASTNode[] sameNodes= LinkedNodeFinder.findByNode(astRoot, decl.getName()); for (int i= 0; i < sameNodes.length; i++) { rewrite.replace(sameNodes[i], ast.newSimpleName(fNewName), null); } } return rewrite; }
sameNodes= LinkedNodeFinder.findByNode(root, (SimpleName) nameNode); } else { sameNodes= new ASTNode[] { nameNode };
sameNodes= LinkedNodeFinder.findByNode(root, (SimpleName) nameNode); } else { sameNodes= new ASTNode[] { nameNode };
sameNodes= LinkedNodeFinder.findByNode(root, (SimpleName) nameNode); } else { sameNodes= new ASTNode[] { nameNode };
private static SimpleType getRawReference(SimpleName name, CompilationUnit compilationUnit) { SimpleName[] names= LinkedNodeFinder.findByNode(compilationUnit, name); for (int j= 0; j < names.length; j++) { if (names[j].getParent() instanceof VariableDeclarationFragment) { VariableDeclarationFragment fragment= (VariableDeclarationFragment)names[j].getParent(); if (fragment.getParent() instanceof VariableDeclarationStatement) { VariableDeclarationStatement statement= (VariableDeclarationStatement)fragment.getParent(); ASTNode result= (ASTNode)statement.getStructuralProperty(VariableDeclarationStatement.TYPE_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } else if (fragment.getParent() instanceof FieldDeclaration) { FieldDeclaration declaration= (FieldDeclaration)fragment.getParent(); ASTNode result= (ASTNode)declaration.getStructuralProperty(FieldDeclaration.TYPE_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } } else if (names[j].getParent() instanceof SingleVariableDeclaration) { SingleVariableDeclaration declaration= (SingleVariableDeclaration)names[j].getParent(); ASTNode result= (ASTNode)declaration.getStructuralProperty(SingleVariableDeclaration.TYPE_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } else if (names[j].getParent() instanceof MethodDeclaration) { MethodDeclaration methodDecl= (MethodDeclaration)names[j].getParent(); ASTNode result= (ASTNode)methodDecl.getStructuralProperty(MethodDeclaration.RETURN_TYPE2_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } } return null; }
private static SimpleType getRawReference(SimpleName name, CompilationUnit compilationUnit) { SimpleName[] names= LinkedNodeFinder.findByNode(compilationUnit, name); for (int j= 0; j < names.length; j++) { if (names[j].getParent() instanceof VariableDeclarationFragment) { VariableDeclarationFragment fragment= (VariableDeclarationFragment)names[j].getParent(); if (fragment.getParent() instanceof VariableDeclarationStatement) { VariableDeclarationStatement statement= (VariableDeclarationStatement)fragment.getParent(); ASTNode result= (ASTNode)statement.getStructuralProperty(VariableDeclarationStatement.TYPE_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } else if (fragment.getParent() instanceof FieldDeclaration) { FieldDeclaration declaration= (FieldDeclaration)fragment.getParent(); ASTNode result= (ASTNode)declaration.getStructuralProperty(FieldDeclaration.TYPE_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } } else if (names[j].getParent() instanceof SingleVariableDeclaration) { SingleVariableDeclaration declaration= (SingleVariableDeclaration)names[j].getParent(); ASTNode result= (ASTNode)declaration.getStructuralProperty(SingleVariableDeclaration.TYPE_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } else if (names[j].getParent() instanceof MethodDeclaration) { MethodDeclaration methodDecl= (MethodDeclaration)names[j].getParent(); ASTNode result= (ASTNode)methodDecl.getStructuralProperty(MethodDeclaration.RETURN_TYPE2_PROPERTY); if (isRawTypeReference(result)) return (SimpleType) result; } } return null; }
private static ASTNode getRawReference(SimpleName name, CompilationUnit compilationUnit) { SimpleName[] names= LinkedNodeFinder.findByNode(compilationUnit, name); for (int j= 0; j < names.length; j++) { if (names[j].getParent() instanceof VariableDeclarationFragment) { VariableDeclarationFragment fragment= (VariableDeclarationFragment)names[j].getParent(); if (fragment.getParent() instanceof VariableDeclarationStatement) { VariableDeclarationStatement statement= (VariableDeclarationStatement)fragment.getParent(); ASTNode result= (ASTNode)statement.getStructuralProperty(VariableDeclarationStatement.TYPE_PROPERTY); if (isRawTypeReference(result)) return result; } else if (fragment.getParent() instanceof FieldDeclaration) { FieldDeclaration declaration= (FieldDeclaration)fragment.getParent(); ASTNode result= (ASTNode)declaration.getStructuralProperty(FieldDeclaration.TYPE_PROPERTY); if (isRawTypeReference(result)) return result; } } else if (names[j].getParent() instanceof SingleVariableDeclaration) { SingleVariableDeclaration declaration= (SingleVariableDeclaration)names[j].getParent(); ASTNode result= (ASTNode)declaration.getStructuralProperty(SingleVariableDeclaration.TYPE_PROPERTY); if (isRawTypeReference(result)) return result; } else if (names[j].getParent() instanceof MethodDeclaration) { MethodDeclaration methodDecl= (MethodDeclaration)names[j].getParent(); ASTNode result= (ASTNode)methodDecl.getStructuralProperty(MethodDeclaration.RETURN_TYPE2_PROPERTY); if (isRawTypeReference(result)) return result; } } return null; }
ASTNode[] sameNodes= LinkedNodeFinder.findByNode(root, nameNode);
ASTNode[] sameNodes= LinkedNodeFinder.findByNode(root, nameNode);
ASTNode[] sameNodes= LinkedNodeFinder.findByNode(root, nameNode);