Search in sources :

Example 1 with TemporaryAnnotation

use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.

the class ReconcileStepForValidator method createAnnotations.

protected IReconcileResult[] createAnnotations(AnnotationInfo[] infos) {
    List annotations = new ArrayList();
    for (int i = 0; i < infos.length; i++) {
        AnnotationInfo info = infos[i];
        IMessage validationMessage = info.getMessage();
        int offset = validationMessage.getOffset();
        if (offset < 0)
            continue;
        String messageText = null;
        try {
            messageText = validationMessage.getText(validationMessage.getClass().getClassLoader());
        } catch (Exception t) {
            // $NON-NLS-1$
            Logger.logException("exception reporting message from validator", t);
            continue;
        }
        String type = getSeverity(validationMessage);
        // this position seems like it would be possibly be the wrong
        // length
        int length = validationMessage.getLength();
        if (length >= 0) {
            Position p = new Position(offset, length);
            ReconcileAnnotationKey key = createKey(getPartitionType(getDocument(), offset), getScope());
            // create an annotation w/ problem ID and fix info
            TemporaryAnnotation annotation = new TemporaryAnnotation(p, type, messageText, key);
            Object extraInfo = info.getAdditionalFixInfo();
            // add quick fix information
            if (extraInfo == null) {
                extraInfo = validationMessage.getAttribute(QUICKASSISTPROCESSOR);
            }
            annotation.setAdditionalFixInfo(extraInfo);
            annotation.setAttributes(validationMessage.getAttributes());
            annotations.add(annotation);
        }
    }
    return (IReconcileResult[]) annotations.toArray(new IReconcileResult[annotations.size()]);
}
Also used : Position(org.eclipse.jface.text.Position) IReconcileResult(org.eclipse.jface.text.reconciler.IReconcileResult) IReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey) ReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)

Example 2 with TemporaryAnnotation

use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.

the class SourceValidationQuickAssistProcessor method computeQuickAssistProposals.

public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext quickAssistContext) {
    ISourceViewer viewer = quickAssistContext.getSourceViewer();
    int documentOffset = quickAssistContext.getOffset();
    int length = viewer != null ? viewer.getSelectedRange().y : 0;
    IAnnotationModel model = viewer.getAnnotationModel();
    if (model == null)
        return null;
    List allProposals = new ArrayList();
    if (model instanceof IAnnotationModelExtension2) {
        Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
        while (iter.hasNext()) {
            List processors = new ArrayList();
            Annotation anno = (Annotation) iter.next();
            if (canFix(anno)) {
                // fix processor attached to it
                if (anno instanceof TemporaryAnnotation) {
                    Object o = ((TemporaryAnnotation) anno).getAdditionalFixInfo();
                    if (o instanceof IQuickAssistProcessor) {
                        processors.add(o);
                    }
                }
                // get all relevant quick fixes for this annotation
                QuickFixRegistry registry = QuickFixRegistry.getInstance();
                processors.addAll(Arrays.asList(registry.getQuickFixProcessors(anno)));
                // set up context
                Map attributes = null;
                if (anno instanceof TemporaryAnnotation) {
                    attributes = ((TemporaryAnnotation) anno).getAttributes();
                }
                Position pos = model.getPosition(anno);
                StructuredTextInvocationContext sseContext = new StructuredTextInvocationContext(viewer, pos.getOffset(), pos.getLength(), attributes);
                // call each processor
                for (int i = 0; i < processors.size(); ++i) {
                    List proposals = new ArrayList();
                    collectProposals((IQuickAssistProcessor) processors.get(i), anno, sseContext, proposals);
                    if (proposals.size() > 0) {
                        allProposals.addAll(proposals);
                    }
                }
            }
        }
    }
    if (allProposals.isEmpty())
        return null;
    return (ICompletionProposal[]) allProposals.toArray(new ICompletionProposal[allProposals.size()]);
}
Also used : 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) IQuickAssistProcessor(org.eclipse.jface.text.quickassist.IQuickAssistProcessor) IAnnotationModelExtension2(org.eclipse.jface.text.source.IAnnotationModelExtension2) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) Map(java.util.Map) StructuredTextInvocationContext(org.eclipse.wst.sse.ui.StructuredTextInvocationContext)

