use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ValueDeclarationImpl method memberApply.
@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get,Set>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Get"), @TypeParameter(value = "Set", defaultValue = "ceylon.language::Nothing") })
@Override
public <Container, Get, Set> ceylon.language.meta.model.Attribute<Container, Get, Set> memberApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, @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);
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());
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);
// 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,$3>", Variance.IN, memberQualifyingType, $reifiedContainer, Variance.OUT, getType, $reifiedGet, Variance.IN, setType, $reifiedSet);
return new AttributeImpl<Container, Get, Set>(reifiedContainer, reifiedGet, reifiedSet, this, typedReference, containerType);
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo 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");
}
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredInterface.
@SuppressWarnings({ "unchecked", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type") })
@TypeInfo("ceylon.language.meta.model::MemberInterface<Container,Type>|ceylon.language::Null")
public <Container, Type> ceylon.language.meta.model.MemberInterface<Container, Type> getDeclaredInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
checkInit();
// do not return the attribute if the container is not a subtype of this type
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
if (!reifiedContainer.isSubtypeOf(producedType))
throw new IncompatibleTypeException("Specified container type '" + reifiedContainer.asString() + "' is not a valid subtype of this type");
final ClassOrInterfaceDeclarationImpl type = declaration.findDeclaredType(name);
if (type == null)
return null;
if (type instanceof InterfaceDeclarationImpl == false)
throw new IncompatibleTypeException("Specified member is not an interface: " + name);
return (ceylon.language.meta.model.MemberInterface<Container, Type>) type.memberApply($reifiedContainer, $reifiedType, (ceylon.language.meta.model.Type<Container>) this, types);
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredAttributes.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Get"), @TypeParameter(value = "Set") })
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::Attribute<Container,Get,Set>>")
public <Container, Get, Set> ceylon.language.Sequential<? extends ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>> getDeclaredAttributes(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, @Sequenced ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
checkInit();
// check the container type first
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
if (!reifiedContainer.isSubtypeOf(this.producedType))
return (ceylon.language.Sequential) empty_.get_();
Sequential<? extends ValueDeclaration> declaredDeclarations = declaration.<ValueDeclaration>declaredMemberDeclarations(ValueDeclaration.$TypeDescriptor$);
if (declaredDeclarations.getEmpty())
return (ceylon.language.Sequential) empty_.get_();
org.eclipse.ceylon.model.typechecker.model.Type reifiedGet = Metamodel.getProducedType($reifiedGet);
org.eclipse.ceylon.model.typechecker.model.Type reifiedSet = Metamodel.getProducedType($reifiedSet);
Iterator<?> iterator = declaredDeclarations.iterator();
Object it;
TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
TypeDescriptor reifiedKind = TypeDescriptor.klass(ceylon.language.meta.model.Attribute.class, $reifiedType, $reifiedGet, $reifiedSet);
ArrayList<ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>> members = new ArrayList<ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>>((int) declaredDeclarations.getSize());
while ((it = iterator.next()) != finished_.get_()) {
ValueDeclarationImpl decl = (ValueDeclarationImpl) it;
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations(decl, annotationTypeDescriptors))
continue;
addAttributeIfCompatible($reifiedContainer, $reifiedGet, $reifiedSet, members, decl, this.producedType, (ceylon.language.meta.model.Type<Container>) this, reifiedGet, reifiedSet);
}
Attribute[] array = members.toArray(new ceylon.language.meta.model.Attribute[0]);
ObjectArrayIterable<Attribute> iterable = new ObjectArrayIterable<ceylon.language.meta.model.Attribute>(reifiedKind, array);
return (ceylon.language.Sequential) iterable.sequence();
}
use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredAttribute.
@SuppressWarnings({ "unchecked" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Get"), @TypeParameter(value = "Set") })
@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get,Set>|ceylon.language::Null")
public <Container, Get, Set> ceylon.language.meta.model.Attribute<Container, Get, Set> getDeclaredAttribute(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, String name) {
checkInit();
// do not return the attribute if the container is not a subtype of this type
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
if (!reifiedContainer.isSubtypeOf(producedType))
throw new IncompatibleTypeException("Specified container type '" + reifiedContainer.asString() + "' is not a valid subtype of this type");
final ValueDeclarationImpl value = declaration.findDeclaredValue(name);
if (value == null)
return null;
return value.memberApply($reifiedContainer, $reifiedGet, $reifiedSet, (ceylon.language.meta.model.Type<Container>) this);
}
Aggregations