Переглянути джерело

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

Stan Hebben 5 роки тому
джерело
коміт
e909486bf3

+ 0
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Переглянути файл

@@ -1869,7 +1869,6 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
1869 1869
 
1870 1870
 		final String descriptor = context.getMethodDescriptor(expression.header);
1871 1871
 		final String signature = context.getMethodSignature(expression.header);
1872
-		final String signature2 = context.getMethodDescriptor(expression.header);
1873 1872
 		final String name = context.getLambdaCounter();
1874 1873
 
1875 1874
 		final JavaMethod methodInfo = JavaMethod.getNativeVirtual(javaWriter.method.cls, "accept", descriptor);

+ 20
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java Переглянути файл

@@ -13,6 +13,7 @@ import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 14
 import org.openzen.zenscript.codemodel.FunctionParameter;
15 15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
16
+import org.openzen.zenscript.codemodel.Modifiers;
16 17
 import org.openzen.zenscript.codemodel.Module;
17 18
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
18 19
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
@@ -100,6 +101,25 @@ public abstract class JavaContext {
100 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 123
 	protected abstract JavaSyntheticClassGenerator getTypeGenerator();
104 124
 		
105 125
 	public abstract String getDescriptor(TypeID type);

+ 5
- 3
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaFunctionalInterfaceStorageTag.java Переглянути файл

@@ -14,10 +14,12 @@ import org.openzen.zenscript.codemodel.type.storage.StorageType;
14 14
 import org.openzen.zenscript.codemodel.type.storage.UniqueStorageTag;
15 15
 
16 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 25
 	@Override

+ 5
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaSynthesizedFunctionInstance.java Переглянути файл

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

Завантаження…
Відмінити
Зберегти