Browse Source

Added utility method to retrieve the functional interface method from a type.

Stan Hebben 5 years ago
parent
commit
e909486bf3

+ 0
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

1869
 
1869
 
1870
 		final String descriptor = context.getMethodDescriptor(expression.header);
1870
 		final String descriptor = context.getMethodDescriptor(expression.header);
1871
 		final String signature = context.getMethodSignature(expression.header);
1871
 		final String signature = context.getMethodSignature(expression.header);
1872
-		final String signature2 = context.getMethodDescriptor(expression.header);
1873
 		final String name = context.getLambdaCounter();
1872
 		final String name = context.getLambdaCounter();
1874
 
1873
 
1875
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", descriptor);
1874
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", descriptor);

+ 20
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java View File

13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
 import org.openzen.zenscript.codemodel.FunctionParameter;
14
 import org.openzen.zenscript.codemodel.FunctionParameter;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
16
+import org.openzen.zenscript.codemodel.Modifiers;
16
 import org.openzen.zenscript.codemodel.Module;
17
 import org.openzen.zenscript.codemodel.Module;
17
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
100
 		return getPackageName(pkg.parent) + "/" + pkg.name;
101
 		return getPackageName(pkg.parent) + "/" + pkg.name;
101
 	}
102
 	}
102
 	
103
 	
104
+	public JavaMethod getFunctionalInterface(StoredType type) {
105
+		if (type.getSpecifiedStorage() instanceof JavaFunctionalInterfaceStorageTag) {
106
+			JavaFunctionalInterfaceStorageTag tag = (JavaFunctionalInterfaceStorageTag)type.getSpecifiedStorage();
107
+			return tag.method;
108
+		} else {
109
+			FunctionTypeID functionType = (FunctionTypeID)type.type;
110
+			JavaSynthesizedFunctionInstance function = getFunction(functionType);
111
+			
112
+			return new JavaMethod(
113
+					function.getCls(),
114
+					JavaMethod.Kind.INTERFACE,
115
+					function.getMethod(),
116
+					false,
117
+					getMethodDescriptor(function.getHeader()),
118
+					Modifiers.PUBLIC | Modifiers.ABSTRACT,
119
+					function.getHeader().getReturnType().isGeneric());
120
+		}
121
+	}
122
+	
103
 	protected abstract JavaSyntheticClassGenerator getTypeGenerator();
123
 	protected abstract JavaSyntheticClassGenerator getTypeGenerator();
104
 		
124
 		
105
 	public abstract String getDescriptor(TypeID type);
125
 	public abstract String getDescriptor(TypeID type);

+ 5
- 3
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaFunctionalInterfaceStorageTag.java View File

14
 import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
14
 import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
15
 
15
 
16
 public class JavaFunctionalInterfaceStorageTag implements StorageTag {
16
 public class JavaFunctionalInterfaceStorageTag implements StorageTag {
17
-	public final Method funtionalInterfaceMethod;
17
+	public final Method functionalInterfaceMethod;
18
+	public final JavaMethod method;
18
 	
19
 	
19
-	public JavaFunctionalInterfaceStorageTag(Method functionalInterfaceMethod) {
20
-		this.funtionalInterfaceMethod = functionalInterfaceMethod;
20
+	public JavaFunctionalInterfaceStorageTag(Method functionalInterfaceMethod, JavaMethod method) {
21
+		this.functionalInterfaceMethod = functionalInterfaceMethod;
22
+		this.method = method;
21
 	}
23
 	}
22
 
24
 
23
 	@Override
25
 	@Override

+ 5
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedFunctionInstance.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.javashared;
6
 package org.openzen.zenscript.javashared;
7
 
7
 
8
+import org.openzen.zenscript.codemodel.FunctionHeader;
8
 import org.openzen.zenscript.codemodel.type.TypeID;
9
 import org.openzen.zenscript.codemodel.type.TypeID;
9
 
10
 
10
 /**
11
 /**
27
 	public String getMethod() {
28
 	public String getMethod() {
28
 		return function.method;
29
 		return function.method;
29
 	}
30
 	}
31
+	
32
+	public FunctionHeader getHeader() {
33
+		return function.header;
34
+	}
30
 }
35
 }

Loading…
Cancel
Save