use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ClassOrInterfaceDeclarationImpl method apply.
@SuppressWarnings("unchecked")
@Override
@TypeInfo("ceylon.language.meta.model::ClassOrInterface<Type>")
@TypeParameters({ @TypeParameter("Type") })
public <Type extends Object> ceylon.language.meta.model.ClassOrInterface<Type> apply(@Ignore TypeDescriptor $reifiedType, @Name("typeArguments") @TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::Type<ceylon.language::Anything>>") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
if (!getToplevel())
throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a member declaration with no container type: use memberApply");
List<org.eclipse.ceylon.model.typechecker.model.Type> producedTypes = Metamodel.getProducedTypes(typeArguments);
Metamodel.checkTypeArguments(null, declaration, producedTypes);
org.eclipse.ceylon.model.typechecker.model.Reference appliedType = declaration.appliedReference(null, producedTypes);
Metamodel.checkReifiedTypeArgument("apply", "ClassOrInterface<$1>", Variance.OUT, appliedType.getType(), $reifiedType);
return (ClassOrInterface<Type>) Metamodel.getAppliedMetamodel(appliedType.getType());
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class MemberClassImpl method getDeclaredConstructor.
@Override
@TypeParameters({ @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Anything[]") })
@TypeInfo("ceylon.language.meta.model::MemberClassCallableConstructor<Container,Type,Arguments>|ceylon.language.meta.model::MemberClassValueConstructor<Container,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) {
return new MemberClassInitializerConstructor<>(this.$reifiedContainer, this.$reifiedType, $reified$Arguments, this);
}
CallableConstructorDeclarationImpl callableCtor = (CallableConstructorDeclarationImpl) ctor;
// anonymous classes don't have parameter lists
// TypeDescriptor actualReifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.declaration.getUnit(), (Functional)callableCtor.constructor, this.producedType);
// 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), $reifiedArguments);
// return new AppliedConstructor<Type,Args>(this.$reifiedType, actualReifiedArguments, this, constructorType, ctor, this.instance);
org.eclipse.ceylon.model.typechecker.model.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);
}
return new MemberClassCallableConstructorImpl<Container, Type, Sequential<? extends java.lang.Object>>($reifiedContainer, this.$reifiedType, $reified$Arguments, reference, callableCtor, this);
} 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 MemberClassValueConstructorImpl<Container, Type>(// <Container>
$reifiedContainer, // <Get>
this.$reifiedType, callableCtor, val.getTypedReference(), this);
} else {
throw new AssertionError("Constructor neither CallableConstructorDeclaration nor ValueConstructorDeclaration");
}
/*checkInit();
final FreeConstructor ctor = (FreeConstructor)((FreeClass)declaration).getConstructorDeclaration(name);
if(ctor == null)
return null;
return new AppliedMemberClassConstructor($reifiedContainer, this.$reifiedType, reified$Arguments, this, ctor.constructor.appliedType(this.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList()), ctor);*/
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ModuleImpl method getDependencies.
@Override
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.declaration::Import>")
public Sequential<? extends Import> getDependencies() {
// no need to synchronise as concurrent invocations should get the same array back
if (this.dependencies == null) {
List<org.eclipse.ceylon.model.typechecker.model.ModuleImport> modelImports = declaration.getImports();
// FreeImport[] imports = new FreeImport[modelImports.size()];
ArrayList<ImportImpl> sb = new ArrayList<ImportImpl>(modelImports.size());
for (org.eclipse.ceylon.model.typechecker.model.ModuleImport moduleImport : modelImports) {
sb.add(new ImportImpl(this, moduleImport));
}
ImportImpl[] array = sb.toArray(new ImportImpl[0]);
this.dependencies = new ObjectArrayIterable<ImportImpl>(Import.$TypeDescriptor$, array).sequence();
}
return this.dependencies;
}
Aggregations