[java] skip diamond inference for constructor calls of static nested classes

EA-246216 - T: JavaMethodsConflictResolver.resolveConflict

GitOrigin-RevId: 5fc2f7118bf68a1d0b9f80bfcbbbfa768fc6bea8
This commit is contained in:
Anna Kozlova
2022-07-08 09:08:27 +02:00
committed by intellij-monorepo-bot
parent c378f327ff
commit 5a29d515fc
3 changed files with 25 additions and 17 deletions

View File

@@ -1,18 +1,4 @@
/*
* 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.
* 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.
*/
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.psi;
import com.intellij.lang.java.JavaLanguage;
@@ -109,7 +95,15 @@ public class PsiDiamondTypeImpl extends PsiDiamondType {
private PsiNewExpression getNewExpression() {
PsiElement typeElementWithDiamondTypeArgument = myTypeElement.getParent();
return PsiTreeUtil.getParentOfType(typeElementWithDiamondTypeArgument, PsiNewExpression.class, true, PsiTypeElement.class);
PsiNewExpression newExpression =
PsiTreeUtil.getParentOfType(typeElementWithDiamondTypeArgument, PsiNewExpression.class, true, PsiTypeElement.class, PsiStatement.class);
if (newExpression != null) {
PsiJavaCodeReferenceElement classReference = newExpression.getClassOrAnonymousClassReference();
if (classReference != null && classReference.getParameterList() == typeElementWithDiamondTypeArgument) {
return newExpression;
}
}
return null;
}
@Nullable

View File

@@ -0,0 +1,11 @@
class R<T> {
static class O {
public O(<error descr="'R.this' cannot be referenced from a static context">T</error> t) {
}
}
public static void main(String[] args) {
test(new R<>.O<error descr="'O(java.lang.Object)' in 'R.O' cannot be applied to '()'">()</error>);
}
private static void test(R.O o) {}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon.lambda;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
@@ -101,6 +101,9 @@ public class Diamond8HighlightingTest extends LightDaemonAnalyzerTestCase {
public void testDiamondsUncheckedWarning() { doTest();}
public void testWrongNumberOfArguments() { doTest();}
public void testNestedClassArgConstructor() {
doTest();
}
private void doTest() {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", false, false);