Skip to content

Commit 4f93d44

Browse files
Remove left-overs from Java 1.7 type inference (#4625)
The following are no longer needed since compiler support for 1.7 was dropped: + class InferenceContext + methods collectSubstitutes() which held the only remaining references to InferenceContext See #4625
1 parent ec6376c commit 4f93d44

File tree

6 files changed

+0
-583
lines changed

6 files changed

+0
-583
lines changed

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ArrayBinding.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,6 @@ public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) {
9797
return missingTypes;
9898
}
9999

100-
@Override
101-
public void collectSubstitutes(Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {
102-
103-
if ((this.tagBits & TagBits.HasTypeVariable) == 0) return;
104-
if (actualType == TypeBinding.NULL || actualType.kind() == POLY_TYPE) return;
105-
106-
switch(actualType.kind()) {
107-
case Binding.ARRAY_TYPE :
108-
int actualDim = actualType.dimensions();
109-
if (actualDim == this.dimensions) {
110-
this.leafComponentType.collectSubstitutes(scope, actualType.leafComponentType(), inferenceContext, constraint);
111-
} else if (actualDim > this.dimensions) {
112-
ArrayBinding actualReducedType = this.environment.createArrayType(actualType.leafComponentType(), actualDim - this.dimensions);
113-
this.leafComponentType.collectSubstitutes(scope, actualReducedType, inferenceContext, constraint);
114-
}
115-
break;
116-
case Binding.TYPE_PARAMETER :
117-
//TypeVariableBinding variable = (TypeVariableBinding) otherType;
118-
// TODO (philippe) should consider array bounds, and recurse
119-
break;
120-
}
121-
}
122-
123100
@Override
124101
public boolean mentionsAny(TypeBinding[] parameters, int idx) {
125102
return this.leafComponentType.mentionsAny(parameters, idx);

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/InferenceContext.java

Lines changed: 0 additions & 142 deletions
This file was deleted.

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -270,116 +270,6 @@ public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) {
270270
return missingTypes;
271271
}
272272

273-
/**
274-
* Collect the substitutes into a map for certain type variables inside the receiver type
275-
* e.g. {@code Collection<T>.collectSubstitutes(Collection<List<X>>, Map)} will populate Map with: {@code T --> List<X>}
276-
* Constraints:
277-
* <pre>{@code
278-
* A << F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_EXTENDS (1))
279-
* A = F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_EQUAL (0))
280-
* A >> F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_SUPER (2))
281-
* }</pre>
282-
*/
283-
@Override
284-
public void collectSubstitutes(Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {
285-
if ((this.tagBits & TagBits.HasTypeVariable) == 0) {
286-
TypeBinding actualEquivalent = actualType.findSuperTypeOriginatingFrom(this.type);
287-
if (actualEquivalent != null && actualEquivalent.isRawType()) {
288-
inferenceContext.isUnchecked = true;
289-
}
290-
return;
291-
}
292-
if (actualType == TypeBinding.NULL || actualType.kind() == POLY_TYPE) return;
293-
294-
if (!(actualType instanceof ReferenceBinding)) return;
295-
TypeBinding formalEquivalent, actualEquivalent;
296-
switch (constraint) {
297-
case TypeConstants.CONSTRAINT_EQUAL :
298-
case TypeConstants.CONSTRAINT_EXTENDS :
299-
formalEquivalent = this;
300-
actualEquivalent = actualType.findSuperTypeOriginatingFrom(this.type);
301-
if (actualEquivalent == null) return;
302-
break;
303-
case TypeConstants.CONSTRAINT_SUPER :
304-
default:
305-
formalEquivalent = this.findSuperTypeOriginatingFrom(actualType);
306-
if (formalEquivalent == null) return;
307-
actualEquivalent = actualType;
308-
break;
309-
}
310-
// collect through enclosing type
311-
ReferenceBinding formalEnclosingType = formalEquivalent.enclosingType();
312-
if (formalEnclosingType != null) {
313-
formalEnclosingType.collectSubstitutes(scope, actualEquivalent.enclosingType(), inferenceContext, constraint);
314-
}
315-
// collect through type arguments
316-
if (this.arguments == null) return;
317-
TypeBinding[] formalArguments;
318-
switch (formalEquivalent.kind()) {
319-
case Binding.GENERIC_TYPE :
320-
formalArguments = formalEquivalent.typeVariables();
321-
break;
322-
case Binding.PARAMETERIZED_TYPE :
323-
formalArguments = ((ParameterizedTypeBinding)formalEquivalent).arguments;
324-
break;
325-
case Binding.RAW_TYPE :
326-
if (inferenceContext.depth > 0) {
327-
inferenceContext.status = InferenceContext.FAILED; // marker for impossible inference
328-
}
329-
return;
330-
default :
331-
return;
332-
}
333-
TypeBinding[] actualArguments;
334-
switch (actualEquivalent.kind()) {
335-
case Binding.GENERIC_TYPE :
336-
actualArguments = actualEquivalent.typeVariables();
337-
break;
338-
case Binding.PARAMETERIZED_TYPE :
339-
actualArguments = ((ParameterizedTypeBinding)actualEquivalent).arguments;
340-
break;
341-
case Binding.RAW_TYPE :
342-
if (inferenceContext.depth > 0) {
343-
inferenceContext.status = InferenceContext.FAILED; // marker for impossible inference
344-
} else {
345-
inferenceContext.isUnchecked = true;
346-
}
347-
return;
348-
default :
349-
return;
350-
}
351-
inferenceContext.depth++;
352-
for (int i = 0, length = formalArguments.length; i < length; i++) {
353-
TypeBinding formalArgument = formalArguments[i];
354-
TypeBinding actualArgument = actualArguments[i];
355-
if (formalArgument.isWildcard()) {
356-
formalArgument.collectSubstitutes(scope, actualArgument, inferenceContext, constraint);
357-
continue;
358-
} else if (actualArgument.isWildcard()){
359-
WildcardBinding actualWildcardArgument = (WildcardBinding) actualArgument;
360-
if (actualWildcardArgument.otherBounds == null) {
361-
if (constraint == TypeConstants.CONSTRAINT_SUPER) { // JLS 15.12.7, p.459
362-
switch(actualWildcardArgument.boundKind) {
363-
case Wildcard.EXTENDS :
364-
formalArgument.collectSubstitutes(scope, actualWildcardArgument.bound, inferenceContext, TypeConstants.CONSTRAINT_SUPER);
365-
continue;
366-
case Wildcard.SUPER :
367-
formalArgument.collectSubstitutes(scope, actualWildcardArgument.bound, inferenceContext, TypeConstants.CONSTRAINT_EXTENDS);
368-
continue;
369-
default :
370-
continue; // cannot infer anything further from unbound wildcard
371-
}
372-
} else {
373-
continue; // cannot infer anything further from wildcard
374-
}
375-
}
376-
}
377-
// by default, use EQUAL constraint
378-
formalArgument.collectSubstitutes(scope, actualArgument, inferenceContext, TypeConstants.CONSTRAINT_EQUAL);
379-
}
380-
inferenceContext.depth--;
381-
}
382-
383273
/**
384274
* @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#computeId()
385275
*/

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,21 +243,6 @@ public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) {
243243
return missingTypes;
244244
}
245245

246-
/**
247-
* Collect the substitutes into a map for certain type variables inside the receiver type
248-
* e.g.<pre>{@code
249-
* Collection<T>.findSubstitute(T, Collection<List<X>>): T --> List<X>
250-
*
251-
* Constraints:
252-
* A << F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_EXTENDS (1))
253-
* A = F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_EQUAL (0))
254-
* A >> F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_SUPER (2))
255-
* }</pre>
256-
*/
257-
public void collectSubstitutes(Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {
258-
// no substitute by default
259-
}
260-
261246
/** Virtual copy constructor: a copy is made of the receiver's entire instance state and then suitably
262247
parameterized by the arguments to the clone operation as seen fit by each type. Parameters may not
263248
make sense for every type in the hierarchy, in which case they are silently ignored. A type may

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeVariableBinding.java

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -364,52 +364,6 @@ public List<TypeBinding> collectMissingTypes(List<TypeBinding> missingTypes) {
364364
return missingTypes;
365365
}
366366

367-
/**
368-
* Collect the substitutes into a map for certain type variables inside the receiver type
369-
* e.g. {@code Collection<T>.collectSubstitutes(Collection<List<X>>, Map)} will populate Map with: {@code T --> List<X>}
370-
* <pre>{@code
371-
* Constraints:
372-
* A << F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_EXTENDS (1))
373-
* A = F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_EQUAL (0))
374-
* A >> F corresponds to: F.collectSubstitutes(..., A, ..., CONSTRAINT_SUPER (2))
375-
* }</pre>
376-
*/
377-
@Override
378-
public void collectSubstitutes(Scope scope, TypeBinding actualType, InferenceContext inferenceContext, int constraint) {
379-
380-
// only infer for type params of the generic method
381-
if (this.declaringElement != inferenceContext.genericMethod) return;
382-
383-
// cannot infer anything from a null type
384-
switch (actualType.kind()) {
385-
case Binding.BASE_TYPE :
386-
if (actualType == TypeBinding.NULL) return;
387-
TypeBinding boxedType = scope.environment().computeBoxingType(actualType);
388-
if (boxedType == actualType) return; //$IDENTITY-COMPARISON$
389-
actualType = boxedType;
390-
break;
391-
case Binding.POLY_TYPE: // cannot steer inference, only learn from it.
392-
case Binding.WILDCARD_TYPE :
393-
return; // wildcards are not true type expressions (JLS 15.12.2.7, p.453 2nd discussion)
394-
}
395-
396-
// reverse constraint, to reflect variable on rhs: A << T --> T >: A
397-
int variableConstraint;
398-
switch(constraint) {
399-
case TypeConstants.CONSTRAINT_EQUAL :
400-
variableConstraint = TypeConstants.CONSTRAINT_EQUAL;
401-
break;
402-
case TypeConstants.CONSTRAINT_EXTENDS :
403-
variableConstraint = TypeConstants.CONSTRAINT_SUPER;
404-
break;
405-
default:
406-
//case CONSTRAINT_SUPER :
407-
variableConstraint =TypeConstants.CONSTRAINT_EXTENDS;
408-
break;
409-
}
410-
inferenceContext.recordSubstitute(this, actualType, variableConstraint);
411-
}
412-
413367
/*
414368
* declaringUniqueKey : genericTypeSignature
415369
* p.X<T> { ... } --> Lp/X;:TT;

0 commit comments

Comments
 (0)