mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
[java] [unused declaration]: process record's canonical constructors
EA-296213 (plugin) - CCE: RefJavaManagerImpl.getParameterReference GitOrigin-RevId: 3b01695e5ff11d45fdcfdf6c1ffeb22a67b194bf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
679ebdb31b
commit
3711123cf0
@@ -7,6 +7,7 @@ import com.intellij.java.analysis.JavaAnalysisBundle;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightElement;
|
||||
import com.intellij.psi.impl.light.LightRecordCanonicalConstructor;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -211,10 +212,24 @@ public class RefJavaUtilImpl extends RefJavaUtil {
|
||||
if (psiResolved == null) {
|
||||
psiResolved = tryFindKotlinParameter(node, decl);
|
||||
}
|
||||
if (psiResolved instanceof LightElement) {
|
||||
psiResolved = psiResolved.getNavigationElement();
|
||||
|
||||
RefElement refResolved;
|
||||
if (psiResolved instanceof LightRecordCanonicalConstructor) {
|
||||
refResolved = refFrom.getRefManager().getReference(psiResolved.getNavigationElement());
|
||||
if (refResolved instanceof RefClass) {
|
||||
List<RefMethod> constructors = ((RefClass)refResolved).getConstructors();
|
||||
if (!constructors.isEmpty()) {
|
||||
refResolved = constructors.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (psiResolved instanceof LightElement) {
|
||||
psiResolved = psiResolved.getNavigationElement();
|
||||
}
|
||||
|
||||
refResolved = refFrom.getRefManager().getReference(psiResolved);
|
||||
}
|
||||
RefElement refResolved = refFrom.getRefManager().getReference(psiResolved);
|
||||
boolean writing = isAccessedForWriting(node);
|
||||
boolean reading = isAccessedForReading(node);
|
||||
refFrom.addReference(refResolved, psiResolved, decl, writing, reading, node);
|
||||
|
||||
@@ -152,7 +152,7 @@ public class RefMethodImpl extends RefJavaElementImpl implements RefMethod {
|
||||
}
|
||||
}
|
||||
|
||||
if (sourcePsi.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
|
||||
if (sourcePsi instanceof PsiMethod && sourcePsi.getLanguage().isKindOf(JavaLanguage.INSTANCE)) {
|
||||
collectUncaughtExceptions((PsiMethod)sourcePsi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2018 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-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.
|
||||
package com.intellij.psi.util;
|
||||
|
||||
import com.intellij.core.JavaPsiBundle;
|
||||
@@ -418,7 +418,7 @@ public class PsiFormatUtil extends PsiFormatUtilBase {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
PsiClass psiClass = PsiTreeUtil.getParentOfType(owner, PsiClass.class, false);
|
||||
PsiClass psiClass = PsiTreeUtil.getContextOfType(owner, PsiClass.class, false);
|
||||
if (psiClass == null) return null;
|
||||
ClassUtil.formatClassName(psiClass, builder);
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
@@ -0,0 +1,5 @@
|
||||
record A(int i) {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(new A(1));
|
||||
}
|
||||
}
|
||||
@@ -255,6 +255,10 @@ public class UnusedDeclarationInspectionTest extends AbstractUnusedDeclarationTe
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testRecords() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest5() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_5, () -> doTest());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user