Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jdt-core-dev] JDT - PARSER - HELP

Hello Guys,  

    I am very very sorry for posting this message here, but i have posted it in the eclipse jdt newsgroup and no answer and i need your help urgently please.

          I am stuck in my project at work and need an urgent help. I have to parse my Java project(the java packages in the project as well as the java source files inside the packages) and build a tree from it. What am doing is this: I have some data in a file and i have to compare those data to the name of the nodes in my project(the ast nodes from the java source files) and if i find a match, then i must do something with it
My problem now is how i should parse the Java source files. I don't know how to do it. I have read this tutorial:

http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html

several times but it doesn't give me much idea about the starting point and also got stuck there. Am asking if someone can help me to do it.

At the moment i have this class:

public class TestingBindings {

protected CompilationUnit parse(ICompilationUnit unit) {
ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(unit); // set source
parser.setResolveBindings(true); // we need bindings later on
return (CompilationUnit)parser.createAST(null /*    IProgressMonitor */); // parse
}

public ICompilationUnit findProject()
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
// "yourplugins" is a project name
 IProject project = root.getProject("yourplugins");
   if (project.exists() && !project.isOpen())
try {
project.open(null /* IProgressMonitor */);
} catch (CoreException e1) {
e1.printStackTrace();
}

IJavaProject javaProject = JavaCore.create(project);
IType lwType = null;
try {
                        //"yplugins" is a package name
                        "Activator" is a class name
lwType = javaProject.findType("yplugins.Activator");
} catch (JavaModelException e) {

e.printStackTrace();
}
ICompilationUnit lwCompilationUnit = lwType.getCompilationUnit();

return lwCompilationUnit;

}

}


After i created this class, i am just stuck i don't know how to go further and process the projects and packages and the source files.

IMPORTANT:
I want to be able to parse a project and inside the project all the packages and inside the packages all the classes

So please help me to understand what i should do and how i should do it. I have spent much weeks on the web looking for answers but unable to find a tutorial for a beginner like me.  I searched the JDT documentation but couldn't figure out what to use since there are so many methods and also is not suitable for beginner like me. Please help.  Help me step by step what to do. Thanks.

Thanks for all your help.


Back to the top