java - How to find import statements that are required for the block/method declaration in AST Eclipse JDT? -
this code snippet, here try create new class extracted block class. need find import statements required in method extracted has added generated class.
private void generateclass() throws ioexception { ast ast = ast.newast(ast.jls8); compilationunit unit = ast.newcompilationunit(); typedeclaration type = ast.newtypedeclaration(); type.setinterface(false); type.modifiers().add(ast.newmodifier(modifier.modifierkeyword.public_keyword)); type.setname(ast.newsimplename("generatedclass")); methoddeclaration methoddeclaration = identifyastnode.getmethoddeclaration(); methoddeclaration = (methoddeclaration)astnode.copysubtree(ast, methoddeclaration); type.bodydeclarations().add(methoddeclaration); unit.types().add(type); writetofile(unit.tostring()); }
Comments
Post a Comment