diff --git a/build.gradle.kts b/build.gradle.kts index 948b313..7e82d59 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ group = "io.gitlab.jfronny.gson" -version = "1.2-SNAPSHOT" +version = "1.3-SNAPSHOT" subprojects { group = rootProject.group diff --git a/gson-compile-annotations/src/main/java/module-info.java b/gson-compile-annotations/src/main/java/module-info.java new file mode 100644 index 0000000..2e12a85 --- /dev/null +++ b/gson-compile-annotations/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module io.gitlab.jfronny.gson.compile.annotations { + exports io.gitlab.jfronny.gson.compile.annotations; +} \ No newline at end of file diff --git a/gson-compile-core/build.gradle.kts b/gson-compile-core/build.gradle.kts index 5c5b0cb..a78370a 100644 --- a/gson-compile-core/build.gradle.kts +++ b/gson-compile-core/build.gradle.kts @@ -9,8 +9,8 @@ repositories { } dependencies { - implementation("io.gitlab.jfronny:commons:1.0-SNAPSHOT") - api("io.gitlab.jfronny:commons-gson:1.0-SNAPSHOT") + implementation("io.gitlab.jfronny:commons:1.1-SNAPSHOT") + api("io.gitlab.jfronny:commons-gson:1.1-SNAPSHOT") } publishing { diff --git a/gson-compile-core/src/main/java/module-info.java b/gson-compile-core/src/main/java/module-info.java new file mode 100644 index 0000000..47d4a1c --- /dev/null +++ b/gson-compile-core/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module io.gitlab.jfronny.gson.compile.core { + requires io.gitlab.jfronny.commons.gson; + requires io.gitlab.jfronny.gson; + requires io.gitlab.jfronny.commons; + exports io.gitlab.jfronny.gson.compile.core; + exports io.gitlab.jfronny.gson.compile.util; +} \ No newline at end of file diff --git a/gson-compile-example-manifold/src/main/java/io/gitlab/jfronny/gson/Main.java b/gson-compile-example-manifold/src/main/java/io/gitlab/jfronny/gson/compile/example/manifold/Main.java similarity index 81% rename from gson-compile-example-manifold/src/main/java/io/gitlab/jfronny/gson/Main.java rename to gson-compile-example-manifold/src/main/java/io/gitlab/jfronny/gson/compile/example/manifold/Main.java index f9cc8d8..b5c90c6 100644 --- a/gson-compile-example-manifold/src/main/java/io/gitlab/jfronny/gson/Main.java +++ b/gson-compile-example-manifold/src/main/java/io/gitlab/jfronny/gson/compile/example/manifold/Main.java @@ -1,4 +1,4 @@ -package io.gitlab.jfronny.gson; +package io.gitlab.jfronny.gson.compile.example.manifold; import io.gitlab.jfronny.gson.compile.annotations.GSerializable; diff --git a/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/Main.java b/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/compile/example/Main.java similarity index 98% rename from gson-compile-example/src/main/java/io/gitlab/jfronny/gson/Main.java rename to gson-compile-example/src/main/java/io/gitlab/jfronny/gson/compile/example/Main.java index 1aaaeec..da93cb2 100644 --- a/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/Main.java +++ b/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/compile/example/Main.java @@ -1,4 +1,4 @@ -package io.gitlab.jfronny.gson; +package io.gitlab.jfronny.gson.compile.example; import io.gitlab.jfronny.gson.annotations.SerializedName; import io.gitlab.jfronny.gson.compile.annotations.*; diff --git a/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/Static.java b/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/compile/example/Static.java similarity index 82% rename from gson-compile-example/src/main/java/io/gitlab/jfronny/gson/Static.java rename to gson-compile-example/src/main/java/io/gitlab/jfronny/gson/compile/example/Static.java index 622b3be..c8e128e 100644 --- a/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/Static.java +++ b/gson-compile-example/src/main/java/io/gitlab/jfronny/gson/compile/example/Static.java @@ -1,4 +1,4 @@ -package io.gitlab.jfronny.gson; +package io.gitlab.jfronny.gson.compile.example; import io.gitlab.jfronny.gson.compile.annotations.GSerializable; diff --git a/gson-compile-example/src/main/java/module-info.java b/gson-compile-example/src/main/java/module-info.java new file mode 100644 index 0000000..6b2c908 --- /dev/null +++ b/gson-compile-example/src/main/java/module-info.java @@ -0,0 +1,5 @@ +module io.gitlab.jfronny.gson.compile.example { + requires static io.gitlab.jfronny.gson.compile.annotations; + requires io.gitlab.jfronny.gson; + exports io.gitlab.jfronny.gson.compile.example; +} \ No newline at end of file diff --git a/gson-compile-processor-core/build.gradle.kts b/gson-compile-processor-core/build.gradle.kts index 4f09fe7..6cac049 100644 --- a/gson-compile-processor-core/build.gradle.kts +++ b/gson-compile-processor-core/build.gradle.kts @@ -1,7 +1,6 @@ plugins { `java-library` id("jf.maven-publish") - id("jf.manifold") } repositories { @@ -11,7 +10,7 @@ repositories { dependencies { implementation("org.jetbrains:annotations:24.0.0") - implementation("io.gitlab.jfronny:commons:1.0-SNAPSHOT") + implementation("io.gitlab.jfronny:commons:1.1-SNAPSHOT") } publishing { diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/AbstractProcessor2.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/AbstractProcessor2.java index 1ab3b43..4a96263 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/AbstractProcessor2.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/AbstractProcessor2.java @@ -31,14 +31,14 @@ public abstract class AbstractProcessor2 extends AbstractProcessor { } catch (ClassNotFoundException e) { hasManifold = false; } - options = processingEnv.options; - message = processingEnv.messager; - filer = processingEnv.filer; - elements = processingEnv.elementUtils; - types = processingEnv.typeUtils; - sourceVersion = processingEnv.sourceVersion; - locale = processingEnv.locale; - isPreviewEnabled = processingEnv.isPreviewEnabled; + options = processingEnv.getOptions(); + message = processingEnv.getMessager(); + filer = processingEnv.getFiler(); + elements = processingEnv.getElementUtils(); + types = processingEnv.getTypeUtils(); + sourceVersion = processingEnv.getSourceVersion(); + locale = processingEnv.getLocale(); + isPreviewEnabled = processingEnv.isPreviewEnabled(); valueCreator = new ValueCreator(processingEnv); } diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/TypeHelper.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/TypeHelper.java index 5ae5f82..37b7d29 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/TypeHelper.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/TypeHelper.java @@ -10,11 +10,11 @@ public class TypeHelper { public static boolean isComplexType(TypeMirror type, Types typeUtils) { Element element = typeUtils.asElement(type); if (!(element instanceof TypeElement typeElement)) return false; - return !typeElement.typeParameters.isEmpty; + return !typeElement.getTypeParameters().isEmpty(); } public static boolean isGenericType(TypeMirror type) { - return type.kind == TypeKind.TYPEVAR; + return type.getKind() == TypeKind.TYPEVAR; } public static List getGenericTypes(TypeMirror type) { @@ -23,8 +23,8 @@ public class TypeHelper { return Collections.emptyList(); } ArrayList result = new ArrayList<>(); - for (TypeMirror argType : declaredType.typeArguments) { - if (argType.kind == TypeKind.TYPEVAR) { + for (TypeMirror argType : declaredType.getTypeArguments()) { + if (argType.getKind() == TypeKind.TYPEVAR) { result.add(argType); } } @@ -52,10 +52,10 @@ public class TypeHelper { public static boolean isInstance(DeclaredType type, String parentClassName, Types typeUtils) { if (type == null) return false; TypeElement element = (TypeElement) type.asElement(); - for (TypeMirror interfaceType : element.interfaces) { + for (TypeMirror interfaceType : element.getInterfaces()) { if (typeUtils.erasure(interfaceType).toString().equals(parentClassName)) return true; } - TypeMirror superclassType = element.superclass; + TypeMirror superclassType = element.getSuperclass(); if (superclassType != null) { if (typeUtils.erasure(superclassType).toString().equals(parentClassName)) { return true; @@ -67,7 +67,7 @@ public class TypeHelper { } public static String getDefaultValue(TypeMirror type) { - return switch (type.kind) { + return switch (type.getKind()) { case BYTE, SHORT, INT, LONG, FLOAT, CHAR, DOUBLE -> "0"; case BOOLEAN -> "false"; default -> "null"; diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ConstructionSource.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ConstructionSource.java index b3a08c8..b4a59da 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ConstructionSource.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ConstructionSource.java @@ -46,7 +46,7 @@ public sealed interface ConstructionSource { @Override public TypeElement getTargetClass() { - return targetClass != null ? targetClass : (targetClass = (TypeElement) constructor.enclosingElement); + return targetClass != null ? targetClass : (targetClass = (TypeElement) constructor.getEnclosingElement()); } @Override @@ -82,7 +82,7 @@ public sealed interface ConstructionSource { @Override public TypeElement getTargetClass() { - return targetClass != null ? targetClass : (targetClass = (TypeElement) types.asElement(method.returnType)); + return targetClass != null ? targetClass : (targetClass = (TypeElement) types.asElement(method.getReturnType())); } @Override @@ -135,7 +135,7 @@ public sealed interface ConstructionSource { @Override public TypeElement getTargetClass() { - return targetClass != null ? targetClass : (targetClass = (TypeElement) types.asElement(getBuildMethod().returnType)); + return targetClass != null ? targetClass : (targetClass = (TypeElement) types.asElement(getBuildMethod().getReturnType())); } @Override @@ -150,12 +150,12 @@ public sealed interface ConstructionSource { @Override public TypeElement getBuilderClass() { - return builderClass != null ? builderClass : (builderClass = (TypeElement) constructor.enclosingElement); + return builderClass != null ? builderClass : (builderClass = (TypeElement) constructor.getEnclosingElement()); } @Override public ExecutableElement getBuildMethod() { - return buildMethod != null ? buildMethod : (buildMethod = findBuildMethod((TypeElement) constructor.enclosingElement)); + return buildMethod != null ? buildMethod : (buildMethod = findBuildMethod((TypeElement) constructor.getEnclosingElement())); } } @@ -173,7 +173,7 @@ public sealed interface ConstructionSource { @Override public TypeElement getTargetClass() { - return targetClass != null ? targetClass : (targetClass = (TypeElement) types.asElement(getBuildMethod().returnType)); + return targetClass != null ? targetClass : (targetClass = (TypeElement) types.asElement(getBuildMethod().getReturnType())); } @Override @@ -188,12 +188,12 @@ public sealed interface ConstructionSource { @Override public TypeElement getBuilderClass() { - return builderClass != null ? builderClass : (builderClass = (TypeElement) types.asElement(method.returnType)); + return builderClass != null ? builderClass : (builderClass = (TypeElement) types.asElement(method.getReturnType())); } @Override public ExecutableElement getBuildMethod() { - return buildMethod != null ? buildMethod : (buildMethod = findBuildMethod((TypeElement) types.asElement(method.returnType))); + return buildMethod != null ? buildMethod : (buildMethod = findBuildMethod((TypeElement) types.asElement(method.getReturnType()))); } } @@ -237,7 +237,7 @@ public sealed interface ConstructionSource { ExecutableElement candidate = null; boolean foundMultipleCandidates = false; boolean isCandidateReasonableBuilderMethodName = false; - for (ExecutableElement method : ElementFilter.methodsIn(builderClass.enclosedElements)) { + for (ExecutableElement method : ElementFilter.methodsIn(builderClass.getEnclosedElements())) { if (isPossibleBuilderMethod(method, builderClass)) { if (candidate == null) { candidate = method; @@ -263,10 +263,10 @@ public sealed interface ConstructionSource { } // Last try, check to see if the immediate parent class makes sense. { - Element candidate = builderClass.enclosingElement; - if (candidate.kind == ElementKind.CLASS) { - for (ExecutableElement method : ElementFilter.methodsIn(builderClass.enclosedElements)) { - if (method.returnType.equals(candidate.asType()) && method.parameters.isEmpty) { + Element candidate = builderClass.getEnclosingElement(); + if (candidate.getKind() == ElementKind.CLASS) { + for (ExecutableElement method : ElementFilter.methodsIn(builderClass.getEnclosedElements())) { + if (method.getReturnType().equals(candidate.asType()) && method.getParameters().isEmpty()) { return method; } } @@ -283,10 +283,10 @@ public sealed interface ConstructionSource { */ @ApiStatus.Internal static boolean isPossibleBuilderMethod(ExecutableElement method, TypeElement builderClass) { - if (!method.parameters.isEmpty) return false; - TypeMirror returnType = method.returnType; - if (returnType.kind == TypeKind.VOID) return false; - if (returnType.kind.isPrimitive) return false; + if (!method.getParameters().isEmpty()) return false; + TypeMirror returnType = method.getReturnType(); + if (returnType.getKind() == TypeKind.VOID) return false; + if (returnType.getKind().isPrimitive()) return false; if (returnType.equals(builderClass.asType())) return false; String returnTypeName = returnType.toString(); return !(returnTypeName.startsWith("java.") || returnTypeName.startsWith("javax.") || returnTypeName.startsWith("android.")); @@ -294,7 +294,7 @@ public sealed interface ConstructionSource { @ApiStatus.Internal static boolean isReasonableBuilderMethodName(ExecutableElement method) { - String methodName = method.simpleName.toString().toLowerCase(Locale.ROOT); + String methodName = method.getSimpleName().toString().toLowerCase(Locale.ROOT); return methodName.startsWith("build") || methodName.startsWith("create"); } } diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Properties.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Properties.java index ab5176a..fdf52fe 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Properties.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Properties.java @@ -21,20 +21,20 @@ public class Properties extends DelegateList.Simple> { public static Properties build(Types types, ConstructionSource constructionSource, boolean isStatic) throws ElementException { Builder builder = new Builder(types, isStatic); // constructor params - if (constructionSource.constructionElement != null) { - for (VariableElement param : constructionSource.constructionElement.parameters) { + if (constructionSource.getConstructionElement() != null) { + for (VariableElement param : constructionSource.getConstructionElement().getParameters()) { builder.addConstructorParam(param); } } if (constructionSource instanceof ConstructionSource.Builder csb) { - var builderClass = csb.builderClass; - for (ExecutableElement method : ElementFilter.methodsIn(builderClass.enclosedElements)) { + var builderClass = csb.getBuilderClass(); + for (ExecutableElement method : ElementFilter.methodsIn(builderClass.getEnclosedElements())) { builder.addBuilderParam(method); } } - var targetClass = constructionSource.targetClass; + var targetClass = constructionSource.getTargetClass(); builder.addFieldsAndAccessors(targetClass); return builder.build(); @@ -94,32 +94,32 @@ public class Properties extends DelegateList.Simple> { public void addFieldsAndAccessors(TypeElement targetClass) { // accessors - for (ExecutableElement method : ElementFilter.methodsIn(targetClass.enclosedElements)) { + for (ExecutableElement method : ElementFilter.methodsIn(targetClass.getEnclosedElements())) { addGetter(targetClass, method); addSetter(targetClass, method); } // fields - for (VariableElement field : ElementFilter.fieldsIn(targetClass.enclosedElements)) { + for (VariableElement field : ElementFilter.fieldsIn(targetClass.getEnclosedElements())) { addField(field); } - for (TypeMirror superInterface : targetClass.interfaces) { + for (TypeMirror superInterface : targetClass.getInterfaces()) { addFieldsAndAccessors((TypeElement) types.asElement(superInterface)); } - TypeMirror superclass = targetClass.superclass; - if (superclass.kind != TypeKind.NONE && !superclass.toString().equals("java.lang.Object")) { + TypeMirror superclass = targetClass.getSuperclass(); + if (superclass.getKind() != TypeKind.NONE && !superclass.toString().equals("java.lang.Object")) { addFieldsAndAccessors((TypeElement) types.asElement(superclass)); } } public void addGetter(TypeElement classElement, ExecutableElement method) { - Set modifiers = method.modifiers; + Set modifiers = method.getModifiers(); if (modifiers.contains(Modifier.PRIVATE) || (isStatic != modifiers.contains(Modifier.STATIC)) - || method.returnType.kind == TypeKind.VOID - || !method.parameters.isEmpty + || method.getReturnType().getKind() == TypeKind.VOID + || !method.getParameters().isEmpty() || isMethodToSkip(classElement, method)) { return; } @@ -127,20 +127,20 @@ public class Properties extends DelegateList.Simple> { } public void addSetter(TypeElement classElement, ExecutableElement method) { - Set modifiers = method.modifiers; + Set modifiers = method.getModifiers(); if (modifiers.contains(Modifier.PRIVATE) || (isStatic != modifiers.contains(Modifier.STATIC)) - || method.returnType.kind != TypeKind.VOID - || method.parameters.size() != 1 + || method.getReturnType().getKind() != TypeKind.VOID + || method.getParameters().size() != 1 || isMethodToSkip(classElement, method) - || !method.simpleName.toString().startsWith("set")) { + || !method.getSimpleName().toString().startsWith("set")) { return; } setters.add(new Property.Setter(method)); } public void addField(VariableElement field) { - Set modifiers = field.modifiers; + Set modifiers = field.getModifiers(); if (isStatic != modifiers.contains(Modifier.STATIC)) return; fields.add(new Property.Field(field)); } @@ -152,7 +152,7 @@ public class Properties extends DelegateList.Simple> { } public void addBuilderParam(ExecutableElement method) { - if (method.getParameters().size() == 1 && method.simpleName.toString().startsWith("set")) { + if (method.getParameters().size() == 1 && method.getSimpleName().toString().startsWith("set")) { Property.Setter prop = new Property.Setter(method); builderParams.add(prop); params.add(prop); @@ -198,7 +198,7 @@ public class Properties extends DelegateList.Simple> { private void removeExtraFields() { fields.removeIf(field -> { - Set modifiers = field.element.modifiers; + Set modifiers = field.element.getModifiers(); return modifiers.contains(Modifier.PRIVATE) || modifiers.contains(Modifier.TRANSIENT); }); } @@ -206,19 +206,19 @@ public class Properties extends DelegateList.Simple> { private void removeGettersForTransientFields() { getters.removeIf(getter -> { Property field = findName(fields, getter); - return field != null && field.element.modifiers.contains(Modifier.TRANSIENT); + return field != null && field.element.getModifiers().contains(Modifier.TRANSIENT); }); } private void removeSettersForTransientFields() { getters.removeIf(getter -> { Property field = findName(fields, getter); - return field != null && field.element.modifiers.contains(Modifier.TRANSIENT); + return field != null && field.element.getModifiers().contains(Modifier.TRANSIENT); }); } private boolean isMethodToSkip(TypeElement classElement, ExecutableElement method) { - String name = method.simpleName.toString(); + String name = method.getSimpleName().toString(); if (METHODS_TO_SKIP.contains(name)) { return true; } @@ -231,10 +231,10 @@ public class Properties extends DelegateList.Simple> { List annotations = null; for (Property name : properties) { if (name == null) continue; - if (!name.annotations.isEmpty) { - if (annotations == null) annotations = new ArrayList<>(name.annotations); + if (!name.getAnnotations().isEmpty()) { + if (annotations == null) annotations = new ArrayList<>(name.getAnnotations()); else { - for (AnnotationMirror annotation : name.annotations) { + for (AnnotationMirror annotation : name.getAnnotations()) { if (annotations.contains(annotation)) { throw new ElementException("Duplicate annotation " + annotation + " found on " + name, name.element); } else annotations.add(annotation); @@ -264,7 +264,7 @@ public class Properties extends DelegateList.Simple> { } public static > N findName(List names, Property property) { - return names.stream().filter(n -> n.name.equals(property.name)).findFirst().orElse(null); + return names.stream().filter(n -> n.getName().equals(property.getName())).findFirst().orElse(null); } public static boolean containsName(List> properties, Property property) { @@ -272,6 +272,7 @@ public class Properties extends DelegateList.Simple> { } private static boolean isKotlinClass(TypeElement element) { - return element.annotationMirrors.stream().anyMatch(m -> m.annotationType.toString().equals("kotlin.Metadata")); + return element.getAnnotationMirrors().stream() + .anyMatch(m -> m.getAnnotationType().toString().equals("kotlin.Metadata")); } } diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Property.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Property.java index ceb6517..c63e979 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Property.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Property.java @@ -13,7 +13,7 @@ public abstract sealed class Property { public Property(T element) { this.element = element; - this.annotations = element.annotationMirrors; + this.annotations = element.getAnnotationMirrors(); } public T getElement() { @@ -26,7 +26,7 @@ public abstract sealed class Property { * @see #getCallableName() */ public String getName() { - return element.simpleName.toString(); + return element.getSimpleName().toString(); } /** @@ -113,7 +113,7 @@ public abstract sealed class Property { @Override public TypeMirror getType() { - return element.returnType; + return element.getReturnType(); } @ApiStatus.Internal @@ -123,7 +123,7 @@ public abstract sealed class Property { private String getBeanPrefix() { String name = super.getName(); - if (element.returnType.kind == TypeKind.BOOLEAN) { + if (element.getReturnType().getKind() == TypeKind.BOOLEAN) { if (name.length() > BEAN_PREFIX_BOOL.length() && name.startsWith(BEAN_PREFIX_BOOL)) { return BEAN_PREFIX_BOOL; } @@ -151,7 +151,7 @@ public abstract sealed class Property { public Setter(ExecutableElement method) { super(method.getParameters().get(0)); this.method = method; - name = Character.toLowerCase(method.simpleName.toString().charAt(3)) + method.simpleName.toString().substring(4); + name = Character.toLowerCase(method.getSimpleName().toString().charAt(3)) + method.getSimpleName().toString().substring(4); } @Override @@ -161,7 +161,7 @@ public abstract sealed class Property { @Override public String getCallableName() { - return method.simpleName.toString(); + return method.getSimpleName().toString(); } } } diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Value.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Value.java index ecf1eb1..304ce02 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Value.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/Value.java @@ -14,11 +14,11 @@ public class Value { public Value(ProcessingEnvironment env, ConstructionSource constructionSource) { this.env = env; this.constructionSource = constructionSource; - this.element = constructionSource.targetClass; + this.element = constructionSource.getTargetClass(); } public Properties getProperties() throws ElementException { - return properties != null ? properties : (properties = Properties.build(env.typeUtils, constructionSource, constructionSource.isStatic)); + return properties != null ? properties : (properties = Properties.build(env.getTypeUtils(), constructionSource, constructionSource.isStatic())); } public ConstructionSource getConstructionSource() { diff --git a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ValueCreator.java b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ValueCreator.java index 811a07c..580d0ad 100644 --- a/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ValueCreator.java +++ b/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/value/ValueCreator.java @@ -60,7 +60,7 @@ public class ValueCreator { */ public Value fromBuilderConstructor(ExecutableElement constructor) { checkKind(constructor, ElementKind.CONSTRUCTOR); - return create(new ConstructionSource.BuilderConstructor(env.typeUtils, constructor)); + return create(new ConstructionSource.BuilderConstructor(env.getTypeUtils(), constructor)); } /** @@ -73,7 +73,7 @@ public class ValueCreator { */ public Value fromFactory(ExecutableElement factory) { checkKind(factory, ElementKind.METHOD); - return create(new ConstructionSource.Factory(env.typeUtils, factory)); + return create(new ConstructionSource.Factory(env.getTypeUtils(), factory)); } /** @@ -87,7 +87,7 @@ public class ValueCreator { */ public Value fromBuilderFactory(ExecutableElement builderFactory) { checkKind(builderFactory, ElementKind.METHOD); - return create(new ConstructionSource.BuilderFactory(env.typeUtils, builderFactory)); + return create(new ConstructionSource.BuilderFactory(env.getTypeUtils(), builderFactory)); } /** @@ -120,27 +120,27 @@ public class ValueCreator { private static ExecutableElement findConstructorOrFactory(TypeElement klazz) throws ElementException { ExecutableElement noArgConstructor = null; - List constructors = ElementFilter.constructorsIn(klazz.enclosedElements); + List constructors = ElementFilter.constructorsIn(klazz.getEnclosedElements()); if (constructors.size() == 1) { - ExecutableElement constructor = constructors[0]; - if (constructor.parameters.isEmpty) { + ExecutableElement constructor = constructors.get(0); + if (constructor.getParameters().isEmpty()) { noArgConstructor = constructor; constructors.remove(0); } } - for (ExecutableElement method : ElementFilter.methodsIn(klazz.enclosedElements)) { - Set modifiers = method.modifiers; + for (ExecutableElement method : ElementFilter.methodsIn(klazz.getEnclosedElements())) { + Set modifiers = method.getModifiers(); if (modifiers.contains(Modifier.STATIC) && !modifiers.contains(Modifier.PRIVATE) - && method.returnType.equals(klazz.asType())) { + && method.getReturnType().equals(klazz.asType())) { constructors.add(method); } } - if (constructors.isEmpty) { + if (constructors.isEmpty()) { if (noArgConstructor != null) return noArgConstructor; else throw new ElementException("Lacking constructor or factory method", klazz); } - if (constructors.size() == 1) return constructors[0]; + if (constructors.size() == 1) return constructors.get(0); if (noArgConstructor != null) constructors.add(noArgConstructor); if (preferAnnotation != null) { List preferred = new ArrayList<>(); @@ -149,7 +149,7 @@ public class ValueCreator { preferred.add(constructor); } } - if (preferred.size() == 1) return preferred[0]; + if (preferred.size() == 1) return preferred.get(0); } List messages = new ArrayList<>(); messages.add(new ElementException.Message("More than one constructor or factory method found.", klazz)); @@ -158,7 +158,7 @@ public class ValueCreator { } private static void checkKind(Element element, ElementKind kind) { - if (element.kind != kind) { + if (element.getKind() != kind) { throw new IllegalArgumentException("Expected " + kind + " but got: " + element); } } diff --git a/gson-compile-processor-core/src/main/java/module-info.java b/gson-compile-processor-core/src/main/java/module-info.java new file mode 100644 index 0000000..93be3ea --- /dev/null +++ b/gson-compile-processor-core/src/main/java/module-info.java @@ -0,0 +1,7 @@ +module io.gitlab.jfronny.gson.compile.processor.core { + requires java.compiler; + requires static org.jetbrains.annotations; + requires io.gitlab.jfronny.commons; + exports io.gitlab.jfronny.gson.compile.processor.core; + exports io.gitlab.jfronny.gson.compile.processor.core.value; +} \ No newline at end of file diff --git a/gson-compile-processor/build.gradle.kts b/gson-compile-processor/build.gradle.kts index 505d4e4..c3e4d63 100644 --- a/gson-compile-processor/build.gradle.kts +++ b/gson-compile-processor/build.gradle.kts @@ -1,7 +1,6 @@ plugins { `java-library` id("jf.maven-publish") - id("jf.manifold") } repositories { @@ -13,7 +12,7 @@ dependencies { implementation(project(":gson-compile-processor-core")) implementation(project(":gson-compile-annotations")) implementation("org.jetbrains:annotations:24.0.0") - implementation("io.gitlab.jfronny:commons:1.0-SNAPSHOT") + implementation("io.gitlab.jfronny:commons:1.1-SNAPSHOT") implementation("com.squareup:javapoet:1.13.0") } diff --git a/gson-compile-processor/src/main/java/extensions/com/squareup/javapoet/ClassName/ClassNameExt.java b/gson-compile-processor/src/main/java/extensions/com/squareup/javapoet/ClassName/ClassNameExt.java deleted file mode 100644 index cc6c29a..0000000 --- a/gson-compile-processor/src/main/java/extensions/com/squareup/javapoet/ClassName/ClassNameExt.java +++ /dev/null @@ -1,22 +0,0 @@ -package extensions.com.squareup.javapoet.ClassName; - -import com.squareup.javapoet.ClassName; -import manifold.ext.rt.api.Extension; -import manifold.ext.rt.api.This; - -import java.util.List; - -@Extension -public class ClassNameExt { - public static String getSimpleName(@This ClassName thiz) { - return thiz.simpleName(); - } - - public static String getPackageName(@This ClassName thiz) { - return thiz.packageName(); - } - - public static List getSimpleNames(@This ClassName thiz) { - return thiz.simpleNames(); - } -} diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/Cl.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/Cl.java index c16bf51..9914177 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/Cl.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/Cl.java @@ -8,8 +8,8 @@ public class Cl { public static final ClassName GSON_ELEMENT = ClassName.get("io.gitlab.jfronny.gson", "JsonElement"); public static final ClassName GSON_WRITER = ClassName.get("io.gitlab.jfronny.gson.stream", "JsonWriter"); public static final ClassName GSON_READER = ClassName.get("io.gitlab.jfronny.gson.stream", "JsonReader"); - public static final ClassName GSON_TREE_READER = ClassName.get("io.gitlab.jfronny.gson.internal.bind", "JsonTreeReader"); - public static final ClassName GSON_TREE_WRITER = ClassName.get("io.gitlab.jfronny.gson.internal.bind", "JsonTreeWriter"); + public static final ClassName GSON_TREE_READER = ClassName.get("io.gitlab.jfronny.gson.stream", "JsonTreeReader"); + public static final ClassName GSON_TREE_WRITER = ClassName.get("io.gitlab.jfronny.gson.stream", "JsonTreeWriter"); public static final ClassName JSON_ADAPTER = ClassName.get("io.gitlab.jfronny.gson.annotations", "JsonAdapter"); public static final ClassName TYPE_TOKEN = ClassName.get("io.gitlab.jfronny.gson.reflect", "TypeToken"); public static final ClassName GSON_TOKEN = ClassName.get("io.gitlab.jfronny.gson.stream", "JsonToken"); @@ -17,7 +17,7 @@ public class Cl { public static final ClassName GSON_SYNTAX_EXCEPTION = ClassName.get("io.gitlab.jfronny.gson", "JsonSyntaxException"); public static final ClassName GCOMMENT = ClassName.get("io.gitlab.jfronny.gson.compile.annotations", "GComment"); - public static final ClassName GISO8601UTILS = ClassName.get("io.gitlab.jfronny.gson.internal.bind.util", "ISO8601Utils"); + public static final ClassName GISO8601UTILS = ClassName.get("io.gitlab.jfronny.gson.util", "ISO8601Utils"); public static final ClassName CCORE = ClassName.get("io.gitlab.jfronny.gson.compile.core", "CCore"); public static final ClassName MANIFOLD_EXTENSION = ClassName.get("manifold.ext.rt.api", "Extension"); diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/GsonCompileProcessor.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/GsonCompileProcessor.java index 59aeb84..806cec6 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/GsonCompileProcessor.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/GsonCompileProcessor.java @@ -48,9 +48,9 @@ public class GsonCompileProcessor extends AbstractProcessor2 { // Gather all serializable types for (TypeElement annotation : annotations) { for (Element element : roundEnvironment.getElementsAnnotatedWith(annotation)) { - for (AnnotationMirror mirror : element.annotationMirrors) { + for (AnnotationMirror mirror : element.getAnnotationMirrors()) { try { - if (mirror.annotationType.toString().equals(GSerializable.class.getCanonicalName())) { + if (mirror.getAnnotationType().toString().equals(GSerializable.class.getCanonicalName())) { var bld = new Object() { TypeMirror with = null; TypeMirror builder = null; @@ -59,27 +59,27 @@ public class GsonCompileProcessor extends AbstractProcessor2 { Boolean isStatic = null; }; elements.getElementValuesWithDefaults(mirror).forEach((executableElement, value) -> { - String name = executableElement.simpleName.toString(); + String name = executableElement.getSimpleName().toString(); switch (name) { case "with" -> { if (bld.with != null) throw new IllegalArgumentException("Duplicate annotation parameter: with"); - bld.with = (TypeMirror) value.value; + bld.with = (TypeMirror) value.getValue(); } case "builder" -> { if (bld.builder != null) throw new IllegalArgumentException("Duplicate annotation parameter: builder"); - bld.builder = (TypeMirror) value.value; + bld.builder = (TypeMirror) value.getValue(); } case "configure" -> { if (bld.configure != null) throw new IllegalArgumentException("Duplicate annotation parameter: configure"); - bld.configure = (TypeMirror) value.value; + bld.configure = (TypeMirror) value.getValue(); } case "generateAdapter" -> { if (bld.generateAdapter != null) throw new IllegalArgumentException("Duplicate annotation parameter: generateAdapter"); - bld.generateAdapter = (Boolean) value.value; + bld.generateAdapter = (Boolean) value.getValue(); } case "isStatic" -> { if (bld.isStatic != null) throw new IllegalArgumentException("Duplicate annotation parameter: isStatic"); - bld.isStatic = (Boolean) value.value; + bld.isStatic = (Boolean) value.getValue(); } default -> throw new IllegalArgumentException("Unexpected annotation parameter: " + name); } @@ -109,7 +109,7 @@ public class GsonCompileProcessor extends AbstractProcessor2 { } } for (var entry : seen.keySet().stream().collect(Collectors.groupingBy(ClassName::packageName)).entrySet()) { - Map, TypeSpec.Builder> known = entry.value.stream() + Map, TypeSpec.Builder> known = entry.getValue().stream() .collect(Collectors.toMap( ClassName::simpleNames, seen::get, @@ -132,8 +132,8 @@ public class GsonCompileProcessor extends AbstractProcessor2 { } // Add to parent class for (var entry1 : known.entrySet()) { - if (entry1.key.size() == 1) continue; - find(known, entry1.key.subList(0, entry1.key.size() - 1)).addType(entry1.value.build()); + if (entry1.getKey().size() == 1) continue; + find(known, entry1.getKey().subList(0, entry1.getKey().size() - 1)).addType(entry1.getValue().build()); } // Print // System.out.println("Got " + known.size() + " classes"); @@ -145,8 +145,8 @@ public class GsonCompileProcessor extends AbstractProcessor2 { // } // Write top-level classes for (var entry1 : known.entrySet()) { - if (entry1.key.size() == 1) { - JavaFile javaFile = JavaFile.builder(entry.key, entry1.value.build()) + if (entry1.getKey().size() == 1) { + JavaFile javaFile = JavaFile.builder(entry.getKey(), entry1.getValue().build()) .skipJavaLangImports(true) .indent(" ") .build(); @@ -163,35 +163,35 @@ public class GsonCompileProcessor extends AbstractProcessor2 { } private V find(Map, V> map, List key) { - for (var entry : map.entrySet()) if (entry.key.equals(key)) return entry.value; + for (var entry : map.entrySet()) if (entry.getKey().equals(key)) return entry.getValue(); return null; } private void process(SerializableClass toProcess, Set other) throws ElementException { - if (seen.containsKey(toProcess.generatedClassName)) return; // Don't process the same class more than once + if (seen.containsKey(toProcess.generatedClassName())) return; // Don't process the same class more than once - TypeName classType = toProcess.typeName; + TypeName classType = toProcess.getTypeName(); List typeVariables = new ArrayList<>(); - if (!toProcess.isStatic && classType instanceof ParameterizedTypeName type) { + if (!toProcess.isStatic() && classType instanceof ParameterizedTypeName type) { for (TypeName argument : type.typeArguments) { typeVariables.add(TypeVariableName.get(argument.toString())); } } - TypeSpec.Builder spec = TypeSpec.classBuilder(toProcess.generatedClassName.simpleName()) - .addOriginatingElement(toProcess.classElement) + TypeSpec.Builder spec = TypeSpec.classBuilder(toProcess.generatedClassName().simpleName()) + .addOriginatingElement(toProcess.classElement()) .addModifiers(Modifier.PUBLIC) .addTypeVariables(typeVariables); - seen.put(toProcess.generatedClassName, spec); + seen.put(toProcess.generatedClassName(), spec); - GProcessor processor = toProcess.isStatic ? staticProcessor : instanceProcessor; + GProcessor processor = toProcess.isStatic() ? staticProcessor : instanceProcessor; - if (toProcess.adapter != null) { - processor.generateDelegateToAdapter(spec, classType, toProcess.adapter); + if (toProcess.adapter() != null) { + processor.generateDelegateToAdapter(spec, classType, toProcess.adapter()); } else { - if (toProcess.generateAdapter) { - processor.generateDelegatingAdapter(spec, classType, toProcess.generatedClassName); + if (toProcess.generateAdapter()) { + processor.generateDelegatingAdapter(spec, classType, toProcess.generatedClassName()); } processor.generateSerialisation(spec, toProcess, typeVariables, other); } diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/SerializableClass.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/SerializableClass.java index 1ff9bc3..ea7994a 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/SerializableClass.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/SerializableClass.java @@ -11,8 +11,8 @@ import javax.lang.model.type.TypeMirror; public record SerializableClass(TypeElement classElement, ClassName generatedClassName, @Nullable TypeMirror adapter, @Nullable TypeMirror builder, @Nullable TypeMirror configure, boolean generateAdapter, boolean isStatic) { public static SerializableClass of(TypeElement element, @Nullable TypeMirror with, @Nullable TypeMirror builder, @Nullable TypeMirror configure, boolean generateAdapter, boolean isStatic, boolean manifold) throws ElementException { ClassName className = ClassName.get(element); - String pkg = manifold ? "gsoncompile.extensions." + className.packageName + '.' + className.simpleNames[0] : className.packageName; - ClassName generatedClassName = ClassName.get(pkg, "GC_" + className.simpleNames[0], className.simpleNames.subList(1, className.simpleNames.size()).toArray(String[]::new)); + String pkg = manifold ? "gsoncompile.extensions." + className.packageName() + '.' + className.simpleNames().get(0) : className.packageName(); + ClassName generatedClassName = ClassName.get(pkg, "GC_" + className.simpleNames().get(0), className.simpleNames().subList(1, className.simpleNames().size()).toArray(String[]::new)); return new SerializableClass(element, generatedClassName, voidToNull(with), voidToNull(builder), voidToNull(configure), generateAdapter, isStatic).validate(); } diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/AdapterAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/AdapterAdapter.java index b5ade0b..53fd38a 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/AdapterAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/AdapterAdapter.java @@ -38,7 +38,7 @@ public abstract class AdapterAdapter.Hydrated> exten if (TypeHelper.isComplexType(type, typeUtils)) { TypeName typeTokenType = ParameterizedTypeName.get(Cl.TYPE_TOKEN, typeName); List typeParams = TypeHelper.getGenericTypes(type); - if (typeParams.isEmpty) { + if (typeParams.isEmpty()) { code.add("new $T() {}", typeTokenType); } else { code.add("($T) $T.getParameterized($T.class, ", typeTokenType, Cl.TYPE_TOKEN, typeUtils.erasure(type)); diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/Adapters.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/Adapters.java index 13d3b8a..0a4cbee 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/Adapters.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/Adapters.java @@ -37,7 +37,7 @@ public class Adapters { } private static void withAdapter(Property prop, TypeSpec.Builder klazz, CodeBlock.Builder code, List typeVariables, Set otherAdapters, Messager message, Consumer.Hydrated> action) { - withAdapter(klazz, code, typeVariables, otherAdapters, prop.type, prop.name, prop.annotations, prop.element, message, action); + withAdapter(klazz, code, typeVariables, otherAdapters, prop.getType(), prop.getName(), prop.getAnnotations(), prop.getElement(), message, action); } public static void generateRead(TypeSpec.Builder klazz, CodeBlock.Builder code, List typeVariables, Set other, TypeMirror type, String propName, List annotations, Element sourceElement, Messager message) { diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/ArrayAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/ArrayAdapter.java index 7fb5bd6..ef33a9a 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/ArrayAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/ArrayAdapter.java @@ -30,7 +30,7 @@ public class ArrayAdapter extends Adapter { @Override protected void afterHydrate() { type = TypeHelper.asArrayType(super.type); - componentType = type == null ? null : type.componentType; + componentType = type == null ? null : type.getComponentType(); } @Override @@ -41,7 +41,7 @@ public class ArrayAdapter extends Adapter { .beginControlFlow("if ($N == null)", argName) .addStatement("if (writer.getSerializeNulls()) writer.nullValue()") .nextControlFlow("else"); - generateWrite(code, componentType, argName, componentType.annotationMirrors, () -> code.add(argName)); + generateWrite(code, componentType, argName, componentType.getAnnotationMirrors(), () -> code.add(argName)); code.endControlFlow().endControlFlow(); } @@ -51,7 +51,7 @@ public class ArrayAdapter extends Adapter { // Coerce kode.beginControlFlow("if (reader.isLenient() && reader.peek() != $T.BEGIN_ARRAY)", Cl.GSON_TOKEN) .add("return new $T[] { ", componentType); - generateRead(kode, componentType, argName, componentType.annotationMirrors); + generateRead(kode, componentType, argName, componentType.getAnnotationMirrors()); kode.add(" };\n").endControlFlow(); kode.addStatement("$T<$T> list = new $T<>()", List.class, componentType, ArrayList.class) @@ -62,7 +62,7 @@ public class ArrayAdapter extends Adapter { .addStatement("list.add(null)") .nextControlFlow("else") .add("list.add("); - generateRead(kode, componentType, argName, componentType.annotationMirrors); + generateRead(kode, componentType, argName, componentType.getAnnotationMirrors()); kode.add(");\n") .endControlFlow() .endControlFlow() diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/CollectionAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/CollectionAdapter.java index 51c8c31..502e5e9 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/CollectionAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/CollectionAdapter.java @@ -40,15 +40,15 @@ public class CollectionAdapter extends Adapter { type = TypeHelper.asDeclaredType(super.type); componentType = null; if (type == null) return; - List typeArguments = type.typeArguments; + List typeArguments = type.getTypeArguments(); if (typeArguments.size() == 0) { type = null; } else { componentType = typeArguments.get(0); String ts = TypeHelper.asDeclaredType(typeUtils.erasure(type)).asElement().toString(); for (Map.Entry, List>> entry : SUPPORTED.entrySet()) { - if (entry.key.getCanonicalName().equals(ts)) { - implType = TypeName.get(entry.value[0]); + if (entry.getKey().getCanonicalName().equals(ts)) { + implType = TypeName.get(entry.getValue().get(0)); return; } for (Class klazz : entry.getValue()) { @@ -72,7 +72,7 @@ public class CollectionAdapter extends Adapter { .beginControlFlow("if ($N == null)", argName) .addStatement("if (writer.getSerializeNulls()) writer.nullValue()") .nextControlFlow("else"); - generateWrite(code, componentType, argName, componentType.annotationMirrors, () -> code.add(argName)); + generateWrite(code, componentType, argName, componentType.getAnnotationMirrors(), () -> code.add(argName)); code.endControlFlow().endControlFlow().addStatement("writer.endArray()"); } @@ -83,7 +83,7 @@ public class CollectionAdapter extends Adapter { // Coerce kode.beginControlFlow("if (reader.isLenient() && reader.peek() != $T.BEGIN_ARRAY)", Cl.GSON_TOKEN) .add("list.add("); - generateRead(kode, componentType, argName, componentType.annotationMirrors); + generateRead(kode, componentType, argName, componentType.getAnnotationMirrors()); kode.add(");\n").addStatement("return list").endControlFlow(); kode.addStatement("reader.beginArray()") @@ -93,7 +93,7 @@ public class CollectionAdapter extends Adapter { .addStatement("list.add(null)") .nextControlFlow("else") .add("list.add("); - generateRead(kode, componentType, argName, componentType.annotationMirrors); + generateRead(kode, componentType, argName, componentType.getAnnotationMirrors()); kode.add(");\n") .endControlFlow() .endControlFlow() diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/DeclaredAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/DeclaredAdapter.java index 4dd03a7..d32cc69 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/DeclaredAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/DeclaredAdapter.java @@ -57,10 +57,10 @@ public class DeclaredAdapter extends AdapterAdapter { private static DeclaredType findTypeAdapterClass(List annotations) { for (AnnotationMirror annotation : annotations) { - String typeName = annotation.annotationType.toString(); + String typeName = annotation.getAnnotationType().toString(); if (typeName.equals(Cl.JSON_ADAPTER.toString())) { - Map elements = annotation.elementValues; - if (!elements.isEmpty) { + Map elements = annotation.getElementValues(); + if (!elements.isEmpty()) { AnnotationValue value = elements.values().iterator().next(); return (DeclaredType) value.getValue(); } diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/EnumAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/EnumAdapter.java index dfd80dd..a4a6975 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/EnumAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/EnumAdapter.java @@ -23,7 +23,7 @@ public class EnumAdapter extends Adapter { tel = null; DeclaredType declared = TypeHelper.asDeclaredType(type); if (declared == null) return; - if (declared.asElement().kind != ElementKind.ENUM) return; + if (declared.asElement().getKind() != ElementKind.ENUM) return; tel = declared; } diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/MapAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/MapAdapter.java index 50e6cd3..728ebdb 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/MapAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/MapAdapter.java @@ -36,20 +36,20 @@ public class MapAdapter extends Adapter { type = TypeHelper.asDeclaredType(super.type); componentType1 = componentType2 = null; if (type == null) return; - List typeArguments = type.typeArguments; + List typeArguments = type.getTypeArguments(); if (typeArguments.size() != 2) { type = null; } else { - componentType1 = typeArguments[0]; + componentType1 = typeArguments.get(0); if (!isValidKey(componentType1)) { type = null; componentType1 = null; return; } - componentType2 = typeArguments[1]; + componentType2 = typeArguments.get(1); String ts = TypeHelper.asDeclaredType(typeUtils.erasure(type)).asElement().toString(); if (Map.class.getCanonicalName().equals(ts)) { - implType = TypeName.get(SUPPORTED[0]); + implType = TypeName.get(SUPPORTED.get(0)); return; } for (Class klazz : SUPPORTED) { @@ -66,7 +66,7 @@ public class MapAdapter extends Adapter { private boolean isValidKey(TypeMirror tm) { if (tm.toString().equals(String.class.getCanonicalName())) return true; if (tm.toString().equals(UUID.class.getCanonicalName())) return true; - if (unbox(tm).kind.isPrimitive) return true; + if (unbox(tm).getKind().isPrimitive()) return true; if (isEnum(tm)) return true; return false; } @@ -78,8 +78,8 @@ public class MapAdapter extends Adapter { else if (componentType1.toString().equals(UUID.class.getCanonicalName())) { kode.add("name == null ? null : $T.fromString(name)", UUID.class); } - else if (unbox(componentType1).kind.isPrimitive) { - kode.add("name == null ? null : " + switch (unbox(componentType1).kind) { + else if (unbox(componentType1).getKind().isPrimitive()) { + kode.add("name == null ? null : " + switch (unbox(componentType1).getKind()) { case BOOLEAN -> "Boolean.parseBoolean(name)"; case BYTE -> "Byte.parseByte(name)"; case SHORT -> "Short.parseShort(name)"; @@ -88,7 +88,7 @@ public class MapAdapter extends Adapter { case CHAR -> "name.length() == 0 ? '\\0' : name.charAt(0)"; case FLOAT -> "Float.parseFloat(name)"; case DOUBLE -> "Double.parseDouble(name)"; - default -> throw new IllegalArgumentException("Unsupported primitive: " + unbox(componentType1).kind); + default -> throw new IllegalArgumentException("Unsupported primitive: " + unbox(componentType1).getKind()); }); } else if (isEnum(componentType1)) { @@ -123,7 +123,7 @@ public class MapAdapter extends Adapter { private boolean isEnum(TypeMirror tm) { DeclaredType declared = TypeHelper.asDeclaredType(tm); - return declared != null && declared.asElement().kind == ElementKind.ENUM; + return declared != null && declared.asElement().getKind() == ElementKind.ENUM; } @Override @@ -144,7 +144,7 @@ public class MapAdapter extends Adapter { .beginControlFlow("if (value$N == null)", argName) .addStatement("if (writer.getSerializeNulls()) writer.nullValue()") .nextControlFlow("else"); - generateWrite(code, componentType2, "value" + argName, componentType2.annotationMirrors, () -> code.add("value" + argName)); + generateWrite(code, componentType2, "value" + argName, componentType2.getAnnotationMirrors(), () -> code.add("value" + argName)); code.endControlFlow().endControlFlow().endControlFlow().addStatement("writer.endObject()"); } @@ -165,7 +165,7 @@ public class MapAdapter extends Adapter { .add("map.put("); generateConvertKey(kode); kode.add(", "); - generateRead(kode, componentType2, argName, componentType2.annotationMirrors); + generateRead(kode, componentType2, argName, componentType2.getAnnotationMirrors()); kode.addStatement(")") .endControlFlow() .endControlFlow() diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/OtherSerializableAdapter.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/OtherSerializableAdapter.java index 9e3c300..3b96980 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/OtherSerializableAdapter.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/impl/OtherSerializableAdapter.java @@ -26,9 +26,9 @@ public class OtherSerializableAdapter extends AdapterAdapter { public class Hydrated extends Adapter.Hydrated { @Override public boolean applies() { - return unboxedType.kind.isPrimitive; + return unboxedType.getKind().isPrimitive(); } @Override @@ -23,7 +23,7 @@ public class PrimitiveAdapter extends Adapter { @Override public void generateRead() { - code.add(switch (unboxedType.kind) { + code.add(switch (unboxedType.getKind()) { case BOOLEAN -> "reader.nextBoolean()"; case BYTE -> "(byte) reader.nextInt()"; case SHORT -> "(short) reader.nextInt()"; @@ -32,7 +32,7 @@ public class PrimitiveAdapter extends Adapter { case CHAR -> "(char) reader.nextInt()"; case FLOAT -> "(float) reader.nextDouble()"; case DOUBLE -> "reader.nextDouble()"; - default -> throw new IllegalArgumentException("Unsupported primitive: " + unboxedType.kind); + default -> throw new IllegalArgumentException("Unsupported primitive: " + unboxedType.getKind()); }); } } diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/GProcessor.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/GProcessor.java index 9e33a12..32e90b4 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/GProcessor.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/GProcessor.java @@ -38,12 +38,12 @@ public abstract class GProcessor { public abstract void generateSerialisation(TypeSpec.Builder spec, SerializableClass self, List typeVariables, Set otherAdapters) throws ElementException; protected String getSerializedName(Property property) { - for (AnnotationMirror annotationMirror : property.annotations) { - if (annotationMirror.annotationType.asElement().toString().equals(Cl.SERIALIZED_NAME.toString())) { - return (String) annotationMirror.elementValues.values().iterator().next().value; + for (AnnotationMirror annotationMirror : property.getAnnotations()) { + if (annotationMirror.getAnnotationType().asElement().toString().equals(Cl.SERIALIZED_NAME.toString())) { + return (String) annotationMirror.getElementValues().values().iterator().next().getValue(); } } - return property.name; + return property.getName(); } protected MethodSpec.Builder extension(MethodSpec.Builder method) { @@ -64,9 +64,9 @@ public abstract class GProcessor { } protected void generateComments(Property prop, CodeBlock.Builder code) { - for (AnnotationMirror annotation : prop.annotations) { - if (annotation.annotationType.asElement().toString().equals(Cl.GCOMMENT.toString())) { - String comment = (String) annotation.elementValues.values().iterator().next().value; + for (AnnotationMirror annotation : prop.getAnnotations()) { + if (annotation.getAnnotationType().asElement().toString().equals(Cl.GCOMMENT.toString())) { + String comment = (String) annotation.getElementValues().values().iterator().next().getValue(); code.addStatement("if (writer.isLenient()) writer.comment($S)", comment); } } diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/InstanceProcessor.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/InstanceProcessor.java index b37487d..fbc35d1 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/InstanceProcessor.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/InstanceProcessor.java @@ -31,7 +31,7 @@ public class InstanceProcessor extends GProcessor { .addParameter(Cl.GSON_WRITER, "writer") .addParameter(classType, "value") .addException(IOException.class) - .addCode(generatedClassName.simpleName + ".write(value, writer);") + .addCode(generatedClassName.simpleName() + ".write(value, writer);") .build()) .addMethod(MethodSpec.methodBuilder("read") .addAnnotation(Override.class) @@ -39,7 +39,7 @@ public class InstanceProcessor extends GProcessor { .addParameter(Cl.GSON_READER, "reader") .addException(IOException.class) .returns(classType) - .addCode("return " + generatedClassName.simpleName + ".read(reader);") + .addCode("return " + generatedClassName.simpleName() + ".read(reader);") .build()) .build() ); @@ -52,9 +52,9 @@ public class InstanceProcessor extends GProcessor { // !!!WARNING!!! @Override public void generateSerialisation(TypeSpec.Builder spec, SerializableClass self, List typeVariables, Set otherAdapters) throws ElementException { - Value value = self.builder == null ? valueCreator.from(self.classElement, false) : valueCreator.from(TypeHelper.asDeclaredType(self.builder).asElement(), true); - ConstructionSource constructionSource = value.constructionSource; - Properties properties = value.properties; + Value value = self.builder() == null ? valueCreator.from(self.classElement(), false) : valueCreator.from(TypeHelper.asDeclaredType(self.builder()).asElement(), true); + ConstructionSource constructionSource = value.getConstructionSource(); + Properties properties = value.getProperties(); // public static void write(JsonWriter writer, T value) throws IOException { @@ -67,16 +67,16 @@ public class InstanceProcessor extends GProcessor { code.addStatement("writer.beginObject()"); for (Property.Field param : properties.fields) { if (Properties.containsName(properties.getters, param)) continue; - Runnable writeGet = () -> code.add("value.$N", param.callableName); - if (param.type.kind.isPrimitive) { + Runnable writeGet = () -> code.add("value.$N", param.getCallableName()); + if (param.getType().getKind().isPrimitive()) { generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet); } else { - code.beginControlFlow("if (value.$N != null || writer.getSerializeNulls())", param.callableName); + code.beginControlFlow("if (value.$N != null || writer.getSerializeNulls())", param.getCallableName()); generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); - code.addStatement("if (value.$N == null) writer.nullValue()", param.callableName); + code.addStatement("if (value.$N == null) writer.nullValue()", param.getCallableName()); code.beginControlFlow("else"); Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet); code.endControlFlow(); @@ -84,25 +84,25 @@ public class InstanceProcessor extends GProcessor { } } for (Property.Getter param : properties.getters) { - if (param.type.kind.isPrimitive) { + if (param.getType().getKind().isPrimitive()) { generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); - Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("value.$N()", param.callableName)); + Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("value.$N()", param.getCallableName())); } else { - code.addStatement("$T $L$N = value.$N()", param.type, "$", param.callableName, param.callableName); - code.beginControlFlow("if ($L$N != null || writer.getSerializeNulls())", "$", param.callableName); + code.addStatement("$T $L$N = value.$N()", param.getType(), "$", param.getCallableName(), param.getCallableName()); + code.beginControlFlow("if ($L$N != null || writer.getSerializeNulls())", "$", param.getCallableName()); generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); - code.addStatement("if ($L$N == null) writer.nullValue()", "$", param.callableName); + code.addStatement("if ($L$N == null) writer.nullValue()", "$", param.getCallableName()); code.beginControlFlow("else"); - Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$L$N", "$", param.callableName)); + Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$L$N", "$", param.getCallableName())); code.endControlFlow(); code.endControlFlow(); } } code.addStatement("writer.endObject()"); - spec.addMethod(extension(MethodSpec.methodBuilder("write"), self.typeName) + spec.addMethod(extension(MethodSpec.methodBuilder("write"), self.getTypeName()) .addModifiers(Modifier.PUBLIC, Modifier.STATIC) .addParameter(Cl.GSON_WRITER, "writer") .addException(IOException.class) @@ -121,7 +121,7 @@ public class InstanceProcessor extends GProcessor { boolean isEmpty = true; for (Property param : properties.names) { isEmpty = false; - code.addStatement("$T _$N = $L", param.type, param.name, TypeHelper.getDefaultValue(param.type)); + code.addStatement("$T _$N = $L", param.getType(), param.getName(), TypeHelper.getDefaultValue(param.getType())); } if (isEmpty) { code.addStatement("reader.skipValue()"); @@ -130,16 +130,16 @@ public class InstanceProcessor extends GProcessor { .beginControlFlow("while (reader.hasNext())") .beginControlFlow("switch (reader.nextName())"); for (Property param : properties.names) { - if (param.type.kind.isPrimitive) { - code.add("case $S -> _$N = ", getSerializedName(param), param.name); + if (param.getType().getKind().isPrimitive()) { + code.add("case $S -> _$N = ", getSerializedName(param), param.getName()); Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message); code.add(";\n"); } else { code.beginControlFlow("case $S ->", getSerializedName(param)) .beginControlFlow("if (reader.peek() == $T.NULL)", Cl.GSON_TOKEN) .addStatement("reader.nextNull()") - .addStatement("_$N = null", param.name); - code.unindent().add("} else _$N = ", param.name); + .addStatement("_$N = null", param.getName()); + code.unindent().add("} else _$N = ", param.getName()); Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message); code.add(";\n") .endControlFlow(); @@ -153,48 +153,48 @@ public class InstanceProcessor extends GProcessor { .addStatement("reader.endObject()"); } - code.addStatement("$T result", self.typeName); - ClassName creatorName = ClassName.get((TypeElement) constructionSource.constructionElement.enclosingElement); + code.addStatement("$T result", self.getTypeName()); + ClassName creatorName = ClassName.get((TypeElement) constructionSource.getConstructionElement().getEnclosingElement()); if (constructionSource instanceof ConstructionSource.Builder builder) { StringBuilder args = new StringBuilder(); for (Property.ConstructorParam param : properties.constructorParams) { - args.append(", _").append(param.name); + args.append(", _").append(param.getName()); } - code.add("$T builder = ", builder.builderClass); - if (constructionSource.isConstructor) { - code.add("new $T($L)", builder.builderClass, args.length() > 0 ? args.substring(2) : ""); + code.add("$T builder = ", builder.getBuilderClass()); + if (constructionSource.isConstructor()) { + code.add("new $T($L)", builder.getBuilderClass(), args.length() > 0 ? args.substring(2) : ""); } else { - code.add("$T.$N($L)", creatorName, self.classElement.simpleName, args.length() > 0 ? args.substring(2) : ""); + code.add("$T.$N($L)", creatorName, self.classElement().getSimpleName(), args.length() > 0 ? args.substring(2) : ""); } code.add(";\n"); for (Property.Setter param : properties.builderParams) { - code.addStatement("builder.$N(_$N)", param.callableName, param.name); + code.addStatement("builder.$N(_$N)", param.getCallableName(), param.getName()); } - code.addStatement("result = builder.$N()", builder.buildMethod.simpleName); + code.addStatement("result = builder.$N()", builder.getBuildMethod().getSimpleName()); } else { StringBuilder args = new StringBuilder(); for (Property.Param param : properties.params) { - args.append(", _").append(param.name); + args.append(", _").append(param.getName()); } - if (constructionSource.isConstructor) { - code.addStatement("result = new $T($L)", self.typeName, args.length() > 0 ? args.substring(2) : ""); + if (constructionSource.isConstructor()) { + code.addStatement("result = new $T($L)", self.getTypeName(), args.length() > 0 ? args.substring(2) : ""); } else { - code.addStatement("result = $T.$N($L)", creatorName, constructionSource.constructionElement.simpleName, args.length() > 0 ? args.substring(2) : ""); + code.addStatement("result = $T.$N($L)", creatorName, constructionSource.getConstructionElement().getSimpleName(), args.length() > 0 ? args.substring(2) : ""); } } for (Property.Setter setter : properties.setters) { - code.addStatement("result.$N(_$N)", setter.callableName, setter.name); + code.addStatement("result.$N(_$N)", setter.getCallableName(), setter.getName()); } for (Property.Field field : properties.fields) { if (Properties.containsName(properties.setters, field)) continue; if (Properties.containsName(properties.params, field)) continue; - code.addStatement("result.$N = _$N", field.name, field.callableName); + code.addStatement("result.$N = _$N", field.getName(), field.getCallableName()); } code.addStatement("return result"); spec.addMethod(extension(MethodSpec.methodBuilder("read")) .addModifiers(Modifier.PUBLIC, Modifier.STATIC) - .returns(self.typeName) + .returns(self.getTypeName()) .addParameter(Cl.GSON_READER, "reader") .addException(IOException.class) .addCode(code.build()) diff --git a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/StaticProcessor.java b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/StaticProcessor.java index 4c0ba8d..7f7b50b 100644 --- a/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/StaticProcessor.java +++ b/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/gprocessor/StaticProcessor.java @@ -30,8 +30,8 @@ public class StaticProcessor extends GProcessor { // !!!WARNING!!! @Override public void generateSerialisation(TypeSpec.Builder spec, SerializableClass self, List typeVariables, Set otherAdapters) throws ElementException { - Value value = valueCreator.fromStatic(self.classElement); - Properties properties = value.properties; + Value value = valueCreator.fromStatic(self.classElement()); + Properties properties = value.getProperties(); // public static void write(JsonWriter writer) throws IOException { @@ -39,16 +39,16 @@ public class StaticProcessor extends GProcessor { code.addStatement("writer.beginObject()"); for (Property.Field param : properties.fields) { if (Properties.containsName(properties.getters, param)) continue; - Runnable writeGet = () -> code.add("$T.$N", self.typeName, param.callableName); - if (param.type.kind.isPrimitive) { + Runnable writeGet = () -> code.add("$T.$N", self.getTypeName(), param.getCallableName()); + if (param.getType().getKind().isPrimitive()) { generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet); } else { - code.beginControlFlow("if ($T.$N != null || writer.getSerializeNulls())", self.typeName, param.callableName); + code.beginControlFlow("if ($T.$N != null || writer.getSerializeNulls())", self.getTypeName(), param.getCallableName()); generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); - code.addStatement("if ($T.$N == null) writer.nullValue()", self.typeName, param.callableName); + code.addStatement("if ($T.$N == null) writer.nullValue()", self.getTypeName(), param.getCallableName()); code.beginControlFlow("else"); Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, writeGet); code.endControlFlow(); @@ -56,18 +56,18 @@ public class StaticProcessor extends GProcessor { } } for (Property.Getter param : properties.getters) { - if (param.type.kind.isPrimitive) { + if (param.getType().getKind().isPrimitive()) { generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); - Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$T.$N()", self.typeName, param.callableName)); + Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$T.$N()", self.getTypeName(), param.getCallableName())); } else { - code.addStatement("$T $L$N = $T.$N()", param.type, "$", param.callableName, self.typeName, param.callableName); - code.beginControlFlow("if ($L$N != null || writer.getSerializeNulls())", "$", param.callableName); + code.addStatement("$T $L$N = $T.$N()", param.getType(), "$", param.getCallableName(), self.getTypeName(), param.getCallableName()); + code.beginControlFlow("if ($L$N != null || writer.getSerializeNulls())", "$", param.getCallableName()); generateComments(param, code); code.addStatement("writer.name($S)", getSerializedName(param)); - code.addStatement("if ($L$N == null) writer.nullValue()", "$", param.callableName); + code.addStatement("if ($L$N == null) writer.nullValue()", "$", param.getCallableName()); code.beginControlFlow("else"); - Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$L$N", "$", param.callableName)); + Adapters.generateWrite(param, spec, code, typeVariables, otherAdapters, message, () -> code.add("$L$N", "$", param.getCallableName())); code.endControlFlow(); code.endControlFlow(); } @@ -93,7 +93,7 @@ public class StaticProcessor extends GProcessor { boolean isEmpty = true; for (Property param : properties.names) { isEmpty = false; - code.addStatement("$T.$N = $L", self.typeName, param.name, TypeHelper.getDefaultValue(param.type)); + code.addStatement("$T.$N = $L", self.getTypeName(), param.getName(), TypeHelper.getDefaultValue(param.getType())); } if (isEmpty) { code.addStatement("reader.skipValue()"); @@ -102,16 +102,16 @@ public class StaticProcessor extends GProcessor { .beginControlFlow("while (reader.hasNext())") .beginControlFlow("switch (reader.nextName())"); for (Property param : properties.names) { - if (param.type.kind.isPrimitive) { - code.add("case $S -> $T.$N = ", getSerializedName(param), self.typeName, param.name); + if (param.getType().getKind().isPrimitive()) { + code.add("case $S -> $T.$N = ", getSerializedName(param), self.getTypeName(), param.getName()); Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message); code.add(";\n"); } else { code.beginControlFlow("case $S ->", getSerializedName(param)) .beginControlFlow("if (reader.peek() == $T.NULL)", Cl.GSON_TOKEN) .addStatement("reader.nextNull()") - .addStatement("$T.$N = null", self.typeName, param.name); - code.unindent().add("} else $T.$N = ", self.typeName, param.name); + .addStatement("$T.$N = null", self.getTypeName(), param.getName()); + code.unindent().add("} else $T.$N = ", self.getTypeName(), param.getName()); Adapters.generateRead(param, spec, code, typeVariables, otherAdapters, message); code.add(";\n") .endControlFlow(); diff --git a/gson-compile-processor/src/main/java/module-info.java b/gson-compile-processor/src/main/java/module-info.java new file mode 100644 index 0000000..c79099b --- /dev/null +++ b/gson-compile-processor/src/main/java/module-info.java @@ -0,0 +1,8 @@ +module io.gitlab.jfronny.gson.compile.processor { + requires com.squareup.javapoet; + requires java.compiler; + requires io.gitlab.jfronny.gson.compile.processor.core; + requires io.gitlab.jfronny.commons; + requires io.gitlab.jfronny.gson.compile.annotations; + requires static org.jetbrains.annotations; +} \ No newline at end of file