Browse Source

new: IMethod#symbolic

Mariusz Sieroń 6 năm trước cách đây
mục cha
commit
4d8d7544bf

+ 5 - 1
assira/src/main/java/net/ranides/assira/reflection/IMethod.java

@@ -6,8 +6,8 @@
  */
 package net.ranides.assira.reflection;
 
-import net.ranides.assira.annotations.Meta;
 import net.ranides.assira.reflection.impl.FMethod;
+import net.ranides.assira.reflection.impl.SMethod;
 
 import java.lang.reflect.Method;
 
@@ -25,6 +25,10 @@ public interface IMethod extends IExecutable {
         return FMethod.newMethod(method);
     }
 
+    static IMethod symbolic(String name, IArguments args, IClass<?> rets) {
+        return new SMethod(name, args, rets);
+    }
+
     @Override
     IMethods collect();
 

+ 104 - 0
assira/src/main/java/net/ranides/assira/reflection/impl/SMethod.java

@@ -0,0 +1,104 @@
+package net.ranides.assira.reflection.impl;
+
+import net.ranides.assira.reflection.*;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+public class SMethod extends AMethod implements IMethod {
+
+    private static final String NSE = "Symbolic IMethod is not reflective nor callable.";
+
+    private static final IAttributes ATTRS = IAttributes.of(IAttribute.SYMBOLIC).immutable();
+
+    private final String name;
+
+    private final IArguments args;
+
+    private final IClass<?> rets;
+
+    public SMethod(String name, IArguments args, IClass<?> rets) {
+        super(IContext.DEFAULT);
+        this.name = name;
+        this.args = args;
+        this.rets = rets;
+    }
+
+    @Override
+    public IMethod accessible() {
+        return this;
+    }
+
+    @Override
+    public Method reflective() {
+        throw new UnsupportedOperationException(NSE);
+    }
+
+    @Override
+    public List<IClass<?>> params() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public IClass<?> returns() {
+        return rets;
+    }
+
+    @Override
+    public IArguments arguments() {
+        return args;
+    }
+
+    @Override
+    public List<IClass<?>> exceptions() {
+        return Collections.emptyList();
+    }
+
+    @Override
+    public IClass<?> parent() {
+        return IClass.NULL;
+    }
+
+    @Override
+    public Object invoke() {
+        throw new UnsupportedOperationException(NSE);
+    }
+
+    @Override
+    public Object invoke(Object that) {
+        throw new UnsupportedOperationException(NSE);
+    }
+
+    @Override
+    public Object invoke(Object that, Object... arguments) {
+        throw new UnsupportedOperationException(NSE);
+    }
+
+    @Override
+    public Object call(Object... arguments) {
+        throw new UnsupportedOperationException(NSE);
+    }
+
+    @Override
+    public MethodHandle handle() {
+        throw new UnsupportedOperationException(NSE);
+    }
+
+    @Override
+    public String name() {
+        return name;
+    }
+
+    @Override
+    public IAttributes attributes() {
+        return ATTRS;
+    }
+
+    @Override
+    public IAnnotations annotations() {
+        return AAnnotations.EMPTY;
+    }
+}