@@ -242,18 +242,11 @@ private static boolean isPackage(String packageName)
242242 Package p = Package .getPackage (packageName );
243243 if (p != null )
244244 return true ;
245- ArrayList <String > paths = new ArrayList <String >();
246- paths .add ("java/lang/String.class" );
247- for (String s : System .getProperty ("java.class.path" ).split (System .getProperty ("path.separator" )))
248- {
249- if (!paths .contains (s ))
250- paths .add (s );
251- }
252245
253246 packageName = packageName .replace ("." , "/" );
254247
255248 ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
256- for (String s : paths )
249+ for (String s : getClasspathEntries () )
257250 {
258251 URL url = classLoader .getResource (s + "/" + packageName );
259252 if (url != null )
@@ -322,7 +315,7 @@ private static void addToImportMap(String classFileName)
322315 }
323316 }
324317
325- protected static String [] getClasspathEntries ()
318+ private static String [] getClasspathEntries ()
326319 {
327320 Set <String > paths = new HashSet <String >();
328321 paths .add ("java/lang/String.class" );
@@ -333,7 +326,7 @@ protected static String[] getClasspathEntries()
333326 return paths .toArray (new String [0 ]);
334327 }
335328
336- protected static URL getUrlFromClasspathEntry (ClassLoader classLoader , String classpathEntry , String packagePath )
329+ private static URL getUrlFromClasspathEntry (ClassLoader classLoader , String classpathEntry , String packagePath )
337330 {
338331 URL url = null ;
339332 if (classpathEntry .endsWith (".class" ))
@@ -360,16 +353,31 @@ protected static URL getUrlFromClasspathEntry(ClassLoader classLoader, String cl
360353 return url ;
361354 }
362355
363- protected static void importClass (String classname )
356+ private static Set <File > getClassFilesNotInJar (File current )
357+ {
358+ Set <File > classFiles = new HashSet <File >();
359+ if (current .isFile () && current .getName ().endsWith (".class" ))
360+ {
361+ classFiles .add (current );
362+ }
363+ else if (current .isDirectory ())
364+ {
365+ for (File file : current .listFiles ())
366+ {
367+ classFiles .addAll (getClassFilesNotInJar (file ));
368+ }
369+ }
370+ return classFiles ;
371+ }
372+
373+ private static void getPossibleImports (String classname )
364374 throws IOException
365375 {
366376 boolean importMapPopulated = importMap .size () > 0 ;
367377
368378 if (!importMapPopulated ) {
369- String [] paths = getClasspathEntries ();
370-
371379 ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
372- for (String s : paths )
380+ for (String s : getClasspathEntries () )
373381 {
374382 URL url = getUrlFromClasspathEntry (classLoader , s , "" );
375383 if (url == null )
@@ -406,37 +414,18 @@ protected static void importClass(String classname)
406414 {
407415 for (String impClass : possibleImports )
408416 {
409- System .out .println (impClass + " \t class" + sep + impClass );
417+ System .out .println (impClass );
410418 }
411419 }
412420 }
413421
414- protected static Set <File > getClassFilesNotInJar (File current )
415- {
416- Set <File > classFiles = new HashSet <File >();
417- if (current .isFile () && current .getName ().endsWith (".class" ))
418- {
419- classFiles .add (current );
420- }
421- else if (current .isDirectory ())
422- {
423- for (File file : current .listFiles ())
424- {
425- classFiles .addAll (getClassFilesNotInJar (file ));
426- }
427- }
428- return classFiles ;
429- }
430-
431- protected static void completePackage (String packageName )
422+ private static void completePackage (String packageName )
432423 throws IOException
433424 {
434- String [] paths = getClasspathEntries ();
435-
436425 String packagePath = packageName .replace ("." , "/" );
437426
438427 ClassLoader classLoader = Thread .currentThread ().getContextClassLoader ();
439- for (String s : paths )
428+ for (String s : getClasspathEntries () )
440429 {
441430 URL url = getUrlFromClasspathEntry (classLoader , s , packagePath );
442431 if (url == null )
@@ -528,9 +517,9 @@ public static void main(String... unusedargs)
528517 System .err .println ("quitting upon request" );
529518 return ;
530519 }
531- else if (args [0 ].equals ("-importclass " ))
520+ else if (args [0 ].equals ("-possibleimports " ))
532521 {
533- importClass (args [1 ]);
522+ getPossibleImports (args [1 ]);
534523 continue ;
535524 }
536525 else if (args [0 ].equals ("-findclass" ))
0 commit comments