Java Code Examples for com.sun.source.tree.LiteralTree#getValue()

The following examples show how to use com.sun.source.tree.LiteralTree#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CopyFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Boolean visitLiteral(LiteralTree node, TreePath p) {
    if (p == null)
        return super.visitLiteral(node, p);

    LiteralTree lt = (LiteralTree) p.getLeaf();
    Object nodeValue = node.getValue();
    Object ltValue = lt.getValue();

    if (nodeValue == ltValue)
        return true;

    if (nodeValue == null || ltValue == null)
        return false;
    return nodeValue.equals(ltValue);
}
 
Example 2
Source File: JavaFixUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Number visitLiteral(LiteralTree node, Void p) {
    if (node.getValue() instanceof Number) {
        return (Number) node.getValue();
    }

    return super.visitLiteral(node, p);
}
 
Example 3
Source File: ArithmeticUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object visitLiteral(LiteralTree node, Void p) {
    if (node.getKind() == NULL_LITERAL) {
        return enhanceProcessing ? NULL : null;
    } 
    return node.getValue();
}
 
Example 4
Source File: Flow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean visitLiteral(LiteralTree node, ConstructorData p) {
    Object val = node.getValue();

    if (val instanceof Boolean) {
        return (Boolean) val;
    } else {
        return null;
    }
}
 
Example 5
Source File: Utilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String visitLiteral(LiteralTree node, Void p) {
    if (node.getValue() instanceof String)
        return "...";

    int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), node);
    int end   = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), node);

    if (start < 0 || end < 0 || end < start) {
        return node.toString();
    }
    
    return info.getText().substring(start, end);
}
 
Example 6
Source File: StreamNullabilityPropagator.java    From NullAway with MIT License 5 votes vote down vote up
private boolean canBooleanExpressionEvalToTrue(ExpressionTree expressionTree) {
  if (expressionTree instanceof LiteralTree) {
    LiteralTree expressionAsLiteral = (LiteralTree) expressionTree;
    if (expressionAsLiteral.getValue() instanceof Boolean) {
      return (boolean) expressionAsLiteral.getValue();
    } else {
      throw new RuntimeException("not a boolean expression!");
    }
  }
  // We are fairly conservative, anything other than 'return false;' is assumed to potentially be
  // true.
  // No SAT-solving or any other funny business.
  return true;
}
 
Example 7
Source File: TreeConverter.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private TreeNode convertBooleanLiteral(LiteralTree node, TreePath parent) {
  return new BooleanLiteral((Boolean) node.getValue(), getTypeMirror(getTreePath(parent, node)));
}
 
Example 8
Source File: TreeConverter.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private TreeNode convertCharLiteral(LiteralTree node, TreePath parent) {
  return new CharacterLiteral(
      (Character) node.getValue(), getTypeMirror(getTreePath(parent, node)));
}
 
Example 9
Source File: TreeConverter.java    From j2objc with Apache License 2.0 4 votes vote down vote up
private TreeNode convertStringLiteral(LiteralTree node, TreePath parent) {
  return new StringLiteral((String) node.getValue(), getTypeMirror(getTreePath(parent, node)));
}