Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use OrganizeImportsOperation in o.e.jdt.core.manipulation. #566

Closed
wants to merge 1 commit into from

Conversation

rgrunber
Copy link
Contributor

@rgrunber rgrunber commented Feb 21, 2018

  • With http://eclip.se/506239, OrganizeImportsOperation is now API
  • ImportReferencesCollector is now API in
    org.eclipse.jdt.core.manipulation
  • non-UI methods of SharedASTProvider are exposed in
    org.eclipse.jdt.core.manipulation through CoreASTProvider
  • Preferences such as ORGIMPORTS_IMPORTORDER can now be defined entirely
    through the IEclipsePreferences facility. Simply use
    JavaManipulation.setJavaUIPluginId() to let the JDT know which plug-in
    node will be used to store preferences, and then default/runtime
    preferences for consumption.
  • StubUtility.createImportRewrite() methods are now public API in
    CodeStyleConfiguration

Signed-off-by: Roland Grunberg [email protected]

I figured I'd get the ball rolling on this now that it finally got accepted into JD UI. There are of course still a few items to fix up, and possibly more as I find them :

  • Move preference related code into the preference manager

  • AFAICT JDT-LS caches many ASTs but JDT only ever cached the one for the active document. This patch returns to the old behaviour. Is this a bad thing ? Do we really see a huge gain from caching many different ASTs ? The JDT SharedASTProvider javadoc mention that more than one AST should never be held in memory for performance reasons.

    • Need replacements for sharedASTProvider's clearASTCreationCount() getASTCreationCount() getCacheSize()
    • Easiest solution if these methods are really wanted for testing is to wrap all of CoreASTProvider (can't be subclassed) by some new class and provide those methods there
  • Wait until Oxygen M6 is released so we can stop depending on the 4.8-I-builds to build this change, and just use the current 4.8milestones in the target platform

@eclipse-ls-bot
Copy link

Can one of the admins verify this patch?

@fbricon
Copy link
Contributor

fbricon commented Feb 21, 2018

add to whitelist

@fbricon
Copy link
Contributor

fbricon commented Feb 21, 2018

Nice one @rgrunber, I didn't see that one coming. I love to see more deleted code than added :-)

result.append(val);
result.append(";"); //$NON-NLS-1$
}
pref.put(CodeStyleConfiguration.ORGIMPORTS_IMPORTORDER, result.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pref.put(CodeStyleConfiguration.ORGIMPORTS_IMPORTORDER, String.join(";", importOrder));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in updated version.

@fbricon
Copy link
Contributor

fbricon commented Feb 21, 2018

I'm surprised the server behaves very well without all the AST caching @aeschli introduced in SharedASTProvider.
@aeschli do you want to comment on @rgrunber remarks about that?

@fbricon fbricon added the debt label Feb 21, 2018
@aeschli
Copy link
Contributor

aeschli commented Feb 22, 2018

I don't have any numbers if caching multiple AST is worth it, it probably all depends on how the language client uses the server. I'm fine with caching less.

@rgrunber But I wonder if it is a good idea to have a cache in the jdt.core.codemanipulation...

@fbricon
Copy link
Contributor

fbricon commented Feb 22, 2018

@tsmaeder @yaohaizh @svor @tolusha I strongly advise you to check whether your extensions will be impacted by that change

@@ -142,6 +143,9 @@ public void start(BundleContext bundleContext) throws BackingStoreException {
preferenceManager.addPreferencesChangeListener(preferencesChangeListener);
logInfo(getClass() + " is started");
configureProxy();

// Set the ID to use for preference lookups
JavaManipulation.setJavaUIPluginId(PLUGIN_ID);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about you rename that method upstream to something like setPreferenceStoreId or setPreferenceStorePluginId?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be in for Photon M6, https://git.eclipse.org/r/118209/ . New methods will be getPreferenceNodeId/setPreferenceNodeId . The setter returns true if the value was successfully set and false otherwise.

@fbricon
Copy link
Contributor

fbricon commented Feb 22, 2018

Funny thing is, with this change, #552 can not be reproduced \o/

@gorkem
Copy link
Contributor

gorkem commented Feb 23, 2018

@rgrunber remind me to buy you your favorite beverage next time I am at the office.

@maxandersen
Copy link

This is awesome @rgrunber!

@tolusha
Copy link
Contributor

tolusha commented Feb 26, 2018

@fbricon @tsmaeder
There isn't much impact on eclipse/che-ls-jdt
Just refactoring stuff.

@fbricon fbricon added this to the Mid March 2018 milestone Mar 1, 2018
@ghost
Copy link

ghost commented Mar 5, 2018

@rgrunber nice work!

- With http://eclip.se/506239, OrganizeImportsOperation is now API
- ImportReferencesCollector is now API in
org.eclipse.jdt.core.manipulation
- non-UI methods of SharedASTProvider are exposed in
org.eclipse.jdt.core.manipulation through CoreASTProvider
- Preferences such as ORGIMPORTS_IMPORTORDER can now be defined entirely
through the IEclipsePreferences facility. Simply use
JavaManipulation.setPreferenceNodeId() to let the JDT know which plug-in
node will be used to store preferences, and then default/runtime
preferences for consumption.
- StubUtility.createImportRewrite() methods are now public API in
CodeStyleConfiguration
- Copy over ASTNodes.getEnclosingDeclaration() and
Bindings.findNullnessDefault to avoid growing the patch for now.

Signed-off-by: Roland Grunberg <[email protected]>
@fbricon
Copy link
Contributor

fbricon commented Mar 15, 2018

We'll merge this after the 0.15.0 release

@fbricon
Copy link
Contributor

fbricon commented Mar 15, 2018

Merged as e0bb56a

@fbricon fbricon closed this Mar 15, 2018
@rgrunber rgrunber deleted the organize-imports branch March 15, 2018 20:20
@rgrunber
Copy link
Contributor Author

rgrunber commented Mar 15, 2018

@fbricon Thanks for taking this. I was going to push some additional changes, mainly polishing up the target platform now that 4.8milestones can be used but I see you've done that already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants