source: java2python/src/main/java/tudelft/utilities/j2p/t/PC.java@ 353

Last change on this file since 353 was 346, checked in by wouter, 2 years ago

version 0.1 of automatic java to python translator. Can translate some simple programs, lot of work remains to be done

File size: 1001 bytes
Line 
1package tudelft.utilities.j2p.t;
2
3import java.util.Collections;
4import java.util.HashSet;
5import java.util.Set;
6
7/**
8 * Default {@link PyCode} object
9 *
10 */
11public class PC implements PyCode {
12 private Set<String> imp;
13 private String cd;
14
15 public PC() {
16 this(Collections.emptySet(), "");
17 }
18
19 /**
20 * a default {@link PyCode} object containing a translation of a java call
21 *
22 * @param imports the imports that are needed to evaluate the code
23 * @param code the actual python code
24 */
25 public PC(Set<String> imports, String code) {
26 this.imp = imports;
27 this.cd = code;
28 }
29
30 @Override
31 public Set<String> imports() {
32 return imp;
33 }
34
35 @Override
36 public String code() {
37 return cd;
38 }
39
40 @Override
41 public String toString() {
42 // HACK
43 return imp.toString() + "\n" + cd;
44 }
45
46 public PC add(PyCode othercode) {
47 Set<String> newimports = new HashSet<>(imp);
48 newimports.addAll(othercode.imports());
49 String newcode = cd + othercode.code();
50
51 return new PC(newimports, newcode);
52 }
53
54}
Note: See TracBrowser for help on using the repository browser.