@@ -351,115 +351,6 @@ public static Class<?> findClass(String className) throws ClassNotFoundException
351
351
throw new ClassNotFoundException (prob .getMessage (), prob );
352
352
}
353
353
354
- /*
355
- /**********************************************************
356
- /* Caching access to class metadata, added in 2.7
357
- /**********************************************************
358
- */
359
-
360
- /* 17-Sep-2015, tatu: Although access methods should not be significant
361
- * problems for most proper usage, they may become problematic if
362
- * ObjectMapper has to be re-created; and especially so on Android.
363
- * So let's do somewhat aggressive caching.
364
- */
365
-
366
- private final static LRUMap <Class <?>,ClassMetadata > sCached = new LRUMap <Class <?>,ClassMetadata >(48 , 48 );
367
-
368
- /**
369
- * @since 2.7
370
- */
371
- public static String getPackageName (Class <?> cls ) {
372
- return _getMetadata (cls ).getPackageName ();
373
- }
374
-
375
- /**
376
- * @since 2.7
377
- */
378
- public static boolean hasEnclosingMethod (Class <?> cls ) {
379
- return _getMetadata (cls ).hasEnclosingMethod ();
380
- }
381
-
382
- /**
383
- * @since 2.7
384
- */
385
- public static Field [] getDeclaredFields (Class <?> cls ) {
386
- return _getMetadata (cls ).getDeclaredFields ();
387
- }
388
-
389
- /**
390
- * @since 2.7
391
- */
392
- public static Method [] getDeclaredMethods (Class <?> cls ) {
393
- return _getMetadata (cls ).getDeclaredMethods ();
394
- }
395
-
396
- /**
397
- * @since 2.7
398
- */
399
- public static Annotation [] findClassAnnotations (Class <?> cls ) {
400
- return _getMetadata (cls ).getDeclaredAnnotations ();
401
- }
402
-
403
- /**
404
- * @since 2.7
405
- */
406
- public static Ctor [] getConstructors (Class <?> cls ) {
407
- return _getMetadata (cls ).getConstructors ();
408
- }
409
-
410
- // // // Then methods that do NOT cache access but were considered
411
- // // // (and could be added to do caching if it was proven effective)
412
-
413
- /**
414
- * @since 2.7
415
- */
416
- public static Class <?> getDeclaringClass (Class <?> cls ) {
417
- // Caching does not seem worthwhile, as per profiling
418
- return isObjectOrPrimitive (cls ) ? null : cls .getDeclaringClass ();
419
- }
420
-
421
- /**
422
- * @since 2.7
423
- */
424
- public static Type getGenericSuperclass (Class <?> cls ) {
425
- return cls .getGenericSuperclass ();
426
- }
427
-
428
- /**
429
- * @since 2.7
430
- */
431
- public static Type [] getGenericInterfaces (Class <?> cls ) {
432
- return _getMetadata (cls ).getGenericInterfaces ();
433
- }
434
-
435
- /**
436
- * @since 2.7
437
- */
438
- public static Class <?> getEnclosingClass (Class <?> cls ) {
439
- // Caching does not seem worthwhile, as per profiling
440
- return isObjectOrPrimitive (cls ) ? null : cls .getEnclosingClass ();
441
- }
442
-
443
-
444
- private static Class <?>[] _interfaces (Class <?> cls ) {
445
- return _getMetadata (cls ).getInterfaces ();
446
- }
447
-
448
- private static ClassMetadata _getMetadata (Class <?> cls )
449
- {
450
- ClassMetadata md = sCached .get (cls );
451
- if (md == null ) {
452
- md = new ClassMetadata (cls );
453
- // tiny optimization, but in case someone concurrently constructed it,
454
- // let's use that instance, to reduce extra concurrent work.
455
- ClassMetadata old = sCached .putIfAbsent (cls , md );
456
- if (old != null ) {
457
- md = old ;
458
- }
459
- }
460
- return md ;
461
- }
462
-
463
354
/*
464
355
/**********************************************************
465
356
/* Method type detection methods
@@ -897,6 +788,113 @@ public static boolean isObjectOrPrimitive(Class<?> cls) {
897
788
return (cls == CLS_OBJECT ) || cls .isPrimitive ();
898
789
}
899
790
791
+ /*
792
+ /**********************************************************
793
+ /* Caching access to class metadata, added in 2.7
794
+ /**********************************************************
795
+ */
796
+
797
+ /* 17-Sep-2015, tatu: Although access methods should not be significant
798
+ * problems for most proper usage, they may become problematic if
799
+ * ObjectMapper has to be re-created; and especially so on Android.
800
+ * So let's do somewhat aggressive caching.
801
+ */
802
+ private final static LRUMap <Class <?>,ClassMetadata > sCached = new LRUMap <Class <?>,ClassMetadata >(48 , 48 );
803
+
804
+ /**
805
+ * @since 2.7
806
+ */
807
+ public static String getPackageName (Class <?> cls ) {
808
+ return _getMetadata (cls ).getPackageName ();
809
+ }
810
+
811
+ /**
812
+ * @since 2.7
813
+ */
814
+ public static boolean hasEnclosingMethod (Class <?> cls ) {
815
+ return _getMetadata (cls ).hasEnclosingMethod ();
816
+ }
817
+
818
+ /**
819
+ * @since 2.7
820
+ */
821
+ public static Field [] getDeclaredFields (Class <?> cls ) {
822
+ return _getMetadata (cls ).getDeclaredFields ();
823
+ }
824
+
825
+ /**
826
+ * @since 2.7
827
+ */
828
+ public static Method [] getDeclaredMethods (Class <?> cls ) {
829
+ return _getMetadata (cls ).getDeclaredMethods ();
830
+ }
831
+
832
+ /**
833
+ * @since 2.7
834
+ */
835
+ public static Annotation [] findClassAnnotations (Class <?> cls ) {
836
+ return _getMetadata (cls ).getDeclaredAnnotations ();
837
+ }
838
+
839
+ /**
840
+ * @since 2.7
841
+ */
842
+ public static Ctor [] getConstructors (Class <?> cls ) {
843
+ return _getMetadata (cls ).getConstructors ();
844
+ }
845
+
846
+ // // // Then methods that do NOT cache access but were considered
847
+ // // // (and could be added to do caching if it was proven effective)
848
+
849
+ /**
850
+ * @since 2.7
851
+ */
852
+ public static Class <?> getDeclaringClass (Class <?> cls ) {
853
+ // Caching does not seem worthwhile, as per profiling
854
+ return isObjectOrPrimitive (cls ) ? null : cls .getDeclaringClass ();
855
+ }
856
+
857
+ /**
858
+ * @since 2.7
859
+ */
860
+ public static Type getGenericSuperclass (Class <?> cls ) {
861
+ return cls .getGenericSuperclass ();
862
+ }
863
+
864
+ /**
865
+ * @since 2.7
866
+ */
867
+ public static Type [] getGenericInterfaces (Class <?> cls ) {
868
+ return _getMetadata (cls ).getGenericInterfaces ();
869
+ }
870
+
871
+ /**
872
+ * @since 2.7
873
+ */
874
+ public static Class <?> getEnclosingClass (Class <?> cls ) {
875
+ // Caching does not seem worthwhile, as per profiling
876
+ return isObjectOrPrimitive (cls ) ? null : cls .getEnclosingClass ();
877
+ }
878
+
879
+ private static Class <?>[] _interfaces (Class <?> cls ) {
880
+ return _getMetadata (cls ).getInterfaces ();
881
+ }
882
+
883
+ private static ClassMetadata _getMetadata (Class <?> cls )
884
+ {
885
+ ClassMetadata md = sCached .get (cls );
886
+ if (md == null ) {
887
+ md = new ClassMetadata (cls );
888
+ // tiny optimization, but in case someone concurrently constructed it,
889
+ // let's use that instance, to reduce extra concurrent work.
890
+ ClassMetadata old = sCached .putIfAbsent (cls , md );
891
+ if (old != null ) {
892
+ md = old ;
893
+ }
894
+ }
895
+ return md ;
896
+ }
897
+
900
898
/*
901
899
/**********************************************************
902
900
/* Helper classes
0 commit comments