本文整理汇总了Java中spoon.reflect.code.CtStatement.replace方法的典型用法代码示例。如果您正苦于以下问题:Java CtStatement.replace方法的具体用法?Java CtStatement.replace怎么用?Java CtStatement.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spoon.reflect.code.CtStatement
的用法示例。
在下文中一共展示了CtStatement.replace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCondition
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
@Override
public CtIf processCondition(CtStatement element, String newCondition) {
//logger.debug("##### {} ##### Before:\n{}", element, element.getParent());
// if the element is not a line
if (!new LineFilter().matches(element)) {
element = element.getParent(new LineFilter());
}
CtElement parent = element.getParent();
CtIf newIf = element.getFactory().Core().createIf();
CtCodeSnippetExpression<Boolean> condition = element.getFactory().Core().createCodeSnippetExpression();
condition.setValue(newCondition);
newIf.setCondition(condition);
// Fix : warning: ignoring inconsistent parent for [CtElem1] ( [CtElem2] != [CtElem3] )
newIf.setParent(parent);
element.replace(newIf);
// this should be after the replace to avoid an StackOverflowException caused by the circular reference.
newIf.setThenStatement(element);
//logger.debug("##### {} ##### After:\n{}", element, element.getParent().getParent());
return newIf;
}
示例2: process
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
public void process(CtStatement element) {
logger.debug("##### {} ##### Before:\n{}", element, element.getParent());
CtElement parent = element.getParent();
CtIf newIf = element.getFactory().Core().createIf();
CtCodeSnippetExpression<Boolean> condition;
if (getValue() != null) {
switch (getValue()) {
case "1":
condition = element.getFactory().Code()
.createCodeSnippetExpression("true");
break;
case "0":
condition = element.getFactory().Code()
.createCodeSnippetExpression("false");
break;
default:
condition = element.getFactory().Code()
.createCodeSnippetExpression(getValue());
}
} else {
condition = element
.getFactory()
.Code()
.createCodeSnippetExpression(
Debug.class.getCanonicalName()
+ ".makeSymbolicBoolean(\"guess_fix\")");
}
newIf.setCondition(condition);
// Fix : warning: ignoring inconsistent parent for [CtElem1] ( [CtElem2] != [CtElem3] )
newIf.setParent(parent);
element.replace(newIf);
// this should be after the replace to avoid an StackOverflowException caused by the circular reference.
newIf.setThenStatement(element);
// Fix : warning: ignoring inconsistent parent for [CtElem1] ( [CtElem2] != [CtElem3] )
newIf.getThenStatement().setParent(newIf);
logger.debug("##### {} ##### After:\n{}", element, element.getParent().getParent());
}