public static String[] getUsedVariableNames(ASTNode node) { CompilationUnit root= (CompilationUnit) node.getRoot(); Collection res= (new ScopeAnalyzer(root)).getUsedVariableNames(node.getStartPosition(), node.getLength()); return (String[]) res.toArray(new String[res.size()]); }
public static String[] getUsedVariableNames(ASTNode node) { CompilationUnit root= (CompilationUnit) node.getRoot(); Collection<String> res= (new ScopeAnalyzer(root)).getUsedVariableNames(node.getStartPosition(), node.getLength()); return res.toArray(new String[res.size()]); }
public static String[] getUsedVariableNames(ASTNode node) { CompilationUnit root= (CompilationUnit) node.getRoot(); Collection<String> res= (new ScopeAnalyzer(root)).getUsedVariableNames(node.getStartPosition(), node.getLength()); return res.toArray(new String[res.size()]); }
String proposeLocalName(SimpleName fieldName, CompilationUnit root, IJavaProject javaProject) { // don't propose names that are already in use: Collection<String> variableNames= new ScopeAnalyzer(root).getUsedVariableNames(this.enclosingMethod.getStartPosition(), this.enclosingMethod.getLength()); String[] names = new String[variableNames.size()+1]; variableNames.toArray(names); // don't propose the field name itself, either: String identifier= fieldName.getIdentifier(); names[names.length-1] = identifier; return StubUtility.getLocalNameSuggestions(javaProject, identifier, 0, names)[0]; }
private String[] getExcludedVariableNames() { if (fExcludedVariableNames == null) { try { IExpressionFragment expr = getSelectedExpression(); Collection<String> takenNames = new ScopeAnalyzer(fCuRewrite.getRoot()).getUsedVariableNames(expr.getStartPosition(), expr.getLength()); fExcludedVariableNames = takenNames.toArray(new String[takenNames.size()]); } catch (JavaModelException e) { fExcludedVariableNames = new String[0]; } } return fExcludedVariableNames; }
private String[] getExcludedVariableNames() { if (fExcludedVariableNames == null) { try { IExpressionFragment expr= getSelectedExpression(); Collection<String> takenNames= new ScopeAnalyzer(fCuRewrite.getRoot()).getUsedVariableNames(expr.getStartPosition(), expr.getLength()); fExcludedVariableNames= takenNames.toArray(new String[takenNames.size()]); } catch (JavaModelException e) { fExcludedVariableNames= new String[0]; } } return fExcludedVariableNames; }
private String[] getExcludedVariableNames() { if (fExcludedVariableNames == null) { try { IExpressionFragment expr= getSelectedExpression(); Collection<String> takenNames= new ScopeAnalyzer(fCuRewrite.getRoot()).getUsedVariableNames(expr.getStartPosition(), expr.getLength()); fExcludedVariableNames= takenNames.toArray(new String[takenNames.size()]); } catch (JavaModelException e) { fExcludedVariableNames= new String[0]; } } return fExcludedVariableNames; }
protected String[] getUsedVariableNames() { final List results= new ArrayList(); ForStatement forStatement= getForStatement(); CompilationUnit root= (CompilationUnit)forStatement.getRoot(); Collection variableNames= new ScopeAnalyzer(root).getUsedVariableNames(forStatement.getStartPosition(), forStatement.getLength()); results.addAll(variableNames); forStatement.accept(new GenericVisitor() { public boolean visit(SingleVariableDeclaration node) { results.add(node.getName().getIdentifier()); return super.visit(node); } public boolean visit(VariableDeclarationFragment fragment) { results.add(fragment.getName().getIdentifier()); return super.visit(fragment); } }); results.addAll(Arrays.asList(fUsedNames)); return (String[])results.toArray(new String[results.size()]); }
private String[] getExcludedVariableNames() { if (fExcludedVariableNames == null) { try { IExpressionFragment expr= getSelectedExpression(); Collection takenNames= new ScopeAnalyzer(fCuRewrite.getRoot()).getUsedVariableNames(expr.getStartPosition(), expr.getLength()); fExcludedVariableNames= (String[]) takenNames.toArray(new String[takenNames.size()]); } catch (JavaModelException e) { fExcludedVariableNames= new String[0]; } } return fExcludedVariableNames; }
String proposeLocalName(SimpleName fieldName, CompilationUnit root, IJavaProject javaProject) { // don't propose names that are already in use: Collection<String> variableNames= new ScopeAnalyzer(root).getUsedVariableNames(this.enclosingMethod.getStartPosition(), this.enclosingMethod.getLength()); String[] names = new String[variableNames.size()+1]; variableNames.toArray(names); // don't propose the field name itself, either: String identifier= fieldName.getIdentifier(); names[names.length-1] = identifier; return StubUtility.getLocalNameSuggestions(javaProject, identifier, 0, names)[0]; }
protected String[] getUsedVariableNames() { final List<String> results= new ArrayList<>(); ForStatement forStatement= getForStatement(); CompilationUnit root= (CompilationUnit)forStatement.getRoot(); Collection<String> variableNames= new ScopeAnalyzer(root).getUsedVariableNames(forStatement.getStartPosition(), forStatement.getLength()); results.addAll(variableNames); forStatement.accept(new GenericVisitor() { @Override public boolean visit(SingleVariableDeclaration node) { results.add(node.getName().getIdentifier()); return super.visit(node); } @Override public boolean visit(VariableDeclarationFragment fragment) { results.add(fragment.getName().getIdentifier()); return super.visit(fragment); } }); results.addAll(Arrays.asList(fUsedNames)); return results.toArray(new String[results.size()]); }
protected String[] getUsedVariableNames() { final List<String> results= new ArrayList<>(); ForStatement forStatement= getForStatement(); CompilationUnit root= (CompilationUnit)forStatement.getRoot(); Collection<String> variableNames= new ScopeAnalyzer(root).getUsedVariableNames(forStatement.getStartPosition(), forStatement.getLength()); results.addAll(variableNames); forStatement.accept(new GenericVisitor() { @Override public boolean visit(SingleVariableDeclaration node) { results.add(node.getName().getIdentifier()); return super.visit(node); } @Override public boolean visit(VariableDeclarationFragment fragment) { results.add(fragment.getName().getIdentifier()); return super.visit(fragment); } }); results.addAll(Arrays.asList(fUsedNames)); return results.toArray(new String[results.size()]); }
/** * Retrieves name proposals for a fresh local variable. * * @param basename the basename of the proposals * @param excludedName a name that cannot be used for the variable; <code>null</code> if none * @return an array of proposal strings */ private String[] getVariableNameProposals(String basename, String excludedName) { ASTNode surroundingBlock= fCurrentStatement; while ((surroundingBlock= surroundingBlock.getParent()) != null) { if (surroundingBlock instanceof Block) { break; } } Collection<String> localUsedNames= new ScopeAnalyzer((CompilationUnit) fCurrentExpression.getRoot()).getUsedVariableNames(surroundingBlock.getStartPosition(), surroundingBlock.getLength()); if (excludedName != null) { localUsedNames.add(excludedName); } String[] names= StubUtility.getLocalNameSuggestions(getCompilationUnit().getJavaProject(), basename, 0, localUsedNames.toArray(new String[localUsedNames.size()])); return names; }
/** * Retrieves name proposals for a fresh local variable. * * @param basename the basename of the proposals * @param excludedName a name that cannot be used for the variable; <code>null</code> if none * @return an array of proposal strings */ private String[] getVariableNameProposals(String basename, String excludedName) { ASTNode surroundingBlock= fCurrentStatement; while ((surroundingBlock= surroundingBlock.getParent()) != null) { if (surroundingBlock instanceof Block) { break; } } Collection<String> localUsedNames= new ScopeAnalyzer((CompilationUnit) fCurrentExpression.getRoot()).getUsedVariableNames(surroundingBlock.getStartPosition(), surroundingBlock.getLength()); if (excludedName != null) { localUsedNames.add(excludedName); } String[] names= StubUtility.getLocalNameSuggestions(getCompilationUnit().getJavaProject(), basename, 0, localUsedNames.toArray(new String[localUsedNames.size()])); return names; }