Search in sources :

Example 16 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class DeferredTypeParameterHintCollectorTest method createOwner.

@Override
protected StandardTypeReferenceOwner createOwner() {
    CommonTypeComputationServices _services = this.getServices();
    ResourceSet _contextResourceSet = this.getContextResourceSet();
    return new StandardTypeReferenceOwner(_services, _contextResourceSet) {

        @Override
        public void acceptHint(final Object handle, final LightweightBoundTypeArgument boundTypeArgument) {
            DeferredTypeParameterHintCollectorTest.this.hints.put(handle, boundTypeArgument);
        }

        @Override
        public List<LightweightBoundTypeArgument> getAllHints(final Object handle) {
            return DeferredTypeParameterHintCollectorTest.this.hints.get(handle);
        }

        @Override
        public boolean isResolved(final Object handle) {
            return false;
        }
    };
}
Also used : CommonTypeComputationServices(org.eclipse.xtext.xbase.typesystem.util.CommonTypeComputationServices) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 17 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class ValidationBug450834Test method test_01.

@Test
public void test_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("public static val c1 = 5");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFile c = this.parser.parse(_builder);
        final ResourceSet resourceSet = c.eResource().getResourceSet();
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("class D {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("public static val d1 = 5");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void m() {");
        _builder_1.newLine();
        _builder_1.append("\t\t");
        _builder_1.append("if (C.c1 == D.d1) {");
        _builder_1.newLine();
        _builder_1.append("\t\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final XtendFile d = this.parser.parse(_builder_1, resourceSet);
        this.helper.assertWarning(d, XbasePackage.Literals.XBINARY_OPERATION, IssueCodes.CONSTANT_BOOLEAN_CONDITION, "Constant condition is always true");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.Test)

Example 18 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class JavaIoFileSystemTest method setUp.

@Before
public void setUp() {
    try {
        final File tempDir = this.temporaryFolder.newFolder();
        JavaIOFileSystemSupport _javaIOFileSystemSupport = new JavaIOFileSystemSupport();
        final Procedure1<JavaIOFileSystemSupport> _function = (JavaIOFileSystemSupport it) -> {
            final IProjectConfigProvider _function_1 = (ResourceSet it_1) -> {
                File _file = new File(tempDir, "foo");
                FileProjectConfig _fileProjectConfig = new FileProjectConfig(_file);
                final Procedure1<FileProjectConfig> _function_2 = (FileProjectConfig it_2) -> {
                    it_2.addSourceFolder("src");
                };
                return ObjectExtensions.<FileProjectConfig>operator_doubleArrow(_fileProjectConfig, _function_2);
            };
            it.setProjectConfigProvider(_function_1);
            IEncodingProvider.Runtime _runtime = new IEncodingProvider.Runtime();
            it.setEncodingProvider(_runtime);
            XtextResourceSet _xtextResourceSet = new XtextResourceSet();
            it.setContext(_xtextResourceSet);
        };
        JavaIOFileSystemSupport _doubleArrow = ObjectExtensions.<JavaIOFileSystemSupport>operator_doubleArrow(_javaIOFileSystemSupport, _function);
        this.fs = _doubleArrow;
        this.createProject("foo");
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JavaIOFileSystemSupport(org.eclipse.xtend.core.macro.JavaIOFileSystemSupport) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IEncodingProvider(org.eclipse.xtext.parser.IEncodingProvider) IProjectConfigProvider(org.eclipse.xtext.workspace.IProjectConfigProvider) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) FileProjectConfig(org.eclipse.xtext.workspace.FileProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 19 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class XtendResourceSetBasedResourceDescriptionsTest method testBidirectionalRef.

@Test
public void testBidirectionalRef() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo class ClassA extends bar.ClassB {}");
        Pair<String, String> _mappedTo = Pair.<String, String>of("foo/ClassA.xtend", _builder.toString());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package bar class ClassB { public foo.ClassA myField }");
        Pair<String, String> _mappedTo_1 = Pair.<String, String>of("bar/ClassB.xtend", _builder_1.toString());
        final ResourceSet resourceSet = this.compiler.resourceSet(_mappedTo, _mappedTo_1);
        final List<? extends Resource> resources = resourceSet.getResources();
        ArrayList<Resource> _arrayList = new ArrayList<Resource>(resources);
        for (final Resource res : _arrayList) {
            {
                final List<Issue> issues = this.validator.validate(res, CheckMode.ALL, CancelIndicator.NullImpl);
                Assert.assertTrue(issues.toString(), issues.isEmpty());
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) DerivedStateAwareResource(org.eclipse.xtext.resource.DerivedStateAwareResource) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.Test)

Example 20 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.

the class TestCaseCompiler method compile.

public void compile(String qualifiedName) throws IOException {
    ResourceSet set = injector.getInstance(ResourceSet.class);
    final String from = "src/" + qualifiedName.replace('.', '/') + ".xtend";
    final String to = "src-gen/" + qualifiedName.replace('.', '/') + ".java";
    Resource res = set.getResource(org.eclipse.emf.common.util.URI.createFileURI(from), true);
    EcoreUtil.resolveAll(res);
    if (!res.getErrors().isEmpty())
        throw new RuntimeException(res.getErrors().toString());
    final File file = new File(to);
    createFolders(file);
    FileWriter writer = new FileWriter(file);
    IXtendJvmAssociations associations = injector.getInstance(IXtendJvmAssociations.class);
    JvmModelGenerator generator = injector.getInstance(JvmModelGenerator.class);
    XtendFile xtendFile = (XtendFile) res.getContents().get(0);
    JvmGenericType inferredType = associations.getInferredType((XtendClass) xtendFile.getXtendTypes().get(0));
    GeneratorConfig config = injector.getInstance(IGeneratorConfigProvider.class).get(inferredType);
    CharSequence javaCode = generator.generateType(inferredType, config);
    writer.append(javaCode);
    writer.close();
    System.out.println("compiled " + from + " to " + to);
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmModelGenerator(org.eclipse.xtext.xbase.compiler.JvmModelGenerator) FileWriter(java.io.FileWriter) Resource(org.eclipse.emf.ecore.resource.Resource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) GeneratorConfig(org.eclipse.xtext.xbase.compiler.GeneratorConfig) IGeneratorConfigProvider(org.eclipse.xtext.xbase.compiler.IGeneratorConfigProvider) IXtendJvmAssociations(org.eclipse.xtend.core.jvmmodel.IXtendJvmAssociations) File(java.io.File) XtendFile(org.eclipse.xtend.core.xtend.XtendFile)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8