]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/ClassConstant.java
(refs #7250) Merging master, minor CHR bugfixes
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / ClassConstant.java
1 package org.simantics.scl.compiler.constants;
2
3 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
4 import org.simantics.scl.compiler.internal.codegen.utils.TransientClassBuilder;
5 import org.simantics.scl.compiler.types.Type;
6
7 public class ClassConstant extends Constant {    
8     Type clazz;
9
10     public ClassConstant(Type type, Type clazz) {
11         super(type);
12         this.clazz = clazz;
13     }
14     
15     @Override
16     public void push(MethodBuilder mb) {
17         mb.loadConstant(mb.getJavaTypeTranslator().toTypeDesc(clazz));
18     }
19     
20     @Override
21     public String toString() {
22         return "(" + clazz.toString() + ")";
23     }
24     
25     @Override
26     public int hashCode() {
27         return clazz.hashCode();
28     }
29
30     @Override
31     public boolean equals(Object obj) {
32         if (this == obj)
33             return true;
34         if (obj == null)
35             return false;
36         if (getClass() != obj.getClass())
37             return false;
38         ClassConstant other = (ClassConstant) obj;
39         return type.equals(other.type) && clazz.equals(other.clazz);
40     }
41
42     @Override
43     public Object realizeValue(TransientClassBuilder classBuilder) {
44         return classBuilder.javaTypeTranslator.toTypeDesc(clazz).toClass();
45     }
46 }