Search in sources :

Example 16 with Issue

use of org.eclipse.xtext.validation.Issue in project xtext-eclipse by eclipse.

the class AbstractIncrementalBuilderTest method newBuildRequest.

protected BuildRequest newBuildRequest(final Procedure1<? super BuildRequest> init) {
    BuildRequest _buildRequest = new BuildRequest();
    final Procedure1<BuildRequest> _function = (BuildRequest it) -> {
        final ResourceDescriptionsData newIndex = this.indexState.getResourceDescriptions().copy();
        it.setBaseDir(this.uri(""));
        XtextResourceSet _get = this.resourceSetProvider.get();
        final Procedure1<XtextResourceSet> _function_1 = (XtextResourceSet it_1) -> {
            it_1.getURIConverter().getURIHandlers().clear();
            EList<URIHandler> _uRIHandlers = it_1.getURIConverter().getURIHandlers();
            _uRIHandlers.add(this.inMemoryURIHandler);
            it_1.setClasspathURIContext(AbstractIncrementalBuilderTest.class.getClassLoader());
            ProjectDescription _projectDescription = new ProjectDescription();
            final Procedure1<ProjectDescription> _function_2 = (ProjectDescription it_2) -> {
                it_2.setName("test-project");
            };
            final ProjectDescription projectDescription = ObjectExtensions.<ProjectDescription>operator_doubleArrow(_projectDescription, _function_2);
            projectDescription.attachToEmfObject(it_1);
            Map<String, ResourceDescriptionsData> _emptyMap = CollectionLiterals.<String, ResourceDescriptionsData>emptyMap();
            final ChunkedResourceDescriptions index = new ChunkedResourceDescriptions(_emptyMap, it_1);
            index.setContainer(projectDescription.getName(), newIndex);
        };
        XtextResourceSet _doubleArrow = ObjectExtensions.<XtextResourceSet>operator_doubleArrow(_get, _function_1);
        it.setResourceSet(_doubleArrow);
        it.setDirtyFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        it.setDeletedFiles(Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList()));
        final BuildRequest.IPostValidationCallback _function_2 = (URI uri, Iterable<Issue> issues) -> {
            Iterables.<Issue>addAll(this.issues, issues);
            return IterableExtensions.isEmpty(issues);
        };
        it.setAfterValidate(_function_2);
        final Procedure1<URI> _function_3 = (URI it_1) -> {
            this.deleted.add(it_1);
        };
        it.setAfterDeleteFile(_function_3);
        final Procedure2<URI, URI> _function_4 = (URI source, URI target) -> {
            this.generated.put(source, target);
        };
        it.setAfterGenerateFile(_function_4);
        Source2GeneratedMapping _copy = this.indexState.getFileMappings().copy();
        IndexState _indexState = new IndexState(newIndex, _copy);
        it.setState(_indexState);
    };
    final BuildRequest result = ObjectExtensions.<BuildRequest>operator_doubleArrow(_buildRequest, _function);
    init.apply(result);
    return result;
}
Also used : Issue(org.eclipse.xtext.validation.Issue) Source2GeneratedMapping(org.eclipse.xtext.build.Source2GeneratedMapping) ChunkedResourceDescriptions(org.eclipse.xtext.resource.impl.ChunkedResourceDescriptions) BuildRequest(org.eclipse.xtext.build.BuildRequest) URI(org.eclipse.emf.common.util.URI) IndexState(org.eclipse.xtext.build.IndexState) ResourceDescriptionsData(org.eclipse.xtext.resource.impl.ResourceDescriptionsData) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Procedure2(org.eclipse.xtext.xbase.lib.Procedures.Procedure2) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) URIHandler(org.eclipse.emf.ecore.resource.URIHandler) InMemoryURIHandler(org.eclipse.xtext.junit4.util.InMemoryURIHandler) ProjectDescription(org.eclipse.xtext.resource.impl.ProjectDescription)

Example 17 with Issue

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

the class AbstractXtendTestCase method file.

protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
    XtextResourceSet set = getResourceSet();
    String fileName = getFileName(string);
    Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
    resource.load(new StringInputStream(string), null);
    if (shouldBeSyntacticallyValid) {
        assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
    }
    if (validate) {
        List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {

            @Override
            public boolean apply(Issue issue) {
                return issue.getSeverity() == Severity.ERROR;
            }
        }));
        assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
    }
    XtendFile file = (XtendFile) resource.getContents().get(0);
    return file;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringInputStream(org.eclipse.xtext.util.StringInputStream) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Predicate(com.google.common.base.Predicate)

Example 18 with Issue

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

the class ReducedXtextResourceValidatorTest method testRuleLinkingErrors.

@Test
public void testRuleLinkingErrors() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("import \'http://test\' as test");
    _builder.newLine();
    _builder.append("Root returns test::Foo : name=IDS;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    final List<Issue> issues = this.resourceValidator.validate(this.getErroneousResource(grammarAsString), CheckMode.NORMAL_AND_FAST, CancelIndicator.NullImpl);
    Assert.assertEquals(issues.toString(), 1, issues.size());
    Assert.assertTrue(issues.toString(), IterableExtensions.<Issue>head(issues).getMessage().contains("IDS"));
}
Also used : Issue(org.eclipse.xtext.validation.Issue) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 19 with Issue

