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

51
LINES

< > BotCompany Repo | #596 // Stefan's Auto-Importer, shortened (CURRENT)

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (129L/2K/5K).

1  
!595
2  
3  
import java.util.*;
4  
import java.io.*;
5  
import java.util.regex.*;
6  
7  
public class main {
8  
  static String[] standardClasses = {
9  
    "java.util.*",
10  
    "java.util.zip.*",
11  
    "java.util.List",
12  
    "java.util.regex.*",
13  
    "java.util.concurrent.*",
14  
    "java.util.concurrent.atomic.*",
15  
    "javax.swing.*",
16  
    "javax.swing.event.*",
17  
    "javax.swing.text.*",
18  
    "javax.swing.table.*",
19  
    "java.io.*",
20  
    "java.net.*",
21  
    "java.lang.reflect.*",
22  
    "java.lang.ref.*",
23  
    "java.lang.management.*",
24  
    "java.security.*",
25  
    "java.security.spec.*",
26  
    "java.awt.*",
27  
    "java.awt.event.*",
28  
    "java.awt.image.*",
29  
    "javax.imageio.*",
30  
    "java.math.*"
31  
  };
32  
  
33  
  public static void main(String[] args) throws IOException {
34  
    String s = loadMainJava();
35  
    List<String> imports = findImports(s);
36  
    for (String c : standardClasses)
37  
      if (!(imports.contains(c)))
38  
        s = "import " + c + ";\n" + s;
39  
    saveMainJava(s);
40  
  }
41  
  
42  
  static List<String> findImports(String src) {
43  
    List<String> imports = new ArrayList<String>();
44  
    for (String line : toLines(src)) {
45  
      Matcher matcher = Pattern.compile("^\\s*import\\s+(.*?)\\s*;").matcher(line);
46  
      if (matcher.find())
47  
        imports.add(matcher.group(1));
48  
    }
49  
    return imports;
50  
  }
51  
}

Author comment

Began life as a copy of #592

download  show line numbers  debug dex  old transpilations   

Travelled to 37 computer(s): adtiomwmedle, ajlfxifxfcul, aoiabmzegqzx, bhatertpkbcr, cahelewubzku, cbybwowwnfue, cfunsshuasjs, cmhtpxxajurv, ddnzoavkxhuk, dhtvkmknsjym, exkalrxbqyxc, fumpprspadck, gkwdfizivqfm, gwrvuhgaqvyk, hxnwyiuffukg, ishqpsrjomds, jlatgrcjtklg, jtubtzbbkimh, kmhbujppghqa, liwcxgsjrgqn, lpdgvwnxivlt, mqqgnosmbjvj, mrjhfnjfopze, nrtiiiyxqhmw, omzkqqnokwlv, onfqjnomoxuw, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, qbtsjoyahagl, teubizvjbppd, tslmcundralx, tvejysmllsmz, ufhdzwgrioxs, ugbnzuvxksoj, vouqrxazstgt, xinetxnxrdbb

Comments [hide]

ID Author/Program Comment Date
218 #1000604 (pitcher) 2015-08-18 00:51:30
202 #1000610 (pitcher) 2015-08-18 00:50:54

add comment

Snippet ID: #596
Snippet name: Stefan's Auto-Importer, shortened (CURRENT)
Eternal ID of this version: #596/1
Text MD5: fdfabede9e4052d7f4c777ff700900bf
Transpilation MD5: 2d8ea6d5fe09683d085e2a6653a9399e
Author: stefan
Category: javax
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-10 00:29:16
Source code size: 1310 bytes / 51 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1129 / 23234
Referenced in: [show references]