Search in sources :

Example 36 with ListBuffer

use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer 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 37 with ListBuffer

use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer in project ceylon by eclipse.

the class CeyloncFileManager method list.

public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    Iterable<JavaFileObject> result = super.list(location, packageName, kinds, recurse);
    ListBuffer<JavaFileObject> buf = new ListBuffer<JavaFileObject>();
    for (JavaFileObject f : result) {
        if (f.getName().endsWith(".ceylon")) {
            buf.add(new CeylonFileObject(f));
        } else {
            buf.add(f);
        }
    }
    return buf.toList();
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)

Example 38 with ListBuffer

use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer in project ceylon by eclipse.

the class JavacFileManager method getClassLoader.

public ClassLoader getClassLoader(Location location) {
    nullCheck(location);
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return null;
    ListBuffer<URL> lb = new ListBuffer<URL>();
    for (File f : path) {
        try {
            lb.append(f.toURI().toURL());
        } catch (MalformedURLException e) {
            throw new AssertionError(e);
        }
    }
    return getClassLoader(lb.toArray(new URL[lb.size()]));
}
Also used : MalformedURLException(java.net.MalformedURLException) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) RelativeFile(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) URL(java.net.URL)

Example 39 with ListBuffer

use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer in project ceylon by eclipse.

the class JavacFileManager method list.

public Iterable<JavaFileObject> list(Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse) throws IOException {
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);
    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return List.nil();
    RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
    for (File directory : path) listContainer(directory, subdirectory, kinds, recurse, results);
    return results.toList();
}
Also used : RelativeDirectory(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeDirectory) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) RelativeFile(org.eclipse.ceylon.langtools.tools.javac.file.RelativePath.RelativeFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 40 with ListBuffer

use of org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer in project ceylon by eclipse.

the class JavacPathFileManager method list.

@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);
    Iterable<? extends Path> paths = getLocation(location);
    if (paths == null)
        return List.nil();
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();
    for (Path path : paths) list(path, packageName, kinds, recurse, results);
    return results.toList();
}
Also used : Path(java.nio.file.Path) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)

Aggregations

ListBuffer (org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer)67 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)53 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)30 Type (org.eclipse.ceylon.model.typechecker.model.Type)23 JCStatement (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCStatement)22 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)20 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)16 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)16 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)15 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)14 JCAnnotation (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)13 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)12 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)12 SyntheticName (org.eclipse.ceylon.compiler.java.codegen.Naming.SyntheticName)11 Function (org.eclipse.ceylon.model.typechecker.model.Function)10 Class (org.eclipse.ceylon.model.typechecker.model.Class)9 JCTypeParameter (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter)8 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)8 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)8 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)7