]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/componentaccess/MethodComponentAccess.java
Minor refactorings related to SCL constructors
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / componentaccess / MethodComponentAccess.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/componentaccess/MethodComponentAccess.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/constants/componentaccess/MethodComponentAccess.java
new file mode 100644 (file)
index 0000000..7283266
--- /dev/null
@@ -0,0 +1,30 @@
+package org.simantics.scl.compiler.constants.componentaccess;
+
+import org.cojen.classfile.TypeDesc;
+import org.simantics.scl.compiler.constants.generic.MethodRef;
+import org.simantics.scl.compiler.constants.generic.MethodRef.ObjectMethodRef;
+import org.simantics.scl.compiler.internal.codegen.utils.Constants;
+import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
+
+public class MethodComponentAccess implements ComponentAccess {
+       public final String methodName;
+       public final boolean isInterface;
+
+       public MethodComponentAccess(String fieldName, boolean isInterface) {
+               this.methodName = fieldName;
+               this.isInterface = isInterface;
+       }
+
+       @Override
+       public void load(MethodBuilder mb, String baseClass, TypeDesc returnType) {
+               if(isInterface)
+                       mb.invokeInterface(baseClass, methodName, returnType, Constants.EMPTY_TYPEDESC_ARRAY);
+               else
+                       mb.invokeVirtual(baseClass, methodName, returnType, Constants.EMPTY_TYPEDESC_ARRAY);
+       }
+
+       @Override
+       public MethodRef toMethodRef(String baseClass, TypeDesc returnType) {
+               return new ObjectMethodRef(isInterface, baseClass, methodName, returnType, Constants.EMPTY_TYPEDESC_ARRAY);
+       }
+}