Skip to content

Commit

Permalink
further align DynamicMethod.name now being final and not-null
Browse files Browse the repository at this point in the history
... follow-up on 577d13a
handling a few regressions along the way - mostly from Java integration
kares committed Feb 5, 2018

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent 34e6c11 commit 6c1fd1f
Showing 19 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -1338,7 +1338,7 @@ private void initRoot() {

// In 1.9 and later, Kernel.gsub is defined only when '-p' or '-n' is given on the command line
if (config.getKernelGsubDefined()) {
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE) {
kernel.addMethod("gsub", new JavaMethod(kernel, Visibility.PRIVATE, "gsub") {

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -105,8 +105,8 @@ public static class MethodMissingMethod extends JavaMethodNBlock {
private final Visibility visibility;
private final CallType callType;

public MethodMissingMethod(RubyModule implementationClass, Visibility visibility, CallType callType) {
super(implementationClass, Visibility.PRIVATE);
MethodMissingMethod(RubyModule implementationClass, Visibility visibility, CallType callType) {
super(implementationClass, Visibility.PRIVATE, "method_missing");

this.callType = callType;
this.visibility = visibility;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1870,8 +1870,8 @@ public IRubyObject newMethod(IRubyObject receiver, final String methodName, bool

public static class RespondToMissingMethod extends JavaMethod.JavaMethodNBlock {
final CallSite site;
public RespondToMissingMethod(RubyModule implClass, Visibility vis, String methodName) {
super(implClass, vis);
public RespondToMissingMethod(RubyModule implClass, Visibility visibility, String methodName) {
super(implClass, visibility, methodName);

setParameterList(REST);
site = new FunctionalCachingCallSite(methodName);
3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/ext/pathname/RubyPathname.java
Original file line number Diff line number Diff line change
@@ -136,8 +136,7 @@ public IRubyObject[] addArg(IRubyObject[] args, RubyString path) {
private static void defineDelegateMethodsGeneric(RubyClass cPathname, final RubyModule klass,
final ReturnValueMapper mapper, final AddArg addArg, String... methods) {
for (String method : methods) {
cPathname.addMethod(method, new JavaMethod.JavaMethodNBlock(cPathname,
Visibility.PUBLIC) {
cPathname.addMethod(method, new JavaMethod.JavaMethodNBlock(cPathname, Visibility.PUBLIC, method) {
@Override
public IRubyObject call(ThreadContext context, IRubyObject _self, RubyModule clazz,
String name, IRubyObject[] args, Block block) {
Original file line number Diff line number Diff line change
@@ -276,13 +276,14 @@ protected static void checkArgumentCount(JavaMethod method, ThreadContext contex

// promise to implement N with block
public static abstract class JavaMethodNBlock extends JavaMethod {
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility) {
super(implementationClass, visibility);
}
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility, String name) {
super(implementationClass, visibility, name);
}
@Deprecated
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility) {
super(implementationClass, visibility);
}
@Deprecated
public JavaMethodNBlock(RubyModule implementationClass, Visibility visibility, CallConfiguration callConfig) {
super(implementationClass, visibility);
}
Original file line number Diff line number Diff line change
@@ -17,8 +17,10 @@

public final class ConstructorInvoker extends RubyToJavaInvoker {

public ConstructorInvoker(RubyModule host, List<Constructor> ctors) {
super(host, setAccessible( ctors.toArray(new Constructor[ctors.size()]) ) );
private static final Constructor[] EMPTY_ARRAY = new Constructor[0];

public ConstructorInvoker(RubyModule host, List<Constructor> ctors, String name) {
super(host, setAccessible(ctors.toArray(EMPTY_ARRAY)), name);
}

@Override
Original file line number Diff line number Diff line change
@@ -13,12 +13,12 @@
import org.jruby.util.ArraySupport;

public final class InstanceMethodInvoker extends MethodInvoker {
public InstanceMethodInvoker(RubyModule host, List<Method> methods) {
super(host, methods);
public InstanceMethodInvoker(RubyModule host, List<Method> methods, String name) {
super(host, methods, name);
}

public InstanceMethodInvoker(RubyModule host, Method method) {
super(host, method);
public InstanceMethodInvoker(RubyModule host, Method method, String name) {
super(host, method, name);
}

@Override
10 changes: 6 additions & 4 deletions core/src/main/java/org/jruby/java/invokers/MethodInvoker.java
Original file line number Diff line number Diff line change
@@ -10,12 +10,14 @@

public abstract class MethodInvoker extends RubyToJavaInvoker {

MethodInvoker(RubyModule host, List<Method> methods) {
super(host, setAccessible( methods.toArray(new Method[methods.size()]) ) );
private static final Method[] EMPTY_ARRAY = new Method[0];

MethodInvoker(RubyModule host, List<Method> methods, String name) {
super(host, setAccessible(methods.toArray(EMPTY_ARRAY)), name);
}

MethodInvoker(RubyModule host, Method method) {
super(host, setAccessible(method));
MethodInvoker(RubyModule host, Method method, String name) {
super(host, setAccessible(method), name);
}

@Override
Original file line number Diff line number Diff line change
@@ -71,8 +71,8 @@ public abstract class RubyToJavaInvoker<T extends JavaCallable> extends JavaMeth
private final Ruby runtime;

@SuppressWarnings("unchecked") // NULL_CACHE
RubyToJavaInvoker(RubyModule host, Member member) {
super(host, Visibility.PUBLIC);
RubyToJavaInvoker(RubyModule host, Member member, String name) {
super(host, Visibility.PUBLIC, name);
this.runtime = host.getRuntime();

final T callable;
@@ -97,8 +97,8 @@ public abstract class RubyToJavaInvoker<T extends JavaCallable> extends JavaMeth
}

@SuppressWarnings("unchecked") // NULL_CACHE
RubyToJavaInvoker(RubyModule host, Member[] members) {
super(host, Visibility.PUBLIC);
RubyToJavaInvoker(RubyModule host, Member[] members, String name) {
super(host, Visibility.PUBLIC, name);
this.runtime = host.getRuntime();

// initialize all the callables for this method
Original file line number Diff line number Diff line change
@@ -15,13 +15,13 @@ public final class SingletonMethodInvoker extends MethodInvoker {

private final Object singleton;

public SingletonMethodInvoker(Object singleton, RubyClass host, List<Method> methods) {
super(host, methods);
public SingletonMethodInvoker(Object singleton, RubyClass host, List<Method> methods, String name) {
super(host, methods, name);
this.singleton = singleton;
}

public SingletonMethodInvoker(Object singleton, RubyClass host, Method method) {
super(host, method);
public SingletonMethodInvoker(Object singleton, RubyClass host, Method method, String name) {
super(host, method, name);
this.singleton = singleton;
}

Original file line number Diff line number Diff line change
@@ -14,16 +14,12 @@

public final class StaticMethodInvoker extends MethodInvoker {

public StaticMethodInvoker(RubyClass host, List<Method> methods) {
super(host, methods);
public StaticMethodInvoker(RubyClass host, List<Method> methods, String name) {
super(host, methods, name);
}

public StaticMethodInvoker(RubyClass host, Method method) {
super(host, method);
}

public StaticMethodInvoker(RubyModule host, Method method) {
super(host, method);
public StaticMethodInvoker(RubyModule host, Method method, String name) {
super(host, method, name);
}

@Override
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ private static final class InitializeMethod extends org.jruby.internal.runtime.m

private final CallSite jcreateSite = MethodIndex.getFunctionalCallSite("__jcreate!");

InitializeMethod(final RubyClass clazz) { super(clazz, Visibility.PRIVATE); }
InitializeMethod(final RubyClass clazz) { super(clazz, Visibility.PRIVATE, "initialize"); }

@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
@@ -92,7 +92,7 @@ private static final class NewMethod extends org.jruby.internal.runtime.methods.
final DynamicMethod newMethod;

NewMethod(final RubyClass clazz) {
super(clazz, Visibility.PUBLIC);
super(clazz, Visibility.PUBLIC, "new");
newMethod = clazz.searchMethod("new");
}

Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ public static IRubyObject implement(ThreadContext context, IRubyObject self, IRu
private static class DummyMethodImpl extends org.jruby.internal.runtime.methods.JavaMethod {

DummyMethodImpl(RubyModule targetModule) {
super(targetModule, Visibility.PUBLIC);
super(targetModule, Visibility.PUBLIC, ""); // NOTE: maybe dummy method should not be shared
}

@Override
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/java/proxies/JavaProxy.java
Original file line number Diff line number Diff line change
@@ -445,9 +445,9 @@ private Method getMethod(ThreadContext context, String name, Class... argTypes)

private MethodInvoker getMethodInvoker(Method method) {
if (Modifier.isStatic(method.getModifiers())) {
return new StaticMethodInvoker(metaClass.getMetaClass(), method);
return new StaticMethodInvoker(metaClass.getMetaClass(), method, method.getName());
} else {
return new InstanceMethodInvoker(metaClass, method);
return new InstanceMethodInvoker(metaClass, method, method.getName());
}
}

@@ -623,12 +623,12 @@ public static IRubyObject java_alias(ThreadContext context, IRubyObject clazz, I
final MethodInvoker invoker;

if ( Modifier.isStatic( method.getModifiers() ) ) {
invoker = new StaticMethodInvoker(proxyClass.getMetaClass(), method);
invoker = new StaticMethodInvoker(proxyClass.getMetaClass(), method, newNameStr);
// add alias to meta
proxyClass.getSingletonClass().addMethod(newNameStr, invoker);
}
else {
invoker = new InstanceMethodInvoker(proxyClass, method);
invoker = new InstanceMethodInvoker(proxyClass, method, newNameStr);
proxyClass.addMethod(newNameStr, invoker);
}

@@ -646,11 +646,11 @@ private static AbstractRubyMethod getRubyMethod(ThreadContext context, IRubyObje
final String prettyName = name + CodegenUtils.prettyParams(argTypesClasses);

if ( Modifier.isStatic( method.getModifiers() ) ) {
MethodInvoker invoker = new StaticMethodInvoker(proxyClass, method);
MethodInvoker invoker = new StaticMethodInvoker(proxyClass, method, name);
return RubyMethod.newMethod(proxyClass, prettyName, proxyClass, name, invoker, clazz);
}

MethodInvoker invoker = new InstanceMethodInvoker(proxyClass, method);
MethodInvoker invoker = new InstanceMethodInvoker(proxyClass, method, name);
return RubyUnboundMethod.newUnboundMethod(proxyClass, prettyName, proxyClass, name, invoker);
}

8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/javasupport/Java.java
Original file line number Diff line number Diff line change
@@ -498,7 +498,7 @@ else if ( clazz == Object.class ) {
// solved here by adding an exception-throwing "inherited"
if ( Modifier.isFinal(clazz.getModifiers()) ) {
final String clazzName = clazz.getCanonicalName();
proxy.getMetaClass().addMethod("inherited", new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC) {
proxy.getMetaClass().addMethod("inherited", new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC, "inherited") {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
throw context.runtime.newTypeError("can not extend final Java class: " + clazzName);
@@ -1052,7 +1052,7 @@ private static boolean bindJavaPackageOrClassMethod(final RubyModule parentPacka
}

final RubyClass singleton = parentPackage.getSingletonClass();
singleton.addMethod(name.intern(), new JavaAccessor(singleton, packageOrClass, parentPackage));
singleton.addMethod(name.intern(), new JavaAccessor(singleton, packageOrClass, parentPackage, name));
return true;
}

@@ -1061,8 +1061,8 @@ private static class JavaAccessor extends org.jruby.internal.runtime.methods.Jav
private final RubyModule packageOrClass;
private final RubyModule parentPackage;

JavaAccessor(final RubyClass singleton, final RubyModule packageOrClass, final RubyModule parentPackage) {
super(singleton, PUBLIC);
JavaAccessor(final RubyClass singleton, final RubyModule packageOrClass, final RubyModule parentPackage, final String name) {
super(singleton, PUBLIC, name);
this.parentPackage = parentPackage; this.packageOrClass = packageOrClass;
}

Original file line number Diff line number Diff line change
@@ -36,10 +36,10 @@ void addConstructor(final Constructor ctor, final Class<?> clazz) {

@Override void install(final RubyModule proxy) {
if ( localConstructor ) {
proxy.addMethod(name, new ConstructorInvoker(proxy, constructors));
proxy.addMethod(name, new ConstructorInvoker(proxy, constructors, name));
}
else { // if there's no constructor, we must prevent construction
proxy.addMethod(name, new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC) {
proxy.addMethod(name, new org.jruby.internal.runtime.methods.JavaMethod(proxy, PUBLIC, name) {
@Override
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
throw context.runtime.newTypeError("no public constructors for " + clazz);
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ public class InstanceMethodInvokerInstaller extends MethodInstaller {

@Override void install(final RubyModule proxy) {
if ( hasLocalMethod() ) {
defineMethods(proxy, new InstanceMethodInvoker(proxy, methods));
defineMethods(proxy, new InstanceMethodInvoker(proxy, methods, name));
}
}
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,6 @@ public SingletonMethodInvokerInstaller(String name, Object singleton) {
// we don't check haveLocalMethod() here because it's not local and we know
// that we always want to go ahead and install it
final RubyClass singletonClass = proxy.getSingletonClass();
defineMethods(singletonClass, new SingletonMethodInvoker(this.singleton, singletonClass, methods), false);
defineMethods(singletonClass, new SingletonMethodInvoker(this.singleton, singletonClass, methods, name), false);
}
}
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ public class StaticMethodInvokerInstaller extends MethodInstaller {
@Override void install(final RubyModule proxy) {
if ( hasLocalMethod() ) {
final RubyClass singletonClass = proxy.getSingletonClass();
defineMethods(singletonClass, new StaticMethodInvoker(singletonClass, methods), false);
defineMethods(singletonClass, new StaticMethodInvoker(singletonClass, methods, name), false);
}
}
}

0 comments on commit 6c1fd1f

Please sign in to comment.