use of ceylon.language.meta.model.CallableConstructor 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