0

I am working on reusing Eclipse JDT inline method refactoring and I need to access the workspace so I can get the ICompilationUnit [ please do correct me if I am wrong about this information ]:

IWorkspace workspace = ResourcesPlugin.getWorkspace();

Since the ICompilationUnit is requiered here:

InlineMethodRefactoring refactoring = InlineMethodRefactoring.create(icu,new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL).parse(icu, true), selection[0], selection[1]);

So I have read that accessing the workspace requires building either an Eclipse plug-in or a headless RCP .. so I created a headless RCP application following this tutorial as I do not need the UI to start up. Now everything works fine and the refactoring is applied but the following exceptions are printed in console - such as:

Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin.start() of bundle org.eclipse.wst.jsdt.ui.
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:834)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:762)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1032)
    at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:371)
    at org.eclipse.osgi.container.Module.doStart(Module.java:605)
    at org.eclipse.osgi.container.Module.start(Module.java:468)
    at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:513)
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117)
aused by: java.lang.IllegalStateException: Workbench has not been created yet.
    at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:102)
    at org.eclipse.wst.jsdt.internal.ui.javaeditor.ASTProvider.install(ASTProvider.java:282)
    at org.eclipse.wst.jsdt.internal.ui.javaeditor.ASTProvider.<init>(ASTProvider.java:273)
    at org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin.getASTProvider(JavaScriptPlugin.java:625)
    at org.eclipse.wst.jsdt.internal.ui.JavaScriptPlugin.start(JavaScriptPlugin.java:339)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:813)
    at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:1)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
    at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:805)
    ... 52 more

!ENTRY org.eclipse.core.resources 2 10035 2022-04-11 16:05:29.132
!MESSAGE The workspace will exit with unsaved changes in this session.
!SUBENTRY 1 org.eclipse.equinox.registry 4 1 2022-04-11 16:05:27.541
!MESSAGE Plug-in org.eclipse.wst.jsdt.ui was unable to load class org.eclipse.wst.jsdt.internal.corext.refactoring.scripting.CopyRefactoringContribution.
!STACK 0
java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.wst.jsdt.ui (860).
    at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:126)
    at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:570)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:335)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:397)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:488)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
    at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:622)
    at org.eclipse.core.internal.registry.osgi.RegistryStrategyOSGI.createExecutableExtension(RegistryStrategyOSGI.java:196)
    at org.eclipse.core.internal.registry.ExtensionRegistry.createExecutableExtension(ExtensionRegistry.java:920)
    at org.eclipse.core.internal.registry.ConfigurationElement.createExecutableExtension(ConfigurationElement.java:246)
    at org.eclipse.core.internal.registry.ConfigurationElementHandle.createExecutableExtension(ConfigurationElementHandle.java:63)
    at org.eclipse.ltk.internal.core.refactoring.history.RefactoringContributionManager.populateCache(RefactoringContributionManager.java:172)
    at org.eclipse.ltk.internal.core.refactoring.history.RefactoringContributionManager.getRefactoringContribution(RefactoringContributionManager.java:136)
    at org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryManager.getArgumentMap(RefactoringHistoryManager.java:180)
    at org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService.checkDescriptor(RefactoringHistoryService.java:591)
    at org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService.performHistoryNotification(RefactoringHistoryService.java:911)
    at org.eclipse.ltk.internal.core.refactoring.history.RefactoringHistoryService.lambda$0(RefactoringHistoryService.java:366)
    at org.eclipse.core.commands.operations.DefaultOperationHistory$2.run(DefaultOperationHistory.java:876)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45)
    at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyListeners(DefaultOperationHistory.java:865)
    at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyAboutToExecute(DefaultOperationHistory.java:887)
    at org.eclipse.core.commands.operations.DefaultOperationHistory.openOperation(DefaultOperationHistory.java:1189)
    at org.eclipse.ltk.internal.core.refactoring.UndoManager2.aboutToPerformChange(UndoManager2.java:150)
    at org.eclipse.ltk.core.refactoring.PerformChangeOperation.lambda$0(PerformChangeOperation.java:254)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2315)
    at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2340)
    at org.eclipse.ltk.core.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:295)
    at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:224)
    at org.eclipse.ltk.core.refactoring.PerformRefactoringOperation.run(PerformRefactoringOperation.java:137)
    at seham.phd.synthesiser.transformers.MethodDeclarationTransformer.inlineMethodInvocations(MethodDeclarationTransformer.java:42)
    at seham.phd.synthesiser.runner.Runner.start(Runner.java:53)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1440)
  • Maybe I should configure the application to run with only a set of plug-ins instead of including them all? [ do not know what to include or exclude] Click to see the configuration
  • Is there any other way for me to get the ICompilationUnit without accessing the workspace?
  • Is there any simpler way to use all JDT features in, for example, a simple maven project instead of an Eclipse plug-in or an RCP application?
  • Any tutorials on RCP development from within Eclipse is much appreciated.

Thanks.

  • RefactoringASTParser and InlineMethodRefactoring are in **internal** packages so they are not supported for use by applications. You are including far too much in the RCP, you need to use a target platform and just the core Eclipse SDK target. – greg-449 Apr 12 '22 at 06:38
  • do you mean that I cannot reuse this JDT inline this way, and it is not meant to be reused? how does the internal packages are different from the other packages I used? – Seham Alharbi Apr 12 '22 at 16:01
  • Classes in a package with "internal" in the name are not for public use. They may change or even disappear in different Eclipse releases. [Eclipse API Rules of Engagement](https://www.eclipse.org/articles/Article-API-Use/index.html) – greg-449 Apr 12 '22 at 16:12
  • interesting to know, I used the accepted answer in this post [link](https://stackoverflow.com/questions/12898718/how-to-execute-inline-refactoring-programmatically-using-jdt-ltk) .. have you got any idea on where to find a public API to reuse this feature. Thank you. – Seham Alharbi Apr 12 '22 at 16:15

0 Answers0