当前位置: 首页>>代码示例>>Java>>正文


Java CtStatement.getParent方法代码示例

本文整理汇总了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;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:17,代码来源:SpoonStatementLibrary.java

示例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;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:18,代码来源:PatchGenerator.java

示例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;
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:21,代码来源:ConditionalAdder.java

示例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);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:13,代码来源:SpoonStatementLibrary.java

示例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);
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:13,代码来源:SpoonStatementLibrary.java

示例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();
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:9,代码来源:MethodFromLocation.java

示例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());
}
 
开发者ID:SpoonLabs,项目名称:nopol,代码行数:38,代码来源:SymbolicConditionalAdder.java

示例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++;
	}
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:8,代码来源:StatementProcessor.java

示例9: isToBeProcessed

import spoon.reflect.code.CtStatement; //导入方法依赖的package包/类
@Override
public boolean isToBeProcessed(CtStatement stmt) {
    return stmt.getParent(CtExecutable.class) != null;
}
 
开发者ID:STAMP-project,项目名称:dspot,代码行数:5,代码来源:AddBlockEverywhereProcessor.java


注:本文中的spoon.reflect.code.CtStatement.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。