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;
}
Aggregations