Search in sources :

Example 6 with LazyStringInputStream

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);
}
Also used : LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) StringReader(java.io.StringReader) IOException(java.io.IOException)

Example 7 with LazyStringInputStream

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());
}
Also used : Assignment(org.eclipse.xtext.Assignment) ParserRule(org.eclipse.xtext.ParserRule) Group(org.eclipse.xtext.Group) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) Grammar(org.eclipse.xtext.Grammar) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) NamedArgument(org.eclipse.xtext.NamedArgument) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 8 with LazyStringInputStream

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;
    }
}
Also used : LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream)

Example 9 with LazyStringInputStream

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;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) 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) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) XtextResource(org.eclipse.xtext.resource.XtextResource) RichString(org.eclipse.xtend.core.xtend.RichString)

Example 10 with LazyStringInputStream

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();
}
Also used : IFile(org.eclipse.core.resources.IFile) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) Test(org.junit.Test)

Aggregations

LazyStringInputStream (org.eclipse.xtext.util.LazyStringInputStream)10 Resource (org.eclipse.emf.ecore.resource.Resource)6 IOException (java.io.IOException)5 XtextResource (org.eclipse.xtext.resource.XtextResource)5 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 Issue (org.eclipse.xtext.validation.Issue)2 Test (org.junit.Test)2 Predicate (com.google.common.base.Predicate)1 JsonParseException (com.google.gson.JsonParseException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 EObject (org.eclipse.emf.ecore.EObject)1 RichString (org.eclipse.xtend.core.xtend.RichString)1 Assignment (org.eclipse.xtext.Assignment)1