From fb41fc8821f952c0fcd0bf440d7862a8df14b40d Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Mon, 11 Apr 2016 21:43:35 +0300 Subject: [PATCH 1/9] IDEA-153630 gdb console is blinking and adding and deleting scroll bar try to align width of two editors --- .../execution/console/LanguageConsoleImpl.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java index 3fbf3b3a532a..6327da951da4 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/console/LanguageConsoleImpl.java @@ -32,6 +32,7 @@ import com.intellij.openapi.editor.*; import com.intellij.openapi.editor.colors.EditorColorsManager; import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.editor.ex.FocusChangeListener; +import com.intellij.openapi.editor.ex.util.EditorUtil; import com.intellij.openapi.editor.ex.util.LexerEditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighter; import com.intellij.openapi.editor.highlighter.EditorHighlighterFactory; @@ -632,6 +633,23 @@ public class LanguageConsoleImpl extends ConsoleViewImpl implements LanguageCons final Dimension historySize = history.getContentSize(); final Dimension inputSize = input.getContentSize(); + // deal with width + if (isHistoryViewerForceAdditionalColumnsUsage()) { + history.getSoftWrapModel().forceAdditionalColumnsUsage(); + + int minAdditionalColumns = 2; + // calculate content size without additional columns except minimal amount + int historySpaceWidth = EditorUtil.getPlainSpaceWidth(history); + historySize.width += historySpaceWidth * (minAdditionalColumns - history.getSettings().getAdditionalColumnsCount()); + // calculate content size without additional columns except minimal amount + int inputSpaceWidth = EditorUtil.getPlainSpaceWidth(input); + inputSize.width += inputSpaceWidth * (minAdditionalColumns - input.getSettings().getAdditionalColumnsCount()); + // calculate additional columns according to the corresponding width + int max = Math.max(historySize.width, inputSize.width); + history.getSettings().setAdditionalColumnsCount(minAdditionalColumns + (max - historySize.width) / historySpaceWidth); + input.getSettings().setAdditionalColumnsCount(minAdditionalColumns + (max - inputSize.width) / inputSpaceWidth); + } + int newInputHeight; // deal with height, WEB-11122 we cannot trust editor width - it could be 0 in case of soft wrap even if editor has text if (history.getDocument().getLineCount() == 0) { From 6c9dfc06f127e2d83833cd772a3791accc457086 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Mon, 11 Apr 2016 19:58:55 +0200 Subject: [PATCH 2/9] make method public for reuse --- .../source/com/intellij/structuralsearch/plugin/ui/UIUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java index 0db8d253c0e0..2386c765bd70 100644 --- a/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java +++ b/platform/structuralsearch/source/com/intellij/structuralsearch/plugin/ui/UIUtil.java @@ -291,7 +291,7 @@ public class UIUtil { } @NotNull - static JComponent createCompleteMatchInfo(final Producer configurationProducer) { + public static JComponent createCompleteMatchInfo(final Producer configurationProducer) { final JLabel completeMatchInfo = new JLabel(AllIcons.RunConfigurations.Variables); final Point location = completeMatchInfo.getLocation(); final JLabel label = new JLabel(SSRBundle.message("complete.match.variable.tooltip.message", From 3327a75a63fac230332831e7289d027b4be9a7d2 Mon Sep 17 00:00:00 2001 From: Sergey Malenkov Date: Mon, 11 Apr 2016 22:26:34 +0300 Subject: [PATCH 3/9] IDEA-154396 Floating tool window resize incorrect with Windows taskbar on the left the screen size is not equal to max coordinates if top/left insets are not zero --- .../openapi/wm/impl/FloatingDecorator.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java index 4a05faa4a8f0..4a52861a8e64 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FloatingDecorator.java @@ -221,9 +221,11 @@ public final class FloatingDecorator extends JDialog { final Point newPoint=e.getPoint(); SwingUtilities.convertPointToScreen(newPoint,this); final Rectangle screenBounds=WindowManagerEx.getInstanceEx().getScreenBounds(); + int screenMaxX = screenBounds.x + screenBounds.width; + int screenMaxY = screenBounds.y + screenBounds.height; - newPoint.x=Math.min(Math.max(newPoint.x,screenBounds.x),screenBounds.width); - newPoint.y=Math.min(Math.max(newPoint.y,screenBounds.y),screenBounds.height); + newPoint.x = Math.min(Math.max(newPoint.x, screenBounds.x), screenMaxX); + newPoint.y = Math.min(Math.max(newPoint.y, screenBounds.y), screenMaxY); final Rectangle oldBounds=FloatingDecorator.this.getBounds(); final Rectangle newBounds=new Rectangle(oldBounds); @@ -248,16 +250,16 @@ public final class FloatingDecorator extends JDialog { } if((myMotionMask&ANCHOR_BOTTOM)>0){ newPoint.y=Math.max(newPoint.y,oldBounds.y+2*DIVIDER_WIDTH); - if(newPoint.y>screenBounds.height-DIVIDER_WIDTH){ - newPoint.y=screenBounds.height; + if (newPoint.y > screenMaxY - DIVIDER_WIDTH) { + newPoint.y = screenMaxY; } final Point offset=new Point(newPoint.x-myLastPoint.x,newPoint.y-myLastPoint.y); newBounds.height=oldBounds.height+offset.y; } if((myMotionMask&ANCHOR_RIGHT)>0){ newPoint.x=Math.max(newPoint.x,oldBounds.x+2*DIVIDER_WIDTH); - if(newPoint.x>screenBounds.width-DIVIDER_WIDTH){ - newPoint.x=screenBounds.width; + if (newPoint.x > screenMaxX - DIVIDER_WIDTH) { + newPoint.x = screenMaxX; } final Point offset=new Point(newPoint.x-myLastPoint.x,newPoint.y-myLastPoint.y); newBounds.width=oldBounds.width+offset.x; From 9dda2246ff0468a936952841f57552feea662d75 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 11 Apr 2016 21:42:48 +0200 Subject: [PATCH 4/9] [java-decompiler] fixes enum constant initializer decompilation (IDEA-154547) --- .../decompiler/main/InitializerProcessor.java | 6 ++-- .../testData/classes/pkg/TestEnum$2.class | Bin 428 -> 506 bytes .../testData/classes/pkg/TestEnum$Type.class | Bin 0 -> 871 bytes .../testData/classes/pkg/TestEnum.class | Bin 1491 -> 1652 bytes .../engine/testData/results/TestEnum.dec | 28 +++++++++++------- .../engine/testData/src/pkg/TestEnum.java | 10 ++++--- 6 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 plugins/java-decompiler/engine/testData/classes/pkg/TestEnum$Type.class diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java index fe1a4f79a827..206b669d65ac 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/InitializerProcessor.java @@ -117,7 +117,8 @@ public class InitializerProcessor { StructClass cl = wrapper.getClassStruct(); Statement firstData = Statements.findFirstData(root); if (firstData != null) { - boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE); + boolean inlineInitializers = cl.hasModifier(CodeConstants.ACC_INTERFACE) || cl.hasModifier(CodeConstants.ACC_ENUM); + while (!firstData.getExprents().isEmpty()) { Exprent exprent = firstData.getExprents().get(0); @@ -131,8 +132,7 @@ public class InitializerProcessor { cl.hasField(fExpr.getName(), fExpr.getDescriptor().descriptorString)) { // interfaces fields should always be initialized inline - if (isInterface || isExprentIndependent(assignExpr.getRight(), method)) { - + if (inlineInitializers || isExprentIndependent(assignExpr.getRight(), method)) { String keyField = InterpreterUtil.makeUniqueKey(fExpr.getName(), fExpr.getDescriptor().descriptorString); if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) { wrapper.getStaticFieldInitializers().addWithKey(assignExpr.getRight(), keyField); diff --git a/plugins/java-decompiler/engine/testData/classes/pkg/TestEnum$2.class b/plugins/java-decompiler/engine/testData/classes/pkg/TestEnum$2.class index 99faf412adc5a16866dfbb7efba6b1040bcddadd..3dedba7752417dc953984d6750c47d95d9ff7410 100644 GIT binary patch delta 272 zcmZ3({EOM@)W2Q(7#J8#7{s|4m>C4v83frGgcupvY%=pQOYGPggc%uFLMjVV85wvy z^YT)QoO2S3i&Kjk8LTHNs!jaO2bP@Z7Re|&ae;_hL3X-+NNRD3YhGzCBZD9^R|RAW zJA)V_gEz9yU#9gO42%q%KsP8euraU#X>KiT8C^*h#_bG@8-ZL#1}-4U2BaAnB!MJ1 z0}oV#Bv=-x0$rIj&?~$^NhSt927VyT0^~C=umiCaki`nbYz|UDSs-xW;9wAeFaRi( BESvxU delta 232 zcmeyxyoOov)W2Q(7#J8#7(}=jm>GE48Ti;41Q;3EY%=pQOY9gKG$vZ9O)QQu6JliG zE67gQ4@oU9am_2uRWV{@;PK4MOD%HFNh~f-Ee3Lt<=Gj885t}lTA57tWmKzWWdIrp zv__GEm4O9Fb82bJ=rV3+VB84gFfy$N!|0v_RMX{#4P43A#=R4>7&guR6>+25yud$N>$A*UIs3<5Zc%ebZmbeTRS&fp0 zK$t4>!d4Y*GsxZjeFon9aOp7UhraJj_B?w!b*2o(&gJ`2z2{7WwjW+p1g1gQcE5eZ zpj7&AJI8H{q4aJpE`4Qtp=k5aFy|xq-uRSQmpZQR9EBGHXVS9=9z~R>w0p*|WpvK% zE4%L5{-|yR6W1R#%=vUp*LQZF3IE zE={jl<8U%`4qTx#`*$}rAyP*{ti7n?C0;40G2|2b)3J=YjxrwW$RejBj~v6|zZnHL zLu%-aeIh6sW=vOiaPABP5~0WYGQ5dT9R0mUtm=Mi|C2OYJM;*2dO31yMQ8!Yk{lpc z7L!nhBZCqifR;+$23c{m8Q5n?w~#-Q$MA^mbd*~o{4!SV@lq7k3cUISsaxd1@RNcf-$1=aCUP_$ISZ-pl#*xk i|4;Y~3)VGQvbT)8?(29;-6TB25?PH{I5x4^D*py=Ft1_& literal 0 HcmV?d00001 diff --git a/plugins/java-decompiler/engine/testData/classes/pkg/TestEnum.class b/plugins/java-decompiler/engine/testData/classes/pkg/TestEnum.class index 01c608244d3bbc45b24058733d9c66c7ab99a89f..036f3e623b9467f49e9ec677abc19ea8c9156cb2 100644 GIT binary patch literal 1652 zcmZ`(>r&HD5dKatNg9JdfJ!S0)T%8PD+1n%P=ujZ2IusL2TEoI!U`$igW7?E*801VqgT+({GLUMyzPq z2eGVEvFroF$>H33dM}w}7<}2CLwau%YrMp8B--QjY?NOUnZdMWo7=V0zFFBd_KReZ zMO5YuLnzW)G1^^(l^EQSXpTWzv24p(W$^cjOL2rRYaQ5zQ>##!ct22Yy^eBWKEOE7 z6zLQFA82T&W;<5N%vn{78hmP0jFRb?m37-LJBDMGZJLn3t@5UMSTPHRW4@;OUg=XP z)mdplFxu)1>^ZT{P|;7PshLe#DHL1NoNA-Smt&;^A73SsYPMXf6wC(}Kfi&0TXc;V z*Ki$+Tr6m~!uR{Ch8@tlXzdH9VGg^rWosJ3xU69kQ?!%qh%m)Zb1R$Iu!o$6P%nm7 zmd$E-&fS-U`?P;foi?!}XY)RI3&pZc#7861wpKIyZ_R>3%`LYNR@|C+8?1E^+9O*x z$er2TWEkm~R&#;qCMI*q?Zh-)&hzv;kP-pjF+iGn6q>pdn%V&1;$s1Zf_#Sbt-yx} zqF|VzuMlbesCBr%!t)E>PxQqwOHvX(o$zy*Kf$|%Rn?`LZ;*dM>cul$L#%}lh-{Sc zb646aB1R`mvPr`WHzCxS*$G`?N4@wkZjj$aiFw>2p?O@Gw3oC-aYyjY%zuH}UFmWw zatX_X^l|<-=>dv7H@a+~jL^UM>bGGvVPan2Ajrq>W5Izbt z@ah;+UO(eLf~x`T7z26zEJY7CFeE&~UR|$agz_~odW^BW?w9m)b&MY&&_GcBLE-K? zv~1o}$51x!tz$Hsm+A;+8*ra;_KTT}(9eDpL5$P!1+WU8T5QhnF5<-Ag%w;R9VGh% RF}#on(r=%hghG)*{{2&;EmqRZVk~D>4YNo%F?_g{eV5KL^nd8g zA)INYIxjI8iFP?X+m&OTqOyjm@72pkdi6j%Dv?FBqxL^Cgd*J)qn$-qnZX^29x@0? z!!)c7hCq+F3`h8KM$y!)dX>sVdVzY>qp;x~P@XRIwr*NRSwA#t22p>bRkgBi>D4XM ztXP_5R7~nU;K;e7pH}sPX6eT?xqCgbW^QyBjwg7TwVuGPUGxf-l7&)xDANuee8@MwV>}Bd<}j7k71ElQt$vVE*2Do_({$xc!ew-lk;vAMDUu9WmCa4W)zHJ zoKDM$2*(vna4VxklihAQIySFh%Jy8h$O$ue3#E!l)cldCqnZ7q6TM&&{Z;3j?DI}I zVC{=_M%t&InxPjXNH3s}3Ua~#X`*OrVrXmPLkJh|3K$sWBcNvqK7?@>v`cylk>)?S z0rz)!F5vw_PYm}-3bs!rd<4-eyvw%AsxbEh;su0mJi{F3+j!2AS72W|(oPaFS`0}} zV+J0$N&DvJ$5pA-4G&?F+%C$?!(s&HVPVo9(h7yOD0tx;7N<;Kb^lY4~6#M(u+QPL{?^OHtOq6l061EUHa-T(jq diff --git a/plugins/java-decompiler/engine/testData/results/TestEnum.dec b/plugins/java-decompiler/engine/testData/results/TestEnum.dec index 06649c002abc..6fabfaebda76 100644 --- a/plugins/java-decompiler/engine/testData/results/TestEnum.dec +++ b/plugins/java-decompiler/engine/testData/results/TestEnum.dec @@ -6,8 +6,8 @@ public enum TestEnum { public void m() { }// 22 }, - E3("-"), - E4("+") { + E3("-", TestEnum.Type.ODD), + E4("+", TestEnum.Type.EVEN) { public void m() { }// 27 }; @@ -15,14 +15,19 @@ public enum TestEnum { private String s; public void m() { - }// 30 + }// 32 private TestEnum() { - this("?");// 34 + this("?", (TestEnum.Type)null);// 36 } - private TestEnum(@Deprecated String var3) { - this.s = var3;// 35 + private TestEnum(@Deprecated String var3, TestEnum.Type var4) { + this.s = var3;// 37 + } + + private static enum Type { + ODD, + EVEN; } } @@ -46,10 +51,11 @@ class 'pkg/TestEnum' { method ' (Ljava/lang/String;I)V' { 3 20 5 20 - 8 21 + 6 20 + 9 21 } - method ' (Ljava/lang/String;ILjava/lang/String;)V' { + method ' (Ljava/lang/String;ILjava/lang/String;Lpkg/TestEnum$Type;)V' { 8 24 b 25 } @@ -58,6 +64,6 @@ class 'pkg/TestEnum' { Lines mapping: 22 <-> 7 27 <-> 12 -30 <-> 18 -34 <-> 21 -35 <-> 25 +32 <-> 18 +36 <-> 21 +37 <-> 25 diff --git a/plugins/java-decompiler/engine/testData/src/pkg/TestEnum.java b/plugins/java-decompiler/engine/testData/src/pkg/TestEnum.java index 43fab48355f2..e474d341d406 100644 --- a/plugins/java-decompiler/engine/testData/src/pkg/TestEnum.java +++ b/plugins/java-decompiler/engine/testData/src/pkg/TestEnum.java @@ -21,16 +21,18 @@ public enum TestEnum { @Override public void m() { } }, - E3("-"), - E4("+") { + E3("-", Type.ODD), + E4("+", Type.EVEN) { @Override public void m() { } }; + private enum Type {ODD, EVEN} + public void m() { } private String s; - private TestEnum() { this("?"); } - private TestEnum(@Deprecated String s) { this.s = s; } + private TestEnum() { this("?", null); } + private TestEnum(@Deprecated String s, Type t) { this.s = s; } } From dc45f99a405d06f96c6b0c03335433169a0a834c Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 11 Apr 2016 19:44:48 +0200 Subject: [PATCH 5/9] coverage configuration layout: give rest space to filters --- .../configurations/coverage/CoverageConfigurable.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/coverage/src/com/intellij/execution/configurations/coverage/CoverageConfigurable.java b/plugins/coverage/src/com/intellij/execution/configurations/coverage/CoverageConfigurable.java index b90bf5f9dea3..7b9e1cd97494 100644 --- a/plugins/coverage/src/com/intellij/execution/configurations/coverage/CoverageConfigurable.java +++ b/plugins/coverage/src/com/intellij/execution/configurations/coverage/CoverageConfigurable.java @@ -242,7 +242,7 @@ public class CoverageConfigurable extends SettingsEditor { final GridBagConstraints gc = new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1, 0, - GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, + GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, JBUI.emptyInsets(), 0, 0); result.add(myRunnerPanel, gc); @@ -258,6 +258,8 @@ public class CoverageConfigurable extends SettingsEditor { myTrackTestSourcesCb = new JCheckBox("Enable coverage in test folders"); panel.add(myTrackTestSourcesCb, bagConstraints); + gc.weighty = 1; + gc.fill = GridBagConstraints.BOTH; result.add(panel, gc); myCoverageNotSupportedLabel = new JLabel(CodeInsightBundle.message("code.coverage.is.not.supported")); From 4928ce672f02229b5ae9d344e371395fa7c63235 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 11 Apr 2016 19:45:01 +0200 Subject: [PATCH 6/9] new inference: reorder return constraints according to the spec --- .../graphInference/InferenceSession.java | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 50443509c106..2a4a42aed5fd 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -688,40 +688,43 @@ public class InferenceSession { public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType) { returnType = substituteWithInferenceVariables(returnType); - final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType); - if (inferenceVariable != null) { - final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor); - final PsiType substitutedReturnType = substitutor.substitute(inferenceVariable); - if (substitutedReturnType != null) { - addConstraint(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, myContext))); - } - } - else { - if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) { - final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(returnType); - final PsiClass psiClass = resolveResult.getElement(); - if (psiClass != null) { - LOG.assertTrue(returnType instanceof PsiClassType); - PsiClassType substitutedCapture = (PsiClassType)PsiUtil.captureToplevelWildcards(returnType, myContext); - final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters(); - final InferenceVariable[] copy = initBounds(null, typeParameters); + if (myErased) { + addConstraint(new TypeCompatibilityConstraint(targetType, TypeConversionUtil.erasure(returnType))); + } + else if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) { + final PsiClassType.ClassResolveResult resolveResult = PsiUtil.resolveGenericsClassInType(returnType); + final PsiClass psiClass = resolveResult.getElement(); + if (psiClass != null) { + LOG.assertTrue(returnType instanceof PsiClassType); + PsiClassType substitutedCapture = (PsiClassType)PsiUtil.captureToplevelWildcards(returnType, myContext); + final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters(); + final InferenceVariable[] copy = initBounds(null, typeParameters); - final PsiType[] parameters = substitutedCapture.getParameters(); - final PsiType[] newParameters = new PsiType[parameters.length]; - final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myManager.getProject()); - for (int i = 0; i < parameters.length; i++) { - newParameters[i] = parameters[i]; - if (parameters[i] instanceof PsiCapturedWildcardType) { - newParameters[i] = elementFactory.createType(copy[i]); - } + final PsiType[] parameters = substitutedCapture.getParameters(); + final PsiType[] newParameters = new PsiType[parameters.length]; + final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(myManager.getProject()); + for (int i = 0; i < parameters.length; i++) { + newParameters[i] = parameters[i]; + if (parameters[i] instanceof PsiCapturedWildcardType) { + newParameters[i] = elementFactory.createType(copy[i]); } - substitutedCapture = elementFactory.createType(psiClass, newParameters); - - myIncorporationPhase.addCapture(copy, (PsiClassType)returnType); - addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture)); } - } else { - addConstraint(new TypeCompatibilityConstraint(targetType, myErased ? TypeConversionUtil.erasure(returnType) : returnType)); + substitutedCapture = elementFactory.createType(psiClass, newParameters); + + myIncorporationPhase.addCapture(copy, (PsiClassType)returnType); + addConstraint(new TypeCompatibilityConstraint(targetType, substitutedCapture)); + } + } else { + final InferenceVariable inferenceVariable = shouldResolveAndInstantiate(returnType, targetType); + if (inferenceVariable != null) { + final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor); + final PsiType substitutedReturnType = substitutor.substitute(inferenceVariable); + if (substitutedReturnType != null) { + addConstraint(new TypeCompatibilityConstraint(targetType, PsiUtil.captureToplevelWildcards(substitutedReturnType, myContext))); + } + } + else { + addConstraint(new TypeCompatibilityConstraint(targetType, returnType)); } } } @@ -733,8 +736,7 @@ public class InferenceSession { return inferenceVariable; } if (targetType instanceof PsiClassType) { - if (myErased || - hasUncheckedBounds(inferenceVariable, (PsiClassType)targetType) || + if (hasUncheckedBounds(inferenceVariable, (PsiClassType)targetType) || hasWildcardParameterization(inferenceVariable, (PsiClassType)targetType)) { return inferenceVariable; } From da6de99b117e0571f2fff2b51e999b411f801394 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 11 Apr 2016 20:13:14 +0200 Subject: [PATCH 7/9] type calculation: comment to the javac issue --- .../psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java index 9d88952f7c5d..b320f88cb81a 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/tree/java/PsiMethodCallExpressionImpl.java @@ -244,6 +244,7 @@ public class PsiMethodCallExpressionImpl extends ExpressionPsiElement implements // 18.5.2 // if unchecked conversion was necessary, then this substitution provides the parameter types of the invocation type, // while the return type and thrown types are given by the erasure of m's type (without applying θ'). + //due to https://bugs.openjdk.java.net/browse/JDK-8135087 erasure is called on substitutedReturnType and not on ret type itself as by spec return TypeConversionUtil.erasure(substitutedReturnType); } From 1466b0155ea02cc4269f19f45a10fe0af41a005f Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 11 Apr 2016 20:18:14 +0200 Subject: [PATCH 8/9] bad code green: reject return type constraint if unchecked conversion was applied during applicability check and return type is type parameter --- .../resolve/graphInference/InferenceSession.java | 6 ++++++ .../genericsHighlighting8/IDEA56754.java | 2 +- .../UncheckedWarningsInsideIncorporationPhase.java | 2 +- ...ypeInReturnConstraintWithUncheckedConversion.java | 12 ++++++++++++ .../lambda/GraphInferenceHighlightingTest.java | 4 ++++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveTypeInReturnConstraintWithUncheckedConversion.java diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java index 2a4a42aed5fd..5319fcaa6e19 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/resolve/graphInference/InferenceSession.java @@ -689,6 +689,12 @@ public class InferenceSession { public void registerReturnTypeConstraints(PsiType returnType, PsiType targetType) { returnType = substituteWithInferenceVariables(returnType); if (myErased) { + final InferenceVariable inferenceVariable = getInferenceVariable(returnType); + if (inferenceVariable != null) { + final PsiSubstitutor substitutor = resolveSubset(Collections.singletonList(inferenceVariable), mySiteSubstitutor); + returnType = substitutor.substitute(inferenceVariable); + if (returnType == null) return; + } addConstraint(new TypeCompatibilityConstraint(targetType, TypeConversionUtil.erasure(returnType))); } else if (FunctionalInterfaceParameterizationUtil.isWildcardParameterized(returnType)) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA56754.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA56754.java index ee489aab75ad..7ce30a00c928 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA56754.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/IDEA56754.java @@ -1,5 +1,5 @@ class Foo { public T bar(Class type, String str) { - return Enum.valueOf(type, str); + return Enum.valueOf(type, str); } } \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsInsideIncorporationPhase.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsInsideIncorporationPhase.java index 7fca5e334bb3..0d3c34cd90e7 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsInsideIncorporationPhase.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting8/UncheckedWarningsInsideIncorporationPhase.java @@ -4,7 +4,7 @@ abstract class Group { } public T get(Key key) { - return getCategory(key); + return getCategory(key); } public abstract > R getCategory(Key key); diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveTypeInReturnConstraintWithUncheckedConversion.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveTypeInReturnConstraintWithUncheckedConversion.java new file mode 100644 index 000000000000..a5f0d6bf5909 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/lambda/graphInference/PrimitiveTypeInReturnConstraintWithUncheckedConversion.java @@ -0,0 +1,12 @@ +import java.util.List; + +class Test { + T foo(List l) { + return l.get(0); + } + + void m(List l){ + boolean foo = foo(l); + String s = foo(l); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java index 1e18b3fee52a..97a71067c856 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/lambda/GraphInferenceHighlightingTest.java @@ -429,6 +429,10 @@ public class GraphInferenceHighlightingTest extends LightDaemonAnalyzerTestCase doTest(); } + public void testPrimitiveTypeInReturnConstraintWithUncheckedConversion() throws Exception { + doTest(); + } + public void testVariableNamesOfNestedCalls() throws Exception { IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable()); String filePath = BASE_PATH + "/" + getTestName(false) + ".java"; From fc14dddfd8143e1f10477d9de7984e8d9c4df937 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 11 Apr 2016 21:48:47 +0200 Subject: [PATCH 9/9] check for abstract method implemented optimized: don't go through hierarchy if superClass is not abstract and there is no interfaces, would also fix asm implementations with 'broken' erasures inside --- .../src/com/intellij/codeInsight/ClassUtil.java | 5 +++++ ...fTheyMustBeDeclaredInNonAbstractSuperclass.java | 14 ++++++++++++++ .../daemon/LightAdvHighlightingJdk6Test.java | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/SkipAbstractMethodsIfTheyMustBeDeclaredInNonAbstractSuperclass.java diff --git a/java/java-psi-api/src/com/intellij/codeInsight/ClassUtil.java b/java/java-psi-api/src/com/intellij/codeInsight/ClassUtil.java index 2b0a7b80a827..ed21bf290b09 100644 --- a/java/java-psi-api/src/com/intellij/codeInsight/ClassUtil.java +++ b/java/java-psi-api/src/com/intellij/codeInsight/ClassUtil.java @@ -20,6 +20,7 @@ package com.intellij.codeInsight; import com.intellij.psi.*; +import com.intellij.psi.util.PsiUtil; import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -46,6 +47,10 @@ public class ClassUtil { @Nullable public static PsiMethod getAnyMethodToImplement(@NotNull PsiClass aClass) { + final PsiClass superClass = aClass instanceof PsiAnonymousClass ? PsiUtil.resolveClassInClassTypeOnly(((PsiAnonymousClass)aClass).getBaseClassType()) : aClass.getSuperClass(); + if (superClass != null && !superClass.hasModifierProperty(PsiModifier.ABSTRACT) && aClass.getImplementsListTypes().length == 0) { + return null; + } Set alreadyImplemented = new THashSet(); for (HierarchicalMethodSignature signatureHierarchical : aClass.getVisibleSignatures()) { for (PsiMethod superS : signatureHierarchical.getMethod().findSuperMethods()) { diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/SkipAbstractMethodsIfTheyMustBeDeclaredInNonAbstractSuperclass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/SkipAbstractMethodsIfTheyMustBeDeclaredInNonAbstractSuperclass.java new file mode 100644 index 000000000000..0d603a184ad0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting6/SkipAbstractMethodsIfTheyMustBeDeclaredInNonAbstractSuperclass.java @@ -0,0 +1,14 @@ +interface I { + void m(); +} + +class A implements I {} + +class B extends A {} + +class U { + { + new B() {}; + B b = new B(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java index 2b96a77777c6..428390c027de 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk6Test.java @@ -69,4 +69,7 @@ public class LightAdvHighlightingJdk6Test extends LightDaemonAnalyzerTestCase { public void testUnhandledErrorsFromEnumConstructors() { doTest(true, false); } + public void testSkipAbstractMethodsIfTheyMustBeDeclaredInNonAbstractSuperclass() { + doTest(false, false); + } }