Search in sources :

Example 1 with ModelResolutionException

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);
    }
}
Also used : JavacType(org.eclipse.ceylon.compiler.java.loader.mirror.JavacType) MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) JavacMethod(org.eclipse.ceylon.compiler.java.loader.mirror.JavacMethod) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) TypeSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) MethodType(org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) JavacType(org.eclipse.ceylon.compiler.java.loader.mirror.JavacType) FunctionalInterfaceType(org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) TypeMirror(org.eclipse.ceylon.model.loader.mirror.TypeMirror) JavacClass(org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass) FunctionDescriptorLookupError(org.eclipse.ceylon.langtools.tools.javac.code.Types.FunctionDescriptorLookupError)

Example 2 with ModelResolutionException

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);
    }
}
Also used : ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) CeylonModuleClassLoader(org.eclipse.ceylon.model.runtime.CeylonModuleClassLoader) CeylonModuleClassLoader(org.eclipse.ceylon.model.runtime.CeylonModuleClassLoader) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 3 with ModelResolutionException

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;
}
Also used : ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) Module(org.eclipse.ceylon.model.typechecker.model.Module)

Example 4 with ModelResolutionException

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);
    }
}
Also used : ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) TypeParameterMirror(org.eclipse.ceylon.model.loader.mirror.TypeParameterMirror) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure) ArrayList(java.util.ArrayList) TypeVariableSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeVariableSymbol)

Example 5 with ModelResolutionException

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;
}
Also used : MethodMirror(org.eclipse.ceylon.model.loader.mirror.MethodMirror) ModelResolutionException(org.eclipse.ceylon.model.loader.ModelResolutionException) Constructor(java.lang.reflect.Constructor) Method(java.lang.reflect.Method)

Aggregations

ModelResolutionException (org.eclipse.ceylon.model.loader.ModelResolutionException)5 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)2 LazyModule (org.eclipse.ceylon.model.loader.model.LazyModule)2 Module (org.eclipse.ceylon.model.typechecker.model.Module)2 Constructor (java.lang.reflect.Constructor)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 JavacClass (org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass)1 JavacMethod (org.eclipse.ceylon.compiler.java.loader.mirror.JavacMethod)1 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)1 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)1 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)1 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)1 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)1 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)1 TypeVariableSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeVariableSymbol)1 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)1 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)1 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)1 FunctionDescriptorLookupError (org.eclipse.ceylon.langtools.tools.javac.code.Types.FunctionDescriptorLookupError)1