use of org.eclipse.ceylon.model.loader.ModelResolutionException in project ceylon by eclipse.
the class CeylonModelLoader method getFunctionalInterfaceType.
@Override
protected FunctionalInterfaceType getFunctionalInterfaceType(TypeMirror typeMirror) throws ModelResolutionException {
if (typeMirror.getKind() != TypeKind.DECLARED)
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror);
// FIXME: possibly apply other optimisations to lighten the lookup cost? see what javac does
Type type = ((JavacType) typeMirror).type;
try {
Type descriptorType = types.findDescriptorType(type);
// Let's be honest I've no idea what this means, but it happens and Javac seems to refuse it too
if (descriptorType.hasTag(TypeTag.FORALL))
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror);
MethodType methodDescriptorType = (MethodType) descriptorType;
MethodSymbol methodSymbol = (MethodSymbol) types.findDescriptorSymbol(type.tsym);
List<Type> parameterTypes = methodDescriptorType.getParameterTypes();
ListBuffer<TypeMirror> mirrorParameterTypes = new ListBuffer<>();
for (int i = 0; i < parameterTypes.size(); i++) {
Type parameterType = parameterTypes.get(i);
if (methodSymbol.isVarArgs() && i == parameterTypes.size() - 1)
parameterType = ((ArrayType) parameterType).getComponentType();
mirrorParameterTypes.add(new JavacType(parameterType));
}
return new FunctionalInterfaceType(new JavacMethod(new JavacClass(methodSymbol.enclClass()), methodSymbol), new JavacType(methodDescriptorType.getReturnType()), mirrorParameterTypes.toList(), methodSymbol.isVarArgs());
} catch (Symbol.CompletionFailure err) {
// bad luck
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror, err);
} catch (FunctionDescriptorLookupError err) {
throw new ModelResolutionException("Failed to find functional interface type in " + typeMirror, err);
}
}
use of org.eclipse.ceylon.model.loader.ModelResolutionException in project ceylon by eclipse.
the class RuntimeModelLoader method findModuleForClass.
public Module findModuleForClass(Class<?> klass) {
ClassLoader cl = klass.getClassLoader();
if (cl instanceof CeylonModuleClassLoader) {
CeylonModuleClassLoader classLoader = (CeylonModuleClassLoader) cl;
String name = classLoader.getModuleName();
String version = classLoader.getModuleVersion();
String cacheKey = cacheKeyByModule(name, version);
Module ret = moduleCache.get(cacheKey);
if (ret == null) {
// there's a good chance we didn't get the module loaded in time, wait until that classloader is
// registered then, but give it a nudge:
// this can complete in another thread or this thread
classLoader.registerInMetaModel();
Object lock = getLock();
synchronized (lock) {
int tries = MAX_JBOSS_MODULES_WAITS;
while (!classLoaders.containsValue(cl)) {
try {
lock.wait(JBOSS_MODULES_TIMEOUT);
} catch (InterruptedException e) {
throw new ModelResolutionException(e);
}
if (tries-- < 0)
throw new ModelResolutionException("Failed to find registered classloader for " + klass);
}
ret = moduleCache.get(cacheKey);
}
}
return ret;
} else {
// revert to a single classloader version?
// FIXME: perhaps we can have other one-classloader-to-one-module setups than jboss modules?
String pkgName = ReflectionUtils.getPackageName(klass);
// even on jboss modules, the jdk has no class loader, so jdk classes will have to be resolved
// to the jdk modules by package
String jdkModuleName = JDKUtils.getJDKModuleNameForPackage(pkgName);
if (jdkModuleName != null)
return findModule(jdkModuleName, JDKUtils.jdk.version);
if (isDynamicMetamodel())
return lazyLoadModuleForPackage(pkgName);
return lookupModuleByPackageName(pkgName);
}
}
use of org.eclipse.ceylon.model.loader.ModelResolutionException in project ceylon by eclipse.
the class RuntimeModelLoader method findModuleForClassMirror.
@Override
public Module findModuleForClassMirror(ClassMirror classMirror) {
Class<?> klass = ((ReflectionClass) classMirror).klass;
Module ret = findModuleForClass(klass);
if (ret == null)
throw new ModelResolutionException("Could not find module for class " + klass);
return ret;
}
use of org.eclipse.ceylon.model.loader.ModelResolutionException in project ceylon by eclipse.
the class JavacUtil method getTypeParameters.
public static List<TypeParameterMirror> getTypeParameters(Symbol symbol) {
try {
org.eclipse.ceylon.langtools.tools.javac.util.List<TypeVariableSymbol> typeParameters = symbol.getTypeParameters();
List<TypeParameterMirror> ret = new ArrayList<TypeParameterMirror>(typeParameters.size());
for (TypeVariableSymbol typeParameter : typeParameters) ret.add(new JavacTypeParameter(typeParameter));
return ret;
} catch (CompletionFailure x) {
throw new ModelResolutionException("Failed to load type parameters", x);
}
}
use of org.eclipse.ceylon.model.loader.ModelResolutionException in project ceylon by eclipse.
the class ReflectionClass method getDirectMethods.
@Override
public List<MethodMirror> getDirectMethods() {
if (methods != null)
return methods;
Method[] directMethods;
Constructor<?>[] directConstructors;
try {
directMethods = klass.getDeclaredMethods();
directConstructors = klass.getDeclaredConstructors();
} catch (NoClassDefFoundError x) {
throw new ModelResolutionException("Failed to load methods in " + getQualifiedName(), x);
}
methods = new ArrayList<MethodMirror>(directMethods.length + directConstructors.length);
for (Method directMethod : directMethods) {
// depends on them
if (!directMethod.isSynthetic() && !directMethod.isBridge())
methods.add(new ReflectionMethod(this, directMethod));
}
for (Constructor<?> directConstructor : directConstructors) {
// depends on them
if (!directConstructor.isSynthetic())
methods.add(new ReflectionMethod(this, directConstructor));
}
return methods;
}
Aggregations