本文整理汇总了Java中spoon.reflect.code.CtIf.setCondition方法的典型用法代码示例。如果您正苦于以下问题:Java CtIf.setCondition方法的具体用法?Java CtIf.setCondition怎么用?Java CtIf.setCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spoon.reflect.code.CtIf
的用法示例。
在下文中一共展示了CtIf.setCondition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processCondition
import spoon.reflect.code.CtIf; //导入方法依赖的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.CtIf; //导入方法依赖的package包/类
public void process(Bound annotation, CtParameter<?> element) {
final CtMethod parent = element.getParent(CtMethod.class);
// Build if check for min.
CtIf anIf = getFactory().Core().createIf();
anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " < " + annotation.min()));
CtThrow throwStmt = getFactory().Core().createThrow();
throwStmt.setThrownExpression((CtExpression<? extends Throwable>) getFactory().Core().createCodeSnippetExpression().setValue("new RuntimeException(\"out of min bound (\" + " + element.getSimpleName() + " + \" < " + annotation.min() + "\")"));
anIf.setThenStatement(throwStmt);
parent.getBody().insertBegin(anIf);
anIf.setParent(parent);
// Build if check for max.
anIf = getFactory().Core().createIf();
anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " > " + annotation.max()));
anIf.setThenStatement(getFactory().Code().createCtThrow("new RuntimeException(\"out of max bound (\" + " + element.getSimpleName() + " + \" > " + annotation.max() + "\")"));
parent.getBody().insertBegin(anIf);
anIf.setParent(parent);
}
示例3: process
import spoon.reflect.code.CtIf; //导入方法依赖的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());
}
示例4: cleanStatements
import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
private List<CtElement> cleanStatements(final @NotNull CtAbstractInvocation<?> regInvok, final @NotNull Factory fac) {
List<CtElement> stats = cmd.getAllLocalStatmtsOrdered().stream().map(stat -> stat.clone()).collect(Collectors.toList());
removeLastBreakReturn(stats);
removeActionCommandStatements();
changeNonLocalMethodInvocations(stats, regInvok);
changeNonLocalFieldAccesses(stats, regInvok);
// Removing the unused local variables of the command.
removeUnusedLocalVariables(stats);
final List<CtParameterReference<?>> guiParams = cmd.getExecutable().getParameters().stream().map(param -> param.getReference()).collect(Collectors.toList());
final CtBlock<?> mainBlock = cmd.getExecutable().getBody();
// Adding conditional statements that are not used to identify the widget
for(int i=0, size=cmd.getConditions().size(); i<size; i++) {
final CtExpression<Boolean> cond = cmd.getConditions().get(i).createBoolExp();
if(!CommandAnalyser.conditionalUsesGUIParam(cmd.getConditions().get(i).realStatmt.getParent(), guiParams, mainBlock)) {
CtIf iff = fac.Core().createIf();
CtBlock<?> block = fac.Core().createBlock();
iff.setCondition(cond.clone());
stats.stream().filter(stat -> stat instanceof CtStatement).forEach(stat -> block.insertEnd((CtStatement) stat));
iff.setThenStatement(block);
stats = Collections.singletonList(iff);
}
}
return stats;
}
示例5: getReplaceStmt
import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
protected CtIf getReplaceStmt(CtIf stmt) {
Factory factory = getInputProgram().getFactory();
CtIf clone = factory.Core().clone(stmt);
if(stmt.getElseStatement() == null) {
clone.setCondition(factory.Code().createLiteral(false));
} else {
if(containsOnlyReturn(stmt.getThenStatement())) {
clone.setCondition(factory.Code().createLiteral(false));
} else {
clone.setCondition(factory.Code().createLiteral(true));
}
}
return clone;
}
示例6: buildReplacementElement
import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
protected CtCodeElement buildReplacementElement() throws BuildTransplantException {
CtElement transplantationPoint = transformation.getTransplantationPoint().getCtCodeFragment();
CtCodeElement copyTransplant = transformation.buildReplacementElement();
Factory factory = copyTransplant.getFactory();
CtFieldReference<Boolean> fieldRef = factory.Core().createFieldReference();
fieldRef.setSimpleName("fr.inria.diversify.transformation.switchsosie.Switch.switchTransformation");
CtIf stmtIf = factory.Core().createIf();
stmtIf.setParent(transplantationPoint.getParent());
stmtIf.setCondition(factory.Code().createVariableRead(fieldRef, true));
CtBlock bodyThen = factory.Core().createBlock();
stmtIf.setThenStatement(bodyThen);
CtStatement tmp = (CtStatement) factory.Core().clone(copyTransplant);
tmp.setParent(stmtIf);
bodyThen.addStatement(tmp);
CtBlock bodyElse = factory.Core().createBlock();
stmtIf.setElseStatement(bodyElse);
tmp = (CtStatement) factory.Core().clone(transplantationPoint);
tmp.setParent(stmtIf);
bodyElse.addStatement(tmp);
return stmtIf;
}
示例7: createReturn
import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
private CtElement createReturn(CtElement rootElement) {
CtMethod method = rootElement.getParent(CtMethod.class);
if (method == null) {
log.info("Element without method parent");
return null;
}
// We create the "if(true)"{}
CtIf ifReturn = MutationSupporter.getFactory().Core().createIf();
CtExpression ifTrueExpression = MutationSupporter.getFactory().Code()
.createCodeSnippetExpression("true");
ifReturn.setCondition(ifTrueExpression);
// Now we create the return statement
CtReturn<?> returnStatement = null;
CtTypeReference typeR = method.getType();
if (typeR == null || "void".equals(typeR.getSimpleName())) {
returnStatement = MutationSupporter.getFactory().Core().createReturn();
} else {
String codeExpression = "";
if (prim.contains(typeR.getSimpleName())) {
codeExpression = getZeroValue(typeR.getSimpleName().toLowerCase());
} else if(typeR.getSimpleName().toLowerCase().equals("boolean")){
codeExpression = "false";
} else {
codeExpression = "null";
}
CtExpression returnExpression = MutationSupporter.getFactory().Code()
.createCodeSnippetExpression(codeExpression);
returnStatement = MutationSupporter.getFactory().Core().createReturn();
returnStatement.setReturnedExpression(returnExpression);
}
// Now, we associate if(true){return [...]}
ifReturn.setThenStatement(returnStatement);
return ifReturn;
}
示例8: createIf
import spoon.reflect.code.CtIf; //导入方法依赖的package包/类
/**
* Creates a new if from that one passed as parammeter. The next if has a
* condition expression expression true or false according to the variable
* <b>thenBranch</b>
*
* @param ifElement
* @param thenBranch
* @return
*/
@SuppressWarnings({ "static-access", "rawtypes", "unchecked", })
private CtIf createIf(CtIf ifElement, boolean thenBranch) {
CtIf clonedIf = MutationSupporter.getFactory().Core().clone(ifElement);
CtExpression ifExpression = MutationSupporter.getFactory().Code()
.createCodeSnippetExpression(Boolean.toString(thenBranch));
clonedIf.setCondition(ifExpression);
return clonedIf;
}