Skip to content

Commit

Permalink
Annotate some methods always returning 'this' with CanIgnoreReturnValue.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 698800818
  • Loading branch information
mollyibot authored and copybara-github committed Nov 21, 2024
1 parent df52e9a commit 4434226
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions java/jsinterop/generator/writer/CodeWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static jsinterop.generator.model.PredefinedTypes.OBJECT;

import com.google.common.base.Splitter;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -73,6 +74,7 @@ public CodeWriter emit(String s) {
return this;
}

@CanIgnoreReturnValue
public CodeWriter emitNewLine() {
emit("\n");
return this;
Expand Down Expand Up @@ -106,19 +108,23 @@ private String getImportedTypeName(TypeReference typeReference) {
return typeReferenceImport.substring(index + 1);
}

@CanIgnoreReturnValue
public CodeWriter emitAnnotations(List<Annotation> annotations) {
annotations.forEach(a -> AnnotationWriter.emit(a, this));
return this;
}

@CanIgnoreReturnValue
public CodeWriter emitGenerics(Collection<TypeReference> typeGenerics, boolean emitConstraint) {
return emitTypeReferences(typeGenerics.iterator(), "<", ">", emitConstraint);
}

@CanIgnoreReturnValue
public CodeWriter emitTypeReferences(Collection<TypeReference> typeReferences) {
return emitTypeReferences(typeReferences.iterator(), "", "", false);
}

@CanIgnoreReturnValue
private CodeWriter emitTypeReferences(
Iterator<TypeReference> typeReferences, String start, String end, boolean emitConstraint) {

Expand All @@ -144,6 +150,7 @@ public void setPackage(String aPackageName) {
packageName = aPackageName;
}

@CanIgnoreReturnValue
public CodeWriter emitJavadoc(String javadoc) {
if (isNullOrEmpty(javadoc)) {
return this;
Expand Down Expand Up @@ -177,6 +184,7 @@ public CodeWriter emitJavadoc(String javadoc) {
return this;
}

@CanIgnoreReturnValue
public CodeWriter emitSingleLineComment(String comment) {
if (isNullOrEmpty(comment)) {
return this;
Expand All @@ -189,14 +197,17 @@ public CodeWriter emitSingleLineComment(String comment) {
return this;
}

@CanIgnoreReturnValue
public CodeWriter emitTypeReference(TypeReference type) {
return emitTypeReference(type, false, true);
}

@CanIgnoreReturnValue
public CodeWriter emitTypeReference(TypeReference typeReference, boolean emitConstraint) {
return emitTypeReference(typeReference, emitConstraint, true);
}

@CanIgnoreReturnValue
public CodeWriter emitTypeReference(
TypeReference typeReference, boolean emitConstraint, boolean emitNullable) {
emitSingleLineComment(typeReference.getComment());
Expand Down Expand Up @@ -252,6 +263,7 @@ public CodeWriter emitTypeReference(
return this;
}

@CanIgnoreReturnValue
private CodeWriter emitNullableAnnotation(TypeReference typeReference, boolean emitNullable) {
if (emitNullable && typeReference.isNullable()) {
emit("@").emitTypeReference(NULLABLE.getType()).emit(" ");
Expand Down Expand Up @@ -295,11 +307,13 @@ private void writeImports(StringBuilder content) {
.forEach(content::append);
}

@CanIgnoreReturnValue
public CodeWriter emit(AccessModifier accessModifier) {
emit(accessModifier.getLitteral());
return this;
}

@CanIgnoreReturnValue
public CodeWriter emitStatement(Statement statement) {
if (statement.getLeadingComment() != null) {
emit("// ").emit(statement.getLeadingComment()).emitNewLine();
Expand All @@ -318,6 +332,7 @@ public CodeWriter emitStatement(Statement statement) {
return this;
}

@CanIgnoreReturnValue
public CodeWriter emitExpression(Expression expression) {
if (expression instanceof MethodInvocation) {
return emitMethodInvocation(((MethodInvocation) expression));
Expand Down Expand Up @@ -349,10 +364,12 @@ public CodeWriter emitExpression(Expression expression) {
throw new RuntimeException("Unknown Expression");
}

@CanIgnoreReturnValue
private CodeWriter emitTypeQualifier(TypeQualifier typeQualifier) {
return emitTypeReference(typeQualifier.getType());
}

@CanIgnoreReturnValue
private CodeWriter emitMethodInvocation(MethodInvocation methodInvocation) {
if (methodInvocation.getInvocationTarget() != null) {
emitExpression(methodInvocation.getInvocationTarget()).emit(".");
Expand Down

0 comments on commit 4434226

Please sign in to comment.