public override SymbolDefinition TypeOf() { var result = referencedSymbol.TypeOf() as TypeDefinitionBase; var ctx = parentSymbol as SD_Type_Constructed; if (ctx != null && result != null) { result = result.SubstituteTypeParameters(ctx); } return(result); }
public override string Expand() { string comment = ""; if (SISettings.magicMethods_insertWithComments && UnitySymbols.summaries.Count > 0) { var commentKey = typeof(T).Name + '.' + name; if (UnitySymbols.summaries.TryGetValue(commentKey, out comment)) { comment = "// " + comment + "\n"; } else { comment = ""; } } string modifiers = contextType.IsSealed ? "" : "protected "; string baseCall = ""; if (baseSymbol != null) { modifiers += "new "; if (baseSymbol.kind == SymbolKind.Method) { baseCall = "base." + name + "("; var parameters = baseSymbol.GetParameters(); var separator = ""; foreach (var p in parameters) { baseCall += separator; baseCall += p.name; separator = ", "; } baseCall += ")"; var returnType = baseSymbol.TypeOf(); var baseIsCoroutine = returnType != null && returnType.name == "IEnumerator"; if (baseIsCoroutine) { baseCall = "StartCoroutine(" + baseCall + ")"; if (IsCoroutine) { baseCall = "yield return " + baseCall; } } baseCall += ";"; } } string expandedCode; expandedCode = string.Format("{0}{1}{2}{3}{{\n\t{4}$end$\n}}", comment, modifiers, signature, SISettings.magicMethods_openingBraceOnSameLine ? " " : "\n", baseCall); return(expandedCode); }
private static void GetMemberCompletions(SymbolDefinition targetDef, SyntaxTreeNode_Base parseTreeNode, SD_Assembly assemblyDefinition, Dictionary <string, SymbolDefinition> d, bool includeExtensionMethods) { if (targetDef != null) { var typeOf = targetDef.TypeOf(); var flags = BindingFlags.Instance | BindingFlags.Static; switch (targetDef.kind) { case SymbolKind.None: case SymbolKind.Error: break; case SymbolKind.Namespace: case SymbolKind.Interface: case SymbolKind.Struct: case SymbolKind.Class: case SymbolKind.TypeParameter: case SymbolKind.Delegate: flags = BindingFlags.Static; break; case SymbolKind.Enum: flags = BindingFlags.Static; break; case SymbolKind.Field: case SymbolKind.ConstantField: case SymbolKind.LocalConstant: case SymbolKind.Property: case SymbolKind.Event: case SymbolKind.Indexer: case SymbolKind.Method: case SymbolKind.MethodGroup: case SymbolKind.Constructor: case SymbolKind.Destructor: case SymbolKind.Operator: case SymbolKind.Accessor: case SymbolKind.Parameter: case SymbolKind.CatchParameter: case SymbolKind.Variable: case SymbolKind.ForEachVariable: case SymbolKind.FromClauseVariable: case SymbolKind.EnumMember: flags = BindingFlags.Instance; break; case SymbolKind.BaseTypesList: case SymbolKind.TypeParameterConstraintList: flags = BindingFlags.Static; break; case SymbolKind.Instance: flags = BindingFlags.Instance; break; case SymbolKind.Null: return; default: throw new ArgumentOutOfRangeException(); } //targetDef.kind = targetDef is TypeDefinitionBase && targetDef.kind != SymbolKind.Enum ? BindingFlags.Static : targetDef is InstanceDefinition ? BindingFlags.Instance : 0; TypeDefinitionBase contextType = null; for (var n = parseTreeNode as SyntaxTreeNode_Rule ?? parseTreeNode.Parent; n != null; n = n.Parent) { var s = n.scope as Scope_SymbolDeclaration; if (s != null) { contextType = s.declaration.definition as TypeDefinitionBase; if (contextType != null) { break; } } } AccessLevelMask mask = typeOf == contextType || typeOf.IsSameOrParentOf(contextType) ? AccessLevelMask.Private | AccessLevelMask.Protected | AccessLevelMask.Internal | AccessLevelMask.Public : contextType != null && contextType.DerivesFrom(typeOf as TypeDefinitionBase) ? AccessLevelMask.Protected | AccessLevelMask.Internal | AccessLevelMask.Public : AccessLevelMask.Internal | AccessLevelMask.Public; if (typeOf.Assembly == null || !typeOf.Assembly.InternalsVisibleIn(assemblyDefinition)) { mask &= ~AccessLevelMask.Internal; } typeOf.GetMembersCompletionData(d, flags, mask, assemblyDefinition); if (includeExtensionMethods && flags == BindingFlags.Instance && (typeOf.kind == SymbolKind.Class || typeOf.kind == SymbolKind.Struct || typeOf.kind == SymbolKind.Interface || typeOf.kind == SymbolKind.Enum)) { var enclosingScopeNode = parseTreeNode as SyntaxTreeNode_Rule ?? parseTreeNode.Parent; while (enclosingScopeNode != null && enclosingScopeNode.scope == null) { enclosingScopeNode = enclosingScopeNode.Parent; } var enclosingScope = enclosingScopeNode != null ? enclosingScopeNode.scope : null; if (enclosingScope != null) { enclosingScope.GetExtensionMethodsCompletionData(typeOf as TypeDefinitionBase, d); } } } }