Merge "Minor refactorings related to SCL constructors"
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / constants / componentaccess / MethodComponentAccess.java
1 package org.simantics.scl.compiler.constants.componentaccess;
2
3 import org.cojen.classfile.TypeDesc;
4 import org.simantics.scl.compiler.constants.generic.MethodRef;
5 import org.simantics.scl.compiler.constants.generic.MethodRef.ObjectMethodRef;
6 import org.simantics.scl.compiler.internal.codegen.utils.Constants;
7 import org.simantics.scl.compiler.internal.codegen.utils.MethodBuilder;
8
9 public class MethodComponentAccess implements ComponentAccess {
10         public final String methodName;
11         public final boolean isInterface;
12
13         public MethodComponentAccess(String fieldName, boolean isInterface) {
14                 this.methodName = fieldName;
15                 this.isInterface = isInterface;
16         }
17
18         @Override
19         public void load(MethodBuilder mb, String baseClass, TypeDesc returnType) {
20                 if(isInterface)
21                         mb.invokeInterface(baseClass, methodName, returnType, Constants.EMPTY_TYPEDESC_ARRAY);
22                 else
23                         mb.invokeVirtual(baseClass, methodName, returnType, Constants.EMPTY_TYPEDESC_ARRAY);
24         }
25
26         @Override
27         public MethodRef toMethodRef(String baseClass, TypeDesc returnType) {
28                 return new ObjectMethodRef(isInterface, baseClass, methodName, returnType, Constants.EMPTY_TYPEDESC_ARRAY);
29         }
30 }