mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-381369 [java]: don't offer Create Field fix on method references
GitOrigin-RevId: 1c63811f47a794614121a45f48f8df02b69baaac
This commit is contained in:
committed by
intellij-monorepo-bot
parent
35bf973a53
commit
bef566cf0e
+8
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixActionRegistrar;
|
||||
@@ -19,6 +19,7 @@ import com.intellij.psi.PsiJavaCodeReferenceCodeFragment;
|
||||
import com.intellij.psi.PsiJavaCodeReferenceElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiMethodCallExpression;
|
||||
import com.intellij.psi.PsiMethodReferenceExpression;
|
||||
import com.intellij.psi.PsiNewExpression;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
@@ -151,11 +152,13 @@ public class DefaultQuickFixProvider extends UnresolvedReferenceQuickFixProvider
|
||||
result.add(kind == VariableKind.LOCAL_VARIABLE ? PriorityIntentionActionWrapper.highPriority(createLocalFix) : createLocalFix);
|
||||
}
|
||||
|
||||
List<IntentionAction> createFieldFixes = CreateFieldFromUsage.generateActions(refExpr);
|
||||
if (kind == VariableKind.FIELD) {
|
||||
createFieldFixes = ContainerUtil.map(createFieldFixes, fix -> PriorityIntentionActionWrapper.highPriority(fix));
|
||||
if (!(refExpr instanceof PsiMethodReferenceExpression)) {
|
||||
List<IntentionAction> createFieldFixes = CreateFieldFromUsage.generateActions(refExpr);
|
||||
if (kind == VariableKind.FIELD) {
|
||||
createFieldFixes = ContainerUtil.map(createFieldFixes, fix -> PriorityIntentionActionWrapper.highPriority(fix));
|
||||
}
|
||||
result.addAll(createFieldFixes);
|
||||
}
|
||||
result.addAll(createFieldFixes);
|
||||
|
||||
if (!isQualified) {
|
||||
IntentionAction createParameterFix = new CreateParameterFromUsageFix(refExpr);
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Create field 'foo' in 'Target'" "false"
|
||||
|
||||
public class MethodReference {
|
||||
void test() {
|
||||
Supplier<Target> supplier = Target::new;
|
||||
Supplier<Target> s = Target::<caret>foo;
|
||||
}
|
||||
}
|
||||
|
||||
class Target {
|
||||
|
||||
private Target() {}
|
||||
|
||||
private static Target foo() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+4
-11
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -44,6 +44,7 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase {
|
||||
public void testReferenceInCall() { doSingleTest(); }
|
||||
public void testReferenceLambdaType() { doSingleTest(); }
|
||||
public void testReferenceNull() { doSingleTest(); }
|
||||
|
||||
public void testWithAlignment() {
|
||||
final CommonCodeStyleSettings settings = CodeStyle.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
|
||||
boolean old = settings.ALIGN_GROUP_FIELD_DECLARATIONS;
|
||||
@@ -69,21 +70,13 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase {
|
||||
|
||||
public void testDependantConstant() { doSingleTest(); }
|
||||
public void testDependantConstant2() { doSingleTest(); }
|
||||
|
||||
public void testArrayBraces() {
|
||||
doSingleTest();
|
||||
}
|
||||
|
||||
public void testMethodReference() { doSingleTest(); }
|
||||
public void testArrayBraces() { doSingleTest(); }
|
||||
public void testInnerGeneric() { doSingleTest(); }
|
||||
|
||||
public void testInnerGenericArray() { doSingleTest(); }
|
||||
|
||||
public void testFromUnfinishedAnonymousClass() { doSingleTest(); }
|
||||
|
||||
public void testCreateFromAnnotationParameterIncorrectCode() { doSingleTest(); }
|
||||
|
||||
public void testAbstractClassIncorrectCode() { doSingleTest(); }
|
||||
|
||||
public void testBrokenCode() { doSingleTest(); }
|
||||
|
||||
protected void doSingleTest() {
|
||||
|
||||
Reference in New Issue
Block a user