Java Code Examples for spoon.reflect.declaration.CtMethod

The following examples show how to use spoon.reflect.declaration.CtMethod. These examples are extracted from open source projects. 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
@Override
public void process(final CtMethod<?> method) {
  final CtAnnotation<Annotation> annotation = getFactory().Code().createAnnotation(getFactory().Code().createCtTypeReference(ApiModelProperty.class));

  final String fieldName = uncapitalize(removeStart(method.getSimpleName(), "get"));
  final String classFqn = TypeHelper.getClassname(method);

  final Map<String, ParameterDescription> docs = context.getDtoDocumentation().get(classFqn);
  if (docs != null) {
    final ParameterDescription parameterDescription = docs.get(fieldName);
    if (parameterDescription != null) {
      log.debug("Found parameter description for {} {}", classFqn, fieldName);
      annotation.addValue("value", parameterDescription.getDescription());
      if (parameterDescription.getRequired() != null) {
        annotation.addValue("required", parameterDescription.getRequired().booleanValue());
      }
    }
  }

  annotation.addValue("name", fieldName);

  method.addAnnotation(annotation);
}
 
Example 2
Source Project: astor   Source File: SupportOperators.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static List<CtExpression> checkOcurrenceOfOtherParameters(CtMethod anotherMethod, CtMethod affectedMethod,
		List realParameters) {

	List newRealParameters = new ArrayList();

	for (Object parameterFromAnotherM : anotherMethod.getParameters()) {
		CtParameter parAnother = (CtParameter) parameterFromAnotherM;

		int indexOfParameter = affectedMethod.getParameters().indexOf(parAnother);
		// The parameter does not exist in the previous version
		if (indexOfParameter < 0) {
			return null;
		} else {
			CtExpression parameterAtI = (CtExpression) realParameters.get(indexOfParameter);
			newRealParameters.add(parameterAtI);
		}

	}
	// all parameters exist
	return newRealParameters;
}
 
Example 3
Source Project: gumtree-spoon-ast-diff   Source File: NodeCreator.java    License: 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 4
Source Project: astor   Source File: VarMappingTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testNotMappedVars() {
	// Testing Not Mapped variables
	// We get a method setup(UnivariateRealFunction f) for testing the
	// insertion of a ingredient out of scope
	CtMethod mSetup = getMethod4Test1(engine);
	assertNotNull(mSetup);
	CtStatement stmSetup = mSetup.getBody().getStatement(0);
	List<CtVariable> varsScopeStmSetup = VariableResolver.searchVariablesInScope(stmSetup);
	assertFalse(varsScopeStmSetup.isEmpty());
	// field: private static final String NULL_FUNCTION_MESSAGE, parameter
	// UnivariateRealFunction f
	assertEquals(2, varsScopeStmSetup.size());
	log.debug("context of Setup method " + varsScopeStmSetup);

	VarMapping vmapping3 = VariableResolver.mapVariablesUsingCluster(varsScopeStmSetup, otherClassElementC8);
	assertTrue(vmapping3.getMappedVariables().isEmpty());
	assertFalse(vmapping3.getNotMappedVariables().isEmpty());
	assertEquals(2, vmapping3.getNotMappedVariables().size());

}
 
Example 5
@SuppressWarnings({ "rawtypes", "unchecked" })
private void fetchLibOverload(CtInvocation call) {
       
	List<String> origTypes = resolveTypes(call.getArguments());
	CtExpression exp = call.getTarget();
	String typename=exp.getType().getQualifiedName();
	if(typename==null||typename.isEmpty())
		return;
	
       CtClass classname = parser.getClassMap().get(typename); 

	if(classname!=null) {
		Set<CtMethod> overloadmethods=classname.getMethods();
           for(CtMethod methodoverloaded : overloadmethods) {
           	if(call.getExecutable().getSimpleName().equals(methodoverloaded.getSimpleName())) {
           	  List<CtParameter> paramlist=methodoverloaded.getParameters();
           	  List<String> target=resolveParams(paramlist);
           	  transformOneMethod(origTypes,target, call);
           	}
           }
	} else {
		List<Class[]> params = parser.fetchMethods(typename, call.getExecutable().getSimpleName());
		for (Class[] p : params)
			transformOneConstructor(origTypes, call, p);
	}
}
 
