Search in sources :

Example 11 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ClassOrInterfaceDeclarationImpl method filteredDeclaredMembers.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <Kind> Sequential<? extends Kind> filteredDeclaredMembers(@Ignore TypeDescriptor $reifiedKind, Predicates.Predicate predicate) {
    if (predicate == Predicates.false_()) {
        return (Sequential<? extends Kind>) empty_.get_();
    }
    checkInit();
    ArrayList<Kind> members = new ArrayList<Kind>(declarations.size());
    for (ceylon.language.meta.declaration.NestableDeclaration decl : declaredDeclarations) {
        Declaration declaration2 = ((NestableDeclarationImpl) decl).declaration;
        if (!declaration2.isNativeHeader() && predicate.accept(declaration2)) {
            members.add((Kind) decl);
        }
    }
    java.lang.Object[] array = members.toArray(new java.lang.Object[0]);
    ObjectArrayIterable<Kind> iterable = new ObjectArrayIterable<Kind>($reifiedKind, (Kind[]) array);
    return (ceylon.language.Sequential) iterable.sequence();
}
Also used : NestableDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.NestableDeclarationImpl) ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) Sequential(ceylon.language.Sequential) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 12 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ClassWithInitializerDeclarationConstructor method apply.

@Override
public <Result, Arguments extends Sequential<? extends Object>> CallableConstructor<Result, Arguments> apply(TypeDescriptor $reified$Result, TypeDescriptor $reified$Arguments, Sequential<? extends Type<? extends Object>> typeArguments) {
    // apply the given type arguments to the containing class
    ClassDeclaration clsDecl = getContainer();
    ceylon.language.meta.model.Class<? extends Result, ?> cls = clsDecl.<Result, Sequential<? extends java.lang.Object>>classApply($reified$Result, Nothing.NothingType, typeArguments);
    // then get the constructor from that
    return Util.assertExists((CallableConstructor) cls.<Arguments>getDeclaredConstructor($reified$Arguments, getName()));
}
Also used : ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) Sequential(ceylon.language.Sequential) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Example 13 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class Util method sequentialWrapperBoxed.

