--- a/java.source/apichanges.xml Sun Oct 30 12:32:59 2011 +0100 +++ a/java.source/apichanges.xml Mon Oct 31 12:33:41 2011 +0100 @@ -108,6 +108,18 @@ + + + Added TreeUtilities.isCompileTimeConstantExpression. + + + + + + Added TreeUtilities.isCompileTimeConstantExpression that tests whether the given expression is a compile-time constant. + + + Added CompilationInfo.getCachedValue, CompilationInfo.putCachedValue and CompilationInfo.CacheClearPolicy. --- a/java.source/nbproject/project.properties Sun Oct 30 12:32:59 2011 +0100 +++ a/java.source/nbproject/project.properties Mon Oct 31 12:33:41 2011 +0100 @@ -46,7 +46,7 @@ javadoc.title=Java Source javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=0.90.0 +spec.version.base=0.91.0 test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\ ${o.n.core.dir}/lib/boot.jar:\ --- a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java Sun Oct 30 12:32:59 2011 +0100 +++ a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java Mon Oct 31 12:33:41 2011 +0100 @@ -1148,4 +1148,18 @@ return list.size(); } } + + /**Checks whether the given expression is a compile-time constant, as per JLS 15.28. + * + * @param expression the expression to check + * @return true if and only if the given expression represents a compile-time constant value + * @since 0.91 + */ + public boolean isCompileTimeConstantExpression(TreePath expression) { + Scope s = info.getTrees().getScope(expression); + TypeMirror attributeTree = attributeTree(expression.getLeaf(), s); + Type attributeTreeImpl = (Type) attributeTree; + + return attributeTreeImpl != null && attributeTreeImpl.constValue() != null; + } } --- a/java.source/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java Sun Oct 30 12:32:59 2011 +0100 +++ a/java.source/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java Mon Oct 31 12:33:41 2011 +0100 @@ -43,6 +43,7 @@ */ package org.netbeans.api.java.source; +import com.sun.source.tree.AssignmentTree; import com.sun.source.tree.BlockTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.LiteralTree; @@ -53,7 +54,9 @@ import com.sun.source.tree.Tree.Kind; import com.sun.source.tree.VariableTree; import com.sun.source.util.TreePath; +import com.sun.source.util.TreePathScanner; import java.io.File; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -480,4 +483,19 @@ assertFalse(info.getTreeUtilities().isStaticContext(s)); } + + public void testIsCompileTimeConstant() throws Exception { + prepareTest("Test", "package test; public class Test { private void m(String str) { int i; i = 1 + 1; i = str.length(); } }"); + + final List result = new ArrayList(); + + new TreePathScanner() { + @Override public Void visitAssignment(AssignmentTree node, Void p) { + result.add(info.getTreeUtilities().isCompileTimeConstantExpression(new TreePath(getCurrentPath(), node.getExpression()))); + return super.visitAssignment(node, p); + } + }.scan(info.getCompilationUnit(), null); + + assertEquals(Arrays.asList(true, false), result); + } }