org.eclipse.emf.ecore.util.Diagnostician Java Examples

The following examples show how to use org.eclipse.emf.ecore.util.Diagnostician. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNameClash_03() throws Exception {
	String grammarAsText =
			"grammar test with org.eclipse.xtext.common.Terminals\n" +
			"generate test 'http://test'\n" +
			"Foo: myVars=ID my_vars=ID;\n";
	
	Grammar grammar = (Grammar) getModel(grammarAsText);
	AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
	
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
	CompoundElement element = (CompoundElement) grammar.getRules().get(0).getAlternatives();
	messageAcceptor.expectedContext(
			grammar.getRules().get(0).getType(),
			element.getElements().get(0),
			element.getElements().get(1)
	);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
	messageAcceptor.validate();
}
 
Example #2
Source File: ValidatorTester.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Inject
public ValidatorTester(T validator, EValidatorRegistrar registrar, @Named(Constants.LANGUAGE_NAME) final String languageName) {
	this.validator = validator;
	EValidator.Registry originalRegistry = registrar.getRegistry();
	EValidatorRegistryImpl newRegistry = new EValidatorRegistryImpl();
	registrar.setRegistry(newRegistry);
	this.validator.register(registrar);
	diagnostician = new Diagnostician(newRegistry) {
		@Override
		public java.util.Map<Object,Object> createDefaultContext() {
			java.util.Map<Object,Object> map = super.createDefaultContext();
			map.put(AbstractInjectableValidator.CURRENT_LANGUAGE_NAME, languageName);
			return map;
		}
	};
	registrar.setRegistry(originalRegistry);
	validatorCalled = false;
}
 
Example #3
Source File: ExporterProcessor.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates a object instance and its children using the EMF core validator
 * API.
 *
 * @param element
 *            the element to validate
 * @param label
 *            the type label of the element
 * @throws IllegalStateException
 *             if validation errors are encountered
 */
protected static void validateDevice ( final EObject object, final String label )
{
    final Diagnostic diag = Diagnostician.INSTANCE.validate ( object );
    if ( diag.getSeverity () == Diagnostic.ERROR )
    {
        final StringBuilder sb = new StringBuilder ( "Invalid " + label );
        for ( final Diagnostic child : diag.getChildren () )
        {
            if ( child.getSeverity () == Diagnostic.ERROR )
            {
                sb.append ( System.lineSeparator () );
                sb.append ( child.getMessage () );
            }
        }
        throw new IllegalStateException ( sb.toString () );
    }
}
 
Example #4
Source File: GatewayPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Gateway.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #5
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverrideFinal() throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" + 
			"generate supergrammar \"http://org.xtext.supergrammar\"\n" + 
			"@Final\n" + 
			"RuleFinal:name=ID;\n" + 
			"Rule: name=ID;","superGrammar.xtext", rs);
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.xtext.Supergrammar\n" +
			"generate bar \"http://org.xtext.Bar\"\n" + 
			"RuleFinal: name=ID;",  "foo.xtext", rs);
	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	List<Diagnostic> issues = diag.getChildren();
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("This rule illegally overrides RuleFinal in org.xtext.Supergrammar which is final.", issues.get(0).getMessage());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #6
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testOverrideDeprecated_1() throws Exception {
	XtextResourceSet rs = get(XtextResourceSet.class);
	getResourceFromString("grammar org.xtext.Supergrammar with org.eclipse.xtext.common.Terminals\n" + 
			"generate supergrammar \"http://org.xtext.supergrammar\"\n" + 
			"@Deprecated\n" + 
			"RuleDeprecated: name=ID;\n" + 
			"Rule: name=ID;","superGrammar.xtext", rs);
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.xtext.Supergrammar\n" +
			"generate bar \"http://org.xtext.Bar\"\n" + 
			"@Override RuleDeprecated: name=ID;",  "foo.xtext", rs);
	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	List<Diagnostic> issues = diag.getChildren();
	assertEquals(issues.toString(), 1, issues.size());
	assertEquals("This rule overrides RuleDeprecated in org.xtext.Supergrammar which is deprecated.", issues.get(0).getMessage());
	assertEquals("diag.isWarning", diag.getSeverity(), Diagnostic.WARNING);
}
 
