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

Summary: Too complex to find a list of classes in a File
Product: java Reporter: Jaroslav Tulach <jtulach>
Component: SourceAssignee: Tomas Zezula <tzezula>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:
Bug Depends on: 105618    
Bug Blocks:    

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