Search in sources :

Example 6 with JvmDeclaredType

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

the class CompilationUnitImpl method toMemberDeclaration.

public MemberDeclaration toMemberDeclaration(final JvmMember delegate) {
    final Function1<JvmMember, MemberDeclaration> _function = (JvmMember it) -> {
        MemberDeclaration _switchResult = null;
        boolean _matched = false;
        if (delegate instanceof JvmDeclaredType) {
            _matched = true;
            _switchResult = this.toTypeDeclaration(((JvmDeclaredType) delegate));
        }
        if (!_matched) {
            if (delegate instanceof JvmOperation) {
                _matched = true;
                MemberDeclaration _xifexpression = null;
                JvmDeclaredType _declaringType = ((JvmOperation) delegate).getDeclaringType();
                if ((_declaringType instanceof JvmAnnotationType)) {
                    JvmAnnotationTypeElementDeclarationImpl _xifexpression_1 = null;
                    boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                    if (_isBelongedToCompilationUnit) {
                        MutableJvmAnnotationTypeElementDeclarationImpl _mutableJvmAnnotationTypeElementDeclarationImpl = new MutableJvmAnnotationTypeElementDeclarationImpl();
                        final Procedure1<MutableJvmAnnotationTypeElementDeclarationImpl> _function_1 = (MutableJvmAnnotationTypeElementDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_1 = ObjectExtensions.<MutableJvmAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_mutableJvmAnnotationTypeElementDeclarationImpl, _function_1);
                    } else {
                        JvmAnnotationTypeElementDeclarationImpl _jvmAnnotationTypeElementDeclarationImpl = new JvmAnnotationTypeElementDeclarationImpl();
                        final Procedure1<JvmAnnotationTypeElementDeclarationImpl> _function_2 = (JvmAnnotationTypeElementDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_1 = ObjectExtensions.<JvmAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_jvmAnnotationTypeElementDeclarationImpl, _function_2);
                    }
                    _xifexpression = _xifexpression_1;
                } else {
                    JvmMethodDeclarationImpl _xifexpression_2 = null;
                    boolean _isBelongedToCompilationUnit_1 = this.isBelongedToCompilationUnit(delegate);
                    if (_isBelongedToCompilationUnit_1) {
                        MutableJvmMethodDeclarationImpl _mutableJvmMethodDeclarationImpl = new MutableJvmMethodDeclarationImpl();
                        final Procedure1<MutableJvmMethodDeclarationImpl> _function_3 = (MutableJvmMethodDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_2 = ObjectExtensions.<MutableJvmMethodDeclarationImpl>operator_doubleArrow(_mutableJvmMethodDeclarationImpl, _function_3);
                    } else {
                        JvmMethodDeclarationImpl _jvmMethodDeclarationImpl = new JvmMethodDeclarationImpl();
                        final Procedure1<JvmMethodDeclarationImpl> _function_4 = (JvmMethodDeclarationImpl it_1) -> {
                            it_1.setDelegate(((JvmOperation) delegate));
                            it_1.setCompilationUnit(this);
                        };
                        _xifexpression_2 = ObjectExtensions.<JvmMethodDeclarationImpl>operator_doubleArrow(_jvmMethodDeclarationImpl, _function_4);
                    }
                    _xifexpression = ((MemberDeclaration) _xifexpression_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmConstructor) {
                _matched = true;
                JvmConstructorDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmConstructorDeclarationImpl _mutableJvmConstructorDeclarationImpl = new MutableJvmConstructorDeclarationImpl();
                    final Procedure1<MutableJvmConstructorDeclarationImpl> _function_1 = (MutableJvmConstructorDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmConstructor) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmConstructorDeclarationImpl>operator_doubleArrow(_mutableJvmConstructorDeclarationImpl, _function_1);
                } else {
                    JvmConstructorDeclarationImpl _jvmConstructorDeclarationImpl = new JvmConstructorDeclarationImpl();
                    final Procedure1<JvmConstructorDeclarationImpl> _function_2 = (JvmConstructorDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmConstructor) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmConstructorDeclarationImpl>operator_doubleArrow(_jvmConstructorDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmEnumerationLiteral) {
                _matched = true;
                JvmEnumerationValueDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmEnumerationValueDeclarationImpl _mutableJvmEnumerationValueDeclarationImpl = new MutableJvmEnumerationValueDeclarationImpl();
                    final Procedure1<MutableJvmEnumerationValueDeclarationImpl> _function_1 = (MutableJvmEnumerationValueDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationLiteral) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmEnumerationValueDeclarationImpl>operator_doubleArrow(_mutableJvmEnumerationValueDeclarationImpl, _function_1);
                } else {
                    JvmEnumerationValueDeclarationImpl _jvmEnumerationValueDeclarationImpl = new JvmEnumerationValueDeclarationImpl();
                    final Procedure1<JvmEnumerationValueDeclarationImpl> _function_2 = (JvmEnumerationValueDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmEnumerationLiteral) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmEnumerationValueDeclarationImpl>operator_doubleArrow(_jvmEnumerationValueDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        if (!_matched) {
            if (delegate instanceof JvmField) {
                _matched = true;
                JvmFieldDeclarationImpl _xifexpression = null;
                boolean _isBelongedToCompilationUnit = this.isBelongedToCompilationUnit(delegate);
                if (_isBelongedToCompilationUnit) {
                    MutableJvmFieldDeclarationImpl _mutableJvmFieldDeclarationImpl = new MutableJvmFieldDeclarationImpl();
                    final Procedure1<MutableJvmFieldDeclarationImpl> _function_1 = (MutableJvmFieldDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<MutableJvmFieldDeclarationImpl>operator_doubleArrow(_mutableJvmFieldDeclarationImpl, _function_1);
                } else {
                    JvmFieldDeclarationImpl _jvmFieldDeclarationImpl = new JvmFieldDeclarationImpl();
                    final Procedure1<JvmFieldDeclarationImpl> _function_2 = (JvmFieldDeclarationImpl it_1) -> {
                        it_1.setDelegate(((JvmField) delegate));
                        it_1.setCompilationUnit(this);
                    };
                    _xifexpression = ObjectExtensions.<JvmFieldDeclarationImpl>operator_doubleArrow(_jvmFieldDeclarationImpl, _function_2);
                }
                _switchResult = _xifexpression;
            }
        }
        return _switchResult;
    };
    return this.<JvmMember, MemberDeclaration>getOrCreate(delegate, _function);
}
Also used : JvmAnnotationType(org.eclipse.xtext.common.types.JvmAnnotationType) MutableJvmConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmConstructorDeclarationImpl) JvmConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmConstructorDeclarationImpl) MemberDeclaration(org.eclipse.xtend.lib.macro.declaration.MemberDeclaration) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) MutableJvmMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmMethodDeclarationImpl) MutableJvmMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmMethodDeclarationImpl) JvmMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmMethodDeclarationImpl) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) MutableJvmFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmFieldDeclarationImpl) JvmFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmFieldDeclarationImpl) JvmAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmAnnotationTypeElementDeclarationImpl) MutableJvmAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeElementDeclarationImpl) MutableJvmAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmAnnotationTypeElementDeclarationImpl) MutableJvmEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationValueDeclarationImpl) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.JvmEnumerationValueDeclarationImpl) MutableJvmEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmEnumerationValueDeclarationImpl) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) MutableJvmFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmFieldDeclarationImpl) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) MutableJvmConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.MutableJvmConstructorDeclarationImpl)

