Search in sources :

Example 6 with ClassSymbol

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

the class CeylonEnter method resetAndRunEnterAgain.

private void resetAndRunEnterAgain(List<JCCompilationUnit> trees) {
    timer.startTask("Resetting all trees for bootstrap");
    // get rid of some caches and state
    chk.compiled.clear();
    types.reset();
    annotate.reset();
    super.reset();
    // reset all class symbols
    for (ClassSymbol classSymbol : symtab.classes.values()) {
        if (Util.isLoadedFromSource(classSymbol) || (classSymbol.sourcefile != null && classSymbol.sourcefile.getKind() == Kind.SOURCE)) {
            resetClassSymbol(classSymbol);
        }
    }
    // reset the trees
    JCTypeResetter jcTypeResetter = new JCTypeResetter();
    for (JCCompilationUnit tree : trees) {
        tree.accept(jcTypeResetter);
    }
    // and reset the list of things to compile, because we got rid of the Env key we used to look them up
    // so they'd appear as extra things to compile when we do Enter
    todo.reset();
    timer.endTask();
    timer.startTask("Enter on Java+Ceylon trees");
    // now do Enter on all the java+ceylon code
    try {
        sourceLanguage.push(Language.CEYLON);
        super.main(trees);
    } finally {
        sourceLanguage.pop();
    }
    timer.endTask();
}
Also used : JCCompilationUnit(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCCompilationUnit) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)

Example 7 with ClassSymbol

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

the class CeylonModelLoader method lookupNewClassMirror.

private ClassMirror lookupNewClassMirror(String name) {
    ClassSymbol classSymbol = null;
    String outerName = name;
    /*
         * This madness here tries to look for a class, and if it fails, tries to resolve it 
         * from its parent class. This is required because a.b.C.D (where D is an inner class
         * of C) is not found in symtab.classes but in C's ClassSymbol.enclosedElements.
         */
    // make sure we load the class file, since we no longer complete packages unless we absolutely must
    loadClass(outerName);
    do {
        // we must first try with no postfix, because we can have a valid class foo.bar in Java,
        // when in Ceylon it would be foo.bar_
        classSymbol = symtab.classes.get(names.fromString(Util.quoteJavaKeywords(outerName)));
        // try again with a postfix "_"
        if (classSymbol == null && lastPartHasLowerInitial(outerName) && !outerName.endsWith("_")) {
            classSymbol = symtab.classes.get(names.fromString(Util.quoteJavaKeywords(outerName + "_")));
        }
        if (classSymbol != null) {
            // if we got a source symbol for something non-Java it's a slipery slope
            if (Util.isLoadedFromSource(classSymbol) && !Util.isJavaSource(classSymbol))
                return null;
            if (outerName.length() != name.length()) {
                try {
                    classSymbol = lookupInnerClass(classSymbol, name.substring(outerName.length() + 1).split("\\."));
                } catch (CompletionFailure x) {
                    // something wrong, we will report it properly elsewhere
                    classSymbol = null;
                }
            }
            if (classSymbol != null && classSymbol.classfile == null && classSymbol.sourcefile == null) {
                // try to complete it if that changes anything
                try {
                    classSymbol.complete();
                } catch (CompletionFailure x) {
                // if we can't complete it it doesn't exist, its classfile will remain null
                }
                if (classSymbol.classfile == null) {
                    PackageSymbol pkg = classSymbol.packge();
                    // do not log an error for missing oracle jdk stuff
                    if (pkg == null || !jdkProvider.isImplementationSpecificJDKPackage(pkg.getQualifiedName().toString())) {
                        // do not log an error because it will be logged elsewhere
                        logVerbose("Unable to find required class file for " + name);
                    }
                    return null;
                }
            }
            return classSymbol != null ? new JavacClass(classSymbol) : null;
        }
        int lastDot = outerName.lastIndexOf(".");
        if (lastDot == -1 || lastDot == 0)
            return null;
        outerName = outerName.substring(0, lastDot);
    } while (classSymbol == null);
    return null;
}
Also used : PackageSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol) JavacClass(org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) CompletionFailure(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)

Example 8 with ClassSymbol

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

the class JavacTrees method searchMethod.

/**
 * @see com.sun.tools.javadoc.ClassDocImpl#searchMethod
 */
