Код: Выделить всё
public class Foo{
public static void main(String[] args) {
SourceRoot sourceRoot = new SourceRoot(Path.of(".\"));
CompilationUnit cu = sourceRoot.parse("", "MyFile.java);
ClassVisitor cv = new ClassVisitor();
cu.accept(cv, null);
}
}
class ClassVisitor extends VoidVisitorAdapter {
private final String MY_ANNOTATION = "@myAnnotation";
@Override
public void visit(ClassOrInterfaceDeclaration cid, Void arg) {
super.visit(cid, arg);
boolean isAnnotated = false;
for (Node node : cid.getAnnotations()){
if (MY_ANNOTATION == node.toString()) {
isAnnotated = true;
break;
}
}
if (isAnnotated == false) {
cid.addAnnotation(MY_ANNOTATION); // error happens here
}
}
}
Исключение в потоке «main»
com.github.javaparser.ParseProblemException: обнаружен неожиданный
токен: "@" "@"
в строке 1, столбец 1.
Ожидал одно из:< /p>
Код: Выделить всё
"enum"
"exports"
"module"
"open"
"opens"
"provides"
"record"
"requires"
"strictfp"
"to"
"transitive"
"uses"
"with"
"yield"
Подробнее здесь: https://stackoverflow.com/questions/717 ... ng-classes
Мобильная версия