Search in sources :

Example 26 with IProblemLocation

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) MultiStatus(org.eclipse.core.runtime.MultiStatus) Problem(org.eclipse.che.ide.ext.java.shared.dto.Problem) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation)

Example 27 with IProblemLocation

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()]);
}
Also used : ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation)

Example 28 with IProblemLocation

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();
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) HashSet(java.util.HashSet)

Example 29 with IProblemLocation

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()]);
}
Also used : ICommandAccess(org.eclipse.jdt.ui.text.java.correction.ICommandAccess) ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) HashSet(java.util.HashSet)

Example 30 with IProblemLocation

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()]);
}
Also used : ArrayList(java.util.ArrayList) IProblemLocation(org.eclipse.jdt.ui.text.java.IProblemLocation) IJavaCompletionProposal(org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)

Aggregations

IProblemLocation (org.eclipse.jdt.ui.text.java.IProblemLocation)39 ArrayList (java.util.ArrayList)15 ProblemLocation (org.eclipse.jdt.internal.ui.text.correction.ProblemLocation)15 Test (org.junit.Test)10 IProblem (org.eclipse.jdt.core.compiler.IProblem)8 ASTNode (org.eclipse.jdt.core.dom.ASTNode)7 HashSet (java.util.HashSet)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 IJavaCompletionProposal (org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)4 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)2 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)2 SimpleName (org.eclipse.jdt.core.dom.SimpleName)2 ICommandAccess (org.eclipse.jdt.ui.text.java.correction.ICommandAccess)2 ArrayDeque (java.util.ArrayDeque)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 LinkedHashSet (java.util.LinkedHashSet)1