Switch to spotless and format code (#1196)

* Add spotless configuration

* Reformat!

* Add copyright config for build.gradle.kts files

* Add toeholds for headers
This commit is contained in:
Zac Sweers
2020-08-27 23:40:15 -04:00
committed by GitHub
parent 701d6ba968
commit 538890e8c0
109 changed files with 6748 additions and 4972 deletions

View File

@@ -15,6 +15,8 @@
*/
package com.squareup.moshi.recipes;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import com.squareup.moshi.FromJson;
import com.squareup.moshi.JsonAdapter;
import com.squareup.moshi.JsonQualifier;
@@ -22,20 +24,17 @@ import com.squareup.moshi.Moshi;
import com.squareup.moshi.ToJson;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
public final class CustomQualifier {
public void run() throws Exception {
String json = ""
+ "{\n"
+ " \"color\": \"#ff0000\",\n"
+ " \"height\": 768,\n"
+ " \"width\": 1024\n"
+ "}\n";
String json =
""
+ "{\n"
+ " \"color\": \"#ff0000\",\n"
+ " \"height\": 768,\n"
+ " \"width\": 1024\n"
+ "}\n";
Moshi moshi = new Moshi.Builder()
.add(new ColorAdapter())
.build();
Moshi moshi = new Moshi.Builder().add(new ColorAdapter()).build();
JsonAdapter<Rectangle> jsonAdapter = moshi.adapter(Rectangle.class);
Rectangle rectangle = jsonAdapter.fromJson(json);
@@ -51,22 +50,25 @@ public final class CustomQualifier {
int height;
@HexColor int color;
@Override public String toString() {
@Override
public String toString() {
return String.format("%dx%d #%06x", width, height, color);
}
}
@Retention(RUNTIME)
@JsonQualifier
public @interface HexColor {
}
public @interface HexColor {}
static class ColorAdapter {
@ToJson String toJson(@HexColor int rgb) {
@ToJson
String toJson(@HexColor int rgb) {
return String.format("#%06x", rgb);
}
@FromJson @HexColor int fromJson(String rgb) {
@FromJson
@HexColor
int fromJson(String rgb) {
return Integer.parseInt(rgb.substring(1), 16);
}
}