@@ -42,7 +42,13 @@ public string Format(ICodePane activeCodePane, Declaration declaration)
4242
4343 public string Format ( Declaration declaration , bool multipleControls )
4444 {
45- return declaration == null ? string . Empty : FormatDeclaration ( declaration , multipleControls ) ;
45+ if ( declaration == null )
46+ {
47+ return string . Empty ;
48+ }
49+
50+ // designer, there is no code pane selection
51+ return FormatDeclaration ( declaration , multipleControls ) ;
4652 }
4753
4854 private string FormatDeclaration ( Declaration declaration , bool multipleControls = false )
@@ -72,18 +78,18 @@ private static string FormattedDeclaration(
7278 if ( declaration . ParentDeclaration . DeclarationType . HasFlag ( DeclarationType . Module ) )
7379 {
7480 // fields
75- var withEvents = declaration . IsWithEvents ? "( WithEvents) " : string . Empty ;
81+ var withEvents = declaration . IsWithEvents ? $ "( { Tokens . WithEvents } ) " : string . Empty ;
7682 return $ "{ withEvents } { moduleName } .{ declaration . IdentifierName } { typeName } ";
7783 }
7884 }
7985
8086 if ( declaration . DeclarationType . HasFlag ( DeclarationType . Member ) )
8187 {
82- var formattedDeclaration = declaration . QualifiedName . ToString ( ) ;
88+ var formattedDeclaration = $ " { declaration . QualifiedName } " ;
8389 if ( declaration . DeclarationType == DeclarationType . Function
8490 || declaration . DeclarationType == DeclarationType . PropertyGet )
8591 {
86- formattedDeclaration += typeName ;
92+ formattedDeclaration += $ " { typeName } " ;
8793 }
8894
8995 return formattedDeclaration ;
@@ -103,16 +109,16 @@ private static string FormattedDeclaration(
103109 case DeclarationType . Enumeration :
104110 case DeclarationType . UserDefinedType :
105111 return ! declaration . IsUserDefined
106- // built-in enums & UDT's don't have a module
107- ? $ "{ Path . GetFileName ( moduleName . ProjectPath ) } ;{ moduleName . ProjectName } . { declaration . IdentifierName } "
112+ // built-in enums & UDTs don't have a module
113+ ? $ "{ Path . GetFileName ( moduleName . ProjectPath ) } ;{ declaration . IdentifierName } "
108114 : moduleName . ToString ( ) ;
109115 case DeclarationType . EnumerationMember :
110116 case DeclarationType . UserDefinedTypeMember :
111117 return declaration . IsUserDefined
112118 ? $ "{ moduleName } .{ declaration . ParentDeclaration . IdentifierName } .{ declaration . IdentifierName } { typeName } "
113- : $ "{ Path . GetFileName ( moduleName . ProjectPath ) } ;{ moduleName . ProjectName } . { declaration . ParentDeclaration . IdentifierName } .{ declaration . IdentifierName } { typeName } ";
119+ : $ "{ Path . GetFileName ( moduleName . ProjectPath ) } ;{ declaration . ParentDeclaration . IdentifierName } .{ declaration . IdentifierName } { typeName } ";
114120 case DeclarationType . ComAlias :
115- return $ "{ Path . GetFileName ( moduleName . ProjectPath ) } ;{ moduleName . ProjectName } . { declaration . IdentifierName } (alias:{ declaration . AsTypeName } )";
121+ return $ "{ Path . GetFileName ( moduleName . ProjectPath ) } ;{ declaration . IdentifierName } (alias:{ declaration . AsTypeName } )";
116122 }
117123
118124 return string . Empty ;
@@ -125,22 +131,20 @@ private static string TypeName(Declaration declaration, bool multipleControls, s
125131 return RubberduckUI . ContextMultipleControlsSelection ;
126132 }
127133
128- var friendlyTypeName = " IDispatch" . Equals ( declaration . AsTypeName , System . StringComparison . InvariantCultureIgnoreCase )
129- ? " Object"
134+ var typeName = Tokens . IDispatch . Equals ( declaration . AsTypeName , System . StringComparison . InvariantCultureIgnoreCase )
135+ ? Tokens . Object
130136 : declaration . AsTypeName ?? string . Empty ;
131137
132- var typeName = declaration . IsArray
133- ? $ "{ friendlyTypeName } ()"
134- : friendlyTypeName ;
138+ var friendlyTypeName = declaration . IsArray ? $ "{ typeName } ()" : typeName ;
135139
136140 switch ( declaration )
137141 {
138142 case ValuedDeclaration valued :
139- return $ "({ declarationType } { ( string . IsNullOrEmpty ( typeName ) ? string . Empty : ":" + typeName ) } { ( string . IsNullOrEmpty ( valued . Expression ) ? string . Empty : $ " = { valued . Expression } ") } )";
143+ return $ "({ declarationType } { ( string . IsNullOrEmpty ( friendlyTypeName ) ? string . Empty : ":" + friendlyTypeName ) } { ( string . IsNullOrEmpty ( valued . Expression ) ? string . Empty : $ " = { valued . Expression } ") } )";
140144 case ParameterDeclaration parameter :
141- return $ "({ declarationType } { ( string . IsNullOrEmpty ( typeName ) ? string . Empty : ":" + typeName ) } { ( string . IsNullOrEmpty ( parameter . DefaultValue ) ? string . Empty : $ " = { parameter . DefaultValue } ") } )";
145+ return $ "({ declarationType } { ( string . IsNullOrEmpty ( friendlyTypeName ) ? string . Empty : ":" + friendlyTypeName ) } { ( string . IsNullOrEmpty ( parameter . DefaultValue ) ? string . Empty : $ " = { parameter . DefaultValue } ") } )";
142146 default :
143- return $ "({ declarationType } { ( string . IsNullOrEmpty ( typeName ) ? string . Empty : ":" + typeName ) } )";
147+ return $ "({ declarationType } { ( string . IsNullOrEmpty ( friendlyTypeName ) ? string . Empty : ":" + friendlyTypeName ) } )";
144148 }
145149 }
146150 }
0 commit comments