Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1942fad573fe
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 53c8c561a713
Choose a head ref
  • 5 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 29, 2016

  1. Copy the full SHA
    98d1af3 View commit details
  2. Copy the full SHA
    65f4f1b View commit details
  3. Copy the full SHA
    56747df View commit details
  4. Copy the full SHA
    15055fa View commit details
  5. Copy the full SHA
    53c8c56 View commit details
25 changes: 14 additions & 11 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -776,8 +776,12 @@ public RubyString convertToString() {
@Override
public IRubyObject anyToString() {
String cname = getMetaClass().getRealClass().getName();
String hex = Integer.toHexString(System.identityHashCode(this));
/* 6:tags 16:addr 1:eos */
RubyString str = getRuntime().newString("#<" + cname + ":0x" + Integer.toHexString(System.identityHashCode(this)) + '>');
RubyString str = RubyString.newString(getRuntime(),
new StringBuilder(2 + cname.length() + 3 + hex.length() + 1).
append("#<").append(cname).append(":0x").append(hex).append('>')
);
str.setTaint(isTaint());
return str;
}
@@ -1063,30 +1067,29 @@ protected long getObjectId() {
*/
@Override
public IRubyObject inspect() {
Ruby runtime = getRuntime();
if ((!isImmediate()) && !(this instanceof RubyModule) && hasVariables()) {
return hashyInspect();
} else {
if (isNil()) return RubyNil.inspect(runtime.getCurrentContext(), this);
return to_s();
}

if (isNil()) return RubyNil.inspect(getRuntime());
return to_s();
}

public IRubyObject hashyInspect() {
Ruby runtime = getRuntime();
StringBuilder part = new StringBuilder();
final Ruby runtime = getRuntime();
String cname = getMetaClass().getRealClass().getName();
StringBuilder part = new StringBuilder(2 + cname.length() + 3 + 8 + 1); // #<Object:0x5a1c0542>
part.append("#<").append(cname).append(":0x");
part.append(Integer.toHexString(inspectHashCode()));

if (runtime.isInspecting(this)) {
/* 6:tags 16:addr 1:eos */
part.append(" ...>");
return runtime.newString(part.toString());
return RubyString.newString(runtime, part);
}
try {
runtime.registerInspecting(this);
return runtime.newString(inspectObj(part).toString());
return RubyString.newString(runtime, inspectObj(runtime, part));
} finally {
runtime.unregisterInspecting(this);
}
@@ -1126,8 +1129,8 @@ protected int inspectHashCode() {
* The internal helper method that takes care of the part of the
* inspection that inspects instance variables.
*/
private StringBuilder inspectObj(StringBuilder part) {
ThreadContext context = getRuntime().getCurrentContext();
private StringBuilder inspectObj(final Ruby runtime, StringBuilder part) {
final ThreadContext context = runtime.getCurrentContext();
String sep = "";

for (Map.Entry<String, VariableAccessor> entry : metaClass.getVariableTableManager().getVariableAccessorsForRead().entrySet()) {
8 changes: 6 additions & 2 deletions core/src/main/java/org/jruby/RubyNil.java
Original file line number Diff line number Diff line change
@@ -162,9 +162,13 @@ public static RubyHash to_h(ThreadContext context, IRubyObject recv) {
*/
@JRubyMethod
public static RubyString inspect(ThreadContext context, IRubyObject recv) {
return RubyString.newUSASCIIString(context.runtime, "nil");
return inspect(context.runtime);
}


static RubyString inspect(Ruby runtime) {
return RubyString.newUSASCIIString(runtime, "nil");
}

/** nil_and
*
*/
2 changes: 0 additions & 2 deletions core/src/main/java/org/jruby/javasupport/JavaClass.java
Original file line number Diff line number Diff line change
@@ -992,6 +992,4 @@ public static Field[] getFields(final Class<?> clazz) {
catch (SecurityException e) { return new Field[0]; }
}

@Deprecated
public static final boolean CAN_SET_ACCESSIBLE = JavaUtil.CAN_SET_ACCESSIBLE;
}
34 changes: 31 additions & 3 deletions core/src/main/java/org/jruby/javasupport/JavaPackage.java
Original file line number Diff line number Diff line change
@@ -100,11 +100,22 @@ private JavaPackage(final Ruby runtime, final CharSequence packageName) {
this.packageName = packageName.toString();
}

@JRubyMethod
// NOTE: name is Ruby name not pkg.name ~ maybe it should be just like with JavaClass?

@JRubyMethod(name = "package_name", alias = "to_s")
public RubyString package_name() {
return getRuntime().newString(packageName);
}

@Override
public RubyString to_s() { return package_name(); }

@Override
@JRubyMethod
public IRubyObject inspect() {
return getRuntime().newString(getName()); // super.to_s()
}

@JRubyMethod(name = "const_missing", required = 1, visibility = Visibility.PRIVATE)
public IRubyObject const_missing(final ThreadContext context, final IRubyObject name) {
return relativeJavaClassOrPackage(context, name, false);
@@ -255,11 +266,28 @@ static RaiseException packageMethodArgumentMismatch(final Ruby runtime, final Ru
final String method, final int argsLength) {
String packageName = ((JavaPackage) pkg).packageName;
return runtime.newArgumentError(
"Java package '"+ packageName +"' does not have a method `"+
method +"' with "+ argsLength + (argsLength == 1 ? " argument" : " arguments")
"Java package '" + packageName + "' does not have a method `" +
method + "' with " + argsLength + (argsLength == 1 ? " argument" : " arguments")
);
}

public final boolean isAvailable() {
// may be null if no package information is available from the archive or codebase
return Package.getPackage(packageName) != null;
}

@JRubyMethod(name = "available?")
public IRubyObject available_p(ThreadContext context) {
return context.runtime.newBoolean(isAvailable());
}

@JRubyMethod(name = "sealed?")
public IRubyObject sealed_p(ThreadContext context) {
final Package pkg = Package.getPackage(packageName);
if ( pkg == null ) return context.nil;
return context.runtime.newBoolean(pkg.isSealed());
}

@Override
@SuppressWarnings("unchecked")
public Object toJava(final Class target) {
9 changes: 9 additions & 0 deletions test/jruby/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
@@ -925,6 +925,15 @@ def test_package_does_respond_to_missing
assert java.lang.respond_to_missing?(:test, true)
end

def test_package_to_s_returns_name
assert_equal 'org.jruby', org.jruby.to_s
assert_equal 'java.lang.reflect', Java::JavaLangReflect.to_s
end

def test_package_inspect
assert_equal 'Java::JavaLangReflect', java.lang.reflect.inspect
end

@@include_proc = Proc.new do
Thread.stop
java_import "java.lang.System"