当前位置: 首页>>代码示例>>Java>>正文


Java LiteralTree.getValue方法代码示例

本文整理汇总了Java中com.sun.source.tree.LiteralTree.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java LiteralTree.getValue方法的具体用法?Java LiteralTree.getValue怎么用?Java LiteralTree.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.source.tree.LiteralTree的用法示例。


在下文中一共展示了LiteralTree.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: matchMethodInvocation

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree t, VisitorState state) {
  if (PRECONDITIONS_CHECK.matches(t, state)
      && t.getArguments().size() >= 2
      && t.getArguments().get(1) instanceof LiteralTree) {
    LiteralTree formatStringTree = (LiteralTree) t.getArguments().get(1);
    if (formatStringTree.getValue() instanceof String) {
      String formatString = (String) formatStringTree.getValue();
      int expectedArgs = expectedArguments(formatString);
      if (expectedArgs < t.getArguments().size() - 2
          && BAD_PLACEHOLDER_REGEX.matcher(formatString).find()) {
        return describe(t, state);
      }
    }
  }
  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:18,代码来源:PreconditionsInvalidPlaceholder.java

示例2: matchDivZero

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
private Description matchDivZero(Tree tree, ExpressionTree operand, VisitorState state) {
  if (!anyOf(kindIs(Kind.DIVIDE), kindIs(Kind.DIVIDE_ASSIGNMENT)).matches(tree, state)) {
    return Description.NO_MATCH;
  }

  if (!kindIs(Kind.INT_LITERAL).matches(operand, state)) {
    return Description.NO_MATCH;
  }

  LiteralTree rightOperand = (LiteralTree) operand;
  if (((Integer) rightOperand.getValue()) != 0) {
    return Description.NO_MATCH;
  }

  // Find and replace enclosing Statement.
  StatementTree enclosingStmt =
      ASTHelpers.findEnclosingNode(state.getPath(), StatementTree.class);
  return (enclosingStmt != null)
      ? describeMatch(
          tree,
          SuggestedFix.replace(enclosingStmt, "throw new ArithmeticException(\"/ by zero\");"))
      : describeMatch(tree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:DivZero.java

示例3: matchDivZero

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Description matchDivZero(Tree tree, ExpressionTree operand, VisitorState state) {
  if (!anyOf(kindIs(Kind.DIVIDE), kindIs(Kind.DIVIDE_ASSIGNMENT)).matches(tree, state)) {
    return Description.NO_MATCH;
  }

  if (!kindIs(Kind.INT_LITERAL).matches(operand, state)) {
    return Description.NO_MATCH;
  }

  LiteralTree rightOperand = (LiteralTree) operand;
  if (((Integer) rightOperand.getValue()) != 0) {
    return Description.NO_MATCH;
  }

  // Find and replace enclosing Statement.
  StatementTree enclosingStmt =
      ASTHelpers.findEnclosingNode(state.getPath(), StatementTree.class);
  SuggestedFix fix = new SuggestedFix();
  if (enclosingStmt != null) {
    fix = fix.replace(enclosingStmt, "throw new ArithmeticException(\"/ by zero\");");
  }

  return describeMatch(tree, fix);
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:26,代码来源:DivZero.java

示例4: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
    if (!type.isAnnotatedInHierarchy(FORMAT)) {
        String format = null;
        if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
            format = (String) tree.getValue();
        } else if (tree.getKind() == Tree.Kind.CHAR_LITERAL) {
            format = Character.toString((Character) tree.getValue());
        }
        if (format != null) {
            AnnotationMirror anno;
            try {
                ConversionCategory[] cs = FormatUtil.formatParameterCategories(format);
                anno = FormatterAnnotatedTypeFactory.this.treeUtil.categoriesToFormatAnnotation(cs);
            } catch (IllegalFormatException e) {
                anno = FormatterAnnotatedTypeFactory.this.treeUtil.exceptionToInvalidFormatAnnotation(e);
            }
            type.addAnnotation(anno);
        }
    }
    return super.visitLiteral(tree, type);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:23,代码来源:FormatterAnnotatedTypeFactory.java

示例5: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
/**
 * Case 1: valid regular expression String or char literal.
 * Adds PartialRegex annotation to String literals that are not valid
 * regular expressions.
 */
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
    if (!type.isAnnotatedInHierarchy(REGEX)) {
        String regex = null;
        if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
            regex = (String) tree.getValue();
        } else if (tree.getKind() == Tree.Kind.CHAR_LITERAL) {
            regex = Character.toString((Character) tree.getValue());
        }
        if (regex != null) {
            if (isRegex(regex)) {
                int groupCount = getGroupCount(regex);
                type.addAnnotation(createRegexAnnotation(groupCount));
            } else {
                type.addAnnotation(createPartialRegexAnnotation(regex));
            }
        }
    }
    return super.visitLiteral(tree, type);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:26,代码来源:RegexAnnotatedTypeFactory.java

示例6: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
/**
 * Go through the string patterns and add the greatest lower bound of all matching patterns.
 */
@Override
public Void visitLiteral(LiteralTree tree, AnnotatedTypeMirror type) {
    if (!stringPatterns.isEmpty() && tree.getKind() == Tree.Kind.STRING_LITERAL) {
        Set<? extends AnnotationMirror> res = null;
        String string = (String) tree.getValue();
        for (Pattern pattern : stringPatterns.keySet()) {
            if (pattern.matcher(string).matches()) {
                if (res == null) {
                    res = stringPatterns.get(pattern);
                } else {
                    Set<? extends AnnotationMirror> newres = stringPatterns.get(pattern);
                    res = qualHierarchy.greatestLowerBounds(res, newres);
                }
            }
        }
        if (res != null) {
            type.addAnnotations(res);
        }
    }
    return super.visitLiteral(tree, type);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:25,代码来源:TreeAnnotator.java

示例7: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:CopyFinder.java

示例8: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Number visitLiteral(LiteralTree node, Void p) {
    if (node.getValue() instanceof Number) {
        return (Number) node.getValue();
    }

    return super.visitLiteral(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JavaFixUtilities.java

示例9: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Object visitLiteral(LiteralTree node, Void p) {
    if (node.getKind() == NULL_LITERAL) {
        return enhanceProcessing ? NULL : null;
    } 
    return node.getValue();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ArithmeticUtilities.java

示例10: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Boolean visitLiteral(LiteralTree node, ConstructorData p) {
    Object val = node.getValue();

    if (val instanceof Boolean) {
        return (Boolean) val;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:Flow.java

示例11: visitLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:Utilities.java

示例12: canBooleanExpressionEvalToTrue

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
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;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:15,代码来源:RxNullabilityPropagator.java

示例13: matches

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
  if (expressionTree instanceof LiteralTree) {
    LiteralTree literalTree = (LiteralTree) expressionTree;
    Object actualValue = literalTree.getValue();
    return actualValue instanceof String && pattern.matcher((String) actualValue).matches();
  } else {
    return false;
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:11,代码来源:StringLiteral.java

示例14: matchLiteral

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public Description matchLiteral(LiteralTree tree, VisitorState state) {
  Object value = tree.getValue();
  if (!(value instanceof String)) {
    return NO_MATCH;
  }
  if (!missingFormatArgs((String) value)) {
    return NO_MATCH;
  }
  Tree parent = state.getPath().getParentPath().getLeaf();
  if (!MATCHER.matches(parent, state)) {
    return NO_MATCH;
  }
  return describeMatch(tree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:16,代码来源:OrphanedFormatString.java

示例15: matches

import com.sun.source.tree.LiteralTree; //导入方法依赖的package包/类
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
  if (expressionTree instanceof LiteralTree) {
    LiteralTree literalTree = (LiteralTree) expressionTree;
    Object actualValue = literalTree.getValue();
    return actualValue instanceof String && actualValue.equals(value);
  } else {
    return false;
  }
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:11,代码来源:StringLiteral.java


注:本文中的com.sun.source.tree.LiteralTree.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。