Search in sources :

Example 1 with Issue

use of org.eclipse.xtext.validation.Issue in project xtext-eclipse by eclipse.

the class DerivedResourceMarkerCopier method determinateMarkerTypeByURI.

private String determinateMarkerTypeByURI(SourceRelativeURI resourceURI) {
    IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(resourceURI.getURI());
    if (serviceProvider == null)
        return null;
    MarkerTypeProvider typeProvider = serviceProvider.get(MarkerTypeProvider.class);
    Issue.IssueImpl issue = new Issue.IssueImpl();
    issue.setType(CheckType.NORMAL);
    return typeProvider.getMarkerType(issue);
}
Also used : MarkerTypeProvider(org.eclipse.xtext.ui.validation.MarkerTypeProvider) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Issue(org.eclipse.xtext.validation.Issue)

Example 2 with Issue

use of org.eclipse.xtext.validation.Issue in project xtext-eclipse by eclipse.

the class NoJRESmokeTester method checkNoErrorsInValidator.

protected void checkNoErrorsInValidator(final String model, XtextResource resource) {
    ResourceValidatorImpl validator = resourceValidatorProvider.get();
    Assert.assertNotSame(validator, resource.getResourceServiceProvider().getResourceValidator());
    validator.setDiagnosticConverter(new IDiagnosticConverter() {

        @Override
        public void convertValidatorDiagnostic(org.eclipse.emf.common.util.Diagnostic diagnostic, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof BasicDiagnostic) {
                List<?> data = diagnostic.getData();
                if (!data.isEmpty() && data.get(0) instanceof Throwable) {
                    Throwable t = (Throwable) data.get(0);
                    throwError(t);
                }
                if (EObjectValidator.DIAGNOSTIC_SOURCE.equals(diagnostic.getSource()) && diagnostic.getCode() == EObjectValidator.EOBJECT__EVERY_REFERENCE_IS_CONTAINED) {
                    throwError(new RuntimeException("Dangling reference found."));
                }
            }
        }

        private void throwError(Throwable e) {
            ComparisonFailure result = new ComparisonFailure(e.getMessage(), model, "");
            result.setStackTrace(e.getStackTrace());
            throw result;
        }

        @Override
        public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
            if (diagnostic instanceof ExceptionDiagnostic) {
                Exception e = ((ExceptionDiagnostic) diagnostic).getException();
                throwError(e);
            }
        }
    });
    validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
}
Also used : Issue(org.eclipse.xtext.validation.Issue) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) BasicDiagnostic(org.eclipse.emf.common.util.BasicDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) Severity(org.eclipse.xtext.diagnostics.Severity) ResourceValidatorImpl(org.eclipse.xtext.validation.ResourceValidatorImpl) IDiagnosticConverter(org.eclipse.xtext.validation.IDiagnosticConverter) ComparisonFailure(org.junit.ComparisonFailure) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) List(java.util.List)

Example 3 with Issue

use of org.eclipse.xtext.validation.Issue in project xtext-eclipse by eclipse.

the class DeclarativeQuickfixProviderTest method testHasResolutions.

@Test
public void testHasResolutions() throws Exception {
    abstract class __DeclarativeQuickfixProviderTest_1 extends AbstractDeclarativeQuickfixProvider {

        public abstract void signature(final Issue i, final IssueResolutionAcceptor acceptor);
    }
    AbstractDeclarativeQuickfixProvider provider = new __DeclarativeQuickfixProviderTest_1() {

        @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE)
        public void signature(final Issue i, final IssueResolutionAcceptor acceptor) {
        }
    };
    Assert.assertFalse(provider.hasResolutionFor((DeclarativeQuickfixProviderTest.DUMMY_CODE + Integer.valueOf(1))));
    Assert.assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE));
}
Also used : AbstractDeclarativeQuickfixProvider(org.eclipse.xtext.ui.editor.quickfix.AbstractDeclarativeQuickfixProvider) Issue(org.eclipse.xtext.validation.Issue) IssueResolutionAcceptor(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor) Test(org.junit.Test)

Example 4 with Issue

use of org.eclipse.xtext.validation.Issue in project xtext-eclipse by eclipse.

the class DeclarativeQuickfixProviderTest method testHasResolutions2.

@Test
public void testHasResolutions2() throws Exception {
    abstract class __DeclarativeQuickfixProviderTest_2 extends AbstractDeclarativeQuickfixProvider {

        public abstract void signature(final Issue i, final IssueResolutionAcceptor acceptor);
    }
    AbstractDeclarativeQuickfixProvider provider = new __DeclarativeQuickfixProviderTest_2() {

        @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE)
        @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE2)
        public void signature(final Issue i, final IssueResolutionAcceptor acceptor) {
        }
    };
    Assert.assertFalse(provider.hasResolutionFor((DeclarativeQuickfixProviderTest.DUMMY_CODE + Integer.valueOf(1))));
    Assert.assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE));
    Assert.assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE2));
}
Also used : AbstractDeclarativeQuickfixProvider(org.eclipse.xtext.ui.editor.quickfix.AbstractDeclarativeQuickfixProvider) Issue(org.eclipse.xtext.validation.Issue) IssueResolutionAcceptor(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor) Test(org.junit.Test)

Example 5 with Issue

use of org.eclipse.xtext.validation.Issue in project xtext-eclipse by eclipse.

the class DeclarativeQuickfixProviderTest method testHasResolutions3.

@Test
public void testHasResolutions3() throws Exception {
    abstract class __DeclarativeQuickfixProviderTest_3 extends AbstractDeclarativeQuickfixProvider {

        public abstract void signature(final Issue i, final IssueResolutionAcceptor acceptor);
    }
    AbstractDeclarativeQuickfixProvider provider = new __DeclarativeQuickfixProviderTest_3() {

        @Fixes({ @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE), @Fix(DeclarativeQuickfixProviderTest.DUMMY_CODE2) })
        public void signature(final Issue i, final IssueResolutionAcceptor acceptor) {
        }
    };
    Assert.assertFalse(provider.hasResolutionFor((DeclarativeQuickfixProviderTest.DUMMY_CODE + Integer.valueOf(1))));
    Assert.assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE));
    Assert.assertTrue(provider.hasResolutionFor(DeclarativeQuickfixProviderTest.DUMMY_CODE2));
}
Also used : AbstractDeclarativeQuickfixProvider(org.eclipse.xtext.ui.editor.quickfix.AbstractDeclarativeQuickfixProvider) Issue(org.eclipse.xtext.validation.Issue) IssueResolutionAcceptor(org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor) Test(org.junit.Test)

Aggregations

Issue (org.eclipse.xtext.validation.Issue)105 Test (org.junit.Test)38 XtextResource (org.eclipse.xtext.resource.XtextResource)33 Resource (org.eclipse.emf.ecore.resource.Resource)21 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)18 URI (org.eclipse.emf.common.util.URI)16 List (java.util.List)14 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)12 IssueResolution (org.eclipse.xtext.ui.editor.quickfix.IssueResolution)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)11 ArrayList (java.util.ArrayList)9 Severity (org.eclipse.xtext.diagnostics.Severity)9 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)9 EObject (org.eclipse.emf.ecore.EObject)8 IOException (java.io.IOException)7 CoreException (org.eclipse.core.runtime.CoreException)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)7 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)6 IssueResolutionAcceptor (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor)6