summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java
diff options
context:
space:
mode:
authorKenny Ballou <kballou@devnulllabs.io>2018-11-19 22:59:50 -0700
committerKenny Ballou <kballou@devnulllabs.io>2018-11-19 22:59:50 -0700
commitea3e1b949dcbdc09518f17eee0bcf21d41d76896 (patch)
tree7ec7a7fb4df67815a9b7bb0e4d95d67c4050e2a2 /src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java
downloadopenjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.gz
openjava-ea3e1b949dcbdc09518f17eee0bcf21d41d76896.tar.xz
OJ (aka OpenJava) modernization/mirroring
Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java')
-rw-r--r--src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java b/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java
new file mode 100644
index 0000000..95dbe70
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/ptree/SelfAccess.java
@@ -0,0 +1,105 @@
+/*
+ * SelfAccess.java 1.0
+ *
+ * Jun 20, 1997 by micn
+ * Sep 29, 1997 by bv
+ * Oct 10, 1997 by mich
+ *
+ * @see io.devnulllabs.openjava.ptree.ParseTree
+ * @version 1.0 last updated: Oct 10, 1997
+ * @author Michiaki Tatsubori
+ */
+package io.devnulllabs.openjava.ptree;
+
+import io.devnulllabs.openjava.mop.Environment;
+import io.devnulllabs.openjava.mop.OJClass;
+import io.devnulllabs.openjava.ptree.util.ParseTreeVisitor;
+
+/**
+ * The class <code>SelfAccess</code> represents an access to
+ * <pre>this</pre> object.
+ * this or super
+ *
+ */
+public class SelfAccess extends Leaf implements Expression {
+ public static final int THIS = 0;
+ public static final int SUPER = 1;
+
+ private static SelfAccess _constantSuper = null;
+ private static SelfAccess _constantThis = null;
+
+ protected String qualifier = null;
+
+ int id = -1;
+
+ SelfAccess() {
+ this(null);
+ }
+
+ SelfAccess(String q) {
+ super(((q == null) ? "" : q + ".") + "this");
+ this.qualifier = q;
+ this.id = THIS;
+ }
+
+ SelfAccess(int id) {
+ super(id == SUPER ? "super" : "this");
+ this.id = id;
+ }
+
+ public String getQualifier() {
+ return this.qualifier;
+ }
+
+ public int getAccessType() {
+ return id;
+ }
+
+ public boolean isSuperAccess() {
+ return (id == SUPER);
+ }
+
+ public static SelfAccess makeSuper() {
+ return constantSuper();
+ }
+
+ public static SelfAccess makeThis() {
+ return constantThis();
+ }
+
+ public static SelfAccess makeThis(String qualifier) {
+ if (qualifier == null || qualifier.equals("")) {
+ return constantThis();
+ }
+ return new SelfAccess(qualifier);
+ }
+
+ public static SelfAccess constantSuper() {
+ if (_constantSuper == null) {
+ _constantSuper = new SelfAccess(SUPER);
+ }
+ return _constantSuper;
+ }
+
+ public static SelfAccess constantThis() {
+ if (_constantThis == null) {
+ _constantThis = new SelfAccess();
+ }
+ return _constantThis;
+ }
+
+ public void accept(ParseTreeVisitor v) throws ParseTreeException {
+ v.visit(this);
+ }
+
+ public OJClass getType(Environment env) throws Exception {
+ OJClass current = env.lookupClass(env.currentClassName());
+ if (isSuperAccess())
+ return current.getSuperclass();
+ String qualifier = getQualifier();
+ if (qualifier == null)
+ return current;
+ return env.lookupClass(env.toQualifiedName(qualifier));
+ }
+
+}