本文整理汇总了Java中spoon.reflect.code.CtVariableAccess类的典型用法代码示例。如果您正苦于以下问题:Java CtVariableAccess类的具体用法?Java CtVariableAccess怎么用?Java CtVariableAccess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CtVariableAccess类属于spoon.reflect.code包,在下文中一共展示了CtVariableAccess类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getText
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
@Override
public @NotNull String getText() {
final String txt;
if(exp instanceof CtInvocation<?> && ((CtInvocation<?>) exp).getTarget() instanceof CtVariableAccess<?>) {
txt = ((CtVariableAccess<?>)((CtInvocation<?>) exp).getTarget()).getVariable().getSimpleName();
}else {
if(exp instanceof CtVariableAccess<?>) {
txt = ((CtVariableAccess<?>)exp).getVariable().getSimpleName();
}else {
if(exp instanceof CtLambda<?>) {
final CtLambda<?> lambda = (CtLambda<?>) exp;
txt = lambda.getExpression().getElements((CtInvocation<?> invok) -> TestFXProcessor.isRobotInvocation(invok)).stream().
map(invok -> invok.getExecutable().getSimpleName()).collect(Collectors.joining());
}else {
txt = exp.toString();
}
}
}
return txt.replaceAll("[^A-Za-z0-9]", "") + getIDCmd();
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:22,代码来源:GUICmd.java
示例2: equals
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
@Override
public boolean equals(final @Nullable Object o) {
if(this == o) return true;
if(!(o instanceof Cmd)) return false;
Cmd<?> cmd = (Cmd<?>) o;
if(exp instanceof CtVariableAccess<?> && cmd.exp instanceof CtVariableAccess<?>) {
return ((CtVariableAccess<?>) exp).getVariable().getDeclaration() == ((CtVariableAccess<?>) cmd.exp).getVariable().getDeclaration();
}
if(exp instanceof CtInvocation<?> && cmd.exp instanceof CtInvocation<?>) {
final CtInvocation<?> invok1 = (CtInvocation<?>) exp;
final CtInvocation<?> invok2 = (CtInvocation<?>) cmd.exp;
if(invok1.getTarget() instanceof CtVariableAccess<?> && invok2.getTarget() instanceof CtVariableAccess<?>) {
return ((CtVariableAccess<?>) invok1.getTarget()).getVariable().getDeclaration() == ((CtVariableAccess<?>) invok1.getTarget()).getVariable().getDeclaration();
}
}
return exp.equals(cmd.exp);
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:22,代码来源:Cmd.java
示例3: checkMapping
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
public static List<CtVariableAccess> checkMapping(Map<CtVariableAccess, List<CtVariable>> matched) {
List<CtVariableAccess> notMapped = new ArrayList<>();
if (matched == null)
return notMapped;
// Now, we analyze if all access were matched
for (CtVariableAccess ctVariableAccess : matched.keySet()) {
List<CtVariable> mapped = matched.get(ctVariableAccess);
if (mapped.isEmpty()) {
// One var access was not mapped
// return false;
notMapped.add(ctVariableAccess);
}
}
// All VarAccess were mapped
// return true;
return notMapped;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:VariableResolver.java
示例4: searchVarNameConflicts
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Returns a map between the variables with name conflicts.
*
* @param varsFromContext
* @param varInductionCollected
* @return
*/
public static Map<CtVariableAccess, List<CtVariable>> searchVarNameConflicts(List<CtVariable> varsFromContext,
List<CtVariableAccess> varInductionCollected) {
Map<CtVariableAccess, List<CtVariable>> mappingConflicts = new HashMap<>();
for (CtVariableAccess inductionVar : varInductionCollected) {
List<CtVariable> varsConf = new ArrayList<>();
String nameInduction = inductionVar.getVariable().getSimpleName();
for (CtVariable ctVariableContext : varsFromContext) {
String nameVarContexr = ctVariableContext.getSimpleName();
if (nameInduction.equals(nameVarContexr)) {
varsConf.add(ctVariableContext);
}
}
if (varsConf.size() > 0) {
mappingConflicts.put(inductionVar, varsConf);
}
}
return mappingConflicts;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:VariableResolver.java
示例5: 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
示例6: 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
示例7: getVarDefs
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
private Set<CtExpression<?>> getVarDefs(CtVariableAccess<?> var) {
Set<CtExpression<?>> res = new HashSet<>();
Set<CtCodeElement> defs = defuse.getReachingDef(var);
CtVariable<?> dec = var.getVariable().getDeclaration();
if (defs != null) {
for (CtCodeElement def : defs) {
res.addAll(processLine(def));
}
} else if (dec != null && dec.getDefaultExpression() != null) {
res.add(dec.getDefaultExpression());
}
return res;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:16,代码来源:Command.java
示例8: storeUseDef
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Find variables in the expression, find their last definitions and store
* these pairs
*/
private void storeUseDef(CtExpression<?> expr, Map<CtVariable<?>, Set<CtCodeElement>> definitions) {
List<CtVariableAccess<?>> varAccess = findUsedVar(expr);
if (!varAccess.isEmpty()) {
usedVar.put(expr, varAccess);
}
for (CtVariableAccess<?> var : varAccess) {
CtVariable<?> decl = var.getVariable().getDeclaration();
reachingDef.put(var, definitions.get(decl)); // store (use,def)
}
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:15,代码来源:DefUse.java
示例9: updateUseDef
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Find variables access in the expression, and add new definitions
*/
private void updateUseDef(CtExpression<?> expr, Map<CtVariable<?>, Set<CtCodeElement>> definitions) {
List<CtVariableAccess<?>> varAccess = findUsedVar(expr);
for (CtVariableAccess<?> var : varAccess) {
CtVariable<?> decl = var.getVariable().getDeclaration();
Set<CtCodeElement> oldDef = reachingDef.get(var);
if (oldDef != null) {
Set<CtCodeElement> newDef = definitions.get(decl);
if (newDef != null)
oldDef.addAll(newDef);
}
}
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:17,代码来源:DefUse.java
示例10: findUsedVar
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Get used variables in this expression. If the expression is a method
* call, the caller is included in used variables
*/
public List<CtVariableAccess<?>> findUsedVar(CtExpression<?> expr) {
List<CtVariableAccess<?>> res = new ArrayList<>();
if (expr instanceof CtFieldAccess) {
CtFieldAccess<?> access = (CtFieldAccess<?>) expr;
if (access.getTarget() != null) {
res.addAll(findUsedVar(access.getTarget()));
} else {
res.add(access);
}
} else if (expr instanceof CtBinaryOperator) {
CtBinaryOperator<?> op = (CtBinaryOperator<?>) expr;
res.addAll(findUsedVar(op.getLeftHandOperand()));
res.addAll(findUsedVar(op.getRightHandOperand()));
} else if (expr instanceof CtUnaryOperator) {// Added to get all
// conditions of a
// command in Command
// class
CtUnaryOperator<?> unary = (CtUnaryOperator<?>) expr;
res.addAll(findUsedVar(unary.getOperand()));
} else if (expr instanceof CtInvocation) {
CtInvocation<?> invoke = (CtInvocation<?>) expr;
res.addAll(findUsedVar(invoke.getTarget()));
for (Object param : invoke.getArguments()) {
res.addAll(findUsedVar((CtExpression<?>) param));
}
} else if (expr instanceof CtVariableAccess) {
res.add((CtVariableAccess<?>) expr);
}
return res;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:37,代码来源:DefUse.java
示例11: getDeepDef
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Get attributes & methods parameters dependences for variable access in
* this condition
*/
public Set<CtVariable<?>> getDeepDef(CtExpression<?> condition) {
Set<CtVariable<?>> res = new HashSet<>();
List<CtVariableAccess<?>> vars = findUsedVar(condition);
for (CtVariableAccess<?> var : vars) {
res.addAll(getDeepDef(var));
}
return res;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:15,代码来源:DefUse.java
示例12: getAllTerminalStatements
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Return statements that are not used by another.
*/
public Set<CtCodeElement> getAllTerminalStatements() {
Set<CtCodeElement> res = new HashSet<>();
for (BasicBlock block : cfg.getAllNode()) {
for (CtCodeElement line : block.getElements()) {
// Add this line to candidates statements
res.add(line);
// Remove statements which are dependencies
List<CtVariableAccess<?>> vars = getUsedVariables(line);
if (vars != null && !vars.isEmpty()) {
for (CtVariableAccess<?> var : vars) {
Set<CtCodeElement> defs = reachingDef.get(var);
if (defs != null) {
for (CtCodeElement def : defs) {
if (res.contains(def))
res.remove(def);
}
}
}
}
}
}
return res;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:32,代码来源:DefUse.java
示例13: isControlledBy
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Must return true if the field is used in @action's conditionals and not
* defined in the @action's method
*/
public boolean isControlledBy(Action action, CtAssignment<?, ?> fieldAssignment) {// TODO:
// move
// to
// Action
CtField<?> field = null;
CtExpression<?> leftPart = fieldAssignment.getAssigned();
if (leftPart instanceof CtFieldAccess) {
field = ((CtFieldAccess<?>) leftPart).getVariable().getDeclaration();
}
for (CtExpression<?> cond : action.getConditions()) {
List<CtVariableAccess<?>> usedVars = defuse.findUsedVar(cond);
for (CtVariableAccess<?> usedVar : usedVars) {
// if(field != null && field ==
// usedVar.getVariable().getDeclaration()){
// Set<CtCodeElement> lastDef = defuse.getReachingDef(usedVar);
// if(lastDef == null) return true;
// }
Set<CtVariable<?>> allDep = defuse.getDeepDef(usedVar);
if (field != null && allDep.contains(field))
return true;
}
}
return false;
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:34,代码来源:MethodSummary.java
示例14: extractUsagesOfVar
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
public List<CtVariableAccess<?>> extractUsagesOfVar(final @NotNull CtVariable<?> var) {
CtElement parent;
if(var instanceof CtLocalVariable<?>) {
parent = var.getParent(CtBlock.class);
}else {
if(var.getVisibility() == null) {
parent = var.getParent(CtPackage.class);
if(parent == null) parent = var.getParent(CtClass.class);
}else {
switch(var.getVisibility()) {
case PRIVATE:
parent = var.getParent(CtClass.class);
break;
case PROTECTED:
parent = var.getParent(CtPackage.class);
if(parent == null) parent = var.getParent(CtClass.class);
break;
case PUBLIC:
parent = var.getFactory().Package().getRootPackage();
break;
default:
parent = null;
break;
}
}
}
if(parent != null) {
return parent.getElements(new MyVariableAccessFilter(var));
}
return Collections.emptyList();
}
开发者ID:diverse-project,项目名称:InspectorGuidget,代码行数:35,代码来源:SpoonHelper.java
示例15: 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
示例16: formatIngredient
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void formatIngredient(CtElement ingredientCtElement) {
// log.debug("\n------" + ingredientCtElement);
List<CtVariableAccess> varAccessCollected = VariableResolver.collectVariableAccess(ingredientCtElement, true);
Map<String, String> varMappings = new HashMap<>();
int nrvar = 0;
for (int i = 0; i < varAccessCollected.size(); i++) {
CtVariableAccess var = varAccessCollected.get(i);
if (VariableResolver.isStatic(var.getVariable())) {
continue;
}
String abstractName = "";
if (!varMappings.containsKey(var.getVariable().getSimpleName())) {
String currentTypeName = var.getVariable().getType().getSimpleName();
if (currentTypeName.contains("?")) {
// Any change in case of ?
abstractName = var.getVariable().getSimpleName();
} else {
abstractName = "_" + currentTypeName + "_" + nrvar;
}
varMappings.put(var.getVariable().getSimpleName(), abstractName);
nrvar++;
} else {
abstractName = varMappings.get(var.getVariable().getSimpleName());
}
var.getVariable().setSimpleName(abstractName);
// workaround: Problems with var Shadowing
var.getFactory().getEnvironment().setNoClasspath(true);
if (var instanceof CtFieldAccess) {
CtFieldAccess fieldAccess = (CtFieldAccess) var;
fieldAccess.getVariable().setDeclaringType(null);
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:41,代码来源:ExpressionTypeIngredientSpace.java
示例17: getCode
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
@Override
public CtElement getCode() {
if (this.code == null) {
Map<String, CtVariable> selectedTransformation = this.combination.getCombination();
Map<VarAccessWrapper, CtVariableAccess> originalMap = VariableResolver.convertIngredient(mapping,
selectedTransformation);
// Cloned transformed element
this.code = MutationSupporter.clone((CtCodeElement) this.baseIngredient);
VariableResolver.resetIngredient(originalMap);
}
return this.code;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:DynamicIngredient.java
示例18: getNGramsFromCodeElements
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Obtain all n-gram of the element give as parameter according to the
* ingredient processor also passed as argument. The results (n-grams) are
* stored in the ngram stored passed as argument
*
* @param codeToProcess
* @param ngramStore
* @param ingp
* @return
*/
private int getNGramsFromCodeElements(CtElement codeToProcess, NGrams ngramStore, IngredientProcessor ingp) {
int allElements = 0;
List<CtCodeElement> elementsFromSpace = ingp.createFixSpace(codeToProcess, false);
for (CtCodeElement ctCodeElement : elementsFromSpace) {
List<CtVariableAccess> vars = VariableResolver.collectVariableAccess(ctCodeElement);
if (vars.isEmpty())
continue;
if (vars.size() > ConfigurationProperties.getPropertyDouble("maxnumvariablesperingredient")) {
logger.debug("Attention, Large Ingredient discarted: \n" + ctCodeElement.getShortRepresentation());
continue;
}
cleanParenthesis(vars);
sortVarsByNames(vars);
for (int i = vars.size(); i >= 1; i--) {
List allpermutations = getPermutationsOfVarNames(vars, i);
ngramStore.add(allpermutations, i);
}
//logger.debug("\n: "+ctCodeElement+ " ng" + ngramStore);
allElements++;
}
return allElements;
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:41,代码来源:GramProcessor.java
示例19: cleanParenthesis
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Remove parenthesis from a var access. e.g. (a)
*
* @param vars
*/
private void cleanParenthesis(List<CtVariableAccess> vars) {
for (CtVariableAccess ctVariableAccess : vars) {
String name = ctVariableAccess.getVariable().getSimpleName();
if (name.startsWith("(")) {
int l = name.length();
String nm = name.substring(1, l - 2);
}
}
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:GramProcessor.java
示例20: sortVarsByNames
import spoon.reflect.code.CtVariableAccess; //导入依赖的package包/类
/**
* Order the var access list by name.
*
* @param vars
*/
public void sortVarsByNames(List<CtVariableAccess> vars) {
Collections.sort(vars, new Comparator<CtVariableAccess>() {
@Override
public int compare(CtVariableAccess o1, CtVariableAccess o2) {
return o1.getVariable().getSimpleName().compareTo(o2.getVariable().getSimpleName());
}
});
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:GramProcessor.java
注:本文中的spoon.reflect.code.CtVariableAccess类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论