Changes between Version 26 and Version 27 of j2p


Ignore:
Timestamp:
06/20/23 11:44:50 (17 months ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • j2p

    v26 v27  
    2727
    2828== Usage
     29For usage you have the choice between translating a single file or an entire package. We generally recommend translating the entire package.
     30
     31=== Single File
     32If you want to translate a single java file or even just a string containing your program, that does not need any specialized libraries, you can do the approach as many tests in core do. Check the examples. The heart of the code will look like this, where most boilerplate is about setting up the javaparser:
     33
     34{{{
     35                ParserConfiguration conf = new ParserConfiguration();
     36                CombinedTypeSolver typeSolver = new CombinedTypeSolver();
     37                typeSolver.add(new ReflectionTypeSolver(false));
     38                JavaSymbolSolver symbolSolver = new JavaSymbolSolver(typeSolver);
     39                conf.setSymbolResolver(symbolSolver);
     40                JavaParser parser = new JavaParser(conf);
     41                ParseResult<CompilationUnit> res = parser.parse(new File(javaFile));
     42
     43                Block translation = Translator.translate(res.getResult().get());
     44
     45}}}
     46
     47After you get the translation, you can print it or put it in a {{{.py}}} file.
     48
     49=== Entire Package
     50If you want to translate an entire package, first create a separate source directory containing all the java code that you want to translate. Also make sure that your code is compiled (eg, using the build-helper-maven-plugin , check the pom files). Then you just do
     51{{{
     52PyProgram program = PyProgram.fromDirectory(Paths.get("src/test/myprogram"));
     53}}}
     54
     55This gives you a fully translated program that you can print or get a zip file from. To get a zip file, call
     56{{{program.getZip() }}}
     57
     58The zip file is ready for a pip install (eg in your own virtual environment) or running from java through our PythonVenv.
     59
    2960
    3061== Overriding the translation