-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
120 additions
and
2 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
58 changes: 58 additions & 0 deletions
58
generator/src/main/java/org/sudu/protogen/descriptors/OneOf.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,58 @@ | ||
package org.sudu.protogen.descriptors; | ||
|
||
import com.google.protobuf.Descriptors; | ||
import com.squareup.javapoet.ClassName; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.sudu.protogen.config.naming.NamingManager; | ||
import org.sudu.protogen.utils.Name; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class OneOf implements Descriptor { | ||
|
||
private final Descriptors.OneofDescriptor oneofDescriptor; | ||
|
||
private final Message parent; | ||
|
||
public OneOf(Descriptors.OneofDescriptor oneofDescriptor, Message parent) { | ||
this.oneofDescriptor = oneofDescriptor; | ||
this.parent = parent; | ||
} | ||
|
||
@NotNull | ||
public String getName() { | ||
return oneofDescriptor.getName(); | ||
} | ||
|
||
@NotNull | ||
public List<String> getFieldsCases() { | ||
return oneofDescriptor.getFields().stream() | ||
.map(Descriptors.FieldDescriptor::getName) | ||
.map(String::toUpperCase) | ||
.toList(); | ||
} | ||
|
||
public ClassName getProtobufTypeName() { | ||
ClassName parentClass = parent.getProtobufTypeName(); | ||
return ClassName.get(parentClass.packageName(), parentClass.simpleName(), Name.toCamelCase(getName()) + "Case"); | ||
} | ||
|
||
public ClassName getDomainTypeName(NamingManager namingManager) { | ||
ClassName parentClass = parent.getDomainTypeName(namingManager); | ||
return ClassName.get(parentClass.packageName(), parentClass.simpleName(), Name.toCamelCase(getName()) + "Case"); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
OneOf oneOf = (OneOf) o; | ||
return Objects.equals(oneofDescriptor, oneOf.oneofDescriptor) && Objects.equals(parent, oneOf.parent); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(oneofDescriptor, parent); | ||
} | ||
} |
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