@@ -148,7 +148,14 @@ export class ApexMigration extends BaseRelatedObjectMigration {
148148 parser . parse ( ) ;
149149 const tokenUpdates : TokenUpdater [ ] = [ ] ;
150150 const tokenUpdatesForRemoteCalls = this . processApexFileForRemotecalls ( file , parser ) ;
151- const tokeUpdatesForMethodCalls = this . processApexFileForMethodCalls ( file , parser ) ;
151+ const ipNameUpdateFailed = new Set < string > ( ) ;
152+ const dmNameUpdateFailed = new Set < string > ( ) ;
153+ const tokenUpdatesForMethodCalls = this . processApexFileForMethodCalls ( file , parser , ipNameUpdateFailed ) ;
154+ const tokenUpdatesForSimpleVarDeclarations = this . processApexFileForSimpleVarDeclarations (
155+ parser ,
156+ ipNameUpdateFailed ,
157+ dmNameUpdateFailed
158+ ) ;
152159 const updateMessages : string [ ] = [ ] ;
153160
154161 if ( tokenUpdatesForRemoteCalls && tokenUpdatesForRemoteCalls . length > 0 ) {
@@ -159,14 +166,37 @@ export class ApexMigration extends BaseRelatedObjectMigration {
159166 updateMessages . push ( assessMessages . getMessage ( 'fileUpdatedToAllowRemoteCalls' ) ) ;
160167 }
161168 }
162- if ( tokeUpdatesForMethodCalls && tokeUpdatesForMethodCalls . length > 0 ) {
169+ if ( tokenUpdatesForMethodCalls && tokenUpdatesForMethodCalls . length > 0 ) {
163170 if ( type === 'migration' ) {
164171 updateMessages . push ( migrateMessages . getMessage ( 'fileUpdatedToAllowCalls' ) ) ;
165172 } else {
166173 updateMessages . push ( assessMessages . getMessage ( 'fileUpdatedToAllowCalls' ) ) ;
167174 }
168- tokenUpdates . push ( ...tokeUpdatesForMethodCalls ) ;
175+ tokenUpdates . push ( ...tokenUpdatesForMethodCalls ) ;
176+ }
177+
178+ if ( tokenUpdatesForSimpleVarDeclarations && tokenUpdatesForSimpleVarDeclarations . length > 0 ) {
179+ if ( type === 'migration' ) {
180+ updateMessages . push ( migrateMessages . getMessage ( 'varDeclarationUpdated' ) ) ;
181+ } else {
182+ updateMessages . push ( assessMessages . getMessage ( 'varDeclarationUpdated' ) ) ;
183+ }
184+ tokenUpdates . push ( ...tokenUpdatesForSimpleVarDeclarations ) ;
169185 }
186+
187+ const warnings : string [ ] = [ ] ;
188+
189+ if ( ipNameUpdateFailed . size > 0 ) {
190+ ipNameUpdateFailed . forEach ( ( name ) => {
191+ warnings . push ( assessMessages . getMessage ( 'ipNameUpdateFailed' , [ name ] ) ) ;
192+ } ) ;
193+ }
194+ if ( dmNameUpdateFailed . size > 0 ) {
195+ dmNameUpdateFailed . forEach ( ( name ) => {
196+ warnings . push ( assessMessages . getMessage ( 'dmNameUpdateFailed' , [ name ] ) ) ;
197+ } ) ;
198+ }
199+
170200 let difference = [ ] ;
171201 if ( tokenUpdates && tokenUpdates . length > 0 ) {
172202 const updatedContent = parser . rewrite ( tokenUpdates ) ;
@@ -182,16 +212,60 @@ export class ApexMigration extends BaseRelatedObjectMigration {
182212 if ( updateMessages . length === 0 ) {
183213 Logger . info ( assessMessages . getMessage ( 'fileNoOmnistudioCalls' , [ file . name ] ) ) ;
184214 }
185- const warningMessage : string [ ] = this . processNonReplacableMethodCalls ( file , parser ) ;
215+ warnings . push ( ... this . processNonReplacableMethodCalls ( file , parser ) ) ;
186216 return {
187217 name : file . name ,
188218 errors : [ ] ,
189- warnings : warningMessage ,
219+ warnings,
190220 infos : updateMessages ,
191221 path : file . location ,
192222 diff : JSON . stringify ( difference ) ,
193223 } ;
194224 }
225+ private processApexFileForSimpleVarDeclarations (
226+ parser : ApexASTParser ,
227+ ipNameUpdateFailed : Set < string > ,
228+ dmNameUpdateFailed : Set < string >
229+ ) : TokenUpdater [ ] {
230+ const simpleVarDeclarations = parser . simpleVarDeclarations ;
231+ const tokenUpdates : TokenUpdater [ ] = [ ] ;
232+ // check and update for DM
233+ const dmVarInMethodCalls = parser . dmVarInMethodCalls ;
234+ for ( const varName of dmVarInMethodCalls ) {
235+ const varToken = simpleVarDeclarations . get ( varName ) ;
236+ if ( ! varToken ) {
237+ dmNameUpdateFailed . add ( varName ) ;
238+ continue ;
239+ }
240+ const newName = `'${ Stringutil . cleanName ( varToken . text . substring ( 1 , varToken . text . length - 1 ) ) } '` ;
241+ if ( newName === varToken . text ) {
242+ continue ;
243+ }
244+ tokenUpdates . push ( new SingleTokenUpdate ( newName , varToken ) ) ;
245+ }
246+ // check and update for IP
247+ const ipVarInMethodCalls = parser . ipVarInMethodCalls ;
248+ for ( const varName of ipVarInMethodCalls ) {
249+ const varToken = simpleVarDeclarations . get ( varName ) ;
250+ if ( ! varToken ) {
251+ ipNameUpdateFailed . add ( varName ) ;
252+ continue ;
253+ }
254+ const oldName = varToken . text . substring ( 1 , varToken . text . length - 1 ) ;
255+ const parts = oldName . split ( '_' ) ;
256+ if ( parts . length !== 2 ) {
257+ ipNameUpdateFailed . add ( varName ) ;
258+ continue ;
259+ }
260+ const newName = `'${ Stringutil . cleanName ( parts [ 0 ] ) } _${ Stringutil . cleanName ( parts [ 1 ] ) } '` ;
261+ if ( newName === varToken . text ) {
262+ continue ;
263+ }
264+ tokenUpdates . push ( new SingleTokenUpdate ( newName , varToken ) ) ;
265+ }
266+
267+ return tokenUpdates ;
268+ }
195269
196270 private processApexFileForRemotecalls ( file : File , parser : ApexASTParser ) : TokenUpdater [ ] {
197271 const implementsInterface = parser . implementsInterfaces ;
@@ -281,7 +355,11 @@ export class ApexMigration extends BaseRelatedObjectMigration {
281355 return tokenUpdates ;
282356 }
283357
284- private processApexFileForMethodCalls ( file : File , parser : ApexASTParser ) : TokenUpdater [ ] {
358+ private processApexFileForMethodCalls (
359+ file : File ,
360+ parser : ApexASTParser ,
361+ ipNameUpdateFailed : Set < string >
362+ ) : TokenUpdater [ ] {
285363 const namespaceChanges = parser . namespaceChanges ;
286364 const tokenUpdates : TokenUpdater [ ] = [ ] ;
287365 if ( namespaceChanges && namespaceChanges . has ( this . namespace ) ) {
@@ -300,6 +378,24 @@ export class ApexMigration extends BaseRelatedObjectMigration {
300378 tokenUpdates . push ( new SingleTokenUpdate ( newName , token ) ) ;
301379 }
302380 }
381+
382+ const ipParameters = methodParameters . get ( ParameterType . IP_NAME ) ;
383+ if ( ipParameters ) {
384+ for ( const token of ipParameters ) {
385+ const oldName = token . text ;
386+ const parts = oldName . split ( '_' ) ;
387+ if ( parts . length !== 2 ) {
388+ ipNameUpdateFailed . add ( oldName ) ;
389+ continue ;
390+ }
391+ const newName = `'${ Stringutil . cleanName ( parts [ 0 ] ) } _${ Stringutil . cleanName ( parts [ 1 ] ) } '` ;
392+ if ( newName === oldName ) {
393+ continue ;
394+ }
395+ Logger . info ( assessMessages . getMessage ( 'inApexIpNameWillBeUpdated' , [ file . name , oldName , newName ] ) ) ;
396+ tokenUpdates . push ( new SingleTokenUpdate ( newName , token ) ) ;
397+ }
398+ }
303399 return tokenUpdates ;
304400 }
305401
0 commit comments