source: java2python/src/main/java/tudelft/utilities/j2p/t/Stub.java@ 362

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

#110 transforming the Group/Block structure, getName now always returns ExpressionLine. Removed few TextBlocks in the translator.

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