Skip to content

Commit

Permalink
fix: cleanup @BetaApi from Resource Name Builder Methods (#2450)
Browse files Browse the repository at this point in the history
fixes #2099
  • Loading branch information
zhumin8 authored and lqiu96 committed Feb 26, 2024
1 parent 8915733 commit fac2738
Show file tree
Hide file tree
Showing 14 changed files with 1 addition and 218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.google.api.generator.gapic.composer.resourcename;

import com.google.api.core.BetaApi;
import com.google.api.generator.engine.ast.AnnotationNode;
import com.google.api.generator.engine.ast.AssignmentExpr;
import com.google.api.generator.engine.ast.AssignmentOperationExpr;
Expand Down Expand Up @@ -60,7 +59,6 @@
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -503,13 +501,6 @@ private static List<MethodDefinition> createBuilderCreatorMethods(
ResourceName resourceName, List<List<String>> tokenHierarchies, TypeStore typeStore) {
List<MethodDefinition> javaMethods = new ArrayList<>();
String newMethodNameFormat = "new%s";
AnnotationNode betaAnnotation =
AnnotationNode.builder()
.setType(FIXED_TYPESTORE.get("BetaApi"))
.setDescription(
"The per-pattern Builders are not stable yet and may be changed in the future.")
.build();
List<AnnotationNode> annotations = Arrays.asList(betaAnnotation);

// Create the newBuilder and variation methods here.
// Variation example: newProjectLocationAutoscalingPolicyBuilder().
Expand All @@ -533,17 +524,13 @@ private static List<MethodDefinition> createBuilderCreatorMethods(

String variantName = getBuilderTypeName(tokenHierarchies, i);
javaMethods.add(
methodDefStarterFn
.apply(String.format(newMethodNameFormat, variantName))
.setAnnotations(i == 0 ? Collections.emptyList() : annotations)
.build());
methodDefStarterFn.apply(String.format(newMethodNameFormat, variantName)).build());
if (i == 0 && tokenHierarchies.size() > 1) {
// Create another builder creator method, but with the per-variant name.
javaMethods.add(
methodDefStarterFn
.apply(
String.format(newMethodNameFormat, getBuilderTypeName(tokenHierarchies.get(i))))
.setAnnotations(annotations)
.build());
}
}
Expand Down Expand Up @@ -597,15 +584,6 @@ private static List<MethodDefinition> createOfOrFormatMethodHelper(
String setMethodNameFormat = "set%s";
String buildMethodName = "build";
String toStringMethodName = "toString";
AnnotationNode betaAnnotation =
AnnotationNode.builder()
.setType(FIXED_TYPESTORE.get("BetaApi"))
.setDescription(
String.format(
"The static %s methods are not stable yet and may be changed in the future.",
isFormatMethod ? "format" : "create"))
.build();
List<AnnotationNode> annotations = Arrays.asList(betaAnnotation);

TypeNode thisClassType = typeStore.get(getThisClassName(resourceName));
TypeNode returnType = isFormatMethod ? TypeNode.STRING : thisClassType;
Expand All @@ -624,7 +602,6 @@ private static List<MethodDefinition> createOfOrFormatMethodHelper(
MethodDefinition.builder()
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
.setAnnotations(annotations)
.setReturnType(returnType)
.setName(
String.format(methodNameFormat, concatToUpperCamelCaseName(tokens) + "Name"))
Expand Down Expand Up @@ -682,7 +659,6 @@ private static List<MethodDefinition> createOfOrFormatMethodHelper(
MethodDefinition.builder()
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
.setAnnotations(i == 0 ? Collections.emptyList() : annotations)
.setReturnType(returnType)
.setName(
String.format(
Expand All @@ -696,7 +672,6 @@ private static List<MethodDefinition> createOfOrFormatMethodHelper(
MethodDefinition.builder()
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
.setAnnotations(annotations)
.setReturnType(returnType)
.setName(
String.format(
Expand Down Expand Up @@ -1701,21 +1676,12 @@ private static ClassDefinition createNestedBuilderClass(
nestedClassMethods.add(buildMethod);

// Return the class.
AnnotationNode betaAnnotation =
AnnotationNode.builder()
.setType(FIXED_TYPESTORE.get("BetaApi"))
.setDescription(
"The per-pattern Builders are not stable yet and may be changed in the future.")
.build();
List<AnnotationNode> classAnnotations =
isDefaultClass ? Collections.emptyList() : Arrays.asList(betaAnnotation);

return ClassDefinition.builder()
.setHeaderCommentStatements(
CommentStatement.withComment(
JavaDocComment.withComment(
String.format(BUILDER_CLASS_HEADER_PATTERN, resourceNamePattern))))
.setAnnotations(classAnnotations)
.setIsNested(true)
.setScope(ScopeNode.PUBLIC)
.setIsStatic(true)
Expand All @@ -1729,7 +1695,6 @@ private static TypeStore createStaticTypes() {
List<Class<?>> concreteClazzes =
Arrays.asList(
ArrayList.class,
BetaApi.class,
Generated.class,
ImmutableMap.class,
List.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.google.cloud.dialogflow.v2beta1;

import com.google.api.core.BetaApi;
import com.google.api.pathtemplate.PathTemplate;
import com.google.api.pathtemplate.ValidationException;
import com.google.api.resourcenames.ResourceName;
Expand Down Expand Up @@ -55,12 +54,10 @@ public class AgentName implements ResourceName {
return new Builder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static Builder newProjectLocationBuilder() {
return new Builder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static ProjectBuilder newProjectBuilder() {
return new ProjectBuilder();
}
Expand All @@ -73,12 +70,10 @@ public class AgentName implements ResourceName {
return newBuilder().setProject(project).setLocation(location).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static AgentName ofProjectLocationName(String project, String location) {
return newBuilder().setProject(project).setLocation(location).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static AgentName ofProjectName(String project) {
return newProjectBuilder().setProject(project).build();
}
Expand All @@ -87,12 +82,10 @@ public class AgentName implements ResourceName {
return newBuilder().setProject(project).setLocation(location).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectLocationName(String project, String location) {
return newBuilder().setProject(project).setLocation(location).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectName(String project) {
return newProjectBuilder().setProject(project).build().toString();
}
Expand Down Expand Up @@ -227,7 +220,6 @@ public class AgentName implements ResourceName {
}

/** Builder for projects/{project}/agent. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class ProjectBuilder {
private String project;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.google.showcase.v1beta1;

import com.google.api.core.BetaApi;
import com.google.api.pathtemplate.PathTemplate;
import com.google.api.pathtemplate.ValidationException;
import com.google.api.resourcenames.ResourceName;
Expand Down Expand Up @@ -92,22 +91,18 @@ public class FoobarName implements ResourceName {
return new Builder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static Builder newProjectFoobarBuilder() {
return new Builder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static ProjectVariantFoobarBuilder newProjectVariantFoobarBuilder() {
return new ProjectVariantFoobarBuilder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static FoobarBuilder newFoobarBuilder() {
return new FoobarBuilder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static BarFooFoobarBuilder newBarFooFoobarBuilder() {
return new BarFooFoobarBuilder();
}
Expand All @@ -120,12 +115,10 @@ public class FoobarName implements ResourceName {
return newBuilder().setProject(project).setFoobar(foobar).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FoobarName ofProjectFoobarName(String project, String foobar) {
return newBuilder().setProject(project).setFoobar(foobar).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FoobarName ofProjectVariantFoobarName(
String project, String variant, String foobar) {
return newProjectVariantFoobarBuilder()
Expand All @@ -135,12 +128,10 @@ public class FoobarName implements ResourceName {
.build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FoobarName ofFoobarName(String foobar) {
return newFoobarBuilder().setFoobar(foobar).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FoobarName ofBarFooFoobarName(String barFoo, String foobar) {
return newBarFooFoobarBuilder().setBarFoo(barFoo).setFoobar(foobar).build();
}
Expand All @@ -149,12 +140,10 @@ public class FoobarName implements ResourceName {
return newBuilder().setProject(project).setFoobar(foobar).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectFoobarName(String project, String foobar) {
return newBuilder().setProject(project).setFoobar(foobar).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectVariantFoobarName(
String project, String variant, String foobar) {
return newProjectVariantFoobarBuilder()
Expand All @@ -165,12 +154,10 @@ public class FoobarName implements ResourceName {
.toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatFoobarName(String foobar) {
return newFoobarBuilder().setFoobar(foobar).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatBarFooFoobarName(String barFoo, String foobar) {
return newBarFooFoobarBuilder().setBarFoo(barFoo).setFoobar(foobar).build().toString();
}
Expand Down Expand Up @@ -327,7 +314,6 @@ public class FoobarName implements ResourceName {
}

/** Builder for projects/{project}/chocolate/variants/{variant}/foobars/{foobar}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class ProjectVariantFoobarBuilder {
private String project;
private String variant;
Expand Down Expand Up @@ -368,7 +354,6 @@ public class FoobarName implements ResourceName {
}

/** Builder for foobars/{foobar}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class FoobarBuilder {
private String foobar;

Expand All @@ -389,7 +374,6 @@ public class FoobarName implements ResourceName {
}

/** Builder for bar_foos/{bar_foo}/foobars/{foobar}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class BarFooFoobarBuilder {
private String barFoo;
private String foobar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.showcase.v1beta1;

import com.google.api.core.BetaApi;
import com.google.api.pathtemplate.PathTemplate;
import com.google.api.pathtemplate.ValidationException;
import com.google.api.resourcenames.ResourceName;
Expand Down Expand Up @@ -118,22 +117,18 @@ public static Builder newBuilder() {
return new Builder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static Builder newUserLegacyUserBlurbBuilder() {
return new Builder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static UserBlurbBuilder newUserBlurbBuilder() {
return new UserBlurbBuilder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static RoomBlurbBuilder newRoomBlurbBuilder() {
return new RoomBlurbBuilder();
}

@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static RoomLegacyRoomBlurbBuilder newRoomLegacyRoomBlurbBuilder() {
return new RoomLegacyRoomBlurbBuilder();
}
Expand All @@ -146,22 +141,18 @@ public static BlurbName of(String user, String legacyUser, String blurb) {
return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static BlurbName ofUserLegacyUserBlurbName(String user, String legacyUser, String blurb) {
return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static BlurbName ofUserBlurbName(String user, String blurb) {
return newUserBlurbBuilder().setUser(user).setBlurb(blurb).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static BlurbName ofRoomBlurbName(String room, String blurb) {
return newRoomBlurbBuilder().setRoom(room).setBlurb(blurb).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static BlurbName ofRoomLegacyRoomBlurbName(String room, String legacyRoom, String blurb) {
return newRoomLegacyRoomBlurbBuilder()
.setRoom(room)
Expand All @@ -174,22 +165,18 @@ public static String format(String user, String legacyUser, String blurb) {
return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatUserLegacyUserBlurbName(String user, String legacyUser, String blurb) {
return newBuilder().setUser(user).setLegacyUser(legacyUser).setBlurb(blurb).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatUserBlurbName(String user, String blurb) {
return newUserBlurbBuilder().setUser(user).setBlurb(blurb).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatRoomBlurbName(String room, String blurb) {
return newRoomBlurbBuilder().setRoom(room).setBlurb(blurb).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatRoomLegacyRoomBlurbName(String room, String legacyRoom, String blurb) {
return newRoomLegacyRoomBlurbBuilder()
.setRoom(room)
Expand Down Expand Up @@ -369,7 +356,6 @@ public BlurbName build() {
}

/** Builder for users/{user}/profile/blurbs/{blurb}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class UserBlurbBuilder {
private String user;
private String blurb;
Expand Down Expand Up @@ -400,7 +386,6 @@ public BlurbName build() {
}

/** Builder for rooms/{room}/blurbs/{blurb}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class RoomBlurbBuilder {
private String room;
private String blurb;
Expand Down Expand Up @@ -431,7 +416,6 @@ public BlurbName build() {
}

/** Builder for rooms/{room}/blurbs/legacy/{legacy_room}.{blurb}. */
@BetaApi("The per-pattern Builders are not stable yet and may be changed in the future.")
public static class RoomLegacyRoomBlurbBuilder {
private String room;
private String legacyRoom;
Expand Down
Loading

0 comments on commit fac2738

Please sign in to comment.