Example 3 with TemporaryAnnotation

use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.

the class AnnotationQuery method performQuery.

/**
 * Performs a query against the given annotation.
 * <p>
 * Returns a <code>AnnotationQueryResult</code> if the marker is
 * appropriate for this query (correct type and has all of the query
 * attributes), otherwise <code>null</code> is returned.
 *
 * @param annotation
 *            the annotation to perform the query against
 * @return a annotation query result or <code>null</code>
 */
public AnnotationQueryResult performQuery(Annotation anno) {
    if (!(anno instanceof TemporaryAnnotation))
        return null;
    Map annoAttributes = ((TemporaryAnnotation) anno).getAttributes();
    /*
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=243660
		 * 
		 * May be null if the original validation IMessage contained no
		 * attributes or this annotation was not based on a validation
		 * IMessage
		 */
    if (annoAttributes == null) {
        return null;
    }
    // Check type
    if (type != null) {
        // $NON-NLS-1$;
        String problemType = (String) annoAttributes.get("problemType");
        if (!type.equals(problemType))
            return null;
    }
    String[] values = new String[attributes.length];
    for (int i = 0; i < attributes.length; i++) {
        Object value = annoAttributes.get(attributes[i]);
        if (value == null) {
            return null;
        }
        values[i] = value.toString();
    }
    // Create and return the result
    return new AnnotationQueryResult(values);
}
Also used : TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) Map(java.util.Map)

Example 4 with TemporaryAnnotation

use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.

the class HTMLAttributeValidationQuickFixProcessor method computeQuickAssistProposals.

/*
	 * @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#computeQuickAssistProposals(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
	 */
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
    ISourceViewer viewer = invocationContext.getSourceViewer();
    int documentOffset = invocationContext.getOffset();
    int length = viewer != null ? viewer.getSelectedRange().y : 0;
    IAnnotationModel model = viewer.getAnnotationModel();
    if (model == null)
        return null;
    List proposals = new ArrayList();
    if (model instanceof IAnnotationModelExtension2) {
        Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
        while (iter.hasNext()) {
            Annotation anno = (Annotation) iter.next();
            if (canFix(anno)) {
                int offset = -1;
                if (anno instanceof TemporaryAnnotation) {
                    offset = ((TemporaryAnnotation) anno).getPosition().getOffset();
                } else if (anno instanceof MarkerAnnotation) {
                    offset = ((MarkerAnnotation) anno).getMarker().getAttribute(IMarker.CHAR_START, -1);
                }
                if (offset == -1)
                    continue;
                IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
                if (!(node instanceof Element))
                    continue;
                Object adapter = (node instanceof IAdaptable ? ((IAdaptable) node).getAdapter(IResource.class) : null);
                IProject project = (adapter instanceof IResource ? ((IResource) adapter).getProject() : null);
                IScopeContext[] fLookupOrder = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
                if (project != null) {
                    ProjectScope projectScope = new ProjectScope(project);
                    if (projectScope.getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false))
                        fLookupOrder = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
                }
                boolean ignore = fPreferenceService.getBoolean(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES, HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES_DEFAULT, fLookupOrder);
                String ignoreList = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE_DEFAULT, fLookupOrder);
                Set result = new HashSet();
                if (ignoreList.trim().length() > 0) {
                    // $NON-NLS-1$
                    String[] names = ignoreList.split(",");
                    for (int i = 0; names != null && i < names.length; i++) {
                        String name = names[i] == null ? null : names[i].trim();
                        if (name != null && name.length() > 0)
                            result.add(name.toLowerCase());
                    }
                }
                String name = getAttributeName(node, offset);
                if (name == null)
                    continue;
                // If ignore == false. then show a quick fix anyway (due to allow to turn 'ignore' option on)
                if (!ignore || shouldShowQuickFix(result, name.toLowerCase())) {
                    IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(name.toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAttribute, name), HTMLUIMessages.DoNotValidateAttributeAddInfo, node);
                    if (!proposals.contains(p))
                        proposals.add(p);
                }
                int dashIndex = name.indexOf('-');
                while (dashIndex != -1) {
                    StringBuffer namePattern = new StringBuffer(name.substring(0, dashIndex + 1)).append('*');
                    // a more common pattern is already created
                    if (ignore && result.contains(namePattern.toString().toLowerCase()))
                        break;
                    IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(namePattern.toString().toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAllAttributes, namePattern.toString()), HTMLUIMessages.DoNotValidateAllAttributesAddInfo, node);
                    if (!proposals.contains(p))
                        proposals.add(p);
                    dashIndex = name.indexOf('-', dashIndex + 1);
                }
            }
        }
    }
    if (proposals.isEmpty())
        return null;
    return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IAdaptable(org.eclipse.core.runtime.IAdaptable) HashSet(java.util.HashSet) Set(java.util.Set) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) Annotation(org.eclipse.jface.text.source.Annotation) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IProject(org.eclipse.core.resources.IProject) IAnnotationModelExtension2(org.eclipse.jface.text.source.IAnnotationModelExtension2) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IResource(org.eclipse.core.resources.IResource)

