public FixCorrectionProposal(IProposableFix fix, ICleanUp cleanUp, int relevance, Image image, IInvocationContext context) { super(fix.getDisplayString(), context.getCompilationUnit(), null, relevance, image); fFix= fix; fCleanUp= cleanUp; fCompilationUnit= context.getASTRoot(); }
private ICompletionProposal getLocalRenameProposal(IInvocationContext context) { ASTNode node= context.getCoveringNode(); if (node instanceof SimpleName) { return new LinkedNamesAssistProposal(context.getCompilationUnit(), (SimpleName) node); } return null; }
public final Point getSelection(final IDocument document) { return new Point(fContext.getSelectionOffset(), fContext.getSelectionLength()); } }
public static boolean isApplicable(IInvocationContext context) throws CoreException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= SharedASTProviderCore.getAST(unit, SharedASTProviderCore.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection, false); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
public void safeRun(ContributedProcessorDescriptor desc) throws Exception { IQuickAssistProcessor curr= (IQuickAssistProcessor) desc.getProcessor(fContext.getCompilationUnit()); if (curr != null) { IJavaCompletionProposal[] res= curr.getAssists(fContext, fLocations); if (res != null) { for (int k= 0; k < res.length; k++) { fProposals.add(res[k]); } } } } }
public static void getGenerateForLoopProposals(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { ASTNode coveringNode= problem.getCoveringNode(context.getASTRoot()); if (coveringNode != null) { QuickAssistProcessor.getGenerateForLoopProposals(context, coveringNode, null, proposals); } }
@Override public boolean hasAssists(IInvocationContext context) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); IDocument document= getDocument(cu); int offset= context.getSelectionOffset(); int length= context.getSelectionLength(); if (length == 0) { return false; } try { int startLine= document.getLineOfOffset(offset); int endLine= document.getLineOfOffset(offset + length); IRegion region= document.getLineInformation(endLine); return startLine < endLine || length > 0 && offset == region.getOffset() && length == region.getLength(); } catch (BadLocationException e) { return false; } }
private static boolean getMakeVariableDeclarationFinalProposals(IInvocationContext context, Collection<ICommandAccess> resultingCollections) { SelectionAnalyzer analyzer= new SelectionAnalyzer(Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()), false); context.getASTRoot().accept(analyzer); ASTNode[] selectedNodes= analyzer.getSelectedNodes(); if (selectedNodes.length == 0) return false; IProposableFix fix= VariableDeclarationFix.createChangeModifierToFinalFix(context.getASTRoot(), selectedNodes); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpOptions.TRUE); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES, CleanUpOptions.TRUE); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS, CleanUpOptions.TRUE); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS, CleanUpOptions.TRUE); VariableDeclarationCleanUp cleanUp= new VariableDeclarationCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, IProposalRelevance.MAKE_VARIABLE_DECLARATION_FINAL, image, context); resultingCollections.add(proposal); return true; }
private static boolean getRemoveExtraParenthesisProposals(IInvocationContext context, ASTNode covering, ArrayList coveredNodes, Collection resultingCollections) { ArrayList nodes; if ((context.getSelectionLength() == 0) && (covering instanceof ParenthesizedExpression)) { nodes = new ArrayList(); nodes.add(covering); } else { nodes= coveredNodes; } if (nodes.isEmpty()) return false; IFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), (ASTNode[])nodes.toArray(new ASTNode[nodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE); Map options= new Hashtable(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpConstants.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpConstants.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), 1, image, context); resultingCollections.add(proposal); return true; } private static int getExpressionPrecedence(Expression expression) {
@Override public ASTNode getCoveringNode() { return originalContext.getCoveringNode(); }
@Override public int getSelectionOffset() { return originalContext.getSelectionOffset(); }
@Override public int getSelectionLength() { return originalContext.getSelectionLength(); }
@Override public ASTNode getCoveredNode() { return originalContext.getCoveredNode(); }
public static boolean isApplicable(IInvocationContext context) throws CoreException { ICompilationUnit unit= context.getCompilationUnit(); CompilationUnit ast= SharedASTProvider.getAST(unit, SharedASTProvider.WAIT_NO, null); if (ast == null) return true; Selection selection= Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()); SurroundWithAnalyzer analyzer= new SurroundWithAnalyzer(unit, selection, false); context.getASTRoot().accept(analyzer); return analyzer.getStatus().isOK() && analyzer.hasSelectedNodes(); }
@Override public void safeRun(ContributedProcessorDescriptor desc) throws Exception { IQuickFixProcessor curr= (IQuickFixProcessor) desc.getProcessor(fContext.getCompilationUnit(), IQuickFixProcessor.class); if (curr != null) { IJavaCompletionProposal[] res= curr.getCorrections(fContext, fLocations); if (res != null) { for (int k= 0; k < res.length; k++) { fProposals.add(res[k]); } } } } }
public FixCorrectionProposal(IFix fix, ICleanUp cleanUp, int relevance, Image image, IInvocationContext context) { super(fix.getDescription(), fix.getCompilationUnit(), null, relevance, image); fFix= fix; fCleanUp= cleanUp; fCompilationUnit= context.getASTRoot(); }
@Override public boolean hasAssists(IInvocationContext context) throws CoreException { ICompilationUnit cu= context.getCompilationUnit(); IDocument document= getDocument(cu); int offset= context.getSelectionOffset(); int length= context.getSelectionLength(); if (length == 0) { return false; } try { int startLine= document.getLineOfOffset(offset); int endLine= document.getLineOfOffset(offset + length); IRegion region= document.getLineInformation(endLine); return startLine < endLine || length > 0 && offset == region.getOffset() && length == region.getLength(); } catch (BadLocationException e) { return false; } }
private static boolean getMakeVariableDeclarationFinalProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { SelectionAnalyzer analyzer= new SelectionAnalyzer(Selection.createFromStartLength(context.getSelectionOffset(), context.getSelectionLength()), false); context.getASTRoot().accept(analyzer); ASTNode[] selectedNodes= analyzer.getSelectedNodes(); if (selectedNodes.length == 0) return false; IFix fix= VariableDeclarationFix.createChangeModifierToFinalFix(context.getASTRoot(), selectedNodes); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map options= new Hashtable(); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL, CleanUpConstants.TRUE); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_LOCAL_VARIABLES, CleanUpConstants.TRUE); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PARAMETERS, CleanUpConstants.TRUE); options.put(CleanUpConstants.VARIABLE_DECLARATIONS_USE_FINAL_PRIVATE_FIELDS, CleanUpConstants.TRUE); VariableDeclarationCleanUp cleanUp= new VariableDeclarationCleanUp(options); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, cleanUp, 5, image, context); resultingCollections.add(proposal); return true; }
private static boolean getRemoveExtraParenthesesProposals(IInvocationContext context, ASTNode covering, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) { ArrayList<ASTNode> nodes; if (context.getSelectionLength() == 0 && covering instanceof ParenthesizedExpression) { nodes= new ArrayList<>(); nodes.add(covering); } else { nodes= coveredNodes; } if (nodes.isEmpty()) return false; IProposableFix fix= ExpressionsFix.createRemoveUnnecessaryParenthesisFix(context.getASTRoot(), nodes.toArray(new ASTNode[nodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_REMOVE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_NEVER, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.REMOVE_EXTRA_PARENTHESES, image, context); resultingCollections.add(proposal); return true; }
@Override public ASTNode getCoveringNode() { return originalContext.getCoveringNode(); }