• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Suitable datastructure for classes...?

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anyone suggest a suitable datastructure to represent java classes?
I have information of a given class e.g what its name is, what methods it has, what fields etc. I need to store this information in some way.
Should i just have something like this:
//a classstructure object which has a list of methods and fields and
whatever else there is...
class ClassStructure
{
String name ;
List methods ;
List fields ;
//the usual getter/setter methods
addMethod(MethodStructure m) ;
addField(FieldStructure f) ;
}
class MethodStructure
{
String name ;
List parameters ;
String body ;
//etc
}
I hope you understand what i am doing.
Is this the best way to represent a java class???
I need to do this so that i can carry out quick searches on source code. For example, I want to be able to say something like: "Get me all the
methods whose names begin with "get*" and return a String". So the program would return
getName(), getAddress() etc. I do not want to carry out a full text search.
Any comments would be appreciated
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you just use reflection to do this?
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To clarify what Cindy just said, the java.lang.Class is the "structure" you're looking for.
 
Fahd Shariff
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know about the reflection api. But my ultimate goal is to create a database that contains lots of classes.
I have already created a parser that can parse java source and return all the information from a particular class(similar to the reflection api plus more info). But I would like to store this somewhere. Once stored i should be able to display the code in a number of ways.
Now the question is: what should the database "look like"? Should it be object oriented like i described previously, in the form of a tree, table? Which one would be the best?
 
reply
    Bookmark Topic Watch Topic
  • New Topic