Example 6
Source Project: nopol   Source File: TestSelectionProcessor.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean isToBeProcessed(CtMethod element){

    boolean isTest = false;
    for(CtAnnotation<? extends Annotation> annotation : element.getAnnotations()){
        if (annotation.getType().equals(annotation.getFactory().Annotation().createReference(org.junit.Test.class))) {
            isTest = true;
        }
    }

    if(!isTest){
        return false; //keep this one
    }

    for(CtMethod<?> method : keptMethods){
        if(element.getSignature().equals(method.getSignature())){
            return false; //keep this one
        }
    }

    return super.isToBeProcessed(element);
}
 
Example 7
Source Project: astor   Source File: MetaGenerator.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static CtInvocation creationInvocationToMega(ModificationPoint modificationPoint,
		List<CtExpression<?>> realParameters, CtMethod<?> megaMethod) {
	CtType target = modificationPoint.getCodeElement().getParent(CtType.class);
	CtExpression invocationTarget = MutationSupporter.getFactory().createThisAccess(target.getReference());

	// Here, we have to consider if the parent method is static.
	CtMethod parentMethod = modificationPoint.getCodeElement().getParent(CtMethod.class);
	if (parentMethod != null) {

		if (parentMethod.getModifiers().contains(ModifierKind.STATIC)) {
			// modifiers.add(ModifierKind.STATIC);
			invocationTarget = MutationSupporter.getFactory().createTypeAccess(target.getReference());

		}
	}

	// Invocation to mega

	CtInvocation newInvocationToMega = MutationSupporter.getFactory().createInvocation(invocationTarget,
			megaMethod.getReference(), realParameters);
	return newInvocationToMega;
}
 
Example 8
public void process(Bound annotation, CtParameter<?> element) {
	final CtMethod parent = element.getParent(CtMethod.class);

	// Build if check for min.
	CtIf anIf = getFactory().Core().createIf();
	anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " < " + annotation.min()));
	CtThrow throwStmt = getFactory().Core().createThrow();
	throwStmt.setThrownExpression((CtExpression<? extends Throwable>) getFactory().Core().createCodeSnippetExpression().setValue("new RuntimeException(\"out of min bound (\" + " + element.getSimpleName() + " + \" < " + annotation.min() + "\")"));
	anIf.setThenStatement(throwStmt);
	parent.getBody().insertBegin(anIf);
	anIf.setParent(parent);

	// Build if check for max.
	anIf = getFactory().Core().createIf();
	anIf.setCondition(getFactory().Code().<Boolean>createCodeSnippetExpression(element.getSimpleName() + " > " + annotation.max()));
	anIf.setThenStatement(getFactory().Code().createCtThrow("new RuntimeException(\"out of max bound (\" + " + element.getSimpleName() + " + \" > " + annotation.max() + "\")"));
	parent.getBody().insertBegin(anIf);
	anIf.setParent(parent);
}
 
Example 9
Source Project: coming   Source File: AbstractCodeAnalyzer.java    License: MIT License 6 votes vote down vote up
/**
 * Check if a method declaration has a parameter compatible and return with the
 * cttype as argument
 * 
 * @param allMethods
 * @param typeToMatch
 * @return
 */
public CtMethod checkMethodDeclarationWithParameterReturnCompatibleType(List allMethods,
		CtTypeReference typeToMatch) {
	for (Object omethod : allMethods) {

		if (!(omethod instanceof CtMethod))
			continue;

		CtMethod anotherMethodInBuggyClass = (CtMethod) omethod;

		// Check the parameters
		for (Object oparameter : anotherMethodInBuggyClass.getParameters()) {
			CtParameter parameter = (CtParameter) oparameter;

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

				return anotherMethodInBuggyClass;
			}
		}
	}

	return null;
}
 
Example 10
Source Project: coming   Source File: LogicalExpressionAnalyzer.java    License: MIT License 6 votes vote down vote up
/**
 * Check if a method declaration has a parameter compatible with that one from
 * the var affected
 * 
 * @param allMethods
 * @param varAffected
 * @return
 */
