• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Explicit tests for inner, member, and anonymous classes

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have built up a simple GUI builder tool that I use to experiment with different layout managers and general coding exercises. Now I'm playing with a simple ( or maybe it will become not so simple) code generator that will unwrap the root container and spew out source code that can be compiled to recreate the UI structure.

Well, I guess I've gone brain dead because for the life of me, I can not recall ever explicitly testing a class to determine if its an inner class, anonymous class, component member class, etc.

With the .getClass().getName() its easy to screen out the anonymous classes with a test for the '$' delimiter, but the question becomes "Is there a more formal test that can be applied?" such as using ancestry. Would appreciate anyone's experiences in unwrapping and code generation.

If I ever get it unscrewed to the point I'm not embrassed by the code I'll post it back here for the next person's query. Thanks All,
- Dan
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use JDK 5, there are a number of new methods in the Class class which can help you - isAnonymousClass(), isMemberClass(), getContainingClass(), etc. For earlier JDKs - well, there's getDeclaringClass() at least. That can be used to tell you if you're dealing with a member class, though it's no good for identifying local or anonymous classes. What you're trying to do will be much easier under JDK 5, that's for sure.
 
Doe, a deer, a female deer. Ray, a pockeful of sun. Me, a name, I call my tiny ad ...
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic