use of com.sun.tools.javac.code.Symbol.TypeSymbol in project ceylon-compiler by ceylon.
the class JavacTrees method getTree.
public JCTree getTree(Element element) {
Symbol symbol = (Symbol) element;
TypeSymbol enclosing = symbol.enclClass();
Env<AttrContext> env = enter.getEnv(enclosing);
if (env == null)
return null;
JCClassDecl classNode = env.enclClass;
if (classNode != null) {
if (TreeInfo.symbolFor(classNode) == element)
return classNode;
for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element)
return node;
}
return null;
}
use of com.sun.tools.javac.code.Symbol.TypeSymbol in project ceylon-compiler by ceylon.
the class JavacUtil method getTypeParameters.
public static List<TypeParameterMirror> getTypeParameters(Symbol symbol) {
try {
com.sun.tools.javac.util.List<TypeSymbol> typeParameters = symbol.getTypeParameters();
List<TypeParameterMirror> ret = new ArrayList<TypeParameterMirror>(typeParameters.size());
for (TypeSymbol typeParameter : typeParameters) ret.add(new JavacTypeParameter(typeParameter));
return ret;
} catch (CompletionFailure x) {
throw new ModelResolutionException("Failed to load type parameters", x);
}
}
use of com.sun.tools.javac.code.Symbol.TypeSymbol in project ceylon-compiler by ceylon.
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 com.sun.tools.javac.code.Symbol.TypeSymbol in project ceylon-compiler by ceylon.
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 com.sun.tools.javac.code.Symbol.TypeSymbol in project bazel by bazelbuild.
the class InternalUtils method substituteMethodReturnType.
/**
* Returns the return type of a method, where the "raw" return type of that
* method is given (i.e., the return type might still contain unsubstituted
* type variables), given the receiver of the method call.
*/
public static TypeMirror substituteMethodReturnType(TypeMirror methodType, TypeMirror substitutedReceiverType) {
if (methodType.getKind() != TypeKind.TYPEVAR) {
return methodType;
}
// TODO: find a nicer way to substitute type variables
String t = methodType.toString();
Type finalReceiverType = (Type) substitutedReceiverType;
int i = 0;
for (TypeSymbol typeParam : finalReceiverType.tsym.getTypeParameters()) {
if (t.equals(typeParam.toString())) {
return finalReceiverType.getTypeArguments().get(i);
}
i++;
}
assert false;
return null;
}
Aggregations