Example #7
Source File: CompositeProcessorPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.CompositeProcessor.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #8
Source File: ServiceActivatorPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.ServiceActivator.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #9
Source File: SplitterPropertiesEditionComponent.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * 
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#validateValue(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
 * 
 */
public Diagnostic validateValue(IPropertiesEditionEvent event) {
	Diagnostic ret = Diagnostic.OK_INSTANCE;
	if (event.getNewValue() != null) {
		try {
			if (EipViewsRepository.Splitter.Properties.name == event.getAffectedEditor()) {
				Object newValue = event.getNewValue();
				if (newValue instanceof String) {
					newValue = EEFConverterUtil.createFromString(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), (String)newValue);
				}
				ret = Diagnostician.INSTANCE.validate(EipPackage.eINSTANCE.getEndpoint_Name().getEAttributeType(), newValue);
			}
		} catch (IllegalArgumentException iae) {
			ret = BasicDiagnostic.toDiagnostic(iae);
		} catch (WrappedException we) {
			ret = BasicDiagnostic.toDiagnostic(we);
		}
	}
	return ret;
}
 
Example #10
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testCycleInTypeHierarchy() throws Exception {
	String grammarAsText = "grammar test with org.eclipse.xtext.common.Terminals" +
			" generate test 'http://test'";
	grammarAsText += " RuleA: RuleB;";
	grammarAsText += " RuleB: RuleC;";
	grammarAsText += " RuleC: RuleA;";
	grammarAsText += " RuleD: RuleA;";

	Grammar grammar = (Grammar) getModel(grammarAsText);
	AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
	
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(grammar.getRules().get(0).getType(), true, false);
	messageAcceptor.expectedContext(
			grammar.getRules().get(1).getType(),
			grammar.getRules().get(2).getType()
	);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
	messageAcceptor.validate();
}
 
Example #11
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNameClash_02() throws Exception {
	String grammarAsText =
			"grammar test with org.eclipse.xtext.common.Terminals\n" +
			"generate test 'http://test'\n" +
			"Class returns Class: {Class_} name=ID;\n";
	
	Grammar grammar = (Grammar) getModel(grammarAsText);
	AbstractMetamodelDeclaration metamodelDeclaration = grammar.getMetamodelDeclarations().get(0);
	
	XtextValidator validator = get(XtextValidator.class);
	ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, true, false);
	CompoundElement element = (CompoundElement) grammar.getRules().get(0).getAlternatives();
	messageAcceptor.expectedContext(
			grammar.getRules().get(0).getType(),
			((Action) element.getElements().get(0)).getType()
	);
	validator.setMessageAcceptor(messageAcceptor);
	validator.checkGeneratedPackage((GeneratedMetamodel) metamodelDeclaration, Diagnostician.INSTANCE, Collections.EMPTY_MAP);
	messageAcceptor.validate();
}
 
Example #12
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkExitTransitionExists() {
	statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "NoExitTransition.sct");
	
	Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
	assertIssueCount(diagnostics, 1);
	assertError(diagnostics, EXIT_UNUSED);
}
 
Example #13
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLeftRecursion_Bug_285605_11() 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(), 6, diag.getChildren().size());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #14
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testLeftRecursion_Bug_285605_10() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate foo 'http://foo/bar'\n" +
			"Y: x+=X? x+=X;\n" +
			"X: name=ID;\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.getSeverity(), Diagnostic.OK);
	assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
 
Example #15
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkAssignmentToFinalVariable() {
	Statechart statechart = AbstractTestModelsUtil
			.loadStatechart(VALIDATION_TESTMODEL_DIR + "AssignmentToValue.sct");
	Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
	assertIssueCount(diagnostics, 2);
	assertError(diagnostics, ERROR_ASSIGNMENT_TO_CONST_MSG);
}
 
Example #16
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_281660() throws Exception {
	XtextResource resource = getResourceFromStringAndExpect(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate foo 'http://foo/bar'\n" +
			"RuleA : foo += [RuleB] ('->' foo+=RuleB)*;\n" +
			"RuleB : 'holla' name=ID;", 1);
	assertTrue(resource.getErrors().toString(), resource.getErrors().size()==1);
	assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());

	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	assertNotNull("diag", diag);
	assertEquals(diag.getSeverity(), Diagnostic.OK);
	assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
 
