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;
}
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;
}
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"));
}
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;
}
}
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());
}
}
Aggregations