public CtMethod checkBooleanMethodDeclarationWithTypeInParameter(List allMethods, CtVariableAccess varAffected) {
	
	for (Object omethod : allMethods) {

		if (!(omethod instanceof CtMethod))
			continue;

		CtMethod anotherMethodInBuggyClass = (CtMethod) omethod;

		for (Object oparameter : anotherMethodInBuggyClass.getParameters()) {
			CtParameter parameter = (CtParameter) oparameter;

			if (compareTypes(varAffected.getType(), parameter.getType())) {
				if (anotherMethodInBuggyClass.getType().unbox().toString().equals("boolean")) {

					return anotherMethodInBuggyClass;
				}
			}
		}
	}
	return null;
}
 
Example 11
Source Project: coming   Source File: EnhancedRepairAnalyzer.java    License: MIT License 6 votes vote down vote up
public List<CtInvocation> getCandidateCalleeFunction(CtInvocation CE) {
    List<CtInvocation> ret = new ArrayList<>();

    CtMethod ownedMethod = CE.getParent(new TypeFilter<>(CtMethod.class));
    if (ownedMethod != null) {
        List<CtInvocation> invocations = ownedMethod.getElements(new TypeFilter<>(CtInvocation.class));
        for (CtInvocation invocation : invocations) {
            if (CE == invocation) {
                continue;
            }
            if (CE.getExecutable() != invocation.getExecutable()) {
                continue;
            }
            if (CE.getArguments().size() != invocation.getArguments().size()) {
                continue;
            }
            ret.add(invocation);
        }
    }
    return ret;
}
 
Example 12
Source Project: coming   Source File: EnhancedRepairGenerator.java    License: MIT License 6 votes vote down vote up
private Set<CtElement> fuzzyLocator(CtElement statement) {
    Set<CtElement> locations = new HashSet<>();
    if (statement instanceof CtMethod || statement instanceof CtClass || statement instanceof CtIf || statement instanceof CtStatementList) {
        locations.add(statement);
    } else {
        // "int a;" is not CtStatement?
        CtElement parent = statement.getParent();
        if (parent != null) {
            List<CtElement> statements = parent.getElements(new TypeFilter<>(CtElement.class));
            if (parent instanceof CtStatement) {
                statements = statements.subList(1, statements.size());
            }
            int idx = statements.indexOf(statement);
            if (idx >= 0) {
                if (idx > 0)
                    locations.add(statements.get(idx - 1));
                locations.add(statements.get(idx));
                if (idx < statements.size() - 1)
                    locations.add(statements.get(idx + 1));
            }
        }
    }
    return locations;
}
 
Example 13
Source Project: coming   Source File: OriginalRepairGenerator.java    License: MIT License 6 votes vote down vote up
private Set<CtElement> fuzzyLocator(CtElement statement) {
    Set<CtElement> locations = new HashSet<>();
    if (statement instanceof CtMethod || statement instanceof CtClass || statement instanceof CtIf || statement instanceof CtStatementList) {
        locations.add(statement);
    } else {
        // "int a;" is not CtStatement?
        CtElement parent = statement.getParent();
        if (parent != null) {
            List<CtElement> statements = parent.getElements(new TypeFilter<>(CtElement.class));
            if (parent instanceof CtStatement) {
                statements = statements.subList(1, statements.size());
            }
            int idx = statements.indexOf(statement);
            if (idx >= 0) {
                if (idx > 0)
                    locations.add(statements.get(idx - 1));
                locations.add(statements.get(idx));
                if (idx < statements.size() - 1)
                    locations.add(statements.get(idx + 1));
            }
        }
    }
    return locations;
}
 
