Search in sources :

Example 11 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType 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 12 with JvmGenericType

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

the class XtendOutlineSourceTreeBuilder method buildLocalClasses.

protected void buildLocalClasses(final JvmFeature jvmFeature, final IXtendOutlineContext context) {
    boolean _isEmpty = jvmFeature.getLocalClasses().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        EList<JvmGenericType> _localClasses = jvmFeature.getLocalClasses();
        for (final JvmGenericType jvmGenericType : _localClasses) {
            {
                final IXtendOutlineContext typeContext = context.newContext();
                Set<EObject> _sourceElements = this._iXtendJvmAssociations.getSourceElements(jvmGenericType);
                for (final EObject sourceElement : _sourceElements) {
                    this.buildType(sourceElement, typeContext);
                }
            }
        }
    }
}
Also used : Set(java.util.Set) IXtendOutlineContext(org.eclipse.xtend.ide.common.outline.IXtendOutlineContext) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType)

Example 13 with JvmGenericType

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

the class ResourceStorageTest method testWriteAndLoad.

@Test
public void testWriteAndLoad() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("package foo");
        _builder.newLine();
        _builder.newLine();
        _builder.append("class Bar {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch myMethod(String s) {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("/**");
        _builder.newLine();
        _builder.append("\t ");
        _builder.append("* Hello myMethod ");
        _builder.newLine();
        _builder.append("\t ");
        _builder.append("*/");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch myMethod(CharSequence cs) {}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("def dispatch other(String it) {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("var x = \"\"");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("x = length.toString");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("println(x)");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _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);
        Assert.assertEquals("java.lang.CharSequence", IterableExtensions.<JvmFormalParameter>head(((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2].getParameters()).getParameterType().getQualifiedName());
        Assert.assertEquals("java.lang.Object", ((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[2].getReturnType().getQualifiedName());
        Assert.assertEquals("Hello myMethod", IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter(((JvmOperation[]) Conversions.unwrapArray(jvmClass.getDeclaredOperations(), JvmOperation.class))[1].eAdapters(), DocumentationAdapter.class)).getDocumentation());
        Assert.assertEquals(resource.getURI(), resource.getResourceDescription().getURI());
        Assert.assertEquals(2, IterableExtensions.size(resource.getResourceDescription().getExportedObjects()));
        Assert.assertEquals("foo.Bar", IterableExtensions.<IEObjectDescription>head(resource.getResourceDescription().getExportedObjects()).getQualifiedName().toString());
        final BidiTreeIterator<INode> restoredNodes = NodeModelUtils.findActualNodeFor(IterableExtensions.<EObject>head(resource.getContents())).getAsTreeIterable().iterator();
        final BidiTreeIterator<INode> originalNodes = NodeModelUtils.findActualNodeFor(file).getAsTreeIterable().iterator();
        while (restoredNodes.hasNext()) {
            {
                final INode rest = restoredNodes.next();
                final INode orig = originalNodes.next();
                Assert.assertEquals(orig.getStartLine(), rest.getStartLine());
                Assert.assertEquals(orig.getEndLine(), rest.getEndLine());
                Assert.assertEquals(orig.getOffset(), rest.getOffset());
                Assert.assertEquals(orig.getEndOffset(), rest.getEndOffset());
                Assert.assertEquals(orig.getLength(), rest.getLength());
                Assert.assertEquals(orig.getTotalStartLine(), rest.getTotalStartLine());
                Assert.assertEquals(orig.getTotalEndLine(), rest.getTotalEndLine());
                Assert.assertEquals(orig.getTotalOffset(), rest.getTotalOffset());
                Assert.assertEquals(orig.getTotalEndOffset(), rest.getTotalEndOffset());
                Assert.assertEquals(orig.getTotalLength(), rest.getTotalLength());
                Assert.assertSame(orig.getGrammarElement(), rest.getGrammarElement());
                Assert.assertEquals(file.eResource().getURIFragment(orig.getSemanticElement()), resource.getURIFragment(rest.getSemanticElement()));
                Assert.assertEquals(orig.getText(), rest.getText());
            }
        }
        Assert.assertFalse(originalNodes.hasNext());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) InMemoryURIConverter(org.eclipse.xtend.core.tests.util.InMemoryURIConverter) INode(org.eclipse.xtext.nodemodel.INode) 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) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) DocumentationAdapter(org.eclipse.xtext.xbase.compiler.DocumentationAdapter) ResourceStorageLoadable(org.eclipse.xtext.resource.persistence.ResourceStorageLoadable) ByteArrayInputStream(java.io.ByteArrayInputStream) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 14 with JvmGenericType

use of org.eclipse.xtext.common.types.JvmGenericType 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 15 with JvmGenericType

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

the class XtendCompiler method isVariableDeclarationRequired.

@Override
protected boolean isVariableDeclarationRequired(XExpression expr, ITreeAppendable b, boolean recursive) {
    boolean result = super.isVariableDeclarationRequired(expr, b, recursive);
    if (result && expr instanceof XConstructorCall) {
        EObject container = expr.eContainer();
        if (container instanceof AnonymousClass) {
            AnonymousClass anonymousClass = (AnonymousClass) container;
            result = isVariableDeclarationRequired(anonymousClass, b, recursive);
            if (result) {
                JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
                JvmDeclaredType type = constructor.getDeclaringType();
                if (((JvmGenericType) type).isAnonymous()) {
                    return false;
                }
            }
        }
    }
    return result;
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Aggregations

JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)155 Test (org.junit.Test)106 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)71 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)64 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)56 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)33 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)30 EObject (org.eclipse.emf.ecore.EObject)23 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)23 JvmMember (org.eclipse.xtext.common.types.JvmMember)21 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)19 JvmField (org.eclipse.xtext.common.types.JvmField)19 JvmType (org.eclipse.xtext.common.types.JvmType)13 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)11 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)11 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)11 DispatchHelper (org.eclipse.xtend.core.jvmmodel.DispatchHelper)10 Resource (org.eclipse.emf.ecore.resource.Resource)9 Check (org.eclipse.xtext.validation.Check)9 DispatchSignature (org.eclipse.xtend.core.jvmmodel.DispatchHelper.DispatchSignature)8