use of org.eclipse.xtext.util.LazyStringInputStream in project n4js by eclipse.
the class SmokeTestWriter method parse.
@Override
public Script parse(InputStream in, URI uriToUse, Map<?, ?> options, ResourceSet resourceSet) {
if (active) {
if (in instanceof LazyStringInputStream) {
try {
String string = ((LazyStringInputStream) in).getString();
if (string.length() < 1000 && seen.add(string)) {
List<String> lines = CharStreams.readLines(new StringReader(string));
if (lines.size() < 50) {
System.out.println("\t@Test");
System.out.format("\tdef void test_%04d() {", counter++);
System.out.println();
System.out.println("\t\t'''");
for (String s : lines) {
System.out.print("\t\t\t");
System.out.println(s);
}
System.out.println("\t\t'''.assertNoException");
System.out.println("\t}");
System.out.println();
}
}
} catch (IOException e) {
// ignore
}
}
}
return super.parse(in, uriToUse, options, resourceSet);
}
use of org.eclipse.xtext.util.LazyStringInputStream in project xtext-xtend by eclipse.
the class ConvertJavaCode method createResource.
private Resource createResource(IFile file, String content) throws ExecutionException {
ResourceSet set = resourceSetProvider.get(file.getProject());
Resource resource = set.createResource(URI.createPlatformResourceURI(file.getFullPath().toString(), false));
try {
resource.load(new LazyStringInputStream(content, file.getCharset()), null);
} catch (CoreException e) {
handleException("Failed to read file content", e, file);
} catch (IOException e) {
handleException("Failed to load resource.", e, file);
}
return resource;
}
use of org.eclipse.xtext.util.LazyStringInputStream 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 LazyStringInputStream(string, StandardCharsets.ISO_8859_1.name()), 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.util.LazyStringInputStream in project xtext-xtend by eclipse.
the class RichStringEvaluationTest method file.
protected XtendFile file(String string, boolean validate) throws Exception {
XtextResourceSet set = resourceSetProvider.get();
Map<Object, Object> loadOptions = set.getLoadOptions();
loadOptions.put(XtextResource.OPTION_ENCODING, StandardCharsets.ISO_8859_1.name());
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new LazyStringInputStream(string, StandardCharsets.ISO_8859_1.name()), loadOptions);
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
if (validate) {
List<Issue> issues = ((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl);
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.xtext.util.LazyStringInputStream in project xtext-xtend by eclipse.
the class XtendBuilderParticipantTest method testIncrementalBuild.
@Test
public void testIncrementalBuild() throws Exception {
IFile first = testHelper.createFile("incrementalBuild/First", "package incrementalBuild\n" + "import incrementalBuild.Second.I\n" + "class First {\n" + " def m() {} \n" + " def I i() {\n" + " return [ cancelIndicator |\n" + " ]\n" + " }\n" + " def Second get() {}\n" + "}");
assertTrue(first.exists());
IFile second = testHelper.createFile("incrementalBuild/Second", "package incrementalBuild\n" + "import java.util.List\n" + "class Second {\n" + " public First first\n" + " static interface I {\n" + " def List<?> m(Object o)\n" + " }\n" + "}");
assertTrue(second.exists());
waitForBuild();
assertNoErrorsInWorkspace();
IFile firstTarget = testHelper.getProject().getFile("/xtend-gen/incrementalBuild/First.java");
assertTrue(firstTarget.exists());
assertFalse(fileIsEmpty(firstTarget));
IFile secondTarget = testHelper.getProject().getFile("/xtend-gen/incrementalBuild/Second.java");
assertTrue(secondTarget.exists());
assertFalse(fileIsEmpty(secondTarget));
first.setContents(new LazyStringInputStream("package incrementalBuild\n" + "import incrementalBuild.Second.I\n" + "class First {\n" + " // removed def m() {} \n" + " def I i() {\n" + " return [ cancelIndicator |\n" + " ]\n" + " }\n" + " def Second get() {}\n" + "}"), true, true, null);
waitForBuild();
assertTrue(firstTarget.exists());
assertFalse(fileIsEmpty(firstTarget));
assertTrue(secondTarget.exists());
assertFalse(fileIsEmpty(secondTarget));
assertNoErrorsInWorkspace();
}
Aggregations