Repository navigation
Sync with JB: option "Shorten FQ names" is always visible #305
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,11 +44,7 @@ public KeyWithDefaultValue<Boolean> getKey() { | |
| } | ||
|
|
||
| @Override | ||
| public void processText(Project project, | ||
| Template template, | ||
| Document document, | ||
| RangeMarker templateRange, | ||
| Editor editor) { | ||
| public void processText(Project project, Template template, Document document, RangeMarker templateRange, Editor editor) { | ||
| try { | ||
| PsiDocumentManager.getInstance(project).commitDocument(document); | ||
| JavaCodeStyleManager javaStyle = JavaCodeStyleManager.getInstance(project); | ||
|
|
@@ -66,4 +62,9 @@ public void processText(Project project, | |
| public LocalizeValue getOptionText() { | ||
| return CodeInsightLocalize.dialogEditTemplateCheckboxShortenFqNames(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isVisible(Template template) { | ||
| return true; | ||
| } | ||
|
Comment on lines
+66
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct sync, and worth spelling out why it is needed here, because Consulo differs from JB at the interface level:
Side effect worth being aware of: |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,7 +43,7 @@ | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * @author Denis Zhdanov | ||||||||||||||||||||||||
| * @since 4/27/11 3:07 PM | ||||||||||||||||||||||||
| * @since 2011-04-27 | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| @ExtensionImpl | ||||||||||||||||||||||||
| public class ShortenToStaticImportProcessor implements TemplateOptionalProcessor { | ||||||||||||||||||||||||
|
|
@@ -57,21 +57,22 @@ public KeyWithDefaultValue<Boolean> getKey() { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||
| @RequiredReadAction | ||||||||||||||||||||||||
| public void processText(Project project, Template template, Document document, RangeMarker templateRange, Editor editor) { | ||||||||||||||||||||||||
|
Comment on lines
59
to
61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this file is already being touched, consider whether the "Use static import" checkbox needs the same treatment — right now it is unreachable from the UI:
JB solves this with a context-aware override (
Suggested change
If you would rather keep this PR narrowly scoped to the JB sync, that is fine — but then it is worth filing a follow-up, because the option is currently dead UI. |
||||||||||||||||||||||||
| PsiDocumentManager.getInstance(project).commitDocument(document); | ||||||||||||||||||||||||
| PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project); | ||||||||||||||||||||||||
| if (file == null) { | ||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| List<Pair<PsiElement, StaticImporter>> staticImportTargets = new ArrayList<Pair<PsiElement, StaticImporter>>(); | ||||||||||||||||||||||||
| List<Pair<PsiElement, StaticImporter>> staticImportTargets = new ArrayList<>(); | ||||||||||||||||||||||||
| for ( | ||||||||||||||||||||||||
| PsiElement element = PsiUtilCore.getElementAtOffset(file, templateRange.getStartOffset()); | ||||||||||||||||||||||||
| element != null && element.getTextRange().getStartOffset() < templateRange.getEndOffset(); | ||||||||||||||||||||||||
| element = getNext(element)) { | ||||||||||||||||||||||||
| for (StaticImporter importer : IMPORTERS) { | ||||||||||||||||||||||||
| if (importer.canPerform(element)) { | ||||||||||||||||||||||||
| staticImportTargets.add(new Pair<PsiElement, StaticImporter>(element, importer)); | ||||||||||||||||||||||||
| staticImportTargets.add(Pair.create(element, importer)); | ||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
@@ -85,6 +86,7 @@ public void processText(Project project, Template template, Document document, R | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Nullable | ||||||||||||||||||||||||
| @RequiredReadAction | ||||||||||||||||||||||||
| private static PsiElement getNext(PsiElement element) { | ||||||||||||||||||||||||
| PsiElement result = element.getNextSibling(); | ||||||||||||||||||||||||
| for (PsiElement current = element; current != null && result == null; current = current.getParent()) { | ||||||||||||||||||||||||
|
|
@@ -106,6 +108,7 @@ private interface StaticImporter { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private static class SingleMemberStaticImporter implements StaticImporter { | ||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||
| @RequiredReadAction | ||||||||||||||||||||||||
| public boolean canPerform(PsiElement element) { | ||||||||||||||||||||||||
| return AddSingleMemberStaticImportAction.getStaticImportClass(element) != null; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency nit: this PR adds
@RequiredReadActiontoprocessTextinShortenToStaticImportProcessor, but this one does the same kind of PSI work (PsiUtilBase.getPsiFileInEditor, plusJavaCodeStyleManager#shortenClassReferences, which is itself@RequiredReadActioninJavaCodeStyleManagerImpl) and stays unannotated. Since the signature line is being reformatted here anyway, annotating both keeps the pair symmetric.Needs
import consulo.annotation.access.RequiredReadAction;next to the otherconsulo.annotation.*imports.