Search in sources :

Example 31 with JvmType

use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.

the class LinkingTest method doTestNestedTypeResolution.

protected void doTestNestedTypeResolution(String input, boolean success) throws Exception {
    XtendFile file = file(input);
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XtendParameter firstParameter = m.getParameters().get(0);
    JvmType parameterType = firstParameter.getParameterType().getType();
    if (success)
        assertEquals("org.eclipse.emf.ecore.EDataType$Internal$ConversionDelegate$Factory$Registry", parameterType.getIdentifier());
    else
        assertTrue(parameterType.eIsProxy());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 32 with JvmType

use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.

the class XtendQuickfixProvider method getExceptions.

/**
 * @param all but the last element in the issue data is considered to be a URI to an exception type.
 */
protected List<JvmType> getExceptions(String[] issueData, XtextResource resource) {
    List<JvmType> exceptions = Lists.newArrayList();
    for (int i = 0; i < issueData.length - 1; i++) {
        URI exceptionURI = URI.createURI(issueData[i]);
        EObject exception = resource.getResourceSet().getEObject(exceptionURI, true);
        if (exception instanceof JvmType) {
            exceptions.add((JvmType) exception);
        }
    }
    return exceptions;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI)

Example 33 with JvmType

use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testEnumReference.

@Test
public void testEnumReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def baz(Foo f){}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("enum Foo { BAR, BAZ }");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendMember _head = IterableExtensions.<XtendMember>head(IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes()).getMembers());
        final JvmType en = IterableExtensions.<XtendParameter>head(((XtendFunction) _head).getParameters()).getParameterType().getType();
        Assert.assertEquals("Foo", this.signatureProvider.getSignature(en));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 34 with JvmType

use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.

the class XtendHoverSignatureProviderTest method testAnnotationReference.

@Test
public void testAnnotationReference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package testPackage");
        _builder.newLine();
        _builder.append("@Foo");
        _builder.newLine();
        _builder.append("class Bar {}");
        _builder.newLine();
        _builder.append("annotation Foo { }");
        _builder.newLine();
        final XtendFile xtendFile = this.parseHelper.parse(_builder, this.getResourceSet());
        XtendTypeDeclaration _head = IterableExtensions.<XtendTypeDeclaration>head(xtendFile.getXtendTypes());
        final JvmType in = IterableExtensions.<XAnnotation>head(((XtendClass) _head).getAnnotations()).getAnnotationType();
        Assert.assertEquals("Foo", this.signatureProvider.getSignature(in));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmType(org.eclipse.xtext.common.types.JvmType) Test(org.junit.Test)

Example 35 with JvmType

use of org.eclipse.xtext.common.types.JvmType in project xtext-xtend by eclipse.

the class ResourceStorageTest method testUpstreamResourcesAreLoadedFromStorage.

@Test
public void testUpstreamResourcesAreLoadedFromStorage() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package mypack");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class MyClass {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        this.helper.createFile("mypack/MyClass.xtend", _builder.toString());
        final IProject downStreamProject = WorkbenchTestHelper.createPluginProject("downstream", this.helper.getProject().getName());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("package downstream");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("class SomeClass {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("def void foo(mypack.MyClass myClass) {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("}");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        final IFile downstreamFile = this.helper.createFileImpl("/downstream/src/downstream/SomeClass.xtend", _builder_1.toString());
        IResourcesSetupUtil.waitForBuild();
        final URI downstreamUri = this.uriMapper.getUri(downstreamFile);
        final ResourceSet resourceSet = this.resourceSetProvider.get(downStreamProject);
        SourceLevelURIsAdapter.setSourceLevelUris(resourceSet, Collections.<URI>unmodifiableList(CollectionLiterals.<URI>newArrayList(downstreamUri)));
        Resource _resource = resourceSet.getResource(downstreamUri, true);
        final StorageAwareResource downstreamResource = ((StorageAwareResource) _resource);
        EObject _get = downstreamResource.getContents().get(1);
        final JvmGenericType type = ((JvmGenericType) _get);
        final JvmType parameterType = IterableExtensions.<JvmFormalParameter>head(IterableExtensions.<JvmOperation>head(Iterables.<JvmOperation>filter(type.getMembers(), JvmOperation.class)).getParameters()).getParameterType().getType();
        Assert.assertNotNull(parameterType);
        Resource _eResource = parameterType.eResource();
        Assert.assertTrue(((StorageAwareResource) _eResource).isLoadedFromStorage());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Resource(org.eclipse.emf.ecore.resource.Resource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmType(org.eclipse.xtext.common.types.JvmType) URI(org.eclipse.emf.common.util.URI) AbsoluteURI(org.eclipse.xtext.generator.trace.AbsoluteURI) SourceRelativeURI(org.eclipse.xtext.generator.trace.SourceRelativeURI) IProject(org.eclipse.core.resources.IProject) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

JvmType (org.eclipse.xtext.common.types.JvmType)73 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)29 EObject (org.eclipse.emf.ecore.EObject)18 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)17 Test (org.junit.Test)17 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)14 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 XExpression (org.eclipse.xtext.xbase.XExpression)12 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)11 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)10 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)9 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)9 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)8 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)8 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)8 Resource (org.eclipse.emf.ecore.resource.Resource)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)6 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)6