From 33cc3ba4f4a7ae5f7f9555f1a9b6b5ed4f5a25ee Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Mon, 28 Nov 2011 21:46:06 +0400 Subject: [PATCH 1/6] EA-31390 - CCE: GroovyExpectedTypesProvider$1.compute --- .../GroovyExpectedTypesProvider.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java index 3c1590b9131f..fb2b4edfe5e0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/expectedTypes/GroovyExpectedTypesProvider.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.codeInspection.utils.ControlFlowUtils; import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; +import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementVisitor; import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult; import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap; import org.jetbrains.plugins.groovy.lang.psi.api.statements.*; @@ -66,7 +67,13 @@ public class GroovyExpectedTypesProvider { expression.putUserData(CACHED_EXPECTED_TYPES, cached = CachedValuesManager.getManager(expression.getProject()).createCachedValue(new CachedValueProvider() { public Result compute() { MyCalculator calculator = new MyCalculator(expression); - ((GroovyPsiElement)expression.getParent()).accept(calculator); + final PsiElement parent = expression.getParent(); + if (parent instanceof GroovyPsiElement) { + ((GroovyPsiElement)parent).accept(calculator); + } + else { + parent.accept(new GroovyPsiElementVisitor(calculator)); + } final TypeConstraint[] result = calculator.getResult(); List custom = new ArrayList(); @@ -248,7 +255,7 @@ public class GroovyExpectedTypesProvider { final IElementType type = expression.getOperationTokenType(); final GrExpression left = expression.getLeftOperand(); final GrExpression right = expression.getRightOperand(); - + if (type == mREGEX_FIND || type == mREGEX_MATCH) { final PsiClassType string = TypesUtil.createType(CommonClassNames.JAVA_LANG_STRING, expression); @@ -260,7 +267,7 @@ public class GroovyExpectedTypesProvider { final PsiType otherType = other != null ? other.getType() : null; if (otherType == null) return; - + if (type== mPLUS && otherType.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { final PsiClassType obj = TypesUtil.getJavaLangObject(expression); myResult = new TypeConstraint[]{new SubtypeConstraint(obj, obj)}; @@ -347,7 +354,13 @@ public class GroovyExpectedTypesProvider { @Override public void visitParenthesizedExpression(GrParenthesizedExpression expression) { - ((GroovyPsiElement)expression.getParent()).accept(this); + final PsiElement parent = expression.getParent(); + if (parent instanceof GroovyPsiElement) { + ((GroovyPsiElement)parent).accept(this); + } + else { + parent.accept(new GroovyPsiElementVisitor(this)); + } } @Override From 7de79de553a7a6b9d44189ff449dc7aff7312465 Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Wed, 30 Nov 2011 00:43:06 +0400 Subject: [PATCH 2/6] IDEA-77422 Private constructors shouldn't be considered in resolve when there are matching public ones --- .../lang/resolve/processors/MethodResolverProcessor.java | 2 +- .../plugins/groovy/lang/resolve/ResolveMethodTest.groovy | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java index 03485a5581b2..988607b9af11 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/resolve/processors/MethodResolverProcessor.java @@ -100,7 +100,7 @@ public class MethodResolverProcessor extends ResolverProcessor { boolean isAccessible = isAccessible(method); GroovyPsiElement resolveContext = state.get(RESOLVE_CONTEXT); boolean isStaticsOK = isStaticsOK(method, resolveContext, true); - if (!myAllVariants && isStaticsOK && + if (!myAllVariants && isStaticsOK && isAccessible && PsiUtil.isApplicable(myArgumentTypes, method, substitutor, (GroovyPsiElement)myPlace, myByShape)) { addCandidate(new GroovyResolveResultImpl(method, resolveContext, substitutor, isAccessible, isStaticsOK)); } else { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy index 0f7a68d198a4..8190f600573c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/resolve/ResolveMethodTest.groovy @@ -815,4 +815,13 @@ def test() { """) assertNotNull(ref.resolve()) } + + public void testPublicVsPrivateConstructor() { + def resolved = (configureByText('throw new AssertionError("foo")').element.parent as GrNewExpression).resolveMethod() + assertNotNull resolved + + PsiParameter[] parameters = resolved.parameterList.parameters + assertTrue parameters.length == 1 + assertEquals "java.lang.Object", parameters[0].type.canonicalText + } } From 7f53d75827e68bf19d79ff1845ce2331681d25bd Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 1 Dec 2011 10:39:48 +0100 Subject: [PATCH 3/6] less IdeNotificationArea constant activity --- .../notification/impl/IdeNotificationArea.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/notification/impl/IdeNotificationArea.java b/platform/platform-impl/src/com/intellij/notification/impl/IdeNotificationArea.java index 25fc5da778ac..d77090c27e84 100644 --- a/platform/platform-impl/src/com/intellij/notification/impl/IdeNotificationArea.java +++ b/platform/platform-impl/src/com/intellij/notification/impl/IdeNotificationArea.java @@ -67,13 +67,14 @@ public class IdeNotificationArea implements StatusBarWidget, StatusBarWidget.Ico new Runnable() { @Override public void run() { - LogModel logModel = EventLog.getLogModel(getProject()); - ToolWindow eventLog = EventLog.getEventLog(getProject()); + final Project project = getProject(); + LogModel logModel = EventLog.getLogModel(project); + ToolWindow eventLog = EventLog.getEventLog(project); if (eventLog != null && eventLog.isVisible()) { logModel.logShown(); } - updateStatus(); - myLogAlarm.addRequest(this, 50); + updateStatus(logModel); + myLogAlarm.addRequest(this, 100); } }.run(); @@ -111,8 +112,8 @@ public class IdeNotificationArea implements StatusBarWidget, StatusBarWidget.Ico return WIDGET_ID; } - private void updateStatus() { - myCurrentIcon = getPendingNotificationsIcon(EMPTY_ICON, NotificationModel.getMaximumType(EventLog.getLogModel(getProject()).getNotifications())); + private void updateStatus(final LogModel model) { + myCurrentIcon = getPendingNotificationsIcon(EMPTY_ICON, NotificationModel.getMaximumType(model.getNotifications())); myStatusBar.updateWidget(ID()); } From 29021f6c41e32f0b22a2aeb852b361846cba638e Mon Sep 17 00:00:00 2001 From: "Maxim.Medvedev" Date: Thu, 1 Dec 2011 13:47:38 +0400 Subject: [PATCH 4/6] Script parameters for GroovyScriptRunConfiguration --- .../groovy/runner/DefaultGroovyScriptRunner.java | 10 +++++----- .../runner/GroovyRunConfigurationEditor.java | 9 +++++---- .../runner/GroovyScriptRunConfiguration.java | 14 +++++++++++++- 3 files changed, 23 insertions(+), 10 deletions(-) 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 5180322e86d9..412c3da1b89e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/DefaultGroovyScriptRunner.java @@ -23,19 +23,19 @@ import com.intellij.execution.configurations.JavaParameters; import com.intellij.execution.configurations.RunProfile; import com.intellij.execution.runners.ExecutionUtil; import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ui.configuration.ClasspathEditor; +import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.encoding.EncodingManager; import com.intellij.openapi.vfs.encoding.EncodingProjectManager; -import com.intellij.openapi.roots.ui.configuration.ModulesConfigurator; -import com.intellij.openapi.roots.ui.configuration.ClasspathEditor; -import com.intellij.openapi.project.Project; import com.intellij.util.ObjectUtils; -import org.jetbrains.plugins.groovy.util.LibrariesUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.groovy.util.LibrariesUtil; import java.nio.charset.Charset; @@ -77,7 +77,7 @@ public class DefaultGroovyScriptRunner extends GroovyScriptRunner { } params.getProgramParametersList().add(FileUtil.toSystemDependentName(configuration.getScriptPath())); - params.getProgramParametersList().addParametersString(configuration.getProgramParameters()); + params.getProgramParametersList().addParametersString(configuration.getScriptParameters()); } public static void configureGenericGroovyRunner(JavaParameters params, Module module, String mainClass) { diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java index d88ee318bf11..eaf8d150f078 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/runner/GroovyRunConfigurationEditor.java @@ -27,8 +27,8 @@ import com.intellij.openapi.options.SettingsEditor; import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.ComboboxSpeedSearch; -import com.intellij.ui.PanelWithAnchor; import com.intellij.ui.FieldPanel; +import com.intellij.ui.PanelWithAnchor; import com.intellij.ui.RawCommandLineEditor; import com.intellij.ui.components.JBLabel; import org.jetbrains.annotations.NotNull; @@ -36,7 +36,8 @@ import org.jetbrains.plugins.groovy.GroovyFileType; import javax.swing.*; import java.awt.*; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class GroovyRunConfigurationEditor extends SettingsEditor implements PanelWithAnchor { @@ -86,7 +87,7 @@ public class GroovyRunConfigurationEditor extends SettingsEditor implements CommonJavaRunConfigurationParameters { + + private static final Logger LOG = Logger.getInstance(GroovyScriptRunConfiguration.class); private String vmParams; private String workDir; private boolean isDebugEnabled; @@ -191,6 +194,10 @@ public class GroovyScriptRunConfiguration extends ModuleBasedConfiguration Date: Thu, 1 Dec 2011 13:59:41 +0400 Subject: [PATCH 5/6] hide convertGroovyToJava --- plugins/groovy/src/META-INF/plugin.xml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 584b94f7eca1..07799cbffd2b 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -1005,8 +1005,10 @@ - + description="Convert Groovy files to Java" + internal = "true"> + + @@ -1014,7 +1016,7 @@ - + Date: Thu, 1 Dec 2011 14:13:09 +0300 Subject: [PATCH 6/6] 1. rails project view tests fixed 2. workaround which allows to ignore nodes order in tree (due to bugs with nodes sorters in project view) --- .../testFramework/PlatformTestUtil.java | 97 ++++++++++++------- 1 file changed, 63 insertions(+), 34 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 4233400a1ee5..2604da35f53f 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -46,10 +46,7 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileFilter; -import com.intellij.util.Alarm; -import com.intellij.util.ArrayUtil; -import com.intellij.util.SystemProperties; -import com.intellij.util.ThrowableRunnable; +import com.intellij.util.*; import com.intellij.util.containers.HashMap; import com.intellij.util.io.ZipUtil; import com.intellij.util.ui.UIUtil; @@ -120,13 +117,27 @@ public class PlatformTestUtil { public static String print(JTree tree, boolean withSelection, Condition nodePrintCondition) { StringBuilder buffer = new StringBuilder(); - Object root = tree.getModel().getRoot(); - printImpl(tree, root, buffer, 0, withSelection, nodePrintCondition); + + final Collection strings = printAsList(tree, withSelection, nodePrintCondition); + for (String string : strings) { + buffer.append(string).append("\n"); + } return buffer.toString(); } - - private static void printImpl(JTree tree, Object root, StringBuilder buffer, int level, boolean withSelection, @Nullable Condition nodePrintCondition) { + public static Collection printAsList(JTree tree, boolean withSelection, Condition nodePrintCondition) { + Collection strings = new ArrayList(); + Object root = tree.getModel().getRoot(); + printImpl(tree, root, strings, 0, withSelection, nodePrintCondition); + return strings; + } + + private static void printImpl(JTree tree, + Object root, + Collection strings, + int level, + boolean withSelection, + @Nullable Condition nodePrintCondition) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode)root; @@ -143,34 +154,42 @@ public class PlatformTestUtil { if (nodePrintCondition != null && !nodePrintCondition.value(nodeText)) return; boolean expanded = tree.isExpanded(new TreePath(defaultMutableTreeNode.getPath())); - StringUtil.repeatSymbol(buffer, ' ', level); - if (expanded && !defaultMutableTreeNode.isLeaf()) { - buffer.append("-"); - } - if (!expanded && !defaultMutableTreeNode.isLeaf()) { - buffer.append("+"); - } - - final boolean selected = tree.getSelectionModel().isPathSelected(new TreePath(defaultMutableTreeNode.getPath())); - - if (withSelection && selected) { - buffer.append("["); - } - - - buffer.append(nodeText); - - if (withSelection && selected) { - buffer.append("]"); - } - - buffer.append("\n"); - int childCount = tree.getModel().getChildCount(root); - if (expanded) { - for (int i = 0; i < childCount; i++) { - printImpl(tree, tree.getModel().getChild(root, i), buffer, level + 1, withSelection, nodePrintCondition); + final StringBuilder buff = StringBuilderSpinAllocator.alloc(); + try { + StringUtil.repeatSymbol(buff, ' ', level); + if (expanded && !defaultMutableTreeNode.isLeaf()) { + buff.append("-"); } + + if (!expanded && !defaultMutableTreeNode.isLeaf()) { + buff.append("+"); + } + + final boolean selected = tree.getSelectionModel().isPathSelected(new TreePath(defaultMutableTreeNode.getPath())); + + if (withSelection && selected) { + buff.append("["); + } + + + buff.append(nodeText); + + if (withSelection && selected) { + buff.append("]"); + } + + //buff.append("\n"); + strings.add(buff.toString()); + + int childCount = tree.getModel().getChildCount(root); + if (expanded) { + for (int i = 0; i < childCount; i++) { + printImpl(tree, tree.getModel().getChild(root, i), strings, level + 1, withSelection, nodePrintCondition); + } + } + } finally { + StringBuilderSpinAllocator.dispose(buff); } } @@ -178,11 +197,21 @@ public class PlatformTestUtil { assertTreeEqual(tree, expected, false); } + public static void assertTreeEqualIgnoringNodesOrder(JTree tree, @NonNls String expected) { + assertTreeEqualIgnoringNodesOrder(tree, expected, false); + } + public static void assertTreeEqual(JTree tree, String expected, boolean checkSelected) { String treeStringPresentation = print(tree, checkSelected); Assert.assertEquals(expected, treeStringPresentation); } + public static void assertTreeEqualIgnoringNodesOrder(JTree tree, String expected, boolean checkSelected) { + final Collection actualNodesPresentation = printAsList(tree, checkSelected, null); + final List expectedNodes = StringUtil.split(expected, "\n"); + UsefulTestCase.assertSameElements(actualNodesPresentation, expectedNodes); + } + @TestOnly public static void waitForAlarm(final int delay) throws InterruptedException { assert !ApplicationManager.getApplication().isWriteAccessAllowed(): "It's a bad idea to wait for an alarm under the write action. Somebody creates an alarm which requires read action and you are deadlocked.";