From 436b39433367c08bec8dcbd2bb3acbf1f5253001 Mon Sep 17 00:00:00 2001 From: Alexander Koshevoy Date: Fri, 25 Dec 2015 16:37:43 +0300 Subject: [PATCH 01/19] PY-17573 Initial steps to Docker Compose as Python remote interpreter --- .../DockerComposeCredentialsHolder.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java diff --git a/platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java new file mode 100644 index 000000000000..9a57daf2e6c9 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/remote/DockerComposeCredentialsHolder.java @@ -0,0 +1,83 @@ +/* + * Copyright 2000-2015 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.remote; + +import com.intellij.openapi.util.text.StringUtil; +import org.jdom.Element; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Alexander Koshevoy + */ +public class DockerComposeCredentialsHolder { + public static final String DOCKER_MACHINE_NAME = "DOCKER_MACHINE_NAME"; + public static final String DOCKER_COMPOSE_FILE_PATH = "DOCKER_COMPOSE_FILE_PATH"; + public static final String DOCKER_COMPOSE_SERVICE_NAME = "DOCKER_COMPOSE_SERVICE_NAME"; + public static final String DOCKER_REMOTE_PROJECT_PATH = "DOCKER_REMOTE_PROJECT_PATH"; + + private String myMachineName; + + private String myComposeFilePath; + + private String myComposeServiceName; + + private String myRemoteProjectPath; + + public DockerComposeCredentialsHolder() { + } + + public DockerComposeCredentialsHolder(@Nullable String machineName, + @Nullable String composeFilePath, + @Nullable String composeServiceName, + @Nullable String remoteProjectPath) { + myMachineName = machineName; + myComposeFilePath = composeFilePath; + myComposeServiceName = composeServiceName; + myRemoteProjectPath = remoteProjectPath; + } + + public String getMachineName() { + return myMachineName; + } + + public String getComposeFilePath() { + return myComposeFilePath; + } + + public String getComposeServiceName() { + return myComposeServiceName; + } + + public String getRemoteProjectPath() { + return myRemoteProjectPath; + } + + public void save(@NotNull Element element) { + if (StringUtil.isNotEmpty(myMachineName)) { + element.setAttribute(DOCKER_MACHINE_NAME, myMachineName); + } + element.setAttribute(DOCKER_COMPOSE_FILE_PATH, myComposeFilePath); + element.setAttribute(DOCKER_COMPOSE_SERVICE_NAME, myComposeServiceName); + } + + public void load(@NotNull Element element) { + myMachineName = element.getAttributeValue(DOCKER_MACHINE_NAME); + myComposeFilePath = element.getAttributeValue(DOCKER_COMPOSE_FILE_PATH); + myComposeServiceName = element.getAttributeValue(DOCKER_COMPOSE_SERVICE_NAME); + myRemoteProjectPath = element.getAttributeValue(DOCKER_REMOTE_PROJECT_PATH); + } +} From 67d2bb22871e27974c8c8a2668cd6f92f9f31221 Mon Sep 17 00:00:00 2001 From: Alexander Koshevoy Date: Fri, 15 Jan 2016 11:19:07 +0300 Subject: [PATCH 02/19] PY-17573 DockerCredentialsHolder extended to hold Compose properties --- .../remote/DockerCredentialsHolder.java | 62 ++++++++++++++++--- .../RemoteConnectionCredentialsWrapper.java | 15 ++++- 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java b/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java index 2ea73e504b9d..c0515ac87d24 100644 --- a/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java +++ b/platform/platform-impl/src/com/intellij/remote/DockerCredentialsHolder.java @@ -18,6 +18,7 @@ package com.intellij.remote; import com.intellij.openapi.util.text.StringUtil; import org.jdom.Element; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author Alexander Koshevoy @@ -28,12 +29,19 @@ public class DockerCredentialsHolder { public static final String DOCKER_CONTAINER_NAME = "DOCKER_CONTAINER_NAME"; public static final String DOCKER_REMOTE_PROJECT_PATH = "DOCKER_REMOTE_PROJECT_PATH"; + public static final String DOCKER_COMPOSE_FILE_PATH = "DOCKER_COMPOSE_FILE_PATH"; + public static final String DOCKER_COMPOSE_SERVICE_NAME = "DOCKER_COMPOSE_SERVICE_NAME"; + private String myMachineName; private String myImageName; private String myContainerName; + private String myComposeFilePath; + + private String myComposeServiceName; + private String myRemoteProjectPath; public DockerCredentialsHolder() { @@ -49,6 +57,20 @@ public class DockerCredentialsHolder { myRemoteProjectPath = remoteProjectPath; } + public DockerCredentialsHolder(String machineName, + String composeFilePath, + String composeServiceName, + String imageName, + String containerName, + String remoteProjectPath) { + myMachineName = machineName; + myComposeFilePath = composeFilePath; + myComposeServiceName = composeServiceName; + myImageName = imageName; + myContainerName = containerName; + myRemoteProjectPath = remoteProjectPath; + } + public String getMachineName() { return myMachineName; } @@ -65,21 +87,47 @@ public class DockerCredentialsHolder { return myRemoteProjectPath; } + public String getComposeFilePath() { + return myComposeFilePath; + } + + public String getComposeServiceName() { + return myComposeServiceName; + } + public void save(@NotNull Element element) { - if (StringUtil.isNotEmpty(myMachineName)) { - element.setAttribute(DOCKER_MACHINE_NAME, myMachineName); - } - element.setAttribute(DOCKER_IMAGE_NAME, myImageName); - if (StringUtil.isNotEmpty(myContainerName)) { - element.setAttribute(DOCKER_CONTAINER_NAME, myContainerName); - } + setAttributeIfNotEmpty(element, DOCKER_MACHINE_NAME, myMachineName); + setAttributeIfNotEmpty(element, DOCKER_IMAGE_NAME, myImageName); + setAttributeIfNotEmpty(element, DOCKER_CONTAINER_NAME, myContainerName); + setAttributeIfNotEmpty(element, DOCKER_COMPOSE_FILE_PATH, myComposeFilePath); + setAttributeIfNotEmpty(element, DOCKER_COMPOSE_SERVICE_NAME, myComposeServiceName); element.setAttribute(DOCKER_REMOTE_PROJECT_PATH, myRemoteProjectPath); } + private static void setAttributeIfNotEmpty(@NotNull Element element, @NotNull String attribute, @Nullable String value) { + if (StringUtil.isNotEmpty(value)) { + element.setAttribute(attribute, value); + } + } + public void load(@NotNull Element element) { myMachineName = element.getAttributeValue(DOCKER_MACHINE_NAME); myImageName = element.getAttributeValue(DOCKER_IMAGE_NAME); myContainerName = element.getAttributeValue(DOCKER_CONTAINER_NAME); + myComposeFilePath = element.getAttributeValue(DOCKER_COMPOSE_FILE_PATH); + myComposeServiceName = element.getAttributeValue(DOCKER_COMPOSE_SERVICE_NAME); myRemoteProjectPath = element.getAttributeValue(DOCKER_REMOTE_PROJECT_PATH); } + + public boolean isDockerComposeCredentials() { + return myComposeFilePath != null; + } + + @NotNull + public static DockerCredentialsHolder newDockerComposeCredentials(@Nullable String machineName, + @Nullable String composeFilePath, + @Nullable String composeServiceName, + @Nullable String remoteProjectPath) { + return new DockerCredentialsHolder(machineName, composeFilePath, composeServiceName, null, null, remoteProjectPath); + } } diff --git a/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java b/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java index 7cbac5774097..7898c4f88504 100644 --- a/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java +++ b/platform/platform-impl/src/com/intellij/remote/RemoteConnectionCredentialsWrapper.java @@ -185,7 +185,13 @@ public class RemoteConnectionCredentialsWrapper { @Override public void docker(@NotNull DockerCredentialsHolder cred) { // TODO [Docker] review - String name = StringUtil.isNotEmpty(cred.getContainerName()) ? cred.getContainerName() : cred.getImageName(); + String name; + if (cred.isDockerComposeCredentials()) { + name = cred.getComposeFilePath() + ":" + cred.getComposeServiceName(); + } + else { + name = StringUtil.isNotEmpty(cred.getContainerName()) ? cred.getContainerName() : cred.getImageName(); + } result.set(DOCKER_PREFIX + name + "/"); } }); @@ -270,7 +276,12 @@ public class RemoteConnectionCredentialsWrapper { public void docker(@NotNull DockerCredentialsHolder credentials) { String containerName = StringUtil.isNotEmpty(credentials.getContainerName()) ? credentials.getContainerName() + " " : ""; - result.set("Docker " + containerName + "(" + credentials.getImageName() + ")"); + if (credentials.isDockerComposeCredentials()) { + result.set("Docker Compose " + credentials.getComposeFilePath() + ":" + credentials.getComposeServiceName()); + } + else { + result.set("Docker " + containerName + "(" + credentials.getImageName() + ")"); + } } }); From 88fdd75397826c304656e2d2efee7c8a169d7fb6 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 1 Mar 2016 12:20:54 +0100 Subject: [PATCH 03/19] java smart completion: don't suggest generic call variants with inapplicable types --- .../psi/filters/types/AssignableFromFilter.java | 3 ++- .../completion/smartType/OnlyCompatibleTypes.java | 13 +++++++++++++ .../completion/SmartType18CompletionTest.java | 5 +++++ .../completion/SmartTypeCompletionTest.java | 5 +++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java diff --git a/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java b/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java index e791c926fd58..23309bd687c0 100644 --- a/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java +++ b/java/java-impl/src/com/intellij/psi/filters/types/AssignableFromFilter.java @@ -119,7 +119,8 @@ public class AssignableFromFilter implements ElementFilter{ expectedType, false, PsiUtil.getLanguageLevel(place)); - if (substitutionForParameter != PsiType.NULL && !(substitutionForParameter instanceof PsiIntersectionType)) { + if (substitutionForParameter != PsiType.NULL && !(substitutionForParameter instanceof PsiIntersectionType) && + PsiUtil.resolveClassInClassTypeOnly(substitutionForParameter) != parameter) { return true; } } diff --git a/java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java b/java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java new file mode 100644 index 000000000000..e10ac9709676 --- /dev/null +++ b/java/java-tests/testData/codeInsight/completion/smartType/OnlyCompatibleTypes.java @@ -0,0 +1,13 @@ +class A { + { + Func2 f = gex + } + + Func1 get1() {} + Func2 get2() {} + +} + + +interface Func1 {} +interface Func2 {} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java index 372dadf4c287..8db77fabc563 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartType18CompletionTest.java @@ -175,4 +175,9 @@ public void testConvertToObjectStream() { } checkResultByFile("/" + getTestName(false) + "-out.java"); } + + public void testOnlyCompatibleTypes() { + configureByTestName(); + assertOrderedEquals(myFixture.getLookupElementStrings(), "get2"); + } } diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java index 5a4d3b4a41a2..4daca42f2236 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/completion/SmartTypeCompletionTest.java @@ -1232,4 +1232,9 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase { private CommonCodeStyleSettings getCodeStyleSettings() { return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE); } + + public void testOnlyCompatibleTypes() { + configureByTestName(); + assertOrderedEquals(myFixture.getLookupElementStrings(), "get2"); + } } From 0f7f48076fd99201fc1e8f3cd726348c024f96ba Mon Sep 17 00:00:00 2001 From: Andrey Vokin Date: Tue, 1 Mar 2016 08:52:42 +0300 Subject: [PATCH 04/19] Code cleanup --- .../intellij/platform/DirectoryProjectGenerator.java | 3 --- .../com/intellij/platform/WebProjectGenerator.java | 12 ------------ .../edu/coursecreator/PyCCProjectGenerator.java | 6 ------ .../learning/PyStudyDirectoryProjectGenerator.java | 6 ------ .../newProject/PythonBaseProjectGenerator.java | 6 ------ 5 files changed, 33 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java b/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java index f26b0375428c..b21e9d1580cb 100644 --- a/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java +++ b/platform/platform-impl/src/com/intellij/platform/DirectoryProjectGenerator.java @@ -37,9 +37,6 @@ public interface DirectoryProjectGenerator { @Nls String getName(); - @Nullable - T showGenerationSettings(final VirtualFile baseDir) throws ProcessCanceledException; - /** * @return 16x16 icon or null, if no icon is available */ diff --git a/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java b/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java index 94f09af302cb..0a555fad5a53 100644 --- a/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java +++ b/platform/platform-impl/src/com/intellij/platform/WebProjectGenerator.java @@ -57,18 +57,6 @@ public abstract class WebProjectGenerator implements DirectoryProjectGenerato return null; } - @Override - @NotNull - public final T showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - GeneratorPeer peer = createPeer(); - DialogWrapper dialog = new MyDialogWrapper(peer); - dialog.show(); - if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) { - throw new ProcessCanceledException(); - } - return peer.getSettings(); - } - @Override public abstract void generateProject(@NotNull Project project, @NotNull VirtualFile baseDir, @NotNull T settings, @NotNull Module module); diff --git a/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java b/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java index a8c0082f9d99..29f60e14a0bd 100644 --- a/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java +++ b/python/educational-python/course-creator-python/src/com/jetbrains/edu/coursecreator/PyCCProjectGenerator.java @@ -39,12 +39,6 @@ public class PyCCProjectGenerator extends PythonProjectGenerator implements Dire return "Course creation"; } - @Nullable - @Override - public Object showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - return null; - } - @Nullable @Override public Icon getLogo() { diff --git a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java index 37eb89c49bef..d4d95ad5e5d1 100644 --- a/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java +++ b/python/educational-python/student-python/src/com/jetbrains/edu/learning/PyStudyDirectoryProjectGenerator.java @@ -49,12 +49,6 @@ public class PyStudyDirectoryProjectGenerator extends PythonProjectGenerator imp return "Educational"; } - @Nullable - @Override - public Object showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - return null; - } - @Nullable @Override public Icon getLogo() { diff --git a/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java b/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java index 138c242761ce..c1a33744b475 100644 --- a/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java +++ b/python/ide/src/com/jetbrains/python/newProject/PythonBaseProjectGenerator.java @@ -42,12 +42,6 @@ public class PythonBaseProjectGenerator extends PythonProjectGenerator implement return "Pure Python"; } - @Nullable - @Override - public Object showGenerationSettings(VirtualFile baseDir) throws ProcessCanceledException { - return null; - } - @Override @Nullable public JComponent getSettingsPanel(File baseDir) throws ProcessCanceledException { From 2695cd3d3b60d93347f4f3f38b2b20576676261f Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 1 Mar 2016 12:40:45 +0100 Subject: [PATCH 05/19] Make 'scale' field protected --- platform/util/src/com/intellij/util/ui/EmptyIcon.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/util/ui/EmptyIcon.java b/platform/util/src/com/intellij/util/ui/EmptyIcon.java index 8ff79ab1015c..2d08af300fdf 100644 --- a/platform/util/src/com/intellij/util/ui/EmptyIcon.java +++ b/platform/util/src/com/intellij/util/ui/EmptyIcon.java @@ -41,7 +41,7 @@ public class EmptyIcon implements Icon, ScalableIcon { private final int width; private final int height; - private float scale = 1f; + protected float scale = 1f; public static Icon create(int size) { Icon icon = cache.get(size); From 73ee1e62c18f2268edd3cd231309a17c6e9ff296 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 1 Mar 2016 12:41:30 +0100 Subject: [PATCH 06/19] Color icon disappears when change editor font size --- .../src/com/intellij/util/ui/ColorIcon.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/ColorIcon.java b/platform/util/src/com/intellij/util/ui/ColorIcon.java index dbce4d0b7798..323a0a1433fb 100644 --- a/platform/util/src/com/intellij/util/ui/ColorIcon.java +++ b/platform/util/src/com/intellij/util/ui/ColorIcon.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -18,6 +18,7 @@ package com.intellij.util.ui; import com.intellij.ui.Gray; import org.jetbrains.annotations.NotNull; +import javax.swing.*; import java.awt.*; /** @@ -27,7 +28,7 @@ public class ColorIcon extends EmptyIcon { private final Color myColor; private boolean myBorder; private int myColorSize; - + private ColorIcon myScaledCache; public ColorIcon(int size, int colorSize, @NotNull Color color, final boolean border) { super(size, size); @@ -53,18 +54,36 @@ public class ColorIcon extends EmptyIcon { final int iconWidth = getIconWidth(); final int iconHeight = getIconHeight(); g.setColor(getIconColor()); + + final int size = getColorSize(); + final int x = i + (iconWidth - size) / 2; + final int y = j + (iconHeight - size) / 2; - final int x = i + (iconWidth - myColorSize) / 2; - final int y = j + (iconHeight - myColorSize) / 2; - - g.fillRect(x, y, myColorSize, myColorSize); + g.fillRect(x, y, size, size); if (myBorder) { g.setColor(Gray.x00.withAlpha(40)); - g.drawRect(x, y, myColorSize, myColorSize); + g.drawRect(x, y, size, size); } } + protected int getColorSize() { + return scale == 1f ? myColorSize : (int)(myColorSize * scale); + } + + @Override + public Icon scale(float scaleFactor) { + if (scale == scaleFactor) { + return this; + } + if (myScaledCache != null && myScaledCache.scale == scaleFactor) { + return myScaledCache; + } + myScaledCache = new ColorIcon(getIconWidth(), myColorSize, myColor, myBorder); + myScaledCache.scale = scaleFactor; + return myScaledCache; + } + @Override public boolean equals(Object o) { if (this == o) return true; From da05d79b77ff3dda6cee06099441cf605c71a0c1 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 1 Mar 2016 14:52:16 +0300 Subject: [PATCH 07/19] do not stop on breakpoints in evaluated methods in resume one thread mode --- .../src/com/intellij/debugger/engine/DebugProcessEvents.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java index 185898e6fbec..6da59a74e04d 100644 --- a/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java +++ b/java/debugger/impl/src/com/intellij/debugger/engine/DebugProcessEvents.java @@ -186,7 +186,7 @@ public class DebugProcessEvents extends DebugProcessImpl { // check if there is already one request with policy SUSPEND_ALL for (SuspendContextImpl context : getSuspendManager().getEventContexts()) { if (context.getSuspendPolicy() == EventRequest.SUSPEND_ALL) { - if (isResumeOnlyCurrentThread() && locatableEvent != null) { + if (isResumeOnlyCurrentThread() && locatableEvent != null && !context.isEvaluating()) { // if step event is present - switch context getSuspendManager().resume(context); //((SuspendManagerImpl)getSuspendManager()).popContext(context); From c31dd7aeb68964bb7df20d5e85108e6555f0557d Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Tue, 1 Mar 2016 14:52:40 +0300 Subject: [PATCH 08/19] inspection tool window: if node has only one file reference show information for this file in right panel --- .../ui/InspectionResultsView.java | 17 ++++++++--------- .../codeInspection/ui/InspectionTreeNode.java | 14 ++++++++++++++ .../codeInspection/ui/RefElementNode.java | 8 ++++++++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java index 05fee7392616..0ecc43093349 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionResultsView.java @@ -71,7 +71,6 @@ import javax.swing.*; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.MutableTreeNode; import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.InputEvent; @@ -399,16 +398,16 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren TreePath pathSelected = myTree.getSelectionModel().getLeadSelectionPath(); if (pathSelected != null) { final InspectionTreeNode node = (InspectionTreeNode)pathSelected.getLastPathComponent(); - if (node instanceof RefElementNode) { - final RefElementNode refElementNode = (RefElementNode)node; - final RefEntity refSelected = refElementNode.getElement(); - showInRightPanel(refSelected); - } - else if (node instanceof ProblemDescriptionNode) { + if (node instanceof ProblemDescriptionNode) { final ProblemDescriptionNode problemNode = (ProblemDescriptionNode)node; showInRightPanel(problemNode.getElement()); } - else if (node instanceof InspectionNode || node instanceof InspectionPackageNode || node instanceof InspectionModuleNode) { + else if (node instanceof InspectionPackageNode || + node instanceof InspectionModuleNode || + node instanceof RefElementNode) { + showInRightPanel(node.getContainingFileLocalEntity()); + } + else if (node instanceof InspectionNode) { showInRightPanel(null); } else if (node instanceof InspectionRootNode || node instanceof InspectionGroupNode || node instanceof InspectionSeverityGroupNode) { @@ -499,7 +498,7 @@ public class InspectionResultsView extends JPanel implements Disposable, Occuren myPreviewEditor.getCaretModel().moveToOffset(finalSelectedElement.getTextOffset()); myPreviewEditor.getScrollingModel().scrollToCaret(ScrollType.CENTER); } - }, ModalityState.NON_MODAL); + }, ModalityState.any()); } return myPreviewEditor.getComponent(); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java index 3e3532631f45..574902b3c16e 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionTreeNode.java @@ -16,6 +16,7 @@ package com.intellij.codeInspection.ui; +import com.intellij.codeInspection.reference.RefEntity; import com.intellij.openapi.vcs.FileStatus; import org.jetbrains.annotations.Nullable; @@ -109,4 +110,17 @@ public abstract class InspectionTreeNode extends DefaultMutableTreeNode { } } + public RefEntity getContainingFileLocalEntity() { + final Enumeration children = children(); + RefEntity current = null; + while (children.hasMoreElements()) { + InspectionTreeNode child = (InspectionTreeNode)children.nextElement(); + final RefEntity entity = child.getContainingFileLocalEntity(); + if (entity == null || current != null) { + return null; + } + current = entity; + } + return current; + } } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java index 1e8c5d44126e..809705237f49 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/RefElementNode.java @@ -18,6 +18,7 @@ package com.intellij.codeInspection.ui; import com.intellij.codeInspection.CommonProblemDescriptor; import com.intellij.codeInspection.InspectionsBundle; +import com.intellij.codeInspection.reference.RefDirectory; import com.intellij.codeInspection.reference.RefElement; import com.intellij.codeInspection.reference.RefEntity; import com.intellij.openapi.util.Computable; @@ -124,4 +125,11 @@ public class RefElementNode extends InspectionTreeNode { return mySingleDescriptor; } + @Override + public RefEntity getContainingFileLocalEntity() { + final RefEntity element = getElement(); + return element instanceof RefElement && !(element instanceof RefDirectory) + ? element + : super.getContainingFileLocalEntity(); + } } From 73e35954fe5eaf9e6e9e10fd6b63cc2977594394 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 1 Mar 2016 12:59:46 +0100 Subject: [PATCH 09/19] [tests] utility method extracted --- .../com/intellij/testFramework/PlatformTestUtil.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 5c474129bb47..581b8bc7fc4b 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -385,8 +385,15 @@ public class PlatformTestUtil { return print(tree, false); } - public static void assertTreeStructureEquals(final AbstractTreeStructure treeStructure, final String expected) { - Assert.assertEquals(expected, print(treeStructure, treeStructure.getRootElement(), 0, null, -1, ' ', null).toString()); + public static void updateRecursively(@NotNull AbstractTreeNode node) { + node.update(); + for (AbstractTreeNode child : node.getChildren()) { + updateRecursively(child); + } + } + + public static void assertTreeStructureEquals(@NotNull AbstractTreeStructure treeStructure, @NotNull String expected) { + Assert.assertEquals(expected.trim(), print(treeStructure, treeStructure.getRootElement(), 0, null, -1, ' ', null).toString().trim()); } public static void invokeNamedAction(final String actionId) { From 42b0bfe079d47d70d3e5ea5b79727ef488787f18 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 1 Mar 2016 13:00:29 +0100 Subject: [PATCH 10/19] IDEA-152373 (Optional.get without Optional.isPresent warning when check is present) --- .../bugs/OptionalGetWithoutIsPresentInspection.java | 11 +++++++++-- .../OptionalGetWithoutIsPresent.java | 10 ++++++++++ .../OptionalGetWithoutIsPresentInspectionTest.java | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java index 5be18f7f4096..6c3822dc1b7d 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspection.java @@ -88,13 +88,20 @@ public class OptionalGetWithoutIsPresentInspection extends BaseInspection { final PsiIfStatement ifStatement = (PsiIfStatement)sibling; final PsiExpression condition = ifStatement.getCondition(); if (condition != null) { - if (!ControlFlowUtils.statementMayCompleteNormally(ifStatement.getThenBranch())) { + final PsiElement target = optionalReference.resolve(); + if (!(target instanceof PsiVariable)) { + return true; + } + final PsiVariable variable = (PsiVariable)target; + final PsiStatement thenBranch = ifStatement.getThenBranch(); + if (!ControlFlowUtils.statementMayCompleteNormally(thenBranch) || VariableAccessUtils.variableIsAssigned(variable, thenBranch)) { checker.negate = true; if (checker.checkExpression(condition)) { return true; } } - else if (!ControlFlowUtils.statementMayCompleteNormally(ifStatement.getElseBranch())) { + final PsiStatement elseBranch = ifStatement.getElseBranch(); + if (!ControlFlowUtils.statementMayCompleteNormally(elseBranch) || VariableAccessUtils.variableIsAssigned(variable, elseBranch)) { checker.negate = false; if (checker.checkExpression(condition)) { return true; diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java index 641210bd6a56..0c1e79aac2b9 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/bugs/optional_get_without_is_present/OptionalGetWithoutIsPresent.java @@ -50,4 +50,14 @@ class OptionalWithoutIsPresent { org.testng.Assert.assertTrue(o3.isPresent()); System.out.println(o3.get()); } + + public static String demo() { + Optional holder = Optional.empty(); + + if (! holder.isPresent()) { + holder = Optional.of("hello world"); + } + + return holder.get(); + } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java index 49592dc51e33..81156b9ba0f7 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/bugs/OptionalGetWithoutIsPresentInspectionTest.java @@ -79,6 +79,9 @@ public class OptionalGetWithoutIsPresentInspectionTest extends LightInspectionTe " public static Optional empty() {" + " return new Optional<>();" + " }" + + " public static Optional of(T value) {" + + " return new Optional<>(value);" + + " }" + "}", "package java.util;" + From a1728581c03a19d43a8375159dee3fa32ce03881 Mon Sep 17 00:00:00 2001 From: Dmitry Batkovich Date: Tue, 1 Mar 2016 15:04:56 +0300 Subject: [PATCH 11/19] SameParameterValueInspection doesn't violate getFamilyName() convention --- .../sameParameterValue/SameParameterValueInspection.java | 2 +- .../src/messages/InspectionsBundle.properties | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java index bcfea46a569c..d9bd3099459b 100644 --- a/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/sameParameterValue/SameParameterValueInspection.java @@ -69,7 +69,7 @@ public class SameParameterValueInspection extends SameParameterValueInspectionBa @Override @NotNull public String getFamilyName() { - return getName(); + return InspectionsBundle.message("inspection.same.parameter.fix.family.name"); } @Override diff --git a/platform/platform-resources-en/src/messages/InspectionsBundle.properties b/platform/platform-resources-en/src/messages/InspectionsBundle.properties index 6b2d9c573a00..69cd502c5e81 100644 --- a/platform/platform-resources-en/src/messages/InspectionsBundle.properties +++ b/platform/platform-resources-en/src/messages/InspectionsBundle.properties @@ -672,6 +672,7 @@ unused.library.roots.problem.descriptor=Unused roots {0} from library ''{1}'' unused.library.backward.analysis.job.description=Perform backward analysis inspection.duplicates.option.report.propertykey.expressions=&Ignore @PropertyKey expressions inspection.same.parameter.fix.name=Inline value ''{1}'' for parameter ''{0}'' +inspection.same.parameter.fix.family.name=Inline parameter as constant value fix.all.inspection.problems.in.file=Fix all ''{0}'' problems in file cleanup.in.file=Cleanup code cleanup.in.scope=Cleanup code on... From 30e7ac3a3b1248e45c79bbd666e4ffbf9a7dd981 Mon Sep 17 00:00:00 2001 From: Liana Bakradze Date: Tue, 1 Mar 2016 15:23:00 +0300 Subject: [PATCH 12/19] changed highlighter layer for placeholders --- .../src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java b/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java index 137062810ec9..da2972c440c3 100644 --- a/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java +++ b/python/educational-core/src/com/jetbrains/edu/EduAnswerPlaceholderPainter.java @@ -51,7 +51,7 @@ public class EduAnswerPlaceholderPainter { public static void createGuardedBlock(Editor editor, List blocks, int start, int end) { RangeHighlighter rh = editor.getMarkupModel() - .addRangeHighlighter(start, end, HighlighterLayer.LAST + 1, null, HighlighterTargetArea.EXACT_RANGE); + .addRangeHighlighter(start, end, PLACEHOLDERS_LAYER, null, HighlighterTargetArea.EXACT_RANGE); blocks.add(rh); } From 1f85600a67dc42f95bdf7b7c738dcb6522699ed2 Mon Sep 17 00:00:00 2001 From: Alexander Doroshko Date: Tue, 1 Mar 2016 15:24:13 +0300 Subject: [PATCH 13/19] sync Ultimate and Community code style settings --- .idea/codeStyleSettings.xml | 172 ++++++++++-------------------------- 1 file changed, 45 insertions(+), 127 deletions(-) diff --git a/.idea/codeStyleSettings.xml b/.idea/codeStyleSettings.xml index 6e5a913cfea4..e08227b860ba 100644 --- a/.idea/codeStyleSettings.xml +++ b/.idea/codeStyleSettings.xml @@ -3,42 +3,6 @@