refactoring

This commit is contained in:
2025-07-13 16:47:10 +02:00
parent d1d97b2a8d
commit 4fc75a534e
32 changed files with 953 additions and 1145 deletions

View File

@@ -0,0 +1,36 @@
package com.example.statemachinedemo.in;
import org.eclipse.jdt.core.dom.*;
import java.util.concurrent.atomic.AtomicBoolean;
public class AstFileFinder {
private final CompilationUnit cu;
public AstFileFinder(String source) {
ASTParser parser = ASTParser.newParser(AST.getJLSLatest());
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setResolveBindings(false);
parser.setSource(source.toCharArray());
this.cu = (CompilationUnit) parser.createAST(null);
}
public boolean hasClassWithAnnotation(String source, String annotationName) {
AtomicBoolean found = new AtomicBoolean(false);
cu.accept(new ASTVisitor() {
@Override
public boolean visit(TypeDeclaration node) {
if (node.isInterface()) return true;
for (Object modifier : node.modifiers()) {
if (modifier instanceof Annotation annotation &&
annotation.getTypeName().getFullyQualifiedName().equals(annotationName)) {
found.set(true);
return false;
}
}
return true;
}
});
return found.get();
}
}