Search in sources :

Example 16 with IResourceValidator

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

the class XtextValidationTest method testMissingArgument.

@Test
public void testMissingArgument() throws Exception {
    XtextResource resource = getResourceFromString("grammar com.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: rule=Rule<First=true, Second=false>;\n" + "Rule<First, Missing, Second>: 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("Missing argument for parameter Missing", 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 17 with IResourceValidator

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

the class XtextValidationTest method testSupressedWarning_02.

@Test
public void testSupressedWarning_02() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "/* SuppressWarnings[potentialOverride] */\n" + "Parens: \n" + "  ('(' Parens ')'|name=ID) em='!'?;");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertTrue(issues.toString(), issues.isEmpty());
}
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 18 with IResourceValidator

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

the class XtextValidationTest method testSupressedWarning_01.

@Test
public void testSupressedWarning_01() throws Exception {
    XtextResource resource = getResourceFromString("grammar org.acme.Bar with org.eclipse.xtext.common.Terminals\n" + "generate metamodel 'myURI'\n" + "Model: child=Child;\n" + "/* SuppressWarnings[noInstantiation] */\n" + "Child: name=ID?;");
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
    IResourceValidator validator = get(IResourceValidator.class);
    List<Issue> issues = validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    assertTrue(issues.toString(), issues.isEmpty());
}
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 19 with IResourceValidator

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

the class XtendBatchCompiler method validate.

protected List<Issue> validate(ResourceSet resourceSet) {
    List<Issue> issues = Lists.newArrayList();
    List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
    for (Resource resource : resources) {
        IResourceServiceProvider resourceServiceProvider = IResourceServiceProvider.Registry.INSTANCE.getResourceServiceProvider(resource.getURI());
        if (resourceServiceProvider != null && isSourceFile(resource)) {
            IResourceValidator resourceValidator = resourceServiceProvider.getResourceValidator();
            List<Issue> result = resourceValidator.validate(resource, CheckMode.ALL, null);
            addAll(issues, result);
        }
    }
    return issues;
}
Also used : IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Issue(org.eclipse.xtext.validation.Issue) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) XtextResource(org.eclipse.xtext.resource.XtextResource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource)

Example 20 with IResourceValidator

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

the class LinkingTest method testBug345433_02.

@Test
public void testBug345433_02() throws Exception {
    String classAsString = "import static extension org.eclipse.xtext.GrammarUtil.*\n" + "class Foo {" + "	org.eclipse.xtext.Grammar grammar\n" + "	def function1() {\n" + "		grammar.containedRuleCalls.filter(e0 | " + "			!e0.isAssigned() && !e0.isEObjectRuleCall()" + "		).map(e1 | e1.rule)\n" + "	}\n" + "}";
    XtendClass clazz = clazz(classAsString);
    IResourceValidator validator = ((XtextResource) clazz.eResource()).getResourceServiceProvider().getResourceValidator();
    List<Issue> issues = validator.validate(clazz.eResource(), CheckMode.ALL, CancelIndicator.NullImpl);
    assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    XtendFunction function = (XtendFunction) clazz.getMembers().get(1);
    XExpression body = function.getExpression();
    LightweightTypeReference bodyType = getType(body);
    assertEquals("java.lang.Iterable<org.eclipse.xtext.AbstractRule>", bodyType.getIdentifier());
    XBlockExpression block = (XBlockExpression) body;
    XMemberFeatureCall featureCall = (XMemberFeatureCall) block.getExpressions().get(0);
    XClosure closure = (XClosure) featureCall.getMemberCallArguments().get(0);
    JvmFormalParameter e1 = closure.getFormalParameters().get(0);
    assertEquals("e1", e1.getSimpleName());
    assertEquals("org.eclipse.xtext.RuleCall", getType(e1).getIdentifier());
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) Issue(org.eclipse.xtext.validation.Issue) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) XClosure(org.eclipse.xtext.xbase.XClosure) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) XExpression(org.eclipse.xtext.xbase.XExpression) 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