18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/modules/json2java4idea_main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/annotation/AnnotationPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.annotation;
18 |
19 | import com.squareup.javapoet.TypeSpec;
20 |
21 | import javax.annotation.Nonnull;
22 |
23 | public interface AnnotationPolicy {
24 | void apply(@Nonnull TypeSpec.Builder builder);
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/idea/src/main/java/io/t28/json2java/idea/exception/ClassAlreadyExistsException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea.exception;
18 |
19 | import javax.annotation.Nonnull;
20 |
21 | public class ClassAlreadyExistsException extends ClassCreationException {
22 | public ClassAlreadyExistsException(@Nonnull String message) {
23 | super(message);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/naming/NamePolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.naming;
18 |
19 | import com.squareup.javapoet.TypeName;
20 |
21 | import javax.annotation.CheckReturnValue;
22 | import javax.annotation.Nonnull;
23 |
24 | public interface NamePolicy {
25 | @Nonnull
26 | @CheckReturnValue
27 | String convert(@Nonnull String name, @Nonnull TypeName type);
28 | }
29 |
--------------------------------------------------------------------------------
/idea/src/main/java/io/t28/json2java/idea/exception/InvalidDirectoryException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea.exception;
18 |
19 | import javax.annotation.Nonnull;
20 |
21 | public class InvalidDirectoryException extends ClassCreationException {
22 | private static final long serialVersionUID = 8602840574745874176L;
23 |
24 | public InvalidDirectoryException(@Nonnull String message) {
25 | super(message);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/io/JsonParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.io;
18 |
19 | import io.t28.json2java.core.io.exception.JsonParseException;
20 | import io.t28.json2java.core.json.JsonValue;
21 |
22 | import javax.annotation.CheckReturnValue;
23 | import javax.annotation.Nonnull;
24 |
25 | public interface JsonParser {
26 | @Nonnull
27 | @CheckReturnValue
28 | JsonValue parse(@Nonnull String json) throws JsonParseException;
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/modules/json2java4idea_test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/io/exception/JavaBuildException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.io.exception;
18 |
19 | import javax.annotation.Nonnull;
20 | import java.io.IOException;
21 |
22 | public class JavaBuildException extends IOException {
23 | private static final long serialVersionUID = 5642915429649238000L;
24 |
25 | public JavaBuildException(@Nonnull String message, @Nonnull Throwable cause) {
26 | super(message, cause);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/io/exception/JsonParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.io.exception;
18 |
19 | import javax.annotation.Nonnull;
20 | import java.io.IOException;
21 |
22 | public class JsonParseException extends IOException {
23 | private static final long serialVersionUID = 1477109671450199015L;
24 |
25 | public JsonParseException(@Nonnull String message, @Nonnull Throwable cause) {
26 | super(message, cause);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/idea/src/main/java/io/t28/json2java/idea/exception/ClassCreationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea.exception;
18 |
19 | import javax.annotation.Nonnull;
20 |
21 | public class ClassCreationException extends Exception {
22 | public ClassCreationException(@Nonnull String message) {
23 | super(message);
24 | }
25 |
26 | public ClassCreationException(@Nonnull String message, @Nonnull Throwable cause) {
27 | super(message, cause);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/io/JavaBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.io;
18 |
19 | import com.squareup.javapoet.TypeSpec;
20 | import io.t28.json2java.core.io.exception.JavaBuildException;
21 |
22 | import javax.annotation.CheckReturnValue;
23 | import javax.annotation.Nonnull;
24 |
25 | public interface JavaBuilder {
26 | @Nonnull
27 | @CheckReturnValue
28 | String build(@Nonnull String packageName, @Nonnull TypeSpec typeSpec) throws JavaBuildException;
29 | }
30 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/json/JsonNull.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.TypeName;
20 |
21 | import javax.annotation.Nonnull;
22 | import javax.annotation.Nullable;
23 |
24 | public class JsonNull extends JsonValue {
25 | @Nonnull
26 | @Override
27 | public TypeName getType() {
28 | return TypeName.OBJECT;
29 | }
30 |
31 | @Nullable
32 | @Override
33 | public Object getValue() {
34 | return null;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/idea/src/main/java/io/t28/json2java/idea/validator/NullValidator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea.validator;
18 |
19 | import com.intellij.openapi.ui.InputValidator;
20 | import org.jetbrains.annotations.Nullable;
21 |
22 | public class NullValidator implements InputValidator {
23 | @Override
24 | public boolean checkInput(@Nullable String text) {
25 | return false;
26 | }
27 |
28 | @Override
29 | public boolean canClose(@Nullable String text) {
30 | return false;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/idea/src/test/java/io/t28/json2java/idea/Assertions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea;
18 |
19 | import org.jdom.Element;
20 | import org.jdom.ElementAssert;
21 |
22 | import javax.annotation.CheckReturnValue;
23 | import javax.annotation.Nonnull;
24 | import javax.annotation.Nullable;
25 |
26 | public class Assertions {
27 | private Assertions() {
28 | }
29 |
30 | @Nonnull
31 | @CheckReturnValue
32 | public static ElementAssert assertThat(@Nullable Element actual) {
33 | return new ElementAssert(actual);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/json/JsonBoolean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.TypeName;
20 |
21 | import javax.annotation.Nonnull;
22 |
23 | public class JsonBoolean extends JsonValue {
24 | private final boolean value;
25 |
26 | public JsonBoolean(boolean value) {
27 | this.value = value;
28 | }
29 |
30 | @Nonnull
31 | @Override
32 | public TypeName getType() {
33 | return TypeName.BOOLEAN;
34 | }
35 |
36 | @Nonnull
37 | @Override
38 | public Boolean getValue() {
39 | return value;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/json/JsonString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.ClassName;
20 | import com.squareup.javapoet.TypeName;
21 |
22 | import javax.annotation.Nonnull;
23 |
24 | public class JsonString extends JsonValue {
25 | private final String value;
26 |
27 | public JsonString(@Nonnull String value) {
28 | this.value = value;
29 | }
30 |
31 | @Nonnull
32 | @Override
33 | public TypeName getType() {
34 | return ClassName.get(String.class);
35 | }
36 |
37 | @Nonnull
38 | @Override
39 | public String getValue() {
40 | return value;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/core/src/test/resources/java/ComplexArrayTest.java:
--------------------------------------------------------------------------------
1 | package io.t28.test;
2 |
3 | import java.util.List;
4 | import javax.annotation.Generated;
5 |
6 | @SuppressWarnings("all")
7 | @Generated("io.t28.json2java.core.JavaConverter")
8 | public class ComplexArrayTest {
9 | private final String name;
10 |
11 | private final List array;
12 |
13 | private final List objects;
14 |
15 | private final List> nested;
16 |
17 | public ComplexArrayTest(String name, List array, List objects,
18 | List> nested) {
19 | this.name = name;
20 | this.array = array;
21 | this.objects = objects;
22 | this.nested = nested;
23 | }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public List getArray() {
30 | return array;
31 | }
32 |
33 | public List getObjects() {
34 | return objects;
35 | }
36 |
37 | public List> getNested() {
38 | return nested;
39 | }
40 |
41 | public static class Objects {
42 | private final String key;
43 |
44 | public Objects(String key) {
45 | this.key = key;
46 | }
47 |
48 | public String getKey() {
49 | return key;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/idea/src/main/java/io/t28/json2java/idea/command/CommandActionFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea.command;
18 |
19 | import com.google.inject.assistedinject.Assisted;
20 | import com.intellij.psi.PsiDirectory;
21 | import io.t28.json2java.core.JavaConverter;
22 |
23 | import javax.annotation.CheckReturnValue;
24 | import javax.annotation.Nonnull;
25 |
26 | public interface CommandActionFactory {
27 | @Nonnull
28 | @CheckReturnValue
29 | NewClassCommandAction create(
30 | @Nonnull @Assisted("Name") String name,
31 | @Nonnull @Assisted("Json") String json,
32 | @Nonnull PsiDirectory directory,
33 | @Nonnull JavaConverter converter
34 | );
35 | }
36 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/json/JsonNumber.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.TypeName;
20 |
21 | import javax.annotation.Nonnull;
22 | import java.lang.reflect.Type;
23 |
24 | public class JsonNumber extends JsonValue {
25 | private final Type type;
26 | private final Number value;
27 |
28 | public JsonNumber(@Nonnull Type type, @Nonnull Number value) {
29 | this.type = type;
30 | this.value = value;
31 | }
32 |
33 | @Nonnull
34 | @Override
35 | public TypeName getType() {
36 | return TypeName.get(type);
37 | }
38 |
39 | @Nonnull
40 | @Override
41 | public Number getValue() {
42 | return value;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/circle.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | build:
4 | working_directory: ~/json2java
5 | docker:
6 | - image: openjdk:8
7 | steps:
8 | - type: shell
9 | name: Set up the build environment
10 | command: apt-get -qq update; apt-get -y install git
11 | - type: checkout
12 | - type: shell
13 | name: Set up the Gradle build
14 | command: chmod +x ./gradlew; ./gradlew --version
15 | - type: shell
16 | name: Assemble the outputs of this project
17 | command: ./gradlew :core:build --full-stacktrace; ./gradlew :idea:buildPlugin --full-stacktrace
18 | - type: shell
19 | name: Run all checks including unit test and static code analysis
20 | command: ./gradlew check --full-stacktrace
21 | - type: shell
22 | name: Upload code coverage report to codacy
23 | command: ./gradlew sendCoverageToCodacy
24 | - type: test-results-store
25 | path: core/build/test-results/
26 | - type: test-results-store
27 | path: idea/build/test-results/
28 | - type: artifacts-store
29 | path: core/build/reports/jacoco/test
30 | destination: core/jacoco
31 | - type: artifacts-store
32 | path: idea/build/reports/jacoco/test
33 | destination: idea/jacoco
34 | - type: artifacts-store
35 | path: idea/build/distributions
36 | destination: idea
37 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/annotation/SuppressWarningsAnnotationPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.annotation;
18 |
19 | import com.squareup.javapoet.AnnotationSpec;
20 | import com.squareup.javapoet.TypeSpec;
21 |
22 | import javax.annotation.Nonnull;
23 |
24 | public class SuppressWarningsAnnotationPolicy implements AnnotationPolicy {
25 | private final String value;
26 |
27 | public SuppressWarningsAnnotationPolicy(@Nonnull String value) {
28 | this.value = value;
29 | }
30 |
31 | @Override
32 | public void apply(@Nonnull TypeSpec.Builder builder) {
33 | builder.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
34 | .addMember("value", "$S", value)
35 | .build());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/annotation/GeneratedAnnotationPolicy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.annotation;
18 |
19 | import com.squareup.javapoet.AnnotationSpec;
20 | import com.squareup.javapoet.TypeSpec;
21 |
22 | import javax.annotation.Generated;
23 | import javax.annotation.Nonnull;
24 |
25 | public class GeneratedAnnotationPolicy implements AnnotationPolicy {
26 | private final Class> klass;
27 |
28 | public GeneratedAnnotationPolicy(@Nonnull Class> klass) {
29 | this.klass = klass;
30 | }
31 |
32 | @Override
33 | public void apply(@Nonnull TypeSpec.Builder builder) {
34 | builder.addAnnotation(AnnotationSpec.builder(Generated.class)
35 | .addMember("value", "$S", klass.getCanonicalName())
36 | .build());
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/io/JavaBuilderImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.io;
18 |
19 | import com.squareup.javapoet.JavaFile;
20 | import com.squareup.javapoet.TypeSpec;
21 | import io.t28.json2java.core.io.JavaBuilder;
22 | import io.t28.json2java.core.io.exception.JavaBuildException;
23 |
24 | import javax.annotation.Nonnull;
25 |
26 | public class JavaBuilderImpl implements JavaBuilder {
27 | private static final String INDENT = " ";
28 |
29 | @Nonnull
30 | @Override
31 | public String build(@Nonnull String packageName, @Nonnull TypeSpec typeSpec) throws JavaBuildException {
32 | return JavaFile.builder(packageName, typeSpec)
33 | .indent(INDENT)
34 | .skipJavaLangImports(true)
35 | .build()
36 | .toString();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/idea/src/main/java/io/t28/json2java/idea/Json2JavaBundle.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.idea;
18 |
19 | import com.intellij.AbstractBundle;
20 | import org.jetbrains.annotations.PropertyKey;
21 |
22 | import javax.annotation.CheckReturnValue;
23 | import javax.annotation.Nonnull;
24 |
25 | public class Json2JavaBundle extends AbstractBundle {
26 | private static final String BUNDLE = "messages.Json2Java4IdeaBundle";
27 |
28 | public Json2JavaBundle() {
29 | super(BUNDLE);
30 | }
31 |
32 | @Nonnull
33 | public static Json2JavaBundle getInstance() {
34 | return new Json2JavaBundle();
35 | }
36 |
37 | @Nonnull
38 | @CheckReturnValue
39 | public String message(@Nonnull @PropertyKey(resourceBundle = BUNDLE) String key, @Nonnull Object... objects) {
40 | return getMessage(key, objects);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/core/src/test/resources/java/ObjectTest.java:
--------------------------------------------------------------------------------
1 | package io.t28.test;
2 |
3 | import java.util.List;
4 | import javax.annotation.Generated;
5 |
6 | @SuppressWarnings("all")
7 | @Generated("io.t28.json2java.core.JavaConverter")
8 | public class ObjectTest {
9 | private final Object nullValue;
10 |
11 | private final int numberValue;
12 |
13 | private final String stringValue;
14 |
15 | private final List arrayValue;
16 |
17 | private final ObjectValue objectValue;
18 |
19 | public ObjectTest(Object nullValue, int numberValue, String stringValue,
20 | List arrayValue, ObjectValue objectValue) {
21 | this.nullValue = nullValue;
22 | this.numberValue = numberValue;
23 | this.stringValue = stringValue;
24 | this.arrayValue = arrayValue;
25 | this.objectValue = objectValue;
26 | }
27 |
28 | public Object getNullValue() {
29 | return nullValue;
30 | }
31 |
32 | public int getNumberValue() {
33 | return numberValue;
34 | }
35 |
36 | public String getStringValue() {
37 | return stringValue;
38 | }
39 |
40 | public List getArrayValue() {
41 | return arrayValue;
42 | }
43 |
44 | public ObjectValue getObjectValue() {
45 | return objectValue;
46 | }
47 |
48 | public static class ObjectValue {
49 | private final String name;
50 |
51 | public ObjectValue(String name) {
52 | this.name = name;
53 | }
54 |
55 | public String getName() {
56 | return name;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/core/src/test/java/io/t28/json2java/core/json/JsonNullTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.TypeName;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import static io.t28.json2java.core.Assertions.assertThat;
24 |
25 | public class JsonNullTest {
26 | private JsonNull underTest;
27 |
28 | @Before
29 | public void setUp() throws Exception {
30 | underTest = new JsonNull();
31 | }
32 |
33 | @Test
34 | public void getType() throws Exception {
35 | // exercise
36 | final TypeName actual = underTest.getType();
37 |
38 | // verify
39 | assertThat(actual)
40 | .isEqualTo(TypeName.OBJECT);
41 | }
42 |
43 | @Test
44 | public void getValue() throws Exception {
45 | // exercise
46 | final Object actual = underTest.getValue();
47 |
48 | // verify
49 | assertThat(actual)
50 | .isNull();
51 | }
52 | }
--------------------------------------------------------------------------------
/core/src/test/java/io/t28/json2java/core/json/JsonBooleanTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.TypeName;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import static io.t28.json2java.core.Assertions.assertThat;
24 |
25 | public class JsonBooleanTest {
26 | private JsonBoolean underTest;
27 |
28 | @Before
29 | public void setUp() throws Exception {
30 | underTest = new JsonBoolean(true);
31 | }
32 |
33 | @Test
34 | public void getType() throws Exception {
35 | // exercise
36 | final TypeName actual = underTest.getType();
37 |
38 | // verify
39 | assertThat(actual)
40 | .isEqualTo(TypeName.BOOLEAN);
41 | }
42 |
43 | @Test
44 | public void getValue() throws Exception {
45 | // exercise
46 | final Boolean actual = underTest.getValue();
47 |
48 | // verify
49 | assertThat(actual)
50 | .isNotNull()
51 | .isTrue();
52 | }
53 | }
--------------------------------------------------------------------------------
/core/src/test/java/io/t28/json2java/core/io/JavaBuilderImplTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.io;
18 |
19 | import com.squareup.javapoet.TypeSpec;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import javax.lang.model.element.Modifier;
24 |
25 | import static io.t28.json2java.core.Assertions.assertThat;
26 |
27 | public class JavaBuilderImplTest {
28 | private JavaBuilderImpl underTest;
29 |
30 | @Before
31 | public void setUp() throws Exception {
32 | underTest = new JavaBuilderImpl();
33 | }
34 |
35 | @Test
36 | public void buildShouldReturnJavaCode() throws Exception {
37 | final TypeSpec typeSpec = TypeSpec.classBuilder("Test")
38 | .addModifiers(Modifier.PUBLIC)
39 | .build();
40 |
41 | // exercise
42 | final String actual = underTest.build("io.t28.example", typeSpec);
43 |
44 | // verify
45 | assertThat(actual)
46 | .isEqualTo("package io.t28.example;\n\npublic class Test {\n}\n");
47 | }
48 | }
--------------------------------------------------------------------------------
/core/src/test/java/io/t28/json2java/core/json/JsonNumberTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.TypeName;
20 | import org.junit.Before;
21 | import org.junit.Test;
22 |
23 | import static io.t28.json2java.core.Assertions.assertThat;
24 |
25 | public class JsonNumberTest {
26 | private JsonNumber underTest;
27 |
28 | @Before
29 | public void setUp() throws Exception {
30 | underTest = new JsonNumber(int.class, 42);
31 | }
32 |
33 | @Test
34 | public void getType() throws Exception {
35 | // exercise
36 | final TypeName actual = underTest.getType();
37 |
38 | // verify
39 | assertThat(actual)
40 | .isEqualTo(TypeName.INT);
41 | }
42 |
43 | @Test
44 | public void getValue() throws Exception {
45 | // exercise
46 | final Number actual = underTest.getValue();
47 |
48 | // verify
49 | assertThat(actual)
50 | .isInstanceOf(Integer.class)
51 | .isEqualTo(42);
52 | }
53 | }
--------------------------------------------------------------------------------
/core/src/test/java/io/t28/json2java/core/json/JsonStringTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.squareup.javapoet.ClassName;
20 | import com.squareup.javapoet.TypeName;
21 | import org.junit.Before;
22 | import org.junit.Test;
23 |
24 | import static io.t28.json2java.core.Assertions.assertThat;
25 |
26 | public class JsonStringTest {
27 | private JsonString underTest;
28 |
29 | @Before
30 | public void setUp() throws Exception {
31 | underTest = new JsonString("foo");
32 | }
33 |
34 | @Test
35 | public void getType() throws Exception {
36 | // exercise
37 | final TypeName actual = underTest.getType();
38 |
39 | // verify
40 | assertThat(actual)
41 | .isEqualTo(ClassName.get(String.class));
42 | }
43 |
44 | @Test
45 | public void getValue() throws Exception {
46 | // exercise
47 | final String actual = underTest.getValue();
48 |
49 | // verify
50 | assertThat(actual)
51 | .isEqualTo("foo");
52 | }
53 | }
--------------------------------------------------------------------------------
/core/src/main/java/io/t28/json2java/core/json/JsonArray.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 Tatsuya Maki
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.t28.json2java.core.json;
18 |
19 | import com.google.common.collect.ImmutableList;
20 | import com.squareup.javapoet.ParameterizedTypeName;
21 | import com.squareup.javapoet.TypeName;
22 |
23 | import javax.annotation.CheckReturnValue;
24 | import javax.annotation.Nonnull;
25 | import java.util.LinkedList;
26 | import java.util.List;
27 | import java.util.stream.Stream;
28 |
29 | public class JsonArray extends JsonValue {
30 | private final List