slcom/slangc/bytecode/MethodSignature.sauce

61 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

package slangc.bytecode;
import slang.data.Mappable;
public final class MethodSignature implements Mappable {
public static enum Kind {
STATIC_INIT,
CONSTRUCTOR,
STATIC_METHOD,
INSTANCE_METHOD,
INTERFACE_METHOD
}
public final TypeSignature owner;
public final Kind kind;
public final TypeSignature returnType;
public final String name;
public final TypeSignature[] argumentTypes;
public MethodSignature(TypeSignature owner, Kind kind, TypeSignature returnType, String name,
TypeSignature[] argumentTypes) {
super();
this.owner = owner;
this.kind = kind;
this.returnType = returnType;
this.name = name;
this.argumentTypes = argumentTypes;
cachedHash = Mappable.hashOf(toString());
}
public boolean isStatic() {
switch (kind) {
case Kind.STATIC_INIT:
case Kind.STATIC_METHOD:
return true;
default:
return false;
}
}
@Override
public String toString() {
return owner.toString() + (isStatic() ? "##" : "#") + name + "(" + TypeSignature.arrayToString(argumentTypes) + ")" + ":" + (returnType == null ? "void" : returnType.toString());
}
int cachedHash = 0;
@Override
public int mappableHash() {
return cachedHash; //Mappable.hashOf(toString());
}
@Override
public boolean mappableEquals(Mappable obj) {
if (obj instanceof MethodSignature) {
MethodSignature mso = (MethodSignature)obj;
return mso.name == this.name && this.toString().equals(mso.toString());
} else {
return false; //super.equals(obj);
}
}
}