Skip to content

Commit f6fb292

Browse files
authored
Fix interface injection deduplication when all injected interfaces are already present (#58)
1 parent 322437c commit f6fb292

5 files changed

Lines changed: 24 additions & 0 deletions

File tree

interfaceinjection/src/main/java/net/neoforged/jst/interfaceinjection/InjectInterfacesVisitor.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ private void inject(PsiClass psiClass, Collection<String> targets) {
7979
.sorted(Comparator.naturalOrder())
8080
.collect(Collectors.joining(", "));
8181

82+
if (interfaceImplementation.isEmpty()) {
83+
return; // Nothing to do, all injected interfaces are already present
84+
}
85+
8286
if (implementsList.getChildren().length == 0) {
8387
StringBuilder text = new StringBuilder();
8488

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package pkg;
2+
3+
import java.util.Set;
4+
5+
public class Example implements Set {
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"pkg/Example": "java/util/Set"
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package pkg;
2+
3+
import java.util.Set;
4+
5+
public class Example implements Set {
6+
}

tests/src/test/java/net/neoforged/jst/tests/EmbeddedTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ void testSimpleInjection() throws Exception {
316316
runInterfaceInjectionTest("simple_injection", tempDir);
317317
}
318318

319+
@Test
320+
void testDeduplication() throws Exception {
321+
runInterfaceInjectionTest("deduplication", tempDir);
322+
}
323+
319324
@Test
320325
void testAdditiveInjection() throws Exception {
321326
runInterfaceInjectionTest("additive_injection", tempDir);

0 commit comments

Comments
 (0)