Search in sources :

Example 1 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 2 with LazyStringInputStream

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;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) LazyStringInputStream(org.eclipse.xtext.util.LazyStringInputStream) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException)

Example 3 with LazyStringInputStream

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;
}
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) Predicate(com.google.common.base.Predicate)

Example 4 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 5 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)7 Resource (org.eclipse.emf.ecore.resource.Resource)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 IOException (java.io.IOException)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)2 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)2 Issue (org.eclipse.xtext.validation.Issue)2 Test (org.junit.Test)2 Predicate (com.google.common.base.Predicate)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 RichString (org.eclipse.xtend.core.xtend.RichString)1 Assignment (org.eclipse.xtext.Assignment)1 Grammar (org.eclipse.xtext.Grammar)1 Group (org.eclipse.xtext.Group)1 NamedArgument (org.eclipse.xtext.NamedArgument)1 ParserRule (org.eclipse.xtext.ParserRule)1