]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/ClassConstant.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / ClassConstant.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/ClassConstant.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/ClassConstant.java
new file mode 100644 (file)
index 0000000..d99b6a8
--- /dev/null
@@ -0,0 +1,46 @@
+package org.simantics.scl.compiler.constants;
+
+import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
+import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
+import org.simantics.scl.compiler.types.Type;
+
+public class ClassConstant extends Constant {    
+    Type clazz;
+
+    public ClassConstant(Type type, Type clazz) {
+        super(type);
+        this.clazz = clazz;
+    }
+    
+    @Override
+    public void push(MethodBuilder mb) {
+        mb.loadConstant(mb.getJavaTypeTranslator().toTypeDesc(clazz));
+    }
+    
+    @Override
+    public String toString() {
+        return "(" + clazz.toString() + ")";
+    }
+    
+    @Override
+    public int hashCode() {
+        return clazz.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ClassConstant other = (ClassConstant) obj;
+        return type.equals(other.type) && clazz.equals(other.clazz);
+    }
+
+    @Override
+    public Object realizeValue(TransientClassBuilder classBuilder) {
+        return classBuilder.javaTypeTranslator.toTypeDesc(clazz).toClass();
+    }
+}