use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class JavaCorrectionProcessor method collectProposals.
public static IStatus collectProposals(IInvocationContext context, /*IAnnotationModel model, */
List<Problem> annotations, boolean addQuickFixes, boolean addQuickAssists, Collection<IJavaCompletionProposal> proposals) {
ArrayList<ProblemLocation> problems = new ArrayList<>();
// collect problem locations and corrections from marker annotations
for (Problem curr : annotations) {
problems.add(new ProblemLocation(curr));
}
// for (int i= 0; i < annotations.length; i++) {
// Annotation curr= annotations[i];
// ProblemLocation problemLocation= null;
// if (curr instanceof IJavaAnnotation) {
// problemLocation= getProblemLocation((IJavaAnnotation) curr, model);
// if (problemLocation != null) {
// problems.add(problemLocation);
// }
// }
//// if (problemLocation == null && addQuickFixes && curr instanceof SimpleMarkerAnnotation) {
//// collectMarkerProposals((SimpleMarkerAnnotation) curr, proposals);
//// }
// }
MultiStatus resStatus = null;
IProblemLocation[] problemLocations = problems.toArray(new IProblemLocation[problems.size()]);
if (addQuickFixes) {
IStatus status = collectCorrections(context, problemLocations, proposals);
if (!status.isOK()) {
resStatus = new MultiStatus(JavaPlugin.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickfix_message, null);
resStatus.add(status);
}
}
if (addQuickAssists) {
IStatus status = collectAssists(context, problemLocations, proposals);
if (!status.isOK()) {
if (resStatus == null) {
resStatus = new MultiStatus(JavaPlugin.ID_PLUGIN, IStatus.ERROR, CorrectionMessages.JavaCorrectionProcessor_error_quickassist_message, null);
}
resStatus.add(status);
}
}
if (resStatus != null) {
return resStatus;
}
return Status.OK_STATUS;
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class JavaCorrectionProcessor method getHandledProblems.
private static IProblemLocation[] getHandledProblems(IProblemLocation[] locations, ContributedProcessorDescriptor processor) {
// implementation tries to avoid creating a new array
boolean allHandled = true;
ArrayList<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 = new ArrayList<IProblemLocation>(locations.length - i);
}
res.add(curr);
}
} else if (allHandled) {
if (i > 0) {
// first non handled problem
res = new ArrayList<IProblemLocation>(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()]);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class UnimplementedCodeCleanUp method computeNumberOfFixes.
/**
* {@inheritDoc}
*/
@Override
public int computeNumberOfFixes(CompilationUnit compilationUnit) {
if (!isEnabled(CleanUpConstants.ADD_MISSING_METHODES) && !isEnabled(MAKE_TYPE_ABSTRACT))
return 0;
IProblemLocation[] locations = filter(convertProblems(compilationUnit.getProblems()), new int[] { IProblem.AbstractMethodMustBeImplemented, IProblem.EnumConstantMustImplementAbstractMethod });
HashSet<ASTNode> types = new HashSet<ASTNode>();
for (int i = 0; i < locations.length; i++) {
ASTNode type = UnimplementedCodeFix.getSelectedTypeNode(compilationUnit, locations[i]);
if (type != null) {
types.add(type);
}
}
return types.size();
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project che by eclipse.
the class QuickFixProcessor method getCorrections.
/* (non-Javadoc)
* @see IAssistProcessor#getCorrections(org.eclipse.jdt.internal.ui.text.correction.IAssistContext, org.eclipse.jdt.internal.ui.text.correction.IProblemLocation[])
*/
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
if (locations == null || locations.length == 0) {
return null;
}
HashSet<Integer> handledProblems = new HashSet<Integer>(locations.length);
ArrayList<ICommandAccess> resultingCollections = new ArrayList<ICommandAccess>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation curr = locations[i];
Integer id = new Integer(curr.getProblemId());
if (handledProblems.add(id)) {
process(context, curr, resultingCollections);
}
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
use of org.eclipse.jdt.ui.text.java.IProblemLocation in project liferay-ide by liferay.
the class LiferayDependencyQuickFix method getCorrections.
@Override
public IJavaCompletionProposal[] getCorrections(IInvocationContext context, IProblemLocation[] locations) throws CoreException {
if (ListUtil.isEmpty(locations)) {
return null;
}
List<IJavaCompletionProposal> resultingCollections = new ArrayList<>();
for (int i = 0; i < locations.length; i++) {
IProblemLocation curr = locations[i];
List<IJavaCompletionProposal> newProposals = _process(context, curr);
for (IJavaCompletionProposal newProposal : newProposals) {
boolean existed = false;
for (IJavaCompletionProposal existedProposal : resultingCollections) {
if (existedProposal.getDisplayString().equals(newProposal.getDisplayString())) {
existed = true;
}
}
if (existed == false) {
resultingCollections.add(newProposal);
}
}
}
return resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]);
}
Aggregations