From 1889e757dfa1da9bfbc4008404f3d9045a901048 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Fri, 17 Aug 2012 21:51:28 +0400 Subject: [PATCH 1/8] EA-38362 - EE: RemoteProcessSupport.acquire --- .../com/intellij/execution/rmi/RemoteProcessSupport.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java b/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java index 2e5306315a6c..2acb8dde4a7a 100644 --- a/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java +++ b/platform/lang-impl/src/com/intellij/execution/rmi/RemoteProcessSupport.java @@ -129,7 +129,13 @@ public abstract class RemoteProcessSupport { } if (ref.isNull()) throw new RuntimeException("Unable to acquire remote proxy for: " + getName(target)); RunningInfo info = ref.get(); - if (info.handler == null) throw new ExecutionException(info.name); + if (info.handler == null) { + String message = info.name; + if (message != null && message.startsWith("ERROR: transport error 202:")) { + message = "Unable to start java process in debug mode: -Xdebug parameters are already in use."; + } + throw new ExecutionException(message); + } return acquire(info); } From 7c519fe5366504ed03cb70d9ca1e525faa5ededc Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 17 Aug 2012 18:37:07 +0400 Subject: [PATCH 2/8] hide add @Override annotation for non-project code (IDEA-90255) --- .../codeInsight/intention/impl/AddOverrideAnnotationAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddOverrideAnnotationAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddOverrideAnnotationAction.java index 4db64387c0f1..b9bd7cd8b019 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddOverrideAnnotationAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/AddOverrideAnnotationAction.java @@ -48,6 +48,7 @@ public class AddOverrideAnnotationAction implements IntentionAction { @Override public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { if (!PsiUtil.isLanguageLevel5OrHigher(file)) return false; + if (!file.getManager().isInProject(file)) return false; PsiMethod method = findMethod(file, editor.getCaretModel().getOffset()); if (method == null) return false; if (method.getModifierList().findAnnotation(JAVA_LANG_OVERRIDE) != null) return false; From 321d3b9dd064f4205eef50cfd6f5f95689406b8c Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 17 Aug 2012 21:43:26 +0400 Subject: [PATCH 3/8] lambda: check all return expressions for constraints --- .../source/resolve/PsiResolveHelperImpl.java | 15 ++++++++--- .../TypeArgsConsistencyMisc1.java | 25 +++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index 2ad9cbc2964e..5bb8634d7044 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -595,6 +595,7 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { final PsiSubstitutor subst = resolveResult.getSubstitutor(); final PsiType returnType = subst.substitute(method.getReturnType()); if (returnType != null && returnType != PsiType.VOID) { + Pair constraint = null; final List expressions = lambdaExpression.getReturnExpressions(); for (final PsiExpression expression : expressions) { final boolean independent = LambdaUtil.isFreeFromTypeInferenceArgs(methodParameters, lambdaExpression, expression); @@ -621,12 +622,20 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { if (exprType == null){ return FAILED_INFERENCE; } - Pair constraint = + + final Pair returnExprConstraint = getSubstitutionForTypeParameterConstraint(typeParam, returnType, exprType, false, PsiUtil.getLanguageLevel(method)); - if (constraint != null) { - return constraint; //todo check that all return statements lead to the same inference + if (returnExprConstraint != null) { + if (returnExprConstraint == FAILED_INFERENCE) return returnExprConstraint; + if (constraint != null) { + final PsiType leastUpperBound = GenericsUtil.getLeastUpperBound(constraint.getFirst(), returnExprConstraint.getFirst(), typeParam.getManager()); + constraint = new Pair(leastUpperBound, ConstraintType.SUPERTYPE); + } else { + constraint = returnExprConstraint; + } } } + if (constraint != null) return constraint; } for (PsiParameter parameter : methodParameters) { if (LambdaUtil.dependsOnTypeParams(parameter.getType(), lambdaExpression)) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyMisc1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyMisc1.java index 8c901fa4fe80..19d7d09b152c 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyMisc1.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyMisc1.java @@ -1,3 +1,18 @@ +/* + * Copyright 2000-2012 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. + */ import java.util.List; class Test1 { @@ -23,6 +38,16 @@ class Test1 { bar2("", x -> x); bar3(x -> x, ""); + + int ixc = 42; + bar(x -> { + if (ixc == 2) return "aaa"; + return x; + }); + bar(x -> { + if (ixc == 2) return x; + return x; + }); } } From 1fa0a6ade43f67aa64b6f6343c1d0fa67010eea4 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 17 Aug 2012 22:44:31 +0400 Subject: [PATCH 4/8] lambda: void return type compatibility (initial); functional interfaces without method params error messages --- .../src/com/intellij/psi/LambdaUtil.java | 33 ++++++++++------- .../source/resolve/PsiResolveHelperImpl.java | 11 ++++-- .../highlighting/ReturnTypeCompatibility.java | 2 +- .../TypeArgsConsistencyWithoutParams.java | 36 +++++++++++++++++++ .../daemon/lambda/LambdaHighlightingTest.java | 4 +++ 5 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyWithoutParams.java diff --git a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java index d315730c807d..aba0c13d4589 100644 --- a/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java +++ b/java/java-psi-api/src/com/intellij/psi/LambdaUtil.java @@ -126,22 +126,29 @@ public class LambdaUtil { } LOG.assertTrue(psiClass != null); PsiType methodReturnType = getReturnType(psiClass, methodSignature); - if (methodReturnType != null && methodReturnType != PsiType.VOID) { - methodReturnType = resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodReturnType)); - final PsiElement body = lambdaExpression.getBody(); - if (body instanceof PsiCodeBlock) { - final PsiCodeBlock block = (PsiCodeBlock)body; - for (PsiStatement statement : block.getStatements()) { - if (statement instanceof PsiReturnStatement) { - final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue(); - if (returnValue != null) { - if (!checkReturnTypeAssignability(returnValue.getType(), parameterTypes, lambdaExpression, methodReturnType)) return false; + if (methodReturnType != null) { + if (methodReturnType != PsiType.VOID) { + methodReturnType = resolveResult.getSubstitutor().substitute(methodSignature.getSubstitutor().substitute(methodReturnType)); + final PsiElement body = lambdaExpression.getBody(); + if (body instanceof PsiCodeBlock) { + final PsiCodeBlock block = (PsiCodeBlock)body; + for (PsiStatement statement : block.getStatements()) { + if (statement instanceof PsiReturnStatement) { + final PsiExpression returnValue = ((PsiReturnStatement)statement).getReturnValue(); + if (returnValue != null) { + if (!checkReturnTypeAssignability(returnValue.getType(), parameterTypes, lambdaExpression, methodReturnType)) return false; + } } } } - } - else if (body instanceof PsiExpression) { - return checkReturnTypeAssignability(((PsiExpression)body).getType(), parameterTypes, lambdaExpression, methodReturnType); + else if (body instanceof PsiExpression) { + return checkReturnTypeAssignability(((PsiExpression)body).getType(), parameterTypes, lambdaExpression, methodReturnType); + } + } else { + final List returnExpressions = lambdaExpression.getReturnExpressions(); + for (PsiExpression returnValue : returnExpressions) { + if (returnValue.getType() != PsiType.VOID) return false; + } } } return true; diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java index 5bb8634d7044..62d12a4a38d9 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/PsiResolveHelperImpl.java @@ -19,6 +19,7 @@ import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; +import com.intellij.psi.impl.source.tree.java.PsiLambdaExpressionImpl; import com.intellij.psi.infos.CandidateInfo; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.scope.MethodProcessorSetupFailedException; @@ -876,8 +877,14 @@ public class PsiResolveHelperImpl implements PsiResolveHelper { final PsiExpressionList argumentList = methodCall.getArgumentList(); if (argumentList != null && PsiUtil.getLanguageLevel(argumentList).isAtLeast(LanguageLevel.JDK_1_8)) { for (PsiExpression expression : argumentList.getExpressions()) { - if (expression instanceof PsiLambdaExpression){ - return getFailedInferenceConstraint(typeParameter); + if (expression instanceof PsiLambdaExpression) { + if (((PsiLambdaExpression)expression).getParameterList().getParametersCount() > 0){ + return getFailedInferenceConstraint(typeParameter); + } + final PsiType functionalInterfaceType = PsiLambdaExpressionImpl.getFunctionalInterfaceType(((PsiLambdaExpression)expression), false); + if (functionalInterfaceType == null || PsiUtil.resolveClassInType(functionalInterfaceType) == typeParameter){ + return getFailedInferenceConstraint(typeParameter); + } } } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility.java index eb2acb162cdd..b1d08e6f04ad 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/ReturnTypeCompatibility.java @@ -57,7 +57,7 @@ class ReturnTypeCompatibility { } public static void main(String[] args) { - call(i-> {return i;}); + call(i-> {return i;}); } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyWithoutParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyWithoutParams.java new file mode 100644 index 000000000000..c0f95dcba9f9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/highlighting/TypeArgsConsistencyWithoutParams.java @@ -0,0 +1,36 @@ +import java.util.*; +class Test4 { + interface I { + List foo(); + } + + static void bar(I i){} + + { + bar(() -> null); + } +} + +class Test5 { + interface I { + void foo(K k); + } + + static void bar(I i){} + + { + bar(() -> null); + } +} +class Test6 { + interface I { + void foo(); + } + + static void bar(I i){} + + { + bar(() -> null); + bar(() -> {}); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java index ee15e97780c8..03d0d87c7731 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/LambdaHighlightingTest.java @@ -49,6 +49,10 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase { doTest(); } + public void testTypeArgsConsistencyWithoutParams() throws Exception { + doTest(); + } + public void testWildcardBounds() throws Exception { doTest(); } From 4d27135dbc4d88a545a6a6575158a1eceecc38c9 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Fri, 17 Aug 2012 22:50:57 +0400 Subject: [PATCH 5/8] EA-38283 - PIEAE: CompositePsiElement.getProject --- .../daemon/impl/quickfix/CreatePropertyFromUsageFix.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java index 03081f89b239..890b0073449c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreatePropertyFromUsageFix.java @@ -315,7 +315,9 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix implement } protected void beforeTemplateFinished(PsiClass aClass, PsiField field) { - positionCursor(myMethodCall.getProject(), myMethodCall.getContainingFile(), myMethodCall); + if (myMethodCall.isValid()) { + positionCursor(myMethodCall.getProject(), myMethodCall.getContainingFile(), myMethodCall); + } } private static String getVariableName(PsiMethodCallExpression methodCall, boolean isStatic) { From 8cbf9378efc0b0ce2a9e272387f1c9ea888b4df0 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sat, 18 Aug 2012 00:31:07 +0400 Subject: [PATCH 6/8] IDEA-90000 Balloon with position BELOW set has bad layout --- .../src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java index 74b3c271b699..e6892ba609b2 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java @@ -268,8 +268,9 @@ public class DebuggerUIUtil { editor.setPropertiesPanel(mainPanel); editor.setShowMoreOptionsLink(true); + final JPanel panel = editor.getMainPanel(); final Balloon balloon = JBPopupFactory.getInstance() - .createDialogBalloonBuilder(editor.getMainPanel(), null) + .createDialogBalloonBuilder(panel, null) .setHideOnClickOutside(true) .setCloseButtonEnabled(false) .setAnimationCycle(0) @@ -295,7 +296,8 @@ public class DebuggerUIUtil { balloon.showInCenterOf(component); } else { - balloon.show(new RelativePoint(component, whereToShow), Balloon.Position.below); + final Point p = new Point(whereToShow.x + panel.getPreferredSize().width / 2, whereToShow.y); + balloon.show(new RelativePoint(component, p), Balloon.Position.below); } BreakpointsMasterDetailPopupFactory.getInstance(project).setBalloonToHide(balloon, breakpoint); From 407a6284e557c22266183417bef87351210d557e Mon Sep 17 00:00:00 2001 From: Dmitry Trofimov Date: Fri, 17 Aug 2012 22:33:50 +0200 Subject: [PATCH 7/8] Correct shutdown of env-tests. --- .../testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java index 7772f2e9426d..6aae8f716a95 100644 --- a/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java +++ b/platform/xdebugger-impl/testSrc/com/intellij/xdebugger/XDebuggerTestUtil.java @@ -322,6 +322,14 @@ public class XDebuggerTestUtil { return breakpoint.get(); } + public static void removeAllBreakpoints(@NotNull final Project project) { + final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager(); + XBreakpoint[] breakpoints = breakpointManager.getAllBreakpoints(); + for (XBreakpoint b: breakpoints) { + breakpointManager.removeBreakpoint(b); + } + } + public static void setBreakpointCondition(Project project, int line, final String condition) { XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager(); for (XBreakpoint breakpoint : breakpointManager.getAllBreakpoints()) { From bf10844f006a74d554ef797b14dfc9a9be17af9a Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Sat, 18 Aug 2012 01:02:08 +0400 Subject: [PATCH 8/8] better fix of IDEA-90000 --- .../intellij/xdebugger/impl/ui/DebuggerUIUtil.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java index e6892ba609b2..0d437c11f439 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java @@ -296,8 +296,16 @@ public class DebuggerUIUtil { balloon.showInCenterOf(component); } else { - final Point p = new Point(whereToShow.x + panel.getPreferredSize().width / 2, whereToShow.y); - balloon.show(new RelativePoint(component, p), Balloon.Position.below); + //todo[kb] modify and move to BalloonImpl? + final Window window = SwingUtilities.windowForComponent(component); + final RelativePoint p = new RelativePoint(component, whereToShow); + if (window != null) { + final RelativePoint point = new RelativePoint(window, new Point(0, 0)); + if (p.getScreenPoint().getX() - point.getScreenPoint().getX() < 40) { // triangle + offsets is ~40px + p.getPoint().x += 40; + } + } + balloon.show(p, Balloon.Position.below); } BreakpointsMasterDetailPopupFactory.getInstance(project).setBalloonToHide(balloon, breakpoint);