Example #17
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
@Ignore("TODO this one should yield a warning, because two different instances of a package (ecore itself) might be referenced.")
public void testBug_280413_03() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"import 'classpath:/org/eclipse/xtext/Xtext.ecore' as xtext\n" +
			"ParserRule returns xtext::ParserRule: name = ID;");
	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.getSeverity(), Diagnostic.OK);
	assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
 
Example #18
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_280413_02() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.Xtext\n" +
			"import 'http://www.eclipse.org/2008/Xtext' as xtext\n" +
			"@Override\n" +
			"ParserRule returns xtext::ParserRule: name = ID;");
	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.getSeverity(), Diagnostic.OK);
	assertTrue(diag.getChildren().toString(), diag.getChildren().isEmpty());
}
 
Example #19
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_280413_01() throws Exception {
	XtextResource resource = getResourceFromStringAndExpect(
			"grammar org.foo.Bar with org.eclipse.xtext.testlanguages.SimpleExpressionsTestLanguage\n" +
			"import 'classpath:/org/eclipse/xtext/testlanguages/SimpleExpressionsTestLanguage.ecore' as mm\n" +
			"Atom returns mm::Atom: name = ID;", 1);
	assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
	assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());

	Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
	assertNotNull("diag", diag);
	assertEquals(diag.getChildren().toString(), 2, diag.getChildren().size());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
	ReferencedMetamodel metamodel = (ReferencedMetamodel) diag.getChildren().get(0).getData().get(0);
	assertNotNull(metamodel);
}
 
Example #20
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkValueDefinitionExpression() {
	Statechart statechart = AbstractTestModelsUtil
			.loadStatechart(VALIDATION_TESTMODEL_DIR + "ConstWithVariable.sct");
	Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
	assertIssueCount(diagnostics, 3); //
	assertError(diagnostics, ExpressionsValidator.REFERENCE_TO_VARIABLE);
	assertError(diagnostics, ExpressionsValidator.CONST_MUST_HAVE_VALUE_MSG);
}
 
Example #21
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testEnumWithEmptyLiteralImported() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" +
			"generate test 'http://foo'\n" +
			"Model: name=ID;\n" +
			"enum ExistingEnum: SameName | DifferentName='Diff' | OverriddenLiteral='';");
	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.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #22
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testEnumWithEmptyLiteralGenerated() 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: NoLiteral | ValidLiteral='literal' | EmptyLiteral='';");
	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.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #23
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testDuplicateEnumLiterals() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" +
			"generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/validation/literal/1'\n" +
			"Model: enumValue=ExistingEnum;\n" +
			"enum ExistingEnum: SameName | DifferentName='SameName';");
	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(), 2, diag.getChildren().size());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #25
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_283534_07() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"Model: ID;\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(), 0, diag.getChildren().size());
	assertEquals("diag.isOk", diag.getSeverity(), Diagnostic.OK);
}
 
Example #26
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_283534_06() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"terminal TERMINAL: ID;\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(), 0, diag.getChildren().size());
	assertEquals("diag.isOk", diag.getSeverity(), Diagnostic.OK);
}
 
Example #27
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_283534_05() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"enum EnumRule: Zonk;\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(), 0, diag.getChildren().size());
	assertEquals("diag.isOk", diag.getSeverity(), Diagnostic.OK);
}
 
Example #28
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_283534_04() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"Model: ID;\n" +
			"SecondModel: name=STRING;\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(), 1, diag.getChildren().size());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #29
Source File: XtextValidationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug_283534_02() throws Exception {
	XtextResource resource = getResourceFromString(
			"grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
			"generate metamodel 'myURI'\n" +
			"enum EnumRule: Zonk;\n"+
			"Model: name=STRING;\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(), 1, diag.getChildren().size());
	assertEquals("diag.isError", diag.getSeverity(), Diagnostic.ERROR);
}
 
Example #30
Source File: STextValidatorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void checkPostFixUnaryExpressionToFinalVariable() {
	Statechart statechart = AbstractTestModelsUtil.loadStatechart(VALIDATION_TESTMODEL_DIR + "IncrementOrDecrementOnConst.sct");
	Diagnostic diagnostics = Diagnostician.INSTANCE.validate(statechart);
	assertIssueCount(diagnostics, 2);
	assertError(diagnostics, ERROR_POST_FIX_TO_CONST_MSG);
}