mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Use smart pointers in GotoRelatedItem to avoid keeping strong PSI references (to support plugin unloading)
GitOrigin-RevId: 1efea96188786cc3e3e4efdba66c3a506e058ed3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1967df4d42
commit
0ff3963399
@@ -1,21 +1,9 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// 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.
|
||||
package com.intellij.navigation;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.SmartPointerManager;
|
||||
import com.intellij.psi.SmartPsiElementPointer;
|
||||
import com.intellij.util.PsiNavigateUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -32,11 +20,11 @@ import java.util.List;
|
||||
public class GotoRelatedItem {
|
||||
private final String myGroup;
|
||||
private final int myMnemonic;
|
||||
private final PsiElement myElement;
|
||||
private final SmartPsiElementPointer<PsiElement> myElementPointer;
|
||||
public static final String DEFAULT_GROUP_NAME = "";
|
||||
|
||||
protected GotoRelatedItem(@Nullable PsiElement element, String group, final int mnemonic) {
|
||||
myElement = element;
|
||||
myElementPointer = element == null ? null : SmartPointerManager.getInstance(element.getProject()).createSmartPsiElementPointer(element);
|
||||
myGroup = group;
|
||||
myMnemonic = mnemonic;
|
||||
}
|
||||
@@ -50,7 +38,10 @@ public class GotoRelatedItem {
|
||||
}
|
||||
|
||||
public void navigate() {
|
||||
PsiNavigateUtil.navigate(myElement);
|
||||
PsiElement element = myElementPointer.getElement();
|
||||
if (element != null) {
|
||||
PsiNavigateUtil.navigate(element);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -70,7 +61,7 @@ public class GotoRelatedItem {
|
||||
|
||||
@Nullable
|
||||
public PsiElement getElement() {
|
||||
return myElement;
|
||||
return myElementPointer.getElement();
|
||||
}
|
||||
|
||||
public int getMnemonic() {
|
||||
@@ -95,7 +86,7 @@ public class GotoRelatedItem {
|
||||
|
||||
GotoRelatedItem item = (GotoRelatedItem)o;
|
||||
|
||||
if (myElement != null ? !myElement.equals(item.myElement) : item.myElement != null) return false;
|
||||
if (myElementPointer != null ? !myElementPointer.equals(item.myElementPointer) : item.myElementPointer != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -106,6 +97,6 @@ public class GotoRelatedItem {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myElement != null ? myElement.hashCode() : 0;
|
||||
return myElementPointer != null ? myElementPointer.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user