Search in sources :

Example 26 with TypeParameters

use of org.eclipse.ceylon.compiler.java.metadata.TypeParameters in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getAttribute.

@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Get"), @TypeParameter(value = "Set") })
@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get,Set>|ceylon.language::Null")
public <Container, Get, Set> ceylon.language.meta.model.Attribute<Container, Get, Set> getAttribute(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, String name) {
    // checkInit();
    ValueDeclarationImpl value = declaration.findValue(name);
    if (value == null)
        return null;
    MemberLookup<ValueDeclarationImpl, Container> lookup = lookupMember(ValueDeclarationImpl.$TypeDescriptor$, $reifiedContainer, value);
    if (lookup == null)
        return null;
    return lookup.declaration.<Container, Get, Set>memberApply($reifiedContainer, $reifiedGet, $reifiedSet, lookup.containerMetamodel);
}
Also used : ValueDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 27 with TypeParameters

use of org.eclipse.ceylon.compiler.java.metadata.TypeParameters in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getDeclaredMethod.

@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::Method<Container,Type,Arguments>|ceylon.language::Null")
public <Container, Type, Arguments extends Sequential<? extends Object>> ceylon.language.meta.model.Method<Container, Type, Arguments> getDeclaredMethod(@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 FunctionDeclarationImpl method = declaration.findDeclaredMethod(name);
    if (method == null)
        return null;
    return method.memberApply($reifiedContainer, $reifiedType, $reifiedArguments, (ceylon.language.meta.model.Type<Container>) this, types);
}
Also used : Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) FunctionDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 28 with TypeParameters

use of org.eclipse.ceylon.compiler.java.metadata.TypeParameters in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getClassOrInterface.

@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> getClassOrInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedKind, 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;
    MemberLookup<ClassOrInterfaceDeclarationImpl, Container> lookup = lookupMember(ClassOrInterfaceDeclarationImpl.$TypeDescriptor$, $reifiedContainer, type);
    if (lookup == null)
        return null;
    return applyClassOrInterface($reifiedContainer, $reifiedKind, lookup.declaration, types);
}
Also used : 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 29 with TypeParameters

use of org.eclipse.ceylon.compiler.java.metadata.TypeParameters in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getMethod.

@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::Method<Container,Type,Arguments>|ceylon.language::Null")
public <Container, Type, Arguments extends Sequential<? extends Object>> ceylon.language.meta.model.Method<Container, Type, Arguments> getMethod(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
    checkInit();
    final FunctionDeclarationImpl method = declaration.findMethod(name);
    if (method == null)
        return null;
    MemberLookup<FunctionDeclarationImpl, Container> lookup = lookupMember(FunctionDeclarationImpl.$TypeDescriptor$, $reifiedContainer, method);
    if (lookup == null)
        return null;
    return lookup.declaration.memberApply($reifiedContainer, $reifiedType, $reifiedArguments, lookup.containerMetamodel, types);
}
Also used : FunctionDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 30 with TypeParameters

use of org.eclipse.ceylon.compiler.java.metadata.TypeParameters in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getClasses.

@SuppressWarnings({ "unchecked", "rawtypes", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::MemberClass<Container,Type,Arguments>>")
public <Container, Type, Arguments extends Sequential<? extends Object>> ceylon.language.Sequential<? extends ceylon.language.meta.model.MemberClass<? super Container, ? extends Type, ? super Arguments>> getClasses(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, @Sequenced ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
    checkInit();
    Sequential<? extends ClassDeclaration> declaredDeclarations = declaration.<ClassDeclaration>memberDeclarations(ClassDeclaration.$TypeDescriptor$);
    if (declaredDeclarations.getEmpty())
        return (ceylon.language.Sequential) empty_.get_();
    org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
    org.eclipse.ceylon.model.typechecker.model.Type reifiedType = Metamodel.getProducedType($reifiedType);
    org.eclipse.ceylon.model.typechecker.model.Type reifiedArguments = Metamodel.getProducedType($reifiedArguments);
    Iterator<?> iterator = declaredDeclarations.iterator();
    Object it;
    TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
    TypeDescriptor reifiedKind = TypeDescriptor.klass(ceylon.language.meta.model.MemberClass.class, $reifiedContainer, $reifiedType, $reifiedArguments);
    ArrayList<ceylon.language.meta.model.MemberClass<? super Container, ? extends Type, ? super Arguments>> members = new ArrayList<ceylon.language.meta.model.MemberClass<? super Container, ? extends Type, ? super Arguments>>((int) declaredDeclarations.getSize());
    while ((it = iterator.next()) != finished_.get_()) {
        ClassDeclarationImpl decl = (ClassDeclarationImpl) it;
        MemberLookup<ClassDeclarationImpl, Container> lookup = lookupMember(ClassDeclarationImpl.$TypeDescriptor$, $reifiedContainer, reifiedContainer, decl);
        if (lookup == null)
            continue;
        // skip generic classes
        if (!lookup.declaration.getTypeParameterDeclarations().getEmpty())
            continue;
        // ATM this is an AND WRT annotation types: all must be present
        if (!Metamodel.hasAllAnnotations(lookup.declaration, annotationTypeDescriptors))
            continue;
        addClassIfCompatible($reifiedContainer, $reifiedType, $reifiedArguments, members, lookup.declaration, lookup.qualifyingType, lookup.containerMetamodel, reifiedType, reifiedArguments);
    }
    ceylon.language.meta.model.MemberClass[] array = members.toArray(new ceylon.language.meta.model.MemberClass[0]);
    ObjectArrayIterable<ceylon.language.meta.model.MemberClass> iterable = new ObjectArrayIterable<ceylon.language.meta.model.MemberClass>(reifiedKind, array);
    return (ceylon.language.Sequential) iterable.sequence();
}
Also used : ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Sequential(ceylon.language.Sequential) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) 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

TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)32 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)32 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)23 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)17 Sequential (ceylon.language.Sequential)10 ArrayList (java.util.ArrayList)8 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)8 ClassOrInterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl)8 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)8 IncompatibleTypeException (ceylon.language.meta.model.IncompatibleTypeException)7 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)6 Type (org.eclipse.ceylon.model.typechecker.model.Type)5 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)4 OpenType (ceylon.language.meta.declaration.OpenType)4 FunctionDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl)4 InterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl)4 ValueDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl)4 MemberClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl)4 Value (org.eclipse.ceylon.model.typechecker.model.Value)3 AssertionError (ceylon.language.AssertionError)2