本文整理汇总了Java中spoon.reflect.code.CtDo类的典型用法代码示例。如果您正苦于以下问题:Java CtDo类的具体用法?Java CtDo怎么用?Java CtDo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CtDo类属于spoon.reflect.code包,在下文中一共展示了CtDo类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import spoon.reflect.code.CtDo; //导入依赖的package包/类
/**
* Build a control flow graph from a do-while statement
*/
private SubGraph process(CtDo doWhileLoop) {
// Get data
CtExpression<Boolean> condition = doWhileLoop.getLoopingExpression();
CtUnaryOperator<Boolean> negCondition = factory.Core().createUnaryOperator();
negCondition.setOperand(condition);
negCondition.setKind(UnaryOperatorKind.NOT);
// negCondition.setParent(condition);
CtStatement body = doWhileLoop.getBody();
// Build the sub-graph
SubGraph loopBody = process(body);
ConditionalSolution continueSolutions = Solver.solve(condition.toString());
ConditionalSolution breakSolutions = Solver.solve("!(" + condition.toString() + ")");
SubGraph res = new SubGraph(cfg);
res.getEntry().addChild(loopBody.getEntry(), null);
loopBody.getExit().addChild(loopBody.getEntry(), condition);
loopBody.getExit().addChild(res.getExit(), negCondition);
return res;
}
示例2: process
import spoon.reflect.code.CtDo; //导入依赖的package包/类
@Override
public void process(CtStatement element) {
if (element instanceof CtIf) {
add(((CtIf) element).getCondition());
} else if (element instanceof CtFor) {
add(((CtFor) element).getExpression());
} else if (element instanceof CtWhile) {
add(((CtWhile) element).getLoopingExpression());
} else if (element instanceof CtDo) {
add(((CtDo) element).getLoopingExpression());
} else if (element instanceof CtThrow) {
add(((CtThrow) element).getThrownExpression());
} else if (element instanceof CtInvocation && (element.getParent() instanceof CtBlock)) {
add(element);
} else if (element instanceof CtAssignment || element instanceof CtConstructorCall
|| element instanceof CtCFlowBreak || element instanceof CtLocalVariable) {
add(element);
}
}
示例3: isCondStatement
import spoon.reflect.code.CtDo; //导入依赖的package包/类
public boolean isCondStatement(CtCodeElement stmt) {
if (stmt instanceof CtIf || stmt instanceof CtConditional || stmt instanceof CtDo || stmt instanceof CtForEach
|| stmt instanceof CtFor || stmt instanceof CtSwitch || stmt instanceof CtWhile) {
return true;
}
return false;
}
示例4: isConditionalStatement
import spoon.reflect.code.CtDo; //导入依赖的package包/类
public boolean isConditionalStatement(CtCodeElement stmt) {// Refactor and
// change the
// name: bad
// name
if (stmt instanceof CtIf || stmt instanceof CtConditional || stmt instanceof CtDo || stmt instanceof CtForEach
|| stmt instanceof CtFor || stmt instanceof CtSwitch || stmt instanceof CtTry
|| stmt instanceof CtWhile || stmt instanceof CtBlock) {
return true;
}
return false;
}
示例5: gatherContainingCondition
import spoon.reflect.code.CtDo; //导入依赖的package包/类
/**
* Get expression from the containment hierarchy of the action
* (while,for,switch,conditional)
*/
private List<CtExpression<?>> gatherContainingCondition(CtCodeElement action, CtMethod<?> method) {
List<CtExpression<?>> res = new ArrayList<>();
CtElement parent = action;
try {
parent = action.getParent();
while (parent != null && parent != method) {
if (parent instanceof CtIf) { // TODO: get the negation too
CtIf if_ = (CtIf) parent;
res.add(if_.getCondition());
} else if (parent instanceof CtWhile) {
CtWhile while_ = (CtWhile) parent;
res.add(while_.getLoopingExpression());
} else if (parent instanceof CtFor) {
CtFor for_ = (CtFor) parent;
res.add(for_.getExpression());
} else if (parent instanceof CtCase) {
CtCase<?> case_ = (CtCase<?>) parent;
res.add(case_.getCaseExpression());
} else if (parent instanceof CtConditional) {// TODO: get the
// negation too
CtConditional<?> cond = (CtConditional<?>) parent;
res.add(cond.getCondition());
} else if (parent instanceof CtDo) {
CtDo do_ = (CtDo) parent;
res.add(do_.getLoopingExpression());
}
parent = parent.getParent();
}
} catch (ParentNotInitializedException e) {
System.out.println("Parent init exeption: " + parent);
}
return res;
}
示例6: getSuperConditionalExpressions
import spoon.reflect.code.CtDo; //导入依赖的package包/类
/**
* @param elt The element from which the research starts.
* @return All the conditional expressions from the given element 'elt' up to the given top parent.
*/
public @NotNull List<CtElement> getSuperConditionalExpressions(final @NotNull CtElement elt) {
CtElement parent = elt.isParentInitialized() ? elt.getParent() : null;
List<CtElement> conds = new ArrayList<>();
// Exploring the parents to identify the conditional statements
while(parent != null) {
if(parent instanceof CtIf) {
conds.add(((CtIf) parent).getCondition());
}else {
if(parent instanceof CtCase<?>) {
conds.add(((CtCase<?>) parent).getCaseExpression());
CtSwitch<?> switzh = parent.getParent(CtSwitch.class);
if(switzh == null) System.err.println("Cannot find the switch statement from the case statement: " + parent);
else conds.add(switzh.getSelector());
}else {
if(parent instanceof CtWhile) {
conds.add(((CtWhile) parent).getLoopingExpression());
}else {
if(parent instanceof CtDo) {
conds.add(((CtDo) parent).getLoopingExpression());
}else {
if(parent instanceof CtFor) {
conds.add(((CtFor) parent).getExpression());
}
}
}
}
}
parent = parent.isParentInitialized() ? parent.getParent() : null;
}
return conds;
}
示例7: process
import spoon.reflect.code.CtDo; //导入依赖的package包/类
@Override
public void process(CtLoop element) {
if(element instanceof CtFor){
addExpressionAndSubexpressions(((CtFor)element).getExpression());
}
if(element instanceof CtWhile){
addExpressionAndSubexpressions(((CtWhile)element).getLoopingExpression());
}
if(element instanceof CtDo){
addExpressionAndSubexpressions(((CtDo)element).getLoopingExpression());
}
}
示例8: exploreConditionals
import spoon.reflect.code.CtDo; //导入依赖的package包/类
public List<CtExpression<?>> exploreConditionals(CtCodeElement action, CtCodeElement parent) {
CtUnaryOperator<Boolean> negCondition = factory.Core().createUnaryOperator();
List<CtExpression<?>> res = new ArrayList<>();
if (parent instanceof CtIf) {
CtIf ctif = (CtIf) parent;
CtStatement thenpart = ctif.getThenStatement();
if (isContainedBy(action, thenpart)) {
res.add(ctif.getCondition());
return res;
}
List<CtExpression<?>> childCond = exploreConditionals(action, thenpart);
if (!childCond.isEmpty()) {
res.add(ctif.getCondition());
res.addAll(exploreConditionals(action, thenpart));
}
CtStatement elsepart = ctif.getElseStatement();
if (isContainedBy(action, elsepart)) {
negCondition.setOperand(ctif.getCondition());
negCondition.setKind(UnaryOperatorKind.NOT);
res.add(negCondition);
return res;
}
childCond = exploreConditionals(action, elsepart);
if (!childCond.isEmpty()) {
res.add(ctif.getCondition());
res.addAll(exploreConditionals(action, elsepart));
}
} else if (parent instanceof CtWhile) {
CtWhile while_ = (CtWhile) parent;
res.add(while_.getLoopingExpression());
} else if (parent instanceof CtFor) {
CtFor for_ = (CtFor) parent;
res.add(for_.getExpression());
} else if (parent instanceof CtCase) {
CtCase<?> case_ = (CtCase<?>) parent;
res.add(case_.getCaseExpression());
} else if (parent instanceof CtConditional) {// TODO: get the negation
// too
CtConditional<?> cond = (CtConditional<?>) parent;
res.add(cond.getCondition());
} else if (parent instanceof CtDo) {
CtDo do_ = (CtDo) parent;
res.add(do_.getLoopingExpression());
} else if (parent instanceof CtSwitch) {
CtSwitch<?> switch_ = (CtSwitch<?>) parent;
res.add(switch_.getSelector());
}
return res;
}
示例9: getSurroundedBlock
import spoon.reflect.code.CtDo; //导入依赖的package包/类
private List<CtCodeElement> getSurroundedBlock(Action cmd, CtExpression<?> cond) {
List<CtCodeElement> res = new ArrayList<>();
CtUnaryOperator<Boolean> negation = factory.Core().createUnaryOperator();
List<CtCodeElement> stmts = cmd.getStatements();
CtCodeElement stmt1 = stmts.get(0);
CtElement parent = stmt1;
if (stmt1 != null) {
try {
parent = stmt1.getParent();
while (parent != null && parent != cmd.getSource()) {
if (parent instanceof CtIf) {
CtIf if_ = (CtIf) parent;
negation.setOperand(if_.getCondition());
negation.setKind(UnaryOperatorKind.NOT);
if (if_.getCondition() == cond) {
CtStatement thenPart = if_.getThenStatement();
res.add(thenPart);
return res;
} else if (negation.toString().equals(cond.toString())) {// Handle
// the
// else
// part
// as
// a
// command
CtStatement elsePart = if_.getElseStatement();
res.add(elsePart);
return res;
}
} else if (parent instanceof CtWhile) {
CtWhile while_ = (CtWhile) parent;
if (while_.getLoopingExpression() == cond) {
res.add(while_.getBody());
return res;
}
} else if (parent instanceof CtFor) {
CtFor for_ = (CtFor) parent;
if (for_.getExpression() == cond) {
res.add(for_.getBody());
return res;
}
} else if (parent instanceof CtCase) {
CtCase<?> case_ = (CtCase<?>) parent;
if (case_.getCaseExpression() == cond) {
res.addAll(case_.getStatements());
return res;
}
} else if (parent instanceof CtConditional) {
CtConditional<?> conditional = (CtConditional<?>) parent;
if (conditional.getCondition() == cond) {
res.add(conditional.getThenExpression());
return res;
}
} else if (parent instanceof CtDo) {
CtDo do_ = (CtDo) parent;
if (do_.getLoopingExpression() == cond) {
res.add(do_.getBody());
return res;
}
} else if (parent instanceof CtSwitch) {
CtSwitch<?> switch_ = (CtSwitch<?>) parent;
if (switch_.getSelector() == cond) {
res.addAll(switch_.getCases());
return res;
}
}
parent = parent.getParent();
}
} catch (ParentNotInitializedException e) {
System.out.println("Parent init exeption: " + parent);
}
}
return null;
}