本文整理汇总了Java中com.sun.source.tree.AssertTree类的典型用法代码示例。如果您正苦于以下问题:Java AssertTree类的具体用法?Java AssertTree怎么用?Java AssertTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssertTree类属于com.sun.source.tree包,在下文中一共展示了AssertTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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));
}
}
示例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;
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
}