Search in sources :

Example 1 with ClassOrInterface

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

the class Metamodel method getMetamodel.

public static ceylon.language.meta.declaration.FunctionDeclaration getMetamodel(Function method) {
    // find its container
    Scope container = method.getContainer();
    if (container instanceof org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) {
        org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl classOrInterface = (ClassOrInterfaceDeclarationImpl) getOrCreateMetamodel((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) container);
        // now find the method
        ceylon.language.meta.declaration.FunctionDeclaration ret = classOrInterface.findMethod(method.getName());
        if (ret == null)
            throw Metamodel.newModelError("Failed to find method " + method.getName() + " in " + container);
        return ret;
    }
    if (container instanceof org.eclipse.ceylon.model.typechecker.model.Package) {
        ceylon.language.meta.declaration.Package pkg = getOrCreateMetamodel((org.eclipse.ceylon.model.typechecker.model.Package) container);
        ceylon.language.meta.declaration.FunctionDeclaration ret = pkg.getFunction(method.getName());
        if (ret == null)
            throw Metamodel.newModelError("Failed to find method " + method.getName() + " in " + container);
        return ret;
    }
    throw Metamodel.newModelError("Unsupported method container for " + method.getName() + ": " + container);
}
Also used : ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) LazyPackage(org.eclipse.ceylon.model.loader.model.LazyPackage) Package(ceylon.language.meta.declaration.Package) Package(ceylon.language.meta.declaration.Package)

Example 2 with ClassOrInterface

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

the class ClassOrInterfaceDeclarationImpl method memberApply.

@SuppressWarnings("rawtypes")
@TypeInfo("ceylon.language.meta.model::Member<Container,ceylon.language.meta.model::ClassOrInterface<Type>>&ceylon.language.meta.model::ClassOrInterface<Type>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Type") })
@Override
public <Container, Type extends Object> java.lang.Object memberApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Name("containerType") ceylon.language.meta.model.Type<? extends Object> containerType, @Name("typeArguments") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
    if (getToplevel())
        throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a toplevel declaration to a container type: use apply");
    ceylon.language.meta.model.Member<? extends Container, ceylon.language.meta.model.ClassOrInterface<?>> member = getAppliedClassOrInterface(null, null, typeArguments, containerType);
    // This is all very ugly but we're trying to make it cheaper and friendlier than just checking the full type and showing
    // implementation types to the user, such as AppliedMemberClass
    TypeDescriptor actualReifiedContainer;
    if (member instanceof MemberClassImpl)
        actualReifiedContainer = ((MemberClassImpl) member).$reifiedContainer;
    else
        actualReifiedContainer = ((MemberInterfaceImpl) member).$reifiedContainer;
    org.eclipse.ceylon.model.typechecker.model.Type actualType = Metamodel.getModel((ceylon.language.meta.model.Type<?>) member);
    Metamodel.checkReifiedTypeArgument("memberApply", "Member<$1,ClassOrInterface<$2>>&ClassOrInterface<$2>", Variance.IN, Metamodel.getProducedType(actualReifiedContainer), $reifiedContainer, Variance.OUT, actualType, $reifiedType);
    return member;
}
Also used : ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) MemberInterfaceImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberInterfaceImpl) Type(org.eclipse.ceylon.model.typechecker.model.Type) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) MemberClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 3 with ClassOrInterface

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

the class Util method javaClassForModel.

// Used by the code generator
// Copied from ceylon.interop.java
@SuppressWarnings("unchecked")
public static <T> java.lang.Class<? extends T> javaClassForModel(ClassOrInterface<? extends T> model) {
    ClassOrInterfaceDeclaration decl = model.getDeclaration();
    if (decl instanceof ClassOrInterfaceDeclarationImpl) {
        ClassOrInterfaceDeclarationImpl ci = (ClassOrInterfaceDeclarationImpl) decl;
        String prefix = null;
        while (ci.getJavaClass().equals(ObjectArray.class)) {
            model = ((ClassOrInterface) model.getTypeArgumentList().getFromFirst(0));
            decl = model.getDeclaration();
            ci = (ClassOrInterfaceDeclarationImpl) decl;
            prefix = prefix == null ? "[" : prefix + "[";
        }
        java.lang.Class result = (java.lang.Class<? extends T>) classErasure(ci.getJavaClass());
        if (prefix != null) {
            String name = result.isArray() && result.getComponentType().isPrimitive() ? prefix + result.getName() : prefix + "L" + result.getName() + ";";
            try {
                result = java.lang.Class.forName(name, false, result.getClassLoader());
            } catch (ClassNotFoundException e1) {
                rethrow(e1);
            }
        }
        return result;
    }
    throw new ceylon.language.AssertionError("Unsupported declaration type: " + decl);
}
Also used : ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) ClassOrInterfaceDeclaration(ceylon.language.meta.declaration.ClassOrInterfaceDeclaration) AssertionError(ceylon.language.AssertionError) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) Class(org.eclipse.ceylon.compiler.java.metadata.Class)

Example 4 with ClassOrInterface

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

the class ClassOrInterfaceDeclarationImpl method apply.

@SuppressWarnings("unchecked")
@Override
@TypeInfo("ceylon.language.meta.model::ClassOrInterface<Type>")
@TypeParameters({ @TypeParameter("Type") })
public <Type extends Object> ceylon.language.meta.model.ClassOrInterface<Type> apply(@Ignore TypeDescriptor $reifiedType, @Name("typeArguments") @TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::Type<ceylon.language::Anything>>") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
    if (!getToplevel())
        throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a member declaration with no container type: use memberApply");
    List<org.eclipse.ceylon.model.typechecker.model.Type> producedTypes = Metamodel.getProducedTypes(typeArguments);
    Metamodel.checkTypeArguments(null, declaration, producedTypes);
    org.eclipse.ceylon.model.typechecker.model.Reference appliedType = declaration.appliedReference(null, producedTypes);
    Metamodel.checkReifiedTypeArgument("apply", "ClassOrInterface<$1>", Variance.OUT, appliedType.getType(), $reifiedType);
    return (ClassOrInterface<Type>) Metamodel.getAppliedMetamodel(appliedType.getType());
}
Also used : ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) Type(org.eclipse.ceylon.model.typechecker.model.Type) OpenType(ceylon.language.meta.declaration.OpenType) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Aggregations

ClassOrInterface (ceylon.language.meta.model.ClassOrInterface)4 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)3 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)2 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)2 ClassOrInterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl)2 Type (org.eclipse.ceylon.model.typechecker.model.Type)2 AssertionError (ceylon.language.AssertionError)1 ClassOrInterfaceDeclaration (ceylon.language.meta.declaration.ClassOrInterfaceDeclaration)1 OpenType (ceylon.language.meta.declaration.OpenType)1 Package (ceylon.language.meta.declaration.Package)1 Class (org.eclipse.ceylon.compiler.java.metadata.Class)1 MemberClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl)1 MemberInterfaceImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberInterfaceImpl)1 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)1 LazyPackage (org.eclipse.ceylon.model.loader.model.LazyPackage)1 Reference (org.eclipse.ceylon.model.typechecker.model.Reference)1 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)1