use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class CeylonModelLoader method implemented.
/**
* Copied from MethodSymbol.implemented and adapted for ignoring methods
*/
private Symbol implemented(MethodSymbol m, TypeSymbol c, Types types) {
Symbol impl = null;
for (List<Type> is = types.interfaces(c.type); impl == null && is.nonEmpty(); is = is.tail) {
TypeSymbol i = is.head.tsym;
impl = implementedIn(m, i, types);
if (impl == null)
impl = implemented(m, i, types);
}
return impl;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type 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.Type 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.Type in project ceylon by eclipse.
the class JavacClass method getInterfaces.
@Override
public List<TypeMirror> getInterfaces() {
if (interfaces == null) {
List<TypeMirror> ret = new ArrayList<TypeMirror>(classSymbol.getInterfaces().size());
for (Type interfce : classSymbol.getInterfaces()) ret.add(new JavacType(interfce));
interfaces = Collections.unmodifiableList(ret);
}
return interfaces;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class JavacType method getComponentType.
@Override
public TypeMirror getComponentType() {
if (!componentTypeSet && type instanceof ArrayType) {
Type compType = ((ArrayType) type).getComponentType();
if (compType != null) {
componentType = new JavacType(compType);
}
componentTypeSet = true;
}
return componentType;
}
Aggregations