Search in sources :

Example 1 with ClassSymbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol in project ceylon by eclipse.

the class CeylonModelLoader method loadPackage.

@Override
public boolean loadPackage(Module module, String packageName, boolean loadDeclarations) {
    synchronized (getLock()) {
        // abort if we already loaded it, but only record that we loaded it if we want
        // to load the declarations, because merely calling complete() on the package
        // is OK
        packageName = Util.quoteJavaKeywords(packageName);
        String cacheKey = cacheKeyByModule(module, packageName);
        if (loadDeclarations) {
            if (!loadedPackages.add(cacheKey)) {
                return true;
            }
        } else {
            Boolean exists = packageExistence.get(cacheKey);
            if (exists != null)
                return exists.booleanValue();
        }
        PackageSymbol ceylonPkg = packageName.equals("") ? syms().unnamedPackage : reader.enterPackage(names.fromString(packageName));
        if (loadDeclarations) {
            logVerbose("load package " + packageName + " full");
            ceylonPkg.complete();
            /*
                 * Eventually this will go away as we get a hook from the typechecker to load on demand, but
                 * for now the typechecker requires at least ceylon.language to be loaded 
                 */
            for (Symbol m : ceylonPkg.members().getElements()) {
                // skip things that are not classes (perhaps package-info?)
                if (!(m instanceof ClassSymbol))
                    continue;
                ClassSymbol enclosingClass = getEnclosing((ClassSymbol) m);
                if (enclosingClass == m && !Util.isLoadedFromSource(enclosingClass)) {
                    m.complete();
                    // avoid anonymous and local classes
                    if (isAnonymousOrLocal((ClassSymbol) m))
                        continue;
                    // avoid member classes
                    if (((ClassSymbol) m).getNestingKind() != NestingKind.TOP_LEVEL)
                        continue;
                    // skip module and package descriptors
                    if (isModuleOrPackageDescriptorName(m.name.toString()))
                        continue;
                    ClassMirror classMirror = lookupClassMirror(module, m.getQualifiedName().toString());
                    // So ATM we just avoid it, presumably we don't support what it does anyways
                    if (classMirror != null)
                        convertToDeclaration(module, classMirror, DeclarationType.VALUE);
                }
            }
            if (module.getNameAsString().equals(JAVA_BASE_MODULE_NAME) && packageName.equals("java.lang"))
                loadJavaBaseExtras();
            // might be too late
            return ceylonPkg.members().getElements().iterator().hasNext();
        } else {
            logVerbose("load package " + packageName + " light");
            try {
                // it is cheaper to verify that we have a class file somewhere than to complete the whole package
                // just to check for its existence
                Iterable<JavaFileObject> list = fileManager.list(PLATFORM_CLASS_PATH, packageName, EnumSet.of(JavaFileObject.Kind.CLASS), false);
                if (list.iterator().hasNext()) {
                    packageExistence.put(cacheKey, Boolean.TRUE);
                    return true;
                }
                list = fileManager.list(CLASS_PATH, packageName, EnumSet.of(JavaFileObject.Kind.CLASS), false);
                if (list.iterator().hasNext()) {
                    packageExistence.put(cacheKey, Boolean.TRUE);
                    return true;
                } else {
                    packageExistence.put(cacheKey, Boolean.FALSE);
                    return false;
                }
            } catch (IOException e) {
                return false;
            }
        }
    }
}
Also used : PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) 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) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) IOException(java.io.IOException) ClassMirror(org.eclipse.ceylon.model.loader.mirror.ClassMirror)

Example 2 with ClassSymbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol in project ceylon by eclipse.

the class CeylonModelLoader method getEnclosing.

private ClassSymbol getEnclosing(ClassSymbol c) {
    Symbol owner = c.owner;
    org.eclipse.ceylon.langtools.tools.javac.util.List<Name> enclosing = Convert.enclosingCandidates(Convert.shortName(c.name));
    if (enclosing.isEmpty())
        return c;
    Name name = enclosing.head;
    Symbol encl = owner.members().lookup(name).sym;
    if (encl == null || !(encl instanceof ClassSymbol))
        encl = symtab.classes.get(TypeSymbol.formFlatName(name, owner));
    if (encl != null)
        return (ClassSymbol) encl;
    return c;
}
Also used : 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) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) Name(org.eclipse.ceylon.langtools.tools.javac.util.Name)

Example 3 with ClassSymbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol in project ceylon by eclipse.

the class JavacClass method getEnclosingClass.

@Override
public ClassMirror getEnclosingClass() {
    if (!enclosingClassSet) {
        Symbol encl = classSymbol.getEnclosingElement();
        if (encl != null && encl instanceof ClassSymbol) {
            enclosingClass = new JavacClass((ClassSymbol) encl);
        }
        enclosingClassSet = true;
    }
    return enclosingClass;
}
Also used : VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)

Example 4 with ClassSymbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol in project ceylon by eclipse.

the class JavacClass method getEnclosingMethod.

@Override
public MethodMirror getEnclosingMethod() {
    if (!enclosingMethodSet) {
        Symbol encl = classSymbol.getEnclosingElement();
        if (encl != null && encl instanceof MethodSymbol) {
            // it's a method, it must be in a Class
            ClassSymbol enclosingClass = (ClassSymbol) encl.getEnclosingElement();
            JavacClass enclosingClassMirror = new JavacClass(enclosingClass);
            enclosingMethod = new JavacMethod(enclosingClassMirror, (MethodSymbol) encl);
        }
        enclosingMethodSet = true;
    }
    return enclosingMethod;
}
Also used : MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)

Example 5 with ClassSymbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol in project ceylon by eclipse.

the class CeylonEnter method resetClassSymbol.

/**
 * This resets a ClassSymbol recursively, for bootstrap
 */
private void resetClassSymbol(ClassSymbol classSymbol) {
    // look for inner classes
    if (classSymbol.members_field != null) {
        for (Symbol member : classSymbol.getEnclosedElements()) {
            if (member instanceof ClassSymbol) {
                resetClassSymbol((ClassSymbol) member);
            }
        }
    }
    // reset its type, we need to keep it
    org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType classType = (ClassType) classSymbol.type;
    classType.all_interfaces_field = null;
    classType.interfaces_field = null;
    classType.supertype_field = null;
    classType.typarams_field = null;
    // make sure we give erroneous types a second chance
    if (classType.getTag() == TypeTag.ERROR) {
        // This is how ClassSymbol's constructor builds them, so make'em brand new
        classSymbol.type = new ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.noType, null, null);
        classSymbol.type.tsym = classSymbol;
    }
    // reset its members and completer
    classSymbol.members_field = null;
    classSymbol.completer = null;
    // make sure we revert the class symbol kind to a new state by removing ERR kinds
    classSymbol.kind = Kinds.TYP;
    classSymbol.flags_field = 0;
}
Also used : ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType) Type(org.eclipse.ceylon.model.typechecker.model.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType) ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType)

Aggregations

ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)9 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)5 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)5 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)3 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)3 ClassType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType)3 DeclaredType (org.eclipse.ceylon.javax.lang.model.type.DeclaredType)2 Scope (org.eclipse.ceylon.langtools.source.tree.Scope)2 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)2 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)2 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)2 ErrorType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ErrorType)2 UnionClassType (org.eclipse.ceylon.langtools.tools.javac.code.Type.UnionClassType)2 IOException (java.io.IOException)1 JavacClass (org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass)1 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)1 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)1 JCCompilationUnit (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit)1 Name (org.eclipse.ceylon.langtools.tools.javac.util.Name)1 ClassMirror (org.eclipse.ceylon.model.loader.mirror.ClassMirror)1