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:
1.3 KB
|
Line | |
---|
1 | package tudelft.utilities.j2p.t;
|
---|
2 |
|
---|
3 | import com.github.javaparser.ast.expr.FieldAccessExpr;
|
---|
4 | import com.github.javaparser.ast.expr.MethodCallExpr;
|
---|
5 |
|
---|
6 | import tudelft.utilities.j2p.formatting.ExpressionLine;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * a class that implements J2P translator given an arbitrary java class. The
|
---|
10 | * translator assumes all functions in the given class can be accessed and will
|
---|
11 | * be translated properly to the same package name in python. System classes are
|
---|
12 | * translated using the t.java translateors.
|
---|
13 | *
|
---|
14 | */
|
---|
15 | public class Stub extends tudelft.utilities.j2p.t.java.lang.Object {
|
---|
16 | private Class<?> clazz;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | *
|
---|
20 | * @param clazz the class to be stubbed.
|
---|
21 | */
|
---|
22 | public Stub(Class<?> clazz) {
|
---|
23 | this.clazz = clazz;
|
---|
24 | }
|
---|
25 |
|
---|
26 | @Override
|
---|
27 | public ExpressionLine call(MethodCallExpr call) {
|
---|
28 |
|
---|
29 | // forward the translation of standard calls to Object
|
---|
30 | switch (call.getName().asString()) {
|
---|
31 | case "toString":
|
---|
32 | case "hashCode":
|
---|
33 | case "equals":
|
---|
34 | return super.call(call);
|
---|
35 | }
|
---|
36 |
|
---|
37 | return Translator.callClassFunction(call);
|
---|
38 |
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public String getName() {
|
---|
43 | return clazz.getSimpleName();
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public ExpressionLine field(FieldAccessExpr node) {
|
---|
48 | return new ExpressionLine("." + node.getName());
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Override
|
---|
52 | public java.lang.String getImport() {
|
---|
53 | return "from " + clazz.getCanonicalName() + " import "
|
---|
54 | + clazz.getSimpleName();
|
---|
55 | }
|
---|
56 |
|
---|
57 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.