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-core by eclipse.
the class XtextLinkerTest method testNamedParameterAdjustment.
@Test
public void testNamedParameterAdjustment() throws Exception {
String grammarAsString = "grammar test.Lang with org.eclipse.xtext.common.Terminals\n" + "generate test 'http://test'\n" + "Root<MyParam>: rule=Rule<true>;\n" + "Rule<MyParam>: name=ID child=Root<false>?;\n";
Grammar grammar = (Grammar) getModel(grammarAsString);
ResourceSet resourceSet = grammar.eResource().getResourceSet();
Resource otherResource = resourceSet.createResource(URI.createURI("other.xtext"));
String otheGrammar = "grammar test.SubLang with test.Lang\n" + "import 'http://test'\n" + "Root<MyParam>: rule=super::Rule<true>;\n";
otherResource.load(new LazyStringInputStream(otheGrammar), null);
Grammar subGrammar = (Grammar) Iterables.getFirst(otherResource.getContents(), null);
ParserRule rootRule = (ParserRule) Iterables.getFirst(subGrammar.getRules(), null);
ParserRule parentRule = (ParserRule) Iterables.getLast(grammar.getRules());
Assignment getLastAssignment = (Assignment) Iterables.getLast(((Group) parentRule.getAlternatives()).getElements());
RuleCall ruleCall = (RuleCall) getLastAssignment.getTerminal();
NamedArgument argument = Iterables.getFirst(ruleCall.getArguments(), null);
Assert.assertEquals(Iterables.getFirst(rootRule.getParameters(), null), argument.getParameter());
Assert.assertFalse(((LiteralCondition) argument.getValue()).isTrue());
}
use of org.eclipse.xtext.util.LazyStringInputStream in project xtext-core by eclipse.
the class XtextResource method reparse.
public void reparse(String newContent) throws IOException {
try {
isUpdating = true;
clearInternalState();
doLoad(new LazyStringInputStream(newContent, getEncoding()), null);
setModified(false);
} finally {
isUpdating = false;
}
}
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