Skip to content

Commit 8702c89

Browse files
committed
[refactort] remove allocator classes
1 parent 4b2968b commit 8702c89

22 files changed

+24
-168
lines changed

src/main/java/org/jruby/ext/openssl/BN.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.jruby.anno.JRubyMethod;
4747
import org.jruby.exceptions.RaiseException;
4848
import org.jruby.runtime.Arity;
49-
import org.jruby.runtime.ObjectAllocator;
5049
import org.jruby.runtime.ThreadContext;
5150
import org.jruby.runtime.builtin.IRubyObject;
5251
import org.jruby.util.ByteList;
@@ -77,10 +76,6 @@ public class BN extends RubyObject {
7776

7877
private static final int DEFAULT_CERTAINTY = 100;
7978

80-
private static final ObjectAllocator BN_ALLOCATOR = new ObjectAllocator() {
81-
public BN allocate(Ruby runtime, RubyClass klass) { return new BN(runtime, klass); }
82-
};
83-
8479
public static BN newBN(Ruby runtime, BigInteger value) {
8580
return newInstance(runtime, value);
8681
}
@@ -92,7 +87,7 @@ static BN newInstance(final Ruby runtime, BigInteger value) {
9287
static void createBN(final Ruby runtime, final RubyModule OpenSSL, final RubyClass OpenSSLError) {
9388
OpenSSL.defineClassUnder("BNError", OpenSSLError, OpenSSLError.getAllocator());
9489

95-
RubyClass BN = OpenSSL.defineClassUnder("BN", runtime.getObject(), BN_ALLOCATOR);
90+
RubyClass BN = OpenSSL.defineClassUnder("BN", runtime.getObject(), (r, klass) -> new BN(r, klass));
9691
BN.includeModule( runtime.getModule("Comparable") );
9792
BN.defineAnnotatedMethods(BN.class);
9893
}

src/main/java/org/jruby/ext/openssl/Cipher.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
import java.util.HashMap;
4343
import java.util.LinkedHashMap;
4444
import java.util.List;
45-
import java.util.Map;
4645
import javax.crypto.NoSuchPaddingException;
4746
import javax.crypto.spec.GCMParameterSpec;
4847
import javax.crypto.spec.IvParameterSpec;
@@ -78,12 +77,8 @@
7877
public class Cipher extends RubyObject {
7978
private static final long serialVersionUID = -5390983669951165103L;
8079

81-
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
82-
public Cipher allocate(Ruby runtime, RubyClass klass) { return new Cipher(runtime, klass); }
83-
};
84-
8580
static void createCipher(final Ruby runtime, final RubyModule OpenSSL, final RubyClass OpenSSLError) {
86-
final RubyClass Cipher = OpenSSL.defineClassUnder("Cipher", runtime.getObject(), ALLOCATOR);
81+
final RubyClass Cipher = OpenSSL.defineClassUnder("Cipher", runtime.getObject(), (r, klass) -> new Cipher(r, klass));
8782
Cipher.defineClassUnder("CipherError", OpenSSLError, OpenSSLError.getAllocator());
8883
Cipher.defineAnnotatedMethods(Cipher.class);
8984

src/main/java/org/jruby/ext/openssl/Digest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,12 @@
5252
public class Digest extends RubyObject {
5353
private static final long serialVersionUID = 7409857414064319518L;
5454

55-
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
56-
public Digest allocate(Ruby runtime, RubyClass klass) { return new Digest(runtime, klass); }
57-
};
58-
5955
static void createDigest(Ruby runtime, final RubyModule OpenSSL, final RubyClass OpenSSLError) {
6056
runtime.getLoadService().require("digest");
6157

6258
final RubyModule coreDigest = runtime.getModule("Digest");
6359
final RubyClass DigestClass = coreDigest.getClass("Class"); // ::Digest::Class
64-
RubyClass Digest = OpenSSL.defineClassUnder("Digest", DigestClass, ALLOCATOR);
60+
RubyClass Digest = OpenSSL.defineClassUnder("Digest", DigestClass, (r, klass) -> new Digest(r, klass));
6561
OpenSSL.defineClassUnder("DigestError", OpenSSLError, OpenSSLError.getAllocator());
6662
Digest.defineAnnotatedMethods(Digest.class);
6763

src/main/java/org/jruby/ext/openssl/HMAC.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.jruby.RubyObject;
3838
import org.jruby.RubyString;
3939
import org.jruby.anno.JRubyMethod;
40-
import org.jruby.runtime.ObjectAllocator;
4140
import org.jruby.runtime.builtin.IRubyObject;
4241
import org.jruby.util.ByteList;
4342
import org.jruby.runtime.Visibility;
@@ -50,12 +49,8 @@
5049
public class HMAC extends RubyObject {
5150
private static final long serialVersionUID = 7602535792884680307L;
5251

53-
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
54-
public HMAC allocate(Ruby runtime, RubyClass klass) { return new HMAC(runtime, klass); }
55-
};
56-
5752
static void createHMAC(final Ruby runtime, final RubyModule OpenSSL, final RubyClass OpenSSLError) {
58-
RubyClass HMAC = OpenSSL.defineClassUnder("HMAC", runtime.getObject(), ALLOCATOR);
53+
RubyClass HMAC = OpenSSL.defineClassUnder("HMAC", runtime.getObject(), (r, klass) -> new HMAC(r, klass));
5954
OpenSSL.defineClassUnder("HMACError", OpenSSLError, OpenSSLError.getAllocator());
6055
HMAC.defineAnnotatedMethods(HMAC.class);
6156
}

src/main/java/org/jruby/ext/openssl/NetscapeSPKI.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.jruby.anno.JRubyMethod;
5050
import org.jruby.exceptions.RaiseException;
5151
import org.jruby.ext.openssl.impl.Base64;
52-
import org.jruby.runtime.ObjectAllocator;
5352
import org.jruby.runtime.builtin.IRubyObject;
5453
import org.jruby.runtime.ThreadContext;
5554
import org.jruby.runtime.Visibility;
@@ -68,15 +67,9 @@
6867
public class NetscapeSPKI extends RubyObject {
6968
private static final long serialVersionUID = 3211242351810109432L;
7069

71-
private static ObjectAllocator NETSCAPESPKI_ALLOCATOR = new ObjectAllocator() {
72-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
73-
return new NetscapeSPKI(runtime, klass);
74-
}
75-
};
76-
7770
static void createNetscapeSPKI(Ruby runtime, final RubyModule OpenSSL, final RubyClass OpenSSLError) {
7871
RubyModule Netscape = OpenSSL.defineModuleUnder("Netscape");
79-
RubyClass SPKI = Netscape.defineClassUnder("SPKI",runtime.getObject(),NETSCAPESPKI_ALLOCATOR);
72+
RubyClass SPKI = Netscape.defineClassUnder("SPKI", runtime.getObject(), (r, klass) -> new NetscapeSPKI(r, klass));
8073
Netscape.defineClassUnder("SPKIError", OpenSSLError, OpenSSLError.getAllocator());
8174
SPKI.defineAnnotatedMethods(NetscapeSPKI.class);
8275
}

src/main/java/org/jruby/ext/openssl/OCSPBasicResponse.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
import org.jruby.ext.openssl.x509store.X509AuxCertificate;
8989
import org.jruby.ext.openssl.x509store.X509Utils;
9090
import org.jruby.runtime.Arity;
91-
import org.jruby.runtime.ObjectAllocator;
9291
import org.jruby.runtime.ThreadContext;
9392
import org.jruby.runtime.Visibility;
9493
import org.jruby.runtime.builtin.IRubyObject;
@@ -117,14 +116,8 @@ public class OCSPBasicResponse extends RubyObject {
117116
private static final String OCSP_RESPID_KEY = "RESPID_KEY";
118117
private static final String OCSP_TRUSTOTHER = "TRUSTOTHER";
119118

120-
private static ObjectAllocator BASICRESPONSE_ALLOCATOR = new ObjectAllocator() {
121-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
122-
return new OCSPBasicResponse(runtime, klass);
123-
}
124-
};
125-
126119
public static void createBasicResponse(final Ruby runtime, final RubyModule OCSP) {
127-
RubyClass BasicResponse = OCSP.defineClassUnder("BasicResponse", runtime.getObject(), BASICRESPONSE_ALLOCATOR);
120+
RubyClass BasicResponse = OCSP.defineClassUnder("BasicResponse", runtime.getObject(), (r, klass) -> new OCSPBasicResponse(r, klass));
128121
BasicResponse.defineAnnotatedMethods(OCSPBasicResponse.class);
129122
}
130123

src/main/java/org/jruby/ext/openssl/OCSPCertificateId.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import org.jruby.RubyObject;
5353
import org.jruby.RubyString;
5454
import org.jruby.anno.JRubyMethod;
55-
import org.jruby.ext.openssl.impl.ASN1Registry;
56-
import org.jruby.runtime.ObjectAllocator;
5755
import org.jruby.runtime.ThreadContext;
5856
import org.jruby.runtime.Visibility;
5957
import org.jruby.runtime.builtin.IRubyObject;
@@ -70,14 +68,8 @@
7068
public class OCSPCertificateId extends RubyObject {
7169
private static final long serialVersionUID = 6324454052172773918L;
7270

73-
private static ObjectAllocator CERTIFICATEID_ALLOCATOR = new ObjectAllocator() {
74-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
75-
return new OCSPCertificateId(runtime, klass);
76-
}
77-
};
78-
7971
public static void createCertificateId(final Ruby runtime, final RubyModule _OCSP) {
80-
RubyClass _certificateId = _OCSP.defineClassUnder("CertificateId", runtime.getObject(), CERTIFICATEID_ALLOCATOR);
72+
RubyClass _certificateId = _OCSP.defineClassUnder("CertificateId", runtime.getObject(), (r, klass) -> new OCSPCertificateId(r, klass));
8173
_certificateId.defineAnnotatedMethods(OCSPCertificateId.class);
8274
}
8375

src/main/java/org/jruby/ext/openssl/OCSPRequest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
import org.jruby.anno.JRubyMethod;
8383
import org.jruby.ext.openssl.x509store.X509AuxCertificate;
8484
import org.jruby.runtime.Arity;
85-
import org.jruby.runtime.ObjectAllocator;
8685
import org.jruby.runtime.ThreadContext;
8786
import org.jruby.runtime.Visibility;
8887
import org.jruby.runtime.builtin.IRubyObject;
@@ -98,19 +97,13 @@
9897
*/
9998
public class OCSPRequest extends RubyObject {
10099
private static final long serialVersionUID = -4020616730425816999L;
101-
102-
private static ObjectAllocator REQUEST_ALLOCATOR = new ObjectAllocator() {
103-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
104-
return new OCSPRequest(runtime, klass);
105-
}
106-
};
107100

108101
public OCSPRequest(Ruby runtime, RubyClass metaClass) {
109102
super(runtime, metaClass);
110103
}
111104

112105
public static void createRequest(final Ruby runtime, final RubyModule _OCSP) {
113-
RubyClass _request = _OCSP.defineClassUnder("Request", runtime.getObject(), REQUEST_ALLOCATOR);
106+
RubyClass _request = _OCSP.defineClassUnder("Request", runtime.getObject(), (r, klass) -> new OCSPRequest(r, klass));
114107
_request.defineAnnotatedMethods(OCSPRequest.class);
115108
}
116109

src/main/java/org/jruby/ext/openssl/OCSPResponse.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.jruby.RubyString;
4848
import org.jruby.anno.JRubyMethod;
4949
import org.jruby.runtime.Arity;
50-
import org.jruby.runtime.ObjectAllocator;
5150
import org.jruby.runtime.ThreadContext;
5251
import org.jruby.runtime.Visibility;
5352
import org.jruby.runtime.builtin.IRubyObject;
@@ -62,12 +61,6 @@
6261
*/
6362
public class OCSPResponse extends RubyObject {
6463
private static final long serialVersionUID = 5763247988029815198L;
65-
66-
private static ObjectAllocator RESPONSE_ALLOCATOR = new ObjectAllocator() {
67-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
68-
return new OCSPResponse(runtime, klass);
69-
}
70-
};
7164

7265
public OCSPResponse(Ruby runtime, RubyClass metaClass) {
7366
super(runtime, metaClass);
@@ -78,7 +71,7 @@ public OCSPResponse(Ruby runtime) {
7871
}
7972

8073
public static void createResponse(final Ruby runtime, final RubyModule OCSP) {
81-
RubyClass Response = OCSP.defineClassUnder("Response", runtime.getObject(), RESPONSE_ALLOCATOR);
74+
RubyClass Response = OCSP.defineClassUnder("Response", runtime.getObject(), (r, klass) -> new OCSPResponse(r, klass));
8275
Response.defineAnnotatedMethods(OCSPResponse.class);
8376
}
8477

src/main/java/org/jruby/ext/openssl/OCSPSingleResponse.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import org.jruby.RubyTime;
5757
import org.jruby.anno.JRubyMethod;
5858
import org.jruby.runtime.Arity;
59-
import org.jruby.runtime.ObjectAllocator;
6059
import org.jruby.runtime.ThreadContext;
6160
import org.jruby.runtime.Visibility;
6261
import org.jruby.runtime.builtin.IRubyObject;
@@ -71,15 +70,9 @@
7170
*/
7271
public class OCSPSingleResponse extends RubyObject {
7372
private static final long serialVersionUID = 7947277768033100227L;
74-
75-
private static ObjectAllocator SINGLERESPONSE_ALLOCATOR = new ObjectAllocator() {
76-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
77-
return new OCSPSingleResponse(runtime, klass);
78-
}
79-
};
8073

8174
public static void createSingleResponse(final Ruby runtime, final RubyModule _OCSP) {
82-
RubyClass _request = _OCSP.defineClassUnder("SingleResponse", runtime.getObject(), SINGLERESPONSE_ALLOCATOR);
75+
RubyClass _request = _OCSP.defineClassUnder("SingleResponse", runtime.getObject(), (r, klass) -> new OCSPSingleResponse(r, klass));
8376
_request.defineAnnotatedMethods(OCSPSingleResponse.class);
8477
}
8578

0 commit comments

Comments
 (0)