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();
}
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()));
}
use of ceylon.language.Sequential in project ceylon by eclipse.
the class Util method sequentialWrapperBoxed.
/**
* <p>Return a {@link Sequential Sequential<Character>} 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);
}
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);
}
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");
}
}
Aggregations