Search in sources :

Example 31 with JvmMember

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

the class XtendReferenceFinder method addReferenceToTypeFromStaticImport.

protected void addReferenceToTypeFromStaticImport(final XAbstractFeatureCall sourceCandidate, final Predicate<URI> targetURISet, final IReferenceFinder.Acceptor acceptor) {
    final JvmIdentifiableElement feature = sourceCandidate.getFeature();
    if ((feature instanceof JvmMember)) {
        final JvmDeclaredType type = ((JvmMember) feature).getDeclaringType();
        this.addReferenceIfTarget(type, targetURISet, sourceCandidate, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, acceptor);
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 32 with JvmMember

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

the class SyntheticNameClashResolver method resolveNameClashes.

public void resolveNameClashes(JvmGenericType type) {
    Multimap<String, JvmIdentifiableElement> classScope = HashMultimap.create();
    List<JvmMember> renameableMembers = newArrayList();
    int i = 1;
    for (JvmMember member : type.getMembers()) {
        String simpleName = member.getSimpleName();
        if (simpleName != null) {
            if (!isRenameable(member))
                classScope.put(simpleName, member);
            else
                renameableMembers.add(member);
        }
        if (member instanceof JvmFeature) {
            for (JvmGenericType localType : ((JvmFeature) member).getLocalClasses()) {
                localType.setSimpleName(localType.getSimpleName() + '_' + (i++));
            }
        }
    }
    for (JvmMember renameable : renameableMembers) {
        String simpleName = renameable.getSimpleName();
        if (collides(renameable, simpleName, classScope)) {
            int count = 0;
            String currentName;
            do {
                if (count == Integer.MAX_VALUE)
                    throw new IllegalStateException("Cannot find a collision-free name for " + renameable.getIdentifier());
                currentName = simpleName + "_" + ++count;
            } while (collides(renameable, currentName, classScope));
            renameable.setSimpleName(currentName);
            classScope.put(currentName, renameable);
        } else {
            classScope.put(simpleName, renameable);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmFeature(org.eclipse.xtext.common.types.JvmFeature) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 33 with JvmMember

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

the class ResourceStorageTest method testConstantValueIsPersisted.

@Test
public void testConstantValueIsPersisted() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("static val CONSTANT = \'a\' + \'b\' + 0");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final String contents = _builder.toString();
        final XtendFile file = this.file(contents);
        final ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
        Resource _eResource = file.eResource();
        this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
        byte[] _byteArray = bout.toByteArray();
        ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
        final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
        Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
        final StorageAwareResource resource = ((StorageAwareResource) _createResource);
        final InMemoryURIConverter converter = new InMemoryURIConverter();
        converter.addModel(resource.getURI().toString(), contents);
        ResourceSet _resourceSet = resource.getResourceSet();
        _resourceSet.setURIConverter(converter);
        EList<Resource> _resources = file.eResource().getResourceSet().getResources();
        _resources.add(resource);
        resource.loadFromStorage(in);
        EObject _get = resource.getContents().get(1);
        final JvmGenericType jvmClass = ((JvmGenericType) _get);
        JvmMember _last = IterableExtensions.<JvmMember>last(jvmClass.getMembers());
        final JvmField field = ((JvmField) _last);
        Assert.assertTrue(field.isConstant());
        Assert.assertTrue(field.isSetConstant());
        Assert.assertEquals("ab0", field.getConstantValue());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) InMemoryURIConverter(org.eclipse.xtend.core.tests.util.InMemoryURIConverter) ResourceStorageFacade(org.eclipse.xtext.resource.persistence.ResourceStorageFacade) IResourceStorageFacade(org.eclipse.xtext.resource.persistence.IResourceStorageFacade) Resource(org.eclipse.emf.ecore.resource.Resource) BatchLinkableResource(org.eclipse.xtext.xbase.resource.BatchLinkableResource) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StorageAwareResource(org.eclipse.xtext.resource.persistence.StorageAwareResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Test(org.junit.Test)

Example 34 with JvmMember

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

the class JvmModelTests method testAnonymousClass_02.

@Test
public void testAnonymousClass_02() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Runnable() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override run() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(this.function(_builder.toString()));
        this.typeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals(1, operation.getLocalClasses().size());
        final JvmGenericType anonymous = IterableExtensions.<JvmGenericType>head(operation.getLocalClasses());
        Assert.assertTrue(anonymous.isFinal());
        Assert.assertFalse(anonymous.isStatic());
        Assert.assertTrue(anonymous.isLocal());
        Assert.assertTrue(anonymous.isAnonymous());
        Assert.assertEquals(JvmVisibility.DEFAULT, anonymous.getVisibility());
        Assert.assertEquals(2, anonymous.getSuperTypes().size());
        Assert.assertEquals("java.lang.Runnable", IterableExtensions.<JvmTypeReference>last(anonymous.getSuperTypes()).getQualifiedName());
        Assert.assertEquals(2, anonymous.getMembers().size());
        final JvmMember constructor = IterableExtensions.<JvmMember>last(anonymous.getMembers());
        Assert.assertTrue((constructor instanceof JvmConstructor));
        Assert.assertEquals(0, ((JvmConstructor) constructor).getParameters().size());
        final JvmMember overriding = IterableExtensions.<JvmMember>head(anonymous.getMembers());
        Assert.assertTrue((overriding instanceof JvmOperation));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 35 with JvmMember

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

the class JvmModelTests method testEnumInAnnotationIsStatic.

@Test
public void testEnumInAnnotationIsStatic() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("enum E { L0, L1 }");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final JvmAnnotationType inferred = this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString()));
        JvmMember _head = IterableExtensions.<JvmMember>head(inferred.getMembers());
        final JvmEnumerationType e = ((JvmEnumerationType) _head);
        Assert.assertTrue(e.isStatic());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Test(org.junit.Test)

Aggregations

JvmMember (org.eclipse.xtext.common.types.JvmMember)41 Test (org.junit.Test)22 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)21 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)15 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)15 EObject (org.eclipse.emf.ecore.EObject)14 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)12 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)12 JvmField (org.eclipse.xtext.common.types.JvmField)12 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)7 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)6 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)6 MemberDeclaration (org.eclipse.xtend.lib.macro.declaration.MemberDeclaration)4 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)4 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)4 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)3 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)3