mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-385919 [java]: offer "Make '<functional interface>' public" fix on lambda
GitOrigin-RevId: 75a800bb70ffd0a0c90cde65a170b3dba3778fed
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bef566cf0e
commit
7ce9a6ced0
+5
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 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.analysis;
|
||||
|
||||
import com.intellij.codeInsight.ClassUtil;
|
||||
@@ -1139,10 +1139,10 @@ public final class DefaultJavaErrorFixProvider extends AbstractJavaErrorFixProvi
|
||||
|
||||
private void createAccessFixes() {
|
||||
JavaFixesPusher<PsiElement, JavaResolveResult> accessFix = (error, sink) -> {
|
||||
if (error.psi() instanceof PsiJavaCodeReferenceElement ref &&
|
||||
error.context().isStaticsScopeCorrect() && error.context().getElement() instanceof PsiJvmMember member) {
|
||||
HighlightFixUtil.registerAccessQuickFixAction(sink, member, ref, null);
|
||||
if (ref instanceof PsiReferenceExpression expression) {
|
||||
if (error.context().isStaticsScopeCorrect() && error.context().getElement() instanceof PsiJvmMember member) {
|
||||
PsiElement element = error.psi();
|
||||
HighlightFixUtil.registerAccessQuickFixAction(sink, member, element, null);
|
||||
if (element instanceof PsiReferenceExpression expression) {
|
||||
sink.accept(myFactory.createRenameWrongRefFix(expression));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2025 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.analysis;
|
||||
|
||||
import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
@@ -195,12 +195,11 @@ public final class HighlightFixUtil {
|
||||
*/
|
||||
static void registerAccessQuickFixAction(@NotNull Consumer<? super CommonIntentionAction> info,
|
||||
@NotNull PsiJvmMember refElement,
|
||||
@NotNull PsiJavaCodeReferenceElement place,
|
||||
@NotNull PsiElement place,
|
||||
@Nullable PsiElement fileResolveScope) {
|
||||
PsiClass accessObjectClass = null;
|
||||
PsiElement qualifier = place.getQualifier();
|
||||
if (qualifier instanceof PsiExpression) {
|
||||
accessObjectClass = (PsiClass)PsiUtil.getAccessObjectClass((PsiExpression)qualifier).getElement();
|
||||
if (place instanceof PsiJavaCodeReferenceElement ref && ref.getQualifier() instanceof PsiExpression expr) {
|
||||
accessObjectClass = (PsiClass)PsiUtil.getAccessObjectClass(expr).getElement();
|
||||
}
|
||||
if (place instanceof PsiReferenceExpression ref) {
|
||||
FieldAccessFixer fixer = FieldAccessFixer.create(ref, refElement, place);
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// 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.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
|
||||
public final class ModifierFixtureTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
public void testUnreachableFunctionalTypeFromLambda() {
|
||||
myFixture.addClass("""
|
||||
package one;
|
||||
public interface Supplier<T> {
|
||||
T get();
|
||||
}
|
||||
""");
|
||||
myFixture.addClass("""
|
||||
package one;
|
||||
class M1 {} // note package-private
|
||||
""");
|
||||
myFixture.addClass("""
|
||||
package one;
|
||||
|
||||
public class M2 {
|
||||
public static void test(Supplier<M1> supplier) {
|
||||
System.out.println(supplier.get());
|
||||
}
|
||||
|
||||
public static M1Sub create() {
|
||||
return new M1Sub();
|
||||
}
|
||||
|
||||
public static class M1Sub extends M1 {
|
||||
|
||||
}
|
||||
}
|
||||
""");
|
||||
myFixture.configureByText("M3.java", """
|
||||
package two;
|
||||
|
||||
import one.*;
|
||||
|
||||
public class M3 {
|
||||
public static void main(String[] args) {
|
||||
M2.test(() -> M2.<caret>create());
|
||||
}
|
||||
}
|
||||
""");
|
||||
myFixture.findSingleIntention("Make 'M1' public");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user