Search in sources :

Example 1 with IncompatibleTypeException

use of ceylon.language.meta.model.IncompatibleTypeException in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getDeclaredClass.

@SuppressWarnings({ "unchecked", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language.meta.model::MemberClass<Container,Type,Arguments>|ceylon.language::Null")
public <Container, Type, Arguments extends ceylon.language.Sequential<? extends java.lang.Object>> ceylon.language.meta.model.MemberClass<Container, Type, Arguments> getDeclaredClass(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
    checkInit();
    // do not return the attribute if the container is not a subtype of this type
    org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
    if (!reifiedContainer.isSubtypeOf(producedType))
        throw new IncompatibleTypeException("Specified container type '" + reifiedContainer.asString() + "' is not a valid subtype of this type");
    final ClassOrInterfaceDeclarationImpl type = declaration.findDeclaredType(name);
    if (type == null)
        return null;
    if (type instanceof ClassDeclarationImpl == false)
        throw new IncompatibleTypeException("Specified member is not a class: " + name);
    return ((ClassDeclarationImpl) type).memberClassApply($reifiedContainer, $reifiedType, $reifiedArguments, (ceylon.language.meta.model.Type<Container>) this, types);
}
Also used : ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 2 with IncompatibleTypeException

use of ceylon.language.meta.model.IncompatibleTypeException in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getDeclaredClassOrInterface.

@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Kind", satisfies = "ceylon.language.meta.model::ClassOrInterface<ceylon.language::Anything,ceylon.language::Nothing>") })
@TypeInfo("ceylon.language.meta.model::Member<Container,Kind>|ceylon.language::Null")
public <Container, Kind extends ceylon.language.meta.model.ClassOrInterface<? extends java.lang.Object>> ceylon.language.meta.model.Member<Container, Kind> getDeclaredClassOrInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedKind, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
    checkInit();
    // do not return the attribute if the container is not a subtype of this type
    org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
    if (!reifiedContainer.isSubtypeOf(producedType))
        throw new IncompatibleTypeException("Specified container type '" + reifiedContainer.asString() + "' is not a valid subtype of this type");
    final ClassOrInterfaceDeclarationImpl type = declaration.findDeclaredType(name);
    if (type == null)
        return null;
    return applyClassOrInterface($reifiedContainer, $reifiedKind, type, types);
}
Also used : ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 3 with IncompatibleTypeException

use of ceylon.language.meta.model.IncompatibleTypeException in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getInterface.

@SuppressWarnings({ "unchecked", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type") })
@TypeInfo("ceylon.language.meta.model::MemberInterface<Container,Type>|ceylon.language::Null")
public <Container, Type> ceylon.language.meta.model.MemberInterface<Container, Type> getInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
    checkInit();
    final ClassOrInterfaceDeclarationImpl type = declaration.findType(name);
    if (type == null)
        return null;
    if (type instanceof InterfaceDeclarationImpl == false)
        throw new IncompatibleTypeException("Specified member is not an interface: " + name);
    MemberLookup<InterfaceDeclarationImpl, Container> lookup = lookupMember(InterfaceDeclarationImpl.$TypeDescriptor$, $reifiedContainer, (InterfaceDeclarationImpl) type);
    if (lookup == null)
        return null;
    return (ceylon.language.meta.model.MemberInterface<Container, Type>) lookup.declaration.memberApply($reifiedContainer, $reifiedType, lookup.containerMetamodel, types);
}
Also used : ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) InterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 4 with IncompatibleTypeException

use of ceylon.language.meta.model.IncompatibleTypeException in project ceylon by eclipse.

the class ClassOrInterfaceImpl method $getClass.

@SuppressWarnings("hiding")
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language.meta.model::MemberClass<Container,Type,Arguments>|ceylon.language::Null")
public <Container, Type, Arguments extends ceylon.language.Sequential<? extends java.lang.Object>> ceylon.language.meta.model.MemberClass<Container, Type, Arguments> $getClass(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
    checkInit();
    final ClassOrInterfaceDeclarationImpl type = declaration.findType(name);
    if (type == null)
        return null;
    if (type instanceof ClassDeclarationImpl == false)
        throw new IncompatibleTypeException("Specified member is not a class: " + name);
    MemberLookup<ClassDeclarationImpl, Container> lookup = lookupMember(ClassDeclarationImpl.$TypeDescriptor$, $reifiedContainer, (ClassDeclarationImpl) type);
    if (lookup == null)
        return null;
    return lookup.declaration.memberClassApply($reifiedContainer, $reifiedType, $reifiedArguments, lookup.containerMetamodel, types);
}
Also used : ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 5 with IncompatibleTypeException

use of ceylon.language.meta.model.IncompatibleTypeException in project ceylon by eclipse.

the class Metamodel method checkQualifyingType.

public static void checkQualifyingType(Type qualifyingType, Declaration declaration) {
    Scope container = declaration.getContainer();
    if (container instanceof TypeDeclaration == false)
        throw new IncompatibleTypeException("Declaration container is not a type: " + container);
    TypeDeclaration typeDecl = (TypeDeclaration) container;
    Type supertype = qualifyingType.getSupertype(typeDecl);
    if (supertype == null)
        throw new IncompatibleTypeException("Invalid container type: " + qualifyingType + " is not a subtype of " + typeDecl);
}
Also used : ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) OpenClassOrInterfaceType(ceylon.language.meta.declaration.OpenClassOrInterfaceType) OpenType(ceylon.language.meta.declaration.OpenType) DeclarationType(org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

IncompatibleTypeException (ceylon.language.meta.model.IncompatibleTypeException)10 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)7 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)7 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)5 ClassOrInterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl)5 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)4 OpenClassOrInterfaceType (ceylon.language.meta.declaration.OpenClassOrInterfaceType)3 OpenType (ceylon.language.meta.declaration.OpenType)3 DeclarationType (org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType)3 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)3 Type (org.eclipse.ceylon.model.typechecker.model.Type)3 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)3 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)2 InterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl)2 InvocationException (ceylon.language.meta.model.InvocationException)1 FunctionDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl)1 ValueDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl)1 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)1 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)1 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)1