Search in sources :

Example 16 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.

the class OnChangeEvictingCacheAdapterTest method testCacheSurvivesChangeToDiagnostics.

@Test
public void testCacheSurvivesChangeToDiagnostics() throws Exception {
    EcoreFactory factory = EcoreFactory.eINSTANCE;
    EClass eClass = factory.createEClass();
    Resource resource = new ResourceImpl();
    resource.getContents().add(eClass);
    CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
    setValue(ca);
    List<Diagnostic> errors = resource.getErrors();
    assertIsSet(ca);
    errors.clear();
    assertIsSet(ca);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) ResourceImpl(org.eclipse.emf.ecore.resource.impl.ResourceImpl) EcoreFactory(org.eclipse.emf.ecore.EcoreFactory) Resource(org.eclipse.emf.ecore.resource.Resource) CacheAdapter(org.eclipse.xtext.util.OnChangeEvictingCache.CacheAdapter) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) Test(org.junit.Test)

Example 17 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.

the class ParseErrorHandlingTest method testTrailingRecoverableError.

@Test
public void testTrailingRecoverableError() throws Exception {
    with(TreeTestLanguageStandaloneSetup.class);
    String model = "parent ('Teststring') { \n" + "	child ('Teststring'){};\n" + "	child ('Teststring'){};\n" + "};\n" + "};\n" + "\n";
    Resource res = getResourceFromStringAndExpect(model, 1);
    assertEquals(res.getErrors().size(), 1, res.getErrors().size());
    Diagnostic diag = res.getErrors().get(0);
    assertNotNull(diag);
    assertEquals(5, diag.getLine());
    Model parsedModel = (Model) res.getContents().get(0);
    assertNotNull(parsedModel);
    ICompositeNode composite = NodeModelUtils.getNode(parsedModel);
    assertNotNull(composite);
    List<ILeafNode> leafs = Lists.newArrayList(composite.getLeafNodes());
    ILeafNode lastWs = leafs.get(leafs.size() - 1);
    assertTrue(lastWs.isHidden());
    assertNull(lastWs.getSyntaxErrorMessage());
    ILeafNode lastNode = leafs.get(leafs.size() - 2);
    assertFalse(lastNode.isHidden());
    assertNotNull(lastNode);
    assertEquals("};", lastNode.getText());
    assertNotNull(lastNode.getSyntaxErrorMessage());
}
Also used : ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Model(org.eclipse.xtext.testlanguages.treeTestLanguage.Model) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 18 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.

the class DiagnosticConverterImpl method convertResourceDiagnostic.

@Override
public void convertResourceDiagnostic(Diagnostic diagnostic, Severity severity, IAcceptor<Issue> acceptor) {
    IssueImpl issue = new Issue.IssueImpl();
    issue.setSyntaxError(diagnostic instanceof XtextSyntaxDiagnostic);
    issue.setSeverity(severity);
    issue.setLineNumber(diagnostic.getLine());
    issue.setColumn(diagnostic.getColumn());
    issue.setMessage(diagnostic.getMessage());
    if (diagnostic instanceof org.eclipse.xtext.diagnostics.Diagnostic) {
        org.eclipse.xtext.diagnostics.Diagnostic xtextDiagnostic = (org.eclipse.xtext.diagnostics.Diagnostic) diagnostic;
        issue.setOffset(xtextDiagnostic.getOffset());
        issue.setLength(xtextDiagnostic.getLength());
    }
    if (diagnostic instanceof AbstractDiagnostic) {
        AbstractDiagnostic castedDiagnostic = (AbstractDiagnostic) diagnostic;
        issue.setUriToProblem(castedDiagnostic.getUriToProblem());
        issue.setCode(castedDiagnostic.getCode());
        issue.setData(castedDiagnostic.getData());
        issue.setLineNumberEnd(castedDiagnostic.getLineEnd());
        issue.setColumnEnd(castedDiagnostic.getColumnEnd());
    }
    issue.setType(CheckType.FAST);
    acceptor.accept(issue);
}
Also used : XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) IssueImpl(org.eclipse.xtext.validation.Issue.IssueImpl) XtextSyntaxDiagnostic(org.eclipse.xtext.resource.XtextSyntaxDiagnostic) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic) AbstractDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic)

