Java Code Examples for spoon.reflect.declaration.CtVariable#getType()
The following examples show how to use
spoon.reflect.declaration.CtVariable#getType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariableResolver.java From coming with MIT License | 6 votes |
/** * For a given VariableAccess, we search the list of Variables contains * compatible types (i.e. sub types) * * @param varContext * @param vartofind * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected static List<CtVariable> compatiblesSubType(List<CtVariable> varContext, CtTypeReference typeToFind) { List<CtVariable> result = new ArrayList<CtVariable>(); for (CtVariable ctVariable_i : varContext) { CtTypeReference typeref_i = ctVariable_i.getType(); try { if (typeref_i.isSubtypeOf(typeToFind)) { result.add(ctVariable_i); } } catch (Exception e) { result.add(ctVariable_i); } } return result; }
Example 2
Source File: VariableResolver.java From astor with GNU General Public License v2.0 | 6 votes |
/** * For a given VariableAccess, we search the list of Variables contains * compatible types (i.e. sub types) * * @param varContext * @param vartofind * @return */ @SuppressWarnings({ "rawtypes", "unchecked" }) protected static List<CtVariable> compatiblesSubType(List<CtVariable> varContext, CtTypeReference typeToFind) { List<CtVariable> result = new ArrayList<CtVariable>(); for (CtVariable ctVariable_i : varContext) { CtTypeReference typeref_i = ctVariable_i.getType(); try { if (typeref_i.isSubtypeOf(typeToFind)) { result.add(ctVariable_i); } } catch (Exception e) { result.add(ctVariable_i); } } return result; }
Example 3
Source File: NodeCreator.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
@Override public <T> void scanCtVariable(CtVariable<T> e) { CtTypeReference<T> type = e.getType(); if (type != null) { ITree variableType = builder.createNode("VARIABLE_TYPE", type.getQualifiedName()); variableType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, type); type.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, variableType); builder.addSiblingNode(variableType); } }
Example 4
Source File: SupportOperators.java From astor with GNU General Public License v2.0 | 4 votes |
public static List<CtInvocation> retrieveInvocationsFromVar(CtTypeReference variableToReplaceType, CtClass classUnderAnalysis, ModificationPoint point) { List<CtInvocation> newInvocations = new ArrayList<>(); List<CtVariable> variablesInScope = point.getContextOfModificationPoint(); boolean isParentMethodStatic = isParentMethodStatic(point.getCodeElement()); for (CtVariable varInScope : variablesInScope) { if (varInScope.getType() == null || varInScope.getType().isPrimitive()) { continue; } // if (isParentMethodStatic && // !varInScope.getModifiers().contains(ModifierKind.STATIC)) { // if the modification point is in a static method, the variable to target must // be // static continue; } // List<CtMethod> allMethods = varInScope.getType().getAllExecutables().stream() .filter(e -> e.getExecutableDeclaration() instanceof CtMethod) .map(e -> e.getExecutableDeclaration()).map(CtMethod.class::cast).collect(Collectors.toList()); for (CtMethod anotherMethod : allMethods) { if (anotherMethod.getSimpleName().startsWith(VarReplacementByMethodCallOp.META_METHOD_LABEL)) // It's a meta-method, discard continue; if (!anotherMethod.isPublic()) continue; boolean compatibleReturnTypes = SupportOperators.checkIsSubtype(anotherMethod.getType(), variableToReplaceType); if (compatibleReturnTypes) { List<CtInvocation> newInvToMethods = createRealInvocationsAllPosibilities(point, anotherMethod, MutationSupporter.getFactory().createVariableRead(varInScope.getReference(), varInScope.isStatic())); newInvocations.addAll(newInvToMethods); } } } return newInvocations; }
Example 5
Source File: VariableResolver.java From coming with MIT License | 3 votes |
/** * Return true if the variables are compatible * * @param varOutScope * @param varInScope * @return */ public static boolean areVarsCompatible(CtVariableAccess varOutScope, CtVariable varInScope) { CtTypeReference refCluster = varInScope.getType(); CtTypeReference refOut = varOutScope.getType(); return areTypesCompatible(refCluster, refOut); }
Example 6
Source File: VariableResolver.java From astor with GNU General Public License v2.0 | 3 votes |
/** * Return true if the variables are compatible * * @param varOutScope * @param varInScope * @return */ public static boolean areVarsCompatible(CtVariableAccess varOutScope, CtVariable varInScope) { CtTypeReference refCluster = varInScope.getType(); CtTypeReference refOut = varOutScope.getType(); return areTypesCompatible(refCluster, refOut); }