Example 14
Source Project: coming   Source File: S4RORepairAnalyzer.java    License: MIT License 6 votes vote down vote up
public List<CtInvocation> getCandidateCalleeFunction(CtInvocation CE) {
    List<CtInvocation> ret = new ArrayList<>();

    CtMethod ownedMethod = CE.getParent(new TypeFilter<>(CtMethod.class));
    if (ownedMethod != null) {
        List<CtInvocation> invocations = ownedMethod.getElements(new TypeFilter<>(CtInvocation.class));
        for (CtInvocation invocation : invocations) {
            if (CE == invocation) {
                continue;
            }
            if (CE.getExecutable() != invocation.getExecutable()) {
                continue;
            }
            if (CE.getArguments().size() != invocation.getArguments().size()) {
                continue;
            }
            ret.add(invocation);
        }
    }
    return ret;
}
 
Example 15
Source Project: coming   Source File: S4RORepairGenerator.java    License: MIT License 6 votes vote down vote up
private Set<CtElement> fuzzyLocator(CtElement statement) {
    Set<CtElement> locations = new HashSet<>();
    if (statement instanceof CtMethod || statement instanceof CtClass || statement instanceof CtIf || statement instanceof CtStatementList) {
        locations.add(statement);
    } else {
        // "int a;" is not CtStatement?
        CtElement parent = statement.getParent();
        if (parent != null) {
            List<CtElement> statements = parent.getElements(new TypeFilter<>(CtElement.class));
            if (parent instanceof CtStatement) {
                statements = statements.subList(1, statements.size());
            }
            int idx = statements.indexOf(statement);
            if (idx >= 0) {
                if (idx > 0)
                    locations.add(statements.get(idx - 1));
                locations.add(statements.get(idx));
                if (idx < statements.size() - 1)
                    locations.add(statements.get(idx + 1));
            }
        }
    }
    return locations;
}
 
Example 16
Source Project: coming   Source File: ExtendedRepairGenerator.java    License: MIT License 6 votes vote down vote up
private Set<CtElement> fuzzyLocator(CtElement statement) {
    Set<CtElement> locations = new HashSet<>();
    if (statement instanceof CtMethod || statement instanceof CtClass || statement instanceof CtIf || statement instanceof CtStatementList) {
        locations.add(statement);
    } else {
        // "int a;" is not CtStatement?
        CtElement parent = statement.getParent();
        if (parent != null) {
            List<CtElement> statements = parent.getElements(new TypeFilter<>(CtElement.class));
            if (parent instanceof CtStatement) {
                statements = statements.subList(1, statements.size());
            }
            int idx = statements.indexOf(statement);
            if (idx >= 0) {
                if (idx > 0)
                    locations.add(statements.get(idx - 1));
                locations.add(statements.get(idx));
                if (idx < statements.size() - 1)
                    locations.add(statements.get(idx + 1));
            }
        }
    }
    return locations;
}
 
Example 17
Source Project: astor   Source File: SupportOperators.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static List<List<CtExpression<?>>> computeParameters(CtMethod anotherMethod, ModificationPoint point) {

		List<CtVariable> variablesInScope = point.getContextOfModificationPoint();

		List<CtParameter> parameterTypes = anotherMethod.getParameters();

		MapList<CtTypeReference, CtElement> candidateMappings = new MapList<>();
		// Groups vars according to types
		for (CtParameter ctTypeParameter : parameterTypes) {
			CtTypeReference parType = ctTypeParameter.getType();

			if (!candidateMappings.containsKey(parType)) {
				List compatible = variablesInScope.stream().filter(e -> e.getType().isSubtypeOf(parType))
						.collect(Collectors.toList());
				// A par without a var
				if (compatible.isEmpty())
					return null;

				candidateMappings.put(parType, compatible);

			}

		}
		List<List<CtExpression<?>>> candidateArguments = createAllParametersCombinations(parameterTypes,
				candidateMappings);

		return candidateArguments;
	}
 
Example 18
Source Project: nopol   Source File: SpoonReferenceLibrary.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Collection<CtMethod<?>> accessibleMethodsFrom(CtTypeReference<?> accessingType, CtTypeReference<?> accessedType) {
    Collection<CtMethod<?>> accessibleMethods = MetaList.newLinkedList();
    try {
        Collection<CtMethod<?>> allMethods = methodsOf(accessedType);
        for (CtMethod<?> method : allMethods) {
            if (isVisibleFrom(accessingType, method, method.getDeclaringType().getReference(), accessedType)) {
                accessibleMethods.add(method);
            }
        }
    } catch (Throwable e) {
        logWarning(logger(), e.toString());
    }
    return accessibleMethods;
}
 
