Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,26 @@ public ClassDefinition build() {
for (Statement statement : classDef.statements()) {
// TODO(xiaozhenliu): Add CommentStatement check here.
Preconditions.checkState(
statement instanceof ExprStatement,
"Class statement type must be either an expression or comment statement");
Expr expr = ((ExprStatement) statement).expression();
if (expr instanceof VariableExpr) {
VariableExpr variableExpr = (VariableExpr) expr;
Preconditions.checkState(
variableExpr.isDecl(), "Class expression variable statements must be declarations");
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable statement cannot have a local scope");
} else {
Preconditions.checkState(
expr instanceof AssignmentExpr,
"Class expression statement must be assignment or variable declaration");
VariableExpr variableExpr = ((AssignmentExpr) expr).variableExpr();
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable in assignment statement cannot have a local scope");
statement instanceof ExprStatement || statement instanceof BlockStatement,
"Class statement type must be either an expression, block, or comment statement");
if (statement instanceof ExprStatement) {
Expr expr = ((ExprStatement) statement).expression();
if (expr instanceof VariableExpr) {
VariableExpr variableExpr = (VariableExpr) expr;
Preconditions.checkState(
variableExpr.isDecl(), "Class expression variable statements must be declarations");
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable statement cannot have a local scope");
} else {
Preconditions.checkState(
expr instanceof AssignmentExpr,
"Class expression statement must be assignment or variable declaration");
VariableExpr variableExpr = ((AssignmentExpr) expr).variableExpr();
Preconditions.checkState(
!variableExpr.scope().equals(ScopeNode.LOCAL),
"Class variable in assignment statement cannot have a local scope");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -122,10 +123,7 @@ public abstract static class Builder {
public abstract Builder setHeaderCommentStatements(
List<CommentStatement> headeCommentStatements);

public Builder setAnnotations(List<AnnotationNode> annotations) {
annotationsBuilder().addAll(annotations);
return this;
}
public abstract Builder setAnnotations(List<AnnotationNode> annotations);

public abstract Builder setIsStatic(boolean isStatic);

Expand Down Expand Up @@ -162,10 +160,10 @@ public Builder setArguments(VariableExpr... arguments) {

// Private accessors.

abstract ImmutableList.Builder<AnnotationNode> annotationsBuilder();

abstract String name();

abstract ImmutableList<AnnotationNode> annotations();

abstract TypeNode returnType();

abstract boolean isOverride();
Expand Down Expand Up @@ -231,9 +229,19 @@ public MethodDefinition build() {
}

// If this method overrides another, ensure that the Override annotaiton is the last one.
ImmutableList<AnnotationNode> processedAnnotations = annotations();
if (isOverride()) {
annotationsBuilder().add(AnnotationNode.OVERRIDE);
processedAnnotations =
annotations()
.<AnnotationNode>builder()
.addAll(annotations())
.add(AnnotationNode.OVERRIDE)
.build();
}
// Remove duplicates while maintaining insertion order.
setAnnotations(
new LinkedHashSet<AnnotationNode>(processedAnnotations)
.stream().collect(Collectors.toList()));

MethodDefinition method = autoBuild();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public class Literal {
private static final Pattern LONG_PATTERN = Pattern.compile("^[0-9]+[Ll]?$");
private static final Pattern FLOAT_PATTERN =
Pattern.compile("^[0-9]+([fF]|(\\.(([0-9]+[fF])|[fF])))?$");
private static final Pattern DOUBLE_PATTERN =
private static final Pattern DOUBLE_PATTERN_ONE =
Pattern.compile("^[0-9]+(\\.[0-9]+)?(\\.?[eE]\\-?[0-9]+)$");
private static final Pattern DOUBLE_PATTERN_TWO = Pattern.compile("^\\d*\\.\\d+$|^\\d+\\.\\d*$");

public static boolean isBooleanLiteral(String str) {
return str.equals(BOOLEAN_TRUE) || str.equals(BOOLEAN_FALSE);
Expand All @@ -46,7 +47,9 @@ public static boolean isFloatLiteral(String str) {
}

public static boolean isDoubleLiteral(String str) {
return isFloatLiteral(str) || DOUBLE_PATTERN.matcher(str).matches();
return isFloatLiteral(str)
|| DOUBLE_PATTERN_ONE.matcher(str).matches()
|| DOUBLE_PATTERN_TWO.matcher(str).matches();
}

public static boolean isNullLiteral(String str) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ java_library(
"@com_google_api_gax_java//jar",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_guava_guava//jar",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//:protobuf_java_util",
"@com_google_protobuf//java/core",
"@io_grpc_java//api",
"@io_grpc_java//protobuf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
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;
import com.google.api.generator.gapic.model.GapicServiceConfig;
import com.google.api.generator.gapic.model.Message;
import com.google.api.generator.gapic.model.ResourceName;
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.utils.ApacheLicense;
import com.google.common.annotations.VisibleForTesting;
import io.grpc.serviceconfig.ServiceConfig;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -45,7 +45,7 @@ public static List<GapicClass> composeServiceClasses(GapicContext context) {

public static List<GapicClass> generateServiceClasses(
@Nonnull Service service,
@Nullable ServiceConfig serviceConfig,
@Nullable GapicServiceConfig serviceConfig,
@Nonnull Map<String, Message> messageTypes) {
List<GapicClass> clazzes = new ArrayList<>();
clazzes.addAll(generateStubClasses(service, serviceConfig, messageTypes));
Expand All @@ -64,7 +64,7 @@ public static List<GapicClass> generateResourceNameHelperClasses(
}

public static List<GapicClass> generateStubClasses(
Service service, ServiceConfig serviceConfig, Map<String, Message> messageTypes) {
Service service, GapicServiceConfig serviceConfig, Map<String, Message> messageTypes) {
List<GapicClass> clazzes = new ArrayList<>();
clazzes.add(ServiceStubClassComposer.instance().generate(service, messageTypes));
clazzes.add(
Expand Down
Loading