/** * {@inheritDoc} */ public String getName() { return packageDescription.getName() + "." + PackageDescription.PACKAGE_CLASS_NAME; }
@Override public boolean equals(Object other) { return this == other || other instanceof PackageDescription && getName().equals(((PackageDescription) other).getName()); }
/** * {@inheritDoc} */ public Map<String, Class<?>> injectRaw(Map<? extends String, byte[]> types) { String expectedPackage = TypeDescription.ForLoadedType.of(lookupType()).getPackage().getName(); Map<String, Class<?>> result = new HashMap<String, Class<?>>(); for (Map.Entry<? extends String, byte[]> entry : types.entrySet()) { int index = entry.getKey().lastIndexOf('.'); if (!expectedPackage.equals(index == -1 ? "" : entry.getKey().substring(0, index))) { throw new IllegalArgumentException(entry.getKey() + " must be defined in the same package as " + lookup); } result.put(entry.getKey(), DISPATCHER.defineClass(lookup, entry.getValue())); } return result; }
/** * Append a package specifier * * @param pakkage Package specifier to append * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendPackageSpecifier(PackageDescription pakkage, A output) { try { output.append(pakkage.getName().replace('.', '/')); output.append('/'); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not package specifier %s", pakkage)); } }
/** * Append a package specifier * * @param pakkage Package specifier to append * @param output Output to append to * @param <A> Type of output * @return Supplied output to append to */ public <A extends Appendable> A appendPackageSpecifier(PackageDescription pakkage, A output) { try { output.append(pakkage.getName().replace('.', '/')); output.append('/'); return output; } catch (Exception e) { throw new RuntimeException(String.format("Could not package specifier %s", pakkage)); } }
if (!pakkage.getName().isEmpty()) { appendPackageSpecifier(pakkage, output);
if (!pakkage.getName().isEmpty()) { appendPackageSpecifier(pakkage, output);
@Test void testIncludedPackages() { final TypeDescription thisClass = TypeDescription.ForLoadedType.of(getClass()); assertThat(isInAnyPackage(List.of(), none()).matches(thisClass)).isFalse(); assertThat(isInAnyPackage(List.of(thisClass.getPackage().getName()), none()).matches(thisClass)).isTrue(); assertThat(isInAnyPackage(List.of(thisClass.getPackage().getName()), none()).matches(TypeDescription.ForLoadedType.of(Object.class))).isFalse(); }