Example 19
Source Project: nopol   Source File: SpoonMethodLibrary.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean isGetter(CtMethod<?> method) {
    if (hasNoArguments(method) && numberOfStatements(method) == 1) {
        CtStatement statement = lastStatementOf(method);
        return isReturnStatement(statement) && isFieldAccess(((CtReturn<?>) statement).getReturnedExpression());
    }
    return false;
}
 
Example 20
Source Project: nopol   Source File: SpoonMethodLibrary.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Collection<CtMethod<?>> methodsOf(CtTypeReference<?> type) {
    CtType<?> declaration = type.getDeclaration();
    if (isType(declaration)) {
        return ((CtType<?>) declaration).getAllMethods();
    }
    return asList();
}
 
Example 21
@Override
public boolean isToBeProcessed(CtLiteral candidate) {
    CtMethod parent = candidate.getParent(CtMethod.class);
    Object value = candidate.getValue();
    if (parent == null) {
        return false;
    } else if (value instanceof Boolean || value == null) {
        return false;
    }
    return (this.buggyMethod == null || parent.getSimpleName().equals(this.buggyMethod)) &&
            Number.class.isAssignableFrom(value.getClass());
}
 
Example 22
public boolean isUnbreakable(CtWhile loopStatement) {
    CtMethod<?> correspondingMethod = loopStatement.getParent(CtMethod.class);
    if (SpoonStatementLibrary.isLastStatementOfMethod(loopStatement)) {
        return !SpoonReferenceLibrary.isVoidType(correspondingMethod.getType());
    }
    return false;
}
 
Example 23
Source Project: astor   Source File: VarMappingTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected CtMethod getMethodFromClass(AstorCoreEngine core, String classname, String methodName) {
	//
	log.debug("Searching for class " + classname);
	List<CtType<?>> classes = core.getMutatorSupporter().getFactory().Type().getAll();
	CtType cUniv = classes.stream().filter(x -> x.getQualifiedName().equals(classname)).findFirst().get();
	CtMethod mSetup = (CtMethod) cUniv.getAllMethods().stream()
			.filter(x -> ((CtMethod) x).getSimpleName().equals(methodName)).findFirst().get();
	return mSetup;
	//
}
 
Example 24
@Override
public void process(final CtMethod<?> method) {
    if (method != null) {
        if (isTestCase(method)) {
            instrumentMethod(method);
        } else {
            if (method.getBody() != null) {
                List<CtIf> ifList = method.getBody().getElements(
                        new Filter<CtIf>() {

                            @Override
                            public boolean matches(CtIf arg0) {
                                if (!(arg0 instanceof CtIf)) {
                                    return false;
                                }

                                return true;
                            }
                        });
                for (CtIf tmp : ifList) {
                    instrumentIfInsideMethod(tmp);
                }
            }
        }

        String s = method.getDeclaringType().getQualifiedName();
        if (this.ifMetric != null && !this.ifMetric.modifyClass.contains(s)) {
            this.ifMetric.modifyClass.add(s);
        }


    }

}
 
Example 25
Source Project: nopol   Source File: Main.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * this method analyze all java class in generatedTestDir and return a list of all Junit method
 * @param generatedTestFolder
 * @param classPath
 * @return List<CtMethod> list of methods
 */
public static List<CtMethod<?>> getNewTestsMethods(String generatedTestFolder, String classPath){
    List<CtMethod<?>>  testsMethods = new ArrayList<CtMethod<?>>();

    logger.debug("--------------------------------------------------");
    logger.debug(" ##### Search tests methods ##### ");
    Launcher spoon = new Launcher();
    spoon.getEnvironment().setAutoImports(true);
    spoon.addInputResource(generatedTestFolder);
    spoon.getEnvironment().setSourceClasspath(classPath.split(File.pathSeparator));
    spoon.buildModel();
    //getannotatedMethod.. could be better
    for(CtType<?> clazz : spoon.getFactory().Class().getAll()){
        methodLoop:
            for(CtMethod<?> method : clazz.getAllMethods()){
                for(CtAnnotation<? extends Annotation> annotation : method.getAnnotations()){
                    if (annotation.getType().equals(method.getFactory().Annotation().createReference(org.junit.Test.class))) {
                        logger.debug("[FOUND] "+method.getSignature());
                        testsMethods.add(method);
                        continue methodLoop;
                    }
                }
            }
    }

    return testsMethods;
}
 
