Search in sources :

Example 6 with JvmTypeParameter

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

the class XtendQualifiedNameProvider method getFullyQualifiedName.

@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
    if (obj instanceof XtendTypeDeclaration) {
        XtendTypeDeclaration typeDecl = (XtendTypeDeclaration) obj;
        String typeName = typeDecl.getName();
        if (typeDecl.eContainer() instanceof XtendFile) {
            if (typeName == null)
                return null;
            XtendFile file = (XtendFile) typeDecl.eContainer();
            String packageName = file.getPackage();
            if (packageName != null) {
                return qualifiedNameConverter.toQualifiedName(packageName).append(typeName);
            }
            return QualifiedName.create(typeName);
        } else {
            return concatNames(obj, typeName);
        }
    }
    if (obj instanceof XtendConstructor) {
        return getFullyQualifiedName(obj.eContainer());
    }
    if (obj instanceof JvmIdentifiableElement && !(obj instanceof JvmTypeParameter)) {
        return getFullyQualifiedName((JvmIdentifiableElement) obj);
    }
    if (obj instanceof XtendField) {
        return concatNames(obj, ((XtendField) obj).getName());
    }
    if (obj instanceof XtendFunction) {
        return concatNames(obj, ((XtendFunction) obj).getName());
    }
    if (obj instanceof XtendEnumLiteral) {
        return concatNames(obj, ((XtendEnumLiteral) obj).getName());
    }
    return null;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 7 with JvmTypeParameter

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

the class TypeParameterScope method doGetElements.

@Override
protected void doGetElements(JvmType type, List<IEObjectDescription> result) {
    if (type instanceof JvmTypeParameter) {
        JvmTypeParameter casted = (JvmTypeParameter) type;
        QualifiedName name = QualifiedName.create(casted.getSimpleName());
        IEObjectDescription candidate = doGetSingleElement(name);
        if (candidate != null) {
            if (candidate.getEObjectOrProxy() == type) {
                result.add(candidate);
            }
        }
        return;
    }
    parent.doGetElements(type, result);
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) QualifiedName(org.eclipse.xtext.naming.QualifiedName) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 8 with JvmTypeParameter

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

the class XtendImportedNamespaceScopeProvider method getContainerScope.

private AbstractScope getContainerScope(XtendMember syntacticContainer, AbstractScope result) {
    JvmDeclaredType innermost = null;
    List<List<JvmTypeParameter>> typeParameters = null;
    XtendMember workWithMe = syntacticContainer;
    while (workWithMe != null) {
        EObject derivedJvmElement = getAssociations().getPrimaryJvmElement(workWithMe);
        // scope for JvmTypeParameterDeclarator
        if (derivedJvmElement instanceof JvmTypeParameterDeclarator) {
            JvmTypeParameterDeclarator parameterDeclarator = (JvmTypeParameterDeclarator) derivedJvmElement;
            List<JvmTypeParameter> current = parameterDeclarator.getTypeParameters();
            if (!current.isEmpty()) {
                if (typeParameters == null) {
                    typeParameters = Lists.newArrayListWithCapacity(3);
                }
                typeParameters.add(current);
            }
        }
        if (innermost == null && derivedJvmElement instanceof JvmDeclaredType) {
            if (syntacticContainer != workWithMe) {
                // prevent stackoverflow / cyclic resolution
                innermost = (JvmDeclaredType) derivedJvmElement;
            }
        }
        EObject container = workWithMe;
        do {
            container = container.eContainer();
            if (container == null) {
                if (typeParameters == null) {
                    if (innermost == null)
                        return result;
                    return new NestedTypesScope(innermost, this, result);
                }
                TypeParameterScope typeParameterScope = new TypeParameterScope(typeParameters, result);
                if (innermost == null) {
                    return typeParameterScope;
                }
                return new NestedTypesScope(innermost, this, typeParameterScope);
            }
        } while (!(container instanceof XtendMember));
        workWithMe = (XtendMember) container;
    }
    return result;
}
Also used : XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeParameterDeclarator(org.eclipse.xtext.common.types.JvmTypeParameterDeclarator) EObject(org.eclipse.emf.ecore.EObject) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList)

Example 9 with JvmTypeParameter

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

the class XtendImportedNamespaceScopeProvider method getScope.

