Search in sources :

Example 26 with JvmMember

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

the class NestedTypesScope method findNestedTypeInLocalTypeNonResolving.

/**
 * We have to be careful to keep the unresolved super type of a local type which may depend on type resolution.
 * Therefore these types are treated differently from other types.
 */
protected IEObjectDescription findNestedTypeInLocalTypeNonResolving(JvmDeclaredType localType, QualifiedName name, String firstSegment, int dollarIndex) {
    List<JvmMember> members = localType.getMembers();
    for (int i = 0; i < members.size(); i++) {
        JvmMember member = members.get(i);
        if (member instanceof JvmDeclaredType) {
            JvmDeclaredType nestedType = (JvmDeclaredType) member;
            if (firstSegment.equals(nestedType.getSimpleName())) {
                JvmType candidate = findNestedType(nestedType, 0, name);
                if (candidate != null) {
                    return toDescription(name, candidate, dollarIndex, 0);
                }
            }
        }
    }
    JvmDeclaredType superType = typeScopeProvider.getSuperTypeOfLocalTypeNonResolving(localType);
    if (superType == null) {
        return null;
    }
    return doGetSingleElement(superType, name, firstSegment, dollarIndex);
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmType(org.eclipse.xtext.common.types.JvmType)

Example 27 with JvmMember

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

the class XtendImportedNamespaceScopeProvider method doGetAllDescriptions.

private void doGetAllDescriptions(JvmDeclaredType type, List<IEObjectDescription> descriptions) {
    descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(type.getIdentifier()), type));
    EList<JvmMember> members = null;
    if (type instanceof JvmDeclaredTypeImplCustom) {
        members = ((JvmDeclaredTypeImplCustom) type).basicGetMembers();
    } else {
        members = type.getMembers();
    }
    for (JvmMember member : members) {
        if (member instanceof JvmDeclaredType) {
            // add nested types also with the dot delimiter
            descriptions.add(EObjectDescription.create(getQualifiedNameConverter().toQualifiedName(member.getQualifiedName('.')), member));
            doGetAllDescriptions((JvmDeclaredType) member, descriptions);
        }
    }
}
Also used : JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmDeclaredTypeImplCustom(org.eclipse.xtext.common.types.impl.JvmDeclaredTypeImplCustom)

Example 28 with JvmMember

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

the class XtendReentrantTypeResolver method doPrepareLocalTypes.

protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    List<JvmGenericType> localClasses = container.getLocalClasses();
    for (final JvmGenericType localClass : localClasses) {
        JvmTypeReference superType = localClass.getSuperTypes().get(0);
        final IFeatureScopeSession nestedSession = featureScopeSession;
        if (InferredTypeIndicator.isInferred(superType)) {
            final XComputedTypeReference casted = (XComputedTypeReference) superType;
            InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
            final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
            XConstructorCall constructorCall = anonymousClass.getConstructorCall();
            IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
            final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
            if (type == null) {
                JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        inferAnonymousClassConstructor(anonymousClass, localClass);
                    }
                });
            } else {
                final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    @SuppressWarnings("deprecation")
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
                        if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
                            localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
                            inferAnonymousClassConstructor(anonymousClass, localClass);
                        } else {
                            for (JvmMember superMember : type.getMembers()) {
                                if (superMember instanceof JvmConstructor) {
                                    JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
                                    boolean visible = mySession.isVisible(superTypeConstructor);
                                    inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
                                }
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : IFeatureScopeSession(org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmUnknownTypeReference(org.eclipse.xtext.common.types.JvmUnknownTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) InferredTypeIndicator(org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IScope(org.eclipse.xtext.scoping.IScope) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 29 with JvmMember

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

the class XtendGenerator method getAddedDeclarations.

protected ArrayList<JvmMember> getAddedDeclarations(final JvmGenericType it, final AnonymousClass anonymousClass) {
    final ArrayList<JvmMember> result = CollectionLiterals.<JvmMember>newArrayList();
    final JvmConstructor constructor = anonymousClass.getConstructorCall().getConstructor();
    int _size = constructor.getParameters().size();
    boolean _greaterEqualsThan = (_size >= 1);
    if (_greaterEqualsThan) {
        result.add(0, constructor);
    }
    Iterable<JvmField> _declaredFields = it.getDeclaredFields();
    Iterables.<JvmMember>addAll(result, _declaredFields);
    final Function1<JvmOperation, Boolean> _function = (JvmOperation it_1) -> {
        EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it_1));
        final XtendFunction function = ((XtendFunction) _head);
        boolean _isOverride = function.isOverride();
        return Boolean.valueOf((!_isOverride));
    };
    Iterable<JvmOperation> _filter = IterableExtensions.<JvmOperation>filter(it.getDeclaredOperations(), _function);
    Iterables.<JvmMember>addAll(result, _filter);
    Iterable<JvmDeclaredType> _filter_1 = Iterables.<JvmDeclaredType>filter(it.getMembers(), JvmDeclaredType.class);
    Iterables.<JvmMember>addAll(result, _filter_1);
    return result;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField)

Example 30 with JvmMember

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

the class XtendGenerator method compileLocalTypeStubs.

public void compileLocalTypeStubs(final JvmFeature feature, final ITreeAppendable appendable, final GeneratorConfig config) {
    final Function1<JvmGenericType, Boolean> _function = (JvmGenericType it) -> {
        boolean _isAnonymous = it.isAnonymous();
        return Boolean.valueOf((!_isAnonymous));
    };
    final Consumer<JvmGenericType> _function_1 = (JvmGenericType it) -> {
        appendable.newLine();
        EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
        final AnonymousClass anonymousClass = ((AnonymousClass) _head);
        final ITreeAppendable childAppendable = appendable.trace(anonymousClass);
        childAppendable.append("abstract class ");
        this._treeAppendableUtil.traceSignificant(childAppendable, anonymousClass).append(it.getSimpleName());
        boolean _isEmpty = it.getTypeParameters().isEmpty();
        if (_isEmpty) {
            childAppendable.append(" ");
        }
        this.generateExtendsClause(it, childAppendable, null);
        childAppendable.append("{").increaseIndentation();
        boolean _needSyntheticThisVariable = this.needSyntheticThisVariable(anonymousClass, it);
        if (_needSyntheticThisVariable) {
            Pair<String, JvmGenericType> _mappedTo = Pair.<String, JvmGenericType>of("this", it);
            String _simpleName = it.getSimpleName();
            String _plus = ("_this" + _simpleName);
            final String thisName = childAppendable.declareSyntheticVariable(_mappedTo, _plus);
            childAppendable.newLine().append("final ").append(it.getSimpleName()).append(" ").append(thisName).append(" = this;").newLine();
        }
        final Procedure1<LoopParams> _function_2 = (LoopParams it_1) -> {
            final Function1<ITreeAppendable, ITreeAppendable> _function_3 = (ITreeAppendable it_2) -> {
                return it_2.newLine();
            };
            it_1.setSeparator(_function_3);
        };
        final Procedure1<JvmMember> _function_3 = (JvmMember it_1) -> {
            final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(childAppendable, it_1);
            memberAppendable.openScope();
            if ((it_1 instanceof JvmOperation)) {
                final ITreeAppendable tracedAppendable = childAppendable.trace(it_1);
                tracedAppendable.newLine();
                this.generateJavaDoc(it_1, tracedAppendable, config);
                this.generateVisibilityModifier(it_1, tracedAppendable);
                tracedAppendable.append("abstract ");
                this.generateTypeParameterDeclaration(((JvmTypeParameterDeclarator) it_1), tracedAppendable, null);
                JvmTypeReference _returnType = ((JvmOperation) it_1).getReturnType();
                boolean _tripleEquals = (_returnType == null);
                if (_tripleEquals) {
                    tracedAppendable.append("void");
                } else {
                    this._errorSafeExtensions.serializeSafely(((JvmOperation) it_1).getReturnType(), "Object", tracedAppendable);
                }
                tracedAppendable.append(" ");
                this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(((JvmOperation) it_1).getSimpleName());
                tracedAppendable.append("(");
                this.generateParameters(((JvmExecutable) it_1), tracedAppendable, null);
                tracedAppendable.append(")");
                this.generateThrowsClause(((JvmExecutable) it_1), tracedAppendable, null);
                tracedAppendable.append(";");
            } else {
                if ((it_1 instanceof JvmField)) {
                    final ITreeAppendable tracedAppendable_1 = childAppendable.trace(it_1);
                    tracedAppendable_1.newLine();
                    this.generateJavaDoc(it_1, tracedAppendable_1, config);
                    this.generateAnnotations(((JvmField) it_1).getAnnotations(), tracedAppendable_1, true, config);
                    if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
                        tracedAppendable_1.append("final ");
                    }
                    boolean _isStatic = ((JvmField) it_1).isStatic();
                    if (_isStatic) {
                        tracedAppendable_1.append("static ");
                    }
                    boolean _isTransient = ((JvmField) it_1).isTransient();
                    if (_isTransient) {
                        tracedAppendable_1.append("transient ");
                    }
                    boolean _isVolatile = ((JvmField) it_1).isVolatile();
                    if (_isVolatile) {
                        tracedAppendable_1.append("volatile ");
                    }
                    this._errorSafeExtensions.serializeSafely(((JvmField) it_1).getType(), "Object", tracedAppendable_1);
                    tracedAppendable_1.append(" ");
                    this._treeAppendableUtil.traceSignificant(tracedAppendable_1, it_1).append(((JvmField) it_1).getSimpleName());
                    if ((((JvmField) it_1).isFinal() && ((JvmField) it_1).isStatic())) {
                        Object _constantValue = ((JvmField) it_1).getConstantValue();
                        boolean _tripleNotEquals = (_constantValue != null);
                        if (_tripleNotEquals) {
                            tracedAppendable_1.append(" = ");
                            this.generateJavaConstant(((JvmField) it_1).getConstantValue(), tracedAppendable_1);
                        } else {
                            this.generateInitialization(((JvmField) it_1), tracedAppendable_1, config);
                        }
                    }
                    tracedAppendable_1.append(";");
                } else {
                    this.generateMember(it_1, memberAppendable, config);
                }
            }
            memberAppendable.closeScope();
        };
        this._loopExtensions.<JvmMember>forEach(childAppendable, this.getAddedDeclarations(it, anonymousClass), _function_2, _function_3);
        childAppendable.decreaseIndentation().newLine().append("}");
        appendable.newLine();
    };
    IterableExtensions.<JvmGenericType>filter(feature.getLocalClasses(), _function).forEach(_function_1);
}
Also used : JvmTypeParameterDeclarator(org.eclipse.xtext.common.types.JvmTypeParameterDeclarator) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable) LoopParams(org.eclipse.xtext.xbase.compiler.LoopParams) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmExecutable(org.eclipse.xtext.common.types.JvmExecutable) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmMember(org.eclipse.xtext.common.types.JvmMember) EObject(org.eclipse.emf.ecore.EObject) JvmField(org.eclipse.xtext.common.types.JvmField) Pair(org.eclipse.xtext.xbase.lib.Pair)

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