Skip to content

Commit

Permalink
Implement getting inline specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto committed Jan 14, 2025
1 parent f3ef8c6 commit 6062279
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.TypeSpec;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;

public abstract class AbstractTypeGenerator extends AbstractFileGenerator {
Expand All @@ -33,15 +35,30 @@ public TypeSpec getTypeSpec() {
}

private List<TypeSpec> getInlineTypeSpecs() {
// if (generatorContext.getCustomConfig().enableInlineTypes()) {
// return List.of();
// }
//
// List<TypeDeclaration> declarations = getInlineTypeDeclarations();
// for (TypeDeclaration declaration : declarations) {
//
// }
return List.of();
if (generatorContext.getCustomConfig().enableInlineTypes()) {
return List.of();
}

List<TypeDeclaration> declarations = getInlineTypeDeclarations();
List<TypeSpec> result = new ArrayList<>();
for (TypeDeclaration declaration : declarations) {
Optional<AbstractTypeGenerator> generator = declaration
.getShape()
.visit(new SingleTypeGenerator(
generatorContext,
declaration.getName(),
className.nestedClass(declaration
.getName()
.getName()
.getPascalCase()
.getSafeName()),
TypesGenerator.getGeneratedInterfaces(generatorContext),
false,
reservedTypeNames));
generator.map(AbstractTypeGenerator::getTypeSpec).ifPresent(result::add);
}

return result;
}

protected String resolveName(String rawName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public TypesGenerator(AbstractGeneratorContext<?, ?> generatorContext) {
}

public Result generateFiles() {
Map<TypeId, GeneratedJavaInterface> generatedInterfaces = getGeneratedInterfaces();
Map<TypeId, GeneratedJavaInterface> generatedInterfaces = getGeneratedInterfaces(generatorContext);
Map<TypeId, GeneratedJavaFile> generatedTypes = KeyedStream.stream(typeDeclarations)
.map(typeDeclaration -> {
ClassName className =
Expand All @@ -65,10 +65,12 @@ public Result generateFiles() {
return new Result(generatedInterfaces, generatedTypes);
}

private Map<TypeId, GeneratedJavaInterface> getGeneratedInterfaces() {
public static Map<TypeId, GeneratedJavaInterface> getGeneratedInterfaces(
AbstractGeneratorContext<?, ?> generatorContext) {
Set<TypeId> interfaceCandidates = generatorContext.getInterfaceIds();
return interfaceCandidates.stream().collect(Collectors.toMap(Function.identity(), typeId -> {
TypeDeclaration typeDeclaration = typeDeclarations.get(typeId);
TypeDeclaration typeDeclaration =
generatorContext.getTypeDeclarations().get(typeId);
ObjectTypeDeclaration objectTypeDeclaration = typeDeclaration
.getShape()
.getObject()
Expand Down

0 comments on commit 6062279

Please sign in to comment.