List of usage examples for com.google.common.reflect Reflection getPackageName
public static String getPackageName(String classFullName)
From source file:de.mineformers.gui.api.loader.UILoader.java
public static void loadDefaultAliases() { if (aliases == null) aliases = new HashMap<String, Class<? extends UIComponent>>(); if (aliases.isEmpty()) try {/*from w w w .j ava2s . co m*/ String currentPackage = Reflection.getPackageName(UILoader.class); ImmutableSet<ClassPath.ClassInfo> classes = ClassPath.from(UILoader.class.getClassLoader()) .getTopLevelClassesRecursive( currentPackage.substring(0, currentPackage.lastIndexOf(".")) + ".component"); for (ClassPath.ClassInfo clazz : classes) { if (!clazz.getName().endsWith("UIComponent")) { addAlias(clazz.getSimpleName(), (Class<? extends UIComponent>) Class.forName(clazz.getName())); } } } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.glowroot.weaving.IsolatedWeavingClassLoader.java
public Class<?> weaveAndDefineClass(String name, byte[] bytes) { byte[] wovenBytes = weaveClass(name, bytes); String packageName = Reflection.getPackageName(name); if (getPackage(packageName) == null) { definePackage(packageName, null, null, null, null, null, null, null); }//from w w w. j a va2 s. c o m return super.defineClass(name, wovenBytes, 0, wovenBytes.length); }
From source file:org.glowroot.agent.weaving.IsolatedWeavingClassLoader.java
public Class<?> weaveAndDefineClass(String name, byte[] bytes, @Nullable CodeSource codeSource) { byte[] wovenBytes = weaveClass(name, bytes); String packageName = Reflection.getPackageName(name); if (!packages.containsKey(packageName)) { Method getDefinedPackageMethod; try {// ww w . j a v a 2 s. c om getDefinedPackageMethod = getClass().getMethod("getDefinedPackage", String.class); } catch (NoSuchMethodException e) { getDefinedPackageMethod = null; } Package pkg; if (getDefinedPackageMethod == null) { pkg = definePackage(packageName, null, null, null, null, null, null, null); } else { // Java 9 try { pkg = (Package) getDefinedPackageMethod.invoke(this, packageName); if (pkg == null) { pkg = definePackage(packageName, null, null, null, null, null, null, null); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } packages.put(packageName, pkg); } if (codeSource == null) { return super.defineClass(name, wovenBytes, 0, wovenBytes.length); } else { ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null); return super.defineClass(name, wovenBytes, 0, wovenBytes.length, protectionDomain); } }