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 209759

Summary: Need API to check if an expression is a compile-time constant
Product: java Reporter: Jesse Glick <jglick>
Component: SourceAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal Keywords: API
Priority: P3    
Version: 7.2   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description Jesse Glick 2012-03-19 22:07:17 UTC
For some Java hints it would be useful to have something like org.netbeans.modules.java.hints.errors.Utilities.isConstantString available in a public API. More generally you may need to know the constant value, and expressions of primitive (rather than String) type may be of interest too. I would suggest a signature like

  Object getConstantValue(CompilationInfo info, TreePath tp)

which could return a String, primitive wrapper, or null, akin to the method of the same name in VariableElement. This could subsume isConstantString:

  boolean isConst = Whatever.getConstantValue(...) instanceof String;

as well as ArithmeticUtilities.compute and probably some other code in java.hints (like the scanner in Regexp.hint).