Modifiers and ClassOrInterfaceDeclaration

55 views
Skip to first unread message

Schabby

unread,
Nov 13, 2010, 12:18:46 PM11/13/10
to JavaParser
Hi There!

I find JavaParser very useful. I have been toying around a bit with
antlr and the Java Compilation API, but I guess I will stick to
JavaParser for my little project.

Here come two questions/remarks:

1. Could somebody provide some information regarding the correct
interpretation of the modifier values? I believe it is simply a bit
mask, but some explaining words in the "How To" about it would be
helpful.

2. Also, a word on the different TypeDeclarations would be nice. I
took me some time to figure out how to get the "extends" and
"implements" of classes/interfaces from the TypeDeclarations, until I
found out that I have to cast them up to their respective type in
order to get this information.

Cheers and please keep up the good work!

Johannes

jgesser

unread,
Nov 16, 2010, 7:33:56 PM11/16/10
to JavaParser
Hi Johannes

1.
Yes, it is a bit set. You should use japa.parser.ast.body.ModifierSet
to get the individual modifiers. For example:

int modifiers = classDecl.getModifiers();
if (ModifierSet.isPrivate(modifiers)) {
System.out.println("It is private");
}

Check ModifierSet javadoc for more information.

2.
By while you have only 2 options:
- use "instanceof" to check which instance the TypeDeclaration is
- use a visitor, the visitor pattern will make you land in the right
implementation of TypeDeclaration without the instanceof


regards,

--
Júlio Vilmar Gesser
Reply all
Reply to author
Forward
0 new messages