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 - Need API to check if an expression is a compile-time constant
Summary: Need API to check if an expression is a compile-time constant
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords: API
Depends on:
Blocks:
 
Reported: 2012-03-19 22:07 UTC by Jesse Glick
Modified: 2013-09-02 14:25 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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).