Example 7 with JvmDeclaredType

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

the class NestedTypesScope method doGetSingleElement.

@Override
protected IEObjectDescription doGetSingleElement(QualifiedName name, String firstSegment, int dollarIndex) {
    JvmDeclaredType declaredType = innermost;
    while (declaredType != null) {
        IEObjectDescription result = doGetSingleElement(declaredType, name, firstSegment, dollarIndex);
        if (result != null) {
            return result;
        }
        declaredType = EcoreUtil2.getContainerOfType(declaredType.eContainer(), JvmDeclaredType.class);
    }
    if (dollarIndex > 0 && name.getSegmentCount() == 1) {
        QualifiedName splitted = QualifiedName.create(Strings.split(name.getFirstSegment(), '$'));
        IEObjectDescription result = doGetSingleElement(splitted, splitted.getFirstSegment(), -1);
        if (result != null) {
            return new AliasedEObjectDescription(name, result);
        }
    }
    return null;
}
Also used : AliasedEObjectDescription(org.eclipse.xtext.resource.impl.AliasedEObjectDescription) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 8 with JvmDeclaredType

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

the class TypeScopeWithWildcardImports method doGetElements.

@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
    if (!(type instanceof JvmDeclaredType)) {
        return;
    }
    JvmDeclaredType declaredType = (JvmDeclaredType) type;
    String packageName = declaredType.getPackageName();
    if (!Strings.isEmpty(packageName)) {
        QualifiedName qualifiedPackageName = QualifiedName.create(Strings.split(packageName, '.'));
        QualifiedName withDot = null;
        String withDollar = null;
        for (int i = 0; i < imports.length; i++) {
            ImportNormalizer[] chunk = imports[i];
            for (int j = 0; j < chunk.length; j++) {
                ImportNormalizer normalizer = chunk[j];
                QualifiedName namespacePrefix = normalizer.getImportedNamespacePrefix();
                if (namespacePrefix.equals(qualifiedPackageName)) {
                    if (withDot == null) {
                        withDot = QualifiedName.create(Strings.split(type.getQualifiedName('.'), '.'));
                        withDollar = type.eContainer() instanceof JvmType ? type.getQualifiedName('$').substring(packageName.length() + 1) : null;
                    }
                    result.add(EObjectDescription.create(withDot.skipFirst(qualifiedPackageName.getSegmentCount()), type));
                    if (withDollar != null) {
                        result.add(EObjectDescription.create(withDollar, type));
                    }
                }
            }
        }
    }
    if (parent != null) {
        parent.doGetElements(type, result);
    } else {
        Iterables.addAll(result, typeScope.getElements(type));
    }
}
Also used : ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 9 with JvmDeclaredType

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

