Bug 24518

Summary: Public flag not set for interface method
Product: [Eclipse Project] JDT Reporter: Randy Giffen <ragiffen>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: akiezun
Version: 2.0.1   
Target Milestone: 2.1 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Randy Giffen CLA 2002-10-08 11:37:15 EDT
If I have the following interface definition

public interface Test extends javax.ejb.EJBObject {
	String toUpper(String s) throws RemoteException, EJBException;
}

then when I ask for the flags for the method and test them it reports 
that the method is not public

int flags = method.getFlags();
Flags.isPublic(flags) <<< returns false.

However if I add the optional public keyword
public interface Test extends javax.ejb.EJBObject {
	public String toUpper(String s) throws RemoteException, EJBException;
}

int flags = method.getFlags();
Flags.isPublic(flags) <<< returns true.

In both cases the method is public.
Comment 1 Philipe Mulet CLA 2002-10-08 11:59:22 EDT
It depends whether you look at the AST or the resolved binding for the method. 
The AST itself only reflects syntactical information on it (if code did 
specify 'public', then yes it would answer it is public).

The binding is doing all inference, based on the context.
Comment 2 Randy Giffen CLA 2002-10-08 14:25:49 EDT
I'm dealing with an IType so I assume it is not easy to obtain
a resolved binding for the method?
Comment 3 Philipe Mulet CLA 2002-10-09 05:23:31 EDT
Ok I see. The JavaModel is only surfacing the information found in the source 
in a digested way (parsed text). No inference is performed (propagating flags 
from enclosing contexts).

We could add some new API to do so though. How critical is this for you ?
Comment 4 Randy Giffen CLA 2002-10-09 09:01:59 EDT
In our situation we need to know if a method is public. We could change
our code from 
int flags = method.getFlags();
return Flags.isPublic(flags)
to
int flags = method.getFlags();
return (Flags.isPublic(flags) || method.getDeclaringType().isInterface())

However I filed this bug because after reading the API Javadoc I thought the 
behavior was incorrect. So perhaps the doc should be clarified.
Comment 5 Adam Kiezun CLA 2002-10-09 09:20:58 EDT
Randy, have a look at our (jdt ui) JdtFlags class - we had the same problem and 
that class is a solution for it.
Comment 6 Jerome Lanneluc CLA 2002-10-29 09:25:30 EST
Clarified spec as follows:
**
 * Returns the modifier flags for this member. The flags can be examined using 
class
 * <code>Flags</code>.
 * <p>
 * Note that only flags as indicated in the source are returned. Thus if an 
interface
 * defines a method <code>void myMethod();</code> the flags don't include the
 * 'public' flag.
 *
 * @exception JavaModelException if this element does not exist or if an
 *      exception occurs while accessing its corresponding resource.
 * @return the modifier flags for this member
 * @see Flags
 */
int getFlags() throws JavaModelException;
Comment 7 David Audel CLA 2002-11-13 06:49:21 EST
Verified.