mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-252714 [java] use anchor if request is coming from tree child of target class
GitOrigin-RevId: 8248fb4f61867773b41c5274b52f2e73b3867972
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5ee07a5589
commit
932ea20745
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
@file:JvmName("CreateFieldFromUsage")
|
||||
|
||||
package com.intellij.lang.java.request
|
||||
@@ -15,6 +15,7 @@ import com.intellij.lang.jvm.actions.EP_NAME
|
||||
import com.intellij.lang.jvm.actions.groupActionsByType
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.impl.PsiImplUtil
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.util.PsiUtil.resolveClassInClassTypeOnly
|
||||
import com.intellij.psi.util.PsiUtilCore
|
||||
import com.intellij.psi.util.parentOfType
|
||||
@@ -115,7 +116,7 @@ private class CreateFieldRequests(val myRef: PsiReferenceExpression) {
|
||||
val request = CreateFieldFromJavaUsageRequest(
|
||||
modifiers = modifiers,
|
||||
reference = myRef,
|
||||
useAnchor = target.toJavaClassOrNull() == ownerClass,
|
||||
useAnchor = ownerClass != null && PsiTreeUtil.isAncestor(target.toJavaClassOrNull(), ownerClass, false),
|
||||
isConstant = false
|
||||
)
|
||||
addRequest(target, request)
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Create field 'i' in 'A'" "true"
|
||||
class A {
|
||||
private int i<caret>;
|
||||
Object o = new Object() {
|
||||
|
||||
public void f(A a) {
|
||||
a.i = 0;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Create field 'i' in 'A'" "true"
|
||||
class A {
|
||||
Object o = new Object() {
|
||||
|
||||
public void f(A a) {
|
||||
a.<caret>i = 0;
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
@@ -73,6 +73,8 @@ public class CreateFieldFromUsageTest extends LightQuickFixTestCase {
|
||||
public void testInnerGeneric() { doSingleTest(); }
|
||||
|
||||
public void testInnerGenericArray() { doSingleTest(); }
|
||||
|
||||
public void testFromUnfinishedAnonymousClass() { doSingleTest(); }
|
||||
|
||||
protected void doSingleTest() {
|
||||
doSingleTest(getTestName(false) + ".java");
|
||||
|
||||
Reference in New Issue
Block a user