Skip to content

Commit

Permalink
TypeBinding: What happens without custom hash()?
Browse files Browse the repository at this point in the history
  • Loading branch information
EcljpseB0T committed Dec 6, 2024
1 parent 11bf464 commit e2f78ee
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 44 deletions.
5 changes: 1 addition & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ pipeline {
# The max heap should be specified for tycho explicitly
# via configuration/argLine property in pom.xml
# export MAVEN_OPTS="-Xmx2G"
mvn clean install -f org.eclipse.jdt.core.compiler.batch -DlocalEcjVersion=99.99 -Dmaven.repo.local=$WORKSPACE/.m2/repository -DcompilerBaselineMode=disable -DcompilerBaselineReplace=none
mvn -U clean verify --batch-mode --fail-at-end -Dmaven.repo.local=$WORKSPACE/.m2/repository \
-Ptest-on-javase-23 -Pbree-libs -Papi-check -Pjavadoc -Pp2-repo \
-Dmaven.test.failure.ignore=true \
Expand All @@ -39,7 +37,6 @@ pipeline {
-DDetectVMInstallationsJob.disabled=true \
-Dtycho.apitools.debug \
-Dtycho.debug.artifactcomparator \
-Dcbi-ecj-version=99.99
"""
}
post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,6 @@ public PackageBinding getPackage() {
return this.leafComponentType.getPackage();
}

@Override
public int hashCode() {
return this.leafComponentType == null ? super.hashCode() : this.leafComponentType.hashCode();
}

/* Answer true if the receiver type can be assigned to the argument type (right)
*/
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ public TypeBinding clone(TypeBinding outerType) {
return copy;
}

@Override
public int hashCode() {
return this.enclosingType.hashCode();
}
/*
* Overriden for code assist. In this case, the constantPoolName() has not been computed yet.
* Slam the source name so that the signature is syntactically correct.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,15 +1204,6 @@ public TypeVariableBinding getTypeVariable(char[] variableName) {
return null;
}

@Override
public int hashCode() {
// ensure ReferenceBindings hash to the same position as UnresolvedReferenceBindings so they can be replaced without rehashing
// ALL ReferenceBindings are unique when created so equals() is the same as ==
return (this.compoundName == null || this.compoundName.length == 0)
? super.hashCode()
: CharOperation.hashCode(this.compoundName[this.compoundName.length - 1]);
}

final int identityHashCode() {
return super.hashCode();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*******************************************************************************/
package org.eclipse.jdt.internal.compiler.lookup;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
Expand Down Expand Up @@ -133,25 +135,9 @@ public boolean equals(Object other) {
PTBKey that = (PTBKey) other; // homogeneous container.
return this.type == that.type && this.enclosingType == that.enclosingType && Util.effectivelyEqual(this.arguments, that.arguments); //$IDENTITY-COMPARISON$
}
final int hash(TypeBinding b) {
if(b instanceof WildcardBinding || b instanceof TypeVariableBinding || b.getClass() == ParameterizedTypeBinding.class) {
return System.identityHashCode(b);
}
return b.hashCode();
}
@Override
public int hashCode() {
final int prime=31;
int hashCode = 1 + hash(this.type);
if (this.enclosingType != null && this.enclosingType.getClass() == ParameterizedTypeBinding.class) {
// Note: this works as in swapUnresolved, a null enclosingType is never replaced by a
// ParameterizedTypeBinding (just by a non-generic or RawTypeBinding)
hashCode = hashCode * prime + System.identityHashCode(this.enclosingType);
}
for (int i = 0, length = this.arguments == null ? 0 : this.arguments.length; i < length; i++) {
hashCode = hashCode * prime + hash(this.arguments[i]);
}
return hashCode;
return Objects.hash(this.type, this.enclosingType, Arrays.hashCode(this.arguments));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,6 @@ public char[] genericTypeSignature() {
return this.genericSignature;
}

@Override
public int hashCode() {
return this.genericType.hashCode();
}

@Override
public boolean hasTypeBit(int bit) {
if (this.typeBits == TypeIds.BitUninitialized) {
Expand Down

0 comments on commit e2f78ee

Please sign in to comment.