Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Getting Import statements for a Block(How to find import statements that are required for the block/method declaration in AST Eclipse JDT?)
Getting Import statements for a Block [message #1741781] Mon, 29 August 2016 14:03
Ferooz Khan is currently offline Ferooz KhanFriend
Messages: 1
Registered: August 2016
Junior Member
This is my code snippet, here I try to create a new class from a extracted block from another class. Now I need to find what are all import statements required in the method that is extracted which has be added to the 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());
}

Previous Topic:Issue on install of Eclipse Java Developers
Next Topic:Eclipse fails to install on Linux Mint 18 (Known issue?)
Goto Forum:
  


Current Time: Sun Oct 13 17:04:43 GMT 2024

Powered by FUDForum. Page generated in 0.03571 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top