在JavaParser中创建无效的AST

问题描述

我正在使用JavaParser库,并且希望能够通过省略变量类型来创建无效的AST。我正在尝试创建以下内容

输入代码

package org.javaparser.samples;
public class Simple {
public static void main(String[] args) {
    int numberOne = 5;
    int numberTwo = 10;
}

输出代码

    package org.javaparser.samples;
    public class Simple {
    public static void main(String[] args) {
        ... numberOne = 5;
        ... numberTwo = 10;
    }
}

但是以这种方式修改AST之后,我得到一个错误

com.github.javaparser.ParseProblemException: Encountered unexpected token: "..." "..."
 Was expecting one of:
    "boolean"
    "byte"
    ...

我正在使用ModifierVisitor更改变量类型

 private static class VariableDeclaratorModifier extends ModifierVisitor<Void> {
        @Override
        public VariableDeclarator visit(VariableDeclarator vd,Void arg) {
            super.visit(vd,arg);
            vd.setType("...");
            return vd;
        }
    }

有什么办法可以使用JavaParser实现所需的输出

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)