Skip to content

Commit

Permalink
feat: Do not expose Kind.Empty
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 committed Jan 11, 2023
1 parent ffa1265 commit 41ffc47
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected Transport getTransport() {
public GapicClass generate(GapicContext context, Service service) {
// Do not generate the Callable Factory if there are no RPCs enabled for the Transport
if (!service.hasAnyEnabledMethodsForTransport(getTransport())) {
return GapicClass.createEmpty();
return GapicClass.createNonGeneratedGapicClass();
}

TypeStore typeStore = createTypes(service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static TypeStore createStaticTypes() {
@Override
public GapicClass generate(GapicContext context, Service service) {
if (!service.hasAnyEnabledMethodsForTransport(getTransport())) {
return GapicClass.createEmpty();
return GapicClass.createNonGeneratedGapicClass();
}

String pakkage = service.pakkage() + ".stub";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public enum Kind {
MAIN,
STUB,
TEST,
PROTO,
EMPTY
PROTO
};

public abstract Kind kind();
Expand All @@ -43,20 +42,25 @@ public enum Kind {
// Only used for generating the region tag for samples; therefore only used in select Composers.
public abstract String apiVersion();

public abstract boolean shouldGenerateClass();

/**
* Create an empty GapicClass with minimal information. This is intended to be used for
* GapicClasses that will not generate any Java files
*
* @return Empty GapicClass
* @return Minimal GapicClass with setShouldGenerateClass set to False
*/
public static GapicClass createEmpty() {
return create(
Kind.EMPTY,
ClassDefinition.builder()
.setPackageString("Empty Package")
.setName("Empty Name")
.setScope(ScopeNode.PUBLIC)
.build());
public static GapicClass createNonGeneratedGapicClass() {
return builder()
.setKind(Kind.STUB)
.setClassDefinition(
ClassDefinition.builder()
.setPackageString("Empty Package")
.setName("Empty Name")
.setScope(ScopeNode.PUBLIC)
.build())
.setShouldGenerateClass(false)
.build();
}

public static GapicClass create(Kind kind, ClassDefinition classDefinition) {
Expand All @@ -72,7 +76,8 @@ static Builder builder() {
return new AutoValue_GapicClass.Builder()
.setSamples(Collections.emptyList())
.setApiShortName("")
.setApiVersion("");
.setApiVersion("")
.setShouldGenerateClass(true);
}

abstract Builder toBuilder();
Expand Down Expand Up @@ -101,6 +106,8 @@ abstract static class Builder {

abstract Builder setApiVersion(String apiVersion);

abstract Builder setShouldGenerateClass(boolean shouldGenerateClass);

abstract GapicClass build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static CodeGeneratorResponse write(
}

for (GapicClass gapicClazz : clazzes) {
if (gapicClazz.kind() == GapicClass.Kind.EMPTY) {
if (!gapicClazz.shouldGenerateClass()) {
continue;
}
String classPath = writeClazz(gapicClazz, codeWriter, jos);
Expand Down

0 comments on commit 41ffc47

Please sign in to comment.