Search in sources :

Example 61 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.

the class AbstractStructuredTextReconcilingStrategy method getAnnotationsToRemove.

protected TemporaryAnnotation[] getAnnotationsToRemove(DirtyRegion dr, List stepsRun) {
    List remove = new ArrayList();
    IAnnotationModel annotationModel = getAnnotationModel();
    // can be null when closing the editor
    if (getAnnotationModel() != null) {
        // clear validator annotations
        getMarkerAnnotations().clear();
        Iterator i = annotationModel.getAnnotationIterator();
        while (i.hasNext()) {
            Object obj = i.next();
            // if it is save it for comparision later (to "gray" icons)
            if (obj instanceof StructuredMarkerAnnotation) {
                StructuredMarkerAnnotation sma = (StructuredMarkerAnnotation) obj;
                if (sma.getAnnotationType() == TemporaryAnnotation.ANNOT_ERROR || sma.getAnnotationType() == TemporaryAnnotation.ANNOT_WARNING)
                    fMarkerAnnotations.add(sma);
            }
            if (!(obj instanceof TemporaryAnnotation))
                continue;
            TemporaryAnnotation annotation = (TemporaryAnnotation) obj;
            ReconcileAnnotationKey key = (ReconcileAnnotationKey) annotation.getKey();
            // partition type
            if (canHandlePartition(key.getPartitionType()) && stepsRun.contains(key.getStep())) {
                if (key.getScope() == ReconcileAnnotationKey.PARTIAL && annotation.getPosition().overlapsWith(dr.getOffset(), dr.getLength())) {
                    remove.add(annotation);
                } else if (key.getScope() == ReconcileAnnotationKey.TOTAL) {
                    remove.add(annotation);
                }
            }
        }
    }
    return (TemporaryAnnotation[]) remove.toArray(new TemporaryAnnotation[remove.size()]);
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ITemporaryAnnotation(org.eclipse.wst.sse.ui.internal.ITemporaryAnnotation) StructuredMarkerAnnotation(org.eclipse.wst.sse.ui.internal.StructuredMarkerAnnotation)

Example 62 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.

the class ShowTranslationHandler method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands
	 * .ExecutionEvent)
	 */
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    if (selection instanceof IStructuredSelection) {
        List list = ((IStructuredSelection) selection).toList();
        if (!list.isEmpty()) {
            if (list.get(0) instanceof IDOMNode) {
                final IDOMModel model = ((IDOMNode) list.get(0)).getModel();
                INodeAdapter adapter = model.getDocument().getAdapterFor(IJSPTranslation.class);
                if (adapter != null) {
                    Job opener = new UIJob("Opening JSP Java Translation") {

                        public IStatus runInUIThread(IProgressMonitor monitor) {
                            JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
                            final JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
                            // create an IEditorInput for the Java editor
                            final IStorageEditorInput input = new JSPTranslationEditorInput(model);
                            try {
                                IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaUI.ID_CU_EDITOR, true);
                                // Now add the problems we found
                                if (editor instanceof ITextEditor) {
                                    IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
                                    translation.reconcileCompilationUnit();
                                    List problemsList = translation.getProblems();
                                    IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
                                    AnnotationTypeLookup lookup = new AnnotationTypeLookup();
                                    for (int i = 0; i < problems.length; i++) {
                                        if (problems[i] instanceof IJSPProblem)
                                            continue;
                                        int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
                                        Position position = new Position(problems[i].getSourceStart(), length);
                                        Annotation annotation = null;
                                        String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
                                        if (problems[i].isError()) {
                                            type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
                                        } else if (problems[i].isWarning()) {
                                            type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
                                        }
                                        annotation = new Annotation(type, false, problems[i].getMessage());
                                        if (annotation != null) {
                                            annotationModel.addAnnotation(annotation, position);
                                        }
                                    }
                                }
                            } catch (PartInitException e) {
                                e.printStackTrace();
                                Display.getCurrent().beep();
                            }
                            return Status.OK_STATUS;
                        }
                    };
                    opener.setSystem(false);
                    opener.setUser(true);
                    opener.schedule();
                }
            }
        }
    }
    return null;
}
Also used : INodeAdapter(org.eclipse.wst.sse.core.internal.provisional.INodeAdapter) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IJSPProblem(org.eclipse.jst.jsp.core.internal.java.IJSPProblem) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) JSPTranslationExtension(org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension) ISelection(org.eclipse.jface.viewers.ISelection) UIJob(org.eclipse.ui.progress.UIJob) List(java.util.List) PartInitException(org.eclipse.ui.PartInitException) Job(org.eclipse.core.runtime.jobs.Job) UIJob(org.eclipse.ui.progress.UIJob) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) Position(org.eclipse.jface.text.Position) IEditorPart(org.eclipse.ui.IEditorPart) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter) IProblem(org.eclipse.jdt.core.compiler.IProblem) Annotation(org.eclipse.jface.text.source.Annotation) AnnotationTypeLookup(org.eclipse.ui.texteditor.AnnotationTypeLookup) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 63 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.

