Java Code Examples for org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#typeVariables()
The following examples show how to use
org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#typeVariables() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PatchVal.java From EasyMPermission with MIT License | 5 votes |
private static TypeBinding getForEachComponentType(Expression collection, BlockScope scope) { if (collection != null) { TypeBinding resolved = collection.resolvedType; if (resolved == null) resolved = collection.resolveType(scope); if (resolved == null) return null; if (resolved.isArrayType()) { resolved = ((ArrayBinding) resolved).elementsType(); return resolved; } else if (resolved instanceof ReferenceBinding) { ReferenceBinding iterableType = ((ReferenceBinding)resolved).findSuperTypeOriginatingFrom(TypeIds.T_JavaLangIterable, false); TypeBinding[] arguments = null; if (iterableType != null) switch (iterableType.kind()) { case Binding.GENERIC_TYPE : // for (T t : Iterable<T>) - in case used inside Iterable itself arguments = iterableType.typeVariables(); break; case Binding.PARAMETERIZED_TYPE : // for(E e : Iterable<E>) arguments = ((ParameterizedTypeBinding)iterableType).arguments; break; case Binding.RAW_TYPE : // for(Object e : Iterable) return null; } if (arguments != null && arguments.length == 1) { return arguments[0]; } } } return null; }
Example 2
Source File: TypesImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@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 (DeclaredType) _env.getFactory().newTypeMirror(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 (DeclaredType) _env.getFactory().newTypeMirror( this._env.getLookupEnvironment().createParameterizedType(referenceBinding, typeArguments, null)); }
Example 3
Source File: TypesImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public DeclaredType getDeclaredType(DeclaredType containing, 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; DeclaredTypeImpl declaredTypeImpl = (DeclaredTypeImpl) containing; ReferenceBinding enclosingType = (ReferenceBinding) declaredTypeImpl._binding; if (typeArgsLength == 0) { if (referenceBinding.isGenericType()) { // must return a raw type return (DeclaredType) _env.getFactory().newTypeMirror(this._env.getLookupEnvironment().createRawType(referenceBinding, enclosingType)); } // TODO (see how to create a member type binding throw new UnsupportedOperationException("NYI: TypesImpl.getDeclaredType(...) for member types"); //$NON-NLS-1$ } 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 for a type arguments : " + typeMirrorImpl); //$NON-NLS-1$ } typeArguments[i] = (TypeBinding) binding; } return (DeclaredType) _env.getFactory().newTypeMirror( this._env.getLookupEnvironment().createParameterizedType(referenceBinding, typeArguments, enclosingType)); }
Example 4
Source File: TypeElementImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public List<? extends TypeParameterElement> getTypeParameters() { ReferenceBinding binding = (ReferenceBinding)_binding; TypeVariableBinding[] variables = binding.typeVariables(); if (variables.length == 0) { return Collections.emptyList(); } List<TypeParameterElement> params = new ArrayList<TypeParameterElement>(variables.length); for (TypeVariableBinding variable : variables) { params.add(_env.getFactory().newTypeParameterElement(variable, this)); } return Collections.unmodifiableList(params); }