Example 19 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-core by eclipse.

the class ToEcoreTrafoTest method testAbstractLanguageToMetamodel.

@Test
public void testAbstractLanguageToMetamodel() throws Exception {
    XtextResource r = getResource("classpath:/" + AbstractTestLanguage.class.getName().replace('.', '/') + ".xtext");
    Grammar element = (Grammar) r.getParseResult().getRootASTElement();
    if (!r.getErrors().isEmpty()) {
        EList<Diagnostic> errors = r.getErrors();
        for (Diagnostic syntaxError : errors) {
            logger.debug(syntaxError.getMessage() + " - " + syntaxError.getLine());
        }
        fail(errors.toString());
    }
    List<TerminalRule> lexerRules = GrammarUtil.allTerminalRules(element);
    assertEquals(8, lexerRules.size());
    List<EPackage> list = Xtext2EcoreTransformer.doGetGeneratedPackages(element);
    assertNotNull(list);
    assertEquals(0, list.size());
}
Also used : Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) TerminalRule(org.eclipse.xtext.TerminalRule) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 20 with Diagnostic

use of org.eclipse.emf.ecore.resource.Resource.Diagnostic in project xtext-eclipse by eclipse.

the class AbstractXtextTests method getResourceAndExpect.

public final XtextResource getResourceAndExpect(InputStream in, URI uri, int expectedErrors) throws Exception {
    XtextResource resource = doGetResource(in, uri);
    checkNodeModel(resource);
    if (expectedErrors != UNKNOWN_EXPECTATION) {
        if (expectedErrors == EXPECT_ERRORS)
            assertFalse(Joiner.on('\n').join(resource.getErrors()), resource.getErrors().isEmpty());
        else
            assertEquals(Joiner.on('\n').join(resource.getErrors()), expectedErrors, resource.getErrors().size());
    }
    for (Diagnostic d : resource.getErrors()) {
        if (d instanceof ExceptionDiagnostic)
            fail(d.getMessage());
    }
    if (expectedErrors == 0 && resource.getContents().size() > 0 && shouldTestSerializer(resource)) {
        SerializerTester tester = get(SerializerTester.class);
        EObject obj = resource.getContents().get(0);
        tester.assertSerializeWithNodeModel(obj);
        tester.assertSerializeWithoutNodeModel(obj);
    }
    return resource;
}
Also used : ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) EObject(org.eclipse.emf.ecore.EObject) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) ExceptionDiagnostic(org.eclipse.xtext.diagnostics.ExceptionDiagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) SerializerTester(org.eclipse.xtext.junit4.serializer.SerializerTester)

Aggregations

Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)32 Test (org.junit.Test)12 ExceptionDiagnostic (org.eclipse.xtext.diagnostics.ExceptionDiagnostic)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 XtextResource (org.eclipse.xtext.resource.XtextResource)8 XtextLinkingDiagnostic (org.eclipse.xtext.linking.impl.XtextLinkingDiagnostic)7 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)6 Issue (org.eclipse.xtext.validation.Issue)6 List (java.util.List)5 EObject (org.eclipse.emf.ecore.EObject)5 Severity (org.eclipse.xtext.diagnostics.Severity)5 IDiagnosticConverter (org.eclipse.xtext.validation.IDiagnosticConverter)5 ResourceValidatorImpl (org.eclipse.xtext.validation.ResourceValidatorImpl)5 IOException (java.io.IOException)4 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)3 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)3 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)3 ComparisonFailure (org.junit.ComparisonFailure)3 ArrayList (java.util.ArrayList)2 URI (org.eclipse.emf.common.util.URI)2