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

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

#113 Fixed/worked around resolving issue for annotations.

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