use of ceylon.language.meta.declaration.ClassOrInterfaceDeclaration in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getCaseValues.
@Override
@TypeInfo("ceylon.language::Sequential<Type>")
public ceylon.language.Sequential<? extends Type> getCaseValues() {
if (!((ClassOrInterface) declaration.declaration).isAbstract()) {
// optimization: a concrete class cannot have cases
return (Sequential) empty_.get_();
}
Sequential<? extends ceylon.language.meta.declaration.OpenType> caseTypeDeclarations = getDeclaration().getCaseTypes();
Iterator<? extends ceylon.language.meta.declaration.OpenType> iterator = caseTypeDeclarations.iterator();
Object it;
Array<Type> ret = new Array<Type>($reifiedType, (int) caseTypeDeclarations.getSize(), (Type) null);
int count = 0;
while ((it = iterator.next()) != finished_.get_()) {
if (it instanceof ceylon.language.meta.declaration.OpenClassType == false)
continue;
ceylon.language.meta.declaration.OpenClassType caseClassType = (ceylon.language.meta.declaration.OpenClassType) it;
ceylon.language.meta.declaration.ClassDeclaration caseClass = caseClassType.getDeclaration();
if (!caseClass.getAnonymous())
continue;
Type value = null;
Object container = caseClass.getContainer();
while (true) {
if (container instanceof ceylon.language.meta.declaration.Package) {
ValueDeclaration valueDeclaration = ((ceylon.language.meta.declaration.Package) container).getValue(caseClass.getName());
ceylon.language.meta.model.Value<? extends Type, ? super Object> valueModel = valueDeclaration.<Type, Object>apply($reifiedType, TypeDescriptor.NothingType);
value = valueModel.get();
break;
} else {
if (container instanceof ClassOrInterfaceDeclaration) {
ValueDeclaration valueDeclaration = ((ClassOrInterfaceDeclaration) container).getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, caseClass.getName());
Attribute a = valueDeclaration.memberApply($reifiedType, $reifiedType, Nothing.NothingType, this);
value = (Type) a.bind(null).get();
}
// other nestable decls can't contain members, so keep looking up scopes
container = ((NestableDeclaration) container).getContainer();
}
if (value != null) {
break;
}
}
if (value == null && !producedType.isNull()) {
throw new AssertionError("case " + caseClassType + " of " + this + " not found");
}
ret.set(count++, value);
}
return ret.take(count).sequence();
}
use of ceylon.language.meta.declaration.ClassOrInterfaceDeclaration in project ceylon by eclipse.
the class Util method javaClassForModel.
// Used by the code generator
// Copied from ceylon.interop.java
@SuppressWarnings("unchecked")
public static <T> java.lang.Class<? extends T> javaClassForModel(ClassOrInterface<? extends T> model) {
ClassOrInterfaceDeclaration decl = model.getDeclaration();
if (decl instanceof ClassOrInterfaceDeclarationImpl) {
ClassOrInterfaceDeclarationImpl ci = (ClassOrInterfaceDeclarationImpl) decl;
String prefix = null;
while (ci.getJavaClass().equals(ObjectArray.class)) {
model = ((ClassOrInterface) model.getTypeArgumentList().getFromFirst(0));
decl = model.getDeclaration();
ci = (ClassOrInterfaceDeclarationImpl) decl;
prefix = prefix == null ? "[" : prefix + "[";
}
java.lang.Class result = (java.lang.Class<? extends T>) classErasure(ci.getJavaClass());
if (prefix != null) {
String name = result.isArray() && result.getComponentType().isPrimitive() ? prefix + result.getName() : prefix + "L" + result.getName() + ";";
try {
result = java.lang.Class.forName(name, false, result.getClassLoader());
} catch (ClassNotFoundException e1) {
rethrow(e1);
}
}
return result;
}
throw new ceylon.language.AssertionError("Unsupported declaration type: " + decl);
}
Aggregations