Eclipse 插件开发项目中的JavaModelException
我正在开发一些“eclipse插件”,打算提取一些关于源代码中使用的类型的信息。为了实现这一点,我开始使用Eclipse JDT 1) 选择所需的项目:Eclipse 插件开发项目中的JavaModelException,eclipse,exception,plugins,model,eclipse-jdt,Eclipse,Exception,Plugins,Model,Eclipse Jdt,我正在开发一些“eclipse插件”,打算提取一些关于源代码中使用的类型的信息。为了实现这一点,我开始使用Eclipse JDT 1) 选择所需的项目: IProject userDesiredProject = workspace.getProject(userDesiredProjectName); IJavaProject userDesiredJavaProject = JavaCore.create(userDesiredProject); 2) 选择所需的源代码文件(类似于foo.
IProject userDesiredProject = workspace.getProject(userDesiredProjectName);
IJavaProject userDesiredJavaProject = JavaCore.create(userDesiredProject);
2) 选择所需的源代码文件(类似于foo.java
):
3-使用包含foo.java
编译单元的userDesiredCompilationUnit
,以便使用getTypes()
方法捕获类型:
IType[] allTypes = null;
try
{
allTypes = userDesiredCompilationUnit.getAllTypes();
//CODE STUCKS HERE AND "JavaModelException" OCCURS.
}
catch (JavaModelException e)
{
//TODO Auto-generated catch block
e.printStackTrace();
}
但在执行上述代码时,会发生JavaModelException
。需要注意的是,我已经测试了userDesiredCompilationUnit
,它包含了正确的对象
请帮帮我。
非常感谢。堆栈跟踪显示了什么?@greg-449:Solved!!它显示没有找到用于此源代码的java模型。我重新创建了该项目并解决了问题。:-)非常感谢greg。
IType[] allTypes = null;
try
{
allTypes = userDesiredCompilationUnit.getAllTypes();
//CODE STUCKS HERE AND "JavaModelException" OCCURS.
}
catch (JavaModelException e)
{
//TODO Auto-generated catch block
e.printStackTrace();
}