From ddcbc8d148b3b013e4904c0223bc4f230cc423ed Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Mon, 27 Jan 2020 10:56:58 -0500 Subject: [PATCH 1/6] Created the template for Objects --- .../refastertemplates/MethodTemplates.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java new file mode 100644 index 0000000000..b3c739447b --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java @@ -0,0 +1,24 @@ +package tech.picnic.errorprone.refastertemplates; + +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import java.util.Objects; + +/** Refaster templates related to expressions dealing with (possibly) null values. */ +final class MethodTemplates { + private MethodTemplates() {} + + /** Prefer {@link Objects#requireNonNullElse(Object, Object)} over the Guava alternative. */ + static final class DirectlyReturnInsteadOfFirstAssignVariable { + @BeforeTemplate + T before(T element) { + T var = element; + return var; + } + + @AfterTemplate + T after(T element) { + return element; + } + } +} From db2e22436430c906f846f954ac83f8063680301a Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Mon, 27 Jan 2020 11:02:08 -0500 Subject: [PATCH 2/6] Created the template for primitive types --- .../refastertemplates/MethodTemplates.java | 108 +++++++++++++++++- 1 file changed, 106 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java index b3c739447b..de82071be6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java @@ -8,8 +8,8 @@ final class MethodTemplates { private MethodTemplates() {} - /** Prefer {@link Objects#requireNonNullElse(Object, Object)} over the Guava alternative. */ - static final class DirectlyReturnInsteadOfFirstAssignVariable { + /** We prefer that variables are directly returned instead of first assigned and then returned. */ + static final class DirectlyReturnObjectVariable { @BeforeTemplate T before(T element) { T var = element; @@ -21,4 +21,108 @@ T after(T element) { return element; } } + + static final class DirectlyReturnBooleanVariable { + @BeforeTemplate + boolean before(boolean element) { + boolean var = element; + return var; + } + + @AfterTemplate + boolean after(boolean element) { + return element; + } + } + + static final class DirectlyReturnIntegerVariable { + @BeforeTemplate + int before(int element) { + int var = element; + return var; + } + + @AfterTemplate + int after(int element) { + return element; + } + } + + static final class DirectlyReturnFloatVariable { + @BeforeTemplate + float before(float element) { + float var = element; + return var; + } + + @AfterTemplate + float after(float element) { + return element; + } + } + + static final class DirectlyReturnCharVariable { + @BeforeTemplate + char before(char element) { + char var = element; + return var; + } + + @AfterTemplate + char after(char element) { + return element; + } + } + + static final class DirectlyReturnByteVariable { + @BeforeTemplate + byte before(byte element) { + byte var = element; + return var; + } + + @AfterTemplate + byte after(byte element) { + return element; + } + } + + static final class DirectlyReturnShortVariable { + @BeforeTemplate + short before(short element) { + short var = element; + return var; + } + + @AfterTemplate + short after(short element) { + return element; + } + } + + static final class DirectlyReturnLongVariable { + @BeforeTemplate + long before(long element) { + long var = element; + return var; + } + + @AfterTemplate + long after(long element) { + return element; + } + } + + static final class DirectlyReturnDoubleVariable { + @BeforeTemplate + double before(double element) { + double var = element; + return var; + } + + @AfterTemplate + double after(double element) { + return element; + } + } } From 9ff9ef75df1178728dca62104136403e62b05cad Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Mon, 27 Jan 2020 11:07:17 -0500 Subject: [PATCH 3/6] Format --- .../picnic/errorprone/refastertemplates/MethodTemplates.java | 1 - 1 file changed, 1 deletion(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java index de82071be6..8fc42fa80d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java @@ -2,7 +2,6 @@ import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; -import java.util.Objects; /** Refaster templates related to expressions dealing with (possibly) null values. */ final class MethodTemplates { From 581db54f7ab654e9dca3b6f453ddab7b2b7015cb Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Mon, 27 Jan 2020 13:19:28 -0500 Subject: [PATCH 4/6] Create tests for Method group --- .../bugpatterns/RefasterCheckTest.java | 1 + .../bugpatterns/MethodTemplatesTestInput.java | 68 +++++++++++++++++++ .../MethodTemplatesTestOutput.java | 56 +++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java index 4238d22212..e8e699fc5e 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java @@ -57,6 +57,7 @@ public final class RefasterCheckTest { "JUnit", "LongStream", "MapEntry", + "Method", "Mockito", "Multimap", "Null", diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java new file mode 100644 index 0000000000..17682401e1 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java @@ -0,0 +1,68 @@ +package tech.picnic.errorprone.bugpatterns; + +import java.util.stream.Collectors; + +final class MethodTemplateTest implements RefasterTemplateTestCase { + String testObjectReturn() { + String var = "Hello!"; + return var; + } + + byte testByteReturn() { + byte var = Byte.MAX_VALUE; + return var; + } + + char testCharacterReturn() { + char var = Character.MAX_VALUE; + return var; + } + + short testShortReturn() { + short var = Short.MAX_VALUE; + return var; + } + + int testIntegerReturn() { + int var = Integer.MAX_VALUE; + return var; + } + + long testLongReturn() { + long var = 349827359L; + return var; + } + + float testFloatReturn() { + float var = 4324.347284F; + return var; + } + + double testDoubleReturn() { + double var = 3492.34284D; + return var; + } + + boolean testBooleanReturn() { + boolean var = true; + return var; + } + + String testStuffAboveDoesntMatter() { + System.out.println("Hi"); + String var = "Hello!"; + return var; + } + + String testStuffBelowDoesMatter() { + String var = "Hello!"; + System.out.println("Hi"); + return var; + } + + String testChainedReturn() { + String var = + Stream.of("I", "like", "error-prone", ":-)").collect(Collectors.joining(" ", "", "!")); + return var; + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java new file mode 100644 index 0000000000..40347dab52 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java @@ -0,0 +1,56 @@ +package tech.picnic.errorprone.bugpatterns; + +import java.util.stream.Collectors; + +final class MethodTemplateTest implements RefasterTemplateTestCase { + String testObjectReturn() { + return "Hello!"; + } + + byte testByteReturn() { + return Byte.MAX_VALUE; + } + + char testCharacterReturn() { + return Character.MAX_VALUE; + } + + short testShortReturn() { + return Short.MAX_VALUE; + } + + int testIntegerReturn() { + return Integer.MAX_VALUE; + } + + long testLongReturn() { + return 349827359L; + } + + float testFloatReturn() { + return 4324.347284F; + } + + double testDoubleReturn() { + return 3492.34284D; + } + + boolean testBooleanReturn() { + return true; + } + + String testStuffAboveDoesntMatter() { + System.out.println("Hi"); + return "Hello!"; + } + + String testStuffBelowDoesMatter() { + String var = "Hello!"; + System.out.println("Hi"); + return var; + } + + String testChainedReturn() { + return Stream.of("I", "like", "error-prone", ":-)").collect(Collectors.joining(" ", "", "!")); + } +} From 97c9349bb0df514cc352bc82d9a6085c2bc0ad19 Mon Sep 17 00:00:00 2001 From: Simon Baars Date: Mon, 27 Jan 2020 13:28:13 -0500 Subject: [PATCH 5/6] Forgot import --- .../picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java | 1 + .../picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java | 1 + 2 files changed, 2 insertions(+) diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java index 17682401e1..3581e164fb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.bugpatterns; import java.util.stream.Collectors; +import java.util.stream.Stream; final class MethodTemplateTest implements RefasterTemplateTestCase { String testObjectReturn() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java index 40347dab52..1793d44393 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.bugpatterns; import java.util.stream.Collectors; +import java.util.stream.Stream; final class MethodTemplateTest implements RefasterTemplateTestCase { String testObjectReturn() { From a5e226f10f2b61e04c80fbbf321aff179da09a8c Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 31 Jan 2020 13:14:48 +0100 Subject: [PATCH 6/6] Suggestions --- ...plates.java => DirectReturnTemplates.java} | 82 ++++++++++--------- .../bugpatterns/RefasterCheckTest.java | 2 +- .../DirectReturnTemplatesTestInput.java | 64 +++++++++++++++ .../DirectReturnTemplatesTestOutput.java | 54 ++++++++++++ .../bugpatterns/MethodTemplatesTestInput.java | 69 ---------------- .../MethodTemplatesTestOutput.java | 57 ------------- 6 files changed, 161 insertions(+), 167 deletions(-) rename error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/{MethodTemplates.java => DirectReturnTemplates.java} (88%) create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestOutput.java delete mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java delete mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DirectReturnTemplates.java similarity index 88% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DirectReturnTemplates.java index 8fc42fa80d..9213f3a676 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MethodTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DirectReturnTemplates.java @@ -3,124 +3,126 @@ import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; -/** Refaster templates related to expressions dealing with (possibly) null values. */ -final class MethodTemplates { - private MethodTemplates() {} +/** + * Refaster templates that inline variables which are declared and initialized only to be directly + * returned. + */ +final class DirectReturnTemplates { + private DirectReturnTemplates() {} - /** We prefer that variables are directly returned instead of first assigned and then returned. */ - static final class DirectlyReturnObjectVariable { + static final class DirectlyReturnBooleanVariable { @BeforeTemplate - T before(T element) { - T var = element; + boolean before(boolean element) { + boolean var = element; return var; } @AfterTemplate - T after(T element) { + boolean after(boolean element) { return element; } } - static final class DirectlyReturnBooleanVariable { + static final class DirectlyReturnByteVariable { @BeforeTemplate - boolean before(boolean element) { - boolean var = element; + byte before(byte element) { + byte var = element; return var; } @AfterTemplate - boolean after(boolean element) { + byte after(byte element) { return element; } } - static final class DirectlyReturnIntegerVariable { + static final class DirectlyReturnCharVariable { @BeforeTemplate - int before(int element) { - int var = element; + char before(char element) { + char var = element; return var; } @AfterTemplate - int after(int element) { + char after(char element) { return element; } } - static final class DirectlyReturnFloatVariable { + static final class DirectlyReturnShortVariable { @BeforeTemplate - float before(float element) { - float var = element; + short before(short element) { + short var = element; return var; } @AfterTemplate - float after(float element) { + short after(short element) { return element; } } - static final class DirectlyReturnCharVariable { + static final class DirectlyReturnIntVariable { @BeforeTemplate - char before(char element) { - char var = element; + int before(int element) { + int var = element; return var; } @AfterTemplate - char after(char element) { + int after(int element) { return element; } } - static final class DirectlyReturnByteVariable { + static final class DirectlyReturnLongVariable { @BeforeTemplate - byte before(byte element) { - byte var = element; + long before(long element) { + long var = element; return var; } @AfterTemplate - byte after(byte element) { + long after(long element) { return element; } } - static final class DirectlyReturnShortVariable { + static final class DirectlyReturnFloatVariable { @BeforeTemplate - short before(short element) { - short var = element; + float before(float element) { + float var = element; return var; } @AfterTemplate - short after(short element) { + float after(float element) { return element; } } - static final class DirectlyReturnLongVariable { + static final class DirectlyReturnDoubleVariable { @BeforeTemplate - long before(long element) { - long var = element; + double before(double element) { + double var = element; return var; } @AfterTemplate - long after(long element) { + double after(double element) { return element; } } - static final class DirectlyReturnDoubleVariable { + static final class DirectlyReturnObjectVariable { @BeforeTemplate - double before(double element) { - double var = element; + T before(T element) { + T var = element; return var; } @AfterTemplate - double after(double element) { + T after(T element) { return element; } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java index e8e699fc5e..a265a71bd2 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterCheckTest.java @@ -42,6 +42,7 @@ public final class RefasterCheckTest { "BigDecimal", "Collection", "Comparator", + "DirectReturn", "DoubleStream", "Equality", "ImmutableList", @@ -57,7 +58,6 @@ public final class RefasterCheckTest { "JUnit", "LongStream", "MapEntry", - "Method", "Mockito", "Multimap", "Null", diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestInput.java new file mode 100644 index 0000000000..b264c1d505 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestInput.java @@ -0,0 +1,64 @@ +package tech.picnic.errorprone.bugpatterns; + +import static java.util.stream.Collectors.joining; + +import java.util.stream.Stream; + +final class DirectReturnTemplatesTest implements RefasterTemplateTestCase { + boolean testDirectlyReturnBooleanVariable() { + boolean var = true; + return var; + } + + byte testDirectlyReturnByteVariable() { + byte var = Byte.MAX_VALUE; + return var; + } + + char testDirectlyReturnCharVariable() { + char var = Character.MAX_VALUE; + return var; + } + + short testDirectlyReturnShortVariable() { + short var = Short.MAX_VALUE; + return var; + } + + int testDirectlyReturnIntVariable() { + int var = Integer.MAX_VALUE; + return var; + } + + long testDirectlyReturnLongVariable() { + long var = Long.MAX_VALUE; + return var; + } + + float testDirectlyReturnFloatVariable() { + float var = Float.MAX_VALUE; + return var; + } + + double testDirectlyReturnDoubleVariable() { + double var = Double.MAX_VALUE; + return var; + } + + String testDirectlyReturnObjectVariable() { + String var = "foo"; + return var; + } + + String testDirectlyReturnObjectVariableWithPrecedingStatement() { + String unrelated = "foo"; + String var = Stream.of("bar", "baz").collect(joining(" ")); + return var; + } + + String testDirectlyReturnObjectVariableWithInterveningStatement() { + String var = "foo"; + String unrelated = "bar"; + return var; + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestOutput.java new file mode 100644 index 0000000000..800773a65d --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/DirectReturnTemplatesTestOutput.java @@ -0,0 +1,54 @@ +package tech.picnic.errorprone.bugpatterns; + +import static java.util.stream.Collectors.joining; + +import java.util.stream.Stream; + +final class DirectReturnTemplatesTest implements RefasterTemplateTestCase { + boolean testDirectlyReturnBooleanVariable() { + return true; + } + + byte testDirectlyReturnByteVariable() { + return Byte.MAX_VALUE; + } + + char testDirectlyReturnCharVariable() { + return Character.MAX_VALUE; + } + + short testDirectlyReturnShortVariable() { + return Short.MAX_VALUE; + } + + int testDirectlyReturnIntVariable() { + return Integer.MAX_VALUE; + } + + long testDirectlyReturnLongVariable() { + return Long.MAX_VALUE; + } + + float testDirectlyReturnFloatVariable() { + return Float.MAX_VALUE; + } + + double testDirectlyReturnDoubleVariable() { + return Double.MAX_VALUE; + } + + String testDirectlyReturnObjectVariable() { + return "foo"; + } + + String testDirectlyReturnObjectVariableWithPrecedingStatement() { + String unrelated = "foo"; + return Stream.of("bar", "baz").collect(joining(" ")); + } + + String testDirectlyReturnObjectVariableWithInterveningStatement() { + String var = "foo"; + String unrelated = "bar"; + return var; + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java deleted file mode 100644 index 3581e164fb..0000000000 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestInput.java +++ /dev/null @@ -1,69 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import java.util.stream.Collectors; -import java.util.stream.Stream; - -final class MethodTemplateTest implements RefasterTemplateTestCase { - String testObjectReturn() { - String var = "Hello!"; - return var; - } - - byte testByteReturn() { - byte var = Byte.MAX_VALUE; - return var; - } - - char testCharacterReturn() { - char var = Character.MAX_VALUE; - return var; - } - - short testShortReturn() { - short var = Short.MAX_VALUE; - return var; - } - - int testIntegerReturn() { - int var = Integer.MAX_VALUE; - return var; - } - - long testLongReturn() { - long var = 349827359L; - return var; - } - - float testFloatReturn() { - float var = 4324.347284F; - return var; - } - - double testDoubleReturn() { - double var = 3492.34284D; - return var; - } - - boolean testBooleanReturn() { - boolean var = true; - return var; - } - - String testStuffAboveDoesntMatter() { - System.out.println("Hi"); - String var = "Hello!"; - return var; - } - - String testStuffBelowDoesMatter() { - String var = "Hello!"; - System.out.println("Hi"); - return var; - } - - String testChainedReturn() { - String var = - Stream.of("I", "like", "error-prone", ":-)").collect(Collectors.joining(" ", "", "!")); - return var; - } -} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java deleted file mode 100644 index 1793d44393..0000000000 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/bugpatterns/MethodTemplatesTestOutput.java +++ /dev/null @@ -1,57 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import java.util.stream.Collectors; -import java.util.stream.Stream; - -final class MethodTemplateTest implements RefasterTemplateTestCase { - String testObjectReturn() { - return "Hello!"; - } - - byte testByteReturn() { - return Byte.MAX_VALUE; - } - - char testCharacterReturn() { - return Character.MAX_VALUE; - } - - short testShortReturn() { - return Short.MAX_VALUE; - } - - int testIntegerReturn() { - return Integer.MAX_VALUE; - } - - long testLongReturn() { - return 349827359L; - } - - float testFloatReturn() { - return 4324.347284F; - } - - double testDoubleReturn() { - return 3492.34284D; - } - - boolean testBooleanReturn() { - return true; - } - - String testStuffAboveDoesntMatter() { - System.out.println("Hi"); - return "Hello!"; - } - - String testStuffBelowDoesMatter() { - String var = "Hello!"; - System.out.println("Hi"); - return var; - } - - String testChainedReturn() { - return Stream.of("I", "like", "error-prone", ":-)").collect(Collectors.joining(" ", "", "!")); - } -}