public override void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration) { var resolveResult = _resolver.Resolve(operatorDeclaration); if (!(resolveResult is MemberResolveResult)) { _errorReporter.Region = operatorDeclaration.GetRegion(); _errorReporter.InternalError("Operator declaration " + OperatorDeclaration.GetName(operatorDeclaration.OperatorType) + " does not resolve to a member."); return; } var method = ((MemberResolveResult)resolveResult).Member as IMethod; if (method == null) { _errorReporter.Region = operatorDeclaration.GetRegion(); _errorReporter.InternalError("Operator declaration " + OperatorDeclaration.GetName(operatorDeclaration.OperatorType) + " does not resolve to a method (resolves to " + resolveResult.ToString() + ")"); return; } var jsClass = GetJsClass(method.DeclaringTypeDefinition); if (jsClass == null) { return; } MaybeCompileAndAddMethodToType(jsClass, operatorDeclaration, operatorDeclaration.Body, method, _metadataImporter.GetMethodSemantics(method)); }
public static string GetKey(EnvDTE.CodeElement member) { StringBuilder b = new StringBuilder(); if ((member.Kind == EnvDTE.vsCMElement.vsCMElementDelegate) || (member.Kind == EnvDTE.vsCMElement.vsCMElementEnum) || (member.Kind == EnvDTE.vsCMElement.vsCMElementInterface) || (member.Kind == EnvDTE.vsCMElement.vsCMElementStruct) || (member.Kind == EnvDTE.vsCMElement.vsCMElementClass)) { b.Append("T:"); AppendTypeName(b, member.FullName, true, false); } else if (member.Kind == EnvDTE.vsCMElement.vsCMElementNamespace) { b.Append("N:"); b.Append(member.FullName); } else { if (member.Kind == EnvDTE.vsCMElement.vsCMElementVariable) { b.Append("F:"); } else if (member.Kind == EnvDTE.vsCMElement.vsCMElementProperty) { b.Append("P:"); } else if (member.Kind == EnvDTE.vsCMElement.vsCMElementEvent) { b.Append("E:"); } else if (member.Kind == EnvDTE.vsCMElement.vsCMElementFunction) { b.Append("M:"); } int nameIndex = member.FullName.LastIndexOf(member.Name); string typeName = member.FullName.Substring(0, nameIndex - 1); string memberName = member.FullName.Substring(nameIndex); // Name substitutions for special cases. if (member.Kind == EnvDTE.vsCMElement.vsCMElementFunction) { EnvDTE80.CodeFunction2 mr = (EnvDTE80.CodeFunction2)member; if (mr.FunctionKind == EnvDTE.vsCMFunction.vsCMFunctionConstructor) { memberName = memberName.Replace(member.Name, "#ctor"); } else if (mr.FunctionKind == EnvDTE.vsCMFunction.vsCMFunctionDestructor) { memberName = memberName.Replace(member.Name, "Finalize"); } else if (mr.FunctionKind == EnvDTE.vsCMFunction.vsCMFunctionOperator) { if (memberName.StartsWith("implicit operator")) { memberName = "op_Implicit"; } else if (memberName.StartsWith("explicit operator")) { memberName = "op_Explicit"; } else { // NRefactory has a handy mapping we can make use of, just need to extract the operator symbol first. string[] memberNameWords = member.Name.Split(' '); if (memberNameWords.Length >= 2) { string operatorSymbol = memberNameWords[1]; string operatorName = OperatorDeclaration.GetName(OperatorDeclaration.GetOperatorType(operatorSymbol)); if (operatorName != null) { memberName = memberName.Replace(member.Name, operatorName); } } } } } else if (member.Kind == EnvDTE.vsCMElement.vsCMElementProperty) { if (member.Name == "this") { memberName = memberName.Replace(member.Name, "Item"); } } string[] genericTypeParameters = AppendTypeName(b, typeName, true, false); b.Append('.'); string[] genericMethodParameters = AppendTypeName(b, memberName.Replace('.', '#'), true, true); EnvDTE.CodeElements parameters; EnvDTE.CodeTypeRef explicitReturnType = null; if (member.Kind == EnvDTE.vsCMElement.vsCMElementProperty) { parameters = ((EnvDTE.CodeProperty)member).Getter.Parameters; } else if (member.Kind == EnvDTE.vsCMElement.vsCMElementFunction) { EnvDTE80.CodeFunction2 mr = (EnvDTE80.CodeFunction2)member; parameters = mr.Parameters; if (memberName == "op_Implicit" || memberName == "op_Explicit") { explicitReturnType = mr.Type; } } else { parameters = null; } if (parameters != null && parameters.Count > 0) { b.Append('('); int i = 0; foreach (EnvDTE80.CodeParameter2 parameter in parameters) { if (i > 0) { b.Append(','); } AppendParameterTypeName(b, parameter, genericTypeParameters, genericMethodParameters); ++i; } b.Append(')'); } if (explicitReturnType != null) { b.Append('~'); AppendTypeName(b, explicitReturnType.AsFullName, true, false); } } return(b.ToString()); }