Search in sources :

Example 1 with VoidTypeBinding

use of org.eclipse.jdt.internal.compiler.lookup.VoidTypeBinding in project spoon by INRIA.

the class ReferenceBuilder method getExecutableReference.

@SuppressWarnings("unchecked")
<T> CtExecutableReference<T> getExecutableReference(MethodBinding exec) {
    if (exec == null) {
        return null;
    }
    final CtExecutableReference ref = this.jdtTreeBuilder.getFactory().Core().createExecutableReference();
    if (exec.isConstructor()) {
        ref.setSimpleName(CtExecutableReference.CONSTRUCTOR_NAME);
        // in case of constructor of an array, it's the return type that we want
        if (exec.returnType instanceof VoidTypeBinding) {
            ref.setType(getTypeReference(exec.declaringClass, true));
        } else {
            ref.setType(getTypeReference(exec.returnType, true));
        }
    } else {
        ref.setSimpleName(new String(exec.selector));
        ref.setType(getTypeReference(exec.returnType, true));
    }
    if (exec instanceof ProblemMethodBinding) {
        if (exec.declaringClass != null && Arrays.asList(exec.declaringClass.methods()).contains(exec)) {
            ref.setDeclaringType(getTypeReference(exec.declaringClass));
        } else {
            final CtReference declaringType = getDeclaringReferenceFromImports(exec.constantPoolName());
            if (declaringType instanceof CtTypeReference) {
                ref.setDeclaringType((CtTypeReference<?>) declaringType);
            }
        }
        if (exec.isConstructor()) {
            // super() invocation have a good declaring class.
            ref.setDeclaringType(getTypeReference(exec.declaringClass));
        }
        ref.setStatic(true);
    } else {
        if (exec.isConstructor() && !(exec.returnType instanceof VoidTypeBinding)) {
            ref.setDeclaringType(getTypeReference(exec.returnType));
        } else {
            ref.setDeclaringType(getTypeReference(exec.declaringClass));
        }
        ref.setStatic(exec.isStatic());
    }
    if (exec.declaringClass instanceof ParameterizedTypeBinding) {
        ref.setDeclaringType(getTypeReference(exec.declaringClass.actualType()));
    }
    // original() method returns a result not null when the current method is generic.
    if (exec.original() != null) {
        final List<CtTypeReference<?>> parameters = new ArrayList<>(exec.original().parameters.length);
        for (TypeBinding b : exec.original().parameters) {
            parameters.add(getTypeReference(b, true));
        }
        ref.setParameters(parameters);
    } else if (exec.parameters != null) {
        // This is a method without a generic argument.
        final List<CtTypeReference<?>> parameters = new ArrayList<>();
        for (TypeBinding b : exec.parameters) {
            parameters.add(getTypeReference(b, true));
        }
        ref.setParameters(parameters);
    }
    return ref;
}
Also used : ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) ProblemMethodBinding(org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding) CtReference(spoon.reflect.reference.CtReference) CtTypeReference(spoon.reflect.reference.CtTypeReference) BinaryTypeBinding(org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding) ParameterizedTypeBinding(org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding) TypeBinding(org.eclipse.jdt.internal.compiler.lookup.TypeBinding) MissingTypeBinding(org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding) VoidTypeBinding(org.eclipse.jdt.internal.compiler.lookup.VoidTypeBinding) SourceTypeBinding(org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding) JDTTreeBuilderQuery.searchTypeBinding(spoon.support.compiler.jdt.JDTTreeBuilderQuery.searchTypeBinding) PolyTypeBinding(org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding) LocalTypeBinding(org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding) BaseTypeBinding(org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding) RawTypeBinding(org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding) VoidTypeBinding(org.eclipse.jdt.internal.compiler.lookup.VoidTypeBinding) ArrayList(java.util.ArrayList) CtExecutableReference(spoon.reflect.reference.CtExecutableReference) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 BaseTypeBinding (org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding)1 BinaryTypeBinding (org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding)1 LocalTypeBinding (org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding)1 MissingTypeBinding (org.eclipse.jdt.internal.compiler.lookup.MissingTypeBinding)1 ParameterizedTypeBinding (org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding)1 PolyTypeBinding (org.eclipse.jdt.internal.compiler.lookup.PolyTypeBinding)1 ProblemMethodBinding (org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding)1 RawTypeBinding (org.eclipse.jdt.internal.compiler.lookup.RawTypeBinding)1 SourceTypeBinding (org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding)1 TypeBinding (org.eclipse.jdt.internal.compiler.lookup.TypeBinding)1 VoidTypeBinding (org.eclipse.jdt.internal.compiler.lookup.VoidTypeBinding)1 CtExecutableReference (spoon.reflect.reference.CtExecutableReference)1 CtReference (spoon.reflect.reference.CtReference)1 CtTypeReference (spoon.reflect.reference.CtTypeReference)1 JDTTreeBuilderQuery.searchTypeBinding (spoon.support.compiler.jdt.JDTTreeBuilderQuery.searchTypeBinding)1