Example 5 with TemporaryAnnotation

use of org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation in project webtools.sourceediting by eclipse.

the class SpellcheckStrategy method getSpellingAnnotationsToRemove.

private TemporaryAnnotation[] getSpellingAnnotationsToRemove(IRegion region) {
    List toRemove = new ArrayList();
    IAnnotationModel annotationModel = getAnnotationModel();
    // can be null when closing the editor
    if (annotationModel != null) {
        Iterator i = null;
        boolean annotationOverlaps = false;
        if (annotationModel instanceof IAnnotationModelExtension2) {
            i = ((IAnnotationModelExtension2) annotationModel).getAnnotationIterator(region.getOffset(), region.getLength(), true, true);
            annotationOverlaps = true;
        } else {
            i = annotationModel.getAnnotationIterator();
        }
        while (i.hasNext()) {
            Object obj = i.next();
            if (!(obj instanceof TemporaryAnnotation))
                continue;
            TemporaryAnnotation annotation = (TemporaryAnnotation) obj;
            ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
            // partition type
            if (key != null && key.equals(fReconcileAnnotationKey)) {
                if (key.getScope() == ReconcileAnnotationKey.PARTIAL && (annotationOverlaps || annotation.getPosition().overlapsWith(region.getOffset(), region.getLength()))) {
                    toRemove.add(annotation);
                } else if (key.getScope() == ReconcileAnnotationKey.TOTAL) {
                    toRemove.add(annotation);
                }
            }
        }
    }
    return (TemporaryAnnotation[]) toRemove.toArray(new TemporaryAnnotation[toRemove.size()]);
}
Also used : IAnnotationModelExtension2(org.eclipse.jface.text.source.IAnnotationModelExtension2) ReconcileAnnotationKey(org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)

Aggregations

TemporaryAnnotation (org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)13 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Iterator (java.util.Iterator)5 Annotation (org.eclipse.jface.text.source.Annotation)5 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)5 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)5 IResource (org.eclipse.core.resources.IResource)4 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)4 IAnnotationModelExtension2 (org.eclipse.jface.text.source.IAnnotationModelExtension2)4 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)4 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Set (java.util.Set)3 Position (org.eclipse.jface.text.Position)3 IMarker (org.eclipse.core.resources.IMarker)2 IProject (org.eclipse.core.resources.IProject)2 ProjectScope (org.eclipse.core.resources.ProjectScope)2 IAdaptable (org.eclipse.core.runtime.IAdaptable)2 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)2