use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class ValueConstructorDeclarationImpl method memberApply.
@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Get") })
@Override
public <Container, Get> ceylon.language.meta.model.MemberClassValueConstructor<Container, Get> memberApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Name("containerType") ceylon.language.meta.model.Type<? extends Object> containerType) {
if (getToplevel())
throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a toplevel declaration to a container type: use apply");
Type qualifyingType = Metamodel.getModel(containerType);
Metamodel.checkQualifyingType(qualifyingType, (Declaration) declaration.getContainer());
org.eclipse.ceylon.model.typechecker.model.Value modelDecl = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
// find the proper qualifying type
Type memberQualifyingType = qualifyingType.getSupertype((TypeDeclaration) modelDecl.getContainer().getContainer());
org.eclipse.ceylon.model.typechecker.model.TypedReference typedReference = modelDecl.appliedTypedReference(memberQualifyingType, Collections.<Type>emptyList());
TypeDescriptor reifiedContainer = Metamodel.getTypeDescriptorForProducedType(qualifyingType);
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("memberApply", "Attribute<$1,$2>", Variance.IN, memberQualifyingType, $reifiedContainer, Variance.OUT, getType, $reifiedGet);
ClassDeclaration clsDecl = getContainer();
ceylon.language.meta.model.MemberClass cls = clsDecl.memberClassApply($reifiedContainer, $reifiedGet, TypeDescriptor.NothingType, containerType);
return (ceylon.language.meta.model.MemberClassValueConstructor) new MemberClassValueConstructorImpl<Container, Get>(reifiedContainer, reifiedGet, this, typedReference, (MemberClassImpl) cls);
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method applyClassOrInterface.
@SuppressWarnings("rawtypes")
private <Container, Kind extends ceylon.language.meta.model.ClassOrInterface<?>> ceylon.language.meta.model.Member<Container, Kind> applyClassOrInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedKind, ClassOrInterfaceDeclarationImpl type, Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
if (type == null)
return null;
ceylon.language.meta.model.Type<Container> appliedContainer = getAppliedContainer($reifiedContainer, type);
Member<Container, Kind> member = type.getAppliedClassOrInterface(this.$reifiedType, $reifiedKind, types, appliedContainer);
// 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
TypeDescriptor actualReifiedContainer;
TypeDescriptor actualKind;
if (member instanceof MemberClassImpl) {
actualReifiedContainer = ((MemberClassImpl) member).$reifiedContainer;
actualKind = TypeDescriptor.klass(ceylon.language.meta.model.Class.class, ((MemberClassImpl) member).$reifiedType, ((MemberClassImpl) member).$reifiedArguments);
} else {
actualReifiedContainer = ((MemberInterfaceImpl) member).$reifiedContainer;
actualKind = TypeDescriptor.klass(ceylon.language.meta.model.Interface.class, ((MemberInterfaceImpl) member).$reifiedType);
}
Metamodel.checkReifiedTypeArgument("getClassOrInterface", "Member<$1,$2>&$2", Variance.IN, Metamodel.getProducedType(actualReifiedContainer), $reifiedContainer, Variance.OUT, Metamodel.getProducedType(actualKind), $reifiedKind);
return member;
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class Metamodel method getConstructors.
public static <Type> Sequential getConstructors(ClassOrInterfaceImpl<Type> cls, boolean justShared, boolean callableConstructors, TypeDescriptor $reified$Arguments, ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
ArrayList<Object> ctors = new ArrayList<>();
org.eclipse.ceylon.model.typechecker.model.Type reifiedArguments = $reified$Arguments == null ? null : Metamodel.getProducedType($reified$Arguments);
TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
if (cls.declaration instanceof ClassWithInitializerDeclarationImpl) {
Reference producedReference = cls.declaration.declaration.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(cls.declaration.declaration.getUnit(), (Functional) cls.declaration.declaration, producedReference);
if (reifiedArguments == null || reifiedArguments.isSubtypeOf(argumentsType)) {
if (hasAllAnnotations(((ClassWithInitializerDeclarationImpl) cls.declaration).getDefaultConstructor(), annotationTypeDescriptors)) {
// TODO test for arguments too
// ctors.add(new AppliedInitializer((AppliedClass)cls));
ctors.add(((ClassModel<?, ?>) cls).getDefaultConstructor());
}
}
} else {
for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) cls.declaration).constructors()) {
Declaration dd = null;
AnnotatedDeclaration annotated;
if (d instanceof CallableConstructorDeclarationImpl && callableConstructors) {
dd = ((CallableConstructorDeclarationImpl) d).declaration;
annotated = (CallableConstructorDeclaration) d;
} else if (d instanceof ValueConstructorDeclarationImpl && !callableConstructors) {
dd = ((ValueConstructorDeclarationImpl) d).declaration;
annotated = (ValueConstructorDeclaration) d;
} else {
continue;
}
// ATM this is an AND WRT annotation types: all must be present
if (!hasAllAnnotations(annotated, annotationTypeDescriptors))
continue;
if (dd instanceof Functional && reifiedArguments != null) {
// CallableConstructor need a check on the <Arguments>
Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
if (!reifiedArguments.isSubtypeOf(argumentsType))
continue;
}
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations((AnnotatedDeclaration) d, annotationTypeDescriptors))
continue;
if (dd instanceof Functional && reifiedArguments != null) {
// CallableConstructor need a check on the <Arguments>
Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
if (!reifiedArguments.isSubtypeOf(argumentsType))
continue;
}
if (!justShared || (d instanceof NestableDeclaration && ((NestableDeclaration) d).getShared())) {
Object ctor;
if (cls instanceof ClassImpl<?, ?>) {
ctor = ((ClassImpl<?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
} else {
// if (cls instanceof AppliedMemberClass<?,?,?>) {
ctor = ((MemberClassImpl<?, ?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
}
ctors.add(ctor);
}
}
}
Object[] array = ctors.toArray(new Object[ctors.size()]);
ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(TypeDescriptor.union(TypeDescriptor.klass(FunctionModel.class, cls.$reifiedType, TypeDescriptor.NothingType), TypeDescriptor.klass(ValueModel.class, cls.$reifiedType, TypeDescriptor.NothingType)), (Object[]) array);
return (ceylon.language.Sequential) iterable.sequence();
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class ClassDeclarationImpl method staticClassApply.
@SuppressWarnings("unchecked")
@Override
@TypeInfo("ceylon.language.meta.model::Class<Type,Arguments>")
@TypeParameters({ @TypeParameter("Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
public <Type, Arguments extends Sequential<? extends Object>> ceylon.language.meta.model.Class<Type, Arguments> staticClassApply(@Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, @Name("containerType") @TypeInfo("ceylon.language.meta.model::Type<ceylon.language::Anything>") ceylon.language.meta.model.Type<? extends Object> containerType, @Name("typeArguments") @TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::Type<ceylon.language::Anything>>") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
if (!getStatic()) {
throw new ceylon.language.meta.model.TypeApplicationException("Cannot staticClassApply a non-static declaration: use " + (getToplevel() ? "apply" : "memberClassApply"));
}
List<org.eclipse.ceylon.model.typechecker.model.Type> producedTypes = Metamodel.getProducedTypes(typeArguments);
if (getStatic()) {
producedTypes.addAll(0, Metamodel.getModel(containerType).getTypeArgumentList());
}
Metamodel.checkTypeArguments(null, declaration, producedTypes);
org.eclipse.ceylon.model.typechecker.model.Type ct = Metamodel.getProducedType(Metamodel.getTypeDescriptor(containerType));
org.eclipse.ceylon.model.typechecker.model.Reference appliedType = declaration.appliedReference(ct, producedTypes);
// MemberClassImpl<Object, Type, Arguments> ret = (MemberClassImpl<Object, Type, Arguments>) Metamodel.getAppliedMetamodel(appliedType.getType());
// Metamodel.checkReifiedTypeArgument("staticClassApply", "Class<$1,$2>", Variance.OUT, appliedType.getType(), $reifiedType,
// Variance.IN, Metamodel.getProducedType(ret.$reifiedArguments), $reifiedArguments);
// return (ClassImpl)ret.$call$();
TypeDescriptor reifiedArguments;
if (!declaration.isAnonymous())
reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) declaration, appliedType.getType());
else
reifiedArguments = TypeDescriptor.NothingType;
TypeDescriptor reifiedType = Metamodel.getTypeDescriptorForProducedType(appliedType.getType());
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl(reifiedType, reifiedArguments, appliedType.getType(), null, null);
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl in project ceylon by eclipse.
the class ClassDeclarationImpl method memberClassApply.
@SuppressWarnings({ "unchecked", "rawtypes" })
@TypeInfo("ceylon.language.meta.model::MemberClass<Container,Type,Arguments>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@Override
public <Container, Type, Arguments extends Sequential<? extends Object>> ceylon.language.meta.model.MemberClass<Container, Type, Arguments> memberClassApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, @Name("containerType") ceylon.language.meta.model.Type<? extends Object> containerType, @Name("typeArguments") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> typeArguments) {
if (getToplevel())
throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a toplevel declaration to a container type: use apply");
ceylon.language.meta.model.MemberClass<Container, Type, Arguments> member = (ceylon.language.meta.model.MemberClass) getAppliedClassOrInterface(null, null, typeArguments, containerType);
// 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
TypeDescriptor actualReifiedContainer = ((MemberClassImpl) member).$reifiedContainer;
TypeDescriptor actualReifiedArguments = ((MemberClassImpl) member).$reifiedArguments;
org.eclipse.ceylon.model.typechecker.model.Type actualType = Metamodel.getModel((ceylon.language.meta.model.Type<?>) member);
Metamodel.checkReifiedTypeArgument("memberApply", "Member<$1,Class<$2,$3>>&Class<$2,$3>", Variance.IN, Metamodel.getProducedType(actualReifiedContainer), $reifiedContainer, Variance.OUT, actualType, $reifiedType, Variance.IN, Metamodel.getProducedType(actualReifiedArguments), $reifiedArguments);
return member;
}
Aggregations