private MethodSymbol searchMethod(ClassSymbol tsym, Name methodName, List<Type> paramTypes, Set<ClassSymbol> searched) {
    // do not match constructors
    if (methodName == names.init)
        return null;
    if (searched.contains(tsym))
        return null;
    searched.add(tsym);
    // search current class
    org.eclipse.ceylon.langtools.tools.javac.code.Scope.Entry e = tsym.members().lookup(methodName);
    if (paramTypes == null) {
        // If no parameters specified, we are allowed to return
        // any method with a matching name.  In practice, the old
        // code returned the first method, which is now the last!
        // In order to provide textually identical results, we
        // attempt to emulate the old behavior.
        MethodSymbol lastFound = null;
        for (; e.scope != null; e = e.next()) {
            if (e.sym.kind == Kinds.MTH) {
                if (e.sym.name == methodName) {
                    lastFound = (MethodSymbol) e.sym;
                }
            }
        }
        if (lastFound != null) {
            return lastFound;
        }
    } else {
        for (; e.scope != null; e = e.next()) {
            if (e.sym != null && e.sym.kind == Kinds.MTH) {
                if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) {
                    return (MethodSymbol) e.sym;
                }
            }
        }
    }
    // ### If we found a MethodSymbol above, but which did not pass
    // ### the modifier filter, we should return failure here!
    // search superclass
    Type superclass = tsym.getSuperclass();
    if (superclass.tsym != null) {
        MethodSymbol msym = searchMethod((ClassSymbol) superclass.tsym, methodName, paramTypes, searched);
        if (msym != null) {
            return msym;
        }
    }
    // search interfaces
    List<Type> intfs = tsym.getInterfaces();
    for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
        Type intf = l.head;
        if (intf.isErroneous())
            continue;
        MethodSymbol msym = searchMethod((ClassSymbol) intf.tsym, methodName, paramTypes, searched);
        if (msym != null) {
            return msym;
        }
    }
    // search enclosing class
    ClassSymbol encl = tsym.owner.enclClass();
    if (encl != null) {
        MethodSymbol msym = searchMethod(encl, methodName, paramTypes, searched);
        if (msym != null) {
            return msym;
        }
    }
    return null;
}
Also used : UnionClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.UnionClassType) DeclaredType(org.eclipse.ceylon.javax.lang.model.type.DeclaredType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) ErrorType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ErrorType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType) Scope(org.eclipse.ceylon.langtools.source.tree.Scope) MethodSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)

Example 9 with ClassSymbol

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

the class JavacTrees method searchField.

/**
 * @see com.sun.tools.javadoc.ClassDocImpl#searchField
 */
private VarSymbol searchField(ClassSymbol tsym, Name fieldName, Set<ClassSymbol> searched) {
    if (searched.contains(tsym)) {
        return null;
    }
    searched.add(tsym);
    for (org.eclipse.ceylon.langtools.tools.javac.code.Scope.Entry e = tsym.members().lookup(fieldName); e.scope != null; e = e.next()) {
        if (e.sym.kind == Kinds.VAR) {
            return (VarSymbol) e.sym;
        }
    }
    // ### If we found a VarSymbol above, but which did not pass
    // ### the modifier filter, we should return failure here!
    ClassSymbol encl = tsym.owner.enclClass();
    if (encl != null) {
        VarSymbol vsym = searchField(encl, fieldName, searched);
        if (vsym != null) {
            return vsym;
        }
    }
    // search superclass
    Type superclass = tsym.getSuperclass();
    if (superclass.tsym != null) {
        VarSymbol vsym = searchField((ClassSymbol) superclass.tsym, fieldName, searched);
        if (vsym != null) {
            return vsym;
        }
    }
    // search interfaces
    List<Type> intfs = tsym.getInterfaces();
    for (List<Type> l = intfs; l.nonEmpty(); l = l.tail) {
        Type intf = l.head;
        if (intf.isErroneous())
            continue;
        VarSymbol vsym = searchField((ClassSymbol) intf.tsym, fieldName, searched);
        if (vsym != null) {
            return vsym;
        }
    }
    return null;
}
Also used : UnionClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.UnionClassType) DeclaredType(org.eclipse.ceylon.javax.lang.model.type.DeclaredType) Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) ErrorType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ErrorType) ArrayType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType) ClassType(org.eclipse.ceylon.langtools.tools.javac.code.Type.ClassType) Scope(org.eclipse.ceylon.langtools.source.tree.Scope) ClassSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol) VarSymbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)

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