Bug 122460

Summary: Why is checking a modifier so code intensive
Product: [Eclipse Project] JDT Reporter: Dirk Baeumer <dirk_baeumer>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: philippe_mulet
Version: 3.2   
Target Milestone: 3.2 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Dirk Baeumer CLA 2006-01-02 12:23:57 EST
I have a modifier (ast node) in hand and want to find out if it is a public modifier. The code I have to write is:

Modifier.isPublic(modifier.getKeyword().toFlagValue())

why can't I simply write:

modifier.isPublic()
Comment 1 Philipe Mulet CLA 2006-01-03 05:02:50 EST
If only interested in checking flags, you could use:

(method.getModifiers() & Modifier.PUBLIC) != 0

But I agree, more convenience methods wouldn't hurt.
Comment 2 Olivier Thomann CLA 2006-01-03 09:12:49 EST
What do you expect for this PR?
New API?
Comment 3 Dirk Baeumer CLA 2006-01-03 09:55:10 EST
Actually I am checking flags and annotations. That's why I am iterating over all extended modifiers of the method declaration node.
Comment 4 Olivier Thomann CLA 2006-01-03 10:41:51 EST
Do you suggest to add all these methods on org.eclipse.jdt.core.dom.Modifier?

isPublic()
isPrivate()
isProtected()
isStatic()
isFinal()
isSynchronized()
isVolatile()
isTransient()
isNative()
isAbstract()
isStrictfp()
Comment 5 Dirk Baeumer CLA 2006-01-03 12:02:34 EST
+1 since this is what I expected to have when I typed in my code.

The static methods were good to use when the modifiers where still encoded as flags (JSL2), but with JSL3 I think we should have corresponding instance methods as well. 
Comment 6 Olivier Thomann CLA 2006-01-04 10:39:51 EST
Fixed and released in HEAD.
Added regression test in org.eclipse.jdt.core.tests.dom.ASTTest.testModifiers
Comment 7 Olivier Thomann CLA 2006-01-04 10:41:37 EST
Also added regression test in org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2.test0443
Comment 8 Maxime Daniel CLA 2006-02-15 10:47:26 EST
Verified for 3.2 M5 using build I20060215-0010.