/**
 * <p>Return a {@link Sequential Sequential&lt;Character&gt;} copying the
 * given {@code char[]} elements
 * (subsequent changes to the array will not be visible in
 * the returned {@link Sequential}).</p>
 *
 * <p>Used to obtain a {@code Sequential<Character>} from a {@code char[]}.</p>
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Sequential<? extends ceylon.language.Character> sequentialWrapperBoxed(char[] elements) {
    if (elements.length == 0) {
        return (Sequential) empty_.get_();
    }
    int total = Character.codePointCount(elements, 0, elements.length);
    java.lang.Object[] newArray = new java.lang.Object[total];
    int i = 0;
    char lastHighSurrogate = 0;
    for (char element : elements) {
        if (lastHighSurrogate != 0) {
            if (Character.isLowSurrogate(element)) {
                newArray[i++] = ceylon.language.Character.instance(Character.toCodePoint(lastHighSurrogate, element));
                lastHighSurrogate = 0;
            } else {
                throw new AssertionError("Illegal low surrogate value " + element + " after high surrogate value " + lastHighSurrogate);
            }
        } else if (Character.isHighSurrogate(element)) {
            lastHighSurrogate = element;
        } else if (Character.isLowSurrogate(element)) {
            throw new AssertionError("Illegal low surrogate value " + element + " after no high surrogate value");
        } else {
            newArray[i++] = ceylon.language.Character.instance(element);
        }
    }
    if (lastHighSurrogate != 0)
        throw new AssertionError("Missing low surrogate value after high surrogate value " + lastHighSurrogate);
    return new Tuple(ceylon.language.Character.$TypeDescriptor$, newArray);
}
Also used : Sequential(ceylon.language.Sequential) AssertionError(ceylon.language.AssertionError) Tuple(ceylon.language.Tuple)

Example 14 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ValueConstructorDeclarationImpl method apply.

@Override
@TypeInfo("ceylon.language.meta.model::Value<Get>")
@TypeParameters({ @TypeParameter("Get") })
public <Get> ceylon.language.meta.model.ValueConstructor<Get> apply(@Ignore TypeDescriptor $reifiedGet) {
    // TODO if(!getToplevel())
    // throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a member declaration with no container type: use memberApply");
    // TODO what is Set is anything other than Nothing?
    // c.f. classApply with an incorect parameters
    org.eclipse.ceylon.model.typechecker.model.Value modelDecl = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
    org.eclipse.ceylon.model.typechecker.model.TypedReference typedReference = modelDecl.appliedTypedReference(null, Collections.<Type>emptyList());
    org.eclipse.ceylon.model.typechecker.model.Type getType = typedReference.getType();
    TypeDescriptor reifiedGet = Metamodel.getTypeDescriptorForProducedType(getType.getQualifyingType());
    // immutable values have Set=Nothing
    // org.eclipse.ceylon.model.typechecker.model.Type setType = getVariable() ?
    // getType : modelDecl.getUnit().getNothingType();
    // TypeDescriptor reifiedSet = getVariable() ? reifiedGet : TypeDescriptor.NothingType;
    Metamodel.checkReifiedTypeArgument("apply", "Value<$1>", Variance.OUT, getType, $reifiedGet);
    // XXX This is a lie, and we only get away with it due to erasure
    ClassDeclaration clsDecl = getContainer();
    ceylon.language.meta.model.Class<? extends Get, ?> cls = clsDecl.<Get, Sequential<? extends java.lang.Object>>classApply($reifiedGet, Nothing.NothingType, (Sequential) empty_.get_());
    return (ceylon.language.meta.model.ValueConstructor<Get>) new ValueConstructorImpl<Get>(reifiedGet, this, typedReference, (ClassImpl) cls, null);
}
Also used : MemberClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl) ClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl) Type(org.eclipse.ceylon.model.typechecker.model.Type) Value(org.eclipse.ceylon.model.typechecker.model.Value) ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Sequential(ceylon.language.Sequential) Value(org.eclipse.ceylon.model.typechecker.model.Value) 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)

Example 15 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ClassImpl method getDeclaredConstructor.

@Override
@TypeParameters(@TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>"))
@TypeInfo("ceylon.language.meta.model::CallableConstructor<Type,Arguments>|ceylon.language.meta.model::ValueConstructor<Type>|ceylon.language::Null")
public <Arguments extends Sequential<? extends Object>> java.lang.Object getDeclaredConstructor(@Ignore TypeDescriptor $reified$Arguments, @Name("name") String name) {
    checkInit();
    final ceylon.language.meta.declaration.Declaration ctor = ((ClassDeclarationImpl) declaration).getConstructorDeclaration(name);
    if (ctor == null)
        return null;
    if (ctor instanceof CallableConstructorDeclaration) {
        if (ctor instanceof ClassWithInitializerDeclarationConstructor) {
            TypeDescriptor actualReifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.declaration.getUnit(), (Functional) ((ClassWithInitializerDeclarationConstructor) ctor).declaration, this.producedType);
            Metamodel.checkReifiedTypeArgument("getDeclaredConstructor", "CallableConstructor<$1,$2>", // // this line is bullshit since it's always true, but otherwise we can't substitute the error message above :(
            Variance.OUT, this.producedType, $reifiedType, Variance.IN, Metamodel.getProducedType(actualReifiedArguments), $reified$Arguments);
            ClassInitializerConstructor c = new ClassInitializerConstructor<>(this);
            return c;
        }
        CallableConstructorDeclarationImpl callableCtor = (CallableConstructorDeclarationImpl) ctor;
        org.eclipse.ceylon.model.typechecker.model.Type constructorType = callableCtor.constructor.appliedType(this.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
        // return new AppliedConstructor<Type,Args>(this.$reifiedType, actualReifiedArguments, this, constructorType, ctor, this.instance);
        // Reference reference = ((Function)callableCtor.declaration).getReference();
        Reference reference;
        if (callableCtor.declaration instanceof Function) {
            reference = ((Function) callableCtor.declaration).appliedTypedReference(producedType, null);
        } else if (callableCtor.declaration instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
            reference = ((org.eclipse.ceylon.model.typechecker.model.Class) callableCtor.declaration).appliedReference(producedType, null);
        } else if (callableCtor.declaration instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
            reference = ((org.eclipse.ceylon.model.typechecker.model.Constructor) callableCtor.declaration).appliedReference(producedType, null);
        } else {
            throw Metamodel.newModelError("Unexpect declaration " + callableCtor.declaration);
        }
        // anonymous classes don't have parameter lists
        TypeDescriptor actualReifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.declaration.getUnit(), (Functional) callableCtor.declaration, reference);
        // 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
        Metamodel.checkReifiedTypeArgument("getConstructor", "Constructor<$1,$2>", // this line is bullshit since it's always true, but otherwise we can't substitute the error message above :(
        Variance.OUT, this.producedType, $reifiedType, Variance.IN, Metamodel.getProducedType(actualReifiedArguments), $reified$Arguments);
        CallableConstructorImpl<Type, Sequential<? extends Object>> appliedConstructor = new CallableConstructorImpl<Type, Sequential<? extends java.lang.Object>>(this.$reifiedType, $reified$Arguments, reference, callableCtor, this, instance);
        Metamodel.checkReifiedTypeArgument("apply", "CallableConstructor<$1,$2>", Variance.OUT, producedType, $reifiedType, Variance.IN, Metamodel.getProducedTypeForArguments(declaration.declaration.getUnit(), (Functional) callableCtor.declaration, reference), $reified$Arguments);
        return appliedConstructor;
    } else if (ctor instanceof ValueConstructorDeclaration) {
        ValueConstructorDeclarationImpl callableCtor = (ValueConstructorDeclarationImpl) ctor;
        org.eclipse.ceylon.model.typechecker.model.Type constructorType = callableCtor.constructor.appliedType(this.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
        TypedDeclaration val = (TypedDeclaration) callableCtor.constructor.getContainer().getDirectMember(callableCtor.constructor.getName(), null, false);
        return new ValueConstructorImpl<Type>(this.$reifiedType, callableCtor, val.getTypedReference(), this, instance);
    } else {
        throw new AssertionError("Constructor neither CallableConstructorDeclaration nor ValueConstructorDeclaration");
    }
}
Also used : CallableConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration) Function(org.eclipse.ceylon.model.typechecker.model.Function) Sequential(ceylon.language.Sequential) ClassWithInitializerDeclarationConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor) AssertionError(ceylon.language.AssertionError) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) CallableConstructorImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.CallableConstructorImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) ClassInitializerConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassInitializerConstructor) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) CallableConstructor(ceylon.language.meta.model.CallableConstructor) ValueConstructor(ceylon.language.meta.model.ValueConstructor) ClassWithInitializerDeclarationConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor) ClassInitializerConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassInitializerConstructor) Class(org.eclipse.ceylon.model.typechecker.model.Class) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) ValueConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Aggregations

Sequential (ceylon.language.Sequential)21 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)16 ArrayList (java.util.ArrayList)12 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)12 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)12 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)12 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)10 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)9 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)6 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)5 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)5 Type (org.eclipse.ceylon.model.typechecker.model.Type)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)4 AssertionError (ceylon.language.AssertionError)3 CallableConstructorDeclaration (ceylon.language.meta.declaration.CallableConstructorDeclaration)3 ClassOrInterfaceDeclaration (ceylon.language.meta.declaration.ClassOrInterfaceDeclaration)3 OpenType (ceylon.language.meta.declaration.OpenType)3 ValueConstructorDeclaration (ceylon.language.meta.declaration.ValueConstructorDeclaration)3 ValueDeclaration (ceylon.language.meta.declaration.ValueDeclaration)3 Attribute (ceylon.language.meta.model.Attribute)3