use of org.eclipse.ceylon.langtools.tools.javac.code.Types.FunctionDescriptorLookupError 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.langtools.tools.javac.code.Types.FunctionDescriptorLookupError in project ceylon by eclipse.
the class CeylonModelLoader method isFunctionalInterface.
@Override
protected String isFunctionalInterface(ClassMirror klass) {
Type type = ((JavacClass) klass).classSymbol.type;
try {
Type descriptorType = types.findDescriptorType(type);
if (descriptorType == null)
return null;
// 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))
return null;
MethodSymbol descriptorSymbol = (MethodSymbol) types.findDescriptorSymbol(type.tsym);
if (descriptorSymbol != null) {
// make sure we don't treat ignored shit like impl accessors as SAM
if (isIgnored(descriptorSymbol))
return null;
String name = descriptorSymbol.getSimpleName().toString();
if (isGetter(descriptorSymbol)) {
name = NamingBase.getJavaAttributeName(name);
}
return name;
}
return null;
} catch (Symbol.CompletionFailure err) {
// bad luck
return null;
} catch (FunctionDescriptorLookupError err) {
return null;
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Types.FunctionDescriptorLookupError in project ceylon by eclipse.
the class CeylonModelLoader method isFunctionalInterfaceType.
@Override
protected boolean isFunctionalInterfaceType(TypeMirror typeMirror) {
if (typeMirror.getKind() != TypeKind.DECLARED)
return false;
// 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))
return false;
MethodType methodDescriptorType = (MethodType) descriptorType;
MethodSymbol methodSymbol = (MethodSymbol) types.findDescriptorSymbol(type.tsym);
// make sure we can load them
methodDescriptorType.complete();
methodSymbol.complete();
return true;
} catch (Symbol.CompletionFailure err) {
// bad luck
return false;
} catch (FunctionDescriptorLookupError err) {
return false;
}
}
Aggregations