public static IStatus collectCorrections(IInvocationContext context, IProblemLocation[] locations, Collection proposals) { ContributedProcessorDescriptor[] processors= getCorrectionProcessors(); SafeCorrectionCollector collector= new SafeCorrectionCollector(context, proposals); for (int i= 0; i < processors.length; i++) { ContributedProcessorDescriptor curr= processors[i]; IProblemLocation[] handled= getHandledProblems(locations, curr); if (handled != null) { collector.setProblemLocations(handled); collector.process(curr); } } return collector.getStatus(); }
private static ContributedProcessorDescriptor[] getCorrectionProcessors() { if (fgContributedCorrectionProcessors == null) { fgContributedCorrectionProcessors= getProcessorDescriptors(QUICKFIX_PROCESSOR_CONTRIBUTION_ID, true); } return fgContributedCorrectionProcessors; }
Annotation curr= annotations[i]; if (curr instanceof IJavaAnnotation) { ProblemLocation problemLocation= getProblemLocation((IJavaAnnotation) curr, model); if (problemLocation != null) { problems.add(problemLocation); collectMarkerProposals((SimpleMarkerAnnotation) curr, proposals); IStatus status= collectCorrections(context, problemLocations, proposals); if (!status.isOK()) { resStatus= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickfix_message, null); IStatus status= collectAssists(context, problemLocations, proposals); if (!status.isOK()) { if (resStatus == null) {
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) { AssistContext context= new AssistContext(cu, selection.getOffset(), selection.getLength()); Collection proposals= new ArrayList(10); if (isAssist) { if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) { return getLocalRenameProposal(context); // shortcut for local rename } JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals); } else { try { boolean goToClosest= selection.getLength() == 0; Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest); JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals); } catch (BadLocationException e) { return null; } } for (Iterator iter= proposals.iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof ICommandAccess) { if (id.equals(((ICommandAccess) curr).getCommandId())) { return (ICompletionProposal) curr; } } } return null; }
public static IStatus collectAssists(IInvocationContext context, IProblemLocation[] locations, Collection<IJavaCompletionProposal> proposals) { ContributedProcessorDescriptor[] processors= getAssistProcessors(); SafeAssistCollector collector= new SafeAssistCollector(context, locations, proposals); collector.process(processors); return collector.getStatus(); }
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) { ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation); ICompilationUnit cu= javaAnnotation.getCompilationUnit(); if (cu == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProviderCore.WAIT_ACTIVE_ONLY); if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location)) return NO_PROPOSALS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
public static boolean hasCorrections(ICompilationUnit cu, int problemId, String markerType) { ContributedProcessorDescriptor[] processors= getCorrectionProcessors(); SafeHasCorrections collector= new SafeHasCorrections(cu, problemId); for (int i= 0; i < processors.length; i++) { if (processors[i].canHandleMarkerType(markerType)) { collector.process(processors[i]); if (collector.hasCorrections()) { return true; } } } return false; }
/** * Constructor for JavaCorrectionAssistant. * @param editor the editor */ public JavaCorrectionAssistant(ITextEditor editor) { super(); Assert.isNotNull(editor); fEditor= editor; IQuickAssistProcessor processor; if (editor instanceof ClassFileEditor) processor= new ExternalNullAnnotationQuickAssistProcessor(this); else processor= new JavaCorrectionProcessor(this); setQuickAssistProcessor(processor); enableColoredLabels(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)); setInformationControlCreator(getInformationControlCreator()); addCompletionListener(new ICompletionListener() { @Override public void assistSessionEnded(ContentAssistEvent event) { fIsCompletionActive= false; } @Override public void assistSessionStarted(ContentAssistEvent event) { fIsCompletionActive= true; } @Override public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { } }); }
ProblemLocation problemLocation= null; if (curr instanceof IJavaAnnotation) { problemLocation= getProblemLocation((IJavaAnnotation) curr, model); if (problemLocation != null) { problems.add(problemLocation); collectMarkerProposals((SimpleMarkerAnnotation) curr, proposals); IStatus status= collectCorrections(context, problemLocations, proposals); if (!status.isOK()) { resStatus= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickfix_message, null); IStatus status= collectAssists(context, problemLocations, proposals); if (!status.isOK()) { if (resStatus == null) {
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) { AssistContext context= new AssistContext(cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength()); Collection<IJavaCompletionProposal> proposals= new ArrayList<>(10); if (isAssist) { if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) { return getLocalRenameProposal(context); // shortcut for local rename } JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals); } else { try { boolean goToClosest= selection.getLength() == 0; Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest); JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals); } catch (BadLocationException e) { return null; } } for (Iterator<IJavaCompletionProposal> iter= proposals.iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof ICommandAccess) { if (id.equals(((ICommandAccess) curr).getCommandId())) { return (ICompletionProposal) curr; } } } return null; }
public static boolean hasAssists(IInvocationContext context) { ContributedProcessorDescriptor[] processors= getAssistProcessors(); SafeHasAssist collector= new SafeHasAssist(context); for (int i= 0; i < processors.length; i++) { collector.process(processors[i]); if (collector.hasAssists()) { return true; } } return false; }
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) { ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation); ICompilationUnit cu= javaAnnotation.getCompilationUnit(); if (cu == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProvider.WAIT_ACTIVE_ONLY); if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location)) return NO_PROPOSALS; ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals); Collections.sort(proposals, new CompletionProposalComparator()); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
private ICompletionProposal[] getMarkerAnnotationFixes(MarkerAnnotation markerAnnotation) { if (markerAnnotation.isQuickFixableStateSet() && !markerAnnotation.isQuickFixable()) return NO_PROPOSALS; IMarker marker= markerAnnotation.getMarker(); ICompilationUnit cu= getCompilationUnit(marker); if (cu == null) return NO_PROPOSALS; IEditorInput input= EditorUtility.getEditorInput(cu); if (input == null) return NO_PROPOSALS; IAnnotationModel model= JavaUI.getDocumentProvider().getAnnotationModel(input); if (model == null) return NO_PROPOSALS; ISourceViewer sourceViewer= null; if (viewer instanceof ISourceViewer) sourceViewer= (ISourceViewer) viewer; AssistContext context= new AssistContext(cu, sourceViewer, position.getOffset(), position.getLength()); ArrayList<IJavaCompletionProposal> proposals= new ArrayList<>(); JavaCorrectionProcessor.collectProposals(context, model, new Annotation[] { markerAnnotation }, true, false, proposals); return proposals.toArray(new ICompletionProposal[proposals.size()]); }
public static boolean hasCorrections(ICompilationUnit cu, int problemId, String markerType) { ContributedProcessorDescriptor[] processors= getCorrectionProcessors(); SafeHasCorrections collector= new SafeHasCorrections(cu, problemId); for (int i= 0; i < processors.length; i++) { if (processors[i].canHandleMarkerType(markerType)) { collector.process(processors[i]); if (collector.hasCorrections()) { return true; } } } return false; }
/** * Constructor for JavaCorrectionAssistant. * @param editor the editor */ public JavaCorrectionAssistant(ITextEditor editor) { super(); Assert.isNotNull(editor); fEditor= editor; IQuickAssistProcessor processor; if (editor instanceof ClassFileEditor) processor= new ExternalNullAnnotationQuickAssistProcessor(this); else processor= new JavaCorrectionProcessor(this); setQuickAssistProcessor(processor); enableColoredLabels(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.USE_COLORED_LABELS)); setInformationControlCreator(getInformationControlCreator()); addCompletionListener(new ICompletionListener() { @Override public void assistSessionEnded(ContentAssistEvent event) { fIsCompletionActive= false; } @Override public void assistSessionStarted(ContentAssistEvent event) { fIsCompletionActive= true; } @Override public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { } }); }
ProblemLocation problemLocation= null; if (curr instanceof IJavaAnnotation) { problemLocation= getProblemLocation((IJavaAnnotation) curr, model); if (problemLocation != null) { problems.add(problemLocation); collectMarkerProposals((SimpleMarkerAnnotation) curr, proposals); IStatus status= collectCorrections(context, problemLocations, proposals); if (!status.isOK()) { resStatus= new MultiStatus(JavaUI.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickfix_message, null); IStatus status= collectAssists(context, problemLocations, proposals); if (!status.isOK()) { if (resStatus == null) {
public static IStatus collectCorrections(IInvocationContext context, IProblemLocation[] locations, Collection<IJavaCompletionProposal> proposals) { ContributedProcessorDescriptor[] processors= getCorrectionProcessors(); SafeCorrectionCollector collector= new SafeCorrectionCollector(context, proposals); for (int i= 0; i < processors.length; i++) { ContributedProcessorDescriptor curr= processors[i]; IProblemLocation[] handled= getHandledProblems(locations, curr); if (handled != null) { collector.setProblemLocations(handled); collector.process(curr); } } return collector.getStatus(); }
private ICompletionProposal findCorrection(String id, boolean isAssist, ITextSelection selection, ICompilationUnit cu, IAnnotationModel model) { AssistContext context= new AssistContext(cu, fEditor.getViewer(), fEditor, selection.getOffset(), selection.getLength()); Collection<IJavaCompletionProposal> proposals= new ArrayList<>(10); if (isAssist) { if (id.equals(LinkedNamesAssistProposal.ASSIST_ID)) { return getLocalRenameProposal(context); // shortcut for local rename } JavaCorrectionProcessor.collectAssists(context, new ProblemLocation[0], proposals); } else { try { boolean goToClosest= selection.getLength() == 0; Annotation[] annotations= getAnnotations(selection.getOffset(), goToClosest); JavaCorrectionProcessor.collectProposals(context, model, annotations, true, false, proposals); } catch (BadLocationException e) { return null; } } for (Iterator<IJavaCompletionProposal> iter= proposals.iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof ICommandAccess) { if (id.equals(((ICommandAccess) curr).getCommandId())) { return (ICompletionProposal) curr; } } } return null; }
private static ContributedProcessorDescriptor[] getCorrectionProcessors() { if (fgContributedCorrectionProcessors == null) { fgContributedCorrectionProcessors= getProcessorDescriptors(QUICKFIX_PROCESSOR_CONTRIBUTION_ID, true); } return fgContributedCorrectionProcessors; }