This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 93100 - Too complex to find a list of classes in a File
Summary: Too complex to find a list of classes in a File
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on: 105618
Blocks:
  Show dependency tree
 
Reported: 2007-01-24 13:52 UTC by Jaroslav Tulach
Modified: 2007-06-05 14:09 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jaroslav Tulach 2007-01-24 13:52:49 UTC
I tried to get list of all (top level) ClassElement for a file and the 
simplest way seems to be:

for (Tree t : cont.getCompilationUnit().getTypeDecls()) {
    if (t.getKind() == Tree.Kind.CLASS) {
        TreePath path = cont.getTrees().getPath(cont.getCompilationUnit(), t);
        Element e = cont.getTrees().getElement(path);
        TypeElement te = (TypeElement)e;
    }
}

that is not really nice, although I want to work just on Element level I need 
to go thru Tree hierarchy. It took me a while and two consulation (Flaskin, 
David Kaspar) to find the right code and maybe (as this seems like a common 
operation) you should consider adding a method:

List<? extends TypeElement> getTypeElementDeclarations()

that would return directly the TypeElements for top level classes.
Comment 1 Jan Lahoda 2007-01-24 14:59:28 UTC
I agree.
Comment 2 Tomas Zezula 2007-06-05 14:09:38 UTC
Checking in apichanges.xml;
/cvs/java/source/apichanges.xml,v  <--  apichanges.xml
new revision: 1.10; previous revision: 1.9
done
Checking in nbproject/project.properties;
/cvs/java/source/nbproject/project.properties,v  <--  project.properties
new revision: 1.20; previous revision: 1.19
done
Checking in src/org/netbeans/api/java/source/CompilationController.java;
/cvs/java/source/src/org/netbeans/api/java/source/CompilationController.java,v 
<--  CompilationController.java
new revision: 1.7; previous revision: 1.6
done
Checking in src/org/netbeans/api/java/source/CompilationInfo.java;
/cvs/java/source/src/org/netbeans/api/java/source/CompilationInfo.java,v  <-- 
CompilationInfo.java
new revision: 1.11; previous revision: 1.10
done
Checking in src/org/netbeans/api/java/source/ElementHandle.java;
/cvs/java/source/src/org/netbeans/api/java/source/ElementHandle.java,v  <-- 
ElementHandle.java
new revision: 1.13; previous revision: 1.12
done
Checking in src/org/netbeans/api/java/source/JavaSource.java;
/cvs/java/source/src/org/netbeans/api/java/source/JavaSource.java,v  <-- 
JavaSource.java
new revision: 1.60; previous revision: 1.59
done
Checking in src/org/netbeans/modules/java/source/parsing/SourceFileObject.java;
/cvs/java/source/src/org/netbeans/modules/java/source/parsing/SourceFileObject.java,v
 <--  SourceFileObject.java
new revision: 1.12; previous revision: 1.11
done
Checking in src/org/netbeans/modules/java/source/resources/mime-resolver.xml;
/cvs/java/source/src/org/netbeans/modules/java/source/resources/mime-resolver.xml,v
 <--  mime-resolver.xml
new revision: 1.3; previous revision: 1.2
done
Checking in src/org/netbeans/modules/java/source/usages/ClassFileUtil.java;
/cvs/java/source/src/org/netbeans/modules/java/source/usages/ClassFileUtil.java,v
 <--  ClassFileUtil.java
new revision: 1.6; previous revision: 1.5
done
Checking in src/org/netbeans/modules/java/ui/Icons.java;
/cvs/java/source/src/org/netbeans/modules/java/ui/Icons.java,v  <--  Icons.java
new revision: 1.6; previous revision: 1.5
done