1

Kindly refer "write it down" section of article http://www.eclipse.org/articles/article.php?file=Article-javaCodeManipulation_AST/index.html

I am parsing a java source code file which has method with contracts written using cofoja. Now when I create abstract syntax tree (ast) of the input file, and modify it. It can show me that Document document, object being modified. But when I try to reflect this document back to the original source file, the following declaration throws an exception:

 // get the buffer manager  
 ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager(); 

The following exception gets thrown for ITextFileBufferManager bufferManager declaration in MyVisitor.java

Exception in thread "main" java.lang.ExceptionInInitializerError
    at ASTModifier.main(ASTModifier.java:205)
Caused by: java.lang.IllegalStateException: Workspace is closed.
at org.eclipse.core.resources.ResourcesPlugin.getWorkspace(ResourcesPlugin.java:340)
at org.eclipse.core.filebuffers.FileBuffers.<clinit>(FileBuffers.java:52)
... 1 more

Because of this, I am not able to change the original java file. One of the link I found on net : http://www.programcreek.com/2011/05/java-lang-illegalstateexception-workspace- is-closed/#comment-1939

It says: In brief, this is caused by simply adding dependent jar files to regular java project. To use JDT, you need to have the program running as a plug-in (or at least, an OSGi- enabled application) rather than using it as a jar.

Since I am creating a simple java project, is that a problem for using FileBuffers class? Do I need to create plug in instead?

4

1 回答 1

0

简短的回答:是的。如果您使用已打开的工作空间运行(即,您编写了一个 Eclipse 插件),则只能使用 JDT API。

如果您想编写一个使用 Eclipse API 的简单程序,您可能想编写一个 RCP 应用程序。这允许您使用 Eclipse 插件的 sib0set 来创建一些功能。

关于 RCP 的一个很好的教程在这里:

http://www.vogella.de/articles/EclipseRCP/article.html

于 2011-08-07T22:41:10.123 回答