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

41
LINES

< > BotCompany Repo | #1006406 - Test straight-to-memory compilation using Eclipse compiler

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Uses 1806K of libraries. Click here for Pure Java version (712L/6K/20K).

1  
!7
2  
3  
lib 1001164 // ecj
4  
5  
import org.eclipse.jdt.internal.compiler.ClassFile;
6  
import org.eclipse.jdt.internal.compiler.CompilationResult;
7  
import org.eclipse.jdt.internal.compiler.Compiler;
8  
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies;
9  
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
10  
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
11  
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
12  
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
13  
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
14  
import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
15  
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
16  
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
17  
import org.eclipse.jdt.internal.compiler.util.Util;
18  
19  
p {
20  
  compile("package test; class main {} class bla {}", "main.java");
21  
}
22  
23  
static void compile(String code, String filename) {
24  
  L<FileSystem.Classpath> cp = new L;
25  
  Util.collectRunningVMBootclasspath(cp);
26  
  INameEnvironment env = new FileSystem(cp.toArray(new FileSystem.Classpath[cp.size()]), null) {};
27  
  ICompilerRequestor requestor = new ICompilerRequestor() {
28  
      @Override
29  
      public void acceptResult(CompilationResult result) {
30  
        ClassFile[] cf = result.getClassFiles();
31  
        print("Got " + n(cf, "class file"));
32  
        for (ClassFile c : cf)
33  
          print("File: " + str(c.fileName()) + ", bytes: " + l(c.getBytes()));
34  
      }
35  
  };
36  
  Compiler compiler = new Compiler(env, DefaultErrorHandlingPolicies.exitAfterAllProblems(),
37  
          new CompilerOptions(), requestor, new DefaultProblemFactory());
38  
39  
  ICompilationUnit[] units = new ICompilationUnit[] { new CompilationUnit(code.toCharArray(), filename, null) };
40  
  compiler.compile(units);
41  
}

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: #1006406
Snippet name: Test straight-to-memory compilation using Eclipse compiler
Eternal ID of this version: #1006406/1
Text MD5: 18e59089be5af3c2bd01a358b0736308
Transpilation MD5: 0ebf607ccdaad6c5691d283057c863da
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-01-01 15:14:53
Source code size: 1832 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 347 / 414
Referenced in: [show references]

Formerly at http://tinybrain.de/1006406 & http://1006406.tinybrain.de