Java 类org.eclipse.ui.texteditor.spelling.SpellingAnnotation 实例源码

项目:bts    文件:XtextQuickAssistProcessor.java   
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;
}
项目:bts    文件:XtextQuickAssistProcessor.java   
/**
 * @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.get(sourceViewer);
    for(Annotation annotation : applicableAnnotations) {
        if (annotation instanceof SpellingAnnotation) {
            SpellingProblem spellingProblem = ((SpellingAnnotation) annotation).getSpellingProblem();
            result.addAll(asList(spellingProblem.getProposals()));
        } else {
            final Issue issue = issueUtil.getIssueFromAnnotation(annotation);
            if (issue != null) {
                Iterable<IssueResolution> resolutions = getResolutions(issue, xtextDocument);
                if (resolutions.iterator().hasNext()) {
                    Position pos = annotationModel.getPosition(annotation);
                    for (IssueResolution resolution : resolutions) {
                        result.add(create(pos, resolution));
                    }
                }
            }
        }
    }
    return result;
   }
项目:Eclipse-Postfix-Code-Completion    文件:ProblemHover.java   
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) {
    ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation);
    ICompilationUnit cu= javaAnnotation.getCompilationUnit();
    if (cu == null)
        return NO_PROPOSALS;

    ISourceViewer sourceViewer= null;
    if (viewer instanceof ISourceViewer)
        sourceViewer= (ISourceViewer) viewer;

    IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProvider.WAIT_ACTIVE_ONLY);
    if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location))
        return NO_PROPOSALS;

    ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>();
    JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals);
    Collections.sort(proposals, new CompletionProposalComparator());

    return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ProblemHover.java   
private ICompletionProposal[] getJavaAnnotationFixes(IJavaAnnotation javaAnnotation) {
    ProblemLocation location= new ProblemLocation(position.getOffset(), position.getLength(), javaAnnotation);
    ICompilationUnit cu= javaAnnotation.getCompilationUnit();
    if (cu == null)
        return NO_PROPOSALS;

    ISourceViewer sourceViewer= null;
    if (viewer instanceof ISourceViewer)
        sourceViewer= (ISourceViewer) viewer;

    IInvocationContext context= new AssistContext(cu, sourceViewer, location.getOffset(), location.getLength(), SharedASTProvider.WAIT_ACTIVE_ONLY);
    if (!SpellingAnnotation.TYPE.equals(javaAnnotation.getType()) && !hasProblem(context.getASTRoot().getProblems(), location))
        return NO_PROPOSALS;

    ArrayList<IJavaCompletionProposal> proposals= new ArrayList<IJavaCompletionProposal>();
    JavaCorrectionProcessor.collectCorrections(context, new IProblemLocation[] { location }, proposals);
    Collections.sort(proposals, new CompletionProposalComparator());

    return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
项目:texlipse    文件:TeXSpellingReconcileStrategy.java   
public void accept(SpellingProblem problem) {
    fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
项目:APICloud-Studio    文件:MultiRegionSpellingReconcileStrategy.java   
public void accept(SpellingProblem problem) {
    fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
项目:Pydev    文件:PyReconciler.java   
@Override
public void accept(SpellingProblem problem) {
    fAddAnnotations
            .put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
项目:Pydev    文件:PyReconciler.java   
@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;
}