Search in sources :

Example 31 with TypeDescriptor

use of org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor in project ceylon by eclipse.

the class Array method instance.

@Ignore
public static <T> Array<T> instance(T[] array) {
    if (array == null) {
        return null;
    }
    java.lang.Class<?> componentType = array.getClass().getComponentType();
    TypeDescriptor optionalType = TypeDescriptor.union(Null.$TypeDescriptor$, TypeDescriptor.klass(componentType));
    return new Array<T>(optionalType, array);
}
Also used : TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Example 32 with TypeDescriptor

use of org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor in project ceylon by eclipse.

the class Array method locations.

@Override
@TypeInfo("{ceylon.language::Entry<ceylon.language::Integer,Element>*}")
public Iterable<? extends Entry<? extends Integer, ? extends Element>, ? extends java.lang.Object> locations(@Name("selecting") @FunctionalParameter("(element)") @TypeInfo("ceylon.language::Boolean(Element&ceylon.language::Object)") final Callable<? extends Boolean> selecting) {
    final TypeDescriptor klass = TypeDescriptor.klass(Entry.class, Integer.$TypeDescriptor$, $reifiedElement);
    return new BaseIterable<Entry<? extends Integer, ? extends Element>, java.lang.Object>(klass, Null.$TypeDescriptor$) {

        @Override
        public Iterator<? extends Entry<? extends Integer, ? extends Element>> iterator() {
            return new BaseIterator<Entry<? extends Integer, ? extends Element>>(klass) {

                int index = 0;

                @Override
                public java.lang.Object next() {
                    while (index < size) {
                        Element element = unsafeItem(index);
                        if (selecting.$call$(element).booleanValue()) {
                            return new Entry(Integer.$TypeDescriptor$, $reifiedElement, Integer.instance(index++), element);
                        }
                        index++;
                    }
                    return finished_.get_();
                }
            };
        }
    };
}
Also used : TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) BaseIterator(ceylon.language.impl.BaseIterator) BaseIterable(ceylon.language.impl.BaseIterable) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 33 with TypeDescriptor

use of org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor in project ceylon by eclipse.

the class flatten_ method flatten.

