List of usage examples for org.eclipse.jdt.internal.compiler.lookup ParameterizedTypeBinding genericType
public ReferenceBinding genericType()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected void updateMatch(ParameterizedTypeBinding parameterizedBinding, char[][][] patternTypeArguments, boolean patternHasTypeParameters, int depth, MatchLocator locator) { // Only possible if locator has an unit scope. if (locator.unitScope == null) return;/*from w ww. j a va2s . c om*/ // Set match raw flag boolean endPattern = patternTypeArguments == null ? true : depth >= patternTypeArguments.length; TypeBinding[] argumentsBindings = parameterizedBinding.arguments; boolean isRaw = parameterizedBinding.isRawType() || (argumentsBindings == null && parameterizedBinding.genericType().isGenericType()); if (isRaw && !this.match.isRaw()) { this.match.setRaw(isRaw); } // Update match if (!endPattern && patternTypeArguments != null) { // verify if this is a reference to the generic type itself if (!isRaw && patternHasTypeParameters && argumentsBindings != null) { boolean needUpdate = false; TypeVariableBinding[] typeVariables = parameterizedBinding.genericType().typeVariables(); int length = argumentsBindings.length; if (length == typeVariables.length) { for (int i = 0; i < length; i++) { if (argumentsBindings[i] != typeVariables[i]) { needUpdate = true; break; } } } if (needUpdate) { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } else { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } // Recurse TypeBinding enclosingType = parameterizedBinding.enclosingType(); if (enclosingType != null && (enclosingType.isParameterizedType() || enclosingType.isRawType())) { updateMatch((ParameterizedTypeBinding) enclosingType, patternTypeArguments, patternHasTypeParameters, depth + 1, locator); } }
From source file:com.google.gdt.eclipse.designer.copied.Util.java
License:Open Source License
public static ReferenceBinding genericType(ParameterizedTypeBinding ptBinding) { return ptBinding.genericType(); }
From source file:com.google.gwt.dev.jdt.TypeRefVisitor.java
License:Open Source License
private void maybeDispatch(Expression expression, TypeBinding binding) { assert (binding != null); if (binding instanceof SourceTypeBinding) { SourceTypeBinding type = (SourceTypeBinding) binding; onTypeRef(type, cud);/* w w w . j a v a2 s . c o m*/ } else if (binding instanceof ArrayBinding) { maybeDispatch(expression, ((ArrayBinding) binding).leafComponentType); } else if (binding instanceof BinaryTypeBinding) { onBinaryTypeRef((BinaryTypeBinding) binding, cud, expression); } else if (binding instanceof ParameterizedTypeBinding) { // Make sure that we depend on the generic version of the class. ParameterizedTypeBinding ptBinding = (ParameterizedTypeBinding) binding; maybeDispatch(expression, ptBinding.genericType()); } else if (binding instanceof RawTypeBinding) { // Make sure that we depend on the generic version of the class. RawTypeBinding rawTypeBinding = (RawTypeBinding) binding; maybeDispatch(expression, rawTypeBinding.genericType()); } else { // We don't care about other cases. } }
From source file:com.redhat.ceylon.eclipse.core.model.loader.JDTUtils.java
License:Open Source License
public static ReferenceBinding inferTypeParametersFromSuperClass(ReferenceBinding declaringClass, ReferenceBinding superClass, LookupEnvironment lookupEnvironment) { if (superClass instanceof RawTypeBinding && declaringClass instanceof ParameterizedTypeBinding) { ParameterizedTypeBinding rawSuperType = (ParameterizedTypeBinding) superClass; ParameterizedTypeBinding declaringType = (ParameterizedTypeBinding) declaringClass; superClass = lookupEnvironment.createParameterizedType(rawSuperType.genericType(), declaringType.arguments, rawSuperType.enclosingType()); }//from w w w .j a va2 s . c o m return superClass; }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.JDTUtils.java
License:Open Source License
public static ReferenceBinding inferTypeParametersFromSuperClass(ReferenceBinding declaringClass, ReferenceBinding superClass) {// ww w . j ava2 s.c om if (superClass instanceof RawTypeBinding && declaringClass instanceof ParameterizedTypeBinding) { LookupEnvironment lookupEnvironment = superClass.getPackage().environment; ParameterizedTypeBinding rawSuperType = (ParameterizedTypeBinding) superClass; ParameterizedTypeBinding declaringType = (ParameterizedTypeBinding) declaringClass; superClass = lookupEnvironment.createParameterizedType(rawSuperType.genericType(), declaringType.arguments, rawSuperType.enclosingType()); } return superClass; }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.java
License:Open Source License
TypeBinding toRawType(TypeBinding tb) { if (tb instanceof ParameterizedTypeBinding) { ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) tb; // resolver.getScope() can return null (if the resolver hasn't yet been used to resolve something) - using // the environment on the ptb seems safe. Other occurrences of getScope in this file could feasibly // be changed in the same way if NPEs become problems there too return ptb.environment().convertToRawType(ptb.genericType(), false); // return resolver.getScope().environment.convertToRawType(ptb.genericType(), false); } else if (tb instanceof TypeVariableBinding) { TypeBinding fb = ((TypeVariableBinding) tb).firstBound; if (fb == null) { return tb.erasure(); // Should be JLObject // return resolver.getScope().getJavaLangObject(); }/* w ww . ja v a2 s .c om*/ return fb; } else if (tb instanceof BinaryTypeBinding) { if (tb.isGenericType()) { try { Field f = BinaryTypeBinding.class.getDeclaredField("environment"); f.setAccessible(true); LookupEnvironment le = (LookupEnvironment) f.get(tb); return le.convertToRawType(tb, false); // return resolver.getScope().environment.convertToRawType(tb, false); } catch (Exception e) { throw new RuntimeException("Problem building rawtype ", e); } } else { return tb; } } else if (tb instanceof ArrayBinding) { return tb; } else if (tb instanceof BaseTypeBinding) { return tb; } else if (tb instanceof SourceTypeBinding) { return tb; } throw new IllegalStateException("nyi " + tb.getClass()); }
From source file:org.codehaus.jdt.groovy.internal.compiler.ast.JDTClassNodeBuilder.java
License:Open Source License
private ClassNode configureParameterizedType(ParameterizedTypeBinding parameterizedType) { if (parameterizedType instanceof RawTypeBinding) { // TODO correct? TypeBinding rt = toRawType(parameterizedType); return new JDTClassNode((RawTypeBinding) rt, resolver); // doesn't need generics initializing // return resolver.makeWithoutCaching(toRawType(parameterizedType));// configureType(toRawType(parameterizedType)); }//from w w w . j a v a2 s . c o m TypeBinding rt = toRawType(parameterizedType); if ((rt instanceof ParameterizedTypeBinding) && !(rt instanceof RawTypeBinding)) { // the type was the inner type of a parameterized type return new JDTClassNode((ParameterizedTypeBinding) rt, resolver); // doesn't need generics initializing } ClassNode base = configureType(rt); if (base instanceof JDTClassNode) { ((JDTClassNode) base).setJdtBinding(parameterizedType); // the messing about in here is for a few reasons. Contrast it with the ClassHelper.makeWithoutCaching // that code when called for Iterable will set the redirect to point to the generics. That is what // we are trying to achieve here. if (/* (parameterizedType instanceof ParameterizedTypeBinding) && */ !(parameterizedType instanceof RawTypeBinding)) { ClassNode cn = configureType(parameterizedType.genericType()); // ClassNode cn = resolver.createClassNode(parameterizedType.genericType()); ((JDTClassNode) base).setRedirect(cn); } } GenericsType[] gts = configureTypeArguments(parameterizedType.arguments); base.setGenericsTypes(gts); return base; }
From source file:org.eclipse.che.jdt.internal.core.search.matching.PatternLocator.java
License:Open Source License
protected void updateMatch(ParameterizedTypeBinding parameterizedBinding, char[][][] patternTypeArguments, boolean patternHasTypeParameters, int depth, MatchLocator locator) { // Only possible if locator has an unit scope. if (locator.unitScope == null) return;//from ww w .j a va 2s. c om // Set match raw flag boolean endPattern = patternTypeArguments == null ? true : depth >= patternTypeArguments.length; TypeBinding[] argumentsBindings = parameterizedBinding.arguments; boolean isRaw = parameterizedBinding.isRawType() || (argumentsBindings == null && parameterizedBinding.genericType().isGenericType()); if (isRaw && !this.match.isRaw()) { this.match.setRaw(isRaw); } // Update match if (!endPattern && patternTypeArguments != null) { // verify if this is a reference to the generic type itself if (!isRaw && patternHasTypeParameters && argumentsBindings != null) { boolean needUpdate = false; TypeVariableBinding[] typeVariables = parameterizedBinding.genericType().typeVariables(); int length = argumentsBindings.length; if (length == typeVariables.length) { for (int i = 0; i < length; i++) { if (TypeBinding.notEquals(argumentsBindings[i], typeVariables[i])) { needUpdate = true; break; } } } if (needUpdate) { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } else { char[][] patternArguments = patternTypeArguments[depth]; updateMatch(argumentsBindings, locator, patternArguments, patternHasTypeParameters); } } // Recurse TypeBinding enclosingType = parameterizedBinding.enclosingType(); if (enclosingType != null && (enclosingType.isParameterizedType() || enclosingType.isRawType())) { updateMatch((ParameterizedTypeBinding) enclosingType, patternTypeArguments, patternHasTypeParameters, depth + 1, locator); } }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Returns a type where either all variables or specific ones got discarded. * e.g. List<E> (discarding <E extends Enum<E>) will return: List<? extends Enum<?>> */// w ww. ja v a 2s .c om public static TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, Set eliminatedVariables) { if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) { switch (originalType.kind()) { case Binding.ARRAY_TYPE: ArrayBinding originalArrayType = (ArrayBinding) originalType; TypeBinding originalLeafComponentType = originalArrayType.leafComponentType; TypeBinding substitute = convertEliminatingTypeVariables(originalLeafComponentType, genericType, rank, eliminatedVariables); // substitute could itself be array type if (substitute != originalLeafComponentType) { return originalArrayType.environment.createArrayType(substitute.leafComponentType(), substitute.dimensions() + originalArrayType.dimensions()); } break; case Binding.PARAMETERIZED_TYPE: ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) originalType; ReferenceBinding originalEnclosing = paramType.enclosingType(); ReferenceBinding substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables); } TypeBinding[] originalArguments = paramType.arguments; TypeBinding[] substitutedArguments = originalArguments; for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) { TypeBinding originalArgument = originalArguments[i]; TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, paramType.genericType(), i, eliminatedVariables); if (substitutedArgument != originalArgument) { if (substitutedArguments == originalArguments) { System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i); } substitutedArguments[i] = substitutedArgument; } else if (substitutedArguments != originalArguments) { substitutedArguments[i] = originalArgument; } } if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) { return paramType.environment.createParameterizedType(paramType.genericType(), substitutedArguments, substitutedEnclosing); } break; case Binding.TYPE_PARAMETER: if (genericType == null) { break; } TypeVariableBinding originalVariable = (TypeVariableBinding) originalType; if (eliminatedVariables != null && eliminatedVariables.contains(originalType)) { return originalVariable.environment.createWildcard(genericType, rank, null, null, Wildcard.UNBOUND); } TypeBinding originalUpperBound = originalVariable.upperBound(); if (eliminatedVariables == null) { eliminatedVariables = new HashSet(2); } eliminatedVariables.add(originalVariable); TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType, rank, eliminatedVariables); eliminatedVariables.remove(originalVariable); return originalVariable.environment.createWildcard(genericType, rank, substitutedUpperBound, null, Wildcard.EXTENDS); case Binding.RAW_TYPE: break; case Binding.GENERIC_TYPE: ReferenceBinding currentType = (ReferenceBinding) originalType; originalEnclosing = currentType.enclosingType(); substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables); } originalArguments = currentType.typeVariables(); substitutedArguments = originalArguments; for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) { TypeBinding originalArgument = originalArguments[i]; TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, currentType, i, eliminatedVariables); if (substitutedArgument != originalArgument) { if (substitutedArguments == originalArguments) { System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i); } substitutedArguments[i] = substitutedArgument; } else if (substitutedArguments != originalArguments) { substitutedArguments[i] = originalArgument; } } if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) { return ((TypeVariableBinding) originalArguments[0]).environment .createParameterizedType(genericType, substitutedArguments, substitutedEnclosing); } break; case Binding.WILDCARD_TYPE: WildcardBinding wildcard = (WildcardBinding) originalType; TypeBinding originalBound = wildcard.bound; TypeBinding substitutedBound = originalBound; if (originalBound != null) { substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables); if (substitutedBound != originalBound) { return wildcard.environment.createWildcard(wildcard.genericType, wildcard.rank, substitutedBound, null, wildcard.boundKind); } } break; case Binding.INTERSECTION_TYPE: WildcardBinding intersection = (WildcardBinding) originalType; originalBound = intersection.bound; substitutedBound = originalBound; if (originalBound != null) { substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables); } TypeBinding[] originalOtherBounds = intersection.otherBounds; TypeBinding[] substitutedOtherBounds = originalOtherBounds; for (int i = 0, length = originalOtherBounds == null ? 0 : originalOtherBounds.length; i < length; i++) { TypeBinding originalOtherBound = originalOtherBounds[i]; TypeBinding substitutedOtherBound = convertEliminatingTypeVariables(originalOtherBound, genericType, rank, eliminatedVariables); if (substitutedOtherBound != originalOtherBound) { if (substitutedOtherBounds == originalOtherBounds) { System.arraycopy(originalOtherBounds, 0, substitutedOtherBounds = new TypeBinding[length], 0, i); } substitutedOtherBounds[i] = substitutedOtherBound; } else if (substitutedOtherBounds != originalOtherBounds) { substitutedOtherBounds[i] = originalOtherBound; } } if (substitutedBound != originalBound || substitutedOtherBounds != originalOtherBounds) { return intersection.environment.createWildcard(intersection.genericType, intersection.rank, substitutedBound, substitutedOtherBounds, intersection.boundKind); } break; } } return originalType; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
/** * Returns a type, where original type was substituted using the receiver * parameterized type.//from w w w .j a va 2 s.com * In raw mode, all parameterized type denoting same original type are converted * to raw types. e.g. * class X <T> { * X<T> foo; * X<String> bar; * } when used in raw fashion, then type of both foo and bar is raw type X. * */ public static TypeBinding substitute(Substitution substitution, TypeBinding originalType) { if (originalType == null) return null; switch (originalType.kind()) { case Binding.TYPE_PARAMETER: return substitution.substitute((TypeVariableBinding) originalType); case Binding.PARAMETERIZED_TYPE: ParameterizedTypeBinding originalParameterizedType = (ParameterizedTypeBinding) originalType; ReferenceBinding originalEnclosing = originalType.enclosingType(); ReferenceBinding substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) substitute(substitution, originalEnclosing); } TypeBinding[] originalArguments = originalParameterizedType.arguments; TypeBinding[] substitutedArguments = originalArguments; if (originalArguments != null) { if (substitution.isRawSubstitution()) { return originalParameterizedType.environment .createRawType(originalParameterizedType.genericType(), substitutedEnclosing); } substitutedArguments = substitute(substitution, originalArguments); } if (substitutedArguments != originalArguments || substitutedEnclosing != originalEnclosing) { return originalParameterizedType.environment.createParameterizedType( originalParameterizedType.genericType(), substitutedArguments, substitutedEnclosing); } break; case Binding.ARRAY_TYPE: ArrayBinding originalArrayType = (ArrayBinding) originalType; TypeBinding originalLeafComponentType = originalArrayType.leafComponentType; TypeBinding substitute = substitute(substitution, originalLeafComponentType); // substitute could itself be array type if (substitute != originalLeafComponentType) { return originalArrayType.environment.createArrayType(substitute.leafComponentType(), substitute.dimensions() + originalType.dimensions()); } break; case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: WildcardBinding wildcard = (WildcardBinding) originalType; if (wildcard.boundKind != Wildcard.UNBOUND) { TypeBinding originalBound = wildcard.bound; TypeBinding substitutedBound = substitute(substitution, originalBound); TypeBinding[] originalOtherBounds = wildcard.otherBounds; TypeBinding[] substitutedOtherBounds = substitute(substitution, originalOtherBounds); if (substitutedBound != originalBound || originalOtherBounds != substitutedOtherBounds) { if (originalOtherBounds != null) { /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=347145: the constituent intersecting types have changed in the last round of substitution. Reevaluate the composite intersection type, as there is a possibility of the intersection collapsing into one of the constituents, the other being fully subsumed. */ TypeBinding[] bounds = new TypeBinding[1 + substitutedOtherBounds.length]; bounds[0] = substitutedBound; System.arraycopy(substitutedOtherBounds, 0, bounds, 1, substitutedOtherBounds.length); TypeBinding[] glb = Scope.greaterLowerBound(bounds); // re-evaluate if (glb != null && glb != bounds) { substitutedBound = glb[0]; if (glb.length == 1) { substitutedOtherBounds = null; } else { System.arraycopy(glb, 1, substitutedOtherBounds = new TypeBinding[glb.length - 1], 0, glb.length - 1); } } } return wildcard.environment.createWildcard(wildcard.genericType, wildcard.rank, substitutedBound, substitutedOtherBounds, wildcard.boundKind); } } break; case Binding.TYPE: if (!originalType.isMemberType()) break; ReferenceBinding originalReferenceType = (ReferenceBinding) originalType; originalEnclosing = originalType.enclosingType(); substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) substitute(substitution, originalEnclosing); } // treat as if parameterized with its type variables (non generic type gets 'null' arguments) if (substitutedEnclosing != originalEnclosing) { return substitution.isRawSubstitution() ? substitution.environment().createRawType(originalReferenceType, substitutedEnclosing) : substitution.environment().createParameterizedType(originalReferenceType, null, substitutedEnclosing); } break; case Binding.GENERIC_TYPE: originalReferenceType = (ReferenceBinding) originalType; originalEnclosing = originalType.enclosingType(); substitutedEnclosing = originalEnclosing; if (originalEnclosing != null) { substitutedEnclosing = (ReferenceBinding) substitute(substitution, originalEnclosing); } if (substitution.isRawSubstitution()) { return substitution.environment().createRawType(originalReferenceType, substitutedEnclosing); } // treat as if parameterized with its type variables (non generic type gets 'null' arguments) originalArguments = originalReferenceType.typeVariables(); substitutedArguments = substitute(substitution, originalArguments); return substitution.environment().createParameterizedType(originalReferenceType, substitutedArguments, substitutedEnclosing); } return originalType; }