本文整理汇总了Java中spoon.reflect.code.CtStatement.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java CtStatement.getParent方法的具体用法?Java CtStatement.getParent怎么用?Java CtStatement.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spoon.reflect.code.CtStatement
的用法示例。
在下文中一共展示了CtStatement.getParent方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: insertBeforeUnderSameParent
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
public static void insertBeforeUnderSameParent(CtStatement toBeInserted, CtStatement insertionPoint) {
CtElement parent;
if (isBlock(insertionPoint)) {
CtBlock<?> block = (CtBlock<?>) insertionPoint;
block.insertBegin(toBeInserted);
parent = block;
} else {
insertionPoint.insertBefore(toBeInserted);
parent = insertionPoint.getParent();
}
setParent(parent, toBeInserted);
}
示例5: insertAfterUnderSameParent
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
public static void insertAfterUnderSameParent(CtStatement toBeInserted, CtStatement insertionPoint) {
CtElement parent;
if (isBlock(insertionPoint)) {
CtBlock<?> block = (CtBlock<?>) insertionPoint;
block.insertEnd(toBeInserted);
parent = block;
} else {
insertionPoint.insertAfter(toBeInserted);
parent = insertionPoint.getParent();
}
setParent(parent, toBeInserted);
}
示例6: isToBeProcessed
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
@Override
public boolean isToBeProcessed(CtStatement candidate) {
CtClass parent = candidate.getParent(CtClass.class);
if (parent == null || !parent.getQualifiedName().equals(this.location.getContainingClassName())) {
return false;
}
return parent.getPosition().getLine() == location.getLineNumber();
}
示例7: 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());
}
示例8: process
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
@Override
public void process(CtStatement arg0) {
if (arg0.getParent() instanceof CtBlock) {// Count the logical lines of
// code
counter++;
}
}
示例9: isToBeProcessed
import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
@Override
public boolean isToBeProcessed(CtStatement stmt) {
return stmt.getParent(CtExecutable.class) != null;
}