Java源码示例:com.sun.source.tree.DoWhileLoopTree
示例1
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
sync(node);
token("do");
visitStatement(
node.getStatement(),
CollapseEmptyOrNot.YES,
AllowLeadingBlankLine.YES,
AllowTrailingBlankLine.YES);
if (node.getStatement().getKind() == BLOCK) {
builder.space();
} else {
builder.breakOp(" ");
}
token("while");
builder.space();
token("(");
scan(skipParen(node.getCondition()), null);
token(")");
token(";");
return null;
}
示例2
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void p) {
super.visitDoWhileLoop(node, p);
if (isMethodCode() && phase == PHASE_AFTER_SELECTION) {
//#109663𛞨:
//the selection was inside the do-while, the variables inside the
//statement part of the do-while loop need to be considered to be used again after the loop:
if (!secondPass) {
secondPass = true;
scan(node.getStatement(), p);
secondPass = false;
stopSecondPass = false;
}
}
return null;
}
示例3
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
sync(node);
token("do");
visitStatement(
node.getStatement(),
CollapseEmptyOrNot.YES,
AllowLeadingBlankLine.YES,
AllowTrailingBlankLine.YES);
if (node.getStatement().getKind() == BLOCK) {
builder.space();
} else {
builder.breakOp(" ");
}
token("while");
builder.space();
token("(");
scan(skipParen(node.getCondition()), null);
token(")");
token(";");
return null;
}
示例4
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Void unused) {
sync(node);
token("do");
visitStatement(
node.getStatement(),
CollapseEmptyOrNot.YES,
AllowLeadingBlankLine.YES,
AllowTrailingBlankLine.YES);
if (node.getStatement().getKind() == BLOCK) {
builder.space();
} else {
builder.breakOp(" ");
}
token("while");
builder.space();
token("(");
scan(skipParen(node.getCondition()), null);
token(")");
token(";");
return null;
}
示例5
@Override
public Tree visitDoWhileLoop(DoWhileLoopTree tree, Void p) {
DoWhileLoopTree n = make.DoWhileLoop(tree.getCondition(), tree.getStatement());
model.setType(n, model.getType(tree));
comments.copyComments(tree, n);
model.setPos(n, model.getPos(tree));
return n;
}
示例6
public Boolean visitDoWhileLoop(DoWhileLoopTree node, TreePath p) {
if (p == null) {
super.visitDoWhileLoop(node, p);
return false;
}
DoWhileLoopTree t = (DoWhileLoopTree) p.getLeaf();
if (!scan(node.getStatement(), t.getStatement(), p))
return false;
return scan(node.getCondition(), t.getCondition(), p);
}
示例7
/**
* Do-while loop adds:
* - no vertex, as it is a member of the linear code.
* - an additional vertex for the code after the while
* - one edge for unsatisfied condition that skips the cycle
* - one edge for satisfied condition which at least re-evaluates the condition
* - an additional vertex and an edge if the body contains a non-empty statement
* = +1 to complexity
*/
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
boolean saveFlag = switchCase;
switchCase = false;
complexity++;
Object o = super.visitDoWhileLoop(node, p);
this.switchCase = saveFlag;
return o;
}
示例8
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
depth++;
Object o = super.visitDoWhileLoop(node, p);
depth--;
return o;
}
示例9
@Override
public Void visitDoWhileLoop(DoWhileLoopTree tree, List<Node> d) {
List<Node> below = new ArrayList<Node>();
addCorrespondingType(below);
addCorrespondingComments(below);
super.visitDoWhileLoop(tree, below);
d.add(new TreeNode(info, getCurrentPath(), below));
return null;
}
示例10
@Override
public State visitDoWhileLoop(DoWhileLoopTree node, Void p) {
State s;
registerBreakTarget((node));
if (returnIfRecurse(s = scan(node.getStatement(), p))) {
return s;
}
returnIfRecurse(s = s.append(scan(node.getCondition(), p)));
return s;
}
示例11
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, ConstructorData p) {
Map< Element, State> beforeLoop = variable2State;
variable2State = new HashMap< Element, Flow.State>(beforeLoop);
scan(node.getStatement(), null);
Boolean condValue = scan(node.getCondition(), null);
if (condValue != null) {
if (condValue) {
//XXX: handle possibly infinite loop
} else {
//will not run more than once, skip:
return null;
}
}
variable2State = mergeOr(beforeLoop, variable2State);
if (!doNotRecord) {
boolean oldDoNotRecord = doNotRecord;
doNotRecord = true;
beforeLoop = new HashMap< Element, State>(variable2State);
scan(node.getStatement(), null);
scan(node.getCondition(), null);
doNotRecord = oldDoNotRecord;
variable2State = mergeOr(beforeLoop, variable2State);
// variable2State = beforeLoop;
}
return null;
}
示例12
@Override
public List<? extends TypeMirror> visitDoWhileLoop(DoWhileLoopTree node, Object p) {
if (theExpression == null) {
initExpression(node.getCondition());
} else if (theExpression.getLeaf() != node.getCondition()) {
return null;
}
return booleanType();
}
示例13
@Override
public List<Tree> visitDoWhileLoop(DoWhileLoopTree node, ExpressionScanner.ExpressionsInfo p) {
List<Tree> statements = scan(node.getStatement(), p);
List<Tree> cond = null;
if (acceptsTree(node.getCondition())) {
cond = scan(node.getCondition(), p);
}
if (cond != null && cond.size() > 0 && statements != null && statements.size() > 0) {
Tree lastCond = cond.get(cond.size() - 1);
p.addNextExpression(lastCond, statements.get(0));
}
return reduce(statements, cond);
}
示例14
private boolean testBlock(StringWriter writer, SourcePositions sp, String text, CompilationUnitTree cut, BlockTree blockTree) {
boolean success = true;
for (StatementTree st : blockTree.getStatements()) {
if (isLegal(st)) {
success &= testStatement(writer, sp, text, cut, st);
}
if (st instanceof IfTree) {
IfTree ifTree = (IfTree) st;
success &= testBranch(writer, sp, text, cut, ifTree.getThenStatement());
success &= testBranch(writer, sp, text, cut, ifTree.getElseStatement());
} else if (st instanceof WhileLoopTree) {
WhileLoopTree whileLoopTree = (WhileLoopTree) st;
success &= testBranch(writer, sp, text, cut, whileLoopTree.getStatement());
} else if (st instanceof DoWhileLoopTree) {
DoWhileLoopTree doWhileLoopTree = (DoWhileLoopTree) st;
success &= testBranch(writer, sp, text, cut, doWhileLoopTree.getStatement());
} else if (st instanceof ForLoopTree) {
ForLoopTree forLoopTree = (ForLoopTree) st;
success &= testBranch(writer, sp, text, cut, forLoopTree.getStatement());
} else if (st instanceof LabeledStatementTree) {
LabeledStatementTree labelTree = (LabeledStatementTree) st;
success &= testBranch(writer, sp, text, cut, labelTree.getStatement());
} else if (st instanceof SwitchTree) {
SwitchTree switchTree = (SwitchTree) st;
for (CaseTree caseTree : switchTree.getCases()) {
for (StatementTree statementTree : caseTree.getStatements()) {
success &= testBranch(writer, sp, text, cut, statementTree);
}
}
}
}
return success;
}
示例15
@Override
public Void visitDoWhileLoop(DoWhileLoopTree expected, Tree actual) {
Optional<DoWhileLoopTree> other = checkTypeAndCast(expected, actual);
if (!other.isPresent()) {
addTypeMismatch(expected, actual);
return null;
}
scan(expected.getCondition(), other.get().getCondition());
scan(expected.getStatement(), other.get().getStatement());
return null;
}
示例16
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, Element p) {
return null;
}
示例17
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
loopCount++;
return super.visitDoWhileLoop(node, p);
}
示例18
@Override
public Object visitDoWhileLoop(DoWhileLoopTree node, Object p) {
statements++;
return super.visitDoWhileLoop(node, p);
}
示例19
@Hint(displayName="#LBL_Braces_DoWhile", description="#DSC_Braces_DoWhile", category="braces", id=BRACES_ID + "DO_WHILE_LOOP", enabled=false, suppressWarnings={"", "ControlFlowStatementWithoutBraces"})
@TriggerTreeKind(Tree.Kind.DO_WHILE_LOOP)
public static ErrorDescription checkDoWhile(HintContext ctx) {
DoWhileLoopTree dwlt = (DoWhileLoopTree) ctx.getPath().getLeaf();
return checkStatement(ctx, "LBL_Braces_DoWhile", dwlt.getStatement(), ctx.getPath());
}
示例20
@Override
protected void performRewrite(TransformationContext ctx) {
WorkingCopy copy = ctx.getWorkingCopy();
TreePath path = ctx.getPath();
if ( path != null ) {
TreeMaker make = copy.getTreeMaker();
Tree oldTree = path.getLeaf();
oldTree = GeneratorUtilities.get(copy).importComments(oldTree, copy.getCompilationUnit());
switch( oldTree.getKind() ) {
case FOR_LOOP:
ForLoopTree oldFor = (ForLoopTree)oldTree;
StatementTree oldBlock = oldFor.getStatement();
BlockTree newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
copy.rewrite(oldBlock, newBlock);
break;
case ENHANCED_FOR_LOOP:
EnhancedForLoopTree oldEnhancedFor = (EnhancedForLoopTree)oldTree;
oldBlock = oldEnhancedFor.getStatement();
newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
copy.rewrite(oldBlock, newBlock);
break;
case WHILE_LOOP:
WhileLoopTree oldWhile = (WhileLoopTree)oldTree;
oldBlock = oldWhile.getStatement();
newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
copy.rewrite(oldBlock, newBlock);
break;
case DO_WHILE_LOOP:
DoWhileLoopTree oldDoWhile = (DoWhileLoopTree)oldTree;
oldBlock = oldDoWhile.getStatement();
newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
copy.rewrite(oldBlock, newBlock);
break;
case IF:
IfTree oldIf = (IfTree)oldTree;
if ( fixThen ) {
oldBlock = oldIf.getThenStatement();
newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
copy.rewrite(oldBlock, newBlock);
}
if ( fixElse ) {
oldBlock = oldIf.getElseStatement();
newBlock = make.Block(Collections.<StatementTree>singletonList(oldBlock), false);
copy.rewrite(oldBlock, newBlock);
}
}
}
}
示例21
public Boolean visitContinue(ContinueTree node, ConstructorData p) {
StatementTree loop = info.getTreeUtilities().getBreakContinueTarget(getCurrentPath());
if (loop == null) {
super.visitContinue(node, p);
return null;
}
Tree resumePoint;
if (loop.getKind() == Kind.LABELED_STATEMENT) {
loop = ((LabeledStatementTree) loop).getStatement();
}
switch (loop.getKind()) {
case WHILE_LOOP:
resumePoint = ((WhileLoopTree) loop).getCondition();
break;
case FOR_LOOP: {
ForLoopTree flt = (ForLoopTree)loop;
resumePoint = null;
if (flt.getUpdate() != null && !flt.getUpdate().isEmpty()) {
// resume will react on the 1st Tree of the update statement (always processed left to right)
resumePoint = flt.getUpdate().get(0);
}
if (resumePoint == null) {
resumePoint = flt.getCondition();
}
if (resumePoint == null) {
resumePoint = flt.getStatement();
}
}
break;
case DO_WHILE_LOOP:
resumePoint = ((DoWhileLoopTree) loop).getCondition();
break;
case ENHANCED_FOR_LOOP:
resumePoint = ((EnhancedForLoopTree) loop).getStatement();
break;
default:
resumePoint = null;
break;
}
if (resumePoint != null) {
recordResume(resumeBefore, resumePoint, variable2State);
}
variable2State = new HashMap< Element, State>();
super.visitContinue(node, p);
return null;
}
示例22
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, Void p) {
return scan(node.getStatement(), p);
}
示例23
@Override
public Boolean visitDoWhileLoop(DoWhileLoopTree node, EvaluationContext p) {
return Boolean.FALSE;
}
示例24
private TreeNode convertDoStatement(DoWhileLoopTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
return new DoStatement()
.setExpression(convertWithoutParens(node.getCondition(), path))
.setBody((Statement) convert(node.getStatement(), path));
}
示例25
void beforeVisitStatement(DoWhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol,
Closure<Void> setError);
示例26
void afterVisitStatementAndBeforeCondition(DoWhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx,
Closure<List<Map<String, Long>>> resolveRowAndCol, Closure<Void> setError);
示例27
void afterVisitCondition(DoWhileLoopTree node, List<ErrMsg> errMsgs, GlobalContext globalCtx, Closure<List<Map<String, Long>>> resolveRowAndCol,
Closure<Void> setError);
示例28
@Override
public UDoWhileLoop visitDoWhileLoop(DoWhileLoopTree tree, Void v) {
return UDoWhileLoop.create(template(tree.getStatement()), template(tree.getCondition()));
}
示例29
@Override
public Void visitDoWhileLoop(DoWhileLoopTree node, Context context) {
scan(node.getStatement(), context);
scan(SKIP_PARENS.visit(node.getCondition(), null), context);
return null;
}
示例30
@Override
@Nullable
public Unifier visitDoWhileLoop(DoWhileLoopTree loop, @Nullable Unifier unifier) {
unifier = getStatement().unify(loop.getStatement(), unifier);
return getCondition().unify(loop.getCondition(), unifier);
}