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);
}
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_();
}
};
}
};
}
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();
}
};
}
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;
}
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;
}
Aggregations