This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new fd9134acc13 Add must override check (#17112)
fd9134acc13 is described below

commit fd9134acc137342921b4b6f9ba99226da625d4d6
Author: Jiang Tian <[email protected]>
AuthorDate: Fri Jan 30 14:44:47 2026 +0800

    Add must override check (#17112)
    
    * Add must override check
    
    * restart ci
    
    * fix variable names
    
    * update tsfile version
---
 .../org/apache/iotdb/db/utils/AnnotationTest.java  | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java
index 91ae2097089..97fc053fabd 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/utils/AnnotationTest.java
@@ -23,15 +23,20 @@ import org.apache.iotdb.commons.utils.TestOnly;
 
 import com.tngtech.archunit.core.domain.JavaClass;
 import com.tngtech.archunit.core.domain.JavaClasses;
+import com.tngtech.archunit.core.domain.JavaMethod;
 import com.tngtech.archunit.core.domain.properties.CanBeAnnotated;
 import com.tngtech.archunit.core.importer.ClassFileImporter;
 import com.tngtech.archunit.core.importer.ImportOption;
 import com.tngtech.archunit.core.importer.ImportOption.DoNotIncludeTests;
 import com.tngtech.archunit.lang.ArchRule;
+import org.apache.tsfile.annotations.MustOverride;
 import org.junit.Test;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
 
@@ -71,4 +76,58 @@ public class AnnotationTest {
     } catch (OutOfMemoryError ignored) {
     }
   }
+
+  @Test
+  public void checkMustOverride() {
+    try {
+      JavaClasses productionClasses =
+          new ClassFileImporter()
+              .withImportOption(new DoNotIncludeTests())
+              .importPackages("org.apache.iotdb", "org.apache.tsfile");
+
+      Map<JavaClass, List<JavaMethod>> classAndMethodsMustOverride = new 
HashMap<>();
+      for (JavaClass productionClass : productionClasses) {
+        for (JavaMethod method : productionClass.getMethods()) {
+          if (method.isAnnotatedWith(MustOverride.class)) {
+            classAndMethodsMustOverride
+                .computeIfAbsent(productionClass, k -> new ArrayList<>())
+                .add(method);
+          }
+        }
+      }
+
+      List<String> failures = new ArrayList<>();
+      for (JavaClass productionClass : productionClasses) {
+        for (Entry<JavaClass, List<JavaMethod>> entry : 
classAndMethodsMustOverride.entrySet()) {
+          JavaClass classWithTargetMethod = entry.getKey();
+          if (productionClass.isAssignableTo(classWithTargetMethod.getName())) 
{
+            List<JavaMethod> methodsThatMustOverride = entry.getValue();
+            for (JavaMethod toBeOverride : methodsThatMustOverride) {
+              boolean methodImplemented = false;
+              for (JavaMethod method : productionClass.getMethods()) {
+                if (method.getName().equals(toBeOverride.getName())
+                    && 
method.getParameters().equals(toBeOverride.getParameters())) {
+                  methodImplemented = true;
+                  break;
+                }
+              }
+              if (!methodImplemented) {
+                failures.add(
+                    String.format(
+                        "Class %s does not implement method %s annotated with 
@MustOverride from class %s",
+                        productionClass.getName(),
+                        toBeOverride.getName(),
+                        classWithTargetMethod.getName()));
+              }
+            }
+          }
+        }
+      }
+
+      if (!failures.isEmpty()) {
+        throw new AssertionError(String.join("\n", failures));
+      }
+    } catch (OutOfMemoryError ignored) {
+    }
+  }
 }

Reply via email to