本文整理汇总了Java中spoon.reflect.code.CtBlock类的典型用法代码示例。如果您正苦于以下问题:Java CtBlock类的具体用法?Java CtBlock怎么用?Java CtBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtBlock类属于spoon.reflect.code包,在下文中一共展示了CtBlock类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: addBlock
import spoon.reflect.code.CtBlock; //导入依赖的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: process
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
public void process(CtMethod element) {
Factory factory = this.getFactory();
CtTry ctTry = factory.Core().createTry();
ctTry.setBody(element.getBody());
String snippet;
String testName;
if(element.getModifiers().contains(ModifierKind.STATIC)) {
testName = element.getPosition().getCompilationUnit().getMainType().getQualifiedName() + "." + element.getSimpleName();
snippet = this.getLogName() + ".testIn(Thread.currentThread(), \"" + testName + "\")";
} else {
testName = element.getSimpleName();
snippet = this.getLogName() + ".testIn(Thread.currentThread(),this, \"" + testName + "\")";
}
CtCodeSnippetStatement snippetStatement = factory.Code().createCodeSnippetStatement(snippet);
element.getBody().insertBegin(snippetStatement);
snippet = this.getLogName() + ".testOut(Thread.currentThread())";
CtCodeSnippetStatement snippetFinish = factory.Code().createCodeSnippetStatement(snippet);
CtBlock finalizerBlock = factory.Core().createBlock();
finalizerBlock.addStatement(snippetFinish);
ctTry.setFinalizer(finalizerBlock);
CtBlock methodBlock = factory.Core().createBlock();
methodBlock.addStatement(ctTry);
element.setBody(methodBlock);
}
开发者ID:STAMP-project,项目名称:dspot,代码行数:26,代码来源:TestLogProcessor.java
示例3: tryFinallyBody
import spoon.reflect.code.CtBlock; //导入依赖的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
示例4: isElseIf
import spoon.reflect.code.CtBlock; //导入依赖的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
示例5: process
import spoon.reflect.code.CtBlock; //导入依赖的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
示例6: build
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
/**
* Add the method in the control flow graph
*/
public static SubGraph build(CtExecutable<?> method, ControlFlowGraph cfg) {
CfgBuilder builder = new CfgBuilder(cfg);
SubGraph res = new SubGraph(cfg);
CtBlock<?> bodyStmt = method.getBody();
if (bodyStmt != null) {
SubGraph body = builder.process(bodyStmt);
res.setEntry(body.getEntry());
body.getExit().addChild(res.getExit(), null);
} else {
res.setEntry(res.getExit());
}
for (SubGraph block : builder.returnStatements) {
block.getExit().setReturnChild(res.getExit());
}
return res;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:24,代码来源:CfgBuilder.java
示例7: refactorRegistrationAsLambda
import spoon.reflect.code.CtBlock; //导入依赖的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
示例8: process
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
@Override
public void process(CtThrow throwStmt) {
int methodId = ProcessorUtil.methodId(getMethod(throwStmt));
int localId = getLocalId(throwStmt);
String localVar = "throwable_" + localId;
String snippet = throwStmt.getThrownExpression().getType() + " " + localVar + " = " + throwStmt.getThrownExpression();
CtCodeSnippetStatement var = getFactory().Code().createCodeSnippetStatement(snippet);
snippet = getLogger()+".writeThrow(Thread.currentThread(),\"" + methodId + "\",\""
+ localId + "\"," + localVar + ")";
CtCodeSnippetStatement log = getFactory().Code().createCodeSnippetStatement(snippet);
CtCodeSnippetStatement thro = getFactory().Code().createCodeSnippetStatement("throw " + localVar);
CtBlock block = getFactory().Core().createBlock();
block.addStatement(var);
block.addStatement(log);
block.addStatement(thro);
throwStmt.replace(block);
throwStmt.getParent(CtBlock.class).removeStatement(throwStmt);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:25,代码来源:ThrowProcessor.java
示例9: buildReplacementElement
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
protected CtElement buildReplacementElement() {
Factory factory = transplantationPoint.getFactory();
CtMethod newMethod = factory.Core().clone(transplantationPoint);
newMethod.setAnnotations(new ArrayList<CtAnnotation<? extends Annotation>>());
CtBlock body = factory.Core().createBlock();
body.setParent(newMethod);
String type = newMethod.getType().getSimpleName();
if(!(type.equals("void") || type.equals("Void"))) {
CtReturn ret = factory.Core().createReturn();
ret.setParent(body);
body.addStatement(ret);
CtCodeSnippetExpression<Object> voidValue = factory.Core().createCodeSnippetExpression();
voidValue.setValue("null");
ret.setReturnedExpression(voidValue);
}
newMethod.setBody(body);
return newMethod;
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:26,代码来源:EmptyMethodBody.java
示例10: setTp
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
public void setTp(CtInvocation tp) {
this.tp = tp;
position = tp.getPosition();
Factory f = tp.getFactory();
save = f.Core().clone(tp);
if(!(tp.getParent() instanceof CtBlock)) {
defaultValue = RandomLiteralFactory.defaultValue(tp.getType());
} else {
rep = f.Code().createCodeSnippetStatement("");
}
if(verbose) {
System.out.println("del: " + tp);
System.out.println("in: " + tp.getParent());
if(defaultValue != null) System.out.println("replace with: (" + defaultValue.getType().getSimpleName() + ") " + defaultValue);
}
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:RemoveInvocation.java
示例11: process
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
@Override
public void process(CtThrow throwStmt) {
int methodId = methodId(getMethod(throwStmt));
int localId = getLocalId(throwStmt);
String localVar = "throwable_" + localId;
String snippet = throwStmt.getThrownExpression().getType() + " " + localVar + " = " + throwStmt.getThrownExpression();
CtCodeSnippetStatement var = getFactory().Code().createCodeSnippetStatement(snippet);
snippet = getLogger()+".writeThrow(Thread.currentThread(),\"" + methodId + "\",\""
+ localId + "\"," + localVar + ")";
CtCodeSnippetStatement log = getFactory().Code().createCodeSnippetStatement(snippet);
CtCodeSnippetStatement thro = getFactory().Code().createCodeSnippetStatement("throw " + localVar);
CtBlock block = getFactory().Core().createBlock();
block.addStatement(var);
block.addStatement(log);
block.addStatement(thro);
throwStmt.replace(block);
throwStmt.getParent(CtBlock.class).removeStatement(throwStmt);
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:25,代码来源:ThrowProcessor.java
示例12: isValidStatement
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
protected boolean isValidStatement(CtStatement element) throws IOException {
if (sourceFilter != null) {
String file = element.getPosition().getCompilationUnit().getFile().toString();
for (File filter : sourceFilter) {
if (file.contains(filter.getCanonicalPath().toString())) return false;
}
}
if(element.getParent() instanceof CtBlock) {
String elementString = element.toString();
return !(elementString.startsWith("super") || elementString.startsWith("this("));
}
return false;
// valid = new ValidStatementVisitor(element, false);
// element.getParent().accept(valid);
// return !valid.inExpression(element) && valid.isValid();
}
开发者ID:DIVERSIFY-project,项目名称:sosiefier,代码行数:18,代码来源:StatementProcessor.java
示例13: testTransformation
import spoon.reflect.code.CtBlock; //导入依赖的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
示例14: applyChangesInModel
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
@Override
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
boolean successful = false;
CtStatement ctst = (CtStatement) operation.getOriginal();
CtStatement fix = (CtStatement) operation.getModified();
CtBlock parentBlock = operation.getParentBlock();
if (parentBlock != null) {
ctst.insertBefore((CtStatement) fix);
fix.setParent(parentBlock);
successful = true;
operation.setSuccessfulyApplied(successful);
this.updateBlockImplicitly(parentBlock, true);
} else {
log.error("Operation not applied. Parent null ");
}
return successful;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:InsertBeforeOp.java
示例15: applyChangesInModel
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
@Override
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
boolean successful = false;
CtStatement ctst = (CtStatement) operation.getOriginal();
CtStatement fix = (CtStatement) operation.getModified();
CtBlock parentBlock = operation.getParentBlock();
if (parentBlock != null) {
ctst.insertAfter((CtStatement) fix);
fix.setParent(parentBlock);
successful = true;
operation.setSuccessfulyApplied(successful);
this.updateBlockImplicitly(parentBlock, true);
} else {
log.error("Operation not applied. Parent null");
}
return successful;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:InsertAfterOp.java
示例16: applyChangesInModel
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
boolean successful = false;
CtStatement ctst = (CtStatement) operation.getOriginal();
CtStatement fix = (CtStatement) operation.getModified();
CtBlock parentBlock = operation.getParentBlock();
if (parentBlock != null) {
try {
ctst.replace((CtStatement) fix);
fix.setParent(parentBlock);
successful = true;
operation.setSuccessfulyApplied(successful);
} catch (Exception ex) {
log.error("Error applying an operation, exception: " + ex.getMessage());
operation.setExceptionAtApplied(ex);
operation.setSuccessfulyApplied(false);
}
} else {
log.error("Operation not applied. Parent null ");
}
return successful;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:ReplaceOp.java
示例17: updateBlockImplicitly
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
/**
* Updates the implicitly of a block. Workarround for Spoon 5.4.0
* @param block
* @param isInsert
*/
public void updateBlockImplicitly(CtBlock block, boolean isInsert) {
if (!block.isImplicit() && block.getStatements().size() == 1 && !(block.getParent() instanceof CtExecutable)) {
block.setImplicit(true);
} else {
if (isInsert) {
if (block.isImplicit() && block.getStatements().size() > 1) {
block.setImplicit(false);
}
} else {// Delete
if (block.isImplicit() && block.getStatements().size() == 0) {
block.setImplicit(false);
}
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:StatementLevelOperator.java
示例18: applyChangesInModel
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
@Override
public boolean applyChangesInModel(OperatorInstance operation, ProgramVariant p) {
boolean successful = false;
CtStatement ctst = (CtStatement) operation.getOriginal();
CtBlock parentBlock = operation.getParentBlock();
if (parentBlock != null) {
try {
parentBlock.getStatements().remove(operation.getLocationInParent());
successful = true;
operation.setSuccessfulyApplied(successful);
this.updateBlockImplicitly(parentBlock, false);
} catch (Exception ex) {
log.error("Error applying an operation, exception: " + ex.getMessage());
operation.setExceptionAtApplied(ex);
operation.setSuccessfulyApplied(false);
}
} else {
log.error("Operation not applied. Parent null ");
}
return successful;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:24,代码来源:RemoveOp.java
示例19: undoChangesInModel
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
@Override
public boolean undoChangesInModel(OperatorInstance operation, ProgramVariant p) {
CtStatement ctst = (CtStatement) operation.getOriginal();
CtBlock<?> parentBlock = operation.getParentBlock();
if (parentBlock != null) {
if ((parentBlock.getStatements().isEmpty() && operation.getLocationInParent() == 0)
|| (parentBlock.getStatements().size() >= operation.getLocationInParent())) {
parentBlock.getStatements().add(operation.getLocationInParent(), ctst);
parentBlock.setImplicit(operation.isParentBlockImplicit());
return true;
} else {
log.error("Problems to recover, re-adding " + ctst + " at location " + operation.getLocationInParent()
+ " from parent size " + parentBlock.getStatements().size());
throw new IllegalStateException("Undo:Not valid index");
}
}
return false;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:RemoveOp.java
示例20: defineParentInformation
import spoon.reflect.code.CtBlock; //导入依赖的package包/类
public boolean defineParentInformation(ModificationPoint genSusp) {
CtElement targetStmt = genSusp.getCodeElement();
CtElement cparent = targetStmt.getParent();
if ((cparent != null && (cparent instanceof CtBlock))) {
CtBlock parentBlock = (CtBlock) cparent;
int location = locationInParent(parentBlock, targetStmt);
if (location >= 0) {
this.setParentBlock(parentBlock);
this.setLocationInParent(location);
return true;
}
} else {
log.debug("Attention: parent different to block");
}
return false;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:OperatorInstance.java
注:本文中的spoon.reflect.code.CtBlock类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论