本文整理汇总了Java中spoon.reflect.code.CtStatement类的典型用法代码示例。如果您正苦于以下问题:Java CtStatement类的具体用法?Java CtStatement怎么用?Java CtStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtStatement类属于spoon.reflect.code包,在下文中一共展示了CtStatement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addBlock
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
public void addBlock(CtBlock ctBlock) {
if (ctBlock == null) {
return;
}
System.out.println("BLOCK: " + ctBlock.getParent().toString());
for (CtStatement ctStatement : ctBlock.getStatements()) {
System.out.println(" STATEMENT: " + ctStatement);
StatementShovel statementShovel = new StatementShovel(codeWriter, typeMapper);
if (ctStatement.toString().equals("super()")) {
// skip super() calls for now
continue;
}
if (ctStatement instanceof CtComment) {
new CommentWriter(codeWriter).write((CtComment)ctStatement);
}
for (CtElement ctElement : ctStatement.getElements(new MatchAllFilter<CtElement>())) {
System.out.println(" ELEMENT: " + ctElement.getClass().getSimpleName() + " " + ctElement);
statementShovel.addElement(ctElement);
}
statementShovel.finish();
}
}
开发者ID:slipperyseal,项目名称:trebuchet,代码行数:27,代码来源:BlockShovel.java
示例2: tryFinallyBody
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
protected CtTry tryFinallyBody(CtExecutable method) {
if(!tryBodyMethod.containsKey(ProcessorUtil.methodId(method))) {
Factory factory = method.getFactory();
CtStatement thisStatement = getThisOrSuperCall(method.getBody());
CtTry ctTry = factory.Core().createTry();
((CtTryImpl)ctTry).setBody(method.getBody());
CtBlock finalizerBlock = factory.Core().createBlock();
ctTry.setFinalizer(finalizerBlock);
CtBlock methodBlock = factory.Core().createBlock();
methodBlock.addStatement(ctTry);
method.setBody(methodBlock);
if (thisStatement != null) {
ctTry.getBody().removeStatement(thisStatement);
method.getBody().getStatements().add(0, thisStatement);
}
tryBodyMethod.put(ProcessorUtil.methodId(method), ctTry);
}
return tryBodyMethod.get(ProcessorUtil.methodId(method)) ;
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:24,代码来源:AbstractLoggingInstrumenter.java
示例3: removeAssertion
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
public void removeAssertion(CtInvocation<?> invocation) {
final Factory factory = invocation.getFactory();
invocation.getArguments().forEach(argument -> {
CtExpression clone = ((CtExpression) argument).clone();
if (clone instanceof CtUnaryOperator) {
clone = ((CtUnaryOperator) clone).getOperand();
}
if (clone instanceof CtStatement) {
invocation.insertBefore((CtStatement) clone);
} else if (! (clone instanceof CtLiteral || clone instanceof CtVariableRead)) {
CtTypeReference<?> typeOfParameter = clone.getType();
if (clone.getType().equals(factory.Type().NULL_TYPE)) {
typeOfParameter = factory.Type().createReference(Object.class);
}
final CtLocalVariable localVariable = factory.createLocalVariable(
typeOfParameter,
typeOfParameter.getSimpleName() + "_" + counter[0]++,
clone
);
invocation.insertBefore(localVariable);
}
});
invocation.getParent(CtStatementList.class).removeStatement(invocation);
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:25,代码来源:AssertionRemover.java
示例4: isLastStatementOfMethod
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
public static boolean isLastStatementOfMethod(CtStatement statement) {
CtElement statementParent = statement.getParent();
if (!isStatementList(statementParent)) {
return isLastStatementOfMethod((CtStatement) statementParent);
}
CtStatementList block = (CtStatementList) statementParent;
if (isLastStatementOf(block, statement)) {
CtElement blockParent = block.getParent();
if (isStatement(blockParent)) {
return isLastStatementOfMethod((CtStatement) blockParent);
} else {
return isMethod(blockParent);
}
}
return false;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:17,代码来源:SpoonStatementLibrary.java
示例5: isElseIf
import spoon.reflect.code.CtStatement; //导入依赖的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
示例6: 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;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:21,代码来源:ConditionalAdder.java
示例7: process
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
@Override
public void process(CtStatement statement) {
String evaluationAccess = "runtimeAngelicValue";
// create the angelic value
String type = subprocessor.getType().getCanonicalName();
CtLocalVariable<?> evaluation = newLocalVariableDeclaration(
statement.getFactory(), subprocessor.getType(), evaluationAccess, "(" + type + ")"
+ this.getClass().getCanonicalName() + ".getValue("
+ subprocessor.getDefaultValue() + ")");
// insert angelic value before the statement
insertBeforeUnderSameParent(evaluation, statement);
// collect values of the statement
appendValueCollection(statement, evaluationAccess);
// insert angelic value in the condition
subprocessor.setValue("runtimeAngelicValue");
subprocessor().process(statement);
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:LoggingInstrumenter.java
示例8: process
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
@Override
public void process(CtStatement ctStatement) {
if (!(ctStatement instanceof CtLocalVariable<?>) && !(ctStatement instanceof CtAssignment<?, ?>))
return;
Class<?> localVariableClass = ((CtTypedElement<?>) ctStatement).getType().getActualClass();
if (localVariableClass.equals(Integer.class) || localVariableClass.equals(int.class)) {
if (ctStatement instanceof CtAssignment<?, ?>) {
replaceInteger(((CtAssignment<?, ?>) ctStatement).getAssignment());
} else {
replaceInteger(((CtLocalVariable<?>) ctStatement).getDefaultExpression());
}
} else if (localVariableClass.equals(Double.class) || localVariableClass.equals(double.class)) {
if (ctStatement instanceof CtAssignment<?, ?>) {
replaceDouble(((CtAssignment<?, ?>) ctStatement).getAssignment());
} else {
replaceDouble(((CtLocalVariable<?>) ctStatement).getDefaultExpression());
}
} else if (localVariableClass.equals(Boolean.class) || localVariableClass.equals(boolean.class)) {
if (ctStatement instanceof CtAssignment<?, ?>) {
replaceBoolean(((CtAssignment<?, ?>) ctStatement).getAssignment());
} else {
replaceBoolean(((CtLocalVariable<?>) ctStatement).getDefaultExpression());
}
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:27,代码来源:LiteralReplacer.java
示例9: replaceDouble
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
private void replaceDouble(CtExpression ctElement) {
if (getValue() == null) {
CtLocalVariable<Double> evaluation = newLocalVariableDeclaration(
ctElement.getFactory(), double.class, "guess_fix",
Debug.class.getCanonicalName() + ".makeSymbolicReal(\"guess_fix\")");
CtStatement firstStatement = getFirstStatement(ctElement);
if (firstStatement == null) {
return;
}
SpoonStatementLibrary.insertBeforeUnderSameParent(evaluation, firstStatement);
// SpoonStatementLibrary.insertAfterUnderSameParent(getFactory().Code().createCodeSnippetStatement("System.out.println(\"guess_fix: \" + guess_fix)"),
// getFirstStatement(ctElement));
ctElement.replace(getFactory().Code().createCodeSnippetExpression("guess_fix"));
} else {
ctElement.replace(getFactory().Code().createCodeSnippetExpression(getValue()));
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:19,代码来源:LiteralReplacer.java
示例10: replaceInteger
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
private void replaceInteger(CtExpression ctElement) {
if (getValue() == null) {
CtLocalVariable<Integer> evaluation = newLocalVariableDeclaration(
ctElement.getFactory(), int.class, "guess_fix",
Debug.class.getCanonicalName()
+ ".makeSymbolicInteger(\"guess_fix\")");
CtStatement firstStatement = getFirstStatement(ctElement);
if (firstStatement == null) {
return;
}
SpoonStatementLibrary.insertBeforeUnderSameParent(evaluation, firstStatement);
// SpoonStatementLibrary.insertAfterUnderSameParent(getFactory().Code().createCodeSnippetStatement("System.out.println(\"guess_fix: \" + guess_fix)"),
// getFirstStatement(ctElement));
ctElement.replace(getFactory().Code().createCodeSnippetExpression("guess_fix"));
} else {
ctElement.replace(getFactory().Code().createCodeSnippetExpression(getValue()));
}
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:21,代码来源:LiteralReplacer.java
示例11: isToBeProcessed
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
/**
* @see spoon.processing.AbstractProcessor#isToBeProcessed(spoon.reflect.declaration.CtElement)
*/
@Override
public boolean isToBeProcessed(final CtStatement candidate) {
boolean isPracticable = this.predicate.apply(candidate);
if (isPracticable) {
SourcePosition position = candidate.getPosition();
if (position == null || position == SourcePosition.NOPOSITION) {
return false;
}
boolean isSameFile = false;
boolean isSameLine = position.getLine() == this.line;
try {
File f1 = position.getFile().getCanonicalFile().getAbsoluteFile();
File f2 = file.getCanonicalFile();
isSameFile = f1.getAbsolutePath().equals(f2.getAbsolutePath());
} catch (Exception e) {
throw new IllegalStateException(e);
}
isPracticable = this.process && isSameLine && isSameFile;
}
return isPracticable;
}
开发者ID:SpoonLabs,项目名称:nopol,代码行数:25,代码来源:DelegatingProcessor.java
示例12: process
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
public void process(Bound annotation, CtParameter<?> element) {
// Is to be process?
CtExecutable<?> e = element.getParent();
if (e.getBody() == null) {
return;
}
// Use template.
CtClass<?> type = (CtClass<?>) e.getParent(CtClass.class);
Template t = new BoundTemplate(getFactory().Type().createReference(Double.class), element.getSimpleName(), annotation.min(), annotation.max());
final CtBlock apply = (CtBlock) t.apply(type);
// Apply transformation.
for (int i = apply.getStatements().size() - 1; i >= 0; i--) {
final CtStatement statement = apply.getStatement(i);
e.getBody().insertBegin(statement);
statement.setParent(e.getBody());
}
}
开发者ID:SpoonLabs,项目名称:spoon-examples,代码行数:20,代码来源:BoundTemplateProcessor.java
示例13: process
import spoon.reflect.code.CtStatement; //导入依赖的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;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:26,代码来源:CfgBuilder.java
示例14: getStatement
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
/**
* Searches for the parent or current statement. If elt is a statement, elt is returned.
* Otherwise, a statement is searched in the parent hierarchy.
* @param elt The element to analyse.
* @return The parent statement or elt or nothing.
*/
public Optional<CtStatement> getStatement(final @Nullable CtElement elt) {
if(elt==null) {
return Optional.empty();
}
if(elt instanceof CtStatement) {
return Optional.of((CtStatement)elt);
}
if(elt.isParentInitialized()) {
return getStatement(elt.getParent());
}
return Optional.empty();
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:22,代码来源:SpoonHelper.java
示例15: getStatementParentNotCtrlFlow
import spoon.reflect.code.CtStatement; //导入依赖的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
示例16: extractCommandsFromConditionalStatements
import spoon.reflect.code.CtStatement; //导入依赖的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
示例17: matchWidgetsUsagesWithStringsInCmdConditions
import spoon.reflect.code.CtStatement; //导入依赖的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
示例18: refactorRegistrationAsLambda
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
private <T> void refactorRegistrationAsLambda(final @NotNull CtAbstractInvocation<?> regInvok,
final @NotNull Set<CtAbstractInvocation<?>> unregInvoks,
final int regPos, final String widgetName) {
final Factory fac = regInvok.getFactory();
final CtTypeReference<T> typeRef = (CtTypeReference<T>) regInvok.getExecutable().getParameters().get(regPos).getTypeDeclaration().getReference();
final CtLambda<T> lambda = fac.Core().createLambda();
final List<CtElement> stats = cleanStatements(regInvok, fac);
if(stats.size()==1 && stats.get(0) instanceof CtExpression<?>) {
lambda.setExpression((CtExpression<T>)stats.get(0));
} else {
final CtBlock<T> block = fac.Core().createBlock();
stats.stream().filter(stat -> stat instanceof CtStatement).forEach(stat -> block.insertEnd((CtStatement)stat));
lambda.setBody(block);
}
CtParameter<?> oldParam = cmd.getExecutable().getParameters().get(0);
CtParameter<?> param = fac.Executable().createParameter(lambda, oldParam.getType(), oldParam.getSimpleName());
lambda.setParameters(Collections.singletonList(param));
lambda.setType(typeRef);
replaceRegistrationParameter(lambda, regInvok, unregInvoks, regPos, widgetName);
changeThisAccesses(stats, regInvok);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:25,代码来源:ListenerCommandRefactor.java
示例19: getThisOrSuperCall
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
protected CtStatement getThisOrSuperCall(CtBlock block) {
if(!block.getStatements().isEmpty()) {
CtStatement stmt = block.getStatement(0);
if(stmt.toString().startsWith("this(") || stmt.toString().startsWith("super(")) {
return stmt;
}
}
return null;
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:10,代码来源:AbstractLoggingInstrumenter.java
示例20: apply
import spoon.reflect.code.CtStatement; //导入依赖的package包/类
private CtMethod apply(CtMethod method, int invocation_index) {
CtMethod<?> cloned_method = AmplificationHelper.cloneMethodTest(method, "_add");
//add the cloned method in the same class as the original method
//get the lit_indexth literal of the cloned method
CtInvocation stmt = Query.getElements(cloned_method, new TypeFilter<>(CtInvocation.class)).get(invocation_index);
CtInvocation cloneStmt = stmt.clone();
final CtStatement parent = getParent(stmt);
parent.insertBefore(cloneStmt);
cloneStmt.setParent(parent.getParent(CtBlock.class));
Counter.updateInputOf(cloned_method, 1);
DSpotUtils.addComment(cloneStmt, "MethodCallAdder", CtComment.CommentType.INLINE);
return cloned_method;
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:14,代码来源:TestMethodCallAdder.java
注:本文中的spoon.reflect.code.CtStatement类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论