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.

View | Details | Raw Unified | Return to bug 204435
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+12 lines)
Lines 108-113 Link Here
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
109
109
110
    <changes>
110
    <changes>
111
        <change id="TreeUtilities-isCompileTimeConstantExpression">
112
             <api name="general"/>
113
             <summary>Added <code>TreeUtilities.isCompileTimeConstantExpression</code>.</summary>
114
             <version major="0" minor="91"/>
115
             <date day="7" month="11" year="2011"/>
116
             <author login="jlahoda"/>
117
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
118
             <description>
119
                 Added <code>TreeUtilities.isCompileTimeConstantExpression</code> that tests whether the given expression is a compile-time constant.
120
             </description>
121
             <issue number="204435"/>
122
        </change>
111
        <change id="CompilationInfo-cache">
123
        <change id="CompilationInfo-cache">
112
             <api name="general"/>
124
             <api name="general"/>
113
             <summary>Added <code>CompilationInfo.getCachedValue</code>, <code>CompilationInfo.putCachedValue</code> and <code>CompilationInfo.CacheClearPolicy</code>.</summary>
125
             <summary>Added <code>CompilationInfo.getCachedValue</code>, <code>CompilationInfo.putCachedValue</code> and <code>CompilationInfo.CacheClearPolicy</code>.</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.90.0
49
spec.version.base=0.91.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/TreeUtilities.java (+14 lines)
Lines 1148-1151 Link Here
1148
            return list.size();
1148
            return list.size();
1149
        }
1149
        }
1150
    }
1150
    }
1151
1152
    /**Checks whether the given expression is a compile-time constant, as per JLS 15.28.
1153
     * 
1154
     * @param expression the expression to check
1155
     * @return true if and only if the given expression represents a compile-time constant value
1156
     * @since 0.91
1157
     */
1158
    public boolean isCompileTimeConstantExpression(TreePath expression) {
1159
        Scope s = info.getTrees().getScope(expression);
1160
        TypeMirror attributeTree = attributeTree(expression.getLeaf(), s);
1161
        Type attributeTreeImpl = (Type) attributeTree;
1162
1163
        return attributeTreeImpl != null && attributeTreeImpl.constValue() != null;
1164
    }
1151
}
1165
}
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/TreeUtilitiesTest.java (+18 lines)
Lines 43-48 Link Here
43
 */
43
 */
44
package org.netbeans.api.java.source;
44
package org.netbeans.api.java.source;
45
45
46
import com.sun.source.tree.AssignmentTree;
46
import com.sun.source.tree.BlockTree;
47
import com.sun.source.tree.BlockTree;
47
import com.sun.source.tree.ClassTree;
48
import com.sun.source.tree.ClassTree;
48
import com.sun.source.tree.LiteralTree;
49
import com.sun.source.tree.LiteralTree;
Lines 53-59 Link Here
53
import com.sun.source.tree.Tree.Kind;
54
import com.sun.source.tree.Tree.Kind;
54
import com.sun.source.tree.VariableTree;
55
import com.sun.source.tree.VariableTree;
55
import com.sun.source.util.TreePath;
56
import com.sun.source.util.TreePath;
57
import com.sun.source.util.TreePathScanner;
56
import java.io.File;
58
import java.io.File;
59
import java.util.ArrayList;
57
import java.util.Arrays;
60
import java.util.Arrays;
58
import java.util.HashSet;
61
import java.util.HashSet;
59
import java.util.List;
62
import java.util.List;
Lines 480-483 Link Here
480
483
481
        assertFalse(info.getTreeUtilities().isStaticContext(s));
484
        assertFalse(info.getTreeUtilities().isStaticContext(s));
482
    }
485
    }
486
487
    public void testIsCompileTimeConstant() throws Exception {
488
        prepareTest("Test", "package test; public class Test { private void m(String str) { int i; i = 1 + 1; i = str.length(); } }");
489
490
        final List<Boolean> result = new ArrayList<Boolean>();
491
492
        new TreePathScanner<Void, Void>() {
493
            @Override public Void visitAssignment(AssignmentTree node, Void p) {
494
                result.add(info.getTreeUtilities().isCompileTimeConstantExpression(new TreePath(getCurrentPath(), node.getExpression())));
495
                return super.visitAssignment(node, p);
496
            }
497
        }.scan(info.getCompilationUnit(), null);
498
499
        assertEquals(Arrays.asList(true, false), result);
500
    }
483
}
501
}

Return to bug 204435