Skip to content

add direct enum ref in JCodemodel #68

@guiguilechat

Description

@guiguilechat

sorry if this is already present, did not find it.

I already have this code in a common class :

class A {
A(MyEnum param){}
}

I want to use JCodeModel to create the class B:

class B extends A{
B(){
super(MyEnum.enum1);
}
}

I create the definedclass bclass, create the constructor, but when I want to set super(enum1) I need to call JExpr.enumConstantRef(cm.ref(MyEnum.class), enum1.name())

I think it would be easier to add an enumRef in JCodeModel that allow to refer to an enum constant more easily.
eg

/** 
* refer to clazz.ref
*/
	public <T extends Enum<T>> JEnumConstantRef enumRef(Class<T> clazz, T ref) {
		return JExpr.enumConstantRef(ref(clazz), ref.name());
	}

(did not test this code, maybe the idea is bad - it compiles but :P )

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions