diff --git a/java/jsinterop/generator/writer/CodeWriter.java b/java/jsinterop/generator/writer/CodeWriter.java index d4edadf..d5c8c58 100644 --- a/java/jsinterop/generator/writer/CodeWriter.java +++ b/java/jsinterop/generator/writer/CodeWriter.java @@ -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; @@ -73,6 +74,7 @@ public CodeWriter emit(String s) { return this; } + @CanIgnoreReturnValue public CodeWriter emitNewLine() { emit("\n"); return this; @@ -106,19 +108,23 @@ private String getImportedTypeName(TypeReference typeReference) { return typeReferenceImport.substring(index + 1); } + @CanIgnoreReturnValue public CodeWriter emitAnnotations(List annotations) { annotations.forEach(a -> AnnotationWriter.emit(a, this)); return this; } + @CanIgnoreReturnValue public CodeWriter emitGenerics(Collection typeGenerics, boolean emitConstraint) { return emitTypeReferences(typeGenerics.iterator(), "<", ">", emitConstraint); } + @CanIgnoreReturnValue public CodeWriter emitTypeReferences(Collection typeReferences) { return emitTypeReferences(typeReferences.iterator(), "", "", false); } + @CanIgnoreReturnValue private CodeWriter emitTypeReferences( Iterator typeReferences, String start, String end, boolean emitConstraint) { @@ -144,6 +150,7 @@ public void setPackage(String aPackageName) { packageName = aPackageName; } + @CanIgnoreReturnValue public CodeWriter emitJavadoc(String javadoc) { if (isNullOrEmpty(javadoc)) { return this; @@ -177,6 +184,7 @@ public CodeWriter emitJavadoc(String javadoc) { return this; } + @CanIgnoreReturnValue public CodeWriter emitSingleLineComment(String comment) { if (isNullOrEmpty(comment)) { return this; @@ -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()); @@ -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(" "); @@ -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(); @@ -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)); @@ -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(".");