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()]); }
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; }