Search in sources :

Example 11 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.

the class XtextValidationTest method testOutOfSequenceArgument_02.

@Test
public void testOutOfSequenceArgument_02() throws Exception {
    XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: rule=Rule<true, B=false, C=true>;\n" + "Rule<A, B, C>: name=ID;");
    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 0, issues.size());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 12 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.

the class XtextValidationTest method testRuleCalledSuper.

@Test
public void testRuleCalledSuper() throws Exception {
    XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: super=super;\n" + "super: name=ID;");
    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("Discouraged rule name 'super'", issues.get(0).getMessage());
    Grammar grammar = (Grammar) resource.getContents().get(0);
    AbstractRule model = grammar.getRules().get(0);
    Assignment assignment = (Assignment) model.getAlternatives();
    RuleCall ruleCall = (RuleCall) assignment.getTerminal();
    assertSame(grammar.getRules().get(1), ruleCall.getRule());
}
Also used : Assignment(org.eclipse.xtext.Assignment) Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 13 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.

the class XtextValidationTest method testExplicitOverride04.

@Test
public void testExplicitOverride04() throws Exception {
    IResourceValidator validator = get(IResourceValidator.class);
    XtextResource resource = getResourceFromString("grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" + "@Override\n" + "terminal ID: ('a'..'z'|'A'..'Z'|'_');");
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 0, issues.size());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 14 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.

the class XtextValidationTest method testDuplicateArgument.

@Test
public void testDuplicateArgument() throws Exception {
    XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: rule=Rule<Single=true, Single=false>;\n" + "Rule<Single>: name=ID;");
    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("Duplicate value for parameter Single", issues.get(0).getMessage());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Example 15 with IResourceValidator

use of org.eclipse.xtext.validation.IResourceValidator in project xtext-core by eclipse.

the class XtextValidationTest method testMissingArgument3.

@Test
public void testMissingArgument3() throws Exception {
    XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: rule=Rule<true>;\n" + "Rule<First, Missing, AlsoMissing>: name=ID;");
    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertEquals(issues.toString(), 1, issues.size());
    assertEquals("Expected 3 arguments but got 1", issues.get(0).getMessage());
}
Also used : Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XtextResource(org.eclipse.xtext.resource.XtextResource) Test(org.junit.Test)

Aggregations

IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)23 Issue (org.eclipse.xtext.validation.Issue)18 XtextResource (org.eclipse.xtext.resource.XtextResource)16 Test (org.junit.Test)14 Resource (org.eclipse.emf.ecore.resource.Resource)7 IResourceServiceProvider (org.eclipse.xtext.resource.IResourceServiceProvider)4 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 URI (org.eclipse.emf.common.util.URI)2 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 MarkerCreator (org.eclipse.xtext.ui.editor.validation.MarkerCreator)2 RevisionIndex (com.b2international.index.revision.RevisionIndex)1 Builder (com.b2international.snowowl.test.commons.snomed.TestBranchContext.Builder)1 Injector (com.google.inject.Injector)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 Model (org.eclipse.vorto.core.api.model.model.Model)1