the class XtendImportedNamespaceScopeProvider method getSuperTypeOfLocalTypeNonResolving.

protected JvmDeclaredType getSuperTypeOfLocalTypeNonResolving(JvmDeclaredType declarator) {
    AnonymousClass anonymousClass = associations.getAnonymousClass(declarator);
    if (anonymousClass != null) {
        IScope typeScope = getScope(anonymousClass, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
        JvmDeclaredType superType = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
        if (superType != null) {
            return superType;
        }
    }
    return null;
}
Also used : AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) IScope(org.eclipse.xtext.scoping.IScope) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType)

Example 10 with JvmDeclaredType

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

the class XtendImportedNamespaceScopeProvider method getImportScope.

private AbstractScope getImportScope(XImportSection importSection, AbstractScope parent, RecordingTypeScope typeScope) {
    if (importSection == null)
        return parent;
    List<XImportDeclaration> importDeclarations = importSection.getImportDeclarations();
    if (importDeclarations.isEmpty()) {
        return parent;
    }
    List<ImportNormalizer> wildcardImports = null;
    List<JvmType> concreteImports = null;
    List<QualifiedName> importedNames = null;
    boolean hasLegacyImport = false;
    for (XImportDeclaration importDeclaration : importDeclarations) {
        if (!importDeclaration.isStatic()) {
            if (importDeclaration.isWildcard()) {
                if (wildcardImports == null) {
                    wildcardImports = Lists.newArrayListWithCapacity(4);
                }
                String importedNamespace = importDeclaration.getImportedNamespace();
                importedNamespace = importedNamespace.substring(0, importedNamespace.length() - 2);
                QualifiedName qualifiedImportedNamespace = qualifiedNameConverter.toQualifiedName(importedNamespace);
                wildcardImports.add(AbstractNestedTypeAwareImportNormalizer.createNestedTypeAwareImportNormalizer(qualifiedImportedNamespace, true, false));
            } else {
                JvmDeclaredType importedType = importDeclaration.getImportedType();
                if (importedType != null && !importedType.eIsProxy()) {
                    if (concreteImports == null || importedNames == null) /* to make JDT happy */
                    {
                        concreteImports = Lists.newArrayListWithCapacity(10);
                        importedNames = Lists.newArrayListWithCapacity(10);
                    }
                    concreteImports.add(importedType);
                    if (importedType.eContainer() instanceof JvmDeclaredType) {
                        String importSyntax = getImportsConfiguration().getLegacyImportSyntax(importDeclaration);
                        if (importSyntax != null) {
                            hasLegacyImport = true;
                            importedNames.add(getQualifiedNameConverter().toQualifiedName(importSyntax));
                        } else
                            importedNames.add(null);
                    } else {
                        importedNames.add(null);
                    }
                }
            }
        }
    }
    return getImportScope(wildcardImports, concreteImports, hasLegacyImport ? importedNames : null, parent, typeScope);
}
Also used : AbstractNestedTypeAwareImportNormalizer(org.eclipse.xtext.xbase.scoping.AbstractNestedTypeAwareImportNormalizer) ImportNormalizer(org.eclipse.xtext.scoping.impl.ImportNormalizer) QualifiedName(org.eclipse.xtext.naming.QualifiedName) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration)

Aggregations

JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)74 EObject (org.eclipse.emf.ecore.EObject)21 JvmType (org.eclipse.xtext.common.types.JvmType)18 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmMember (org.eclipse.xtext.common.types.JvmMember)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)10 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)8 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)8 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)8 Test (org.junit.Test)8 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)7 Resource (org.eclipse.emf.ecore.resource.Resource)5 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 JvmAnnotationType (org.eclipse.xtext.common.types.JvmAnnotationType)5 XExpression (org.eclipse.xtext.xbase.XExpression)5 List (java.util.List)4 EList (org.eclipse.emf.common.util.EList)4 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)4