package jetbrains.mps.baseLanguage.scopes;
/*Generated by MPS */
import org.jetbrains.mps.openapi.model.SNode;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SPropertyOperations;
import jetbrains.mps.smodel.adapter.structure.MetaAdapterFactory;
import jetbrains.mps.lang.smodel.generator.smodelAdapter.SLinkOperations;
import jetbrains.mps.baseLanguage.tuples.runtime.Tuples;
import jetbrains.mps.baseLanguage.tuples.runtime.MultiTuple;
import jetbrains.mps.baseLanguage.behavior.Type__BehaviorDescriptor;
public class MethodSignature implements Signature {
private final String singature;
public MethodSignature(SNode method, Map<SNode, SNode> typeByTypeVariable, MembersPopulatingContext context) {
this.singature = getStringSignature(method, typeByTypeVariable, context);
}
public MethodSignature(SNode method, Map<SNode, SNode> typeByTypeVariable) {
this.singature = getStringSignature(method, typeByTypeVariable, null);
}
@Override
public int hashCode() {
return MethodSignature.class.hashCode() ^ singature.hashCode();
}
@Override
public boolean equals(Object object) {
if (!(object instanceof MethodSignature)) {
return false;
}
MethodSignature arg = (MethodSignature) object;
return eq_1fkaqj_a0c0e(this.singature, arg.singature);
}
public static String getStringSignature(SNode method, Map<SNode, SNode> typeByTypeVariable, @Nullable MembersPopulatingContext context) {
StringBuilder result = new StringBuilder();
result.append(SPropertyOperations.getString(method, MetaAdapterFactory.getProperty(0xceab519525ea4f22L, 0x9b92103b95ca8c0cL, 0x110396eaaa4L, 0x110396ec041L, "name")));
result.append('(');
for (SNode parm : SLinkOperations.getChildren(method, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0xf8cc56b1fcL, 0xf8cc56b1feL, "parameter"))) {
SNode type = SLinkOperations.getTarget(parm, MetaAdapterFactory.getContainmentLink(0xf3061a5392264cc5L, 0xa443f952ceaf5816L, 0x450368d90ce15bc3L, 0x4ed4d318133c80ceL, "type"));
type = GenericTypesUtil.getTypeWithResolvedTypeVars(type, typeByTypeVariable);
if (result.length() > 0) {
result.append(',');
}
if (type != null) {
if (context != null) {
Tuples._2<Class, SNode> cacheKey = MultiTuple.<Class,SNode>from(MethodSignature.class, type);
if (context.containsUserObject(cacheKey)) {
result.append(context.getUserObject(cacheKey));
} else {
String typeSignature = Type__BehaviorDescriptor.getErasureSignature_idhEwIzNx.invoke(type);
context.putUserObject(cacheKey, typeSignature);
result.append(typeSignature);
}
} else {
result.append(Type__BehaviorDescriptor.getErasureSignature_idhEwIzNx.invoke(type));
}
} else {
result.append("");
}
}
result.append(')');
return result.toString();
}
private static boolean eq_1fkaqj_a0c0e(Object a, Object b) {
return (a != null ? a.equals(b) : a == b);
}
}