use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.
the class CeylonModelLoader method isOverloadingMethod.
/**
* Returns true if the given method is overloading an inherited method (from super class or interfaces).
*/
private boolean isOverloadingMethod(final MethodSymbol method) {
/*
* Copied from getOverriddenMethod and adapted for overloading
*/
try {
// interfaces have a different way to work
if (method.owner.isInterface())
return overloaded(method, method.owner.type.tsym, types);
// so we stop there for it, especially since it does not have any overloading
if (method.owner.type.tsym.getQualifiedName().toString().equals("ceylon.language.Exception"))
return false;
for (Type superType = types.supertype(method.owner.type); superType.tsym != null; superType = types.supertype(superType)) {
TypeSymbol i = superType.tsym;
String fqn = i.getQualifiedName().toString();
// never go above this type since it has no supertype in Ceylon (does in Java though)
if (fqn.equals("ceylon.language.Anything"))
break;
try {
for (Entry e = i.members().lookup(method.name); e.scope != null; e = e.next()) {
// ignore some methods
if (isIgnored(e.sym))
continue;
if (!method.overrides(e.sym, (TypeSymbol) method.owner, types, false)) {
return true;
}
}
// try in the interfaces
if (overloaded(method, i, types))
return true;
} catch (Symbol.CompletionFailure x) {
// just ignore unresolved interfaces, error will be logged when we try to add it
}
// so we stop there for it, especially since it does not have any overloading
if (fqn.equals("ceylon.language.Exception"))
break;
}
// try in the interfaces
if (overloaded(method, method.owner.type.tsym, types))
return true;
return false;
} catch (CompletionFailure x) {
handleCompletionFailure(method, x);
return false;
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.
the class LanguageCompiler method complete.
@Override
public void complete(ClassSymbol c) throws CompletionFailure {
try {
sourceLanguage.push(Language.JAVA);
super.complete(c);
} catch (RunTwiceException e) {
hadRunTwiceException = true;
throw new CompletionFailure(c, e.getLocalizedMessage());
} finally {
sourceLanguage.pop();
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure in project ceylon by eclipse.
the class LanguageCompiler method genCodeUnlessError.
private JavaFileObject genCodeUnlessError(Env<AttrContext> env, JCClassDecl cdef) throws IOException {
CeylonFileObject sourcefile = (CeylonFileObject) env.toplevel.sourcefile;
try {
// do not look at the global number of errors but only those for this file
if (super.gen.genClass(env, cdef)) {
String packageName = cdef.sym.packge().getQualifiedName().toString();
Package pkg = modelLoader.findPackage(packageName);
if (pkg == null)
throw new RuntimeException("Failed to find package: " + packageName);
Module module = pkg.getModule();
if (!module.isDefaultModule()) {
String moduleName = module.getNameAsString();
CeylonFileObject moduleFileObject = moduleNamesToFileObjects.get(moduleName);
// if there's no module source file object it means the module descriptor had parse errors
if (moduleFileObject == null || moduleFileObject.hasError()) {
// we do not produce any class files for modules with errors
if (options.get(Option.VERBOSE) != null) {
log.printRawLines(WriterKind.NOTICE, "[Not writing class " + cdef.sym.className() + " because its module has errors: " + moduleName + "]");
}
return null;
}
}
return writer.writeClass(cdef.sym);
}
} catch (ClassWriter.PoolOverflow ex) {
log.error(cdef.pos(), "limit.pool");
} catch (ClassWriter.StringOverflow ex) {
log.error(cdef.pos(), "limit.string.overflow", ex.value.substring(0, 20));
} catch (CompletionFailure ex) {
chk.completionError(cdef.pos(), ex);
} catch (AssertionError e) {
throw new RuntimeException("Error generating bytecode for " + sourcefile.getName(), e);
}
return null;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure 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.CompletionFailure 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);
}
}
Aggregations