/** * {@inheritDoc} */ public String getName() { return packageDescription.getName() + "." + PackageDescription.PACKAGE_CLASS_NAME; }
/** * {@inheritDoc} */ public AnnotationList getDeclaredAnnotations() { return packageDescription.getDeclaredAnnotations(); }
@Override public boolean equals(Object other) { return this == other || other instanceof PackageDescription && getName().equals(((PackageDescription) other).getName()); }
/** * @see me.seeber.gradle.ide.eclipse.annotations.Nullability#getParameterNullability(net.bytebuddy.description.method.ParameterDescription) */ @Override public Nullness getParameterNullability(ParameterDescription parameter) { PackageDescription pakkage = parameter.getDeclaringMethod().getDeclaringType().asErasure().getPackage(); Optional<AnnotationDescription> packageAnnotation = pakkage.getDeclaredAnnotations().stream() .filter(a -> a.getAnnotationType().getName().equals(this.nonnullParameterDefaultAnnotation)).findAny(); Nullness defaultNullness = Validate .notNull(packageAnnotation.map(a -> Nullness.NONNULL).orElse(Nullness.UNDEFINED)); Nullness nullability = getNullability(parameter.getDeclaredAnnotations()); return defaultNullness.override(nullability); }
/** * {@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; }
/** * @see me.seeber.gradle.ide.eclipse.annotations.Nullability#getParameterNullability(net.bytebuddy.description.method.ParameterDescription) */ @Override public Nullness getParameterNullability(ParameterDescription parameter) { PackageDescription pakkage = parameter.getDeclaringMethod().getDeclaringType().asErasure().getPackage(); Optional<AnnotationDescription> packageAnnotation = pakkage.getDeclaredAnnotations().stream() .filter(a -> a.getAnnotationType().getName().equals(this.nonnullParameterDefaultAnnotation)).findAny(); Nullness defaultNullness = Validate .notNull(packageAnnotation.map(a -> Nullness.NONNULL).orElse(Nullness.UNDEFINED)); Nullness nullability = getNullability(parameter.getDeclaredAnnotations()); return defaultNullness.override(nullability); }
/** * 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(); }