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

25
LINES

< > BotCompany Repo | #1006088 // moveImportsUp2 - returns null if no change, TODO

JavaX fragment (include)

static String moveImportsUp2(String s) {
  List<String> l = toLines(s);
  Pattern p = Pattern.compile("^\\s*import\\s");
  
  // Count import statements on top
  int iStart = 0;
  while (iStart < l(l) && p.matcher(l.get(iStart)).find())
    ++iStart;
 
  // Find import statements in rest
  L<S> l2 = subList(l, iStart);
  new L<S> x;
  ListIterator<String> i = l2.listIterator();
  while (i.hasNext()) {
    S line = i.next();
    if (p.matcher(line).find()) {
      x.add(line);
      i.remove();
    }
  }
  
  // Return null or changed version
  if (isEmpty(x)) ret null;
  return fromLines(concatLists(subList(l, 0, iStart), x, l2));
}

Author comment

Began life as a copy of #1000608

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1006088
Snippet name: moveImportsUp2 - returns null if no change, TODO
Eternal ID of this version: #1006088/1
Text MD5: e478e10b30f6043a137d3feaccd52bf1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-12-17 15:00:29
Source code size: 664 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 508 / 649
Referenced in: [show references]