@@ -30,17 +30,18 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
30
31
31
*/
32
32
33
- // Generated by Snowball (build from 867c4ec70debd4daa7fb4d5a9f7759b47887d0b9 )
33
+ // Generated by Snowball (build from 9a22f0d3f44cda36677829328fe2642750114d57 )
34
34
package opennlp .tools .stemmer .snowball ;
35
35
36
- import java .lang .reflect .Method ;
36
+ import java .lang .invoke .MethodHandle ;
37
+ import java .lang .invoke .MethodHandles ;
38
+ import java .lang .invoke .MethodType ;
39
+ import java .util .Locale ;
37
40
41
+ /**
42
+ * Internal class used by Snowball stemmers
43
+ */
38
44
public class Among {
39
- public final char [] s ; /* search string */
40
- public final int substring_i ; /* index to longest matching substring */
41
- public final int result ; /* result of the lookup */
42
- public final Method method ; /* method to use if substring matches */
43
-
44
45
public Among (String s , int substring_i , int result ) {
45
46
this .s = s .toCharArray ();
46
47
this .substring_i = substring_i ;
@@ -49,14 +50,30 @@ public Among(String s, int substring_i, int result) {
49
50
}
50
51
51
52
public Among (String s , int substring_i , int result , String methodname ,
52
- Class <? extends AbstractSnowballStemmer > programclass ) {
53
+ MethodHandles . Lookup methodobject ) {
53
54
this .s = s .toCharArray ();
54
55
this .substring_i = substring_i ;
55
56
this .result = result ;
56
- try {
57
- this .method = programclass .getDeclaredMethod (methodname );
58
- } catch (NoSuchMethodException e ) {
59
- throw new RuntimeException (e );
57
+ final Class <? extends SnowballProgram > clazz = methodobject .lookupClass ().asSubclass (SnowballProgram .class );
58
+ if (methodname .length () > 0 ) {
59
+ try {
60
+ this .method = methodobject .findVirtual (clazz , methodname , MethodType .methodType (boolean .class ))
61
+ .asType (MethodType .methodType (boolean .class , SnowballProgram .class ));
62
+ } catch (NoSuchMethodException | IllegalAccessException e ) {
63
+ throw new RuntimeException (String .format (Locale .ENGLISH ,
64
+ "Snowball program '%s' is broken, cannot access method: boolean %s()" ,
65
+ clazz .getSimpleName (), methodname
66
+ ), e );
67
+ }
68
+ } else {
69
+ this .method = null ;
60
70
}
61
71
}
62
- }
72
+
73
+ final char [] s ; /* search string */
74
+ final int substring_i ; /* index to longest matching substring */
75
+ final int result ; /* result of the lookup */
76
+
77
+ // Make sure this is not accessible outside package for Java security reasons!
78
+ final MethodHandle method ; /* method to use if substring matches */
79
+ };
0 commit comments