Java: Check Constant Value defined from other File

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?

Hello @sopiana

If you are using a version of SonarQube including version >= 6.1 of the Java analyzer, you can use asConstant() from the ExpressionTree interface.

It’s a method returning the value as a constant from a literal, an effectively final (never re-assigned) variable in the same file or a final variable in another file (including when coming from a library). It seems to be exactly what you are looking for.

Hope it helps.

Best,
Quentin