
com.github.leeonky.dal.runtime.MetaData Maven / Gradle / Ivy
package com.github.leeonky.dal.runtime;
import com.github.leeonky.dal.ast.node.DALNode;
import com.github.leeonky.dal.runtime.RuntimeContextBuilder.DALRuntimeContext;
import com.github.leeonky.util.InvocationException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import static com.github.leeonky.dal.runtime.ExpressionException.illegalOp2RuntimeException;
import static java.lang.String.format;
public class MetaData extends RuntimeData {
private Throwable error;
private RuntimeException originalException;
private final Object name;
protected Data data;
public MetaData(DALNode inputNode, Object symbolName, DALRuntimeContext runtimeContext) {
super(null, runtimeContext);
name = symbolName;
setData(() -> inputNode.evaluateData(runtimeContext()));
}
private MetaData(DALRuntimeContext runtimeContext,
Data data, Throwable error, RuntimeException originalException, String name) {
super(null, runtimeContext);
this.name = name;
this.error = error;
this.originalException = originalException;
this.data = data;
}
private void setData(Supplier supplier) {
try {
data = supplier.get();
} catch (RuntimeException e) {
if (!(e.getCause() instanceof InvocationException))
throw e;
originalException = e;
error = e.getCause().getCause();
data = runtimeContext.wrap(null);
}
}
public Throwable catchError() {
Throwable throwable = error;
error = null;
return throwable;
}
private final List> callTypes = new ArrayList<>();
public Object callSuper() {
return runtimeContext().fetchSuperMetaFunction(this).orElseThrow(() -> illegalOp2RuntimeException(format(
"Local meta property `%s` has no super in type %s", name, callTypes.get(callTypes.size() - 1).getName())))
.apply(this);
}
public Object callSuper(Supplier
© 2015 - 2025 Weber Informatics LLC | Privacy Policy