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();
}
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;
}
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;
}
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;
}
Aggregations