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

CodeStyleManagerDecorator extends CodeStyleManagerImpl #313

Merged
merged 2 commits into from
Jun 29, 2020

Conversation

schlosna
Copy link
Contributor

@schlosna schlosna commented Jun 27, 2020

Before this PR

Using this plugin in IntelliJ versions newer than 202.5103.13 leads to the following exception and failure to format newly created Java files.

Steps to reproduce in an existing Java project:

  • File > New > Java Class
  • Provide a name "FooTest"
  • Receive "Cannot Create Class" error below
  • Note that the file & class are actually created

JetBrains/intellij-community@2d57401 added a CodeStyleManager#scheduleReformatWhenSettingsComputed(PsiFile) instance method in idea/202.5103.13 where the default implementation throws an UnsuportedOperationException.

See https://youtrack.jetbrains.com/issue/IDEA-244645 for more details (though that stacktrace shows similar bug with Eclipse Code Formatter plugin as used by default with gradle-baseline.

2020-06-27 17:56:32,707 [  37292]   INFO - es.ui.CreateFromTemplateDialog -  
java.lang.UnsupportedOperationException
	at com.intellij.psi.codeStyle.CodeStyleManager.scheduleReformatWhenSettingsComputed(CodeStyleManager.java:351)
	at com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler.createClassOrInterface(JavaCreateFromTemplateHandler.java:78)
	at com.intellij.ide.fileTemplates.JavaCreateFromTemplateHandler.createFromTemplate(JavaCreateFromTemplateHandler.java:118)
	at com.intellij.ide.fileTemplates.FileTemplateUtil.lambda$createFromTemplate$5(FileTemplateUtil.java:336)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl$2.run(WriteCommandAction.java:115)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$1(WriteCommandAction.java:246)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:980)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:245)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:303)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:211)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:187)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:305)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:244)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:225)
	at com.intellij.openapi.command.WriteCommandAction$BuilderImpl.compute(WriteCommandAction.java:117)
	at com.intellij.ide.fileTemplates.FileTemplateUtil.createFromTemplate(FileTemplateUtil.java:336)
	at com.intellij.ide.fileTemplates.FileTemplateUtil.createFromTemplate(FileTemplateUtil.java:262)
	at com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog.doCreate(CreateFromTemplateDialog.java:136)
	at com.intellij.ide.fileTemplates.ui.CreateFromTemplateDialog.create(CreateFromTemplateDialog.java:104)
	at com.intellij.psi.impl.file.JavaDirectoryServiceImpl.createClassFromTemplate(JavaDirectoryServiceImpl.java:179)
	at com.intellij.psi.impl.file.JavaDirectoryServiceImpl.createClass(JavaDirectoryServiceImpl.java:104)
	at com.intellij.psi.impl.file.JavaDirectoryServiceImpl.createClass(JavaDirectoryServiceImpl.java:96)
	at com.intellij.ide.actions.CreateClassAction.doCreate(CreateClassAction.java:107)
	at com.intellij.ide.actions.CreateClassAction.doCreate(CreateClassAction.java:28)
	at com.intellij.ide.actions.CreateTemplateInPackageAction.lambda$checkOrCreate$2(CreateTemplateInPackageAction.java:114)
	at com.intellij.openapi.project.DumbService.computeWithAlternativeResolveEnabled(DumbService.java:353)
	at com.intellij.ide.actions.CreateTemplateInPackageAction.checkOrCreate(CreateTemplateInPackageAction.java:113)
	at com.intellij.ide.actions.CreateTemplateInPackageAction.createFile(CreateTemplateInPackageAction.java:60)
	at com.intellij.ide.actions.CreateFromTemplateAction$1.createFile(CreateFromTemplateAction.java:70)
	at com.intellij.ide.actions.CreateFromTemplateAction$1.createFile(CreateFromTemplateAction.java:65)
	at com.intellij.ide.actions.CreateFileFromTemplateDialog$NonBlockingPopupBuilderImpl$1.create(CreateFileFromTemplateDialog.java:262)
	at com.intellij.ide.actions.ElementCreator.lambda$tryCreate$0(ElementCreator.java:69)
	at com.intellij.ide.actions.ElementCreator.lambda$executeCommand$1(ElementCreator.java:90)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:220)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:177)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:167)
	at com.intellij.ide.actions.ElementCreator.executeCommand(ElementCreator.java:84)
	at com.intellij.ide.actions.ElementCreator.tryCreate(ElementCreator.java:68)
	at com.intellij.ide.actions.CreateFileFromTemplateDialog$NonBlockingPopupBuilderImpl.createElement(CreateFileFromTemplateDialog.java:311)
	at com.intellij.ide.actions.CreateFileFromTemplateDialog$NonBlockingPopupBuilderImpl.lambda$show$2(CreateFileFromTemplateDialog.java:285)
	at com.intellij.ide.ui.newItemPopup.NewItemSimplePopupPanel$1.keyPressed(NewItemSimplePopupPanel.java:103)
	at java.desktop/java.awt.Component.processKeyEvent(Component.java:6608)
	at java.desktop/javax.swing.JComponent.processKeyEvent(JComponent.java:2852)
	at java.desktop/java.awt.Component.processEvent(Component.java:6427)
	at java.desktop/java.awt.Container.processEvent(Container.java:2263)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5025)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4857)
	at java.desktop/java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1950)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:878)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1148)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:1017)
	at java.desktop/java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:843)
	at com.intellij.ide.IdeKeyboardFocusManager.dispatchEvent(IdeKeyboardFocusManager.java:41)
	at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4906)
	at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
	at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2773)
	at java.desktop/java.awt.Component.dispatchEvent(Component.java:4857)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:778)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:751)
	at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:749)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:748)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:967)
	at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.java:892)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:833)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:450)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:744)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$9(IdeEventQueue.java:449)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:802)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:503)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

