Bug 85226 - [1.5] EnumConstantDeclaration should declare resolveConstructorBinding
Summary: [1.5] EnumConstantDeclaration should declare resolveConstructorBinding
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 85228
  Show dependency tree
 
Reported: 2005-02-15 04:45 EST by Tom Hofmann CLA
Modified: 2005-03-30 22:53 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Hofmann CLA 2005-02-15 04:45:12 EST
I20050209 (jdt-core of 20050215)

EnumConstantDeclaration should allow me to query its method binding, as
declaring an enum constant also invokes a constructor:

enum Natural {
    ONE(1), TWO(2);
    
    private final int fInt;
    Natural(int n) {
        fInt= n;
    }
}

I would expect a method similar to ClassInstanceCreation:

public IMethodBinding resolveConstructorBinding();
Comment 1 Olivier Thomann CLA 2005-02-15 10:36:34 EST
I am not sure I want to see the enum constants highlighted like a method
invocation. From my point of view, this is more a field constant.
Comment 2 Tom Hofmann CLA 2005-02-15 11:11:38 EST
EnumConstantDeclarations have a double nature of both constructor invocations
and constant declarations (plus anonymous class decls sometimes). How this is
presented in the UI is a different story, but the AST element should provide all
that information.

Note that we *do* render EnumConstants like constant fields currently.
Comment 3 Tom Hofmann CLA 2005-02-15 11:26:39 EST
(In reply to comment #2)
> Note that we *do* render EnumConstants like constant fields currently.

...and we don't plan to change this. The dependent bug is about the autoboxing
highlighting, where we analyze the type bindings of, amongst other things,
method parameters. We also want to highlight the autoboxed parameters inside the
enum constant declarations:

static final int one= 1, two= 2;
static enum Natural {
	ONE(one), TWO(two);
	
	private final Integer n;

	Natural(Integer n) {
		this.n= n;
	}
}


Comment 4 Philipe Mulet CLA 2005-02-15 12:07:53 EST
Enum constants are definitely some sort of field constants. Now in compiler
land, they are provided with an initialization expression which is an allocation
(normal or qualified when constant body is supplied). 
Why not simply doing the same ?
Comment 5 Philipe Mulet CLA 2005-03-08 04:12:25 EST
Autoboxing diagnosis can be implemented using the forthcoming API:
isBoxed()/isUnboxed()
Comment 6 Jim des Rivieres CLA 2005-03-08 13:58:04 EST
Adding 
public IMethodBinding resolveConstructorBinding();
to EnumConstantDeclaration makes sense as a way of exposing the constructor 
invoked in the enum constant declaration.
Comment 7 Olivier Thomann CLA 2005-03-08 13:58:16 EST
API has been added.
Regression tests added in ASTConverter15Test. I updated existing tests. Look for
references to resolveConstructorBinding().
Comment 8 Olivier Thomann CLA 2005-03-08 14:02:00 EST
Fixed and released.
Comment 9 Olivier Thomann CLA 2005-03-30 22:53:51 EST
Verified in 20050330-0500