Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

30
LINES

< > BotCompany Repo | #1009477 // migrateClassesInStructureText

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4828L/27K).

1  
static S migrateClassesInStructureText(S s, O... migrations) {
2  
  L<S> tok = javaTokForStructure(s);
3  
  int n = l(tok);
4  
  for (int i = 0; i < l(migrations); i += 2) {
5  
    S from = cast migrations[i];
6  
    S fromPlusDollar = from + "$";
7  
    O to = migrations[i+1];
8  
    S replacement = to instanceof S ? (S) to : dropPrefix("main$", className((Class) to);
9  
    
10  
    int changes = 0;
11  
    for (int j = 1; j < n; j += 2) {
12  
      S t = tok.get(j);
13  
      if (eq(t, from)) {
14  
        tok.set(j, replacement);
15  
        ++changes;
16  
      } else if (startsWith(t, fromPlusDollar)) {
17  
        tok.set(j, replacement + t.substring(l(from)));
18  
        ++changes;
19  
      }
20  
    }
21  
    
22  
    if (changes > 0)
23  
      print("migrateClassesInStructureText: Replaced " + n2(changes, "occurrence") + " of " + from + " with " + to);
24  
  }
25  
  ret join(tok);
26  
}
27  
28  
sS migrateClassesInStructureText(S s, MapSO migrations) {
29  
  ret migrateClassesInStructureText(s, mapToParams(migrations));
30  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1009477
Snippet name: migrateClassesInStructureText
Eternal ID of this version: #1009477/13
Text MD5: 3fa0752bca9262d69c81bf74e5265d9d
Transpilation MD5: 25292fb4c7df976dd71442395b490558
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-01-19 17:01:04
Source code size: 974 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 538 / 607
Version history: 12 change(s)
Referenced in: [show references]