package roxcdi.reflection;

import java.util.HashMap;

public class Package {

	static public String getName() {
		return getName(1) ;
	}
	
	static public String getName(int ignoreCallersLeves) {
		Throwable throwable = new Throwable() ;
		StackTraceElement[] stackTrace = throwable.getStackTrace() ;
		
		int idx = 1+ignoreCallersLeves ;
		if (idx >= stackTrace.length) idx = stackTrace.length-1 ;
		
		StackTraceElement stackTraceElement = stackTrace[idx] ;
		
		String className = stackTraceElement.getClassName() ;
		
		String packageName = extractClassNamePackage(className);
		return packageName ;
	}

	static private final HashMap<String, String> extractClassNamePackageCache = new HashMap<>() ;
	
	private static String extractClassNamePackage(String className) {
		String packageName ;
		
		synchronized (extractClassNamePackageCache) {
			packageName = extractClassNamePackageCache.get(className) ;
		}
		
		if (packageName != null) return packageName ;
		
		packageName = className.indexOf(".") < 0 ? "" : className.replaceFirst("\\.[^\\.]+$", "") ;
		
		synchronized (extractClassNamePackageCache) {
			extractClassNamePackageCache.put(className, packageName) ;
		}
		
		return packageName;
	}
	
	public static void main(String[] args) {
		
		System.out.println( getName() );
		
	}
	
}

@@ -550,27 +550,27 @@
 actClass
-Name
 Package
+Name
 (classNa
@@ -655,35 +655,36 @@
 extractClass
-Name
 Package
+Name_
 Cache = new 
@@ -701,22 +701,21 @@
 ) ;%0A%09%0A%09p
-rivate
+ublic
  static 
@@ -733,27 +733,27 @@
 actClass
-Name
 Package
+Name
 (String 
@@ -815,35 +815,36 @@
 extractClass
-Name
 Package
+Name_
 Cache) %7B%0A%09%09%09
@@ -865,35 +865,36 @@
 extractClass
-Name
 Package
+Name_
 Cache.get(cl
@@ -1083,35 +1083,36 @@
 extractClass
-Name
 Package
+Name_
 Cache) %7B%0A%09%09%09
@@ -1127,19 +1127,20 @@
 lass
-Name
 Package
+Name_
 Cach
@@ -1209,94 +1209,6 @@
 %7D%0A%09%0A
-%09public static void main(String%5B%5D args) %7B%0A%09%09%0A%09%09System.out.println( getName() );%0A%09%09%0A%09%7D%0A%09%0A
 %7D%0A

make public extractClassPackageName