Community
Participate
Working Groups
I am writing code similar to CompilationUnit#findElements(), but not similar enough to be able to directly call that method. I need to be able to re-locate an existing initializer or anonymous type inside a new type or new method. IMethod contains a method getType(String name, int occurrenceCount) and IType contains a method getInitializer(int occurrenceCount). It is however not possible to retrieve the occurence count of an existing initializer or a type with API methods. I cannot use the parents' element type lists or initializer lists to relocate the initializer or type, as those methods require the parent to exist. So, the request is for a method "int getOccurrenceCount()" in IInitializer and IType. Philip
We also wouldn't mind if the method was added on ISourceReference, although IInitializer and IType would be sufficient for now.
Could this PR be considered for 3.2 (or even M4)? We currently cast to the internal SourceRefElement to get at this information, but we shouldn't ship like this ;-)
The occurrence count doesn't really make sense for an IClassFile or an ICompilationUnit, so it cannot be on ISourceReference. Instead I added IMember#getOccurrenceCount(). Also added tests CompilationUnitTests#testGetOccurrenceCount01/02.
Verified for 3.2 M4 using build I20051212-0010