use of org.eclipse.xtext.validation.Issue in project smarthome by eclipse.

the class ScriptEngineImpl method parseScriptIntoXTextEObject.

private XExpression parseScriptIntoXTextEObject(String scriptAsString) throws ScriptParsingException {
    XtextResourceSet resourceSet = getResourceSet();
    // IS-A XtextResource
    Resource resource = resourceSet.createResource(computeUnusedUri(resourceSet));
    try {
        resource.load(new StringInputStream(scriptAsString, StandardCharsets.UTF_8.name()), resourceSet.getLoadOptions());
    } catch (IOException e) {
        throw new ScriptParsingException("Unexpected IOException; from close() of a String-based ByteArrayInputStream, no real I/O; how is that possible???", scriptAsString, e);
    }
    List<Diagnostic> errors = resource.getErrors();
    if (errors.size() != 0) {
        throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors);
    }
    EList<EObject> contents = resource.getContents();
    if (!contents.isEmpty()) {
        Iterable<Issue> validationErrors = getValidationErrors(contents.get(0));
        if (!validationErrors.iterator().hasNext()) {
            return (XExpression) contents.get(0);
        } else {
            throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors);
        }
    } else {
        return null;
    }
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) ScriptParsingException(org.eclipse.smarthome.model.script.engine.ScriptParsingException) Issue(org.eclipse.xtext.validation.Issue) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.emf.ecore.resource.Resource.Diagnostic) XExpression(org.eclipse.xtext.xbase.XExpression) IOException(java.io.IOException)

Example 20 with Issue

use of org.eclipse.xtext.validation.Issue in project n4js by eclipse.

the class AccessControlTest method executeSpecification.

private static void executeSpecification(TestSpecification specification) throws IOException {
    deleteFixtureDirectory();
    boolean failOnExit = specification.getExpectation().isFixMe();
    Map<MemberType, List<String>> fixMeMessages = new HashMap<>();
    for (MemberType memberType : MemberType.values()) {
        createFixtureDirectory(memberType);
        ScenarioGenerator generator = new ScenarioGenerator(specification, memberType);
        generator.generateScenario(Paths.get(FIXTURE_ROOT, memberType.name()));
        List<Issue> issues = new ArrayList<>(compile(memberType));
        issues.removeIf(issue -> N4JSLanguageConstants.DEFAULT_SUPPRESSED_ISSUE_CODES_FOR_TESTS.contains(issue.getCode()));
        IssueExpectations expectations = generator.createIssues();
        if (specification.getExpectation().isFixMe()) {
            // We want the entire test case to fail only if none of the tested scenarios match their
            // expectations.
            List<String> messages = new ArrayList<>();
            final boolean fixMeFailed = !expectations.matchesExactly(issues, messages);
            if (fixMeFailed)
                fixMeMessages.put(memberType, messages);
            failOnExit &= fixMeFailed;
        } else {
            List<String> messages = new ArrayList<>();
            boolean result = expectations.matchesExactly(issues, messages);
            assertTrue(Joiner.on(", ").join(messages), result);
            messages.clear();
        }
    }
    if (failOnExit) {
        StringBuilder message = new StringBuilder();
        for (Map.Entry<MemberType, List<String>> entry : fixMeMessages.entrySet()) {
            final MemberType memberType = entry.getKey();
            final List<String> messages = entry.getValue();
            message.append("FixMe test failed for member type ").append(memberType).append(": \n");
            for (String line : messages) message.append("    ").append(line).append("\n");
        }
        fail(message.toString());
    }
}
Also used : Issue(org.eclipse.xtext.validation.Issue) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IssueExpectations(org.eclipse.n4js.tests.issues.IssueExpectations)

Aggregations

Issue (org.eclipse.xtext.validation.Issue)105 Test (org.junit.Test)38 XtextResource (org.eclipse.xtext.resource.XtextResource)33 Resource (org.eclipse.emf.ecore.resource.Resource)21 IResourceValidator (org.eclipse.xtext.validation.IResourceValidator)18 URI (org.eclipse.emf.common.util.URI)16 List (java.util.List)14 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)12 IssueResolution (org.eclipse.xtext.ui.editor.quickfix.IssueResolution)12 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)11 ArrayList (java.util.ArrayList)9 Severity (org.eclipse.xtext.diagnostics.Severity)9 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)9 EObject (org.eclipse.emf.ecore.EObject)8 IOException (java.io.IOException)7 CoreException (org.eclipse.core.runtime.CoreException)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 StringInputStream (org.eclipse.xtext.util.StringInputStream)7 Diagnostic (org.eclipse.emf.ecore.resource.Resource.Diagnostic)6 IssueResolutionAcceptor (org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor)6