use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getAttributes.
@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>> getAttributes(@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();
Sequential<? extends ValueDeclaration> declaredDeclarations = declaration.<ValueDeclaration>memberDeclarations(ValueDeclaration.$TypeDescriptor$);
if (declaredDeclarations.getEmpty())
return (ceylon.language.Sequential) empty_.get_();
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
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, $reifiedContainer, $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;
MemberLookup<ValueDeclarationImpl, Container> lookup = lookupMember(ValueDeclarationImpl.$TypeDescriptor$, $reifiedContainer, reifiedContainer, decl);
if (lookup == null)
continue;
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations(lookup.declaration, annotationTypeDescriptors))
continue;
addAttributeIfCompatible($reifiedContainer, $reifiedGet, $reifiedSet, members, lookup.declaration, lookup.qualifyingType, lookup.containerMetamodel, reifiedGet, reifiedSet);
}
Attribute[] array = members.toArray(new ceylon.language.meta.model.Attribute[members.size()]);
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.runtime.metamodel.decl.ValueDeclarationImpl 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.runtime.metamodel.decl.ValueDeclarationImpl 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);
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getAttribute.
@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> getAttribute(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, String name) {
// checkInit();
ValueDeclarationImpl value = declaration.findValue(name);
if (value == null)
return null;
MemberLookup<ValueDeclarationImpl, Container> lookup = lookupMember(ValueDeclarationImpl.$TypeDescriptor$, $reifiedContainer, value);
if (lookup == null)
return null;
return lookup.declaration.<Container, Get, Set>memberApply($reifiedContainer, $reifiedGet, $reifiedSet, lookup.containerMetamodel);
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.
the class Metamodel method getOrCreateMetamodel.
public static <R> R getOrCreateMetamodel(org.eclipse.ceylon.model.typechecker.model.Declaration declaration) {
synchronized (getLock()) {
Object ret = typeCheckModelToRuntimeModel.get(declaration);
if (ret == null) {
// make sure its module is loaded
org.eclipse.ceylon.model.typechecker.model.Package pkg = getPackage(declaration);
org.eclipse.ceylon.model.typechecker.model.Module mod = pkg.getModule();
getOrCreateMetamodel(mod);
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
org.eclipse.ceylon.model.typechecker.model.Class klass = (org.eclipse.ceylon.model.typechecker.model.Class) declaration;
ret = klass.hasConstructors() || klass.hasEnumerated() || klass.isAnonymous() ? new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithConstructorsDeclarationImpl(klass) : new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationImpl(klass);
} else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
org.eclipse.ceylon.model.typechecker.model.Interface interf = (org.eclipse.ceylon.model.typechecker.model.Interface) declaration;
ret = new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl(interf);
} else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.TypeAlias) {
org.eclipse.ceylon.model.typechecker.model.TypeAlias alias = (org.eclipse.ceylon.model.typechecker.model.TypeAlias) declaration;
ret = new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.AliasDeclarationImpl(alias);
} else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Function) {
org.eclipse.ceylon.model.typechecker.model.Function method = (org.eclipse.ceylon.model.typechecker.model.Function) declaration;
if (method.getTypeDeclaration() instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
ret = new CallableConstructorDeclarationImpl(method, (org.eclipse.ceylon.model.typechecker.model.Constructor) method.getTypeDeclaration());
} else {
ret = new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl(method);
}
} else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Value) {
org.eclipse.ceylon.model.typechecker.model.Value value = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
if (value.getTypeDeclaration() instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
ret = new ValueConstructorDeclarationImpl(value, (org.eclipse.ceylon.model.typechecker.model.Constructor) value.getTypeDeclaration());
} else {
ret = new ValueDeclarationImpl(value);
}
} else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Setter) {
org.eclipse.ceylon.model.typechecker.model.Setter value = (org.eclipse.ceylon.model.typechecker.model.Setter) declaration;
ret = new SetterDeclarationImpl(value);
} else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
org.eclipse.ceylon.model.typechecker.model.Constructor value = (org.eclipse.ceylon.model.typechecker.model.Constructor) declaration;
Declaration functionOrValue = value.getContainer().getDirectMember(value.getName(), null, false);
if (functionOrValue instanceof org.eclipse.ceylon.model.typechecker.model.Function) {
ret = new CallableConstructorDeclarationImpl((org.eclipse.ceylon.model.typechecker.model.Function) functionOrValue, value);
} else if (functionOrValue instanceof org.eclipse.ceylon.model.typechecker.model.Value) {
ret = new ValueConstructorDeclarationImpl((org.eclipse.ceylon.model.typechecker.model.Value) functionOrValue, value);
} else if (functionOrValue == null) {
ret = new CallableConstructorDeclarationImpl(value, value);
} else {
throw Metamodel.newModelError("Declaration type not supported yet: " + declaration);
}
} else {
throw Metamodel.newModelError("Declaration type not supported yet: " + declaration);
}
typeCheckModelToRuntimeModel.put(declaration, ret);
}
return (R) ret;
}
}
Aggregations