55import java .util .Map ;
66
77import org .jruby .Ruby ;
8- import org .jruby .RubyArray ;
98import org .jruby .RubyClass ;
109import org .jruby .RubyFixnum ;
1110import org .jruby .RubyModule ;
@@ -33,13 +32,14 @@ public class NokogiriService implements BasicLibraryService
3332 public static Map <String , RubyClass >
3433 getNokogiriClassCache (Ruby ruby )
3534 {
35+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
3636 return (Map <String , RubyClass >) ruby .getModule ("Nokogiri" ).getInternalVariable ("cache" );
3737 }
3838
3939 private static Map <String , RubyClass >
4040 populateNokogiriClassCache (Ruby ruby )
4141 {
42- Map <String , RubyClass > nokogiriClassCache = new HashMap <String , RubyClass >();
42+ Map <String , RubyClass > nokogiriClassCache = new HashMap <>();
4343 nokogiriClassCache .put ("Nokogiri::HTML4::Document" , (RubyClass )ruby .getClassFromPath ("Nokogiri::HTML4::Document" ));
4444 nokogiriClassCache .put ("Nokogiri::HTML4::ElementDescription" ,
4545 (RubyClass )ruby .getClassFromPath ("Nokogiri::HTML4::ElementDescription" ));
@@ -78,6 +78,7 @@ public class NokogiriService implements BasicLibraryService
7878 private void
7979 init (Ruby ruby )
8080 {
81+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
8182 RubyModule nokogiri = ruby .defineModule ("Nokogiri" );
8283 RubyModule xmlModule = nokogiri .defineModuleUnder ("XML" );
8384 RubyModule xmlSaxModule = xmlModule .defineModuleUnder ("SAX" );
@@ -97,6 +98,7 @@ public class NokogiriService implements BasicLibraryService
9798 private void
9899 createSyntaxErrors (Ruby ruby , RubyModule nokogiri , RubyModule xmlModule )
99100 {
101+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
100102 RubyClass syntaxError = nokogiri .defineClassUnder ("SyntaxError" , ruby .getStandardError (),
101103 ruby .getStandardError ().getAllocator ());
102104 RubyClass xmlSyntaxError = xmlModule .defineClassUnder ("SyntaxError" , syntaxError , XML_SYNTAXERROR_ALLOCATOR );
@@ -106,6 +108,7 @@ public class NokogiriService implements BasicLibraryService
106108 private RubyClass
107109 createXmlModule (Ruby ruby , RubyModule xmlModule )
108110 {
111+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
109112 RubyClass node = xmlModule .defineClassUnder ("Node" , ruby .getObject (), XML_NODE_ALLOCATOR );
110113 node .defineAnnotatedMethods (XmlNode .class );
111114
@@ -183,6 +186,7 @@ public class NokogiriService implements BasicLibraryService
183186 private void
184187 createHtmlModule (Ruby ruby , RubyModule htmlModule )
185188 {
189+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
186190 RubyClass htmlElemDesc = htmlModule .defineClassUnder ("ElementDescription" , ruby .getObject (),
187191 HTML_ELEMENT_DESCRIPTION_ALLOCATOR );
188192 htmlElemDesc .defineAnnotatedMethods (Html4ElementDescription .class );
@@ -195,6 +199,7 @@ public class NokogiriService implements BasicLibraryService
195199 private void
196200 createDocuments (Ruby ruby , RubyModule xmlModule , RubyModule htmlModule , RubyClass node )
197201 {
202+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
198203 RubyClass xmlDocument = xmlModule .defineClassUnder ("Document" , node , XML_DOCUMENT_ALLOCATOR );
199204 xmlDocument .defineAnnotatedMethods (XmlDocument .class );
200205
@@ -206,6 +211,7 @@ public class NokogiriService implements BasicLibraryService
206211 private void
207212 createSaxModule (Ruby ruby , RubyModule xmlSaxModule , RubyModule htmlSaxModule )
208213 {
214+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
209215 RubyClass xmlSaxParserContext = xmlSaxModule .defineClassUnder ("ParserContext" , ruby .getObject (),
210216 XML_SAXPARSER_CONTEXT_ALLOCATOR );
211217 xmlSaxParserContext .defineAnnotatedMethods (XmlSaxParserContext .class );
@@ -225,6 +231,7 @@ public class NokogiriService implements BasicLibraryService
225231 private void
226232 createXsltModule (Ruby ruby , RubyModule xsltModule )
227233 {
234+ // TODO: switch to common undeprecated API when 9.4 adds 10 methods
228235 RubyClass stylesheet = xsltModule .defineClassUnder ("Stylesheet" , ruby .getObject (), XSLT_STYLESHEET_ALLOCATOR );
229236 stylesheet .defineAnnotatedMethods (XsltStylesheet .class );
230237 }
@@ -259,21 +266,9 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
259266 }
260267 };
261268
262- private static ObjectAllocator HTML_ELEMENT_DESCRIPTION_ALLOCATOR =
263- new ObjectAllocator ()
264- {
265- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
266- return new Html4ElementDescription (runtime , klazz );
267- }
268- };
269+ private static final ObjectAllocator HTML_ELEMENT_DESCRIPTION_ALLOCATOR = Html4ElementDescription ::new ;
269270
270- private static ObjectAllocator HTML_ENTITY_LOOKUP_ALLOCATOR =
271- new ObjectAllocator ()
272- {
273- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
274- return new Html4EntityLookup (runtime , klazz );
275- }
276- };
271+ private static final ObjectAllocator HTML_ENTITY_LOOKUP_ALLOCATOR = Html4EntityLookup ::new ;
277272
278273 public static final ObjectAllocator XML_ATTR_ALLOCATOR = new ObjectAllocator ()
279274 {
@@ -486,25 +481,12 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
486481 }
487482 };
488483
489- private static ObjectAllocator XML_ATTRIBUTE_DECL_ALLOCATOR = new ObjectAllocator ()
490- {
491- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
492- return new XmlAttributeDecl (runtime , klazz );
493- }
494- };
484+ private static final ObjectAllocator XML_ATTRIBUTE_DECL_ALLOCATOR = XmlAttributeDecl ::new ;
495485
496- private static ObjectAllocator XML_ENTITY_DECL_ALLOCATOR = new ObjectAllocator ()
497- {
498- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
499- return new XmlEntityDecl (runtime , klazz );
500- }
501- };
486+ private static final ObjectAllocator XML_ENTITY_DECL_ALLOCATOR = XmlEntityDecl ::new ;
502487
503- private static ObjectAllocator XML_ELEMENT_CONTENT_ALLOCATOR = new ObjectAllocator ()
504- {
505- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
506- throw runtime .newNotImplementedError ("not implemented" );
507- }
488+ private static final ObjectAllocator XML_ELEMENT_CONTENT_ALLOCATOR = (runtime , klazz ) -> {
489+ throw runtime .newNotImplementedError ("not implemented" );
508490 };
509491
510492 public static final ObjectAllocator XML_RELAXNG_ALLOCATOR = new ObjectAllocator ()
@@ -537,19 +519,9 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
537519 }
538520 };
539521
540- private static final ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator ()
541- {
542- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
543- return new XmlSaxPushParser (runtime , klazz );
544- }
545- };
522+ private static final ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = XmlSaxPushParser ::new ;
546523
547- private static final ObjectAllocator HTML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator ()
548- {
549- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
550- return new Html4SaxPushParser (runtime , klazz );
551- }
552- };
524+ private static final ObjectAllocator HTML_SAXPUSHPARSER_ALLOCATOR = Html4SaxPushParser ::new ;
553525
554526 public static final ObjectAllocator XML_SCHEMA_ALLOCATOR = new ObjectAllocator ()
555527 {
@@ -566,12 +538,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
566538 }
567539 };
568540
569- public static final ObjectAllocator XML_SYNTAXERROR_ALLOCATOR = new ObjectAllocator ()
570- {
571- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
572- return new XmlSyntaxError (runtime , klazz );
573- }
574- };
541+ public static final ObjectAllocator XML_SYNTAXERROR_ALLOCATOR = XmlSyntaxError ::new ;
575542
576543 public static final ObjectAllocator XML_TEXT_ALLOCATOR = new ObjectAllocator ()
577544 {
@@ -588,12 +555,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
588555 }
589556 };
590557
591- public static final ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = new ObjectAllocator ()
592- {
593- public IRubyObject allocate (Ruby runtime , RubyClass klazz ) {
594- return new XmlXpathContext (runtime , klazz );
595- }
596- };
558+ public static final ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = XmlXpathContext ::new ;
597559
598560 public static ObjectAllocator XSLT_STYLESHEET_ALLOCATOR = new ObjectAllocator ()
599561 {
0 commit comments