public static boolean hasCorrections(CompilationUnit cu, ErrorCode problemId, String markerType) { List<ContributedProcessorDescriptor> processors = getCorrectionProcessors(); SafeHasCorrections collector = new SafeHasCorrections(cu, problemId); for (ContributedProcessorDescriptor processorDescriptor : processors) { if (processorDescriptor.canHandleMarkerType(markerType)) { collector.process(processorDescriptor); if (collector.hasCorrections()) { return true; } } } return false; }
private static IProblemLocation[] getHandledProblems( IProblemLocation[] locations, ContributedProcessorDescriptor processor) { // implementation tries to avoid creating a new array boolean allHandled = true; List<IProblemLocation> res = null; for (int i = 0; i < locations.length; i++) { IProblemLocation curr = locations[i]; if (processor.canHandleMarkerType(curr.getMarkerType())) { if (!allHandled) { // first handled problem if (res == null) { res = Lists.newArrayListWithCapacity(locations.length - i); } res.add(curr); } } else if (allHandled) { if (i > 0) { // first non handled problem res = Lists.newArrayListWithCapacity(locations.length - i); for (int k = 0; k < i; k++) { res.add(locations[k]); } } allHandled = false; } } if (allHandled) { return locations; } if (res == null) { return null; } return res.toArray(new IProblemLocation[res.size()]); }
@Override public void safeRun(ContributedProcessorDescriptor desc) throws Exception { IQuickFixProcessor processor = (IQuickFixProcessor) desc.getProcessor(fCu, IQuickFixProcessor.class); if (processor != null && processor.hasCorrections(fCu, fProblemId)) { fHasCorrections = true; } }
@Override public void safeRun(ContributedProcessorDescriptor desc) throws Exception { IQuickAssistProcessor processor = (IQuickAssistProcessor) desc.getProcessor(fContext.getCompilationUnit(), IQuickAssistProcessor.class); if (processor != null && processor.hasAssists(fContext)) { fHasAssists = true; } }
private static List<ContributedProcessorDescriptor> getProcessorDescriptors( String contributionId, boolean testMarkerTypes) { IConfigurationElement[] elements = Platform.getExtensionRegistry() .getConfigurationElementsFor(DartUI.ID_PLUGIN, contributionId); List<ContributedProcessorDescriptor> res = Lists.newArrayList(); for (IConfigurationElement element : elements) { ContributedProcessorDescriptor desc = new ContributedProcessorDescriptor(element, testMarkerTypes); IStatus status = desc.checkSyntax(); if (status.isOK()) { res.add(desc); } else { DartToolsPlugin.log(status); } } return res; }
@Override public void safeRun(ContributedProcessorDescriptor desc) throws Exception { IQuickAssistProcessor curr = (IQuickAssistProcessor) desc.getProcessor(fContext.getCompilationUnit(), IQuickAssistProcessor.class); if (curr != null) { IDartCompletionProposal[] res = curr.getAssists(fContext, fLocations); if (res != null) { for (int k = 0; k < res.length; k++) { fProposals.add(res[k]); } } } }