Search in sources :

Example 36 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.

the class XtextValidationTest method testDefinedLiteralTwice.

@Test
public void testDefinedLiteralTwice() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/validation/literal/2'\n" + "Model: enumValue=GeneratedEnum;\n" + "enum GeneratedEnum: SameName ='value' | SameName='otherValue';");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.getChildren().toString(), 1, diag.getChildren().size());
    assertEquals("diag.isWarning", diag.getSeverity(), Diagnostic.WARNING);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 37 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.

the class XtextValidationTest method testLeftRecursion_Bug_285605_05.

@Test
public void testLeftRecursion_Bug_285605_05() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "generate foo 'http://foo/bar'\n" + "RuleA : ruleB=RuleB;\n" + "RuleB : ruleC=RuleC;\n" + "RuleC : ruleA=RuleA ruleB=RuleB;\n");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    assertNotNull("diag", diag);
    assertEquals(diag.getChildren().toString(), 4, diag.getChildren().size());
    assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 38 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.

the class XtextValidationTest method testExplicitOverride05.

@Test
public void testExplicitOverride05() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.foo.Bar\n" + "import \"http://www.eclipse.org/emf/2002/Ecore\" as ecore" + "@Override\n" + "terminal ID: ('a'..'z'|'A'..'Z'|'_');");
    Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
    List<Diagnostic> issues = diag.getChildren();
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("This grammar has no super grammar and therefore cannot override any rules.", issues.get(0).getMessage());
    assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
Also used : Diagnostic(org.eclipse.emf.common.util.Diagnostic) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 39 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.

the class XtextGeneratorLanguage method validateGrammar.

protected void validateGrammar(final Grammar grammar) {
    this.validateAllImports(grammar);
    final EValidator validator = EValidator.Registry.INSTANCE.getEValidator(XtextPackage.eINSTANCE);
    if ((validator != null)) {
        final DiagnosticChain chain = new DiagnosticChain() {

            @Override
            public void add(final Diagnostic diagnostic) {
                int _severity = diagnostic.getSeverity();
                boolean _equals = (_severity == Diagnostic.ERROR);
                if (_equals) {
                    String _name = grammar.getName();
                    String _plus = ("Validation Error in " + _name);
                    final String grammarName = (_plus + ": ");
                    Throwable _exception = diagnostic.getException();
                    boolean _tripleEquals = (_exception == null);
                    if (_tripleEquals) {
                        String _message = diagnostic.getMessage();
                        String _plus_1 = (grammarName + _message);
                        throw new IllegalStateException(_plus_1);
                    } else {
                        String _message_1 = diagnostic.getMessage();
                        String _plus_2 = (grammarName + _message_1);
                        Throwable _exception_1 = diagnostic.getException();
                        throw new IllegalStateException(_plus_2, _exception_1);
                    }
                }
            }

            @Override
            public void addAll(final Diagnostic diagnostic) {
                this.add(diagnostic);
            }

            @Override
            public void merge(final Diagnostic diagnostic) {
                throw new UnsupportedOperationException();
            }
        };
        validator.validate(grammar, chain, null);
        final TreeIterator<EObject> iterator = grammar.eAllContents();
        while (iterator.hasNext()) {
            EObject _next = iterator.next();
            HashMap<Object, Object> _hashMap = new HashMap<Object, Object>();
            validator.validate(_next, chain, _hashMap);
        }
    }
}
Also used : HashMap(java.util.HashMap) Diagnostic(org.eclipse.emf.common.util.Diagnostic) EObject(org.eclipse.emf.ecore.EObject) EValidator(org.eclipse.emf.ecore.EValidator) DiagnosticChain(org.eclipse.emf.common.util.DiagnosticChain) EObject(org.eclipse.emf.ecore.EObject)

Example 40 with Diagnostic

use of org.eclipse.emf.common.util.Diagnostic in project xtext-core by eclipse.

the class EMFGeneratorFragment2 method doGenerate.

