use of com.sun.tools.javac.code.Symbol.MethodSymbol in project ceylon-compiler by ceylon.
the class JavacClass method getDirectMethods.
@Override
public List<MethodMirror> getDirectMethods() {
if (methods == null) {
List<MethodMirror> ret = new LinkedList<MethodMirror>();
for (Symbol sym : classSymbol.getEnclosedElements()) {
if (sym instanceof MethodSymbol && (sym.flags() & Flags.PRIVATE) == 0) {
ret.add(new JavacMethod(this, (MethodSymbol) sym));
}
}
methods = Collections.unmodifiableList(ret);
}
return methods;
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol 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.MethodSymbol 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.MethodSymbol in project checker-framework by typetools.
the class DefaultReflectionResolver method getMethodSymbolsfor.
/**
* Get set of MethodSymbols based on class name, method name, and parameter length.
*
* @param className the class that contains the method
* @param methodName the method's name
* @param paramLength the number of parameters
* @param env the environment
* @return the (potentially empty) set of corresponding method Symbol(s)
*/
private List<Symbol> getMethodSymbolsfor(String className, String methodName, int paramLength, Env<AttrContext> env) {
Context context = ((JavacProcessingEnvironment) processingEnv).getContext();
Resolve resolve = Resolve.instance(context);
Names names = Names.instance(context);
Symbol sym = getSymbol(className, env, names, resolve);
if (!sym.exists()) {
debugReflection("Unable to resolve class: " + className);
return Collections.emptyList();
}
// The common case is probably that `result` is a singleton at method exit.
List<Symbol> result = new ArrayList<>();
ClassSymbol classSym = (ClassSymbol) sym;
while (classSym != null) {
for (Symbol s : classSym.getEnclosedElements()) {
// check all member methods
if (s.getKind() == ElementKind.METHOD) {
// Check for method name and number of arguments
if (names.fromString(methodName) == s.name && ((MethodSymbol) s).getParameters().size() == paramLength) {
result.add(s);
}
}
}
if (!result.isEmpty()) {
break;
}
Type t = classSym.getSuperclass();
if (!t.hasTag(TypeTag.CLASS) || t.isErroneous()) {
break;
}
classSym = (ClassSymbol) t.tsym;
}
if (result.isEmpty()) {
debugReflection("Unable to resolve method: " + className + "@" + methodName);
}
return result;
}
use of com.sun.tools.javac.code.Symbol.MethodSymbol in project checker-framework by typetools.
the class DefaultReflectionResolver method getCorrectedArgs.
private com.sun.tools.javac.util.List<JCExpression> getCorrectedArgs(Symbol symbol, com.sun.tools.javac.util.List<JCExpression> args) {
if (symbol.getKind() == ElementKind.METHOD) {
MethodSymbol method = ((MethodSymbol) symbol);
// neg means too many arg,
// pos means to few args
int diff = method.getParameters().size() - args.size();
if (diff > 0) {
// means too few args
int origArgSize = args.size();
for (int i = 0; i < diff; i++) {
args = args.append(args.get(i % origArgSize));
}
} else if (diff < 0) {
// means too many args
com.sun.tools.javac.util.List<JCExpression> tmp = com.sun.tools.javac.util.List.nil();
for (int i = 0; i < method.getParameters().size(); i++) {
tmp = tmp.append(args.get(i));
}
args = tmp;
}
}
return args;
}
Aggregations