the class XSLEditor method installOverrideIndicator.

protected void installOverrideIndicator() {
    // uninstallOverrideIndicator();
    if (getEditorInput() instanceof FileEditorInput) {
        IAnnotationModel model = getDocumentProvider().getAnnotationModel(getEditorInput());
        IFile file = ((FileEditorInput) getEditorInput()).getFile();
        fOverrideIndicatorManager = new OverrideIndicatorManager(model, file);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)

Example 64 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.

the class TestReconcilerXML method testWellFormed.

/**
 * Tests reconciler by verifying no errors/warnings found with well-formed
 * xml.
 */
public void testWellFormed() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    ITextEditor textEditor = fEditor.getAdapter(ITextEditor.class);
    IAnnotationModel annoModel = textEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
    DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    // verify well-formed xml
    try {
        Thread.sleep(5000);
        Iterator iter = annoModel.getAnnotationIterator();
        // make sure the only problem we find is the lack of a specified grammar
        while (iter.hasNext()) {
            Annotation anno = (Annotation) iter.next();
            String annoType = anno.getType();
            if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
                assertTrue("testReconciler: Unexpected initial annotations" + anno.getText(), anno.getText().indexOf("No grammar constraints") > -1);
            }
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation)

Example 65 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project webtools.sourceediting by eclipse.

the class TestReconcilerXML method testIllFormedNoAttrValue.

/**
 * Tests reconciler by verifying error/warning found with ill-formed xml.
 * (missing attribute value)
 */
public void testIllFormedNoAttrValue() {
    IDocument doc = fEditor.getAdapter(IDocument.class);
    doc.set("<html><body><h1>Title</h1></body></html>");
    ITextEditor textEditor = fEditor.getAdapter(ITextEditor.class);
    IAnnotationModel annoModel = textEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
    DefaultMarkerAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();
    // verify ill-formed xml
    try {
        doc.replace(6, 6, "<body hello>");
        Thread.sleep(5000);
        boolean errorFound = false;
        Iterator iter = annoModel.getAnnotationIterator();
        StringBuffer buffer = new StringBuffer();
        while (iter.hasNext()) {
            Annotation anno = (Annotation) iter.next();
            String annoType = anno.getType();
            buffer.append("\n");
            buffer.append(anno.getText());
            if ((annotationAccess.isSubtype(annoType, ANNOTATION_ERROR)) || (annotationAccess.isSubtype(annoType, ANNOTATION_WARNING))) {
                errorFound = true;
            }
        }
        assertTrue("testReconciler: Did not find expected errors in: " + doc.get() + buffer, errorFound);
    } catch (BadLocationException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) DefaultMarkerAnnotationAccess(org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess) Iterator(java.util.Iterator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Annotation(org.eclipse.jface.text.source.Annotation) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)148 Annotation (org.eclipse.jface.text.source.Annotation)71 Position (org.eclipse.jface.text.Position)58 IDocument (org.eclipse.jface.text.IDocument)41 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)26 Iterator (java.util.Iterator)23 ArrayList (java.util.ArrayList)20 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)20 IDocumentProvider (org.eclipse.ui.texteditor.IDocumentProvider)19 MarkerAnnotation (org.eclipse.ui.texteditor.MarkerAnnotation)19 BadLocationException (org.eclipse.jface.text.BadLocationException)18 IFile (org.eclipse.core.resources.IFile)17 ITextEditor (org.eclipse.ui.texteditor.ITextEditor)16 IEditorInput (org.eclipse.ui.IEditorInput)13 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 List (java.util.List)12 CoreException (org.eclipse.core.runtime.CoreException)11 IMarker (org.eclipse.core.resources.IMarker)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10