IntelliJ build info

IntelliJ IDEA 2020.2 EAP (Community Edition)
Build #IC-202.5958.24, built on June 25, 2020
Runtime version: 11.0.7+10-b944.13 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.5
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
Non-Bundled Plugins: IdeaVIM, Key Promoter X, com.github.kornilovaL.flamegraphProfiler, com.github.pshirshov.bytecodeeditor, CheckStyle-IDEA, Error-prone plugin, JOL, com.dubreuia, com.intellij.bigdecimal-folding, palantir-java-format, org.intellij.scala, InplaceRefactoring.InplaceRefactoring, ru.yole.jitwatch-intellij, PythonCore

After this PR

==COMMIT_MSG==
Explicitly extend the IntelliJ CodeStyleManagerImpl so that any methods added in newer releases are inherited automatically with a reasonable default implementation.

==COMMIT_MSG==

Possible downsides?

There may be cases where CodeStyleManagerDecorator should intercept new methods added to CodeStyleManagerImpl in the future and handle them in a different fashion.

schlosna added 2 commits June 27, 2020 18:43
Explicitly extend the IntelliJ CodeStyleManagerImpl so that any methods
added in newer releases are inherited automatically with a reasonable
default implementation.

JetBrains/intellij-community@2d57401
added a CodeManager#scheduleReformatWhenSettingsComputed(PsiFile) method
in idea/202.5103.13 where the default implementation throws an
UnsuportedOperationException.

See https://youtrack.jetbrains.com/issue/IDEA-244645 for more details.
@changelog-app
Copy link

changelog-app bot commented Jun 27, 2020

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Explicitly extend the IntelliJ CodeStyleManagerImpl so that any methods added in newer releases are inherited automatically with a reasonable default implementation.

Check the box to generate changelog(s)

  • Generate changelog entry

Copy link
Contributor

@carterkozak carterkozak left a comment

Choose a reason for hiding this comment

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

thanks!

@bulldozer-bot bulldozer-bot bot merged commit e588a08 into develop Jun 29, 2020
@bulldozer-bot bulldozer-bot bot deleted the ds/IDEA-244645 branch June 29, 2020 16:12
@svc-autorelease
Copy link
Collaborator

Released 1.0.1

@krasa
Copy link

krasa commented Jun 30, 2020

I suggest using proxies, not directly extend CodeStyleManagerImpl... It does not break the IDE due to API changes.
https://youtrack.jetbrains.com/issue/IDEA-244645#focus=streamItem-27-4230448.0-0

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

Successfully merging this pull request may close these issues.

4 participants