use of com.sun.tools.javac.util.Names in project ceylon-compiler by ceylon.
the class ClassDocImpl method methods.
/**
* Return methods in class.
* This method is overridden by AnnotationTypeDocImpl.
*
* @param filter include only the included methods if filter==true
* @return an array of MethodDocImpl for representing the visible
* methods in this class. Does not include constructors.
*/
public MethodDoc[] methods(boolean filter) {
Names names = tsym.name.table.names;
List<MethodDocImpl> methods = List.nil();
for (Scope.Entry e = tsym.members().elems; e != null; e = e.sibling) {
if (e.sym != null && e.sym.kind == Kinds.MTH && e.sym.name != names.init) {
MethodSymbol s = (MethodSymbol) e.sym;
if (!filter || env.shouldDocument(s)) {
methods = methods.prepend(env.getMethodDoc(s));
}
}
}
//### Cache methods here?
return methods.toArray(new MethodDocImpl[methods.length()]);
}
use of com.sun.tools.javac.util.Names in project ceylon-compiler by ceylon.
the class ClassDocImpl method searchClass.
private ClassDoc searchClass(String className) {
Names names = tsym.name.table.names;
// search by qualified name first
ClassDoc cd = env.lookupClass(className);
if (cd != null) {
return cd;
}
// search inner classes
//### Add private entry point to avoid creating array?
//### Replicate code in innerClasses here to avoid consing?
ClassDoc[] innerClasses = innerClasses();
for (int i = 0; i < innerClasses.length; i++) {
if (innerClasses[i].name().equals(className) || //### 'name' of the inner class, rather than the true simple name.
innerClasses[i].name().endsWith(className)) {
return innerClasses[i];
} else {
ClassDoc innercd = ((ClassDocImpl) innerClasses[i]).searchClass(className);
if (innercd != null) {
return innercd;
}
}
}
// check in this package
cd = containingPackage().findClass(className);
if (cd != null) {
return cd;
}
// make sure that this symbol has been completed
if (tsym.completer != null) {
tsym.complete();
}
if (tsym.sourcefile != null) {
//### This information is available only for source classes.
Env<AttrContext> compenv = env.enter.getEnv(tsym);
if (compenv == null)
return null;
Scope s = compenv.toplevel.namedImportScope;
for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.TYP) {
ClassDoc c = env.getClassDoc((ClassSymbol) e.sym);
return c;
}
}
s = compenv.toplevel.starImportScope;
for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.TYP) {
ClassDoc c = env.getClassDoc((ClassSymbol) e.sym);
return c;
}
}
}
// not found
return null;
}
use of com.sun.tools.javac.util.Names in project ceylon-compiler by ceylon.
the class ClassDocImpl method searchMethod.
private MethodDocImpl searchMethod(String methodName, String[] paramTypes, Set<ClassDocImpl> searched) {
//### Note that this search is not necessarily what the compiler would do!
Names names = tsym.name.table.names;
// do not match constructors
if (names.init.contentEquals(methodName)) {
return null;
}
ClassDocImpl cdi;
MethodDocImpl mdi;
if (searched.contains(this)) {
return null;
}
searched.add(this);
//DEBUG
/*---------------------------------*
System.out.print("searching " + this + " for " + methodName);
if (paramTypes == null) {
System.out.println("()");
} else {
System.out.print("(");
for (int k=0; k < paramTypes.length; k++) {
System.out.print(paramTypes[k]);
if ((k + 1) < paramTypes.length) {
System.out.print(", ");
}
}
System.out.println(")");
}
*---------------------------------*/
// search current class
Scope.Entry e = tsym.members().lookup(names.fromString(methodName));
if (paramTypes == null) {
// If no parameters specified, we are allowed to return
// any method with a matching name. In practice, the old
// code returned the first method, which is now the last!
// In order to provide textually identical results, we
// attempt to emulate the old behavior.
MethodSymbol lastFound = null;
for (; e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.MTH) {
//### Should intern methodName as Name.
if (e.sym.name.toString().equals(methodName)) {
lastFound = (MethodSymbol) e.sym;
}
}
}
if (lastFound != null) {
return env.getMethodDoc(lastFound);
}
} else {
for (; e.scope != null; e = e.next()) {
if (e.sym != null && e.sym.kind == Kinds.MTH) {
//### Should intern methodName as Name.
if (hasParameterTypes((MethodSymbol) e.sym, paramTypes)) {
return env.getMethodDoc((MethodSymbol) e.sym);
}
}
}
}
//### If we found a MethodDoc above, but which did not pass
//### the modifier filter, we should return failure here!
// search superclass
cdi = (ClassDocImpl) superclass();
if (cdi != null) {
mdi = cdi.searchMethod(methodName, paramTypes, searched);
if (mdi != null) {
return mdi;
}
}
// search interfaces
ClassDoc[] intf = interfaces();
for (int i = 0; i < intf.length; i++) {
cdi = (ClassDocImpl) intf[i];
mdi = cdi.searchMethod(methodName, paramTypes, searched);
if (mdi != null) {
return mdi;
}
}
// search enclosing class
cdi = (ClassDocImpl) containingClass();
if (cdi != null) {
mdi = cdi.searchMethod(methodName, paramTypes, searched);
if (mdi != null) {
return mdi;
}
}
return null;
}
use of com.sun.tools.javac.util.Names in project ceylon-compiler by ceylon.
the class ClassDocImpl method searchField.
private FieldDocImpl searchField(String fieldName, Set<ClassDocImpl> searched) {
Names names = tsym.name.table.names;
if (searched.contains(this)) {
return null;
}
searched.add(this);
for (Scope.Entry e = tsym.members().lookup(names.fromString(fieldName)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.VAR) {
//### Should intern fieldName as Name.
return env.getFieldDoc((VarSymbol) e.sym);
}
}
//### If we found a FieldDoc above, but which did not pass
//### the modifier filter, we should return failure here!
ClassDocImpl cdi = (ClassDocImpl) containingClass();
if (cdi != null) {
FieldDocImpl fdi = cdi.searchField(fieldName, searched);
if (fdi != null) {
return fdi;
}
}
// search superclass
cdi = (ClassDocImpl) superclass();
if (cdi != null) {
FieldDocImpl fdi = cdi.searchField(fieldName, searched);
if (fdi != null) {
return fdi;
}
}
// search interfaces
ClassDoc[] intf = interfaces();
for (int i = 0; i < intf.length; i++) {
cdi = (ClassDocImpl) intf[i];
FieldDocImpl fdi = cdi.searchField(fieldName, searched);
if (fdi != null) {
return fdi;
}
}
return null;
}
use of com.sun.tools.javac.util.Names in project ceylon-compiler by ceylon.
the class T6889255 method test.
void test(String testName, boolean expectNames, String... opts) throws Exception {
System.err.println("Test " + testName + ": expectNames:" + expectNames + " javacOpts:" + Arrays.asList(opts));
File outDir = new File(testName);
outDir.mkdirs();
compile(outDir, opts);
Context ctx = new Context();
JavacFileManager fm = new JavacFileManager(ctx, true, null);
fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(outDir));
ClassReader cr = ClassReader.instance(ctx);
cr.saveParameterNames = true;
Names names = Names.instance(ctx);
Set<String> classes = getTopLevelClasses(outDir);
Deque<String> work = new LinkedList<String>(classes);
String classname;
while ((classname = work.poll()) != null) {
System.err.println("Checking class " + classname);
ClassSymbol sym = cr.enterClass(names.table.fromString(classname));
sym.complete();
if ((sym.flags() & Flags.INTERFACE) != 0 && !testInterfaces)
continue;
for (Scope.Entry e = sym.members_field.elems; e != null; e = e.sibling) {
System.err.println("Checking member " + e.sym);
switch(e.sym.kind) {
case Kinds.TYP:
{
String name = e.sym.flatName().toString();
if (!classes.contains(name)) {
classes.add(name);
work.add(name);
}
break;
}
case Kinds.MTH:
verify((MethodSymbol) e.sym, expectNames);
break;
}
}
}
}
Aggregations