Search in sources :

Example 1 with IQuickFixableAnnotation

use of org.eclipse.jface.text.quickassist.IQuickFixableAnnotation in project liferay-ide by liferay.

the class JSPQuickAssistProcessor method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
    ICompletionProposal[] retval = null;
    List<ICompletionProposal> proposals = new ArrayList<>();
    ISourceViewer sourceViewer = context.getSourceViewer();
    IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
    Iterator<Annotation> annotations = annotationModel.getAnnotationIterator();
    while (annotations.hasNext()) {
        Annotation annotation = annotations.next();
        Position position = annotationModel.getPosition(annotation);
        try {
            IMarker marker = _createTempMarker(annotation);
            int lineNum = sourceViewer.getDocument().getLineOfOffset(position.getOffset()) + 1;
            int currentLineNum = sourceViewer.getDocument().getLineOfOffset(context.getOffset()) + 1;
            if ((marker != null) && (currentLineNum == lineNum)) {
                if (marker.getAttribute(LiferayBaseValidator.MARKER_QUERY_ID, null) != null) {
                    ICompletionProposal[] resolutions = _createFromMarkerResolutions(marker);
                    if (ListUtil.isNotEmpty(resolutions)) {
                        Collections.addAll(proposals, resolutions);
                        if (annotation instanceof IQuickFixableAnnotation) {
                            IQuickFixableAnnotation quick = (IQuickFixableAnnotation) annotation;
                            quick.setQuickFixable(true);
                        }
                    }
                }
            }
        } catch (BadLocationException ble) {
            LiferayXMLSearchUI.logError("Error finding quick assists", ble);
        }
    }
    if (ListUtil.isNotEmpty(proposals)) {
        retval = proposals.toArray(new ICompletionProposal[0]);
    }
    return retval;
}
Also used : IQuickFixableAnnotation(org.eclipse.jface.text.quickassist.IQuickFixableAnnotation) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IQuickFixableAnnotation(org.eclipse.jface.text.quickassist.IQuickFixableAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with IQuickFixableAnnotation

use of org.eclipse.jface.text.quickassist.IQuickFixableAnnotation in project liferay-ide by liferay.

the class AbstractQuickAssistProcessorFromMarkerResolution method computeQuickAssistProposals.

@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
    ICompletionProposal[] retval = null;
    List<ICompletionProposal> proposals = new ArrayList<>();
    ISourceViewer sourceViewer = context.getSourceViewer();
    IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
    Iterator<Annotation> annotations = annotationModel.getAnnotationIterator();
    while (annotations.hasNext()) {
        Annotation annotation = annotations.next();
        Position position = annotationModel.getPosition(annotation);
        try {
            IMarker marker = getMarkerFromAnnotation(annotation);
            int lineNum = sourceViewer.getDocument().getLineOfOffset(position.getOffset()) + 1;
            int currentLineNum = sourceViewer.getDocument().getLineOfOffset(context.getOffset()) + 1;
            if ((marker != null) && (currentLineNum == lineNum)) {
                ICompletionProposal[] resolutions = createFromMarkerResolutions(marker);
                if (ListUtil.isNotEmpty(resolutions)) {
                    Collections.addAll(proposals, resolutions);
                    if (annotation instanceof IQuickFixableAnnotation) {
                        IQuickFixableAnnotation quick = (IQuickFixableAnnotation) annotation;
                        quick.setQuickFixable(true);
                    }
                }
            }
        } catch (BadLocationException ble) {
            LiferayXMLSearchUI.logError("Error finding quick assists", ble);
        }
    }
    if (ListUtil.isNotEmpty(proposals)) {
        retval = proposals.toArray(new ICompletionProposal[0]);
    }
    return retval;
}
Also used : IQuickFixableAnnotation(org.eclipse.jface.text.quickassist.IQuickFixableAnnotation) Position(org.eclipse.jface.text.Position) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IQuickFixableAnnotation(org.eclipse.jface.text.quickassist.IQuickFixableAnnotation) Annotation(org.eclipse.jface.text.source.Annotation) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IMarker(org.eclipse.core.resources.IMarker) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ArrayList (java.util.ArrayList)2 IMarker (org.eclipse.core.resources.IMarker)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 Position (org.eclipse.jface.text.Position)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 IQuickFixableAnnotation (org.eclipse.jface.text.quickassist.IQuickFixableAnnotation)2 Annotation (org.eclipse.jface.text.source.Annotation)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 TemporaryAnnotation (org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)1