@TypeParameters({ @TypeParameter(value = "Return"), @TypeParameter(value = "Args", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language::Callable<Return,Args>")
public static <Return, Args> Callable<Return> flatten(@Ignore final TypeDescriptor $reifiedReturn, @Ignore final TypeDescriptor $reifiedArgs, @Name("tupleFunction") @FunctionalParameter("(tuple)") @TypeInfo("ceylon.language::Callable<Return,ceylon.language::Tuple<Args,Args,ceylon.language::Empty>>") final Callable<? extends Return> tupleFunction) {
    return new AbstractCallable<Return>($reifiedReturn, $reifiedArgs, null, (short) -1) {

        private TypeDescriptor getElementType(java.lang.Object[] args, Sequential<?> tail) {
            if ($reifiedArgs instanceof TypeDescriptor.Class) {
                // optimization for common cases
                TypeDescriptor.Class reifiedClass = (TypeDescriptor.Class) $reifiedArgs;
                TypeDescriptor sequenceElement = reifiedClass.getSequenceElement();
                if (sequenceElement != null)
                    return sequenceElement;
            }
            TypeDescriptor[] types = new TypeDescriptor[args.length + (tail != null ? 1 : 0)];
            for (int i = 0; i < args.length; i++) {
                types[i] = getArgType(args[i]);
            }
            if (tail != null) {
                TypeDescriptor restType = getTypeDescriptor(tail);
                TypeDescriptor elementType = Metamodel.getIteratedTypeDescriptor(restType);
                types[args.length] = elementType;
            }
            return TypeDescriptor.union(types);
        }

        private TypeDescriptor getArgType(java.lang.Object arg) {
            return getTypeDescriptor(arg);
        }

        @SuppressWarnings("rawtypes")
        private Tuple tuple(java.lang.Object[] args) {
            return new Tuple(getElementType(args, null), args);
        }

        @SuppressWarnings("rawtypes")
        private Tuple tuple(java.lang.Object[] args, Sequential<?> tail) {
            return Tuple.instance(getElementType(args, tail), args, tail);
        }

        @Override
        public Return $call$() {
            return tupleFunction.$call$(empty_.get_());
        }

        @Override
        public Return $call$(java.lang.Object arg0) {
            return tupleFunction.$call$(tuple(new java.lang.Object[] { arg0 }));
        }

        @Override
        public Return $call$(java.lang.Object arg0, java.lang.Object arg1) {
            return tupleFunction.$call$(tuple(new java.lang.Object[] { arg0, arg1 }));
        }

        @Override
        public Return $call$(java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2) {
            return tupleFunction.$call$(tuple(new java.lang.Object[] { arg0, arg1, arg2 }));
        }

        @Override
        public Return $call$(java.lang.Object... args) {
            return tupleFunction.$call$(tuple(args));
        }

        @Override
        public Return $callvariadic$(Sequential<?> arg0) {
            return tupleFunction.$call$(arg0);
        }

        @Override
        public Return $callvariadic$(java.lang.Object arg0, Sequential<?> arg1) {
            return tupleFunction.$call$(tuple(new java.lang.Object[] { arg0 }, arg1));
        }

        @Override
        public Return $callvariadic$(java.lang.Object arg0, java.lang.Object arg1, Sequential<?> arg2) {
            return tupleFunction.$call$(tuple(new java.lang.Object[] { arg0, arg1 }, arg2));
        }

        @Override
        public Return $callvariadic$(java.lang.Object... args) {
            // it is an array of the first args.length-1 params followed by a Sequential last
            java.lang.Object[] first = new java.lang.Object[args.length - 1];
            System.arraycopy(args, 0, first, 0, args.length - 1);
            return tupleFunction.$call$(tuple(first, (Sequential<?>) args[args.length - 1]));
        }

        @Override
        public java.lang.String toString() {
            return $getType$().toString();
        }
    };
}
Also used : AbstractCallable(org.eclipse.ceylon.compiler.java.language.AbstractCallable) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Metamodel.getTypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel.getTypeDescriptor) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 34 with TypeDescriptor

use of org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor in project ceylon by eclipse.

the class Tuple method computeType.

private TypeDescriptor computeType() {
    TypeDescriptor restType = getTypeDescriptor(rest);
    TypeDescriptor elementType = Metamodel.getIteratedTypeDescriptor(restType);
    for (int i = array.length - 1; i >= 0; i--) {
        TypeDescriptor elemType = $getElementType(i);
        elementType = TypeDescriptor.union(elementType, elemType);
        restType = TypeDescriptor.klass(Tuple.class, elementType, elemType, restType);
    }
    return restType;
}
Also used : TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Metamodel.getTypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel.getTypeDescriptor)

Example 35 with TypeDescriptor

use of org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor in project ceylon by eclipse.

the class Tuple method $getType$.

@Override
@Ignore
public TypeDescriptor $getType$() {
    SoftReference<TypeDescriptor> cachedType = $cachedType;
    TypeDescriptor type = cachedType != null ? cachedType.get() : null;
    if (type == null) {
        synchronized (this) {
            cachedType = $cachedType;
            type = cachedType != null ? cachedType.get() : null;
            if (type == null) {
                type = computeType();
                $cachedType = new SoftReference<TypeDescriptor>(type);
            }
        }
    }
    return type;
}
Also used : TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Metamodel.getTypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel.getTypeDescriptor) Ignore(org.eclipse.ceylon.compiler.java.metadata.Ignore)

Aggregations

TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)46 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)23 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)18 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)17 Sequential (ceylon.language.Sequential)13 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)12 Type (org.eclipse.ceylon.model.typechecker.model.Type)11 OpenType (ceylon.language.meta.declaration.OpenType)9 ArrayList (java.util.ArrayList)9 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)9 MemberClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl)7 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)5 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)5 AssertionError (ceylon.language.AssertionError)4 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)4 ClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl)4 ReflectionClass (org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass)4 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)4 Metamodel.getTypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel.getTypeDescriptor)3 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)3