org.eclipse.ui.texteditor.spelling.SpellingAnnotation Java Examples

The following examples show how to use org.eclipse.ui.texteditor.spelling.SpellingAnnotation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean canFix(Annotation annotation) {
	if (annotation.isMarkedDeleted())
		return false;

	// non-persisted annotation
	if (annotation instanceof XtextAnnotation) {
		XtextAnnotation a = (XtextAnnotation) annotation;
		return getResolutionProvider().hasResolutionFor(a.getIssueCode());
	}

	// persisted markerAnnotation
	if (annotation instanceof MarkerAnnotation) {
		MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
		if (!markerAnnotation.isQuickFixableStateSet())
			markerAnnotation.setQuickFixable(getResolutionProvider().hasResolutionFor(
					issueUtil.getCode(markerAnnotation)));
		return markerAnnotation.isQuickFixable();
	}

	if (annotation instanceof SpellingAnnotation) {
		return true;
	}

	return false;
}
 
Example #2
Source File: ModulaSpellingHover.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private HoverInfoWithSpellingAnnotation getSpellingHover(ITextViewer textViewer, IRegion hoverRegion) {
    IAnnotationModel model= null;
    if (textViewer instanceof ISourceViewerExtension2) {
        model = ((ISourceViewerExtension2)textViewer).getVisualAnnotationModel();
    } else if (textViewer instanceof SourceViewer) {
        model= ((SourceViewer)textViewer).getAnnotationModel();
    }
    if (model != null) {
        @SuppressWarnings("rawtypes")
        Iterator e= model.getAnnotationIterator();
        while (e.hasNext()) {
            Annotation a= (Annotation) e.next();
            if (a instanceof SpellingAnnotation) {
                Position p= model.getPosition(a);
                if (p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) {
                    return new HoverInfoWithSpellingAnnotation((SpellingAnnotation)a, textViewer, p.getOffset());
                }
            }
        }
    }
    return null;
}
 
Example #3
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
protected List<ICompletionProposal> createQuickfixes(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations) {
   	List<ICompletionProposal> result = Lists.newArrayList();
   	ISourceViewer sourceViewer = invocationContext.getSourceViewer();
	IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
	IXtextDocument xtextDocument = xtextDocumentUtil.getXtextDocument(sourceViewer);
   	for(Annotation annotation : applicableAnnotations) {
		if (annotation instanceof SpellingAnnotation) {
			SpellingProblem spellingProblem = ((SpellingAnnotation) annotation).getSpellingProblem();
			ICompletionProposal[] proposals = spellingProblem.getProposals();
			if (proposals != null) {
				result.addAll(asList(proposals));
			}
		} else {
			final Issue issue = issueUtil.getIssueFromAnnotation(annotation);
			Position pos = annotationModel.getPosition(annotation);
			if (issue != null && pos != null) {
				@SuppressWarnings("deprecation")
				Iterable<IssueResolution> resolutions = getResolutions(issue, xtextDocument);
				if (resolutions.iterator().hasNext()) {
					for (IssueResolution resolution : resolutions) {
						result.add(create(pos, resolution));
					}
				}
			}
		}
	}
   	return result;
   }
 
Example #4
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Check whether the given annotation type is supported, i.e. {@link #canFix(Annotation)} might return {@code true}.
 * This could be made protected in a future release.
 */
private boolean isSupported(Annotation annotation) {
	return !annotation.isMarkedDeleted()
			&& (annotation instanceof XtextAnnotation || annotation instanceof MarkerAnnotation
				|| annotation instanceof SpellingAnnotation);
}
 
Example #5
Source File: TeXSpellingReconcileStrategy.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
public void accept(SpellingProblem problem) {
    fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
Example #6
Source File: HoverInfoWithSpellingAnnotation.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public HoverInfoWithSpellingAnnotation(SpellingAnnotation spellingAnnotation, ITextViewer viewer, int offset) {
    this.fSpellingAnnotation = spellingAnnotation;
    this.fViewer = viewer;
    this.fOffset = offset;
}
 
Example #7
Source File: MultiRegionSpellingReconcileStrategy.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void accept(SpellingProblem problem) {
	fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
Example #8
Source File: PyReconciler.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void accept(SpellingProblem problem) {
    fAddAnnotations
            .put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
Example #9
Source File: PyReconciler.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endCollecting() {

    List<Object> toRemove = new ArrayList<Object>();

    Object fLockObject;
    if (fAnnotationModel instanceof ISynchronizable) {
        fLockObject = ((ISynchronizable) fAnnotationModel).getLockObject();
    } else {
        fLockObject = new Object();
    }

    //let other threads execute before getting the lock on the annotation model
    Thread.yield();

    Thread thread = Thread.currentThread();
    int initiaThreadlPriority = thread.getPriority();
    try {
        //before getting the lock, let's execute with normal priority, to optimize the time that we'll 
        //retain that object locked (the annotation model is used on lots of places, so, retaining the lock
        //on it on a minimum priority thread is not a good thing.
        thread.setPriority(Thread.NORM_PRIORITY);
        Iterator<Annotation> iter;

        synchronized (fLockObject) {
            iter = fAnnotationModel.getAnnotationIterator();
            while (iter.hasNext()) {
                Object n = iter.next();
                if (n instanceof SpellingAnnotation) {
                    toRemove.add(n);
                }
            }
            iter = null;
        }

        Annotation[] annotationsToRemove = toRemove.toArray(new Annotation[toRemove.size()]);

        //let other threads execute before getting the lock (again) on the annotation model
        Thread.yield();
        synchronized (fLockObject) {
            if (fAnnotationModel instanceof IAnnotationModelExtension) {
                ((IAnnotationModelExtension) fAnnotationModel).replaceAnnotations(annotationsToRemove,
                        fAddAnnotations);
            } else {
                for (int i = 0; i < annotationsToRemove.length; i++) {
                    fAnnotationModel.removeAnnotation(annotationsToRemove[i]);
                }
                for (iter = fAddAnnotations.keySet().iterator(); iter.hasNext();) {
                    Annotation annotation = iter.next();
                    fAnnotationModel.addAnnotation(annotation, fAddAnnotations.get(annotation));
                }
            }
        }

    } finally {
        thread.setPriority(initiaThreadlPriority);
    }
    fAddAnnotations = null;
}