本文整理汇总了Java中spoon.reflect.code.CtIf类的典型用法代码示例。如果您正苦于以下问题:Java CtIf类的具体用法?Java CtIf怎么用?Java CtIf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtIf类属于spoon.reflect.code包,在下文中一共展示了CtIf类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getTarget
import spoon.reflect.code.CtIf; //导入依赖的package包/类
private CtElement getTarget() {
CtType type = factory.Type().get(patch.getSourceLocation().getRootClassName());
EarlyTerminatingScanner<CtElement> targetFinder = new EarlyTerminatingScanner<CtElement>() {
@Override
protected void enter(CtElement e) {
if (e.getPosition().getSourceStart() == patch.getSourceLocation().getBeginSource()
&& e.getPosition().getSourceEnd() == patch.getSourceLocation().getEndSource() && e.isImplicit() == false) {
if (patch.getType() == StatementType.CONDITIONAL && e instanceof CtIf) {
setResult(((CtIf) e).getCondition());
} else {
setResult(e);
}
terminate();
return;
}
if (e.getPosition().getSourceStart() <= patch.getSourceLocation().getBeginSource()
&& e.getPosition().getSourceEnd() >= patch.getSourceLocation().getEndSource()) {
super.enter(e);
}
}
};
type.accept(targetFinder);
return targetFinder.getResult();
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:25,代码来源:PatchGenerator.java
示例2: isElseIf
import spoon.reflect.code.CtIf; //导入依赖的package包/类
private boolean isElseIf(CtStatement original, CtStatement parentLine) {
if (parentLine.getParent() instanceof CtIf) {
CtStatement elseStatement = ((CtIf) parentLine.getParent()).getElseStatement();
if (elseStatement == original) {
return true;
} else if (elseStatement instanceof CtBlock) {
CtBlock block = (CtBlock) elseStatement;
if (block.isImplicit() && block.getStatement(0) == original) {
return true;
}
}
}
if (parentLine.getParent() instanceof CtBlock) {
return isElseIf(original, (CtStatement) parentLine.getParent());
}
return false;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:PatchGenerator.java
示例3: 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;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:21,代码来源:ConditionalAdder.java
示例4: 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);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:20,代码来源:BoundProcessor.java
示例5: testBoundTemplate
import spoon.reflect.code.CtIf; //导入依赖的package包/类
@Test
public void testBoundTemplate() throws Exception {
SpoonAPI launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.addInputResource("./src/main/java");
launcher.setSourceOutputDirectory("./target/spoon-template");
launcher.addProcessor(new BoundTemplateProcessor());
launcher.run();
final CtType<Main> target = launcher.getFactory().Type().get(Main.class);
final CtMethod<?> m = target.getMethodsByName("m").get(0);
assertTrue(m.getBody().getStatements().size() >= 2);
assertTrue(m.getBody().getStatement(0) instanceof CtIf);
assertTrue(m.getBody().getStatement(1) instanceof CtIf);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:17,代码来源:BoundTest.java
示例6: testBoundProcessor
import spoon.reflect.code.CtIf; //导入依赖的package包/类
@Test
public void testBoundProcessor() throws Exception {
SpoonAPI launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.addInputResource("./src/main/java");
launcher.setSourceOutputDirectory("./target/spoon-processor");
launcher.addProcessor(new BoundProcessor());
launcher.run();
final CtType<Main> target = launcher.getFactory().Type().get(Main.class);
final CtMethod<?> m = target.getMethodsByName("m").get(0);
assertTrue(m.getBody().getStatements().size() >= 2);
assertTrue(m.getBody().getStatement(0) instanceof CtIf);
assertTrue(m.getBody().getStatement(1) instanceof CtIf);
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:17,代码来源:BoundTest.java
示例7: getStatementParentNotCtrlFlow
import spoon.reflect.code.CtIf; //导入依赖的package包/类
/**
* Returns the first parent statement or the element before this statement if the statement is a control flow statement.
* @param elt The element to analyse.
* @return The found element.
*/
public Optional<CtElement> getStatementParentNotCtrlFlow(@Nullable CtElement elt) {
CtElement res = elt;
boolean found = false;
while(!found && res != null) {
if(res instanceof CtStatement) {
found = true;
}else {
if(res.isParentInitialized()) {
CtElement parent = res.getParent();
// FIXME use CtBodyHolder Spoon 5.5
if(parent instanceof CtIf || parent instanceof CtSwitch || parent instanceof CtLoop || parent instanceof CtTry ||
parent instanceof CtCatch || parent instanceof CtCase) {
found = true;
}else {
res = parent;
}
}else {
res = null;
}
}
}
return Optional.ofNullable(res);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:31,代码来源:SpoonHelper.java
示例8: extractCommandsFromConditionalStatements
import spoon.reflect.code.CtIf; //导入依赖的package包/类
private void extractCommandsFromConditionalStatements(final @NotNull CtElement condStat, final @NotNull CtExecutable<?> listenerMethod,
final @NotNull List<CtStatement> conds) {
UIListener uiListener;
synchronized(commands) {
uiListener = commands.computeIfAbsent(listenerMethod, k -> new UIListener(listenerMethod));
}
if(condStat instanceof CtIf) {
extractCommandsFromIf((CtIf) condStat, uiListener, conds);
return;
}
if(condStat instanceof CtCase<?>) {
extractCommandsFromSwitchCase((CtCase<?>) condStat, uiListener);
return;
}
LOG.log(Level.SEVERE, "Unsupported conditional blocks: " + condStat);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:20,代码来源:CommandAnalyser.java
示例9: matchWidgetsUsagesWithStringsInCmdConditions
import spoon.reflect.code.CtIf; //导入依赖的package包/类
/**
* Example:
* if(e.getActionCommand().equals("FOO")){...}
* ...
* button.setActionCommand("FOO");
* @param cmd The command to analyse.
*/
private List<StringLitMatch> matchWidgetsUsagesWithStringsInCmdConditions(final @NotNull Command cmd) {
final StringLiteralFilter stringLiteralFilter = new StringLiteralFilter();
final Set<CtLiteral<?>> stringliterals = cmd.getConditions().parallelStream().
// Must ignore the conditions of if statements when in an else block (in this case the effective if statement is a negation of the
// real conditions, so they are different)
filter(cond -> cond.realStatmt == cond.effectiveStatmt || cond.realStatmt.isParentInitialized() && !(cond.realStatmt.getParent() instanceof CtIf)).
// Getting the variables used in the conditions
map(cond -> cond.effectiveStatmt.getElements(stringLiteralFilter)).flatMap(s -> s.stream()).
// Keeping those that declaration are not null
// Collecting them
distinct().collect(Collectors.toCollection(HashSet::new));
return widgetUsages.stream().map(usage -> {
// Getting the code statement that uses the variable
return usage.accesses.stream().map(acc -> acc.getParent(CtStatement.class)).filter(stat -> stat != null).
// Looking for the variables used in the conditions in the code statement
map(stat -> stringliterals.stream().filter(varr -> !stat.getElements(new FindElementFilter(varr, false)).isEmpty()).
collect(Collectors.toList())).
filter(list -> !list.isEmpty()).
map(var -> new StringLitMatch(usage, var));
}).flatMap(s -> s).collect(Collectors.toList());
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:31,代码来源:CommandWidgetFinder.java
示例10: read
import spoon.reflect.code.CtIf; //导入依赖的package包/类
@Override
public void read(Map<UUID, Transformation> transformations) {
RemoveParameterCondition transf = null;
try {
transf = (RemoveParameterCondition) get(transformations); //add the transformation to the transformations map if not present
JSONObject tpJson = getJsonObject().getJSONObject(JsonSectionOutput.TRANSPLANT_POINT);
CtIf tp = getInputProgram().findElement(CtIf.class,
tpJson.getString(JsonSectionOutput.POSITION),
tpJson.getString(JsonSectionOutput.SOURCE_CODE));
transf.setTransplantationPoint(tp);
transf.setTransplant(getReplaceStmt(tp));
addFailuresToTransformation(transf);
//Add transformation if all went OK
addTransformation(transformations, transf);
} catch (JSONException e) {
String s = "JsonAstReplaceInput::read Unable to parse replace transformation from json object";
throwError(getTransformationErrorString(transf, s), e, true);
}
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:24,代码来源:JsonRemoveParameterConditionInput.java
示例11: elementCoverage
import spoon.reflect.code.CtIf; //导入依赖的package包/类
public double elementCoverage(CtElement elem) {
if(elem instanceof CtIf) {
CtIf ctIf = (CtIf) elem;
if(ctIf.getElseStatement() != null) {
return (coverage(ctIf.getThenStatement()) + coverage(ctIf.getElseStatement())) / 2d;
} else {
return coverage(ctIf.getThenStatement());
}
}
if(elem instanceof CtLoop) {
CtLoop loop = (CtLoop) elem;
if(loop.getBody() != null) {
return coverage(loop.getBody());
} else {
return coverage(loop);
}
}
return coverage(elem);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:22,代码来源:CoverageReport.java
示例12: testTransformation
import spoon.reflect.code.CtIf; //导入依赖的package包/类
/**
* Test the transformation of the AST. Test that after the transformation, the TP is AFTER the transplant
* @throws Exception
*/
@Test
public void testTransformation() throws Exception {
Factory f = new SpoonMetaFactoryTest().build();
InputProgram p = new InputProgram();
p.setFactory(f);
p.setCodeFragmentProcessor(new AllStatementsProcessor());
p.processCodeFragments();
//Test that the replacement was properly built
ASTAddForTest a = new ASTAddForTest();
a.setTransplantationPoint(p.getCodeFragments().get(0));
a.setTransplant(p.getCodeFragments().get(1));
CtBlock e = ((CtIf)a.buildReplacement()).getThenStatement();
assertEquals(2, e.getStatements().size());
assertEquals(e.getStatement(0), p.getCodeFragments().get(0).getCtCodeFragment());
assertEquals(e.getStatement(1), p.getCodeFragments().get(1).getCtCodeFragment());
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:22,代码来源:ASTAddTest.java
示例13: createOperatorInstance
import spoon.reflect.code.CtIf; //导入依赖的package包/类
@Override
public List<OperatorInstance> createOperatorInstance(SuspiciousModificationPoint modificationPoint) {
List<OperatorInstance> ops = new ArrayList<>();
CtIf targetIF = (CtIf) modificationPoint.getCodeElement();
List<MutantCtElement> mutations = getMutants(targetIF);
for (MutantCtElement mutantCtElement : mutations) {
OperatorInstance opInstance;
try {
opInstance = createModificationInstance(modificationPoint, mutantCtElement);
if (opInstance != null)
ops.add(opInstance);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return ops;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:IfExpresionMutOp.java
示例14: process
import spoon.reflect.code.CtIf; //导入依赖的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);
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:SpecialStatementFixSpaceProcessor.java
示例15: test_t_222894
import spoon.reflect.code.CtIf; //导入依赖的package包/类
@Test
public void test_t_222894() throws Exception{
AstComparator diff = new AstComparator();
// meld src/test/resources/examples/t_222894/left_Client_1.150.java src/test/resources/examples/t_222894/right_Client_1.151.java
File fl = new File("src/test/resources/examples/t_222894/left_Client_1.150.java");
File fr = new File("src/test/resources/examples/t_222894/right_Client_1.151.java");
Diff result = diff.compare(fl,fr);
CtElement ancestor = result.commonAncestor();
assertTrue(ancestor instanceof CtIf);
result.getRootOperations();
result.debugInformation();
assertTrue(result.containsOperation(OperationKind.Insert, "BinaryOperator", "AND"));
// TODO there is a move that is not detected but should be
// assertTrue(result.containsOperation(OperationKind.Move, VariableRead", "Settings.keepServerlog"));
// this is the case if gumtree.match.gt.minh" = "0" (but bad for other tests)
}
开发者ID:SpoonLabs,项目名称:gumtree-spoon-ast-diff,代码行数:21,代码来源:AstComparatorTest.java
示例16: collectionWrappingIf
import spoon.reflect.code.CtIf; //导入依赖的package包/类
private static <T> CtIf collectionWrappingIf(List<CtStatement> collectingStatements, RuntimeValues<T> runtimeValues, CtStatement insertionPoint) {
Factory factory = insertionPoint.getFactory();
CtStatement newBlock = newBlock(factory, collectingStatements);
CtExpression<Boolean> isEnabled = newExpressionFromSnippet(factory, runtimeValues.isEnabledInquiry(), Boolean.class);
CtIf newIf = newIf(factory, isEnabled, newBlock);
insertBeforeUnderSameParent(newIf, insertionPoint);
return newIf;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:RuntimeValuesInstrumenter.java
示例17: getCondition
import spoon.reflect.code.CtIf; //导入依赖的package包/类
public static CtExpression<Boolean> getCondition(CtElement element) {
CtExpression<Boolean> condition;
if (element instanceof CtIf) {
condition = ((CtIf) element).getCondition();
} else if (element instanceof CtConditional) {
condition = ((CtConditional<?>) element).getCondition();
} else {
throw new IllegalStateException("Unknown conditional class: " + element.getClass());
}
return condition;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:12,代码来源:ConditionalProcessor.java
示例18: processCondition
import spoon.reflect.code.CtIf; //导入依赖的package包/类
@Override
public CtIf processCondition(CtStatement element, String newCondition) {
CtCodeSnippetExpression<Boolean> snippet = element.getFactory().Core().createCodeSnippetExpression();
snippet.setValue(newCondition);
CtExpression<Boolean> condition = getCondition(element);
condition.replace(snippet);
return (CtIf) element;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:ConditionalReplacer.java
示例19: appendValueCollection
import spoon.reflect.code.CtIf; //导入依赖的package包/类
public void appendValueCollection(CtStatement element, String outputName) {
CollectableValueFinder finder;
if (CtIf.class.isInstance(element)) {
finder = CollectableValueFinder.valueFinderFromIf((CtIf) element);
} else {
finder = CollectableValueFinder.valueFinderFrom(element);
}
Collection<String> collectables = finder.reachableVariables();
Multimap<String, String> getters = finder.accessibleGetters();
collectables.remove(outputName);
RuntimeValuesInstrumenter.runtimeCollectionBefore(element,
MetaMap.autoMap(collectables), getters, outputName,
runtimeValues());
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:15,代码来源:LoggingInstrumenter.java
示例20: 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());
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:38,代码来源:SymbolicConditionalAdder.java
注:本文中的spoon.reflect.code.CtIf类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论