Lines 26-31
Link Here
|
26 |
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; |
26 |
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; |
27 |
|
27 |
|
28 |
public class LookupEnvironment implements ProblemReasons, TypeConstants { |
28 |
public class LookupEnvironment implements ProblemReasons, TypeConstants { |
|
|
29 |
|
29 |
final static int BUILD_FIELDS_AND_METHODS = 4; |
30 |
final static int BUILD_FIELDS_AND_METHODS = 4; |
30 |
final static int BUILD_TYPE_HIERARCHY = 1; |
31 |
final static int BUILD_TYPE_HIERARCHY = 1; |
31 |
final static int CHECK_AND_SET_IMPORTS = 2; |
32 |
final static int CHECK_AND_SET_IMPORTS = 2; |
Lines 60-65
Link Here
|
60 |
private SimpleLookupTable uniqueParameterizedTypeBindings; |
61 |
private SimpleLookupTable uniqueParameterizedTypeBindings; |
61 |
private SimpleLookupTable uniqueRawTypeBindings; |
62 |
private SimpleLookupTable uniqueRawTypeBindings; |
62 |
private SimpleLookupTable uniqueWildcardBindings; |
63 |
private SimpleLookupTable uniqueWildcardBindings; |
|
|
64 |
private SimpleLookupTable uniqueParameterizedGenericMethodBindings; |
63 |
|
65 |
|
64 |
public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units |
66 |
public CompilationUnitDeclaration unitBeingCompleted = null; // only set while completing units |
65 |
|
67 |
|
Lines 79-84
Link Here
|
79 |
this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3); |
81 |
this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3); |
80 |
this.uniqueRawTypeBindings = new SimpleLookupTable(3); |
82 |
this.uniqueRawTypeBindings = new SimpleLookupTable(3); |
81 |
this.uniqueWildcardBindings = new SimpleLookupTable(3); |
83 |
this.uniqueWildcardBindings = new SimpleLookupTable(3); |
|
|
84 |
this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); |
82 |
this.accessRestrictions = new HashMap(3); |
85 |
this.accessRestrictions = new HashMap(3); |
83 |
|
86 |
|
84 |
this.classFilePool = ClassFilePool.newInstance(); |
87 |
this.classFilePool = ClassFilePool.newInstance(); |
Lines 198-204
Link Here
|
198 |
|
201 |
|
199 |
for (int i = this.lastCompletedUnitIndex + 1; i <= this.lastUnitIndex; i++) { |
202 |
for (int i = this.lastCompletedUnitIndex + 1; i <= this.lastUnitIndex; i++) { |
200 |
CompilationUnitScope unitScope = (this.unitBeingCompleted = this.units[i]).scope; |
203 |
CompilationUnitScope unitScope = (this.unitBeingCompleted = this.units[i]).scope; |
201 |
unitScope.checkParameterizedTypeBounds(); |
204 |
unitScope.checkParameterizedTypes(); |
202 |
unitScope.buildFieldsAndMethods(); |
205 |
unitScope.buildFieldsAndMethods(); |
203 |
this.units[i] = null; // release unnecessary reference to the parsed unit |
206 |
this.units[i] = null; // release unnecessary reference to the parsed unit |
204 |
} |
207 |
} |
Lines 249-255
Link Here
|
249 |
|
252 |
|
250 |
(this.unitBeingCompleted = parsedUnit).scope.checkAndSetImports(); |
253 |
(this.unitBeingCompleted = parsedUnit).scope.checkAndSetImports(); |
251 |
parsedUnit.scope.connectTypeHierarchy(); |
254 |
parsedUnit.scope.connectTypeHierarchy(); |
252 |
parsedUnit.scope.checkParameterizedTypeBounds(); |
255 |
parsedUnit.scope.checkParameterizedTypes(); |
253 |
if (buildFieldsAndMethods) |
256 |
if (buildFieldsAndMethods) |
254 |
parsedUnit.scope.buildFieldsAndMethods(); |
257 |
parsedUnit.scope.buildFieldsAndMethods(); |
255 |
this.unitBeingCompleted = null; |
258 |
this.unitBeingCompleted = null; |
Lines 556-572
Link Here
|
556 |
return packageBinding; |
559 |
return packageBinding; |
557 |
} |
560 |
} |
558 |
|
561 |
|
|
|
562 |
public ParameterizedGenericMethodBinding createParameterizedGenericMethod(MethodBinding genericMethod, RawTypeBinding rawType) { |
563 |
|
564 |
// cached info is array of already created parameterized types for this type |
565 |
ParameterizedGenericMethodBinding[] cachedInfo = (ParameterizedGenericMethodBinding[])this.uniqueParameterizedGenericMethodBindings.get(genericMethod); |
566 |
boolean needToGrow = false; |
567 |
int index = 0; |
568 |
if (cachedInfo != null){ |
569 |
nextCachedMethod : |
570 |
// iterate existing parameterized for reusing one with same type arguments if any |
571 |
for (int max = cachedInfo.length; index < max; index++){ |
572 |
ParameterizedGenericMethodBinding cachedMethod = cachedInfo[index]; |
573 |
if (cachedMethod == null) break nextCachedMethod; |
574 |
if (!cachedMethod.isRaw) continue nextCachedMethod; |
575 |
if (cachedMethod.declaringClass != (rawType == null ? genericMethod.declaringClass : rawType)) continue nextCachedMethod; |
576 |
return cachedMethod; |
577 |
} |
578 |
needToGrow = true; |
579 |
} else { |
580 |
cachedInfo = new ParameterizedGenericMethodBinding[5]; |
581 |
this.uniqueParameterizedGenericMethodBindings.put(genericMethod, cachedInfo); |
582 |
} |
583 |
// grow cache ? |
584 |
int length = cachedInfo.length; |
585 |
if (needToGrow && index == length){ |
586 |
System.arraycopy(cachedInfo, 0, cachedInfo = new ParameterizedGenericMethodBinding[length*2], 0, length); |
587 |
this.uniqueParameterizedGenericMethodBindings.put(genericMethod, cachedInfo); |
588 |
} |
589 |
// add new binding |
590 |
ParameterizedGenericMethodBinding parameterizedGenericMethod = new ParameterizedGenericMethodBinding(genericMethod, rawType, this); |
591 |
cachedInfo[index] = parameterizedGenericMethod; |
592 |
return parameterizedGenericMethod; |
593 |
} |
594 |
|
595 |
public ParameterizedGenericMethodBinding createParameterizedGenericMethod(MethodBinding genericMethod, TypeBinding[] typeArguments) { |
596 |
|
597 |
// cached info is array of already created parameterized types for this type |
598 |
ParameterizedGenericMethodBinding[] cachedInfo = (ParameterizedGenericMethodBinding[])this.uniqueParameterizedGenericMethodBindings.get(genericMethod); |
599 |
int argLength = typeArguments == null ? 0: typeArguments.length; |
600 |
boolean needToGrow = false; |
601 |
int index = 0; |
602 |
if (cachedInfo != null){ |
603 |
nextCachedMethod : |
604 |
// iterate existing parameterized for reusing one with same type arguments if any |
605 |
for (int max = cachedInfo.length; index < max; index++){ |
606 |
ParameterizedGenericMethodBinding cachedMethod = cachedInfo[index]; |
607 |
if (cachedMethod == null) break nextCachedMethod; |
608 |
if (cachedMethod.isRaw) continue nextCachedMethod; |
609 |
TypeBinding[] cachedArguments = cachedMethod.typeArguments; |
610 |
int cachedArgLength = cachedArguments == null ? 0 : cachedArguments.length; |
611 |
if (argLength != cachedArgLength) continue nextCachedMethod; |
612 |
for (int j = 0; j < cachedArgLength; j++){ |
613 |
if (typeArguments[j] != cachedArguments[j]) continue nextCachedMethod; |
614 |
} |
615 |
// all arguments match, reuse current |
616 |
return cachedMethod; |
617 |
} |
618 |
needToGrow = true; |
619 |
} else { |
620 |
cachedInfo = new ParameterizedGenericMethodBinding[5]; |
621 |
this.uniqueParameterizedGenericMethodBindings.put(genericMethod, cachedInfo); |
622 |
} |
623 |
// grow cache ? |
624 |
int length = cachedInfo.length; |
625 |
if (needToGrow && index == length){ |
626 |
System.arraycopy(cachedInfo, 0, cachedInfo = new ParameterizedGenericMethodBinding[length*2], 0, length); |
627 |
this.uniqueParameterizedGenericMethodBindings.put(genericMethod, cachedInfo); |
628 |
} |
629 |
// add new binding |
630 |
ParameterizedGenericMethodBinding parameterizedGenericMethod = new ParameterizedGenericMethodBinding(genericMethod, typeArguments, this); |
631 |
cachedInfo[index] = parameterizedGenericMethod; |
632 |
return parameterizedGenericMethod; |
633 |
} |
634 |
|
559 |
public ParameterizedTypeBinding createParameterizedType(ReferenceBinding genericType, TypeBinding[] typeArguments, ReferenceBinding enclosingType) { |
635 |
public ParameterizedTypeBinding createParameterizedType(ReferenceBinding genericType, TypeBinding[] typeArguments, ReferenceBinding enclosingType) { |
560 |
|
636 |
|
561 |
// cached info is array of already created parameterized types for this type |
637 |
// cached info is array of already created parameterized types for this type |
562 |
ParameterizedTypeBinding[] cachedInfo = (ParameterizedTypeBinding[])this.uniqueParameterizedTypeBindings.get(genericType); |
638 |
ParameterizedTypeBinding[] cachedInfo = (ParameterizedTypeBinding[])this.uniqueParameterizedTypeBindings.get(genericType); |
563 |
int argLength = typeArguments == null ? 0: typeArguments.length; |
639 |
int argLength = typeArguments == null ? 0: typeArguments.length; |
564 |
boolean needToGrow = false; |
640 |
boolean needToGrow = false; |
|
|
641 |
int index = 0; |
565 |
if (cachedInfo != null){ |
642 |
if (cachedInfo != null){ |
566 |
nextCachedType : |
643 |
nextCachedType : |
567 |
// iterate existing parameterized for reusing one with same type arguments if any |
644 |
// iterate existing parameterized for reusing one with same type arguments if any |
568 |
for (int i = 0, max = cachedInfo.length; i < max; i++){ |
645 |
for (int max = cachedInfo.length; index < max; index++){ |
569 |
ParameterizedTypeBinding cachedType = cachedInfo[i]; |
646 |
ParameterizedTypeBinding cachedType = cachedInfo[index]; |
|
|
647 |
if (cachedType == null) break nextCachedType; |
570 |
if (cachedType.type != genericType) continue nextCachedType; // remain of unresolved type |
648 |
if (cachedType.type != genericType) continue nextCachedType; // remain of unresolved type |
571 |
if (cachedType.enclosingType() != enclosingType) continue nextCachedType; |
649 |
if (cachedType.enclosingType() != enclosingType) continue nextCachedType; |
572 |
TypeBinding[] cachedArguments = cachedType.arguments; |
650 |
TypeBinding[] cachedArguments = cachedType.arguments; |
Lines 580-597
Link Here
|
580 |
} |
658 |
} |
581 |
needToGrow = true; |
659 |
needToGrow = true; |
582 |
} else { |
660 |
} else { |
583 |
cachedInfo = new ParameterizedTypeBinding[1]; |
661 |
cachedInfo = new ParameterizedTypeBinding[5]; |
584 |
this.uniqueParameterizedTypeBindings.put(genericType, cachedInfo); |
662 |
this.uniqueParameterizedTypeBindings.put(genericType, cachedInfo); |
585 |
} |
663 |
} |
586 |
// grow cache ? |
664 |
// grow cache ? |
587 |
if (needToGrow){ |
665 |
int length = cachedInfo.length; |
588 |
int length = cachedInfo.length; |
666 |
if (needToGrow && index == length){ |
589 |
System.arraycopy(cachedInfo, 0, cachedInfo = new ParameterizedTypeBinding[length+1], 0, length); |
667 |
System.arraycopy(cachedInfo, 0, cachedInfo = new ParameterizedTypeBinding[length*2], 0, length); |
590 |
this.uniqueParameterizedTypeBindings.put(genericType, cachedInfo); |
668 |
this.uniqueParameterizedTypeBindings.put(genericType, cachedInfo); |
591 |
} |
669 |
} |
592 |
// add new binding |
670 |
// add new binding |
593 |
ParameterizedTypeBinding parameterizedType = new ParameterizedTypeBinding(genericType,typeArguments, enclosingType, this); |
671 |
ParameterizedTypeBinding parameterizedType = new ParameterizedTypeBinding(genericType,typeArguments, enclosingType, this); |
594 |
cachedInfo[cachedInfo.length-1] = parameterizedType; |
672 |
cachedInfo[index] = parameterizedType; |
595 |
return parameterizedType; |
673 |
return parameterizedType; |
596 |
} |
674 |
} |
597 |
|
675 |
|
Lines 599-609
Link Here
|
599 |
// cached info is array of already created raw types for this type |
677 |
// cached info is array of already created raw types for this type |
600 |
RawTypeBinding[] cachedInfo = (RawTypeBinding[])this.uniqueRawTypeBindings.get(genericType); |
678 |
RawTypeBinding[] cachedInfo = (RawTypeBinding[])this.uniqueRawTypeBindings.get(genericType); |
601 |
boolean needToGrow = false; |
679 |
boolean needToGrow = false; |
|
|
680 |
int index = 0; |
602 |
if (cachedInfo != null){ |
681 |
if (cachedInfo != null){ |
603 |
nextCachedType : |
682 |
nextCachedType : |
604 |
// iterate existing parameterized for reusing one with same type arguments if any |
683 |
// iterate existing parameterized for reusing one with same type arguments if any |
605 |
for (int i = 0, max = cachedInfo.length; i < max; i++){ |
684 |
for (int max = cachedInfo.length; index < max; index++){ |
606 |
RawTypeBinding cachedType = cachedInfo[i]; |
685 |
RawTypeBinding cachedType = cachedInfo[index]; |
|
|
686 |
if (cachedType == null) break nextCachedType; |
607 |
if (cachedType.type != genericType) continue nextCachedType; // remain of unresolved type |
687 |
if (cachedType.type != genericType) continue nextCachedType; // remain of unresolved type |
608 |
if (cachedType.enclosingType() != enclosingType) continue nextCachedType; |
688 |
if (cachedType.enclosingType() != enclosingType) continue nextCachedType; |
609 |
// all enclosing type match, reuse current |
689 |
// all enclosing type match, reuse current |
Lines 615-628
Link Here
|
615 |
this.uniqueRawTypeBindings.put(genericType, cachedInfo); |
695 |
this.uniqueRawTypeBindings.put(genericType, cachedInfo); |
616 |
} |
696 |
} |
617 |
// grow cache ? |
697 |
// grow cache ? |
618 |
if (needToGrow){ |
698 |
int length = cachedInfo.length; |
619 |
int length = cachedInfo.length; |
699 |
if (needToGrow && index == length){ |
620 |
System.arraycopy(cachedInfo, 0, cachedInfo = new RawTypeBinding[length+1], 0, length); |
700 |
System.arraycopy(cachedInfo, 0, cachedInfo = new RawTypeBinding[length*2], 0, length); |
621 |
this.uniqueRawTypeBindings.put(genericType, cachedInfo); |
701 |
this.uniqueRawTypeBindings.put(genericType, cachedInfo); |
622 |
} |
702 |
} |
623 |
// add new binding |
703 |
// add new binding |
624 |
RawTypeBinding rawType = new RawTypeBinding(genericType, enclosingType, this); |
704 |
RawTypeBinding rawType = new RawTypeBinding(genericType, enclosingType, this); |
625 |
cachedInfo[cachedInfo.length-1] = rawType; |
705 |
cachedInfo[index] = rawType; |
626 |
return rawType; |
706 |
return rawType; |
627 |
|
707 |
|
628 |
} |
708 |
} |
Lines 634-644
Link Here
|
634 |
genericType = ReferenceBinding.LUB_GENERIC; |
714 |
genericType = ReferenceBinding.LUB_GENERIC; |
635 |
WildcardBinding[] cachedInfo = (WildcardBinding[])this.uniqueWildcardBindings.get(genericType); |
715 |
WildcardBinding[] cachedInfo = (WildcardBinding[])this.uniqueWildcardBindings.get(genericType); |
636 |
boolean needToGrow = false; |
716 |
boolean needToGrow = false; |
|
|
717 |
int index = 0; |
637 |
if (cachedInfo != null){ |
718 |
if (cachedInfo != null){ |
638 |
nextCachedType : |
719 |
nextCachedType : |
639 |
// iterate existing wildcards for reusing one with same information if any |
720 |
// iterate existing wildcards for reusing one with same information if any |
640 |
for (int i = 0, max = cachedInfo.length; i < max; i++){ |
721 |
for (int max = cachedInfo.length; index < max; index++){ |
641 |
WildcardBinding cachedType = cachedInfo[i]; |
722 |
WildcardBinding cachedType = cachedInfo[index]; |
|
|
723 |
if (cachedType == null) break nextCachedType; |
642 |
if (cachedType.genericType != genericType) continue nextCachedType; // remain of unresolved type |
724 |
if (cachedType.genericType != genericType) continue nextCachedType; // remain of unresolved type |
643 |
if (cachedType.rank != rank) continue nextCachedType; |
725 |
if (cachedType.rank != rank) continue nextCachedType; |
644 |
if (cachedType.boundKind != boundKind) continue nextCachedType; |
726 |
if (cachedType.boundKind != boundKind) continue nextCachedType; |
Lines 656-673
Link Here
|
656 |
} |
738 |
} |
657 |
needToGrow = true; |
739 |
needToGrow = true; |
658 |
} else { |
740 |
} else { |
659 |
cachedInfo = new WildcardBinding[1]; |
741 |
cachedInfo = new WildcardBinding[10]; |
660 |
this.uniqueWildcardBindings.put(genericType, cachedInfo); |
742 |
this.uniqueWildcardBindings.put(genericType, cachedInfo); |
661 |
} |
743 |
} |
662 |
// grow cache ? |
744 |
// grow cache ? |
663 |
if (needToGrow){ |
745 |
int length = cachedInfo.length; |
664 |
int length = cachedInfo.length; |
746 |
if (needToGrow && index == length){ |
665 |
System.arraycopy(cachedInfo, 0, cachedInfo = new WildcardBinding[length+1], 0, length); |
747 |
System.arraycopy(cachedInfo, 0, cachedInfo = new WildcardBinding[length*2], 0, length); |
666 |
this.uniqueWildcardBindings.put(genericType, cachedInfo); |
748 |
this.uniqueWildcardBindings.put(genericType, cachedInfo); |
667 |
} |
749 |
} |
668 |
// add new binding |
750 |
// add new binding |
669 |
WildcardBinding wildcard = new WildcardBinding(genericType, rank, bound, otherBounds, boundKind, this); |
751 |
WildcardBinding wildcard = new WildcardBinding(genericType, rank, bound, otherBounds, boundKind, this); |
670 |
cachedInfo[cachedInfo.length-1] = wildcard; |
752 |
cachedInfo[index] = wildcard; |
671 |
return wildcard; |
753 |
return wildcard; |
672 |
} |
754 |
} |
673 |
|
755 |
|
Lines 1027-1032
Link Here
|
1027 |
this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3); |
1109 |
this.uniqueParameterizedTypeBindings = new SimpleLookupTable(3); |
1028 |
this.uniqueRawTypeBindings = new SimpleLookupTable(3); |
1110 |
this.uniqueRawTypeBindings = new SimpleLookupTable(3); |
1029 |
this.uniqueWildcardBindings = new SimpleLookupTable(3); |
1111 |
this.uniqueWildcardBindings = new SimpleLookupTable(3); |
|
|
1112 |
this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); |
1030 |
|
1113 |
|
1031 |
for (int i = this.units.length; --i >= 0;) |
1114 |
for (int i = this.units.length; --i >= 0;) |
1032 |
this.units[i] = null; |
1115 |
this.units[i] = null; |