Search in sources :

Example 26 with CtExecutable

use of spoon.reflect.declaration.CtExecutable in project spoon by INRIA.

the class MethodTypingContext method adaptTypeForNewMethod.

private CtTypeReference<?> adaptTypeForNewMethod(CtTypeReference<?> typeRef) {
    if (typeRef == null) {
        return null;
    }
    if (typeRef instanceof CtTypeParameterReference) {
        CtTypeParameterReference typeParamRef = (CtTypeParameterReference) typeRef;
        CtTypeParameter typeParam = typeParamRef.getDeclaration();
        if (typeParam == null) {
            throw new SpoonException("Declaration of the CtTypeParameter should not be null.");
        }
        if (typeParam.getTypeParameterDeclarer() instanceof CtExecutable) {
            // the parameter is declared in scope of Method or Constructor
            return typeRef.clone();
        }
    }
    // it is not type reference of scopeMethod. Adapt it using classTypingContext
    return classTypingContext.adaptType(typeRef);
}
Also used : CtTypeParameterReference(spoon.reflect.reference.CtTypeParameterReference) CtTypeParameter(spoon.reflect.declaration.CtTypeParameter) SpoonException(spoon.SpoonException) CtExecutable(spoon.reflect.declaration.CtExecutable)

Aggregations

CtExecutable (spoon.reflect.declaration.CtExecutable)26 Test (org.junit.Test)10 CtType (spoon.reflect.declaration.CtType)9 CtExecutableReference (spoon.reflect.reference.CtExecutableReference)7 Launcher (spoon.Launcher)6 CtElement (spoon.reflect.declaration.CtElement)6 Factory (spoon.reflect.factory.Factory)6 File (java.io.File)5 CtConstructor (spoon.reflect.declaration.CtConstructor)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SpoonException (spoon.SpoonException)4 CtField (spoon.reflect.declaration.CtField)4 CtMethod (spoon.reflect.declaration.CtMethod)4 SpoonModelBuilder (spoon.SpoonModelBuilder)3 CtParameterRemoveRefactoring (spoon.refactoring.CtParameterRemoveRefactoring)3 CtInvocation (spoon.reflect.code.CtInvocation)3 CtLambda (spoon.reflect.code.CtLambda)3 CtClass (spoon.reflect.declaration.CtClass)3 CtParameter (spoon.reflect.declaration.CtParameter)3