/** * @return the AST root */ public CompilationUnit getRoot() { if (!fIsRootResolved) { fIsRootResolved= true; fRoot= (CompilationUnit) (fNode != null ? fNode : fLiteral).getRoot(); } return fRoot; }
/** * @return the AST root */ public CompilationUnit getRoot() { if (!fIsRootResolved) { fIsRootResolved= true; fRoot= (CompilationUnit) (fNode != null ? fNode : fLiteral).getRoot(); } return fRoot; }
/** * @return the AST root */ public CompilationUnit getRoot() { if (!fIsRootResolved) { fIsRootResolved= true; fRoot= (CompilationUnit) (fNode != null ? fNode : fLiteral).getRoot(); } return fRoot; }
/** * 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; }
private static String getExpressionBaseName(Expression expr) { IBinding argBinding= Bindings.resolveExpressionBinding(expr, true); if (argBinding instanceof IVariableBinding) { IJavaProject project= null; ASTNode root= expr.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot(); if (typeRoot != null) project= typeRoot.getJavaProject(); } return StubUtility.getBaseName((IVariableBinding)argBinding, project); } if (expr instanceof SimpleName) return ((SimpleName) expr).getIdentifier(); return null; }
private static String getExpressionBaseName(Expression expr) { IBinding argBinding= Bindings.resolveExpressionBinding(expr, true); if (argBinding instanceof IVariableBinding) { IJavaProject project= null; ASTNode root= expr.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot(); if (typeRoot != null) { project= typeRoot.getJavaProject(); } } return StubUtility.getBaseName((IVariableBinding)argBinding, project); } if (expr instanceof SimpleName) { return ((SimpleName) expr).getIdentifier(); } return null; }
private static String getExpressionBaseName(Expression expr) { IBinding argBinding= Bindings.resolveExpressionBinding(expr, true); if (argBinding instanceof IVariableBinding) { IJavaProject project= null; ASTNode root= expr.getRoot(); if (root instanceof CompilationUnit) { ITypeRoot typeRoot= ((CompilationUnit) root).getTypeRoot(); if (typeRoot != null) project= typeRoot.getJavaProject(); } return StubUtility.getBaseName((IVariableBinding)argBinding, project); } if (expr instanceof SimpleName) return ((SimpleName) expr).getIdentifier(); return null; }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fCurrentStatement.getAST(); createImportRewrite((CompilationUnit) fCurrentExpression.getRoot()); switch (fLoopTypeToGenerate) { case GenerateForLoopAssistProposal.GENERATE_FOREACH: return generateForEachRewrite(ast); case GenerateForLoopAssistProposal.GENERATE_ITERATOR_FOR: return generateIteratorBasedForRewrite(ast); case GenerateForLoopAssistProposal.GENERATE_ITERATE_ARRAY: return generateForRewrite(ast); case GenerateForLoopAssistProposal.GENERATE_ITERATE_LIST: return generateIndexBasedForRewrite(ast); default: return null; } }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fCurrentStatement.getAST(); createImportRewrite((CompilationUnit) fCurrentExpression.getRoot()); switch (fLoopTypeToGenerate) { case GenerateForLoopAssistProposal.GENERATE_FOREACH: return generateForEachRewrite(ast); case GenerateForLoopAssistProposal.GENERATE_ITERATOR_FOR: return generateIteratorBasedForRewrite(ast); case GenerateForLoopAssistProposal.GENERATE_ITERATE_ARRAY: return generateForRewrite(ast); case GenerateForLoopAssistProposal.GENERATE_ITERATE_LIST: return generateIndexBasedForRewrite(ast); default: return null; } }
private SingleVariableDeclaration createParameterDeclaration(String parameterName, VariableDeclarationFragment fragement, Expression arrayAccess, ForStatement statement, ImportRewrite importRewrite, ASTRewrite rewrite, TextEditGroup group, LinkedProposalPositionGroup pg, boolean makeFinal) { CompilationUnit compilationUnit= (CompilationUnit)arrayAccess.getRoot(); AST ast= compilationUnit.getAST(); SingleVariableDeclaration result= ast.newSingleVariableDeclaration(); SimpleName name= ast.newSimpleName(parameterName); pg.addPosition(rewrite.track(name), true); result.setName(name); ITypeBinding arrayTypeBinding= arrayAccess.resolveTypeBinding(); Type type= importType(arrayTypeBinding.getElementType(), statement, importRewrite, compilationUnit); if (arrayTypeBinding.getDimensions() != 1) { type= ast.newArrayType(type, arrayTypeBinding.getDimensions() - 1); } result.setType(type); if (fragement != null) { VariableDeclarationStatement declaration= (VariableDeclarationStatement)fragement.getParent(); ModifierRewrite.create(rewrite, result).copyAllModifiers(declaration, group); } if (makeFinal) { ModifierRewrite.create(rewrite, result).setModifiers(Modifier.FINAL, 0, group); } return result; }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fNodeToCast.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ImportRewrite importRewrite= createImportRewrite((CompilationUnit) fNodeToCast.getRoot()); Type newTypeNode= getNewCastTypeNode(rewrite, importRewrite); if (fNodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) { CastExpression expression= (CastExpression) fNodeToCast; rewrite.replace(expression.getType(), newTypeNode, null); } else { Expression expressionCopy= (Expression) rewrite.createCopyTarget(fNodeToCast); if (needsInnerParantheses(fNodeToCast)) { ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression(expressionCopy); expressionCopy= parenthesizedExpression; } CastExpression castExpression= ast.newCastExpression(); castExpression.setExpression(expressionCopy); castExpression.setType(newTypeNode); ASTNode replacingNode= castExpression; if (needsOuterParantheses(fNodeToCast)) { ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression(castExpression); replacingNode= parenthesizedExpression; } rewrite.replace(fNodeToCast, replacingNode, null); } return rewrite; }
@Override protected ASTRewrite getRewrite() throws CoreException { AST ast= fNodeToCast.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ImportRewrite importRewrite= createImportRewrite((CompilationUnit) fNodeToCast.getRoot()); Type newTypeNode= getNewCastTypeNode(rewrite, importRewrite); if (fNodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) { CastExpression expression= (CastExpression) fNodeToCast; rewrite.replace(expression.getType(), newTypeNode, null); } else { Expression expressionCopy= (Expression) rewrite.createCopyTarget(fNodeToCast); if (needsInnerParantheses(fNodeToCast)) { ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression(expressionCopy); expressionCopy= parenthesizedExpression; } CastExpression castExpression= ast.newCastExpression(); castExpression.setExpression(expressionCopy); castExpression.setType(newTypeNode); ASTNode replacingNode= castExpression; if (needsOuterParantheses(fNodeToCast)) { ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression(castExpression); replacingNode= parenthesizedExpression; } rewrite.replace(fNodeToCast, replacingNode, null); } return rewrite; }
protected ASTRewrite getRewrite() throws CoreException { AST ast= fNodeToCast.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ImportRewrite importRewrite= createImportRewrite((CompilationUnit) fNodeToCast.getRoot()); Type newTypeNode= getNewCastTypeNode(rewrite, importRewrite); if (fNodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) { CastExpression expression= (CastExpression) fNodeToCast; rewrite.replace(expression.getType(), newTypeNode, null); } else { Expression expressionCopy= (Expression) rewrite.createCopyTarget(fNodeToCast); if (needsInnerParantheses(fNodeToCast)) { ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression(expressionCopy); expressionCopy= parenthesizedExpression; } CastExpression castExpression= ast.newCastExpression(); castExpression.setExpression(expressionCopy); castExpression.setType(newTypeNode); ASTNode replacingNode= castExpression; if (needsOuterParantheses(fNodeToCast)) { ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression(); parenthesizedExpression.setExpression(castExpression); replacingNode= parenthesizedExpression; } rewrite.replace(fNodeToCast, replacingNode, null); } return rewrite; }
private SingleVariableDeclaration createParameterDeclaration(String parameterName, VariableDeclarationFragment fragement, Expression arrayAccess, ForStatement statement, ImportRewrite importRewrite, ASTRewrite rewrite, TextEditGroup group, LinkedProposalPositionGroup pg, boolean makeFinal) { CompilationUnit compilationUnit= (CompilationUnit)arrayAccess.getRoot(); AST ast= compilationUnit.getAST(); SingleVariableDeclaration result= ast.newSingleVariableDeclaration(); SimpleName name= ast.newSimpleName(parameterName); pg.addPosition(rewrite.track(name), true); result.setName(name); ITypeBinding arrayTypeBinding= arrayAccess.resolveTypeBinding(); Type type= importType(arrayTypeBinding.getElementType(), statement, importRewrite, compilationUnit); if (arrayTypeBinding.getDimensions() != 1) { type= ast.newArrayType(type, arrayTypeBinding.getDimensions() - 1); } result.setType(type); if (fragement != null) { VariableDeclarationStatement declaration= (VariableDeclarationStatement)fragement.getParent(); ModifierRewrite.create(rewrite, result).copyAllModifiers(declaration, group); } if (makeFinal && (fragement == null || ASTNodes.findModifierNode(Modifier.FINAL, ASTNodes.getModifiers(fragement)) == null)) { ModifierRewrite.create(rewrite, result).setModifiers(Modifier.FINAL, 0, group); } return result; }
private SingleVariableDeclaration createParameterDeclaration(String parameterName, VariableDeclarationFragment fragement, Expression arrayAccess, ForStatement statement, ImportRewrite importRewrite, ASTRewrite rewrite, TextEditGroup group, LinkedProposalPositionGroup pg, boolean makeFinal) { CompilationUnit compilationUnit= (CompilationUnit)arrayAccess.getRoot(); AST ast= compilationUnit.getAST(); SingleVariableDeclaration result= ast.newSingleVariableDeclaration(); SimpleName name= ast.newSimpleName(parameterName); pg.addPosition(rewrite.track(name), true); result.setName(name); ITypeBinding arrayTypeBinding= arrayAccess.resolveTypeBinding(); Type type= importType(arrayTypeBinding.getElementType(), statement, importRewrite, compilationUnit); if (arrayTypeBinding.getDimensions() != 1) { type= ast.newArrayType(type, arrayTypeBinding.getDimensions() - 1); } result.setType(type); if (fragement != null) { VariableDeclarationStatement declaration= (VariableDeclarationStatement)fragement.getParent(); ModifierRewrite.create(rewrite, result).copyAllModifiers(declaration, group); } if (makeFinal && (fragement == null || ASTNodes.findModifierNode(Modifier.FINAL, ASTNodes.getModifiers(fragement)) == null)) { ModifierRewrite.create(rewrite, result).setModifiers(Modifier.FINAL, 0, group); } return result; }
importRewrite= proposal.createImportRewrite((CompilationUnit) invocation.getRoot());
importRewrite= proposal.createImportRewrite((CompilationUnit) invocation.getRoot());
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) { AST ast= rewrite.getAST(); ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) { AST ast= rewrite.getAST(); ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);