use of org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass 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);
}
}
use of org.eclipse.ceylon.compiler.java.loader.mirror.JavacClass 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;
}
Aggregations