public static void addUnqualifiedFieldAccessProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { IProposableFix fix= CodeStyleFix.createAddFieldQualifierFix(context.getASTRoot(), problem); if (fix != null) { Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new HashMap<>(); options.put(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS, CleanUpOptions.TRUE); options.put(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new CodeStyleCleanUp(options), IProposalRelevance.ADD_FIELD_QUALIFIER, image, context); proposal.setCommandId(ADD_FIELD_QUALIFICATION_ID); proposals.add(proposal); } }
@Override public String getStatusMessage() { if (fCleanUp == null) return null; int count= computeNumberOfFixesForCleanUp(fCleanUp); if (count == -1) { return CorrectionMessages.FixCorrectionProposal_HitCtrlEnter_description; } else if (count < 2) { return null; } else { return Messages.format(CorrectionMessages.FixCorrectionProposal_hitCtrlEnter_variable_description, Integer.valueOf(count)); } }
final ICleanUp cleanUp= fix.getCleanUp(); if (!(cleanUp instanceof IMultiFix)) return NO_MARKERS;
public static void addOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { IProposableFix fix= Java50Fix.createAddOverrideAnnotationFix(context.getASTRoot(), problem); if (fix != null) { Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE); options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE); options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.ADD_OVERRIDE_ANNOTATION, image, context); proposals.add(proposal); } }
if (element instanceof FixCorrectionProposal) { FixCorrectionProposal fixProp= (FixCorrectionProposal)element; if (RAW_TYPE_REFERENCE_ID.equals(fixProp.getCommandId())) { return; Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.RAW_TYPE_REFERENCE, image, context); proposal.setCommandId(RAW_TYPE_REFERENCE_ID); proposals.add(proposal);
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { if ((stateMask & SWT.MODIFIER_MASK) == SWT.CONTROL && fCleanUp != null) { CleanUpRefactoring refactoring= new CleanUpRefactoring(); refactoring.addCompilationUnit(getCompilationUnit()); refactoring.addCleanUp(fCleanUp); refactoring.setLeaveFilesDirty(true); int stopSeverity= RefactoringCore.getConditionCheckingFailedSeverity(); Shell shell= JavaPlugin.getActiveWorkbenchShell(); IRunnableContext context= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); RefactoringExecutionHelper executer= new RefactoringExecutionHelper(refactoring, stopSeverity, RefactoringSaveHelper.SAVE_NOTHING, shell, context); try { executer.perform(true, true); } catch (InterruptedException e) { } catch (InvocationTargetException e) { JavaPlugin.log(e); } return; } apply(viewer.getDocument()); }
int count= proposal.computeNumberOfFixesForCleanUp(proposal.getCleanUp()); if (count > 1) { list.add(createCompletionProposalLink(composite, proposals[i], count));
@Override public Object getAdditionalProposalInfo(IProgressMonitor monitor) { StringBuilder result= new StringBuilder(); IStatus status= getFixStatus(); if (status != null && !status.isOK()) { result.append("<b>"); //$NON-NLS-1$ if (status.getSeverity() == IStatus.WARNING) { result.append(CorrectionMessages.FixCorrectionProposal_WarningAdditionalProposalInfo); } else if (status.getSeverity() == IStatus.ERROR) { result.append(CorrectionMessages.FixCorrectionProposal_ErrorAdditionalProposalInfo); } result.append("</b>"); //$NON-NLS-1$ result.append(status.getMessage()); result.append("<br><br>"); //$NON-NLS-1$ } String info= fFix.getAdditionalProposalInfo(); if (info != null) { result.append(info); } else { result.append(super.getAdditionalProposalInfo(monitor)); } return result.toString(); }
@Override protected TextChange createTextChange() throws CoreException { CompilationUnitChange createChange= fFix.createChange(null); createChange.setSaveMode(TextFileChange.LEAVE_DIRTY); if (fFix instanceof ILinkedFix) { setLinkedProposalModel(((ILinkedFix) fFix).getLinkedPositions()); } return createChange; }
@Override public void run(IMarker[] markers, IProgressMonitor monitor) { if (markers.length == 1) { run(markers[0]); return; } if (!(fProposal instanceof FixCorrectionProposal)) return; if (monitor == null) monitor= new NullProgressMonitor(); try { MultiFixTarget[] problems= getCleanUpTargets(markers); ((FixCorrectionProposal)fProposal).resolve(problems, monitor); IEditorPart part= EditorUtility.isOpenInEditor(fCompilationUnit); if (part instanceof ITextEditor) { ((ITextEditor) part).selectAndReveal(fOffset, fLength); part.setFocus(); } } catch (CoreException e) { JavaPlugin.log(e); } finally { monitor.done(); } }
public static void addOverrideAnnotationProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { IProposableFix fix= Java50Fix.createAddOverrideAnnotationFix(context.getASTRoot(), problem); if (fix != null) { Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS, CleanUpOptions.TRUE); options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE, CleanUpOptions.TRUE); options.put(CleanUpConstants.ADD_MISSING_ANNOTATIONS_OVERRIDE_FOR_INTERFACE_METHOD_IMPLEMENTATION, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.ADD_OVERRIDE_ANNOTATION, image, context); proposals.add(proposal); } }
if (element instanceof FixCorrectionProposal) { FixCorrectionProposal fixProp= (FixCorrectionProposal)element; if (RAW_TYPE_REFERENCE_ID.equals(fixProp.getCommandId())) { return; Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.VARIABLE_DECLARATION_USE_TYPE_ARGUMENTS_FOR_RAW_TYPE_REFERENCES, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new Java50CleanUp(options), IProposalRelevance.RAW_TYPE_REFERENCE, image, context); proposal.setCommandId(RAW_TYPE_REFERENCE_ID); proposals.add(proposal);
@Override public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { if ((stateMask & SWT.MODIFIER_MASK) == SWT.CONTROL && fCleanUp != null) { CleanUpRefactoring refactoring= new CleanUpRefactoring(); refactoring.addCompilationUnit(getCompilationUnit()); refactoring.addCleanUp(fCleanUp); refactoring.setLeaveFilesDirty(true); int stopSeverity= RefactoringCore.getConditionCheckingFailedSeverity(); Shell shell= JavaPlugin.getActiveWorkbenchShell(); IRunnableContext context= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); RefactoringExecutionHelper executer= new RefactoringExecutionHelper(refactoring, stopSeverity, RefactoringSaveHelper.SAVE_NOTHING, shell, context); try { executer.perform(true, true); } catch (InterruptedException e) { } catch (InvocationTargetException e) { JavaPlugin.log(e); } return; } apply(viewer.getDocument()); }
int count= proposal.computeNumberOfFixesForCleanUp(proposal.getCleanUp()); if (count > 1) { list.add(createCompletionProposalLink(composite, proposals[i], count));
@Override public Object getAdditionalProposalInfo(IProgressMonitor monitor) { StringBuffer result= new StringBuffer(); IStatus status= getFixStatus(); if (status != null && !status.isOK()) { result.append("<b>"); //$NON-NLS-1$ if (status.getSeverity() == IStatus.WARNING) { result.append(CorrectionMessages.FixCorrectionProposal_WarningAdditionalProposalInfo); } else if (status.getSeverity() == IStatus.ERROR) { result.append(CorrectionMessages.FixCorrectionProposal_ErrorAdditionalProposalInfo); } result.append("</b>"); //$NON-NLS-1$ result.append(status.getMessage()); result.append("<br><br>"); //$NON-NLS-1$ } String info= fFix.getAdditionalProposalInfo(); if (info != null) { result.append(info); } else { result.append(super.getAdditionalProposalInfo(monitor)); } return result.toString(); }
@Override protected TextChange createTextChange() throws CoreException { CompilationUnitChange createChange= fFix.createChange(null); createChange.setSaveMode(TextFileChange.LEAVE_DIRTY); if (fFix instanceof ILinkedFix) { setLinkedProposalModel(((ILinkedFix) fFix).getLinkedPositions()); } return createChange; }
@Override public void run(IMarker[] markers, IProgressMonitor monitor) { if (markers.length == 1) { run(markers[0]); return; } if (!(fProposal instanceof FixCorrectionProposal) && !(fProposal instanceof CreatePackageInfoWithDefaultNullnessProposal)) return; if (monitor == null) monitor= new NullProgressMonitor(); try { MultiFixTarget[] problems= getCleanUpTargets(markers); if (fProposal instanceof CreatePackageInfoWithDefaultNullnessProposal) { ((CreatePackageInfoWithDefaultNullnessProposal) fProposal).resolve(problems, monitor); return; } ((FixCorrectionProposal)fProposal).resolve(problems, monitor); IEditorPart part= EditorUtility.isOpenInEditor(fCompilationUnit); if (part instanceof ITextEditor) { ((ITextEditor) part).selectAndReveal(fOffset, fLength); part.setFocus(); } } catch (CoreException e) { JavaPlugin.log(e); } finally { monitor.done(); } }
public static void addUnqualifiedFieldAccessProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) { IProposableFix fix= CodeStyleFix.createAddFieldQualifierFix(context.getASTRoot(), problem); if (fix != null) { Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); Map<String, String> options= new HashMap<>(); options.put(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS, CleanUpOptions.TRUE); options.put(CleanUpConstants.MEMBER_ACCESSES_NON_STATIC_FIELD_USE_THIS_ALWAYS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new CodeStyleCleanUp(options), IProposalRelevance.ADD_FIELD_QUALIFIER, image, context); proposal.setCommandId(ADD_FIELD_QUALIFICATION_ID); proposals.add(proposal); } }
private static boolean getAddParanoidalParenthesesProposals(IInvocationContext context, ArrayList<ASTNode> coveredNodes, Collection<ICommandAccess> resultingCollections) { IProposableFix fix= ExpressionsFix.createAddParanoidalParenthesisFix(context.getASTRoot(), coveredNodes.toArray(new ASTNode[coveredNodes.size()])); if (fix == null) return false; if (resultingCollections == null) return true; // add correction proposal Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CAST); Map<String, String> options= new Hashtable<>(); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES, CleanUpOptions.TRUE); options.put(CleanUpConstants.EXPRESSIONS_USE_PARENTHESES_ALWAYS, CleanUpOptions.TRUE); FixCorrectionProposal proposal= new FixCorrectionProposal(fix, new ExpressionsCleanUp(options), IProposalRelevance.ADD_PARANOIDAL_PARENTHESES, image, context); resultingCollections.add(proposal); return true; }
@Override public int getRelevance() { IStatus status= getFixStatus(); if (status != null && !status.isOK()) { return super.getRelevance() - 100; } else { return super.getRelevance(); } }