@Override
public IScope getScope(final EObject context, final EReference reference) {
    EClass referenceType = reference.getEReferenceType();
    if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(referenceType)) {
        if (context instanceof XImportDeclaration) {
            Resource resource = context.eResource();
            IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
            AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
            IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
            IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
            if (resourceDescription != null) {
                typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
            }
            RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
            // TODO this scope doesn't support binary syntax for inner types. It should be a KnownTypes scope which doesn't allow simple names
            // Unfortunately I cannot use a RecordingTypeScope as a parent as it is not compatible...
            IScope scope = SelectableBasedScope.createScope(recordingTypeScope, getAllDescriptions(resource), reference.getEReferenceType(), false);
            return scope;
        }
        final XtendFile xtendFile = getXtendFile(context);
        final Resource resource = xtendFile.eResource();
        AbstractScope result = resourceScopeCache.get("type.scope", xtendFile.eResource(), new Provider<AbstractScope>() {

            @Override
            public AbstractScope get() {
                IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
                AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
                IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
                IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
                if (resourceDescription != null) {
                    typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
                }
                RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
                AbstractScope rootTypeScope = getRootTypeScope(xtendFile, recordingTypeScope);
                AbstractScope importScope = getImportScope(xtendFile.getImportSection(), rootTypeScope, recordingTypeScope);
                AbstractScope localTypes = getResourceTypeScope(xtendFile.eResource(), xtendFile.getPackage(), importScope);
                AbstractScope primitiveAware = new PrimitiveAwareScope(localTypes, typeScope);
                AbstractScope caching = new CachingTypeScope(primitiveAware);
                return caching;
            }
        });
        if (context instanceof AnonymousClass) {
            // necessary for the super type of an anonymous class expression
            JvmDeclaredType inferredAnonymousType = associations.getInferredType((AnonymousClass) context);
            if (inferredAnonymousType != null)
                result = new LocalTypeScope(singletonList(inferredAnonymousType), result);
        }
        XtendMember syntacticContainer = EcoreUtil2.getContainerOfType(context, XtendMember.class);
        if (syntacticContainer != null) {
            result = getContainerScope(syntacticContainer, result);
        }
        EObject logicalContainer = logicalContainerProvider.getNearestLogicalContainer(context);
        if (logicalContainer != null) {
            List<List<JvmTypeParameter>> typeParameters = new ArrayList<List<JvmTypeParameter>>();
            while (logicalContainer instanceof JvmTypeParameterDeclarator) {
                JvmTypeParameterDeclarator typeParamProvider = (JvmTypeParameterDeclarator) logicalContainer;
                if (!typeParamProvider.getTypeParameters().isEmpty()) {
                    typeParameters.add(typeParamProvider.getTypeParameters());
                }
                logicalContainer = logicalContainer.eContainer();
            }
            if (!typeParameters.isEmpty())
                result = new TypeParameterScope(typeParameters, result);
        }
        return result;
    } else if (TypesPackage.Literals.JVM_CONSTRUCTOR.isSuperTypeOf(referenceType)) {
        IScope typeScope = getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
        // this is not called from the type resolution where we want to allow constructors to link to interfaces
        // in order to improve the error message, therefore we use a strict wrapper here
        IScope result = new ConstructorTypeScopeWrapper(context, IVisibilityHelper.ALL, typeScope, true);
        return result;
    } else {
        throw new IllegalArgumentException("Unexpected global request for " + reference);
    }
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeParameterDeclarator(org.eclipse.xtext.common.types.JvmTypeParameterDeclarator) AbstractTypeScope(org.eclipse.xtext.common.types.xtext.AbstractTypeScope) ArrayList(java.util.ArrayList) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) IJvmTypeProvider(org.eclipse.xtext.common.types.access.IJvmTypeProvider) EClass(org.eclipse.emf.ecore.EClass) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) XtendFile(org.eclipse.xtend.core.xtend.XtendFile) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Resource(org.eclipse.emf.ecore.resource.Resource) XImportDeclaration(org.eclipse.xtext.xtype.XImportDeclaration) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) ConstructorTypeScopeWrapper(org.eclipse.xtext.xbase.scoping.batch.ConstructorTypeScopeWrapper)

Example 10 with JvmTypeParameter

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

the class MutableJvmInterfaceDeclarationImpl method addTypeParameter.

@Override
public MutableTypeParameterDeclaration addTypeParameter(final String name, final TypeReference... upperBounds) {
    this.checkMutable();
    ConditionUtils.checkJavaIdentifier(name, "name");
    ConditionUtils.checkIterable(((Iterable<?>) Conversions.doWrapArray(upperBounds)), "upperBounds");
    ConditionUtils.checkInferredTypeReferences("parameter type", upperBounds);
    final JvmTypeParameter param = TypesFactory.eINSTANCE.createJvmTypeParameter();
    param.setName(name);
    this.getDelegate().getTypeParameters().add(param);
    for (final TypeReference upper : upperBounds) {
        {
            final JvmTypeReference typeRef = this.getCompilationUnit().toJvmTypeReference(upper);
            final JvmUpperBound jvmUpperBound = TypesFactory.eINSTANCE.createJvmUpperBound();
            jvmUpperBound.setTypeReference(typeRef);
            param.getConstraints().add(jvmUpperBound);
        }
    }
    TypeParameterDeclaration _typeParameterDeclaration = this.getCompilationUnit().toTypeParameterDeclaration(param);
    return ((MutableTypeParameterDeclaration) _typeParameterDeclaration);
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) TypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.TypeParameterDeclaration) MutableTypeParameterDeclaration(org.eclipse.xtend.lib.macro.declaration.MutableTypeParameterDeclaration) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) TypeReference(org.eclipse.xtend.lib.macro.declaration.TypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference)

Aggregations

JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)57 Test (org.junit.Test)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)14 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)13 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)10 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)7 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)6 List (java.util.List)5 EList (org.eclipse.emf.common.util.EList)5 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 EObject (org.eclipse.emf.ecore.EObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 ArrayList (java.util.ArrayList)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)3 AbstractMethodBuilder (org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)3