internal void UpdateType(SyntaxNode node, EnvDTE.CodeTypeRef codeTypeRef) { node = CodeModelService.GetNodeWithType(node); var typeSymbol = codeTypeRef != null ? CodeModelService.GetTypeSymbolFromFullName(codeTypeRef.AsFullName, GetCompilation()) : null; var updatedNode = CodeModelService.SetType(node, typeSymbol); if (node != updatedNode) { UpdateNode(node, updatedNode); } }
// Builds a model type. private MType BuildMTypeRef(EnvDTE.CodeTypeRef codeTypeRef) { // Declarations MType mType; // Checks if property is generic. if (codeTypeRef.TypeKind == EnvDTE.vsCMTypeRef.vsCMTypeRefOther) { // Builds generic type. mType = new MType(); mType.Name = codeTypeRef.AsString; mType.FullName = codeTypeRef.AsFullName; mType.Type = MType.MTType.Generic; } else { mType = BuildMType(codeTypeRef.CodeType); } return(mType); }
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 sybol first. string[] memberNameWords = member.Name.Split(' '); if (memberNameWords.Length >= 2) { string operatorSymbol = memberNameWords[1]; string operatorName = ICSharpCode.NRefactory.MonoCSharp.Operator.GetMetadataName(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()); }