• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AssertTree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



AssertTree类属于com.sun.source.tree包,在下文中一共展示了AssertTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Void visitAssert(AssertTree node, Void unused) {
    sync(node);
    builder.open(ZERO);
    token("assert");
    builder.space();
    builder.open(node.getDetail() == null ? ZERO : plusFour);
    scan(node.getCondition(), null);
    if (node.getDetail() != null) {
        builder.breakOp(" ");
        token(":");
        builder.space();
        scan(node.getDetail(), null);
    }
    builder.close();
    builder.close();
    token(";");
    return null;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:JavaInputAstVisitor.java


示例5: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public TreePath visitAssert(AssertTree node, Context context) {
	JavacExpressionRecorder expressionRecorder = new JavacExpressionRecorder();

	JCTree.JCAssert assertStatement = (JCTree.JCAssert) node;
	JCTree.JCExpression assertCondition = assertStatement.getCondition();

	JCTree.JCExpressionStatement instrumented = treeMaker.Exec(
			treeMaker.Apply(
					List.<JCTree.JCExpression>nil(),
					qualifiedName(RECORDER_RUNTIME, "powerAssert"),
					List.of(
							treeMaker.Literal(source(assertCondition)),
							expressionRecorder.record(assertCondition),
							treeMaker.Literal(assertCondition.getStartPosition())
					)
			)
	);

	// so that we don't disrupt IDE debugging, give the instrumented expression the same position as the original
	instrumented.setPos(assertCondition.pos);

	return replaceWithInstrumented(assertStatement, instrumented);
}
 
开发者ID:jkschneider,项目名称:java-power-assert,代码行数:25,代码来源:JavacPowerAssertGenerator.java


示例6: matchMethod

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Description matchMethod(MethodTree methodTree, VisitorState state) {
  if (methodTree.getBody() == null) {
    // Method is not implemented (i.e. it's abstract).
    return Description.NO_MATCH;
  }

  if (ASTHelpers.isJUnitTestCode(state)
      && JUnitMatchers.wouldRunInJUnit4.matches(methodTree, state)
      && CONTAINS_ASSERT.matches(methodTree.getBody(), state)) {

    SuggestedFix.Builder fix = SuggestedFix.builder();

    for (AssertTree foundAssert : scanAsserts(methodTree)) {
      replaceAssert(fix, foundAssert, state);
    }

    return buildDescription(methodTree).addFix(fix.build()).build();
  }
  return Description.NO_MATCH;
}
 
开发者ID:google,项目名称:error-prone,代码行数:22,代码来源:UseCorrectAssertInTests.java


示例7: addFix

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
private static void addFix(
    SuggestedFix.Builder fix,
    JCExpression expr,
    AssertTree foundAssert,
    VisitorState state,
    String isMethod) {

  String assertToUse;

  if (foundAssert.getDetail() == null) {
    fix.addImport(STATIC_ASSERT_THAT_IMPORT);
    assertToUse = String.format(ASSERT_THAT, normalizedSourceForExpression(expr, state));
  } else {
    fix.addImport(STATIC_ASSERT_WITH_MESSAGE_IMPORT);
    assertToUse =
        String.format(
            ASSERT_WITH_MESSAGE,
            convertToString(foundAssert.getDetail(), state),
            normalizedSourceForExpression(expr, state));
  }

  fix.replace(foundAssert, assertToUse + isMethod);
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:UseCorrectAssertInTests.java


示例8: suggestFixForSameReference

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
/** Handles the case "expr1 == expr2" */
private static void suggestFixForSameReference(
    SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state, boolean isEqual) {

  BinaryTree equalityTree = (BinaryTree) TreeInfo.skipParens((JCTree) foundAssert.getCondition());
  ExpressionTree expr1 = equalityTree.getLeftOperand();
  ExpressionTree expr2 = equalityTree.getRightOperand();

  if (expr1.getKind() == NULL_LITERAL) {
    // case: "assert null [op] expr"
    addFix(fix, (JCExpression) expr2, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL);
  } else if (expr2.getKind() == NULL_LITERAL) {
    // case: "assert expr [op] null"
    addFix(fix, (JCExpression) expr1, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL);
  } else {
    // case: "assert expr1 [op] expr2"
    addFix(
        fix,
        (JCExpression) expr1,
        foundAssert,
        state,
        String.format(isEqual ? IS_SAME_AS : IS_NOT_SAME_AS, expr2));
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:25,代码来源:UseCorrectAssertInTests.java


示例9: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Tree visitAssert(AssertTree tree, Void p) {
    AssertTree n = make.Assert(tree.getCondition(), tree.getDetail());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:TreeDuplicator.java


示例10: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
public Boolean visitAssert(AssertTree node, TreePath p) {
    if (p == null) {
        super.visitAssert(node, p);
        return false;
    }

    AssertTree at = (AssertTree) p.getLeaf();

    if (!scan(node.getCondition(), at.getCondition(), p)) {
        return false;
    }

    return scan(node.getDetail(), at.getDetail(), p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:CopyFinder.java


示例11: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Void visitAssert(AssertTree tree, EnumSet<UseTypes> p) {
    if (tree.getCondition().getKind() == Kind.IDENTIFIER)
        handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getCondition()), EnumSet.of(UseTypes.READ));
    if (tree.getDetail() != null && tree.getDetail().getKind() == Kind.IDENTIFIER)
        handlePossibleIdentifier(new TreePath(getCurrentPath(), tree.getDetail()), EnumSet.of(UseTypes.READ));
    
    return super.visitAssert(tree, EnumSet.of(UseTypes.READ));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:SemanticHighlighterBase.java


示例12: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Object visitAssert(AssertTree node, Object p) {
    int saveCount = negationsCount;
    Object o = super.visitAssert(node, p);
    if (ignoreAsserts) {
        this.negationsCount = saveCount;
    }
    return o;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:MethodMetrics.java


示例13: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Void visitAssert(AssertTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();
    
    addCorrespondingType(below);
    addCorrespondingComments(below);
    super.visitAssert(tree, below);
    
    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeNode.java


示例14: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public List<? extends TypeMirror> visitAssert(AssertTree node, Object p) {
    if (theExpression == null) {
        initExpression(node.getCondition());
    }
    return booleanType();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ExpectedTypeResolver.java


示例15: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public List<Tree> visitAssert(AssertTree node, ExpressionScanner.ExpressionsInfo p) {
    if (acceptsTree(node)) {
        List<Tree> result = scan(node.getCondition(), p);
        result = reduce(result, scan(node.getDetail(), p));
        return result;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ExpressionScanner.java


示例16: matches

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public boolean matches(StatementTree statementTree, VisitorState state) {
  if (!(statementTree instanceof AssertTree)) {
    return false;
  }

  return expressionMatcher.matches(((AssertTree) statementTree).getCondition(), state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:9,代码来源:Asserts.java


示例17: assertionWithCondition

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
/**
 * Matches an assertion AST node if the given matcher matches its condition.
 *
 * @param conditionMatcher The matcher to apply to the condition in the assertion, e.g. in "assert
 *     false", the "false" part of the statement
 */
public static Matcher<AssertTree> assertionWithCondition(
    final Matcher<ExpressionTree> conditionMatcher) {
  return new Matcher<AssertTree>() {
    @Override
    public boolean matches(AssertTree tree, VisitorState state) {
      return conditionMatcher.matches(tree.getCondition(), state);
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:16,代码来源:Matchers.java


示例18: visitAssert

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
@Override
public Void visitAssert(AssertTree tree, VisitorState visitorState) {
  VisitorState state = visitorState.withPath(getCurrentPath());
  for (AssertTreeMatcher matcher : assertMatchers) {
    if (!isSuppressed(matcher, state)) {
      try {
        reportMatch(matcher.matchAssert(tree, state), tree, state);
      } catch (Throwable t) {
        handleError(matcher, t);
      }
    }
  }
  return super.visitAssert(tree, state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:ErrorProneScanner.java


示例19: 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


示例20: scanAsserts

import com.sun.source.tree.AssertTree; //导入依赖的package包/类
/** Returns all the "assert" expressions in the tree. */
private static ImmutableList<AssertTree> scanAsserts(Tree tree) {
  ImmutableList.Builder<AssertTree> assertTrees = ImmutableList.builder();

  tree.accept(
      new TreeScanner<Void, VisitorState>() {
        @Override
        public Void visitAssert(AssertTree assertTree, VisitorState visitorState) {
          assertTrees.add(assertTree);
          return null;
        }
      },
      null);
  return assertTrees.build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:16,代码来源:UseCorrectAssertInTests.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RefactoringWizardOpenOperation类代码示例发布时间:2022-05-22
下一篇:
Java ThreadPoolManager类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap