spoon.reflect.reference.CtTypeReference Java Examples

The following examples show how to use spoon.reflect.reference.CtTypeReference. 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: VariablesInSuspiciousCollector.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * get all dependencies added by a CtTypedElement
 *
 * @param element
 * @return all dependencies added by element
 */
private List<CtTypeReference<?>> getDependencies(CtTypedElement<?> element) {
    List<CtTypeReference<?>> listDependencies = new ArrayList<>();
    // Literal
    if (element instanceof CtAnnotation) {
        return listDependencies;
    }
    if (element instanceof CtLiteral<?>) {
        CtLiteral<?> literal = (CtLiteral<?>) element;
        literal.getValue();
        if (literal.getValue() instanceof CtTypeReference<?>) {
            listDependencies.add((CtTypeReference<?>) literal.getValue());
        } else if (literal.getValue() instanceof CtTypedElement<?>) {
            listDependencies.add(((CtTypedElement<?>) literal.getValue())
                    .getType());
        }
    }
    // method invocation
    if (element instanceof CtInvocation<?>) {
        CtInvocation<?> invocation = (CtInvocation<?>) element;
        // the class of the method
        listDependencies.add(invocation.getExecutable().getDeclaringType());
    }
    listDependencies.add(element.getType());
    return listDependencies;
}
 
Example #2
Source File: LogicalExpressionMetaMutator.java    From metamutator with GNU General Public License v3.0 6 votes vote down vote up
private boolean isNumber(CtExpression<?> operand) {

	if (operand.getType().toString().equals(CtTypeReference.NULL_TYPE_NAME))
		return false;
	
	if (operand.toString().contains(".class"))
		return false;
			
	return operand.getType().getSimpleName().equals("int")
		|| operand.getType().getSimpleName().equals("long")
		|| operand.getType().getSimpleName().equals("byte")
		|| operand.getType().getSimpleName().equals("char")
	|| operand.getType().getSimpleName().equals("float")
	|| operand.getType().getSimpleName().equals("double")
	|| operand.getType().isSubtypeOf(getFactory().Type().createReference(Number.class));
}
 
Example #3
Source File: NumericVariableMetaMutator.java    From metamutator with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Accept Numeric Variable
 */
@Override
public boolean isToBeProcessed(CtVariableRead candidate) {
	
	// SKIP not declared variable and Finale variable
	if(candidate.getVariable() == null) return false;

	if(candidate.getVariable().getSimpleName().equals("class")) return false;

	if(candidate.getVariable().getModifiers().contains(ModifierKind.FINAL)) return false;
	
	
	// SKIP IF VARIABLE IS CASTED
	if(candidate.getTypeCasts().size() > 0) return false;
	for(CtTypeReference type : candidate.getReferencedTypes()) {
		if(!this.isNumber(type)) return false;
	}
	
	if( candidate.getParent().getClass().equals(CtUnaryOperatorImpl.class)) return false;
	
	if(this.isNumber(candidate.getVariable().getType())){
		return true;
	}
	return false;
}
 
Example #4
Source File: SpoonReferenceLibrary.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isVisibleFrom(CtTypeReference<?> accessingClass, CtModifiable modifiable, CtTypeReference<?> declaringClass, CtTypeReference<?> actualClass) {
    if (hasPublicModifier(modifiable)) {
        return true;
    }
    if ((isNestedIn(accessingClass, actualClass) || isNestedIn(actualClass, accessingClass)) && areSameClass(declaringClass, actualClass)) {
        return true;
    }
    if (hasNoVisibilityModifier(modifiable) && areFromSamePackage(declaringClass, actualClass) && areFromSamePackage(actualClass, accessingClass)) {
        return true;
    }
    if (hasPrivateModifier(modifiable) && areSameClass(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && areFromSamePackage(declaringClass, accessingClass)) {
        return true;
    }
    if (hasProtectedModifier(modifiable) && isSubclassOf(declaringClass, accessingClass) && areSameClass(actualClass, accessingClass)) {
        return true;
    }
    return false;
}
 
Example #5
Source File: ClassCollector.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * get all dependencies added by a CtTypedElement
 *
 * @param element
 * @return all dependencies added by element
 */
private List<CtTypeReference<?>> getDependencies(CtTypedElement<?> element) {
    List<CtTypeReference<?>> listDependencies = new ArrayList<>();
    // Literal
    if (element instanceof CtAnnotation) {
        return listDependencies;
    }
    if (element instanceof CtLiteral<?>) {
        CtLiteral<?> literal = (CtLiteral<?>) element;
        literal.getValue();
        if (literal.getValue() instanceof CtTypeReference<?>) {
            listDependencies.add((CtTypeReference<?>) literal.getValue());
        } else if (literal.getValue() instanceof CtTypedElement<?>) {
            listDependencies.add(((CtTypedElement<?>) literal.getValue())
                    .getType());
        }
    }
    // method invocation
    if (element instanceof CtInvocation<?>) {
        CtInvocation<?> invocation = (CtInvocation<?>) element;
        // the class of the method
        listDependencies.add(invocation.getExecutable().getDeclaringType());
    }
    listDependencies.add(element.getType());
    return listDependencies;
}
 
Example #6
Source File: MethodCollector.java    From nopol with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void process(CtInvocation ctElement) {
    CtExecutableReference executable = ctElement.getExecutable();
    if (executable.isConstructor()) {
        return;
    }
    String key = executable.toString();
    CtTypeReference declaringType = executable.getDeclaringType();
    if (declaringType.getPackage() != null) {
        key = declaringType.getPackage().getSimpleName() + "." + executable.getSimpleName();
    }
    if (!statMethod.containsKey(key)) {
        statMethod.put(key, 1);
    } else {
        statMethod.put(key, statMethod.get(key) + 1);
    }
}
 
Example #7
Source File: QueryExampleTest.java    From spoon-examples with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("all")
@Test
public void main() {
    MavenLauncher launcher = new MavenLauncher(
            "./src/test/resources/project/",
            MavenLauncher.SOURCE_TYPE.APP_SOURCE);

    CtModel model = launcher.buildModel();
    List<CtMethod> methodList = model.
            filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "ow2con")).
            filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "publicapi")).
            filterChildren(new TypeFilter<CtMethod>(CtMethod.class)).
            filterChildren(new Filter<CtMethod>() {
                @Override
                public boolean matches(CtMethod element) {
                    boolean isPublic = element.isPublic();
                    CtTypeReference returnType = element.getType();
                    String privateApiPackage = "ow2con.privateapi";
                    boolean isTypeFromPrivateApi = returnType.getQualifiedName().contains(privateApiPackage);
                    return isPublic && isTypeFromPrivateApi;
                }
            }).list();
}
 
Example #8
Source File: ReferenceProcessor.java    From spoon-examples with GNU General Public License v2.0 6 votes vote down vote up
public void process(CtPackage element) {
	CtPackageReference pack = element.getReference();
	Set<CtPackageReference> refs = new HashSet<>();
	for (CtType t : element.getTypes()) {
		List<CtTypeReference<?>> listReferences = Query.getReferences(t, new ReferenceTypeFilter<>(CtTypeReference.class));

		for (CtTypeReference<?> tref : listReferences) {
			if (tref.getPackage() != null && !tref.getPackage().equals(pack)) {
				if (ignoredTypes.contains(tref))
					continue;
				refs.add(tref.getPackage());
			}
		}
	}
	if (!refs.isEmpty()) {
		packRefs.put(pack, refs);
	}
}
 
Example #9
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 #10
Source File: VariableResolver.java    From coming with MIT License 6 votes vote down vote up
/**
 * 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 #11
Source File: AbstractCodeAnalyzer.java    From coming with MIT License 6 votes vote down vote up
public CtInvocation checkInvocationWithParemetrCompatibleType(List<CtInvocation> invocationsFromClass,
		CtTypeReference type) {

	for (CtInvocation anInvocation : invocationsFromClass) {

		for (Object anObjArgument : anInvocation.getArguments()) {
			CtExpression anArgument = (CtExpression) anObjArgument;

			if (compareTypes(type, anArgument.getType())) {
				return anInvocation;
			}
		}
	}

	return null;
}
 
Example #12
Source File: NodeCreator.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
@Override
public <T> void visitCtMethod(CtMethod<T> e) {
	// add the return type of the method
	CtTypeReference<T> type = e.getType();
	if (type != null) {
		ITree returnType = builder.createNode("RETURN_TYPE", type.getQualifiedName());
		returnType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, type);
		type.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, returnType);
		builder.addSiblingNode(returnType);
	}

	for (CtTypeReference thrown : e.getThrownTypes()) {
		ITree thrownType = builder.createNode("THROWS", thrown.getQualifiedName());
		thrownType.setMetadata(SpoonGumTreeBuilder.SPOON_OBJECT, thrown);
		type.putMetadata(SpoonGumTreeBuilder.GUMTREE_NODE, thrownType);
		builder.addSiblingNode(thrownType);
	}

	super.visitCtMethod(e);
}
 
Example #13
Source File: LogicalExpressionAnalyzer.java    From coming with MIT License 5 votes vote down vote up
public static boolean whetherpotentionalboolean(List<CtTypeReference> potentionaltypes) {
	
	for(int i=0; i<potentionaltypes.size(); i++) {
		
		if(potentionaltypes.get(i)!=null && (potentionaltypes.get(i).getSimpleName().equals("Boolean") ||
				potentionaltypes.get(i).unbox().toString().equals("boolean")))
			return true;
	}
	
	return false;
}
 
Example #14
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public static boolean areTypesCompatible(CtTypeReference type1, CtTypeReference type2) {
	try {// Check if an existing variable (name taken from
			// cluster)
			// is compatible with with that one out of scope

		boolean bothArray = false;
		boolean notCompatible = false;
		do {
			// We check if types are arrays.
			boolean clusterIsArray = type1 instanceof CtArrayTypeReference;
			boolean ourIsArray = type2 instanceof CtArrayTypeReference;

			if (clusterIsArray ^ ourIsArray) {
				notCompatible = true;

			}
			// if both are arrays, we extract the component
			// type, and we compare it again
			bothArray = clusterIsArray && ourIsArray;
			if (bothArray) {
				type1 = ((CtArrayTypeReference) type1).getComponentType();
				type2 = ((CtArrayTypeReference) type2).getComponentType();
			}

		} while (bothArray);

		if (notCompatible)
			return false;

		if (type1.isSubtypeOf(type2)) {
			return true;
		}
	} catch (Exception e) {
		logger.error(e);
	}
	return false;
}
 
Example #15
Source File: SupportOperators.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public static List<List<CtExpression<?>>> createAllParametersCombinations(List<CtParameter> parameterType,
		MapList<CtTypeReference, CtElement> candidateMappings) {
	List<List<CtExpression<?>>> candidateArguments = new ArrayList();

	long maxCombinations = getMaxCombinations(parameterType, candidateMappings);
	// number of arguments
	for (int i = 0; i < maxCombinations; i++) {
		List<CtExpression<?>> callArguments = new ArrayList();
		for (CtParameter ctTypeParameter : parameterType) {

			List<CtElement> compVar = candidateMappings.get(ctTypeParameter.getType());
			CtElement elSelected = compVar.get(RandomManager.nextInt(compVar.size()));
			if (elSelected instanceof CtVariable) {
				CtVariable varSelected = (CtVariable) elSelected;
				callArguments.add(MutationSupporter.getFactory().createVariableRead(varSelected.getReference(),
						varSelected.isStatic()));
			} else {
				if (elSelected instanceof CtExpression) {
					// for the moment, we dont clone
					callArguments.add((CtExpression<?>) elSelected);
				}
			}

		}
		// check if the arguments are not already considered
		if (!candidateArguments.contains(callArguments)) {
			candidateArguments.add(callArguments);
		}
	}
	return candidateArguments;
}
 
Example #16
Source File: ClassCollector.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(CtTypedElement element) {
    List<CtTypeReference<?>> listDependencies = getDependencies(element);

    CtTypeReference<Exception> exception = getFactory().Class().createReference(Exception.class);
    for (CtTypeReference<?> ctTypeReference : listDependencies) {
        if (ctTypeReference == null) {
            continue;
        }
        if (ctTypeReference.isPrimitive()) {
            continue;
        }
        if (ctTypeReference.toString().equals("<nulltype>")) {
            continue;
        }
        if (exception.isSubtypeOf(ctTypeReference)) {
            continue;
        }
        if (classes.contains(ctTypeReference.getQualifiedName())) {
            return;
        }
        if (classes.add(ctTypeReference.getQualifiedName())) {
            logger.debug("[class] " + ctTypeReference.getQualifiedName());
        }
    }

}
 
Example #17
Source File: SupportOperators.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public static boolean checkIsSubtype(CtTypeReference typeCurrent, CtTypeReference typeToBeReturned) {
	try {
		return typeCurrent != null && typeToBeReturned != null
				&& (typeCurrent.toString().equals(typeToBeReturned.toString())
						|| typeCurrent.equals(typeToBeReturned) || typeCurrent.isSubtypeOf(typeToBeReturned));
	} catch (Exception e) {
		System.out.println("Error comparing types");
		e.printStackTrace();
		return false;
	}
}
 
Example #18
Source File: VariabletoNullMetaMutator.java    From metamutator with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isToBeProcessed(CtStatement element) {
	// if (element.getParent(CtAnonymousExecutable.class)!=null) {
			// System.out.println(element.getParent(CtAnonymousExecutable.class));
			// }
	
			if(!(element instanceof CtRHSReceiver))
				return false;
			try {
				Selector.getTopLevelClass(element);
			} catch (Exception e) {
				return false;
			}

			// not in constructors because we use static fields
			if (element.getParent(CtConstructor.class) != null) {
				return false;
			}
			
			if (((CtRHSReceiver)element).getAssignment() == null)
				return false;
			
			CtTypeReference type = ((CtRHSReceiver)element).getAssignment().getType();
			
			if (type == null)
				return false;
			
			if (element.toString().contains("java.lang.String.format"))
				return false;

			return !((CtRHSReceiver)element).getAssignment().getType().isPrimitive() 
					&& (element.getParent(CtAnonymousExecutable.class) == null);
}
 
Example #19
Source File: VariableResolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return a list of variables that match with the variable access passed as
 * parameter. The last argument indicate if we map also the vars name
 * 
 * @param varContext
 * @param vartofind
 * @param mapName
 * @return
 */
protected static List<CtVariable> matchVariable(List<CtVariable> varContext, CtVariableAccess vartofind,
		boolean mapName) {
	List<CtVariable> varMatched = new ArrayList<>();
	try {
		CtTypeReference typeToFind = vartofind.getType();

		// First we search for compatible variables according to the type
		List<CtVariable> types = compatiblesSubType(varContext, typeToFind);
		if (types.isEmpty()) {
			return varMatched;
		}
		// Then, we search
		for (CtVariable ctVariableWithTypes : types) {
			// comparing name is optional, according to argument.
			boolean matchName = !mapName
					|| ctVariableWithTypes.getSimpleName().equals(vartofind.getVariable().getSimpleName());
			if (matchName) {
				varMatched.add(ctVariableWithTypes);
			}
		}

	} catch (Exception ex) {
		logger.error("Variable verification error", ex);
	}

	return varMatched;
}
 
Example #20
Source File: Spoonerism.java    From spoon-examples with GNU General Public License v2.0 5 votes vote down vote up
Spoonerism extendTestingClasses() {
    // Now we need to extend the classes.
    // WARNING: There is a small problem with this, can you spot it?
    // Answer at bottom
    CtTypeReference<?> baseTestingClassRef =
            baseTestingClass.getReference();
    for (CtClass<?> ctClass: testingClasses) {
        if (ctClass.getSuperclass() == null) {
            ctClass.setSuperclass(baseTestingClassRef);
        }
    }
    return this;
}
 
Example #21
Source File: MultiMetaEvalTOSApproach.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * Creates ingredients according to the TypeReference of an element. The
 * ingredients are valid in the modification point location. TODO: Move to the
 * operator?
 * 
 * @param parentVariant
 * @param iModifPoint
 * @param targetType
 * @return
 */
public List<IngredientFromDyna> synthesizeCandidatesIngredientsFromType(ProgramVariant parentVariant,
		ModificationPoint iModifPoint, DynaIngredientPool clusterEvaluatedExpressions, CtTypeReference targetType) {

	List<IngredientFromDyna> newIngredientsResult = new ArrayList<>();

	// for (String i_testName : clusterEvaluatedExpressions.keySet()) {
	// TODO: see how to modify this

	if (clusterEvaluatedExpressions == null
			|| clusterEvaluatedExpressions.getClusterEvaluatedExpressions() == null) {
		return newIngredientsResult;
	}

	for (ClusterExpressions i_cluster : clusterEvaluatedExpressions.getClusterEvaluatedExpressions()) {

		if (i_cluster.size() > 0) {
			EvaluatedExpression firstExpressionOfCluster = i_cluster.get(0);

			operationsExecuted++;

			// let's check the types
			String classofExpression = i_cluster.getClusterType();

			String classofiHole = targetType.box().getQualifiedName();

			if (!ConfigurationProperties.getPropertyBool("avoidtypecomparison")// In case that we dont want
																				// to compare hole types
					&& !classofiHole.equals(classofExpression)) {
				continue;
			}

			IngredientFromDyna ingredientSynthesized = createIngredient(firstExpressionOfCluster);
			newIngredientsResult.add(ingredientSynthesized);

		}
		// }
	}
	return newIngredientsResult;
}
 
Example #22
Source File: NumericVariableMetaMutator.java    From metamutator with GNU General Public License v3.0 5 votes vote down vote up
public boolean isNumber(CtTypeReference type) {
	return type.getSimpleName().equals("int")
		|| type.getSimpleName().equals("long")
		|| type.getSimpleName().equals("byte")
	|| type.getSimpleName().equals("float")
	|| type.getSimpleName().equals("double");
}
 
Example #23
Source File: InvocationResolver.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public static InvocationMatching mapImplicitInvocation(CtClass ctClassMP, CtAbstractInvocation inv0) {
	if (inv0 instanceof CtInvocation) {
		CtInvocation invocation0 = (CtInvocation) inv0;

		CtExpression tpr = invocation0.getTarget();
		if (tpr instanceof CtThisAccess) {
			CtThisAccess<?> targetthis = (CtThisAccess) tpr;
			CtTypeReference tpref = targetthis.getType();
			if (ctClassMP.isSubtypeOf(tpref))
				return InvocationMatching.TARGET_SAME_TYPE;
			else if (chechSignatures(ctClassMP.getAllExecutables(), invocation0.getExecutable(), false)) {
				return InvocationMatching.SAME_SIGNATURE_FROM_DIFF_TYPE;
			} else {
				log.debug("Signature " + invocation0.getExecutable().getSignature());
				log.debug(
						"Not compatible: " + ctClassMP.getQualifiedName() + " with " + (tpref.getQualifiedName()));
				return InvocationMatching.TARGET_INCOMPATIBLE;
			}
		} else {
			log.debug("Explicit target " + tpr);
			return InvocationMatching.TARGET_IS_VARIABLE;
		}
	} else {

		if (inv0 instanceof CtConstructorCall) {
			return InvocationMatching.CONTRUCTOR;

		}

		return InvocationMatching.OTHER;
	}

}
 
Example #24
Source File: WrapwithIfNullCheck.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
	public List<MetaOperatorInstance> createMetaOperatorInstances(ModificationPoint modificationPoint) {

		//
		CtElement codeElement = (targetElement == null) ? modificationPoint.getCodeElement() : targetElement;

		List<CtVariableAccess> varAccessInModificationPoints = VariableResolver.collectVariableAccess(codeElement);

		List<Ingredient> ingredients = this.computeIngredientsNullCheck(modificationPoint,
				varAccessInModificationPoints);

		// The parameters to be included in the new method
		List<CtVariableAccess> varsToBeParameters = varAccessInModificationPoints;

		// List of parameters
		List<CtParameter<?>> parameters = new ArrayList<>();
		List<CtExpression<?>> realParameters = new ArrayList<>();
		for (CtVariableAccess ctVariableAccess : varsToBeParameters) {
			// the parent is null, it is setter latter
			CtParameter pari = MutationSupporter.getFactory().createParameter(null, ctVariableAccess.getType(),
					ctVariableAccess.getVariable().getSimpleName());
			parameters.add(pari);
			realParameters.add(ctVariableAccess.clone().setPositions(new NoSourcePosition()));
		}
///
		// let's start with one, and let's keep the Zero for the default (all ifs are
		// false)
		int candidateNumber = 0;
		CtTypeReference returnType = MutationSupporter.getFactory().createCtTypeReference(Boolean.class);

		MetaOperatorInstance megaOp = MetaGenerator.createMetaStatementReplacement(modificationPoint, codeElement,
				MutationSupporter.getFactory().createCodeSnippetExpression("true"), candidateNumber, ingredients,
				parameters, realParameters, this, returnType);
		List<MetaOperatorInstance> opsMega = new ArrayList();
		opsMega.add(megaOp);

		return opsMega;
	}
 
Example #25
Source File: VariableResolver.java    From coming with MIT License 5 votes vote down vote up
public static boolean areTypesCompatible(CtTypeReference type1, CtTypeReference type2) {
	try {// Check if an existing variable (name taken from
			// cluster)
			// is compatible with with that one out of scope

		boolean bothArray = false;
		boolean notCompatible = false;
		do {
			// We check if types are arrays.
			boolean clusterIsArray = type1 instanceof CtArrayTypeReference;
			boolean ourIsArray = type2 instanceof CtArrayTypeReference;

			if (clusterIsArray ^ ourIsArray) {
				notCompatible = true;

			}
			// if both are arrays, we extract the component
			// type, and we compare it again
			bothArray = clusterIsArray && ourIsArray;
			if (bothArray) {
				type1 = ((CtArrayTypeReference) type1).getComponentType();
				type2 = ((CtArrayTypeReference) type2).getComponentType();
			}

		} while (bothArray);

		if (notCompatible)
			return false;

		if (type1.isSubtypeOf(type2)) {
			return true;
		}
	} catch (Exception e) {
		logger.error(e);
	}
	return false;
}
 
Example #26
Source File: LabelFinder.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void visitCtInvocation(CtInvocation<T> invocation) {
	if (invocation.getExecutable() != null) {
		CtTypeReference decl = invocation.getExecutable().getDeclaringType();
		// label =
		// (decl!=null?decl.getQualifiedName():"")+"#"+invocation.getExecutable().getSignature();
		// label = (decl != null ? decl.getQualifiedName() : "") + "#" +
		// invocation.getExecutable().getSimpleName();
		label = invocation.getExecutable().getSimpleName();

	}
}
 
Example #27
Source File: VariableAnalyzer.java    From coming with MIT License 5 votes vote down vote up
public CtMethod checkMethodDeclarationWithReturnCompatibleType(List allMethods, CtTypeReference typeToMatch) {
	for (Object omethod : allMethods) {

		if (!(omethod instanceof CtMethod))
			continue;

		CtMethod anotherMethodInBuggyClass = (CtMethod) omethod;

		if (compareTypes(typeToMatch, anotherMethodInBuggyClass.getType())) {

			return anotherMethodInBuggyClass;
		}
	}
	return null;
}
 
Example #28
Source File: SupportOperators.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private static long getMaxCombinations(List<CtParameter> parameterType, MapList<CtTypeReference, CtElement> types) {

		long max = 1;
		for (CtParameter ctTypeParameter : parameterType) {

			max *= types.get(ctTypeParameter.getType()).size();

		}
		int maxComb = ConfigurationProperties.getPropertyInt("maxVarCombination");
		if (max > maxComb || max < 0) {
			return (int) maxComb;
		}

		return max;
	}
 
Example #29
Source File: BoundTemplate.java    From spoon-examples with GNU General Public License v2.0 5 votes vote down vote up
@Local
public BoundTemplate(CtTypeReference<Double> typeReference, String parameterName, double minBound, double maxBound) {
	this.typeReference = typeReference;
	_parameter_ = parameterName;
	_maxBound_ = maxBound;
	_minBound_ = minBound;
}
 
Example #30
Source File: SpoonElementLibrary.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
public static CtTypeReference<?> typeOf(CtElement element) {
    if (isSimpleType(element)) {
        return ((CtType<?>) element).getReference();
    }
    if (isTypedElement(element)) {
        return ((CtTypedElement<?>) element).getType();
    }
    return typeOf(parentOfType(CtType.class, element));
}