mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
IDEA-261098 GotoVarTypeHandler: don't target var variable identifier to the variable
This was needed to show the doc as if the variable was referenced. In the new implementation we show the same doc info regardless whether the target under caret is referenced or declared, but this handler made GTDU believe that the variable was referenced, and GTDU was choosing navigation to the referenced target instead of showing usages. GitOrigin-RevId: 78e3554df87d564aeea04f707a0fa1309031912f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1d2e787f53
commit
1ba096bbc2
@@ -1,8 +1,10 @@
|
||||
// Copyright 2000-2017 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. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.navigation.actions;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiKeyword;
|
||||
import com.intellij.psi.PsiTypeElement;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -10,16 +12,7 @@ public class GotoVarTypeHandler extends GotoDeclarationHandlerBase {
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement elementAt, Editor editor) {
|
||||
if (elementAt instanceof PsiIdentifier) {
|
||||
PsiElement parent = elementAt.getParent();
|
||||
if (parent instanceof PsiVariable) {
|
||||
PsiTypeElement typeElement = ((PsiVariable)parent).getTypeElement();
|
||||
if (typeElement != null && typeElement.isInferredType()) {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (elementAt instanceof PsiKeyword && PsiKeyword.VAR.equals(elementAt.getText())) {
|
||||
if (elementAt instanceof PsiKeyword && PsiKeyword.VAR.equals(elementAt.getText())) {
|
||||
PsiElement parent = elementAt.getParent();
|
||||
if (parent instanceof PsiTypeElement && ((PsiTypeElement)parent).isInferredType()) {
|
||||
return PsiUtil.resolveClassInClassTypeOnly(((PsiTypeElement)parent).getType());
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<a href="psi_element://java.lang.String">String</a> a = "aaa"
|
||||
@@ -0,0 +1,6 @@
|
||||
class UsageSample {
|
||||
|
||||
public void foo() {
|
||||
var <caret>a = "aaa";
|
||||
}
|
||||
}
|
||||
@@ -24,4 +24,7 @@ class JavaCtrlMouseTest : LightJavaCodeInsightFixtureTestCase4(
|
||||
|
||||
@Test
|
||||
fun `lambda parameter`(): Unit = doTest()
|
||||
|
||||
@Test
|
||||
fun `var variable`(): Unit = doTest()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user