I would like to develop a rule that check particular constants supplied to specific method. This constants will be on type short or byte data type.
For example:
on library jar file:
public static final short ACTION_DO_NOTHING = (short)0x40;
on Code:
executeAction(ACTION_DO_NOTHING);
From class file perspective, I realize that this constants will compiled as the value by the compiler.
I try to do semantic analysis using VariableSymbol as following snapshot:
if (methodSymbol.name().equals("executeAction"))
{
MemberSelectExpressionTree memberSelectExpressionTree = (MemberSelectExpressionTree) (tree.arguments().get(0));
ExpressionTree expressionTree = memberSelectExpressionTree.expression();
if (expressionTree.is(Tree.Kind.IDENTIFIER)) {
IdentifierTree identifier = (IdentifierTree) memberSelectExpressionTree.identifier();
VariableSymbol var = (VariableSymbol) identifier.symbol();
System.out.println(var.declaration());
}
However I still cannot get the constant value even though I already supply the binaries. Following is test snapshot:
@Test
public void negativeTest()
{
JavaFileScanner check = new ThrowItExceptionOccurenceRule();
File apiJar= new File("src/test/files/generic_api.jar"); //API location
File cp = new File("../Sandbox/TestFiles/RULE14/bin/"); //class file location
JavaCheckVerifier.verify("src/test/files/RULE14/CheckExecuteAction.java", check,
Arrays.asList(apiJar, cp));
}
How can I get constant value which is defined from library jar file?