use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl 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 org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl 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 org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl in project ceylon by eclipse.
the class Metamodel method parseEnumerationReference.
@SuppressWarnings("unchecked")
public static <T> T parseEnumerationReference(java.lang.Class<T> klass) {
ClassOrInterfaceDeclarationImpl decl = (ClassOrInterfaceDeclarationImpl) getOrCreateMetamodel(klass);
String getterName = NamingBase.getGetterName(decl.declaration);
try {
java.lang.reflect.Method method = klass.getDeclaredMethod(getterName);
method.setAccessible(true);
return (T) method.invoke(null);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
/* aka ReflectiveOperationException */
throw Metamodel.newModelError(e.toString());
}
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl 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.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getClassOrInterface.
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Kind", satisfies = "ceylon.language.meta.model::ClassOrInterface<ceylon.language::Anything,ceylon.language::Nothing>") })
@TypeInfo("ceylon.language.meta.model::Member<Container,Kind>|ceylon.language::Null")
public <Container, Kind extends ceylon.language.meta.model.ClassOrInterface<? extends java.lang.Object>> ceylon.language.meta.model.Member<Container, Kind> getClassOrInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedKind, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
checkInit();
final ClassOrInterfaceDeclarationImpl type = declaration.findType(name);
if (type == null)
return null;
MemberLookup<ClassOrInterfaceDeclarationImpl, Container> lookup = lookupMember(ClassOrInterfaceDeclarationImpl.$TypeDescriptor$, $reifiedContainer, type);
if (lookup == null)
return null;
return applyClassOrInterface($reifiedContainer, $reifiedKind, lookup.declaration, types);
}
Aggregations