diff --git a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java index abf5853002f4..ad23fb5a8f56 100644 --- a/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java +++ b/java/idea-ui/src/com/intellij/ide/projectWizard/ProjectTypeStep.java @@ -24,6 +24,7 @@ import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelBase; import com.intellij.ide.util.projectWizard.*; import com.intellij.ide.wizard.CommitStepException; import com.intellij.openapi.Disposable; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleType; @@ -596,7 +597,12 @@ public class ProjectTypeStep extends ModuleWizardStep implements SettingsStep, D } void loadRemoteTemplates(final ChooseTemplateStep chooseTemplateStep) { - UiNotifyConnector.doWhenFirstShown(myPanel, () -> startLoadingRemoteTemplates(chooseTemplateStep)); + if (!ApplicationManager.getApplication().isUnitTestMode()) { + UiNotifyConnector.doWhenFirstShown(myPanel, () -> startLoadingRemoteTemplates(chooseTemplateStep)); + } + else { + startLoadingRemoteTemplates(chooseTemplateStep); + } } private void startLoadingRemoteTemplates(ChooseTemplateStep chooseTemplateStep) { diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java index 70b63da4d515..76ba1c3f1a49 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/RemoveUnusedVariableUtil.java @@ -177,7 +177,7 @@ public class RemoveUnusedVariableUtil { !(variable.getParent() instanceof PsiDeclarationStatement && ((PsiDeclarationStatement)variable.getParent()).getDeclaredElements().length > 1)) { if (deleteMode == RemoveMode.MAKE_STATEMENT) { - element = element.replace(createStatementIfNeeded(expression, factory, element)); + element = element.getParent().replace(createStatementIfNeeded(expression, factory, element)); List references = new ArrayList<>(); collectReferences(element, variable, references); deleteReferences(variable, references, deleteMode); diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java index 31df112fb414..8bf03b086e18 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/InvertIfConditionAction.java @@ -47,6 +47,7 @@ public class InvertIfConditionAction extends PsiElementBaseIntentionAction { if (ifStatement == null) return false; final PsiExpression condition = ifStatement.getCondition(); if (condition == null) return false; + if (condition instanceof PsiPrefixExpression && ((PsiPrefixExpression)condition).getOperand() == null) return false; if (ifStatement.getThenBranch() == null) return false; if (element instanceof PsiKeyword) { PsiKeyword keyword = (PsiKeyword) element; diff --git a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java index c8729a2aed58..a066cd08cca9 100644 --- a/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java +++ b/java/java-impl/src/com/intellij/codeInsight/javadoc/JavaDocInfoGenerator.java @@ -15,7 +15,9 @@ */ package com.intellij.codeInsight.javadoc; -import com.intellij.codeInsight.*; +import com.intellij.codeInsight.AnnotationUtil; +import com.intellij.codeInsight.CodeInsightBundle; +import com.intellij.codeInsight.ExceptionUtil; import com.intellij.codeInsight.documentation.DocumentationManagerProtocol; import com.intellij.codeInsight.documentation.DocumentationManagerUtil; import com.intellij.javadoc.JavadocGeneratorRunProfile; @@ -1617,7 +1619,7 @@ public class JavaDocInfoGenerator { if (valueElement == null) return false; if (Arrays.stream(localTags) .map(PsiDocTag::getValueElement) - .map(ObjectUtils::notNull) + .filter(Objects::nonNull) .anyMatch(docTagValue -> areWeakEqual(docTagValue.getText(), valueElement.getText()))) { return false; } diff --git a/java/java-tests/testData/codeInsight/invertIfCondition/beforeMissingCondition.java b/java/java-tests/testData/codeInsight/invertIfCondition/beforeMissingCondition.java new file mode 100644 index 000000000000..8e3ed90f5534 --- /dev/null +++ b/java/java-tests/testData/codeInsight/invertIfCondition/beforeMissingCondition.java @@ -0,0 +1,6 @@ +// "Invert 'if' condition" "false" +class A { + public void foo(boolean c) { + if (!) return; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java index 8928b6b1e3ec..32300f1e410d 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java @@ -70,9 +70,19 @@ public class JavaCodeInsightSanityTest extends LightPlatformCodeInsightFixtureTe } private static boolean shouldGoInsiderDir(@NotNull String name) { - return !name.equals("out") && - !name.equals("gen") && // https://youtrack.jetbrains.com/issue/IDEA-175404 - !name.endsWith("system") && !name.endsWith("config"); + return !name.equals("gen") && // https://youtrack.jetbrains.com/issue/IDEA-175404 + !name.equals("reports") && // no idea what this is + !name.equals("android") && // no 'android' repo on agents in some builds + !containsBinariesOnly(name) && + !name.endsWith("system") && !name.endsWith("config"); // temporary stuff from tests or debug IDE + } + + private static boolean containsBinariesOnly(@Nullable String name) { + return name.equals("jdk") || + name.equals("jre") || + name.equals("lib") || + name.equals("bin") || + name.equals("out"); } @NotNull @@ -114,6 +124,7 @@ public class JavaCodeInsightSanityTest extends LightPlatformCodeInsightFixtureTe } List toChoose = preferDirs(data, children); + Collections.sort(toChoose); int index = data.drawInt(IntDistribution.uniform(0, toChoose.size() - 1)); File generated = generateRandomFile(data, toChoose.get(index), exhausted); if (generated != null) { diff --git a/platform/diff-impl/src/com/intellij/diff/actions/impl/OpenInEditorAction.java b/platform/diff-impl/src/com/intellij/diff/actions/impl/OpenInEditorAction.java index e2eb94717b02..b6acf5be7ee2 100644 --- a/platform/diff-impl/src/com/intellij/diff/actions/impl/OpenInEditorAction.java +++ b/platform/diff-impl/src/com/intellij/diff/actions/impl/OpenInEditorAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,6 @@ import com.intellij.diff.tools.util.DiffDataKeys; import com.intellij.diff.util.DiffUserDataKeys; import com.intellij.diff.util.DiffUtil; import com.intellij.ide.actions.EditSourceAction; -import com.intellij.openapi.actionSystem.ActionPlaces; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.DataKey; import com.intellij.openapi.actionSystem.ex.ActionUtil; @@ -44,7 +43,7 @@ public class OpenInEditorAction extends EditSourceAction implements DumbAware { @Override public void update(@NotNull AnActionEvent e) { - if (!ActionPlaces.isToolbarPlace(e.getPlace())) { + if (!e.isActionToolbar()) { e.getPresentation().setEnabledAndVisible(true); return; } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java index 652bbb5da588..4943255ec236 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DocumentationManager.java @@ -714,6 +714,13 @@ public class DocumentationManager extends DockablePopupManager { if (myProject.isDisposed()) return; LOG.debug("Started fetching documentation..."); + + final PsiElement element = ReadAction.compute(() -> provider.getElement()); + if (element == null) { + LOG.debug("Element for which documentation was requested is not available anymore"); + return; + } + final Throwable[] ex = new Throwable[1]; String text = null; try { @@ -738,11 +745,6 @@ public class DocumentationManager extends DockablePopupManager provider.getElement()); - if (element == null) { - LOG.debug("Element for which documentation was requested is not available anymore"); - return; - } final String documentationText = text; PsiDocumentManager.getInstance(myProject).performLaterWhenAllCommitted(() -> { if (!element.isValid()) { @@ -1132,6 +1134,7 @@ public class DocumentationManager extends DockablePopupManager result = new Ref<>(); QuickDocUtil.runInReadActionWithWriteActionPriorityWithRetries(() -> { + if (!myElement.isValid()) return; final SmartPsiElementPointer originalElement = myElement.getUserData(ORIGINAL_ELEMENT_KEY); String doc = provider.generateDoc(myElement, originalElement != null ? originalElement.getElement() : null); result.set(doc); diff --git a/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateAction.java b/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateAction.java index 21696aa98e16..4eac1dbc4db5 100644 --- a/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateAction.java +++ b/platform/lang-impl/src/com/intellij/ide/fileTemplates/actions/CreateFromTemplateAction.java @@ -22,31 +22,42 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.util.function.Supplier; public class CreateFromTemplateAction extends CreateFromTemplateActionBase { + private final Supplier myTemplate; - private final FileTemplate myTemplate; + // Avoid calling the constructor from normal IDE actions, because: + // - Normal actions are preloaded at startup + // - Accessing FileTemplate out of FileTemplateManager triggers costly initialization + public CreateFromTemplateAction(@NotNull FileTemplate template) { + this(template.getName(), FileTemplateUtil.getIcon(template), () -> template); + } - public CreateFromTemplateAction(FileTemplate template){ - super(template.getName(), null, FileTemplateUtil.getIcon(template)); + public CreateFromTemplateAction(String templateName, @Nullable Icon icon, @NotNull Supplier template){ + super(templateName, null, icon); myTemplate = template; } @Override protected FileTemplate getTemplate(final Project project, final PsiDirectory dir) { - return myTemplate; + return myTemplate.get(); } @Override public void update(AnActionEvent e){ super.update(e); Presentation presentation = e.getPresentation(); - boolean isEnabled = CreateFromTemplateGroup.canCreateFromTemplate(e, myTemplate); + boolean isEnabled = CreateFromTemplateGroup.canCreateFromTemplate(e, myTemplate.get()); presentation.setEnabled(isEnabled); presentation.setVisible(isEnabled); } public FileTemplate getTemplate() { - return myTemplate; + return myTemplate.get(); } } diff --git a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopePaneSelectInTarget.java b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopePaneSelectInTarget.java index 99d00a895cd4..51c28521530d 100644 --- a/platform/lang-impl/src/com/intellij/ide/scopeView/ScopePaneSelectInTarget.java +++ b/platform/lang-impl/src/com/intellij/ide/scopeView/ScopePaneSelectInTarget.java @@ -20,6 +20,7 @@ import com.intellij.ide.SelectInContext; import com.intellij.ide.SelectInManager; import com.intellij.ide.StandardTargetWeights; import com.intellij.ide.impl.ProjectViewSelectInTarget; +import com.intellij.ide.scratch.ScratchUtil; import com.intellij.openapi.project.Project; import com.intellij.packageDependencies.DependencyValidationManager; import com.intellij.psi.PsiElement; @@ -53,6 +54,7 @@ public class ScopePaneSelectInTarget extends ProjectViewSelectInTarget { @Nullable private NamedScope getContainingScope(@Nullable PsiFile file) { if (file == null) return null; + if (ScratchUtil.isScratch(file.getVirtualFile())) return null; NamedScopesHolder scopesHolder = DependencyValidationManager.getInstance(myProject); for (NamedScope scope : ScopeViewPane.getShownScopes(myProject)) { PackageSet packageSet = scope.getValue(); diff --git a/platform/platform-api/src/com/intellij/ui/HighlightableComponent.java b/platform/platform-api/src/com/intellij/ui/HighlightableComponent.java index 3eb3770683a6..839192003c68 100644 --- a/platform/platform-api/src/com/intellij/ui/HighlightableComponent.java +++ b/platform/platform-api/src/com/intellij/ui/HighlightableComponent.java @@ -21,11 +21,9 @@ import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ui.UIUtil; -import gnu.trove.TIntObjectHashMap; import org.jetbrains.annotations.Nullable; import javax.accessibility.Accessible; -import javax.accessibility.AccessibleAction; import javax.accessibility.AccessibleContext; import javax.accessibility.AccessibleRole; import javax.swing.*; @@ -40,7 +38,6 @@ public class HighlightableComponent extends JComponent implements Accessible { protected Icon myIcon; protected int myIconTextGap; protected ArrayList myHighlightedRegions; - protected TIntObjectHashMap myFontMetrics; protected boolean myIsSelected; protected boolean myHasFocus; protected boolean myPaintUnfocusedSelection = false; @@ -48,20 +45,13 @@ public class HighlightableComponent extends JComponent implements Accessible { public HighlightableComponent() { myIconTextGap = 4; - myFontMetrics = new TIntObjectHashMap<>(); setText(""); - fillFontMetricsMap(); setOpaque(true); + updateUI(); } - protected void fillFontMetricsMap() { - Font font = getFont(); - if (font != null){ - myFontMetrics.put(Font.PLAIN, getFontMetrics(font.deriveFont(Font.PLAIN))); - myFontMetrics.put(Font.BOLD, getFontMetrics(font.deriveFont(Font.BOLD))); - myFontMetrics.put(Font.ITALIC, getFontMetrics(font.deriveFont(Font.ITALIC))); - myFontMetrics.put(Font.BOLD | Font.ITALIC, getFontMetrics(font.deriveFont(Font.BOLD | Font.ITALIC))); - } + @Override public void updateUI() { + UISettings.setupComponentAntialiasing(this); } public void setText(String text) { @@ -88,13 +78,6 @@ public class HighlightableComponent extends JComponent implements Accessible { myIcon = icon; } - public void setFont(Font font) { - if (!font.equals(getFont())){ - super.setFont(font); - fillFontMetricsMap(); - } - } - public void addHighlighter(int startOffset, int endOffset, TextAttributes attributes) { addHighlighter(0, startOffset, endOffset, attributes); } @@ -298,7 +281,8 @@ public class HighlightableComponent extends JComponent implements Accessible { offset += defFontMetrics.stringWidth(text); } - FontMetrics fontMetrics = myFontMetrics.get(hRegion.textAttributes.getFontType()); + Font regFont = getFont().deriveFont(hRegion.textAttributes.getFontType()); + FontMetrics fontMetrics = getFontMetrics(regFont); text = myText.substring(hRegion.startOffset, hRegion.endOffset); @@ -313,8 +297,7 @@ public class HighlightableComponent extends JComponent implements Accessible { if (hRegion.textAttributes.getForegroundColor() != null && paintHighlightsForeground) { g.setColor(hRegion.textAttributes.getForegroundColor()); - } - else { + } else { g.setColor(fgColor); } @@ -323,7 +306,7 @@ public class HighlightableComponent extends JComponent implements Accessible { // draw highlight underscored line - if (hRegion.textAttributes.getEffectColor() != null) { + if (hRegion.textAttributes.getEffectType() != null && hRegion.textAttributes.getEffectColor() != null) { g.setColor(hRegion.textAttributes.getEffectColor()); int y = yOffset/*fontMetrics.getMaxAscent()*/ + 2; UIUtil.drawLine(g, offset, y, offset + fontMetrics.stringWidth(text) - 1, y); @@ -385,7 +368,9 @@ public class HighlightableComponent extends JComponent implements Accessible { if (width > x) return null; String text = getRegionText(hRegion); - FontMetrics fontMetrics = myFontMetrics.get(hRegion.textAttributes.getFontType()); + Font regFont = getFont().deriveFont(hRegion.textAttributes.getFontType()); + FontMetrics fontMetrics = getFontMetrics(regFont); + width += fontMetrics.stringWidth(text); if (width > x) return hRegion; } @@ -409,7 +394,9 @@ public class HighlightableComponent extends JComponent implements Accessible { endIndex = hRegion.endOffset; String text = getRegionText(hRegion); - FontMetrics fontMetrics = myFontMetrics.get(hRegion.textAttributes.getFontType()); + Font regFont = getFont().deriveFont(hRegion.textAttributes.getFontType()); + FontMetrics fontMetrics = getFontMetrics(regFont); + width += fontMetrics.stringWidth(text); } width += defFontMetrics.stringWidth(myText.substring(endIndex, myText.length())); diff --git a/platform/platform-api/src/com/intellij/ui/HyperlinkLabel.java b/platform/platform-api/src/com/intellij/ui/HyperlinkLabel.java index b907c9955d4b..d73f5d7a6d2c 100644 --- a/platform/platform-api/src/com/intellij/ui/HyperlinkLabel.java +++ b/platform/platform-api/src/com/intellij/ui/HyperlinkLabel.java @@ -59,6 +59,9 @@ public class HyperlinkLabel extends HighlightableComponent { private final TextAttributes myAnchorAttributes; private HyperlinkListener myHyperlinkListener = null; + private boolean myMouseHover; + private boolean myMousePressed; + public HyperlinkLabel() { this(""); } @@ -72,8 +75,10 @@ public class HyperlinkLabel extends HighlightableComponent { } public HyperlinkLabel(String text, final Color textForegroundColor, final Color textBackgroundColor, final Color textEffectColor) { - myAnchorAttributes = + myAnchorAttributes = UIUtil.isUnderWin10LookAndFeel() ? + new Win10TextAttributes(textBackgroundColor) : new TextAttributes(textForegroundColor, textBackgroundColor, textEffectColor, EffectType.LINE_UNDERSCORE, Font.PLAIN); + enforceBackgroundOutsideText(textBackgroundColor); setHyperlinkText(text); enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK); @@ -114,11 +119,21 @@ public class HyperlinkLabel extends HighlightableComponent { } protected void processMouseEvent(MouseEvent e) { - if (e.getID() == MouseEvent.MOUSE_EXITED) { + if (e.getID() == MouseEvent.MOUSE_ENTERED && isOnLink(e.getX())) { + myMouseHover = true; + repaint(); + } else if (e.getID() == MouseEvent.MOUSE_EXITED) { setCursor(Cursor.getDefaultCursor()); - } - else if (UIUtil.isActionClick(e, MouseEvent.MOUSE_PRESSED) && isOnLink(e.getX())) { + myMouseHover = false; + myMousePressed = false; + repaint(); + } else if (UIUtil.isActionClick(e, MouseEvent.MOUSE_PRESSED) && isOnLink(e.getX())) { fireHyperlinkEvent(); + myMousePressed = true; + repaint(); + } else if (e.getID() == MouseEvent.MOUSE_RELEASED) { + myMousePressed = false; + repaint(); } super.processMouseEvent(e); } @@ -126,7 +141,14 @@ public class HyperlinkLabel extends HighlightableComponent { @Override protected void processMouseMotionEvent(MouseEvent e) { if (e.getID() == MouseEvent.MOUSE_MOVED) { - setCursor(isOnLink(e.getX()) ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : Cursor.getDefaultCursor()); + boolean onLink = isOnLink(e.getX()); + boolean needRepaint = myMouseHover != onLink; + myMouseHover = onLink; + setCursor(myMouseHover ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : Cursor.getDefaultCursor()); + + if (needRepaint) { + repaint(); + } } super.processMouseMotionEvent(e); } @@ -240,6 +262,7 @@ public class HyperlinkLabel extends HighlightableComponent { @Override public void updateUI() { + super.updateUI(); setFont(UIUtil.getLabelFont()); } @@ -253,7 +276,7 @@ public class HyperlinkLabel extends HighlightableComponent { /** * Hyperlink accessibility: "HYPERLINK" role and expose a "click" action. - * @see javax.swing.AbstractButton.AccessibleAbstractButton + * @see AbstractButton.AccessibleAbstractButton */ protected class AccessibleHyperlinkLabel extends AccessibleHighlightable implements AccessibleAction { @Override @@ -291,4 +314,35 @@ public class HyperlinkLabel extends HighlightableComponent { } } } + + private class Win10TextAttributes extends TextAttributes { + private Win10TextAttributes(Color textBackgroundColor) { + super(null, textBackgroundColor, null, null, Font.PLAIN); + } + + @Override public Color getForegroundColor() { + return !isEnabled() ? UIManager.getColor("Label.disabledForeground") : + myMousePressed ? UIManager.getColor("link.pressed.foreground") : + myMouseHover ? UIManager.getColor("link.hover.foreground") : + UIManager.getColor("link.foreground"); + } + + @Override public Color getEffectColor() { + return getForegroundColor(); + } + + @Override public EffectType getEffectType() { + return !isEnabled() || myMouseHover || myMousePressed ? EffectType.LINE_UNDERSCORE : null; + } + + @Override public void setForegroundColor(Color color) { + throw new UnsupportedOperationException(); + } + @Override public void setEffectColor(Color color) { + throw new UnsupportedOperationException(); + } + @Override public void setEffectType(EffectType effectType) { + throw new UnsupportedOperationException(); + } + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java index 9b143a8201ca..7e38b1a73777 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionButton.java @@ -179,7 +179,7 @@ public class ActionButton extends JComponent implements ActionButtonComponent, A } }); popupMenu.setDataContextProvider(() -> this.getDataContext()); - if (ActionPlaces.isToolbarPlace(event.getPlace())) { + if (event.isActionToolbar()) { popupMenu.getComponent().show(this, 0, getHeight()); } else { diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleUseSoftWrapsMenuAction.java b/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleUseSoftWrapsMenuAction.java index cfe7b6bf1018..0813d5639005 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleUseSoftWrapsMenuAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/actions/ToggleUseSoftWrapsMenuAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2010 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ public class ToggleUseSoftWrapsMenuAction extends AbstractToggleUseSoftWrapsActi @Override public void update(@NotNull AnActionEvent e){ super.update(e); - if (!ActionPlaces.isToolbarPlace(e.getPlace())) { + if (!e.isActionToolbar()) { e.getPresentation().setIcon(null); } if (ActionPlaces.UNKNOWN.equals(e.getPlace())) { diff --git a/plugins/coverage-common/src/com/intellij/coverage/actions/HideCoverageInfoAction.java b/plugins/coverage-common/src/com/intellij/coverage/actions/HideCoverageInfoAction.java index a10c4685a0a2..139e8149d5da 100644 --- a/plugins/coverage-common/src/com/intellij/coverage/actions/HideCoverageInfoAction.java +++ b/plugins/coverage-common/src/com/intellij/coverage/actions/HideCoverageInfoAction.java @@ -1,9 +1,27 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.intellij.coverage.actions; import com.intellij.coverage.CoverageDataManager; import com.intellij.coverage.CoverageSuitesBundle; import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.project.Project; public class HideCoverageInfoAction extends AnAction { @@ -19,8 +37,8 @@ public class HideCoverageInfoAction extends AnAction { public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setEnabled(false); - presentation.setVisible(ActionPlaces.isToolbarPlace(e.getPlace())); - final Project project = e.getData(CommonDataKeys.PROJECT); + presentation.setVisible(e.isActionToolbar()); + final Project project = e.getProject(); if (project != null) { final CoverageSuitesBundle suitesBundle = CoverageDataManager.getInstance(project).getCurrentSuitesBundle(); presentation.setEnabled(suitesBundle != null); diff --git a/plugins/git4idea/src/git4idea/GitCommit.java b/plugins/git4idea/src/git4idea/GitCommit.java index 2696a90bf7ff..9890768d49b8 100644 --- a/plugins/git4idea/src/git4idea/GitCommit.java +++ b/plugins/git4idea/src/git4idea/GitCommit.java @@ -178,7 +178,7 @@ public final class GitCommit extends VcsCommitMetadataImpl implements VcsFullCom @NotNull private ParsedChanges parseChanges() throws VcsException { - List mergedChanges = parseStatusInfo(getMergedStatusInfo(), ContainerUtil.map(getParents(), Hash::asString)); + List mergedChanges = parseStatusInfo(getMergedStatusInfo(), 0); List> changes = computeChanges(mergedChanges); ParsedChanges parsedChanges = new ParsedChanges(mergedChanges, changes); myChanges.compareAndSet(this, parsedChanges); @@ -230,17 +230,19 @@ public final class GitCommit extends VcsCommitMetadataImpl implements VcsFullCom else { List> changes = ContainerUtil.newArrayListWithCapacity(myChangesOutput.size()); for (int i = 0; i < myChangesOutput.size(); i++) { - List statusInfos = myChangesOutput.get(i); - changes.add(parseStatusInfo(statusInfos, Collections.singletonList(getParents().get(i).asString()))); + changes.add(parseStatusInfo(myChangesOutput.get(i), i)); } return changes; } } @NotNull - private List parseStatusInfo(@NotNull List changes, - @NotNull List parentHashes) throws VcsException { - return GitChangesParser.parse(myProject, getRoot(), changes, getId().asString(), new Date(getCommitTime()), parentHashes); + private List parseStatusInfo(@NotNull List changes, int parentIndex) throws VcsException { + String parentHash = null; + if (parentIndex < getParents().size()) { + parentHash = getParents().get(parentIndex).asString(); + } + return GitChangesParser.parse(myProject, getRoot(), changes, getId().asString(), new Date(getCommitTime()), parentHash); } /* diff --git a/plugins/git4idea/src/git4idea/history/GitChangesParser.java b/plugins/git4idea/src/git4idea/history/GitChangesParser.java index fc9d8032104c..9c4da8fb4a04 100644 --- a/plugins/git4idea/src/git4idea/history/GitChangesParser.java +++ b/plugins/git4idea/src/git4idea/history/GitChangesParser.java @@ -25,7 +25,6 @@ import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vfs.VirtualFile; import git4idea.GitContentRevision; import git4idea.GitRevisionNumber; -import git4idea.history.wholeTree.AbstractHash; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,37 +40,27 @@ public class GitChangesParser { @NotNull List statusInfos, @NotNull String hash, @NotNull Date date, - @NotNull List parentsHashes) throws VcsException { + @Nullable String parentsHash) throws VcsException { GitRevisionNumber thisRevision = new GitRevisionNumber(hash, date); - List parentRevisions = prepareParentRevisions(parentsHashes); + GitRevisionNumber parentRevision = parentsHash == null ? null : new GitRevisionNumber(parentsHash); List result = new ArrayList<>(); for (GitLogStatusInfo statusInfo : statusInfos) { - result.add(parseChange(project, root, parentRevisions, statusInfo, thisRevision)); + result.add(parseChange(project, root, thisRevision, parentRevision, statusInfo)); } return result; } - private static List prepareParentRevisions(List parentsHashes) { - final List parents = new ArrayList<>(parentsHashes.size()); - for (String parentsShortHash : parentsHashes) { - parents.add(AbstractHash.create(parentsShortHash)); - } - - final List parentRevisions = new ArrayList<>(parents.size()); - for (AbstractHash parent : parents) { - parentRevisions.add(new GitRevisionNumber(parent.getString())); - } - return parentRevisions; - } - - private static Change parseChange(final Project project, final VirtualFile vcsRoot, final List parentRevisions, - final GitLogStatusInfo statusInfo, final VcsRevisionNumber thisRevision) throws VcsException { + @NotNull + private static Change parseChange(@NotNull Project project, + @NotNull VirtualFile vcsRoot, + @NotNull VcsRevisionNumber thisRevision, + @Nullable VcsRevisionNumber parentRevision, + @NotNull GitLogStatusInfo statusInfo) throws VcsException { final ContentRevision before; final ContentRevision after; FileStatus status = null; final String path = statusInfo.getFirstPath(); - @Nullable GitRevisionNumber firstParent = parentRevisions.isEmpty() ? null : parentRevisions.get(0); switch (statusInfo.getType()) { case ADDED: @@ -86,13 +75,13 @@ public class GitChangesParser { status = FileStatus.MODIFIED; } final FilePath filePath = GitContentRevision.createPath(vcsRoot, path, true, true); - before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, false, true); + before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, false, true); after = GitContentRevision.createRevision(filePath, thisRevision, project, null); break; case DELETED: status = FileStatus.DELETED; final FilePath filePathDeleted = GitContentRevision.createPath(vcsRoot, path, true, true); - before = GitContentRevision.createRevision(filePathDeleted, firstParent, project, null); + before = GitContentRevision.createRevision(filePathDeleted, parentRevision, project, null); after = null; break; case COPIED: @@ -101,13 +90,13 @@ public class GitChangesParser { String secondPath = statusInfo.getSecondPath(); final FilePath filePathAfterRename = GitContentRevision.createPath(vcsRoot, secondPath == null ? path : secondPath, false, true); - before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, true, true); + before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, true, true); after = GitContentRevision.createRevision(filePathAfterRename, thisRevision, project, null); break; case TYPE_CHANGED: status = FileStatus.MODIFIED; final FilePath filePath2 = GitContentRevision.createPath(vcsRoot, path, true, true); - before = GitContentRevision.createRevision(vcsRoot, path, firstParent, project, false, true); + before = GitContentRevision.createRevision(vcsRoot, path, parentRevision, project, false, true); after = GitContentRevision.createRevision(filePath2, thisRevision, project, null); break; default: @@ -115,5 +104,4 @@ public class GitChangesParser { } return new Change(before, after, status); } - } diff --git a/plugins/git4idea/src/git4idea/history/GitLogRecord.java b/plugins/git4idea/src/git4idea/history/GitLogRecord.java index b9cd6bb3e241..7c0b119af8d9 100644 --- a/plugins/git4idea/src/git4idea/history/GitLogRecord.java +++ b/plugins/git4idea/src/git4idea/history/GitLogRecord.java @@ -256,7 +256,8 @@ class GitLogRecord { @NotNull public List parseChanges(@NotNull Project project, @NotNull VirtualFile vcsRoot) throws VcsException { - return GitChangesParser.parse(project, vcsRoot, myStatusInfo, getHash(), getDate(), Arrays.asList(getParentsHashes())); + String[] hashes = getParentsHashes(); + return GitChangesParser.parse(project, vcsRoot, myStatusInfo, getHash(), getDate(), hashes.length == 0 ? null : hashes[0]); } /** diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/AbstractHash.java b/plugins/git4idea/src/git4idea/history/wholeTree/AbstractHash.java deleted file mode 100644 index 9d94f9303a52..000000000000 --- a/plugins/git4idea/src/git4idea/history/wholeTree/AbstractHash.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.history.wholeTree; - -import com.intellij.vcs.log.Hash; -import com.intellij.vcs.log.impl.HashImpl; -import org.jetbrains.annotations.NotNull; - -/** - * @author irengrig - */ -@Deprecated -public class AbstractHash { - - @NotNull private final Hash myHash; - - private AbstractHash(@NotNull Hash hash) { - myHash = hash; - } - - @NotNull - public static AbstractHash create(final String hash) { - return new AbstractHash(HashImpl.build(hash)); - } - - public String getString() { - return myHash.asString(); - } - - @Override - public String toString() { - return getString(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - AbstractHash hash = (AbstractHash)o; - - if (!myHash.equals(hash.myHash)) return false; - - return true; - } - - @Override - public int hashCode() { - return myHash.hashCode(); - } - - public static boolean hashesEqual(@NotNull final AbstractHash hash1, @NotNull final AbstractHash hash2) { - if (hash1.equals(hash2)) return true; - final String s1 = hash1.getString(); - final String s2 = hash2.getString(); - if (s1.startsWith(s2) || s2.startsWith(s1)) return true; - return false; - } -} diff --git a/plugins/git4idea/tests/git4idea/tests/AbstractHashTest.java b/plugins/git4idea/tests/git4idea/tests/AbstractHashTest.java deleted file mode 100644 index 564ccee20778..000000000000 --- a/plugins/git4idea/tests/git4idea/tests/AbstractHashTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2000-2010 JetBrains s.r.o. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package git4idea.tests; - -import git4idea.history.wholeTree.AbstractHash; -import junit.framework.Assert; -import junit.framework.TestCase; - -/** - * @author irengrig - */ -public class AbstractHashTest extends TestCase { - public void testSimple() throws Exception { - final String hash = "0a5b9f"; - final AbstractHash abstractHash = AbstractHash.create(hash); - Assert.assertFalse(abstractHash.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash, abstractHash.getString()); - } - public void testShort() throws Exception { - final String hash = "f"; - final AbstractHash abstractHash = AbstractHash.create(hash); - Assert.assertFalse(abstractHash.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash, abstractHash.getString()); - - final String hash1 = "ff"; - final AbstractHash abstractHash1 = AbstractHash.create(hash1); - Assert.assertFalse(abstractHash1.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash1, abstractHash1.getString()); - } - public void testLong() throws Exception { - final String hash = "0123456789abcdef0123456789abcdef01234567"; - final AbstractHash abstractHash = AbstractHash.create(hash); - Assert.assertFalse(abstractHash.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash, abstractHash.getString()); - } - public void testLeadingNulls() throws Exception { - final String hash0 = "0"; - final AbstractHash abstractHash0 = AbstractHash.create(hash0); - Assert.assertFalse(abstractHash0.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash0, abstractHash0.getString()); - - final String hash = "0f"; - final AbstractHash abstractHash = AbstractHash.create(hash); - Assert.assertFalse(abstractHash.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash, abstractHash.getString()); - - final String hash1 = "001"; - final AbstractHash abstractHash1 = AbstractHash.create(hash1); - Assert.assertFalse(abstractHash1.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash1, abstractHash1.getString()); - - final String hash2 = "000"; - final AbstractHash abstractHash2 = AbstractHash.create(hash2); - Assert.assertFalse(abstractHash2.getClass().getName().contains("AbstractHash.StringPresentation")); - Assert.assertEquals(hash2, abstractHash2.getString()); - } -} diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java index f8faad9c0675..44b75648997c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/console/GroovyConsole.java @@ -27,7 +27,10 @@ import com.intellij.execution.ui.ConsoleView; import com.intellij.execution.ui.ConsoleViewContentType; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.execution.ui.actions.CloseAction; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.ActionToolbar; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileEditorManager; @@ -39,7 +42,6 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Consumer; -import com.intellij.util.PathsList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.runner.DefaultGroovyScriptRunner; @@ -216,12 +218,7 @@ public class GroovyConsole { private static JavaParameters createJavaParameters(@NotNull Module module) throws ExecutionException { JavaParameters res = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module); - DefaultGroovyScriptRunner - .configureGenericGroovyRunner(res, module, "groovy.ui.GroovyMain", !GroovyConsoleUtil.hasGroovyAll(module), true); - PathsList list = GroovyScriptRunner.getClassPathFromRootModel(module, true, res, true, res.getClassPath()); - if (list != null) { - res.getClassPath().addAll(list.getPathList()); - } + DefaultGroovyScriptRunner.configureGenericGroovyRunner(res, module, "groovy.ui.GroovyMain", !GroovyConsoleUtil.hasGroovyAll(module), true, true, false); res.getProgramParametersList().addAll("-p", GroovyScriptRunner.getPathInConf("console.txt")); res.setWorkingDirectory(ModuleRootManager.getInstance(module).getContentRoots()[0].getPath()); res.setUseDynamicClasspath(true); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java index 51bfccce2da8..4af51c3e96c8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/grape/GrabDependencies.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -184,7 +184,7 @@ public class GrabDependencies implements IntentionAction { //javaParameters.getVMParametersList().add("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5239"); try { - DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module, GRAPE_RUNNER, false, true); + DefaultGroovyScriptRunner.configureGenericGroovyRunner(javaParameters, module, GRAPE_RUNNER, false, true, true, false); javaParameters.getClassPath().add(PathUtil.getJarPathForClass(GrapeRunner.class)); javaParameters.getProgramParametersList().add(queries.get(grabText)); javaParameters.setUseDynamicClasspath(true); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java index 8c573979dd7c..280c265fe849 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.incremental.groovy.GroovycOutputParser; import org.jetbrains.plugins.groovy.config.GroovyFacetUtil; -import org.jetbrains.plugins.groovy.grape.GrabDependencies; import org.jetbrains.plugins.groovy.util.LibrariesUtil; import java.nio.charset.Charset; @@ -63,7 +62,7 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { @Override public void configureCommandLine(JavaParameters params, @Nullable Module module, boolean tests, VirtualFile script, GroovyScriptRunConfiguration configuration) throws CantRunException { - configureGenericGroovyRunner(params, module, "groovy.ui.GroovyMain", false, tests, configuration.isAddClasspathToTheRunner()); + configureGenericGroovyRunner(params, module, "groovy.ui.GroovyMain", false, tests, configuration.isAddClasspathToTheRunner(), true); //addClasspathFromRootModel(module, tests, params, true); @@ -85,7 +84,7 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { @NotNull String mainClass, boolean useBundled, boolean tests) throws CantRunException { - configureGenericGroovyRunner(params, module, mainClass, useBundled, tests, true); + configureGenericGroovyRunner(params, module, mainClass, useBundled, tests, true, true); } public static void configureGenericGroovyRunner(@NotNull JavaParameters params, @@ -93,7 +92,8 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { @NotNull String mainClass, boolean useBundled, boolean tests, - boolean addClasspathToRunner) throws CantRunException { + boolean addClasspathToRunner, + boolean addClassPathToStarter) throws CantRunException { final VirtualFile groovyJar = findGroovyJar(module); if (useBundled) { params.getClassPath().add(GroovyFacetUtil.getBundledGroovyJar()); @@ -127,7 +127,7 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { params.getProgramParametersList().add("--main"); params.getProgramParametersList().add(mainClass); - if (!GrabDependencies.GRAPE_RUNNER.equals(mainClass)) { + if (addClassPathToStarter) { addClasspathFromRootModel(module, tests, params, true); } diff --git a/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduStepicConnector.java b/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduStepicConnector.java index 2470a1e83518..f4322494cbf6 100644 --- a/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduStepicConnector.java +++ b/python/educational-core/src/com/jetbrains/edu/learning/stepic/EduStepicConnector.java @@ -200,11 +200,11 @@ public class EduStepicConnector { } private static void setCourseLanguage(RemoteCourse info) { - if (info.isAdaptive()) { - info.setLanguage("Python"); // adaptive courses available only in PyCharm now + String courseType = info.getType(); + if (info.isAdaptive() && StringUtil.isEmptyOrSpaces(courseType)) { + info.setLanguage("Python"); return; } - String courseType = info.getType(); final int separator = courseType.indexOf(" "); assert separator != -1; final String language = courseType.substring(separator + 1); diff --git a/python/helpers/packaging_tool.py b/python/helpers/packaging_tool.py index fc0a71bcc974..e770cf41f671 100644 --- a/python/helpers/packaging_tool.py +++ b/python/helpers/packaging_tool.py @@ -161,6 +161,14 @@ def mkdtemp_ifneeded(): def main(): + try: + # As a workaround for #885 in setuptools, don't expose other helpers + # in sys.path so as not no confuse it with possible combination of + # namespace/ordinary packages + sys.path.remove(os.path.dirname(__file__)) + except ValueError: + pass + retcode = 0 try: if len(sys.argv) < 2: diff --git a/python/src/com/jetbrains/python/packaging/setupPy/CreateSetupPyAction.java b/python/src/com/jetbrains/python/packaging/setupPy/CreateSetupPyAction.java index 7bfff46bdbf1..749938ae36a8 100644 --- a/python/src/com/jetbrains/python/packaging/setupPy/CreateSetupPyAction.java +++ b/python/src/com/jetbrains/python/packaging/setupPy/CreateSetupPyAction.java @@ -16,7 +16,6 @@ package com.jetbrains.python.packaging.setupPy; import com.intellij.ide.IdeView; -import com.intellij.ide.fileTemplates.FileTemplate; import com.intellij.ide.fileTemplates.FileTemplateManager; import com.intellij.ide.fileTemplates.actions.AttributesDefaults; import com.intellij.ide.fileTemplates.actions.CreateFromTemplateAction; @@ -38,6 +37,7 @@ import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiManager; import com.intellij.util.SystemProperties; +import com.jetbrains.python.PythonFileType; import com.jetbrains.python.packaging.PyPackageUtil; import com.jetbrains.python.psi.PyUtil; @@ -50,18 +50,17 @@ import java.util.Properties; public class CreateSetupPyAction extends CreateFromTemplateAction { private static final String AUTHOR_PROPERTY = "python.packaging.author"; private static final String EMAIL_PROPERTY = "python.packaging.author.email"; + static final String SETUP_SCRIPT_TEMPLATE_NAME = "Setup Script"; public CreateSetupPyAction() { - super(FileTemplateManager.getDefaultInstance().getInternalTemplate("Setup Script")); + super( + SETUP_SCRIPT_TEMPLATE_NAME, + PythonFileType.INSTANCE.getIcon(), + () -> FileTemplateManager.getDefaultInstance().getInternalTemplate(SETUP_SCRIPT_TEMPLATE_NAME) + ); getTemplatePresentation().setText("Create setup.py"); } - @Override - public FileTemplate getTemplate() { - // to ensure changes are picked up, reload the template on every call (PY-6681) - return FileTemplateManager.getDefaultInstance().getInternalTemplate("Setup Script"); - } - @Override public void update(AnActionEvent e) { final Module module = e.getData(LangDataKeys.MODULE); diff --git a/python/src/com/jetbrains/python/packaging/setupPy/PyCreateSetupPyFromTemplateHandler.kt b/python/src/com/jetbrains/python/packaging/setupPy/PyCreateSetupPyFromTemplateHandler.kt index 13edb770944d..27a7b901353a 100644 --- a/python/src/com/jetbrains/python/packaging/setupPy/PyCreateSetupPyFromTemplateHandler.kt +++ b/python/src/com/jetbrains/python/packaging/setupPy/PyCreateSetupPyFromTemplateHandler.kt @@ -23,7 +23,7 @@ import com.intellij.openapi.util.text.StringUtil class PyCreateSetupPyFromTemplateHandler : DefaultCreateFromTemplateHandler() { override fun handlesTemplate(template: FileTemplate?): Boolean { - return template == FileTemplateManager.getDefaultInstance().getInternalTemplate("Setup Script") + return template == FileTemplateManager.getDefaultInstance().getInternalTemplate(CreateSetupPyAction.SETUP_SCRIPT_TEMPLATE_NAME) } override fun prepareProperties(props: MutableMap?) {