Skip to content

Commit

Permalink
Merge branch 'master' into release-v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
miraleung committed Apr 7, 2021
2 parents e6932f4 + c9a7e11 commit 5782c95
Show file tree
Hide file tree
Showing 49 changed files with 2,832 additions and 468 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ if [ $NUM_JAVA_FILES_CHANGED -gt 0 ]
then
echo_status "Checking Apache License Header ..."
header_check_preparation
addlicense -c "Google LLC" -l apache -check $(find $PWD -type f -name '*.java' ! -iname '*PlaceholderFile.java')
addlicense -c "Google LLC" -l apache -check $(find $PWD/src -type f -name '*.java' ! -iname '*PlaceholderFile.java')
CHECK_STATUS=$?
if [ $CHECK_STATUS != 0 ]
then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ public enum TypeKind {
public static final TypeNode STRING = withReference(ConcreteReference.withClazz(String.class));
public static final TypeNode VOID_OBJECT = withReference(ConcreteReference.withClazz(Void.class));

public static final TypeNode DEPRECATED =
withReference(ConcreteReference.withClazz(Deprecated.class));

public static final TypeNode STRING_ARRAY =
builder()
.setTypeKind(TypeKind.OBJECT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,18 @@ private UnaryOperationExpr build() {
TypeNode exprType = unaryOperationExpr.expr().type();
OperatorKind operator = unaryOperationExpr.operatorKind();

// TODO: (summerji) Add Decl Check for variable.
// Add final keyword checking for post/prefix ++, -- when needed.
if (operator.equals(OperatorKind.UNARY_POST_INCREMENT)
&& unaryOperationExpr.expr() instanceof VariableExpr) {
VariableExpr varExpr = (VariableExpr) unaryOperationExpr.expr();
Preconditions.checkState(
!((VariableExpr) unaryOperationExpr.expr()).isFinal(),
!varExpr.isFinal(),
String.format("Cannot increment the final variable '%s'.", varExpr.variable().name()));

Preconditions.checkState(
!varExpr.isDecl(),
String.format(
"Cannot assign a value to final variable '%s'.",
((VariableExpr) unaryOperationExpr.expr()).variable().name()));
"Cannot increment the declaration of variable %s", varExpr.variable().name()));
}

final String errorMsg =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import java.util.regex.Pattern;

// TODO(miraleung): Refactor this out into int, bool, null, float, string literal classes.
public class Literal {
private static final String BOOLEAN_TRUE = "true";
private static final String BOOLEAN_FALSE = "false";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public GapicClass generate(GapicContext ignored, Service service) {
.setPackageString(pakkage)
.setHeaderCommentStatements(
StubCommentComposer.createGrpcServiceCallableFactoryClassHeaderComments(
service.name()))
.setAnnotations(createClassAnnotations(service.pakkage(), typeStore))
service.name(), service.isDeprecated()))
.setAnnotations(createClassAnnotations(service, typeStore))
.setImplementsTypes(createClassImplements(typeStore))
.setName(className)
.setMethods(createClassMethods(typeStore))
Expand All @@ -87,11 +87,16 @@ public GapicClass generate(GapicContext ignored, Service service) {
return GapicClass.create(kind, classDef);
}

private static List<AnnotationNode> createClassAnnotations(String pakkage, TypeStore typeStore) {
private static List<AnnotationNode> createClassAnnotations(Service service, TypeStore typeStore) {
List<AnnotationNode> annotations = new ArrayList<>();
if (!PackageChecker.isGaApi(pakkage)) {
if (!PackageChecker.isGaApi(service.pakkage())) {
annotations.add(AnnotationNode.withType(typeStore.get("BetaApi")));
}

if (service.isDeprecated()) {
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
}

annotations.add(
AnnotationNode.builder()
.setType(typeStore.get("Generated"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ public GapicClass generate(GapicContext ignored, Service service) {
ClassDefinition.builder()
.setPackageString(pakkage)
.setHeaderCommentStatements(
StubCommentComposer.createGrpcServiceStubClassHeaderComments(service.name()))
.setAnnotations(createClassAnnotations(service.pakkage()))
StubCommentComposer.createGrpcServiceStubClassHeaderComments(
service.name(), service.isDeprecated()))
.setAnnotations(createClassAnnotations(service))
.setScope(ScopeNode.PUBLIC)
.setName(className)
.setExtendsType(typeStore.get(ClassNames.getServiceStubClassName(service)))
Expand Down Expand Up @@ -387,11 +388,16 @@ private static Map<String, VariableExpr> createCallableClassMembers(
return callableClassMembers;
}

private static List<AnnotationNode> createClassAnnotations(String pakkage) {
private static List<AnnotationNode> createClassAnnotations(Service service) {
List<AnnotationNode> annotations = new ArrayList<>();
if (!PackageChecker.isGaApi(pakkage)) {
if (!PackageChecker.isGaApi(service.pakkage())) {
annotations.add(AnnotationNode.withType(FIXED_TYPESTORE.get("BetaApi")));
}

if (service.isDeprecated()) {
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
}

annotations.add(
AnnotationNode.builder()
.setType(FIXED_TYPESTORE.get("Generated"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public GapicClass generate(GapicContext context, Service service) {
.setHeaderCommentStatements(
createClassHeaderComments(service, typeStore, resourceNames, messageTypes))
.setPackageString(pakkage)
.setAnnotations(createClassAnnotations(pakkage, typeStore))
.setAnnotations(createClassAnnotations(service, typeStore))
.setScope(ScopeNode.PUBLIC)
.setName(className)
.setImplementsTypes(createClassImplements(typeStore))
Expand All @@ -158,11 +158,14 @@ public GapicClass generate(GapicContext context, Service service) {
return GapicClass.create(kind, classDef);
}

private static List<AnnotationNode> createClassAnnotations(String pakkage, TypeStore typeStore) {
private static List<AnnotationNode> createClassAnnotations(Service service, TypeStore typeStore) {
List<AnnotationNode> annotations = new ArrayList<>();
if (!PackageChecker.isGaApi(pakkage)) {
if (!PackageChecker.isGaApi(service.pakkage())) {
annotations.add(AnnotationNode.withType(typeStore.get("BetaApi")));
}
if (service.isDeprecated()) {
annotations.add(AnnotationNode.withType(TypeNode.DEPRECATED));
}
annotations.add(
AnnotationNode.builder()
.setType(typeStore.get("Generated"))
Expand Down Expand Up @@ -544,6 +547,8 @@ private static List<MethodDefinition> createServiceMethods(
messageTypes,
typeStore,
resourceNames);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata
.get(method.name())
.addAll(
Expand All @@ -559,23 +564,31 @@ private static List<MethodDefinition> createServiceMethods(
messageTypes,
typeStore,
resourceNames);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata.get(method.name()).add(javaMethodNameFn.apply(generatedMethod));
javaMethods.add(generatedMethod);
}
if (method.hasLro()) {
MethodDefinition generatedMethod =
createLroCallableMethod(service, method, typeStore, messageTypes, resourceNames);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata.get(method.name()).add(javaMethodNameFn.apply(generatedMethod));
javaMethods.add(generatedMethod);
}
if (method.isPaged()) {
MethodDefinition generatedMethod =
createPagedCallableMethod(service, method, typeStore, messageTypes, resourceNames);

// Collect data for gapic_metadata.json.
grpcRpcToJavaMethodMetadata.get(method.name()).add(javaMethodNameFn.apply(generatedMethod));
javaMethods.add(generatedMethod);
}
MethodDefinition generatedMethod =
createCallableMethod(service, method, typeStore, messageTypes, resourceNames);

// Collect data for the gapic_metadata.json file.
grpcRpcToJavaMethodMetadata.get(method.name()).add(javaMethodNameFn.apply(generatedMethod));
javaMethods.add(generatedMethod);
}
Expand Down Expand Up @@ -670,6 +683,12 @@ private static List<MethodDefinition> createMethodVariants(
methodVariantBuilder =
methodVariantBuilder.setReturnType(methodOutputType).setReturnExpr(rpcInvocationExpr);
}

if (method.isDeprecated()) {
methodVariantBuilder =
methodVariantBuilder.setAnnotations(
Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)));
}
methodVariantBuilder = methodVariantBuilder.setBody(statements);
javaMethods.add(methodVariantBuilder.build());
}
Expand Down Expand Up @@ -739,6 +758,11 @@ private static MethodDefinition createMethodDefaultMethod(
.setName(String.format(method.hasLro() ? "%sAsync" : "%s", methodName))
.setArguments(Arrays.asList(requestArgVarExpr));

if (method.isDeprecated()) {
methodBuilder =
methodBuilder.setAnnotations(Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)));
}

if (isProtoEmptyType(methodOutputType)) {
methodBuilder =
methodBuilder
Expand Down Expand Up @@ -866,7 +890,14 @@ private static MethodDefinition createCallableMethod(
}
}

return MethodDefinition.builder()
MethodDefinition.Builder methodDefBuilder = MethodDefinition.builder();
if (method.isDeprecated()) {
methodDefBuilder =
methodDefBuilder.setAnnotations(
Arrays.asList(AnnotationNode.withType(TypeNode.DEPRECATED)));
}

return methodDefBuilder
.setHeaderCommentStatements(
ServiceClientCommentComposer.createRpcCallableMethodHeaderComment(
method, sampleCodeOpt))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,6 @@ private static MethodDefinition createStreamingRpcTestMethod(
* @param resourceNames the resource names available for use.
* @param messageTypes the proto message types available for use.
*/
// TODO(miraleung): Reorder params.
private static MethodDefinition createRpcExceptionTestMethod(
Method method,
Service service,
Expand Down
Loading

0 comments on commit 5782c95

Please sign in to comment.