-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Json support of non-final subtypes in sealed hierarchies (#117)
- Loading branch information
Showing
82 changed files
with
2,630 additions
and
1,918 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...sor-common/src/main/java/ru/tinkoff/kora/annotation/processor/common/SealedTypeUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ru.tinkoff.kora.annotation.processor.common; | ||
|
||
import javax.lang.model.element.Modifier; | ||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.util.Elements; | ||
import javax.lang.model.util.Types; | ||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
public class SealedTypeUtils { | ||
public static List<TypeElement> collectFinalPermittedSubtypes(Types types, Elements elements, TypeElement jsonElement) { | ||
var result = new ArrayList<TypeElement>(); | ||
var seen = new HashSet<String>(); | ||
var o = new Object() { | ||
void visit(TypeElement element) { | ||
if (element.getModifiers().contains(Modifier.SEALED)) { | ||
for (var permittedSubclass : element.getPermittedSubclasses()) { | ||
visit((TypeElement) types.asElement(permittedSubclass)); | ||
} | ||
} else { | ||
var packageElement = elements.getPackageOf(element).getQualifiedName().toString(); | ||
var name = element.getQualifiedName().toString(); | ||
var fullName = packageElement + "." + name; | ||
if (seen.add(fullName)) { | ||
result.add(element); | ||
} | ||
} | ||
} | ||
}; | ||
o.visit(jsonElement); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.