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).

!595

import java.util.*;
import java.io.*;
import java.util.regex.*;

public class main {
  static String[] standardClasses = {
    "java.util.*",
    "java.util.zip.*",
    "java.util.List",
    "java.util.regex.*",
    "java.util.concurrent.*",
    "java.util.concurrent.atomic.*",
    "javax.swing.*",
    "javax.swing.event.*",
    "javax.swing.text.*",
    "javax.swing.table.*",
    "java.io.*",
    "java.net.*",
    "java.lang.reflect.*",
    "java.lang.ref.*",
    "java.lang.management.*",
    "java.security.*",
    "java.security.spec.*",
    "java.awt.*",
    "java.awt.event.*",
    "java.awt.image.*",
    "javax.imageio.*",
    "java.math.*"
  };
  
  public static void main(String[] args) throws IOException {
    String s = loadMainJava();
    List<String> imports = findImports(s);
    for (String c : standardClasses)
      if (!(imports.contains(c)))
        s = "import " + c + ";\n" + s;
    saveMainJava(s);
  }
  
  static List<String> findImports(String src) {
    List<String> imports = new ArrayList<String>();
    for (String line : toLines(src)) {
      Matcher matcher = Pattern.compile("^\\s*import\\s+(.*?)\\s*;").matcher(line);
      if (matcher.find())
        imports.add(matcher.group(1));
    }
    return imports;
  }
}

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: 1128 / 23233
Referenced in: [show references]