From b72ec9a3679731150f41488431353a8f8d027794 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Wed, 27 Mar 2024 17:31:29 +0000 Subject: [PATCH 01/15] Delete existing class files to avoid JDK/IntelliJ bugs https://github.com/Randgalt/record-builder/pull/147 attempted to do this but it only did it for Record Interface classes. This commit does it for all classes that are to be generated. Ad hoc testing shows that it solves the problem. Fixes #139 --- .../processor/RecordBuilderProcessor.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 643d8e5c..8591a064 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -31,7 +31,10 @@ import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; +import javax.tools.FileObject; import javax.tools.JavaFileObject; +import javax.tools.StandardLocation; +import java.io.File; import java.io.IOException; import java.io.Writer; import java.util.Optional; @@ -216,6 +219,8 @@ private void writeRecordBuilderJavaFile(TypeElement record, String packageName, JavaFile javaFile = javaFileBuilder(packageName, builderType, metaData); Filer filer = processingEnv.getFiler(); try { + deletePossibleClassFile(packageName, builderClassType.name()); + String fullyQualifiedName = packageName.isEmpty() ? builderClassType.name() : (packageName + "." + builderClassType.name()); JavaFileObject sourceFile = filer.createSourceFile(fullyQualifiedName); @@ -235,6 +240,8 @@ private void writeRecordInterfaceJavaFile(TypeElement element, String packageNam Filer filer = processingEnv.getFiler(); try { + deletePossibleClassFile(packageName, classType.name()); + String fullyQualifiedName = packageName.isEmpty() ? classType.name() : (packageName + "." + classType.name()); JavaFileObject sourceFile = filer.createSourceFile(fullyQualifiedName); @@ -263,4 +270,20 @@ private void handleWriteError(TypeElement element, IOException e) { } processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message, element); } + + private void deletePossibleClassFile(String packageName, String className) { + try { + FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, + className + ".class"); + File file = new File(resource.toUri()); + if (file.exists()) { + if (!file.delete()) { + processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, + "Could not delete existing class file: %s".formatted(file)); + } + } + } catch (IOException e) { + // ignore + } + } } From d03b9f2388a5cf6db0f93b69dbc45101695ea4e8 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Thu, 28 Mar 2024 09:22:48 +0000 Subject: [PATCH 02/15] Two separate writer methods are no longer needed --- .../processor/RecordBuilderProcessor.java | 29 +++---------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 8591a064..cc941d7a 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -174,7 +174,7 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde if (!internalProcessor.isValid()) { return; } - writeRecordInterfaceJavaFile(element, internalProcessor.packageName(), internalProcessor.recordClassType(), + writeJavaFile(element, internalProcessor.packageName(), internalProcessor.recordClassType(), internalProcessor.recordType(), metaData); } @@ -193,7 +193,7 @@ private void processRecordBuilder(TypeElement record, RecordBuilder.Options meta validateMetaData(metaData, record); var internalProcessor = new InternalRecordBuilderProcessor(processingEnv, record, metaData, packageName); - writeRecordBuilderJavaFile(record, internalProcessor.packageName(), internalProcessor.builderClassType(), + writeJavaFile(record, internalProcessor.packageName(), internalProcessor.builderClassType(), internalProcessor.builderType(), metaData); } @@ -213,8 +213,8 @@ private void validateMetaData(RecordBuilder.Options metaData, Element record) { } } - private void writeRecordBuilderJavaFile(TypeElement record, String packageName, ClassType builderClassType, - TypeSpec builderType, RecordBuilder.Options metaData) { + private void writeJavaFile(TypeElement record, String packageName, ClassType builderClassType, TypeSpec builderType, + RecordBuilder.Options metaData) { // produces the Java file JavaFile javaFile = javaFileBuilder(packageName, builderType, metaData); Filer filer = processingEnv.getFiler(); @@ -232,27 +232,6 @@ private void writeRecordBuilderJavaFile(TypeElement record, String packageName, } } - private void writeRecordInterfaceJavaFile(TypeElement element, String packageName, ClassType classType, - TypeSpec type, RecordBuilder.Options metaData) { - JavaFile javaFile = javaFileBuilder(packageName, type, metaData); - - String recordSourceCode = javaFile.toString(); - - Filer filer = processingEnv.getFiler(); - try { - deletePossibleClassFile(packageName, classType.name()); - - String fullyQualifiedName = packageName.isEmpty() ? classType.name() - : (packageName + "." + classType.name()); - JavaFileObject sourceFile = filer.createSourceFile(fullyQualifiedName); - try (Writer writer = sourceFile.openWriter()) { - writer.write(recordSourceCode); - } - } catch (IOException e) { - handleWriteError(element, e); - } - } - private JavaFile javaFileBuilder(String packageName, TypeSpec type, RecordBuilder.Options metaData) { var javaFileBuilder = JavaFile.builder(packageName, type).skipJavaLangImports(true) .indent(metaData.fileIndent()); From 37d67075b257a37ce0b2b19ab32477f80f75016a Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 11:25:50 +0100 Subject: [PATCH 03/15] x --- .../soabase/recordbuilder/processor/RecordBuilderProcessor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index cc941d7a..b1f5ea59 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -251,6 +251,7 @@ private void handleWriteError(TypeElement element, IOException e) { } private void deletePossibleClassFile(String packageName, String className) { +/* try { FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, className + ".class"); @@ -264,5 +265,6 @@ private void deletePossibleClassFile(String packageName, String className) { } catch (IOException e) { // ignore } +*/ } } From 578dd9843e28ea8bf7b779222f9b5e630275c42c Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 11:40:25 +0100 Subject: [PATCH 04/15] x --- .../processor/RecordBuilderProcessor.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index b1f5ea59..91e49b48 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -40,6 +40,8 @@ import java.util.Optional; import java.util.Set; +import static io.soabase.recordbuilder.processor.ElementUtils.getBuilderName; + public class RecordBuilderProcessor extends AbstractProcessor { private static final String RECORD_BUILDER = RecordBuilder.class.getName(); private static final String RECORD_BUILDER_INCLUDE = RecordBuilder.Include.class.getName().replace('$', '.'); @@ -174,6 +176,13 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde if (!internalProcessor.isValid()) { return; } + + ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); + String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); + getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); + deletePossibleClassFile(actualPackageName, ifaceClassType.name()); + deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.suffix()); + writeJavaFile(element, internalProcessor.packageName(), internalProcessor.recordClassType(), internalProcessor.recordType(), metaData); } @@ -219,8 +228,6 @@ private void writeJavaFile(TypeElement record, String packageName, ClassType bui JavaFile javaFile = javaFileBuilder(packageName, builderType, metaData); Filer filer = processingEnv.getFiler(); try { - deletePossibleClassFile(packageName, builderClassType.name()); - String fullyQualifiedName = packageName.isEmpty() ? builderClassType.name() : (packageName + "." + builderClassType.name()); JavaFileObject sourceFile = filer.createSourceFile(fullyQualifiedName); @@ -251,11 +258,12 @@ private void handleWriteError(TypeElement element, IOException e) { } private void deletePossibleClassFile(String packageName, String className) { -/* try { - FileObject resource = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, packageName, - className + ".class"); + FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, packageName, + className + ".java"); File file = new File(resource.toUri()); + processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, + "Exists: %s - File %s".formatted(file.exists(), file)); if (file.exists()) { if (!file.delete()) { processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, @@ -265,6 +273,5 @@ private void deletePossibleClassFile(String packageName, String className) { } catch (IOException e) { // ignore } -*/ } } From 343277c7debdd51957fda5b7cdab96cedb144345 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 11:44:48 +0100 Subject: [PATCH 05/15] x --- .../recordbuilder/processor/RecordBuilderProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 91e49b48..b22971c7 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -180,7 +180,7 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); - deletePossibleClassFile(actualPackageName, ifaceClassType.name()); + deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix()); deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.suffix()); writeJavaFile(element, internalProcessor.packageName(), internalProcessor.recordClassType(), @@ -259,7 +259,7 @@ private void handleWriteError(TypeElement element, IOException e) { private void deletePossibleClassFile(String packageName, String className) { try { - FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, packageName, + FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, packageName, className + ".java"); File file = new File(resource.toUri()); processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, From 612c910df05e7d8e65b1d6dce83b9720f45a05b4 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 11:54:31 +0100 Subject: [PATCH 06/15] x --- .../processor/RecordBuilderProcessor.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index b22971c7..02f6a85a 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -180,8 +180,10 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); - deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix()); - deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.suffix()); + deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); + deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); + deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); + deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); writeJavaFile(element, internalProcessor.packageName(), internalProcessor.recordClassType(), internalProcessor.recordType(), metaData); @@ -257,10 +259,11 @@ private void handleWriteError(TypeElement element, IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message, element); } - private void deletePossibleClassFile(String packageName, String className) { + private void deletePossibleClassFile(String packageName, String className, StandardLocation location) { + String extension = (location == StandardLocation.CLASS_OUTPUT) ? ".class" : ".java"; try { - FileObject resource = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, packageName, - className + ".java"); + FileObject resource = processingEnv.getFiler().getResource(location, packageName, + className + extension); File file = new File(resource.toUri()); processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Exists: %s - File %s".formatted(file.exists(), file)); From 91bed641c1fc5656a5447ef119fea557e348ab75 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 11:57:32 +0100 Subject: [PATCH 07/15] x --- .../processor/RecordBuilderProcessor.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 02f6a85a..427d942e 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -171,20 +171,25 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde validateMetaData(metaData, element); + ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); + String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); + getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); + + boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); + boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); + boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); + boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); + + if (b1 || b2 || b3 || b4) { + return; + } + var internalProcessor = new InternalRecordInterfaceProcessor(processingEnv, element, addRecordBuilder, metaData, packageName, fromTemplate); if (!internalProcessor.isValid()) { return; } - ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); - String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); - getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); - deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); - deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); - deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); - deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); - writeJavaFile(element, internalProcessor.packageName(), internalProcessor.recordClassType(), internalProcessor.recordType(), metaData); } @@ -259,7 +264,7 @@ private void handleWriteError(TypeElement element, IOException e) { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message, element); } - private void deletePossibleClassFile(String packageName, String className, StandardLocation location) { + private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { String extension = (location == StandardLocation.CLASS_OUTPUT) ? ".class" : ".java"; try { FileObject resource = processingEnv.getFiler().getResource(location, packageName, @@ -271,10 +276,14 @@ private void deletePossibleClassFile(String packageName, String className, Stand if (!file.delete()) { processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Could not delete existing class file: %s".formatted(file)); + return false; } + return true; } + return false; } catch (IOException e) { // ignore } + return false; } } From 5efdd2ecbd256d4603ffe42cf34050218dd0a626 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:03:48 +0100 Subject: [PATCH 08/15] x --- .../processor/RecordBuilderProcessor.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 427d942e..0cf8eb95 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -37,6 +37,7 @@ import java.io.File; import java.io.IOException; import java.io.Writer; +import java.util.HashSet; import java.util.Optional; import java.util.Set; @@ -48,6 +49,8 @@ public class RecordBuilderProcessor extends AbstractProcessor { private static final String RECORD_INTERFACE = RecordInterface.class.getName(); private static final String RECORD_INTERFACE_INCLUDE = RecordInterface.Include.class.getName().replace('$', '.'); + private static final Set deletedSet = new HashSet<>(); + static final AnnotationSpec generatedRecordBuilderAnnotation = AnnotationSpec.builder(Generated.class) .addMember("value", "$S", RecordBuilder.class.getName()).build(); static final AnnotationSpec generatedRecordInterfaceAnnotation = AnnotationSpec.builder(Generated.class) @@ -177,12 +180,8 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); - boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); - boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); - - if (b1 || b2 || b3 || b4) { - return; - } + //boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); + //boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); var internalProcessor = new InternalRecordInterfaceProcessor(processingEnv, element, addRecordBuilder, metaData, packageName, fromTemplate); @@ -266,6 +265,11 @@ private void handleWriteError(TypeElement element, IOException e) { private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { String extension = (location == StandardLocation.CLASS_OUTPUT) ? ".class" : ".java"; + + if (!deletedSet.add(packageName + "." + className + extension)) { + return false; + } + try { FileObject resource = processingEnv.getFiler().getResource(location, packageName, className + extension); From de238d83ef638e65297d38f77fa0aeb668b57ab0 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:22:00 +0100 Subject: [PATCH 09/15] x --- .../recordbuilder/processor/ElementUtils.java | 6 + .../processor/RecordBuilderCleaner.java | 118 ++++++++++++++++++ .../processor/RecordBuilderProcessor.java | 25 ++-- .../javax.annotation.processing.Processor | 3 +- 4 files changed, 134 insertions(+), 18 deletions(-) create mode 100644 record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/ElementUtils.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/ElementUtils.java index cb6fcec9..aa0cabbe 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/ElementUtils.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/ElementUtils.java @@ -174,4 +174,10 @@ private static String getBuilderNamePrefix(Element element) { private ElementUtils() { } + + static RecordBuilder.Options getMetaData(ProcessingEnvironment processingEnv, Element element) { + var recordSpecificMetaData = element.getAnnotation(RecordBuilder.Options.class); + return (recordSpecificMetaData != null) ? recordSpecificMetaData + : RecordBuilderOptions.build(processingEnv.getOptions()); + } } diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java new file mode 100644 index 00000000..b4110107 --- /dev/null +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -0,0 +1,118 @@ +/* + * Copyright 2019 The original author or authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.soabase.recordbuilder.processor; + +import io.soabase.recordbuilder.core.RecordBuilder; +import io.soabase.recordbuilder.core.RecordInterface; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.Element; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.StandardLocation; +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +import static io.soabase.recordbuilder.processor.ElementUtils.getBuilderName; +import static io.soabase.recordbuilder.processor.ElementUtils.getMetaData; +import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.RECORD_INTERFACE; +import static io.soabase.recordbuilder.processor.RecordBuilderProcessor.RECORD_INTERFACE_INCLUDE; + +public class RecordBuilderCleaner extends AbstractProcessor { + private static final Set deletedSet = new HashSet<>(); + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + annotations.forEach(annotation -> roundEnv.getElementsAnnotatedWith(annotation) + .forEach(element -> process(annotation, element))); + return false; + } + + @Override + public Set getSupportedAnnotationTypes() { + return Set.of("*"); + } + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latest(); + } + + private void process(TypeElement annotation, Element element) { + String annotationClass = annotation.getQualifiedName().toString(); + if (annotationClass.equals(RECORD_INTERFACE)) { + var typeElement = (TypeElement) element; + processRecordInterface(typeElement, element.getAnnotation(RecordInterface.class).addRecordBuilder(), + getMetaData(processingEnv, typeElement), Optional.empty(), false); + } else if (annotationClass.equals(RECORD_INTERFACE_INCLUDE)) { + // processIncludes(element, getMetaData(processingEnv, element), annotationClass); TODO + } else { + var recordBuilderTemplate = annotation.getAnnotation(RecordBuilder.Template.class); + if (recordBuilderTemplate != null) { + if (recordBuilderTemplate.asRecordInterface()) { + processRecordInterface((TypeElement) element, true, recordBuilderTemplate.options(), + Optional.empty(), true); + } + } + } + } + + private void processRecordInterface(TypeElement element, boolean addRecordBuilder, RecordBuilder.Options metaData, + Optional packageName, boolean fromTemplate) { + ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); + String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); + getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); + + boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); + boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); + //boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); + //boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); + } + + private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { + String extension = (location == StandardLocation.CLASS_OUTPUT) ? ".class" : ".java"; + + if (!deletedSet.add(packageName + "." + className + extension)) { + return false; + } + + try { + FileObject resource = processingEnv.getFiler().getResource(location, packageName, + className + extension); + File file = new File(resource.toUri()); + processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, + "Exists: %s - File %s".formatted(file.exists(), file)); + if (file.exists()) { + if (!file.delete()) { + processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, + "Could not delete existing class file: %s".formatted(file)); + return false; + } + return true; + } + return false; + } catch (IOException e) { + // ignore + } + return false; + } +} diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 0cf8eb95..298502a9 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -22,10 +22,7 @@ import io.soabase.recordbuilder.core.RecordBuilderGenerated; import io.soabase.recordbuilder.core.RecordInterface; -import javax.annotation.processing.AbstractProcessor; -import javax.annotation.processing.Filer; -import javax.annotation.processing.Generated; -import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.*; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.PackageElement; @@ -44,10 +41,10 @@ import static io.soabase.recordbuilder.processor.ElementUtils.getBuilderName; public class RecordBuilderProcessor extends AbstractProcessor { - private static final String RECORD_BUILDER = RecordBuilder.class.getName(); - private static final String RECORD_BUILDER_INCLUDE = RecordBuilder.Include.class.getName().replace('$', '.'); - private static final String RECORD_INTERFACE = RecordInterface.class.getName(); - private static final String RECORD_INTERFACE_INCLUDE = RecordInterface.Include.class.getName().replace('$', '.'); + static final String RECORD_BUILDER = RecordBuilder.class.getName(); + static final String RECORD_BUILDER_INCLUDE = RecordBuilder.Include.class.getName().replace('$', '.'); + static final String RECORD_INTERFACE = RecordInterface.class.getName(); + static final String RECORD_INTERFACE_INCLUDE = RecordInterface.Include.class.getName().replace('$', '.'); private static final Set deletedSet = new HashSet<>(); @@ -83,13 +80,13 @@ private void process(TypeElement annotation, Element element) { String annotationClass = annotation.getQualifiedName().toString(); if (annotationClass.equals(RECORD_BUILDER)) { var typeElement = (TypeElement) element; - processRecordBuilder(typeElement, getMetaData(typeElement), Optional.empty()); + processRecordBuilder(typeElement, ElementUtils.getMetaData(processingEnv, typeElement), Optional.empty()); } else if (annotationClass.equals(RECORD_INTERFACE)) { var typeElement = (TypeElement) element; processRecordInterface(typeElement, element.getAnnotation(RecordInterface.class).addRecordBuilder(), - getMetaData(typeElement), Optional.empty(), false); + ElementUtils.getMetaData(processingEnv, typeElement), Optional.empty(), false); } else if (annotationClass.equals(RECORD_BUILDER_INCLUDE) || annotationClass.equals(RECORD_INTERFACE_INCLUDE)) { - processIncludes(element, getMetaData(element), annotationClass); + processIncludes(element, ElementUtils.getMetaData(processingEnv, element), annotationClass); } else { var recordBuilderTemplate = annotation.getAnnotation(RecordBuilder.Template.class); if (recordBuilderTemplate != null) { @@ -103,12 +100,6 @@ private void process(TypeElement annotation, Element element) { } } - private RecordBuilder.Options getMetaData(Element element) { - var recordSpecificMetaData = element.getAnnotation(RecordBuilder.Options.class); - return (recordSpecificMetaData != null) ? recordSpecificMetaData - : RecordBuilderOptions.build(processingEnv.getOptions()); - } - private void processIncludes(Element element, RecordBuilder.Options metaData, String annotationClass) { var isRecordBuilderInclude = annotationClass.equals(RECORD_BUILDER_INCLUDE); var annotationMirrorOpt = ElementUtils.findAnnotationMirror(processingEnv, element, annotationClass); diff --git a/record-builder-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/record-builder-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor index b1715822..9b813c9e 100644 --- a/record-builder-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/record-builder-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1 +1,2 @@ -io.soabase.recordbuilder.processor.RecordBuilderProcessor \ No newline at end of file +io.soabase.recordbuilder.processor.RecordBuilderCleaner +io.soabase.recordbuilder.processor.RecordBuilderProcessor From 2b7e18e41d6f7a32d26b91262fcb04d47920b039 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:33:01 +0100 Subject: [PATCH 10/15] x --- .../processor/RecordBuilderCleaner.java | 22 ++++++++++--------- .../processor/RecordBuilderProcessor.java | 15 ++++++++----- record-builder-test/pom.xml | 3 ++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java index b4110107..cd0e736e 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -64,7 +64,7 @@ private void process(TypeElement annotation, Element element) { processRecordInterface(typeElement, element.getAnnotation(RecordInterface.class).addRecordBuilder(), getMetaData(processingEnv, typeElement), Optional.empty(), false); } else if (annotationClass.equals(RECORD_INTERFACE_INCLUDE)) { - // processIncludes(element, getMetaData(processingEnv, element), annotationClass); TODO + // processIncludes(element, getMetaData(processingEnv, element), annotationClass); TODO } else { var recordBuilderTemplate = annotation.getAnnotation(RecordBuilder.Template.class); if (recordBuilderTemplate != null) { @@ -77,15 +77,19 @@ private void process(TypeElement annotation, Element element) { } private void processRecordInterface(TypeElement element, boolean addRecordBuilder, RecordBuilder.Options metaData, - Optional packageName, boolean fromTemplate) { + Optional packageName, boolean fromTemplate) { ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); - boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); - boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); - //boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); - //boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); + boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), + StandardLocation.SOURCE_OUTPUT); + boolean b2 = deletePossibleClassFile(actualPackageName, + ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); + // boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), + // StandardLocation.CLASS_OUTPUT); + // boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + + // metaData.suffix(), StandardLocation.CLASS_OUTPUT); } private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { @@ -96,11 +100,9 @@ private boolean deletePossibleClassFile(String packageName, String className, St } try { - FileObject resource = processingEnv.getFiler().getResource(location, packageName, - className + extension); + FileObject resource = processingEnv.getFiler().getResource(location, packageName, className + extension); File file = new File(resource.toUri()); - processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, - "Exists: %s - File %s".formatted(file.exists(), file)); + System.err.println("XXXX Cleaner: Exists: %s - File %s".formatted(file.exists(), file)); if (file.exists()) { if (!file.delete()) { processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 298502a9..864365c1 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -169,10 +169,14 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); getBuilderName(element, metaData, ifaceClassType, metaData.interfaceSuffix()); - boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.SOURCE_OUTPUT); - boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); - //boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); - //boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); + boolean b1 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), + StandardLocation.SOURCE_OUTPUT); + boolean b2 = deletePossibleClassFile(actualPackageName, + ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); + // boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), + // StandardLocation.CLASS_OUTPUT); + // boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + + // metaData.suffix(), StandardLocation.CLASS_OUTPUT); var internalProcessor = new InternalRecordInterfaceProcessor(processingEnv, element, addRecordBuilder, metaData, packageName, fromTemplate); @@ -262,8 +266,7 @@ private boolean deletePossibleClassFile(String packageName, String className, St } try { - FileObject resource = processingEnv.getFiler().getResource(location, packageName, - className + extension); + FileObject resource = processingEnv.getFiler().getResource(location, packageName, className + extension); File file = new File(resource.toUri()); processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Exists: %s - File %s".formatted(file.exists(), file)); diff --git a/record-builder-test/pom.xml b/record-builder-test/pom.xml index 1203ee42..07b8e73c 100644 --- a/record-builder-test/pom.xml +++ b/record-builder-test/pom.xml @@ -16,7 +16,8 @@ limitations under the License. --> - + io.soabase.record-builder record-builder From 1a3ceeffa374507c7e361a625d1670ca82581c8b Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:33:47 +0100 Subject: [PATCH 11/15] x --- .../io/soabase/recordbuilder/processor/RecordBuilderCleaner.java | 1 + 1 file changed, 1 insertion(+) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java index cd0e736e..c3e8e3bd 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -105,6 +105,7 @@ private boolean deletePossibleClassFile(String packageName, String className, St System.err.println("XXXX Cleaner: Exists: %s - File %s".formatted(file.exists(), file)); if (file.exists()) { if (!file.delete()) { + System.err.println("Could not delete existing: Exists: %s - File %s".formatted(file.exists(), file)); processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "Could not delete existing class file: %s".formatted(file)); return false; From 57b07af923b4cd63caefeb4eee54817094948eef Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:34:48 +0100 Subject: [PATCH 12/15] x --- .../recordbuilder/processor/RecordBuilderCleaner.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java index c3e8e3bd..b92c84ad 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -86,10 +86,8 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde StandardLocation.SOURCE_OUTPUT); boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); - // boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), - // StandardLocation.CLASS_OUTPUT); - // boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + - // metaData.suffix(), StandardLocation.CLASS_OUTPUT); + boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); + boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); } private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { From 8e47252a075f56c3ab8aa1b5d4c0370ff2329ae9 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:40:18 +0100 Subject: [PATCH 13/15] x --- .../processor/RecordBuilderCleaner.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java index b92c84ad..05f70444 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -29,6 +29,7 @@ import java.io.File; import java.io.IOException; import java.util.HashSet; +import java.util.List; import java.util.Optional; import java.util.Set; @@ -42,9 +43,10 @@ public class RecordBuilderCleaner extends AbstractProcessor { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { - annotations.forEach(annotation -> roundEnv.getElementsAnnotatedWith(annotation) - .forEach(element -> process(annotation, element))); - return false; + List results = annotations.stream() + .flatMap(annotation -> roundEnv.getElementsAnnotatedWith(annotation).stream().map(element -> process(annotation, element))) + .toList(); + return results.stream().allMatch(b -> b); } @Override @@ -57,11 +59,11 @@ public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest(); } - private void process(TypeElement annotation, Element element) { + private boolean process(TypeElement annotation, Element element) { String annotationClass = annotation.getQualifiedName().toString(); if (annotationClass.equals(RECORD_INTERFACE)) { var typeElement = (TypeElement) element; - processRecordInterface(typeElement, element.getAnnotation(RecordInterface.class).addRecordBuilder(), + return processRecordInterface(typeElement, element.getAnnotation(RecordInterface.class).addRecordBuilder(), getMetaData(processingEnv, typeElement), Optional.empty(), false); } else if (annotationClass.equals(RECORD_INTERFACE_INCLUDE)) { // processIncludes(element, getMetaData(processingEnv, element), annotationClass); TODO @@ -69,14 +71,15 @@ private void process(TypeElement annotation, Element element) { var recordBuilderTemplate = annotation.getAnnotation(RecordBuilder.Template.class); if (recordBuilderTemplate != null) { if (recordBuilderTemplate.asRecordInterface()) { - processRecordInterface((TypeElement) element, true, recordBuilderTemplate.options(), + return processRecordInterface((TypeElement) element, true, recordBuilderTemplate.options(), Optional.empty(), true); } } } + return false; } - private void processRecordInterface(TypeElement element, boolean addRecordBuilder, RecordBuilder.Options metaData, + private boolean processRecordInterface(TypeElement element, boolean addRecordBuilder, RecordBuilder.Options metaData, Optional packageName, boolean fromTemplate) { ClassType ifaceClassType = ElementUtils.getClassType(element, element.getTypeParameters()); String actualPackageName = packageName.orElseGet(() -> ElementUtils.getPackageName(element)); @@ -88,6 +91,8 @@ private void processRecordInterface(TypeElement element, boolean addRecordBuilde ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); + + return b1 || b2 || b3 || b4; } private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { From 9f05e466ee2f50f7aa29b8eb1fcb94512883c5e4 Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:42:24 +0100 Subject: [PATCH 14/15] x --- .../soabase/recordbuilder/processor/RecordBuilderCleaner.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java index 05f70444..c4d369ef 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -89,10 +89,12 @@ private boolean processRecordInterface(TypeElement element, boolean addRecordBui StandardLocation.SOURCE_OUTPUT); boolean b2 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.SOURCE_OUTPUT); +/* boolean b3 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix(), StandardLocation.CLASS_OUTPUT); boolean b4 = deletePossibleClassFile(actualPackageName, ifaceClassType.name() + metaData.interfaceSuffix() + metaData.suffix(), StandardLocation.CLASS_OUTPUT); +*/ - return b1 || b2 || b3 || b4; + return b1 || b2;// || b3 || b4; } private boolean deletePossibleClassFile(String packageName, String className, StandardLocation location) { From bf9b79876fa3dcdc6d2b63b3a5263a678060b2de Mon Sep 17 00:00:00 2001 From: Jordan Zimmerman Date: Sun, 31 Mar 2024 12:45:15 +0100 Subject: [PATCH 15/15] x --- .../soabase/recordbuilder/processor/RecordBuilderCleaner.java | 4 +++- .../recordbuilder/processor/RecordBuilderProcessor.java | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java index c4d369ef..7cf8a7bf 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderCleaner.java @@ -46,7 +46,9 @@ public boolean process(Set annotations, RoundEnvironment List results = annotations.stream() .flatMap(annotation -> roundEnv.getElementsAnnotatedWith(annotation).stream().map(element -> process(annotation, element))) .toList(); - return results.stream().allMatch(b -> b); + boolean result = results.stream().allMatch(b -> b); + System.err.println("RecordBuilderCleaner - " + annotations + " - " + result); + return result; } @Override diff --git a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java index 864365c1..3c0e7a79 100644 --- a/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java +++ b/record-builder-processor/src/main/java/io/soabase/recordbuilder/processor/RecordBuilderProcessor.java @@ -57,6 +57,8 @@ public class RecordBuilderProcessor extends AbstractProcessor { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { + System.err.println("RecordBuilderProcessor - " + annotations); + annotations.forEach(annotation -> roundEnv.getElementsAnnotatedWith(annotation) .forEach(element -> process(annotation, element))); return false;