6
6
* The Java Pathfinder core (jpf-core) platform is licensed under the
7
7
* Apache License, Version 2.0 (the "License"); you may not use this file except
8
8
* in compliance with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0.
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0.
11
11
*
12
12
* Unless required by applicable law or agreed to in writing, software
13
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- * See the License for the specific language governing permissions and
15
+ * See the License for the specific language governing permissions and
16
16
* limitations under the License.
17
17
*/
18
18
package java .lang ;
25
25
import java .security .ProtectionDomain ;
26
26
import java .util .*;
27
27
import java .util .concurrent .ConcurrentHashMap ;
28
- import java .util .stream .Stream ;
29
28
30
29
/**
31
30
* @author Nastaran Shafiei <nastaran.shafiei@gmail.com>
@@ -40,8 +39,11 @@ public abstract class ClassLoader {
40
39
private int nativeId ;
41
40
42
41
//--- internals
42
+
43
+ // This variable is to provide support for definePackage(String,Module) method
43
44
private ConcurrentHashMap <String , NamedPackage > packages
44
45
= new ConcurrentHashMap <>();
46
+
45
47
protected ClassLoader () {
46
48
// constructed on the native side
47
49
}
@@ -269,11 +271,39 @@ protected Package definePackage(String name, String specTitle, String specVersio
269
271
throw new UnsupportedOperationException ();
270
272
}
271
273
274
+ /**
275
+ * Written as a replacement for the auxiliary class {@link CompoundEnumeration}
276
+ */
277
+ final class EnumerationAdapter <E > implements Enumeration <E > {
278
+ private final Iterator <E > iterator ;
279
+
280
+ public EnumerationAdapter (Collection <E > collection ) {
281
+ iterator = collection .iterator ();
282
+ }
283
+
284
+ @ Override
285
+ public boolean hasMoreElements () {
286
+ return iterator .hasNext ();
287
+ }
288
+
289
+ @ Override
290
+ public E nextElement () {
291
+ return iterator .next ();
292
+ }
293
+ }
294
+
295
+ public native final Package getDefinedPackage (final String name );
296
+
297
+ public native final Package [] getDefinedPackages ();
298
+
299
+ /**
300
+ * some extra implementation to support for Class.getPackage() method
301
+ */
272
302
Package definePackage (String name , Module m ) {
273
303
if (name .isEmpty () && m .isNamed ()) {
274
304
throw new InternalError ("unnamed package in " + m );
275
305
}
276
-
306
+
277
307
if (packages == null )
278
308
packages = new ConcurrentHashMap <>();
279
309
@@ -296,66 +326,13 @@ private Package toPackage(String name, NamedPackage p, Module m) {
296
326
297
327
return NamedPackage .toPackage (p .packageName (), p .module ());
298
328
}
299
-
300
- /**
301
- * Written as a replacement for the auxiliary class {@link CompoundEnumeration}
302
- */
303
- final class EnumerationAdapter <E > implements Enumeration <E > {
304
- private final Iterator <E > iterator ;
305
-
306
- public EnumerationAdapter (Collection <E > collection ) {
307
- iterator = collection .iterator ();
308
- }
309
-
310
- @ Override
311
- public boolean hasMoreElements () {
312
- return iterator .hasNext ();
313
- }
314
-
315
- @ Override
316
- public E nextElement () {
317
- return iterator .next ();
318
- }
319
- }
320
329
321
-
322
330
Package definePackage (Class <?> c ) {
323
331
if (c .isPrimitive () || c .isArray ()) {
324
332
return null ;
325
333
}
326
334
327
335
return definePackage (c .getPackageName (), c .getModule ());
328
336
}
329
-
330
- //public native final Package getDefinedPackage(final String name);
331
-
332
- public final Package getDefinedPackage (String name ) {
333
- System .out .println (name );
334
- Objects .requireNonNull (name , "name cannot be null" );
335
-
336
- NamedPackage p = packages .get (name );
337
- System .out .println (p .packageName ());
338
- if (p == null )
339
- return null ;
340
-
341
- return definePackage (name , p .module ());
342
- }
343
- public final Module getModule (String name ){
344
-
345
- NamedPackage p = packages .get (name );
346
- return p .module ();
347
-
348
- };
349
- //public native final Package[] getDefinedPackages();
350
-
351
- public final Package [] getDefinedPackages () {
352
- return packages ().toArray (Package []::new );
353
- }
354
-
355
- Stream <Package > packages () {
356
- return packages .values ().stream ()
357
- .map (p -> definePackage (p .packageName (), p .module ()));
358
- }
359
-
360
337
}
361
338
0 commit comments