Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -21,13 +21,16 @@
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import java.io.IOException;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
public class Main {
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
ProtoRegistry.registerAllExtensions(registry);
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry);
CodeGeneratorResponse response = Generator.generateGapic(request);
@Nullable CodeGeneratorResponse response = Generator.generateGapic(request);
Comment thread
nnicolee marked this conversation as resolved.
if (response != EMPTY_RESPONSE) {
response.writeTo(System.out);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import com.google.cloud.ExtendedOperationsProto;
import com.google.longrunning.OperationsProto;
import com.google.protobuf.ExtensionRegistry;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class ProtoRegistry {
/** Register all extensions needed to process API protofiles. */
public static void registerAllExtensions(ExtensionRegistry extensionRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import java.io.IOException;
import org.jspecify.annotations.NullMarked;

// Request dumper class, which dumps the CodeGeneratorRequest to a file on disk which will be
// identical to the one passed to the Main class during normal execution. The dumped file then can
// be used to run this gapic-generator directly (instead of relying on protoc to start the process),
// which would give much greater flexibility in terms of debugging features, like attaching a
// debugger, easier work with stdout and stderr etc.
@NullMarked
public class CodeGeneratorRequestDumper {
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

// A generator entry point class, similar to Main but reads the CodeGeneratorRequest directly from a
// file instead of relying on protoc to pipe it in.
@NullMarked
public class CodeGeneratorRequestFileToGapicMain {
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Expand All @@ -38,7 +41,7 @@ public static void main(String[] args) throws IOException {
try (InputStream inputStream = new FileInputStream(inputFile);
OutputStream outputStream = new FileOutputStream(outputFile)) {
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(inputStream, registry);
CodeGeneratorResponse response = Generator.generateGapic(request);
@Nullable CodeGeneratorResponse response = Generator.generateGapic(request);
Comment thread
nnicolee marked this conversation as resolved.
response.writeTo(outputStream);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
@AutoValue
public abstract class AnnotationNode implements AstNode {
public static AnnotationNode OVERRIDE =
Expand All @@ -34,8 +36,7 @@

public abstract TypeNode type();

@Nullable
public abstract List<Expr> descriptionExprs();
public abstract @Nullable List<Expr> descriptionExprs();

@Override
public void accept(AstNodeVisitor visitor) {
Expand Down Expand Up @@ -138,7 +139,7 @@
List<Expr> exprList = descriptionExprs();
// avoid when single parameter is already set.
Preconditions.checkState(
exprList == null || exprList instanceof ArrayList,

Check warning on line 142 in sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/AnnotationNode.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Remove this expression which always evaluates to "false"

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_generator&issues=AZ9hB_BBvhlaxwr_h2B8&open=AZ9hB_BBvhlaxwr_h2B8&pullRequest=13769
MULTIPLE_AFTER_SINGLE_EXCEPTION_MESSAGE);
if (exprList == null) {
exprList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class AnonymousClassExpr implements Expr {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class ArithmeticOperationExpr implements OperationExpr {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class ArrayExpr implements Expr {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class AssignmentExpr implements Expr {
public abstract VariableExpr variableExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class AssignmentOperationExpr implements OperationExpr {
public abstract VariableExpr variableExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.api.generator.engine.ast;

import org.jspecify.annotations.NullMarked;

@NullMarked
public interface AstNode {
/** Writes the syntatically-correct Java code representation of this node. */
public void accept(AstNodeVisitor visitor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.api.generator.engine.ast;

import org.jspecify.annotations.NullMarked;

@NullMarked
public interface AstNodeVisitor {
/** Writes the syntatically-correct Java code representation of this node. */
public void visit(IdentifierNode identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package com.google.api.generator.engine.ast;

import com.google.auto.value.AutoValue;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class BlockComment implements Comment {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class BlockStatement implements Statement {
// TODO(unsupported): Named blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.api.generator.engine.ast;

import org.jspecify.annotations.NullMarked;

@NullMarked
public class BreakStatement implements Statement {
private BreakStatement() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class CastExpr implements Expr {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
@AutoValue
public abstract class ClassDefinition implements AstNode {
// Optional.
public abstract ImmutableList<CommentStatement> fileHeader();

// Required for samples classes.
@Nullable
public abstract RegionTag regionTag();
public abstract @Nullable RegionTag regionTag();

// Required.
public abstract ScopeNode scope();
Expand All @@ -39,8 +40,7 @@ public abstract class ClassDefinition implements AstNode {
public abstract IdentifierNode classIdentifier();

// Required for outer classes.
@Nullable
public abstract String packageString();
public abstract @Nullable String packageString();

public abstract boolean isNested();

Expand All @@ -52,8 +52,7 @@ public abstract class ClassDefinition implements AstNode {
// Using a list helps with determinism in unit tests.
public abstract ImmutableList<TypeNode> implementsTypes();

@Nullable
public abstract TypeNode extendsType();
public abstract @Nullable TypeNode extendsType();

public abstract boolean isStatic();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.api.generator.engine.ast;

import org.jspecify.annotations.NullMarked;

@NullMarked
public interface Comment {
public String comment();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package com.google.api.generator.engine.ast;

import com.google.auto.value.AutoValue;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class CommentStatement implements Statement {
public abstract Comment comment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
@AutoValue
public abstract class ConcreteReference implements Reference {
private static final String EXTENDS = "extends";
Expand Down Expand Up @@ -152,7 +154,7 @@
@Override
public boolean isAssignableFrom(Reference other) {
if (other instanceof VaporReference && ((VaporReference) other).supertypeReference() != null) {
return isAssignableFrom(((VaporReference) other).supertypeReference());

Check warning on line 157 in sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/engine/ast/ConcreteReference.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Annotate the parameter with @javax.annotation.Nullable in method 'isAssignableFrom' declaration, or make sure that null can not be passed as argument.

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_generator&issues=AZ9hB_CKvhlaxwr_h2B-&open=AZ9hB_CKvhlaxwr_h2B-&pullRequest=13769
}

if (!(other instanceof ConcreteReference)) {
Expand All @@ -176,7 +178,7 @@
}

@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (!(o instanceof ConcreteReference)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.api.generator.engine.ast;

import org.jspecify.annotations.NullMarked;

@NullMarked
public class EmptyLineStatement implements Statement {
private EmptyLineStatement() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class EnumRefExpr implements Expr {
public abstract IdentifierNode identifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

package com.google.api.generator.engine.ast;

import org.jspecify.annotations.NullMarked;

@NullMarked
public interface Expr extends AstNode {
TypeNode type();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class ExprStatement implements Statement {
public abstract Expr expression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class ForStatement implements Statement {
public abstract VariableExpr localVariableExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import com.google.common.collect.ImmutableList;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class GeneralForStatement implements Statement {
public abstract Expr initializationExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import java.util.regex.Pattern;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class IdentifierNode implements AstNode {
static class InvalidIdentifierException extends RuntimeException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.List;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class IfStatement implements Statement {
public abstract Expr conditionExpr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import com.google.auto.value.AutoValue;
import com.google.common.base.Preconditions;
import org.jspecify.annotations.NullMarked;

@NullMarked
@AutoValue
public abstract class InstanceofExpr implements Expr {
public abstract Expr expr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NullMarked
@AutoValue
public abstract class JavaDocComment implements Comment {
@Override
Expand All @@ -48,11 +51,11 @@ public abstract static class Builder {
static final String PARAM_INDENT = " ";

// The lack of a getter for these local variables in the external class is WAI.
String throwsType = null;
String throwsDescription = null;
String deprecated = null;
String internalOnly = null;
String returnDescription = null;
@Nullable String throwsType = null;
@Nullable String throwsDescription = null;
@Nullable String deprecated = null;
@Nullable String internalOnly = null;
@Nullable String returnDescription = null;
List<String> paramsList = new ArrayList<>();
List<String> componentsList = new ArrayList<>();

Expand Down
Loading
Loading