Search in sources :

Example 6 with JvmMember

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

the class AbstractXtendOutlineTreeBuilder method buildMembers.

protected void buildMembers(final JvmDeclaredType inferredType, final JvmDeclaredType baseType, @Extension final IXtendOutlineContext context) {
    EList<JvmMember> _members = inferredType.getMembers();
    for (final JvmMember member : _members) {
        boolean _isProcessed = context.isProcessed(member);
        boolean _not = (!_isProcessed);
        if (_not) {
            if ((member instanceof JvmDeclaredType)) {
                boolean _isShowInherited = context.isShowInherited();
                if (_isShowInherited) {
                    final IXtendOutlineContext typeContext = context.newContext();
                    final EObject sourceElement = this._iXtendJvmAssociations.getPrimarySourceElement(member);
                    if ((sourceElement instanceof XtendTypeDeclaration)) {
                        this.buildType(sourceElement, typeContext);
                    } else {
                        this.buildJvmType(((JvmDeclaredType) member), typeContext);
                    }
                } else {
                    this.buildJvmType(((JvmDeclaredType) member), context);
                }
            } else {
                if ((member instanceof JvmFeature)) {
                    boolean _skipFeature = this.skipFeature(((JvmFeature) member));
                    boolean _not_1 = (!_skipFeature);
                    if (_not_1) {
                        final IXtendOutlineContext featureContext = this.buildFeature(baseType, ((JvmFeature) member), member, context);
                        final Consumer<JvmGenericType> _function = (JvmGenericType it) -> {
                            this.buildJvmType(it, featureContext.newContext());
                        };
                        ((JvmFeature) member).getLocalClasses().forEach(_function);
                    }
                }
            }
            context.markAsProcessed(member);
        }
    }
    boolean _isShowInherited_1 = context.isShowInherited();
    if (_isShowInherited_1) {
        this.buildInheritedMembers(inferredType, context);
    }
}
Also used : JvmFeature(org.eclipse.xtext.common.types.JvmFeature) IXtendOutlineContext(org.eclipse.xtend.ide.common.outline.IXtendOutlineContext) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember)

Example 7 with JvmMember

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

the class ResourceStorageTest method testConstantValueIsPersisted_01.

@Test
public void testConstantValueIsPersisted_01() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class C {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("static val CONSTANT = Object");
        _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.assertFalse(field.isConstant());
        Assert.assertTrue(field.isSetConstant());
        Assert.assertNull(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 8 with JvmMember

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

the class JvmModelTests method testEnumArtificialMethods.

@Test
public void testEnumArtificialMethods() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package bar");
        _builder.newLine();
        _builder.newLine();
        _builder.append("enum Foo {");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final EList<JvmMember> inferred = this._iXtendJvmAssociations.getInferredEnumerationType(this.enumeration(_builder.toString())).getMembers();
        Assert.assertEquals(2, inferred.size());
        JvmMember _get = inferred.get(0);
        final JvmOperation values = ((JvmOperation) _get);
        Assert.assertEquals("bar.Foo.values()", values.getIdentifier());
        Assert.assertTrue(values.isStatic());
        Assert.assertEquals(JvmVisibility.PUBLIC, values.getVisibility());
        JvmMember _get_1 = inferred.get(1);
        final JvmOperation valueOf = ((JvmOperation) _get_1);
        Assert.assertEquals("bar.Foo.valueOf(java.lang.String)", valueOf.getIdentifier());
        Assert.assertTrue(valueOf.isStatic());
        Assert.assertEquals(JvmVisibility.PUBLIC, valueOf.getVisibility());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) Test(org.junit.Test)

Example 9 with JvmMember

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

the class JvmModelTests method testEmptyListAsAnnotationValueDefault.

@Test
public void testEmptyListAsAnnotationValueDefault() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("String[] bar = #[]");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
        final JvmOperation inferred = ((JvmOperation) _head);
        Assert.assertEquals("java.lang.String[]", inferred.getReturnType().getIdentifier());
        JvmAnnotationValue _defaultValue = inferred.getDefaultValue();
        Assert.assertTrue((_defaultValue instanceof JvmCustomAnnotationValue));
        JvmAnnotationValue _defaultValue_1 = inferred.getDefaultValue();
        EObject _head_1 = IterableExtensions.<EObject>head(((JvmCustomAnnotationValue) _defaultValue_1).getValues());
        Assert.assertTrue((_head_1 instanceof XListLiteral));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmCustomAnnotationValue(org.eclipse.xtext.common.types.JvmCustomAnnotationValue) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) XListLiteral(org.eclipse.xtext.xbase.XListLiteral) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) Test(org.junit.Test)

Example 10 with JvmMember

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

the class JvmModelTests method testAnnotationDefaultAssociatedWithJvmOperation.

@Test
public void testAnnotationDefaultAssociatedWithJvmOperation() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("annotation Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val bar = \'\'");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        JvmMember _head = IterableExtensions.<JvmMember>head(this._iXtendJvmAssociations.getInferredAnnotationType(this.annotationType(_builder.toString())).getMembers());
        final JvmOperation inferred = ((JvmOperation) _head);
        final JvmAnnotationValue defaultValue = inferred.getDefaultValue();
        Assert.assertSame(inferred, defaultValue.getOperation());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmAnnotationValue(org.eclipse.xtext.common.types.JvmAnnotationValue) 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