![JAR search and dependency download from the Maven repository](/logo.png)
org.snapscript.tree.define.AnyDefinition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap-all Show documentation
Show all versions of snap-all Show documentation
Dynamic scripting for the JVM
package org.snapscript.tree.define;
import static org.snapscript.core.ModifierType.CONSTANT;
import static org.snapscript.core.ModifierType.PUBLIC;
import static org.snapscript.core.Reserved.ANY_TYPE;
import static org.snapscript.core.Reserved.DEFAULT_PACKAGE;
import static org.snapscript.core.Reserved.METHOD_EQUALS;
import static org.snapscript.core.Reserved.METHOD_HASH_CODE;
import static org.snapscript.core.Reserved.METHOD_NOTIFY;
import static org.snapscript.core.Reserved.METHOD_NOTIFY_ALL;
import static org.snapscript.core.Reserved.METHOD_TO_STRING;
import static org.snapscript.core.Reserved.METHOD_WAIT;
import static org.snapscript.core.Reserved.TYPE_CONSTRUCTOR;
import static org.snapscript.core.Reserved.TYPE_THIS;
import java.util.List;
import org.snapscript.core.Context;
import org.snapscript.core.ModifierType;
import org.snapscript.core.Module;
import org.snapscript.core.Result;
import org.snapscript.core.ResultType;
import org.snapscript.core.Scope;
import org.snapscript.core.State;
import org.snapscript.core.Type;
import org.snapscript.core.TypeLoader;
import org.snapscript.core.Value;
import org.snapscript.core.ValueType;
import org.snapscript.core.define.Instance;
import org.snapscript.core.function.Function;
import org.snapscript.core.function.Invocation;
public class AnyDefinition{
private final AnyFunctionBuilder builder;
public AnyDefinition(){
this.builder = new AnyFunctionBuilder();
}
public Type create(Scope scope) throws Exception {
Module module = scope.getModule();
Context context = module.getContext();
TypeLoader loader = context.getLoader();
Type result = loader.defineType(DEFAULT_PACKAGE, ANY_TYPE);
List functions = result.getFunctions();
if(functions.isEmpty()) { // thread safe?
Function constructor = builder.create(result, TYPE_CONSTRUCTOR, NewInvocation.class, Type.class);
Function hashCode = builder.create(result, METHOD_HASH_CODE, HashCodeInvocation.class);
Function toString = builder.create(result, METHOD_TO_STRING, ToStringInvocation.class);
Function equals = builder.create(result, METHOD_EQUALS, EqualsInvocation.class, Object.class);
Function wait = builder.create(result, METHOD_WAIT, WaitInvocation.class);
Function waitFor = builder.create(result, METHOD_WAIT, WaitForInvocation.class, Long.class);
Function notify = builder.create(result, METHOD_NOTIFY, NotifyInvocation.class);
Function notifyAll = builder.create(result, METHOD_NOTIFY_ALL, NotifyAllInvocation.class);
functions.add(constructor);
functions.add(wait);
functions.add(waitFor);
functions.add(notify);
functions.add(notifyAll);
functions.add(hashCode);
functions.add(equals);
functions.add(toString);
}
return result;
}
private static class NewInvocation implements Invocation
© 2015 - 2025 Weber Informatics LLC | Privacy Policy