This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 253472

Summary: Declarative hints: No way to match against a literal
Product: java Reporter: misterm <misterm>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal CC: geertjan, hmichel, jkovalsky, jlahoda
Priority: P2    
Version: 8.1   
Hardware: PC   
OS: Windows 8   
Issue Type: ENHANCEMENT Exception Reporter:

Description misterm 2015-07-14 19:10:22 UTC
Use case:

I was trying to migrate a Spring project to Java EE 7. So I need rules to change things like:

@Scope("request") -> @RequestScoped
@Scope("view") -> @ViewAccessScoped

However, this is currently not possible with the current infrastructure. It should be simple to implement, because I did it in a hackish way:

<?
   import java.lang.reflect.Field;
   import java.lang.reflect.Method;
?>
	
<?
   Method getSingleVariable;
	Method getLeaf;
	Method getValue;
	
	private Method getSingleVariable() throws Exception {
		if (getSingleVariable != null) {
			return getSingleVariable;
		}

		getSingleVariable = Context.class.getDeclaredMethod("getSingleVariable", 
				Variable.class);
		getSingleVariable.setAccessible(true);
		return getSingleVariable;
	}
	
	private Method getLeaf(Object treePath) throws Exception {
		if (getLeaf != null) {
			return getLeaf;
		}

		return getLeaf = treePath.getClass().getMethod("getLeaf");
	}
	
	private Method getValue(Object tree) throws Exception {
		if (getValue != null) {
			return getValue;
		}

		return getValue = tree.getClass().getMethod("getValue");
	}
	
	private String literal(Variable v) throws Exception {
		Object treePath = getSingleVariable().invoke(context, v);
		Object tree = getLeaf(treePath).invoke(treePath);
		return (String)getValue(tree).invoke(tree);
	}
	
   public boolean isView(Variable v) throws Exception {
		return "view".equals(literal(v));
	}
	
   public boolean isRequest(Variable v) throws Exception {
		return "request".equals(literal(v));
	}
	
   public boolean isSession(Variable v) throws Exception {
		return "session".equals(literal(v));
	}
	
   public boolean isApplication(Variable v) throws Exception {
		return "application".equals(literal(v));
	}
?>

This is of course as hackish as it can get, so we definitely need a permanent solution ;-)

Product Version = NetBeans IDE Dev (Build 20150701-686afc345584)
Operating System = Windows 8 version 6.2 running on amd64
Java; VM; Vendor = 1.8.0_40
Runtime = Java HotSpot(TM) 64-Bit Server VM 25.40-b25