Search in sources :

Example 1 with ReconcileAnnotationKey

use of org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey 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 ReconcileAnnotationKey

use of org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey 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

ArrayList (java.util.ArrayList)2 List (java.util.List)2 ReconcileAnnotationKey (org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey)2 TemporaryAnnotation (org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation)2 Iterator (java.util.Iterator)1 Position (org.eclipse.jface.text.Position)1 IReconcileResult (org.eclipse.jface.text.reconciler.IReconcileResult)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 IAnnotationModelExtension2 (org.eclipse.jface.text.source.IAnnotationModelExtension2)1 IReconcileAnnotationKey (org.eclipse.wst.sse.ui.internal.reconcile.IReconcileAnnotationKey)1 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)1