Example 26
Source Project: spoon-examples   Source File: Util.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static List<CtMethod> getGetters(CtLocalVariable localVariable) {
	return ((Set<CtMethod<?>>) localVariable.getType().getDeclaration().getMethods()).stream()
			.filter(method -> method.getParameters().isEmpty() &&
					method.getType() != localVariable.getFactory().Type().VOID_PRIMITIVE &&
					(method.getSimpleName().startsWith("get") ||
							method.getSimpleName().startsWith("is"))
			).collect(Collectors.toList());
}
 
Example 27
Source Project: spoon-examples   Source File: Collector.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void collect(Launcher launcher, CtMethod<?> testMethod, List<CtLocalVariable> localVariables) {
	CtClass testClass = testMethod.getParent(CtClass.class);
	testClass.removeMethod(testMethod);
	CtMethod<?> clone = testMethod.clone();
	instrument(clone, localVariables);
	testClass.addMethod(clone);
	System.out.println(clone);
	run(launcher, testClass, clone);
	testClass.removeMethod(clone);
	testClass.addMethod(testMethod);
}
 
Example 28
Source Project: gumtree-spoon-ast-diff   Source File: SpoonSupportTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInsert1_SearchInWrong() {
	String c1 = "" + "class X {" + "public int foo0() {" + " int x = 0;return 1;" + "}" + "};";

	String c2 = "" + "class X {" + "public int foo0() {" + " int x = 0;x = 10;return 1;" + "}" + "};";

	AstComparator diff = new AstComparator();
	Diff editScript = diff.compare(c1, c2);
	assertEquals(1, editScript.getRootOperations().size());

	Operation op = editScript.getRootOperations().get(0);
	assertTrue(op instanceof InsertOperation);

	assertNotNull(op.getSrcNode());
	assertEquals("x = 10", op.getSrcNode().toString());

	CtMethod methodRight = op.getSrcNode().getParent(CtMethod.class);
	assertNotNull(methodRight);
	assertEquals("foo0", methodRight.getSimpleName());
	assertEquals(3, methodRight.getBody().getStatements().size());
	assertEquals("x = 10", methodRight.getBody().getStatements().get(1).toString());

	SpoonSupport support = new SpoonSupport();
	// Search one insert in left part
	CtMethod methodLeft = (CtMethod) support.getMappedElement(editScript, methodRight, true);

	assertNull(methodLeft);
}
 
Example 29
Source Project: astor   Source File: SupportOperators.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static boolean checkOcurrenceOfOtherParameters(CtMethod anotherMethod, CtMethod affectedMethod) {
	// anotherMethod.getParameters().stream().map(CtParameter.class::cast)
	// .collect(Collectors.toList()

	for (Object parameterFromAnotherM : anotherMethod.getParameters()) {
		CtParameter parAnother = (CtParameter) parameterFromAnotherM;

		// The parameter does not exist in the previous version
		if (!affectedMethod.getParameters().contains(parAnother)) {
			return false;
		}
	}
	// all parameters exist
	return true;
}
 
Example 30
Source Project: spoon-examples   Source File: Analyzer.java    License: GNU General Public License v2.0 5 votes vote down vote up
public Map<CtMethod, List<CtLocalVariable>> analyze(CtType<?> ctClass) {
	CtTypeReference<Test> reference =
			ctClass.getFactory().Type().createReference(Test.class);
	return ctClass.getMethods().stream()
			.filter(ctMethod -> ctMethod.getAnnotation(reference) != null)
			.collect(Collectors.toMap(
					ctMethod -> ctMethod,
					this::analyze)
			);
}