Search in sources :

Example 6 with CtFormalTypeDeclarer

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

the class CtTypeParameterReferenceImpl method getDeclaration.

@Override
public CtTypeParameter getDeclaration() {
    if (!isParentInitialized()) {
        return null;
    }
    CtElement e = this;
    CtElement parent = getParent();
    if (parent instanceof CtTypeReference) {
        if (parent.isParentInitialized() == false) {
            return null;
        }
        parent = parent.getParent();
    }
    if (parent instanceof CtExecutableReference) {
        CtExecutableReference parentExec = (CtExecutableReference) parent;
        if (!parentExec.getDeclaringType().equals(e)) {
            CtElement parent2 = parentExec.getExecutableDeclaration();
            if (parent2 instanceof CtMethod) {
                e = parent2;
            } else {
                e = e.getParent(CtFormalTypeDeclarer.class);
            }
        } else {
            e = e.getParent(CtFormalTypeDeclarer.class);
        }
    } else {
        e = e.getParent(CtFormalTypeDeclarer.class);
    }
    // collecting all formal type declarers of the hierarchy
    while (e != null) {
        CtTypeParameter result = findTypeParamDeclaration((CtFormalTypeDeclarer) e, this.getSimpleName());
        if (result != null) {
            return result;
        }
        e = e.getParent(CtFormalTypeDeclarer.class);
    }
    return null;
}
Also used : CtTypeParameter(spoon.reflect.declaration.CtTypeParameter) CtElement(spoon.reflect.declaration.CtElement) CtTypeReference(spoon.reflect.reference.CtTypeReference) CtFormalTypeDeclarer(spoon.reflect.declaration.CtFormalTypeDeclarer) CtExecutableReference(spoon.reflect.reference.CtExecutableReference) CtMethod(spoon.reflect.declaration.CtMethod)

Aggregations

CtFormalTypeDeclarer (spoon.reflect.declaration.CtFormalTypeDeclarer)6 CtType (spoon.reflect.declaration.CtType)4 CtMethod (spoon.reflect.declaration.CtMethod)3 CtTypeParameter (spoon.reflect.declaration.CtTypeParameter)3 CtTypeReference (spoon.reflect.reference.CtTypeReference)3 SpoonException (spoon.SpoonException)2 CtExecutable (spoon.reflect.declaration.CtExecutable)2 ArrayList (java.util.ArrayList)1 CtElement (spoon.reflect.declaration.CtElement)1 CtTypeMember (spoon.reflect.declaration.CtTypeMember)1 CtExecutableReference (spoon.reflect.reference.CtExecutableReference)1 CtTypeParameterReference (spoon.reflect.reference.CtTypeParameterReference)1