pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/5d277a34e02f6798fa5e21180653bf7e8950b4a9

/> local (non-member) classes should have correct name just like anonymo… · jruby/jruby@5d277a3 · GitHub
Skip to content

Commit 5d277a3

Browse files
committed
local (non-member) classes should have correct name just like anonymous classes
local and anonymous classes had empty names <= 1.7.19 and the change (for anonymous classes) was not spec-ed properly, but with features such as Java proxy marshalling (#3526) this gained importance.
1 parent ebba35a commit 5d277a3

3 files changed

Lines changed: 68 additions & 5 deletions

File tree

core/src/main/java/org/jruby/javasupport/binding/ClassInitializer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ public RubyModule initialize(RubyModule proxy) {
5858
proxy.setParent(parent);
5959

6060
// set the Java class name and package
61-
if ( javaClass.isAnonymousClass() ) {
62-
String baseName = ""; // javaClass.getSimpleName() returns "" for anonymous
61+
if ( javaClass.isMemberClass() ) {
62+
proxy.setBaseName( javaClass.getSimpleName() );
63+
}
64+
else { // javaClass.isAnonymousClass() || javaClass.isLocalClass()
65+
String baseName = javaClass.getSimpleName(); // returns "" for anonymous
6366
if ( enclosingClass != null ) {
6467
// instead of an empty name anonymous classes will have a "conforming"
6568
// although not valid (by Ruby semantics) RubyClass name e.g. :
@@ -77,9 +80,6 @@ else if ( length > offset + 1 ) { // skip '$'
7780
}
7881
proxy.setBaseName( baseName );
7982
}
80-
else {
81-
proxy.setBaseName( javaClass.getSimpleName() );
82-
}
8383

8484
installClassFields(proxyClass, state);
8585
installClassInstanceMethods(proxyClass, state);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require File.dirname(__FILE__) + "/../spec_helper"
2+
3+
describe "Java class" do
4+
5+
java_import "java_integration.fixtures.InnerClasses"
6+
7+
it "has (qualified) Ruby name" do
8+
expect( InnerClasses.name ).to eql 'Java::Java_integrationFixtures::InnerClasses'
9+
end
10+
11+
it "has name for inner classes" do
12+
base_name = InnerClasses.name
13+
expect( InnerClasses::CapsInnerClass.name ).to eql "#{base_name}::CapsInnerClass"
14+
expect( InnerClasses::lowerInnerClass.name ).to eql "#{base_name}::lowerInnerClass"
15+
end
16+
17+
it "has name for local classes" do
18+
base_name = InnerClasses.name
19+
local = InnerClasses.localMethodClass
20+
# java_integration.fixtures.InnerClasses$1CapsImpl
21+
expect( local.class.name ).to eql "#{base_name}::1CapsImpl"
22+
end
23+
24+
it "has name for anonymous classes" do
25+
base_name = InnerClasses.name
26+
anon = InnerClasses.anonymousMethodClass
27+
expect( anon.class.name ).to eql "#{base_name}::1"
28+
end
29+
30+
end

spec/java_integration/fixtures/InnerClasses.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package java_integration.fixtures;
22

33
public class InnerClasses {
4+
45
public static class CapsInnerClass {
56
public static int value() { return 1; }
67
public static class CapsInnerClass2 {
@@ -57,4 +58,36 @@ static class PackageInner {
5758
private static class PrivateInner {
5859
static String VALUE = PrivateInner.class.getName();
5960
}
61+
62+
private static int capsImplCounter;
63+
64+
public static CapsInnerInterface localMethodClass() {
65+
class CapsImpl implements CapsInnerInterface {
66+
private final int counter;
67+
CapsImpl(int counter) { this.counter = counter; }
68+
public String capsMethod() { return "CapsImpl" + counter; }
69+
70+
}
71+
return new CapsImpl(capsImplCounter++);
72+
}
73+
74+
public static CapsInnerInterface localMethodClass2() {
75+
class CapsImpl implements CapsInnerInterface {
76+
private final int counter;
77+
CapsImpl(int counter) { this.counter = counter; }
78+
public String capsMethod() { return "CapsImpl2" + counter; }
79+
80+
}
81+
return new CapsImpl(capsImplCounter++);
82+
}
83+
84+
private static int capsAnonCounter;
85+
86+
public static CapsInnerInterface anonymousMethodClass() {
87+
return new CapsInnerInterface() {
88+
private final int counter = capsAnonCounter++;
89+
public String capsMethod() { return "CapsAnon" + counter; }
90+
};
91+
}
92+
6093
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy