1 11 12 package org.eclipse.jdt.internal.compiler.apt.model; 13 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.List ; 17 18 import javax.lang.model.type.ExecutableType; 19 import javax.lang.model.type.TypeKind; 20 import javax.lang.model.type.TypeMirror; 21 import javax.lang.model.type.TypeVariable; 22 import javax.lang.model.type.TypeVisitor; 23 24 import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl; 25 import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; 26 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; 27 import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; 28 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 29 import org.eclipse.jdt.internal.compiler.lookup.TypeVariableBinding; 30 31 35 public class ExecutableTypeImpl extends TypeMirrorImpl implements ExecutableType { 36 37 public ExecutableTypeImpl(BaseProcessingEnvImpl env, MethodBinding binding) { 38 super(env, binding); 39 } 40 43 @Override 44 public List <? extends TypeMirror> getParameterTypes() { 45 MethodBinding binding = (MethodBinding) this._binding; 46 TypeBinding[] parameters = binding.parameters; 47 int length = parameters.length; 48 boolean isEnumConstructor = binding.isConstructor() 49 && binding.declaringClass.isEnum() 50 && binding.declaringClass.isBinaryBinding() 51 && ((binding.modifiers & ExtraCompilerModifiers.AccGenericSignature) == 0); 52 if (isEnumConstructor) { 53 if (length == 2) { 54 return Collections.emptyList(); 55 } 56 ArrayList <TypeMirror> list = new ArrayList <TypeMirror>(); 57 for (int i = 2; i < length; i++) { 58 list.add(_env.getFactory().newTypeMirror(parameters[i])); 59 } 60 return Collections.unmodifiableList(list); 61 } 62 if (length != 0) { 63 ArrayList <TypeMirror> list = new ArrayList <TypeMirror>(); 64 for (TypeBinding typeBinding : parameters) { 65 list.add(_env.getFactory().newTypeMirror(typeBinding)); 66 } 67 return Collections.unmodifiableList(list); 68 } 69 return Collections.emptyList(); 70 } 71 72 75 @Override 76 public TypeMirror getReturnType() { 77 return _env.getFactory().newTypeMirror(((MethodBinding) this._binding).returnType); 78 } 79 80 83 @Override 84 public List <? extends TypeMirror> getThrownTypes() { 85 ArrayList <TypeMirror> list = new ArrayList <TypeMirror>(); 86 ReferenceBinding[] thrownExceptions = ((MethodBinding) this._binding).thrownExceptions; 87 if (thrownExceptions.length != 0) { 88 for (ReferenceBinding referenceBinding : thrownExceptions) { 89 list.add(_env.getFactory().newTypeMirror(referenceBinding)); 90 } 91 } 92 return Collections.unmodifiableList(list); 93 } 94 95 98 @Override 99 public List <? extends TypeVariable> getTypeVariables() { 100 ArrayList <TypeVariable> list = new ArrayList <TypeVariable>(); 101 TypeVariableBinding[] typeVariables = ((MethodBinding) this._binding).typeVariables(); 102 if (typeVariables.length != 0) { 103 for (TypeVariableBinding typeVariableBinding : typeVariables) { 104 list.add((TypeVariable) _env.getFactory().newTypeMirror(typeVariableBinding)); 105 } 106 } 107 return Collections.unmodifiableList(list); 108 } 109 110 113 @Override 114 public <R, P> R accept(TypeVisitor<R, P> v, P p) { 115 return v.visitExecutable(this, p); 116 } 117 118 121 @Override 122 public TypeKind getKind() { 123 return TypeKind.EXECUTABLE; 124 } 125 } 126 | Popular Tags |