Search in sources :

Example 1 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project tdi-studio-se by Talend.

the class TalendJavaSourceViewer method initializeModel.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.viewer.ReconcilerViewer#initializeModel(IDocument document)
     */
@Override
protected void initializeModel() {
    getSourceViewerDecorationSupport().install(JavaPlugin.getDefault().getCombinedPreferenceStore());
    this.setRangeIndicator(new DefaultRangeIndicator());
    IAnnotationModel model;
    IDocument document;
    if (checkCode) {
        IDocumentProvider provider = JavaPlugin.getDefault().getCompilationUnitDocumentProvider();
        IEditorInput ei = new FileEditorInput(file);
        try {
            provider.connect(ei);
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
        document = provider.getDocument(ei);
        model = provider.getAnnotationModel(ei);
    } else {
        model = new AnnotationModel();
        document = getDocument();
        model.connect(document);
    }
    if (document != null) {
        setDocument(document, model);
        showAnnotations(model != null && checkCode);
    }
    super.initializeModel();
}
Also used : DefaultRangeIndicator(org.eclipse.ui.texteditor.DefaultRangeIndicator) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 2 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.

the class MarkOccurrencesTest method testMarkOccurrencesCrossFile.

@Test
public void testMarkOccurrencesCrossFile() throws Exception {
    String model1 = "Zonk { Bar(Foo) {} Baz(Foo Bar) {} }";
    String model2 = "Foo {}";
    IFile modelFile1 = IResourcesSetupUtil.createFile("test/src/Test1.outlinetestlanguage", model1);
    IResourcesSetupUtil.createFile("test/src/Test2.outlinetestlanguage", model2);
    IResourcesSetupUtil.waitForBuild();
    XtextEditor editor = openEditor(modelFile1);
    ISelectionProvider selectionProvider = editor.getSelectionProvider();
    selectionProvider.setSelection(new TextSelection(model1.indexOf("Foo"), 1));
    IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
    ExpectationBuilder listener = new ExpectationBuilder().added(OCCURRENCE_ANNOTATION_TYPE, model1.indexOf("Foo", 3), 3).added(OCCURRENCE_ANNOTATION_TYPE, model1.lastIndexOf("Foo"), 3);
    listener.start();
    annotationModel.addAnnotationModelListener(listener);
    setMarkOccurrences(true);
    listener.verify(TIMEOUT);
}
Also used : IFile(org.eclipse.core.resources.IFile) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AbstractEditorTest(org.eclipse.xtext.ui.testing.AbstractEditorTest) Test(org.junit.Test)

Example 3 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.

the class IssueDataTest method testIssueData.

@Test
public void testIssueData() throws Exception {
    XtextEditor xtextEditor = newXtextEditor(PROJECT_NAME, MODEL_FILE, MODEL_WITH_LINKING_ERROR);
    IXtextDocument document = xtextEditor.getDocument();
    IResource file = xtextEditor.getResource();
    List<Issue> issues = getIssues(document);
    assertEquals(1, issues.size());
    Issue issue = issues.get(0);
    assertEquals(2, issue.getLineNumber().intValue());
    assertEquals(3, issue.getColumn().intValue());
    assertEquals(PREFIX.length(), issue.getOffset().intValue());
    assertEquals(QuickfixCrossrefTestLanguageValidator.TRIGGER_VALIDATION_ISSUE.length(), issue.getLength().intValue());
    String[] expectedIssueData = new String[] { QuickfixCrossrefTestLanguageValidator.ISSUE_DATA_0, QuickfixCrossrefTestLanguageValidator.ISSUE_DATA_1 };
    assertTrue(Arrays.equals(expectedIssueData, issue.getData()));
    Thread.sleep(1000);
    IAnnotationModel annotationModel = xtextEditor.getDocumentProvider().getAnnotationModel(xtextEditor.getEditorInput());
    AnnotationIssueProcessor annotationIssueProcessor = new AnnotationIssueProcessor(document, annotationModel, new IssueResolutionProvider.NullImpl());
    annotationIssueProcessor.processIssues(issues, new NullProgressMonitor());
    Iterator<?> annotationIterator = annotationModel.getAnnotationIterator();
    // filter QuickDiffAnnotations
    List<Object> allAnnotations = Lists.newArrayList(annotationIterator);
    List<XtextAnnotation> annotations = newArrayList(filter(allAnnotations, XtextAnnotation.class));
    assertEquals(annotations.toString(), 1, annotations.size());
    XtextAnnotation annotation = annotations.get(0);
    assertTrue(Arrays.equals(expectedIssueData, annotation.getIssueData()));
    IssueUtil issueUtil = new IssueUtil();
    Issue issueFromAnnotation = issueUtil.getIssueFromAnnotation(annotation);
    assertTrue(Arrays.equals(expectedIssueData, issueFromAnnotation.getData()));
    new MarkerCreator().createMarker(issue, file, MarkerTypes.FAST_VALIDATION);
    IMarker[] markers = file.findMarkers(MarkerTypes.FAST_VALIDATION, true, IResource.DEPTH_ZERO);
    assertEquals(1, markers.length);
    String attribute = (String) markers[0].getAttribute(Issue.DATA_KEY);
    assertNotNull(attribute);
    assertTrue(Arrays.equals(expectedIssueData, Strings.unpack(attribute)));
    Issue issueFromMarker = issueUtil.createIssue(markers[0]);
    assertEquals(issue.getColumn(), issueFromMarker.getColumn());
    assertEquals(issue.getLineNumber(), issueFromMarker.getLineNumber());
    assertEquals(issue.getOffset(), issueFromMarker.getOffset());
    assertEquals(issue.getLength(), issueFromMarker.getLength());
    assertTrue(Arrays.equals(expectedIssueData, issueFromMarker.getData()));
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Issue(org.eclipse.xtext.validation.Issue) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IssueUtil(org.eclipse.xtext.ui.util.IssueUtil) AnnotationIssueProcessor(org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor) XtextAnnotation(org.eclipse.xtext.ui.editor.validation.XtextAnnotation) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IMarker(org.eclipse.core.resources.IMarker) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator) IResource(org.eclipse.core.resources.IResource) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 4 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.

the class XtextEditorErrorTickUpdater method getSeverity.

@SuppressWarnings("unchecked")
protected Severity getSeverity(XtextEditor xtextEditor) {
    if (xtextEditor == null || xtextEditor.getInternalSourceViewer() == null)
        return null;
    IAnnotationModel model = xtextEditor.getInternalSourceViewer().getAnnotationModel();
    if (model != null) {
        Iterator<Annotation> iterator = model.getAnnotationIterator();
        boolean hasWarnings = false;
        boolean hasInfos = false;
        while (iterator.hasNext()) {
            Annotation annotation = iterator.next();
            if (!annotation.isMarkedDeleted()) {
                Issue issue = issueUtil.getIssueFromAnnotation(annotation);
                if (issue != null) {
                    if (issue.getSeverity() == Severity.ERROR) {
                        return Severity.ERROR;
                    } else if (issue.getSeverity() == Severity.WARNING) {
                        hasWarnings = true;
                    } else if (issue.getSeverity() == Severity.INFO) {
                        hasInfos = true;
                    }
                }
            }
        }
        if (hasWarnings)
            return Severity.WARNING;
        if (hasInfos)
            return Severity.INFO;
    }
    return null;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) Annotation(org.eclipse.jface.text.source.Annotation)

Example 5 with IAnnotationModel

use of org.eclipse.jface.text.source.IAnnotationModel in project xtext-eclipse by eclipse.

the class MarkerResolutionGenerator method getResolutions.

@Override
public IMarkerResolution[] getResolutions(IMarker marker) {
    final IMarkerResolution[] emptyResult = new IMarkerResolution[0];
    try {
        if (!marker.isSubtypeOf(MarkerTypes.ANY_VALIDATION))
            return emptyResult;
    } catch (CoreException e) {
        return emptyResult;
    }
    if (!languageResourceHelper.isLanguageResource(marker.getResource())) {
        return emptyResult;
    }
    XtextEditor editor = findEditor(marker.getResource());
    if (editor != null) {
        IAnnotationModel annotationModel = editor.getDocumentProvider().getAnnotationModel(editor.getEditorInput());
        if (annotationModel != null && !isMarkerStillValid(marker, annotationModel))
            return emptyResult;
    }
    Issue issue = getIssueUtil().createIssue(marker);
    if (issue == null)
        return emptyResult;
    List<IssueResolution> resolutions = getResolutionProvider().getResolutions(issue);
    List<IMarkerResolution> result = Lists.newArrayList();
    List<IssueResolution> remaining = Lists.newArrayList();
    for (IssueResolution resolution : resolutions) {
        if (resolution.getModification() instanceof IBatchableModification) {
            result.add(adapterFactory.create(marker, resolution));
        } else {
            remaining.add(resolution);
        }
    }
    result.addAll(Lists.newArrayList(getAdaptedResolutions(remaining)));
    return result.toArray(new IMarkerResolution[result.size()]);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IMarkerResolution(org.eclipse.ui.IMarkerResolution) CoreException(org.eclipse.core.runtime.CoreException) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IBatchableModification(org.eclipse.xtext.ui.editor.model.edit.BatchModification.IBatchableModification)

Aggregations

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