Bug 122460 - Why is checking a modifier so code intensive
Summary: Why is checking a modifier so code intensive
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-02 12:23 EST by Dirk Baeumer CLA
Modified: 2006-02-15 10:47 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.