@Override public TypeMirror getEnclosingType() { ReferenceBinding binding = (ReferenceBinding)_binding; ReferenceBinding enclosingType = binding.enclosingType(); if (enclosingType != null) return _env.getFactory().newDeclaredType(enclosingType); return _env.getFactory().getNoType(TypeKind.NONE); }
@Override public DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) { int typeArgsLength = typeArgs.length; TypeElementImpl typeElementImpl = (TypeElementImpl) typeElem; ReferenceBinding referenceBinding = (ReferenceBinding) typeElementImpl._binding; TypeVariableBinding[] typeVariables = referenceBinding.typeVariables(); int typeVariablesLength = typeVariables.length; if (typeArgsLength == 0) { if (referenceBinding.isGenericType()) { // must return a raw type return _env.getFactory().newDeclaredType(this._env.getLookupEnvironment().createRawType(referenceBinding, null)); } return (DeclaredType)typeElem.asType(); } else if (typeArgsLength != typeVariablesLength) { throw new IllegalArgumentException("Number of typeArguments doesn't match the number of formal parameters of typeElem"); //$NON-NLS-1$ } TypeBinding[] typeArguments = new TypeBinding[typeArgsLength]; for (int i = 0; i < typeArgsLength; i++) { TypeMirrorImpl typeMirrorImpl = (TypeMirrorImpl) typeArgs[i]; Binding binding = typeMirrorImpl._binding; if (!(binding instanceof TypeBinding)) { throw new IllegalArgumentException("Invalid type argument: " + typeMirrorImpl); //$NON-NLS-1$ } typeArguments[i] = (TypeBinding) binding; } return _env.getFactory().newDeclaredType( this._env.getLookupEnvironment().createParameterizedType(referenceBinding, typeArguments, null)); }
if (referenceBinding.isGenericType()) { return _env.getFactory().newDeclaredType(this._env.getLookupEnvironment().createRawType(referenceBinding, enclosingType)); return _env.getFactory().newDeclaredType( this._env.getLookupEnvironment().createParameterizedType(referenceBinding, typeArguments, enclosingType));
@Override public TypeMirror getSuperclass() { ReferenceBinding binding = (ReferenceBinding)_binding; ReferenceBinding superBinding = binding.superclass(); if (null == superBinding || binding.isInterface()) { return _env.getFactory().getNoType(TypeKind.NONE); } // superclass of a type must be a DeclaredType return _env.getFactory().newDeclaredType(superBinding); }
@Override public TypeMirror getUpperBound() { TypeVariableBinding typeVariableBinding = (TypeVariableBinding) this._binding; TypeBinding firstBound = typeVariableBinding.firstBound; ReferenceBinding[] superInterfaces = typeVariableBinding.superInterfaces; if (firstBound == null || superInterfaces.length == 0) { // no explicit bound return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound()); } if (firstBound != null && superInterfaces.length == 1 && superInterfaces[0] == firstBound) { // only one bound that is an interface return _env.getFactory().newTypeMirror(typeVariableBinding.upperBound()); } return this._env.getFactory().newDeclaredType((TypeVariableBinding) this._binding); }