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


Java CtElement.isParentInitialized方法代码示例

本文整理汇总了Java中spoon.reflect.declaration.CtElement.isParentInitialized方法的典型用法代码示例。如果您正苦于以下问题:Java CtElement.isParentInitialized方法的具体用法?Java CtElement.isParentInitialized怎么用?Java CtElement.isParentInitialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spoon.reflect.declaration.CtElement的用法示例。


在下文中一共展示了CtElement.isParentInitialized方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStatement

import spoon.reflect.declaration.CtElement; //导入方法依赖的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

示例2: getStatementParentNotCtrlFlow

import spoon.reflect.declaration.CtElement; //导入方法依赖的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

示例3: getSuperConditionalExpressions

import spoon.reflect.declaration.CtElement; //导入方法依赖的package包/类
/**
 * @param elt The element from which the research starts.
 * @return All the conditional expressions from the given element 'elt' up to the given top parent.
 */
public @NotNull List<CtElement> getSuperConditionalExpressions(final @NotNull CtElement elt) {
	CtElement parent = elt.isParentInitialized() ? elt.getParent() : null;
	List<CtElement> conds = new ArrayList<>();

	// Exploring the parents to identify the conditional statements
	while(parent != null) {
		if(parent instanceof CtIf) {
			conds.add(((CtIf) parent).getCondition());
		}else {
			if(parent instanceof CtCase<?>) {
				conds.add(((CtCase<?>) parent).getCaseExpression());
				CtSwitch<?> switzh = parent.getParent(CtSwitch.class);
				if(switzh == null) System.err.println("Cannot find the switch statement from the case statement: " + parent);
				else conds.add(switzh.getSelector());
			}else {
				if(parent instanceof CtWhile) {
					conds.add(((CtWhile) parent).getLoopingExpression());
				}else {
					if(parent instanceof CtDo) {
						conds.add(((CtDo) parent).getLoopingExpression());
					}else {
						if(parent instanceof CtFor) {
							conds.add(((CtFor) parent).getExpression());
						}
					}
				}
			}
		}

		parent = parent.isParentInitialized() ? parent.getParent() : null;
	}

	return conds;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:39,代码来源:SpoonHelper.java

示例4: getLinePosition

import spoon.reflect.declaration.CtElement; //导入方法依赖的package包/类
public int getLinePosition(final CtElement elt) {
	if(elt == null) return -1;

	SourcePosition pos = elt.getPosition();
	CtElement parent = elt.isParentInitialized() ? elt.getParent() : null;

	while(pos == null && parent != null) {
		pos = parent.getPosition();
		parent = parent.isParentInitialized() ? parent.getParent() : null;
	}

	if(pos == null) return -1;
	return pos.getLine();
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:15,代码来源:SpoonHelper.java


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