use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ValueTypeTests method validateVTMethodUnchecked.
// Check if the given method should have a static companion method
// and if so check that it exists and adheres to all the rules
private void validateVTMethodUnchecked(Class<?> clazz, Method classMethod, Method typedMethod) {
String mthName = clazz.getName() + "::" + classMethod.getName() + "()";
System.err.println(mthName);
Assert.assertTrue("Overloaded method " + mthName + " can't have more parameters than the method it overloads", classMethod.getParameterTypes().length <= typedMethod.getParameterTypes().length);
Method staticMethod = findStaticCompanionMethod(clazz, classMethod, typedMethod);
Assert.assertNotNull("Static companion for " + mthName + " not found", staticMethod);
TypeInfo returnTypeInfo = typedMethod.getAnnotation(TypeInfo.class);
Assert.assertEquals("Returns types for static and class methods " + mthName + " do not coincide", getUnboxedType(classMethod.getReturnType(), returnTypeInfo), staticMethod.getReturnType());
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo 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.metadata.TypeInfo 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.metadata.TypeInfo in project ceylon by eclipse.
the class Integer method max.
@TypeParameters(@TypeParameter(value = "Absent", satisfies = "ceylon.language::Null"))
@TypeInfo("ceylon.language::Integer|Absent")
public static <Absent> java.lang.Object max(@Ignore TypeDescriptor $reifiedAbsent, @TypeInfo("ceylon.language::Iterable<ceylon.language::Integer,Absent>") @Name("integers") Iterable<? extends Integer, ? extends java.lang.Object> integers) {
if (integers instanceof Array) {
java.lang.Object array = ((Array<?>) integers).toArray();
if (array instanceof int[]) {
int[] intArray = (int[]) array;
int s = intArray.length;
if (s == 0) {
return null;
}
int max = intArray[0];
for (int i = 1; i < s; i++) {
max = Math.max(max, intArray[i]);
}
return instance(max);
}
if (array instanceof long[]) {
long[] longArray = (long[]) array;
int s = longArray.length;
if (s == 0) {
return null;
}
long max = longArray[0];
for (int i = 1; i < s; i++) {
max = Math.max(max, longArray[i]);
}
return instance(max);
}
}
if (integers instanceof List) {
@SuppressWarnings("unchecked") List<? extends Integer> list = (List<? extends Integer>) integers;
long size = list.getSize();
if (size == 0) {
return null;
}
long max = integers.getFromFirst(0).value;
for (int i = 1; i < size; i++) {
max = Math.max(max, list.getFromFirst(i).value);
}
return instance(max);
}
long max = 0l;
boolean first = true;
Iterator<? extends Integer> it = integers.iterator();
java.lang.Object o;
while ((o = it.next()) != finished_.get_()) {
long x = ((Integer) o).value;
if (first) {
max = x;
first = false;
} else {
max = Math.max(max, x);
}
}
return first ? null : instance(max);
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo 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);
}
Aggregations