Skip to content

Commit

Permalink
seperate defalt value related files and same to resource name (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
summer-ji-eng authored Jan 6, 2021
1 parent c785470 commit 2085654
Show file tree
Hide file tree
Showing 29 changed files with 197 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ java_library(
"//src/main/java/com/google/api/generator/engine/writer",
"//src/main/java/com/google/api/generator/gapic:status_java_proto",
"//src/main/java/com/google/api/generator/gapic/composer/comment",
"//src/main/java/com/google/api/generator/gapic/composer/defaultvalue",
"//src/main/java/com/google/api/generator/gapic/composer/resourcename",
"//src/main/java/com/google/api/generator/gapic/composer/samplecode",
"//src/main/java/com/google/api/generator/gapic/composer/store",
"//src/main/java/com/google/api/generator/gapic/composer/utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.ScopeNode;
import com.google.api.generator.gapic.composer.comment.CommentComposer;
import com.google.api.generator.gapic.composer.resourcename.ResourceNameHelperClassComposer;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.gapic.model.GapicContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import com.google.api.generator.engine.ast.VaporReference;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.defaultvalue.DefaultValueComposer;
import com.google.api.generator.gapic.composer.store.TypeStore;
import com.google.api.generator.gapic.composer.utils.ClassNames;
import com.google.api.generator.gapic.model.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "defaultvalue_files",
srcs = glob(["*.java"]),
)

java_library(
name = "defaultvalue",
srcs = [
":defaultvalue_files",
],
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/gapic/composer/resourcename",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/utils",
"@com_google_googleapis//google/longrunning:longrunning_java_proto",
"@com_google_guava_guava//jar",
"@com_google_protobuf//java/core",
"@google_java_format_all_deps//jar",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

import com.google.api.generator.engine.ast.ConcreteReference;
import com.google.api.generator.engine.ast.Expr;
Expand All @@ -24,6 +24,7 @@
import com.google.api.generator.engine.ast.ValueExpr;
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.gapic.composer.resourcename.ResourceNameTokenizer;
import com.google.api.generator.gapic.model.Field;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.MethodArgument;
Expand All @@ -49,7 +50,7 @@ public class DefaultValueComposer {
private static TypeNode BYTESTRING_TYPE =
TypeNode.withReference(ConcreteReference.withClazz(ByteString.class));

static Expr createDefaultValue(
public static Expr createDefaultValue(
MethodArgument methodArg, Map<String, ResourceName> resourceNames) {
if (methodArg.isResourceNameHelper()) {
Preconditions.checkState(
Expand Down Expand Up @@ -78,7 +79,7 @@ static Expr createDefaultValue(
Field.builder().setName(methodArg.name()).setType(methodArg.type()).build());
}

static Expr createDefaultValue(Field f) {
public static Expr createDefaultValue(Field f) {
return createDefaultValue(f, false);
}

Expand Down Expand Up @@ -154,7 +155,7 @@ static Expr createDefaultValue(Field f, boolean useExplicitInitTypeInGenerics) {
"Default value for field %s with type %s not implemented yet.", f.name(), f.type()));
}

static Expr createDefaultValue(
public static Expr createDefaultValue(
ResourceName resourceName, List<ResourceName> resnames, String fieldOrMessageName) {
boolean hasOnePattern = resourceName.patterns().size() == 1;
if (resourceName.isOnlyWildcard()) {
Expand Down Expand Up @@ -224,7 +225,7 @@ static Expr createDefaultValue(
.build();
}

static Expr createSimpleMessageBuilderExpr(
public static Expr createSimpleMessageBuilderExpr(
Message message, Map<String, ResourceName> resourceNames, Map<String, Message> messageTypes) {
MethodInvocationExpr builderExpr =
MethodInvocationExpr.builder()
Expand Down Expand Up @@ -275,7 +276,7 @@ static Expr createSimpleMessageBuilderExpr(
.build();
}

static Expr createSimpleOperationBuilderExpr(String name, VariableExpr responseExpr) {
public static Expr createSimpleOperationBuilderExpr(String name, VariableExpr responseExpr) {
Expr operationExpr =
MethodInvocationExpr.builder()
.setStaticReferenceType(OPERATION_TYPE)
Expand Down Expand Up @@ -313,7 +314,7 @@ static Expr createSimpleOperationBuilderExpr(String name, VariableExpr responseE
.build();
}

static Expr createSimplePagedResponse(
public static Expr createSimplePagedResponse(
TypeNode responseType, String repeatedFieldName, Expr responseElementVarExpr) {
Expr pagedResponseExpr =
MethodInvocationExpr.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "resourcename_files",
srcs = glob(["*.java"]),
)

java_library(
name = "resourcename",
srcs = [
":resourcename_files",
],
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/gapic/composer/comment",
"//src/main/java/com/google/api/generator/gapic/composer/store",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/utils",
"@com_google_api_api_common",
"@com_google_guava_guava",
"@javax_annotation_javax_annotation_api",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

import com.google.api.core.BetaApi;
import com.google.api.generator.engine.ast.AnnotationNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

import com.google.api.pathtemplate.PathTemplate;
import com.google.common.base.Preconditions;
Expand All @@ -32,7 +32,7 @@ public class ResourceNameTokenizer {

private static final String NON_SLASH_SEP_REGEX = "\\}(_|\\-|\\.|~)\\{";

static List<List<String>> parseTokenHierarchy(List<String> patterns) {
public static List<List<String>> parseTokenHierarchy(List<String> patterns) {
List<List<String>> tokenHierachies = new ArrayList<>();
for (String pattern : patterns) {
List<String> hierarchy = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ filegroup(
"//src/test/java/com/google/api/generator/testutils",
"@com_google_guava_guava//jar",
"@com_google_truth_truth//jar",
"@javax_annotation_javax_annotation_api",
"@junit_junit//jar",
],
) for test_name in TESTS]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ UPDATE_GOLDENS_TESTS = [
"GrpcServiceStubClassComposerTest",
"MockServiceClassComposerTest",
"MockServiceImplClassComposerTest",
"ResourceNameHelperClassComposerTest",
"ServiceClientClassComposerTest",
"ServiceClientTestClassComposerTest",
"ServiceSettingsClassComposerTest",
Expand All @@ -19,8 +18,6 @@ UPDATE_GOLDENS_TESTS = [
]

TESTS = UPDATE_GOLDENS_TESTS + [
"DefaultValueComposerTest",
"ResourceNameTokenizerTest",
"RetrySettingsComposerTest",
]

Expand All @@ -36,8 +33,10 @@ TEST_DEPS = [
"//src/test/java/com/google/api/generator/testutils",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/protoparser",
"//src/main/java/com/google/api/generator/gapic/composer/defaultvalue",
"//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto",
"//src/test/java/com/google/api/generator/gapic/testdata:testgapic_java_proto",
"//src/test/java/com/google/api/generator/gapic/composer/constants",
"@com_google_api_gax_java//gax",
"@com_google_googleapis//google/logging/v2:logging_java_proto",
"@com_google_googleapis//google/pubsub/v1:pubsub_java_proto",
Expand Down Expand Up @@ -71,7 +70,6 @@ java_proto_library(
name = test_name,
srcs = [
"{0}.java".format(test_name),
"ComposerConstants.java",
],
data = [
"//src/test/java/com/google/api/generator/gapic/composer/goldens:goldens_files",
Expand All @@ -91,7 +89,6 @@ TEST_CLASS_DIR = "com.google.api.generator.gapic.composer."
name = "{0}_update".format(test_name),
srcs = [
"{0}.java".format(test_name),
"ComposerConstants.java",
],
data = [
"//src/test/java/com/google/api/generator/gapic/composer/goldens:goldens_files",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import com.google.api.generator.engine.ast.Expr;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicBatchingSettings;
import com.google.api.generator.gapic.model.GapicServiceConfig;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.api.generator.engine.ast.ClassDefinition;
import com.google.api.generator.engine.ast.ScopeNode;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.test.framework.Assert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.api.generator.engine.ast.Variable;
import com.google.api.generator.engine.ast.VariableExpr;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicBatchingSettings;
import com.google.api.generator.gapic.model.GapicServiceConfig;
import com.google.api.generator.gapic.model.Message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import static junit.framework.Assert.assertEquals;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static junit.framework.Assert.assertTrue;

import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.gapic.composer.constants.ComposerConstants;
import com.google.api.generator.gapic.model.GapicBatchingSettings;
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicServiceConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@rules_java//java:defs.bzl", "java_library")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "constants_files",
srcs = glob(["*.java"]),
)

java_binary(
name = "constants",
srcs = ["constants_files"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

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

public class ComposerConstants {
public static final String GOLDENFILES_DIRECTORY =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
load("@rules_java//java:defs.bzl", "java_test")

package(default_visibility = ["//visibility:public"])

TESTS = [
"DefaultValueComposerTest",
]

filegroup(
name = "defaultvalue_files",
srcs = ["{0}.java".format(f) for f in TESTS],
)

[java_test(
name = test_name,
srcs = ["{0}.java".format(test_name)],
test_class = "com.google.api.generator.gapic.composer.defaultvalue.{0}".format(test_name),
deps = [
":common_resources_java_proto",
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/engine/writer",
"//src/main/java/com/google/api/generator/gapic/composer/defaultvalue",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/protoparser",
"//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto",
"//src/test/java/com/google/api/generator/gapic/testdata:testgapic_java_proto",
"//src/test/java/com/google/api/generator/test/framework:asserts",
"//src/test/java/com/google/api/generator/test/framework:utils",
"//src/test/java/com/google/api/generator/testutils",
"@com_google_api_api_common//jar",
"@com_google_api_gax_java//gax",
"@com_google_googleapis//google/rpc:rpc_java_proto",
"@com_google_guava_guava",
"@com_google_protobuf//:protobuf_java",
"@com_google_truth_truth//jar",
"@junit_junit//jar",
],
) for test_name in TESTS]

java_proto_library(
name = "common_resources_java_proto",
deps = [
"@com_google_googleapis//google/cloud:common_resources_proto",
],
)
Loading

0 comments on commit 2085654

Please sign in to comment.