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


Java CtVariableAccess.getVariable方法代码示例

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


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

示例1: collectInductionVariableAccess

import spoon.reflect.code.CtVariableAccess; //导入方法依赖的package包/类
/**
 * It retrieves all variables access which declarations are inside the
 * ingredient.
 * 
 * @param ingredientRootElement
 * @param varAccessCollected
 * @return
 */
public static List<CtVariableAccess> collectInductionVariableAccess(CtElement ingredientRootElement,
		List<CtVariableAccess> varAccessCollected) {

	List<CtVariableAccess> induction = new ArrayList<>();

	for (CtVariableAccess ctVariableAccess : varAccessCollected) {

		CtVariableReference varref = ctVariableAccess.getVariable();

		// We are interesting in induction vars, they are modeled as
		// LocalVariables
		if (!(varref instanceof CtLocalVariableReference))
			continue;

		CtVariable var = varref.getDeclaration();

		boolean insideIngredient = checkParent(var, ingredientRootElement);
		if (insideIngredient)
			induction.add(ctVariableAccess);

	}
	return induction;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:VariableResolver.java

示例2: getDeepDef2

import spoon.reflect.code.CtVariableAccess; //导入方法依赖的package包/类
private List<CtTypeReference<?>> getDeepDef2(CtExpression<?> condition) {
	List<CtTypeReference<?>> res = new ArrayList<>();

	List<CtVariableAccess<?>> vars = defuse.findUsedVar(condition);
	for (CtVariableAccess<?> var : vars) {
		// if (var.getVariable() instanceof CtFieldReference){//conds such
		// as KeyEvent.VK_ESCAPE, where getDeepDef(var) does not found the
		// var declaration
		// CtFieldReference fieldRef = (CtFieldReference)
		// var.getVariable();//FIXME
		// CtTypeReference fieldType = fieldRef.getDeclaringType();
		// res.add(fieldType);
		// }
		// if (var.getVariable() instanceof CtVariable){
		// CtVariable variable = (CtVariable) var.getVariable();
		// res.add(var.getType());//maybe i cannot
		//
		// }
		// else
		if (var.getVariable() instanceof CtParameterReference) {
			CtParameterReference<?> param = (CtParameterReference<?>) var.getVariable();
			res.add(param.getType());
		} else {
			Set<CtExpression<?>> defs = getVarDefs(var);
			for (CtExpression<?> def : defs) {
				res.addAll(getDeepDef2(def));
			}
		}
	}
	return res;
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:32,代码来源:Command.java

示例3: matches

import spoon.reflect.code.CtVariableAccess; //导入方法依赖的package包/类
@Override
public boolean matches(final CtVariableAccess<?> variableAccess) {
	final CtVariableReference<?> varAc = variableAccess.getVariable();

	try {
		return varAc != null && varAc.getDeclaration() == variable;
	}catch(NullPointerException ex) {
		return false;
	}
}
 
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:11,代码来源:MyVariableAccessFilter.java

示例4: collectStaticVariableAccess

import spoon.reflect.code.CtVariableAccess; //导入方法依赖的package包/类
public static List<CtVariableAccess> collectStaticVariableAccess(CtElement rootElement,
		List<CtVariableAccess> varAccessCollected) {
	List<CtVariableAccess> statics = new ArrayList<>();

	for (CtVariableAccess ctVariableAccess : varAccessCollected) {
		CtVariableReference varref = ctVariableAccess.getVariable();

		if (isStatic(varref)) {
			statics.add(ctVariableAccess);
		}
	}
	return statics;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:VariableResolver.java

示例5: getDeepDef

import spoon.reflect.code.CtVariableAccess; //导入方法依赖的package包/类
/**
 * Get attributes & methods parameters dependences for this variable access
 */
public Set<CtVariable<?>> getDeepDef(CtVariableAccess<?> var) {
	Set<CtVariable<?>> res = new HashSet<>();

	Set<CtCodeElement> defs = getReachingDef(var);
	if (defs != null) {
		for (CtCodeElement def : defs) {
			List<CtVariableAccess<?>> topVars = getUsedVariables(def);
			if (topVars != null) {
				for (CtVariableAccess<?> topVar : topVars) {
					res.addAll(getDeepDef(topVar));
				}
			}
		}
	} else {
		CtVariable<?> decl = var.getVariable().getDeclaration();
		if (decl instanceof CtField || decl instanceof CtParameter) {
			res.add(decl);
		}

		/*
		 * Workaround to fix a bug found in Spoon: Getting declaration from
		 * a anonymous
		 */
		if (decl == null) {
			if (var.getVariable() instanceof CtParameterReference) {
				CtParameterReference<?> p = (CtParameterReference<?>) var.getVariable();
				// String name = p.getDeclaringExecutable().getSimpleName();
				String decType = p.getDeclaringExecutable().getDeclaringType().getSimpleName();

				if (decType.length() == 0) {
					CtExecutable<?> exec = getDeclaringMethod(var);
					if (exec != null) {
						List<CtParameter<?>> params = exec.getParameters();
						for (CtParameter<?> param : params) {
							if (var.getVariable().getSimpleName().equals(param.getSimpleName())) {
								res.add(param);
								break;
							}
						}
					}
				}
			}
			// else if (var.getVariable() instanceof CtFieldReference){
			// FIXME get declaration for variable found in this kind of
			// expression: java.awt.event.KeyEvent.VK_ESCAPE
			// }
		}

	}

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


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