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


Java AssertTree.getCondition方法代码示例

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


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

示例1: computeAssert

import com.sun.source.tree.AssertTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeAssert(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    AssertTree at = (AssertTree) parent.getLeaf();
    
    types.add(ElementKind.PARAMETER);
    types.add(ElementKind.LOCAL_VARIABLE);
    types.add(ElementKind.FIELD);
    
    if (at.getCondition() == error) {
        return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.BOOLEAN));
    }
    
    if (at.getDetail() == error) {
        return Collections.singletonList(info.getElements().getTypeElement("java.lang.Object").asType());
    }
    
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CreateElementUtilities.java

示例2: run

import com.sun.source.tree.AssertTree; //导入方法依赖的package包/类
@TriggerTreeKind(Tree.Kind.ASSERT)
public static ErrorDescription run(HintContext ctx) {
    CompilationInfo ci = ctx.getInfo();
    AssertTree at = (AssertTree)ctx.getPath().getLeaf();
    TreePath condPath = new TreePath(ctx.getPath(), at.getCondition());
    if (ci.getTreeUtilities().isCompileTimeConstantExpression(condPath)) {
        return null;
    }
    
    SideEffectVisitor visitor = new SideEffectVisitor(ctx);
    Tree culprit;
    try {
        visitor.scan(new TreePath(ctx.getPath(), at.getCondition()), null);
        return null;
    } catch (StopProcessing stop) {
        culprit = stop.getValue();
    }
    return ErrorDescriptionFactory.forTree(ctx, culprit, TEXT_AssertWithSideEffects());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:AssertWithSideEffects.java

示例3: computeAssert

import com.sun.source.tree.AssertTree; //导入方法依赖的package包/类
private static List<? extends TypeMirror> computeAssert(Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) {
    AssertTree at = (AssertTree) parent.getLeaf();
    
    types.add(ElementKind.PARAMETER);
    types.add(ElementKind.LOCAL_VARIABLE);
    types.add(ElementKind.FIELD);
    
    if (at.getCondition() == error) {
        return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.BOOLEAN));
    }
    
    if (at.getDetail() == error) {
        return typeMirrorCollection(info, "java.lang.Object");
    }
    
    
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:CreateElementUtilities.java

示例4: replaceAssert

import com.sun.source.tree.AssertTree; //导入方法依赖的package包/类
private static void replaceAssert(
    SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state) {

  ExpressionTree expr = foundAssert.getCondition();
  expr = (ExpressionTree) TreeInfo.skipParens((JCTree) expr);

  // case: "assert !expr"
  if (expr.getKind().equals(LOGICAL_COMPLEMENT)) {
    addFix(fix, ((JCUnary) expr).getExpression(), foundAssert, state, IS_FALSE);
    return;
  }

  // case: "assert expr1.equals(expr2)"
  if (instanceMethod().onClass(Any.INSTANCE).named("equals").matches(expr, state)) {
    JCMethodInvocation equalsCall = ((JCMethodInvocation) expr);
    JCExpression expr1 = ((JCFieldAccess) ((JCMethodInvocation) expr).meth).selected;
    JCExpression expr2 = equalsCall.getArguments().get(0);

    addFix(
        fix,
        expr1,
        foundAssert,
        state,
        String.format(IS_EQUAL_TO, normalizedSourceForExpression(expr2, state)));
    return;
  }

  // case: "assert expr1 == expr2" or "assert expr1 != expr2"
  if (expr.getKind().equals(Kind.EQUAL_TO) || expr.getKind().equals(Kind.NOT_EQUAL_TO)) {
    suggestFixForSameReference(fix, foundAssert, state, expr.getKind().equals(Kind.EQUAL_TO));
    return;
  }

  // case: "assert expr", which didn't match any of the previous cases.
  addFix(fix, (JCExpression) expr, foundAssert, state, IS_TRUE);
}
 
开发者ID:google,项目名称:error-prone,代码行数:37,代码来源:UseCorrectAssertInTests.java


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