use of ceylon.language.meta.model.ClassOrInterface in project ceylon by eclipse.
the class Metamodel method getMetamodel.
public static ceylon.language.meta.declaration.FunctionDeclaration getMetamodel(Function method) {
// find its container
Scope container = method.getContainer();
if (container instanceof org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) {
org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl classOrInterface = (ClassOrInterfaceDeclarationImpl) getOrCreateMetamodel((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) container);
// now find the method
ceylon.language.meta.declaration.FunctionDeclaration ret = classOrInterface.findMethod(method.getName());
if (ret == null)
throw Metamodel.newModelError("Failed to find method " + method.getName() + " in " + container);
return ret;
}
if (container instanceof org.eclipse.ceylon.model.typechecker.model.Package) {
ceylon.language.meta.declaration.Package pkg = getOrCreateMetamodel((org.eclipse.ceylon.model.typechecker.model.Package) container);
ceylon.language.meta.declaration.FunctionDeclaration ret = pkg.getFunction(method.getName());
if (ret == null)
throw Metamodel.newModelError("Failed to find method " + method.getName() + " in " + container);
return ret;
}
throw Metamodel.newModelError("Unsupported method container for " + method.getName() + ": " + container);
}
use of ceylon.language.meta.model.ClassOrInterface in project ceylon by eclipse.
the class ClassOrInterfaceDeclarationImpl method memberApply.
@SuppressWarnings("rawtypes")
@TypeInfo("ceylon.language.meta.model::Member<Container,ceylon.language.meta.model::ClassOrInterface<Type>>&ceylon.language.meta.model::ClassOrInterface<Type>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Type") })
@Override
public <Container, Type extends Object> java.lang.Object memberApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @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.Member<? extends Container, ceylon.language.meta.model.ClassOrInterface<?>> member = 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;
if (member instanceof MemberClassImpl)
actualReifiedContainer = ((MemberClassImpl) member).$reifiedContainer;
else
actualReifiedContainer = ((MemberInterfaceImpl) member).$reifiedContainer;
org.eclipse.ceylon.model.typechecker.model.Type actualType = Metamodel.getModel((ceylon.language.meta.model.Type<?>) member);
Metamodel.checkReifiedTypeArgument("memberApply", "Member<$1,ClassOrInterface<$2>>&ClassOrInterface<$2>", Variance.IN, Metamodel.getProducedType(actualReifiedContainer), $reifiedContainer, Variance.OUT, actualType, $reifiedType);
return member;
}
use of ceylon.language.meta.model.ClassOrInterface 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);
}
use of ceylon.language.meta.model.ClassOrInterface 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());
}
Aggregations