Search in sources :

Example 1 with MarkerCreator

use of org.eclipse.xtext.ui.editor.validation.MarkerCreator 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 2 with MarkerCreator

use of org.eclipse.xtext.ui.editor.validation.MarkerCreator in project xtext-eclipse by eclipse.

the class AbstractProblemHoverTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    modelAsText = "stuff mystuff\nstuff yourstuff refs _mystuff// Comment";
    IFile file = IResourcesSetupUtil.createFile("test/test.testlanguage", modelAsText);
    editor = openEditor(file);
    document = editor.getDocument();
    hover = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(MockHover.class);
    hover.setSourceViewer(editor.getInternalSourceViewer());
    List<Issue> issues = document.readOnly(new IUnitOfWork<List<Issue>, XtextResource>() {

        @Override
        public List<Issue> exec(XtextResource state) throws Exception {
            return state.getResourceServiceProvider().getResourceValidator().validate(state, CheckMode.ALL, null);
        }
    });
    MarkerCreator markerCreator = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(MarkerCreator.class);
    for (Issue issue : issues) {
        markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Issue(org.eclipse.xtext.validation.Issue) List(java.util.List) XtextResource(org.eclipse.xtext.resource.XtextResource) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator)

Example 3 with MarkerCreator

use of org.eclipse.xtext.ui.editor.validation.MarkerCreator in project xtext-eclipse by eclipse.

the class ProblemHoverTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    modelAsText = "stuff mystuff\nstuff yourstuff refs _mystuff stuff hisstuff refs _yourstuff// Comment";
    IFile file = IResourcesSetupUtil.createFile("test/test.testlanguage", modelAsText);
    editor = openEditor(file);
    document = editor.getDocument();
    hover = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(ProblemAnnotationHover.class);
    hover.setSourceViewer(editor.getInternalSourceViewer());
    List<Issue> issues = document.readOnly(new IUnitOfWork<List<Issue>, XtextResource>() {

        @Override
        public List<Issue> exec(XtextResource state) throws Exception {
            return state.getResourceServiceProvider().getResourceValidator().validate(state, CheckMode.ALL, null);
        }
    });
    MarkerCreator markerCreator = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(MarkerCreator.class);
    for (Issue issue : issues) {
        markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Issue(org.eclipse.xtext.validation.Issue) ProblemAnnotationHover(org.eclipse.xtext.ui.editor.hover.ProblemAnnotationHover) List(java.util.List) XtextResource(org.eclipse.xtext.resource.XtextResource) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with MarkerCreator

use of org.eclipse.xtext.ui.editor.validation.MarkerCreator in project xtext-eclipse by eclipse.

the class AnnotationWithQuickFixesHoverTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    modelAsText = "stuff mystuff stuff yourstuff refs _mystuff stuff hisstuff refs _yourstuff";
    IFile file = IResourcesSetupUtil.createFile("test/test.testlanguage", modelAsText);
    editor = openEditor(file);
    document = editor.getDocument();
    hover = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(AnnotationWithQuickFixesHover.class);
    hover.setSourceViewer(editor.getInternalSourceViewer());
    List<Issue> issues = document.readOnly(new IUnitOfWork<List<Issue>, XtextResource>() {

        @Override
        public List<Issue> exec(XtextResource state) throws Exception {
            return state.getResourceServiceProvider().getResourceValidator().validate(state, CheckMode.ALL, null);
        }
    });
    assertEquals(2, issues.size());
    MarkerCreator markerCreator = TestsActivator.getInstance().getInjector(getEditorId()).getInstance(MarkerCreator.class);
    for (Issue issue : issues) {
        markerCreator.createMarker(issue, file, MarkerTypes.forCheckType(issue.getType()));
    }
    if (Display.getCurrent().getActiveShell() != editor.getShell()) {
        System.out.println("Editor shell is not active. Active shell is: " + Display.getCurrent().getActiveShell());
        getWorkbenchWindow().getShell().forceActive();
        editor.getInternalSourceViewer().getTextWidget().forceFocus();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Issue(org.eclipse.xtext.validation.Issue) List(java.util.List) XtextResource(org.eclipse.xtext.resource.XtextResource) AnnotationWithQuickFixesHover(org.eclipse.xtext.ui.editor.hover.AnnotationWithQuickFixesHover) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator)

Example 5 with MarkerCreator

use of org.eclipse.xtext.ui.editor.validation.MarkerCreator in project n4js by eclipse.

the class OwnResourceValidatorAwareValidatingEditorCallback method newValidationJob.

private ValidationJob newValidationJob(final XtextEditor editor) {
    final IXtextDocument document = editor.getDocument();
    final IAnnotationModel annotationModel = editor.getInternalSourceViewer().getAnnotationModel();
    final IssueResolutionProvider issueResolutionProvider = getService(editor, IssueResolutionProvider.class);
    final MarkerTypeProvider markerTypeProvider = getService(editor, MarkerTypeProvider.class);
    final MarkerCreator markerCreator = getService(editor, MarkerCreator.class);
    final IValidationIssueProcessor issueProcessor = new CompositeValidationIssueProcessor(new AnnotationIssueProcessor(document, annotationModel, issueResolutionProvider), new MarkerIssueProcessor(editor.getResource(), markerCreator, markerTypeProvider));
    return editor.getDocument().modify(resource -> {
        final IResourceServiceProvider serviceProvider = resource.getResourceServiceProvider();
        final IResourceValidator resourceValidator = serviceProvider.getResourceValidator();
        return new ValidationJob(resourceValidator, editor.getDocument(), issueProcessor, ALL);
    });
}
Also used : IValidationIssueProcessor(org.eclipse.xtext.ui.editor.validation.IValidationIssueProcessor) MarkerTypeProvider(org.eclipse.xtext.ui.validation.MarkerTypeProvider) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) IssueResolutionProvider(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) MarkerCreator(org.eclipse.xtext.ui.editor.validation.MarkerCreator) MarkerIssueProcessor(org.eclipse.xtext.ui.editor.validation.MarkerIssueProcessor) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) AnnotationIssueProcessor(org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor) ValidationJob(org.eclipse.xtext.ui.editor.validation.ValidationJob)

Aggregations

MarkerCreator (org.eclipse.xtext.ui.editor.validation.MarkerCreator)6 IFile (org.eclipse.core.resources.IFile)4 Issue (org.eclipse.xtext.validation.Issue)4 List (java.util.List)3 XtextResource (org.eclipse.xtext.resource.XtextResource)3 IResource (org.eclipse.core.resources.IResource)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)2 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)2 IssueResolutionProvider (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionProvider)2 AnnotationIssueProcessor (org.eclipse.xtext.ui.editor.validation.AnnotationIssueProcessor)2 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IMarker (org.eclipse.core.resources.IMarker)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1