Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.javahelpers.codegen.enums.AccessModifier;
import org.javahelpers.codegen.model.annotation.AnnotationDto;
import org.javahelpers.codegen.model.javadoc.JavadocDto;
Expand Down Expand Up @@ -257,11 +256,7 @@ public String getSignatureKey() {
for (int i = 0; i < parameters.size(); i++) {
if (i > 0) sb.append(',');
TypeName tn = parameters.get(i).getParameterType();
// Handle null package names
if (StringUtils.isNoneBlank(tn.getPackageName())) {
sb.append(tn.getPackageName()).append('.');
}
sb.append(tn.getClassName());
sb.append(tn.getRawQualifiedName());
}
sb.append(')');
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@ public static void assertDiagnosticsHaveNoSourcePosition(
}
}

/**
* Asserts that no diagnostic message contains the given text.
*
* @param compilation the compilation result
* @param text text that must not occur in any diagnostic message
*/
public static void assertNoDiagnosticsContaining(Compilation compilation, String text) {
List<String> matching =
compilation.diagnostics().stream()
.map(d -> d.getMessage(null))
.filter(message -> message.contains(text))
.toList();
Assertions.assertTrue(
matching.isEmpty(),
"Expected no diagnostic containing '" + text + "', but found: " + matching);
}

/**
* Asserts that no generated source file for the given type exists in the compilation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ void assertDiagnosticsHaveNoSourcePosition_passesForElementLessWarnings() {
compilation, Diagnostic.Kind.WARNING, "floating warning");
}

@Test
void assertNoDiagnosticsContaining_checksAllDiagnostics() {
Compilation compilation =
compileWithDiagnostics(
(env, dto) ->
env.getMessager().printMessage(Diagnostic.Kind.WARNING, "floating warning"));

ProcessorAsserts.assertNoDiagnosticsContaining(compilation, "not emitted");
assertThrows(
AssertionError.class,
() -> ProcessorAsserts.assertNoDiagnosticsContaining(compilation, "floating warning"));
}

@Test
void assertNoSourceGenerated_failsWhenFileExists() {
Compilation compilation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.javahelpers.codegen.enums.AccessModifier;
import org.javahelpers.codegen.model.annotation.AnnotationDto;
import org.javahelpers.codegen.model.javadoc.JavadocCodeBlockDto;
Expand Down Expand Up @@ -383,11 +382,7 @@ public String getSignatureKey() {
for (int i = 0; i < parameters.size(); i++) {
if (i > 0) sb.append(',');
TypeName tn = parameters.get(i).getParameterType();
// Handle null package names
if (StringUtils.isNoneBlank(tn.getPackageName())) {
sb.append(tn.getPackageName()).append('.');
}
sb.append(tn.getClassName());
sb.append(tn.getRawQualifiedName());
}
sb.append(')');
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,8 @@ void shouldReportExistingParameterizedCollectionWarnings(String property) {
Compilation compilation = compileOwnerProperty(property);
assertThat(compilation).succeeded();
assertThat(compilation).hadWarningCount(1);
if (property.contains("java.util.List<java.util.List")) {
assertThat(compilation).hadWarningContaining("Method conflict resolved for signature");
} else {
assertThat(compilation)
.hadWarningContaining("Possible heap pollution from parameterized vararg type");
}
assertThat(compilation)
.hadWarningContaining("Possible heap pollution from parameterized vararg type");
}

private Compilation compileOwnerProperty(String property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,32 @@ public void setValue(java.util.function.Supplier<String> valueSupplier) {
d -> System.out.println("✓ Lower priority dropped correctly: " + d.getMessage(null)));
}

/**
* Array dimensions are part of the erased parameter type, so nested lists keep varargs helpers.
*/
@Test
void shouldKeepVarargsForNestedList() {
JavaFileObject sourceFile =
ProcessorTestUtils.simpleBuilderClass(
"test",
"NestedListDto",
"""
private java.util.List<java.util.List<String>> value;
public java.util.List<java.util.List<String>> getValue() { return value; }
public void setValue(java.util.List<java.util.List<String>> value) { this.value = value; }
""");

Compilation compilation = compile(sourceFile);

assertThat(compilation).succeeded();
String generatedCode = loadGeneratedSource(compilation, "NestedListDtoBuilder");
ProcessorAsserts.assertContaining(
generatedCode,
"public NestedListDtoBuilder value(List<List<String>> value)",
"public NestedListDtoBuilder value(List<String>... value)");
ProcessorAsserts.assertNoDiagnosticsContaining(compilation, "Method conflict resolved");
}

/**
* In verbose mode warnings must be emitted without element attachment — javac would otherwise
* prepend {@code File.java:[line,col]} mid-line and break the hierarchical layout. Instead the
Expand Down