protected void doGenerate(final GenModel genModel) {
    final Generator generator = new Generator() {

        @Override
        public JControlModel getJControlModel() {
            if ((this.jControlModel == null)) {
                JControlModel _jControlModel = new JControlModel();
                this.jControlModel = _jControlModel;
                this.jControlModel.initialize(null, this.options.mergeRulesURI);
            }
            return this.jControlModel;
        }
    };
    GeneratorAdapterFactory.Descriptor.Registry _adapterFactoryDescriptorRegistry = generator.getAdapterFactoryDescriptorRegistry();
    String _lineDelimiter = this.codeConfig.getLineDelimiter();
    CvsIdFilteringGeneratorAdapterFactoryDescriptor _cvsIdFilteringGeneratorAdapterFactoryDescriptor = new CvsIdFilteringGeneratorAdapterFactoryDescriptor(_lineDelimiter);
    _adapterFactoryDescriptorRegistry.addDescriptor(GenModelPackage.eNS_URI, _cvsIdFilteringGeneratorAdapterFactoryDescriptor);
    genModel.setCanGenerate(true);
    generator.setInput(genModel);
    BasicMonitor _basicMonitor = new BasicMonitor();
    final Diagnostic diagnostic = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, _basicMonitor);
    int _severity = diagnostic.getSeverity();
    boolean _notEquals = (_severity != Diagnostic.OK);
    if (_notEquals) {
        EMFGeneratorFragment2.LOG.warn(diagnostic);
    }
    if (this.generateEdit) {
        BasicMonitor _basicMonitor_1 = new BasicMonitor();
        final Diagnostic editDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDIT_PROJECT_TYPE, _basicMonitor_1);
        int _severity_1 = editDiag.getSeverity();
        boolean _notEquals_1 = (_severity_1 != Diagnostic.OK);
        if (_notEquals_1) {
            EMFGeneratorFragment2.LOG.warn(editDiag);
        }
    }
    if (this.generateEditor) {
        BasicMonitor _basicMonitor_2 = new BasicMonitor();
        final Diagnostic editorDiag = generator.generate(genModel, GenBaseGeneratorAdapter.EDITOR_PROJECT_TYPE, _basicMonitor_2);
        int _severity_2 = editorDiag.getSeverity();
        boolean _notEquals_2 = (_severity_2 != Diagnostic.OK);
        if (_notEquals_2) {
            EMFGeneratorFragment2.LOG.warn(editorDiag);
        }
    }
}
Also used : JControlModel(org.eclipse.emf.codegen.merge.java.JControlModel) CvsIdFilteringGeneratorAdapterFactoryDescriptor(org.eclipse.emf.mwe2.ecore.CvsIdFilteringGeneratorAdapterFactoryDescriptor) Diagnostic(org.eclipse.emf.common.util.Diagnostic) BasicMonitor(org.eclipse.emf.common.util.BasicMonitor) Generator(org.eclipse.emf.codegen.ecore.generator.Generator) CvsIdFilteringGeneratorAdapterFactoryDescriptor(org.eclipse.emf.mwe2.ecore.CvsIdFilteringGeneratorAdapterFactoryDescriptor)

Aggregations

Diagnostic (org.eclipse.emf.common.util.Diagnostic)73 Test (org.junit.Test)63 XtextResource (org.eclipse.xtext.resource.XtextResource)56 EObject (org.eclipse.emf.ecore.EObject)11 BasicDiagnostic (org.eclipse.emf.common.util.BasicDiagnostic)6 Resource (org.eclipse.emf.ecore.resource.Resource)6 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)5 LazyLinkingResource (org.eclipse.xtext.linking.lazy.LazyLinkingResource)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 EPackage (org.eclipse.emf.ecore.EPackage)2 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 AbstractValidationDiagnostic (org.eclipse.xtext.validation.AbstractValidationDiagnostic)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintWriter (java.io.PrintWriter)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 Generator (org.eclipse.emf.codegen.ecore.generator.Generator)1