private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) { CompilationUnit root= (CompilationUnit) fCallerNode.getRoot(); int offset= fCallerNode.getStartPosition(); Expression best= null; ITypeBinding bestType= null; ScopeAnalyzer analyzer= new ScopeAnalyzer(root); IBinding[] bindings= analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) { IVariableBinding curr= (IVariableBinding) bindings[i]; ITypeBinding type= curr.getType(); if (type != null && canAssign(type, requiredType) && testModifier(curr)) { if (best == null || isMoreSpecific(bestType, type)) { best= ast.newSimpleName(curr.getName()); bestType= type; } addLinkedPositionProposal(key, curr.getName(), null); } } Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, requiredType); if (best == null) { best= defaultExpression; } addLinkedPositionProposal(key, ASTNodes.asString(defaultExpression), null); return best; }
@Override protected ASTRewrite getRewrite() { AST ast= fCallerNode.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ChildListPropertyDescriptor property= getProperty(); for (int i= 0; i < fInsertIndexes.length; i++) { int idx= fInsertIndexes[i]; String key= "newarg_" + i; //$NON-NLS-1$ Expression newArg= evaluateArgumentExpressions(ast, fParamTypes[idx], key); ListRewrite listRewriter= rewrite.getListRewrite(fCallerNode, property); listRewriter.insertAt(newArg, idx, null); addLinkedPosition(rewrite.track(newArg), i == 0, key); } return rewrite; }
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addarguments_description, arg); AddArgumentCorrectionProposal proposal= new AddArgumentCorrectionProposal(label, context.getCompilationUnit(), invocationNode, indexSkipped, paramTypes, IProposalRelevance.ADD_ARGUMENTS); proposal.setImage(JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD)); proposals.add(proposal);
private Expression evaluateArgumentExpressions(AST ast, ITypeBinding requiredType, String key) { CompilationUnit root= (CompilationUnit) fCallerNode.getRoot(); int offset= fCallerNode.getStartPosition(); Expression best= null; ITypeBinding bestType= null; ScopeAnalyzer analyzer= new ScopeAnalyzer(root); IBinding[] bindings= analyzer.getDeclarationsInScope(offset, ScopeAnalyzer.VARIABLES); for (int i= 0; i < bindings.length; i++) { IVariableBinding curr= (IVariableBinding) bindings[i]; ITypeBinding type= curr.getType(); if (type != null && canAssign(type, requiredType) && testModifier(curr)) { if (best == null || isMoreSpecific(bestType, type)) { best= ast.newSimpleName(curr.getName()); bestType= type; } addLinkedPositionProposal(key, curr.getName(), null); } } Expression defaultExpression= ASTNodeFactory.newDefaultExpression(ast, requiredType); if (best == null) { best= defaultExpression; } addLinkedPositionProposal(key, ASTNodes.asString(defaultExpression), null); return best; }
@Override protected ASTRewrite getRewrite() { AST ast= fCallerNode.getAST(); ASTRewrite rewrite= ASTRewrite.create(ast); ChildListPropertyDescriptor property= getProperty(); for (int i= 0; i < fInsertIndexes.length; i++) { int idx= fInsertIndexes[i]; String key= "newarg_" + i; //$NON-NLS-1$ Expression newArg= evaluateArgumentExpressions(ast, fParamTypes[idx], key); ListRewrite listRewriter= rewrite.getListRewrite(fCallerNode, property); listRewriter.insertAt(newArg, idx, null); addLinkedPosition(rewrite.track(newArg), i == 0, key); } return rewrite; }
label= Messages.format(CorrectionMessages.UnresolvedElementsSubProcessor_addarguments_description, arg); AddArgumentCorrectionProposal proposal= new AddArgumentCorrectionProposal(label, context.getCompilationUnit(), invocationNode, indexSkipped, paramTypes, IProposalRelevance.ADD_ARGUMENTS); proposal.setImage(JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD)); proposals.add(proposal);