mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring to retrieve editor
This commit is contained in:
+2
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.navigation.actions;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -27,7 +28,7 @@ public class GotoBreakContinueHandler extends GotoDeclarationHandlerBase {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.navigation.actions.GotoBreakContinueHandler");
|
||||
|
||||
@Nullable
|
||||
public PsiElement getGotoDeclarationTarget(final PsiElement elementAt) {
|
||||
public PsiElement getGotoDeclarationTarget(final PsiElement elementAt, Editor editor) {
|
||||
if (elementAt instanceof PsiKeyword) {
|
||||
IElementType type = ((PsiKeyword)elementAt).getTokenType();
|
||||
if (type == JavaTokenType.CONTINUE_KEYWORD) {
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
|
||||
for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) {
|
||||
try {
|
||||
PsiElement[] result = handler.getGotoDeclarationTargets(elementAt);
|
||||
PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, editor);
|
||||
if (result != null && result.length > 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.codeInsight.navigation.actions;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -30,8 +31,9 @@ public interface GotoDeclarationHandler {
|
||||
* Provides an array of target declarations for given {@code sourceElement}.
|
||||
*
|
||||
* @param sourceElement input psiElement
|
||||
* @param editor
|
||||
* @return all target declarations as an array of {@code PsiElement} or null if none was found
|
||||
*/
|
||||
@Nullable
|
||||
PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement);
|
||||
PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, Editor editor);
|
||||
}
|
||||
|
||||
+4
-3
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.navigation.actions;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,11 +25,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
public abstract class GotoDeclarationHandlerBase implements GotoDeclarationHandler {
|
||||
@Nullable
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement) {
|
||||
final PsiElement target = getGotoDeclarationTarget(sourceElement);
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, Editor editor) {
|
||||
final PsiElement target = getGotoDeclarationTarget(sourceElement, editor);
|
||||
return target != null ? new PsiElement[] {target} : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public abstract PsiElement getGotoDeclarationTarget(PsiElement sourceElement);
|
||||
public abstract PsiElement getGotoDeclarationTarget(PsiElement sourceElement, Editor editor);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.android;
|
||||
|
||||
import com.intellij.codeInsight.navigation.actions.GotoDeclarationHandler;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
@@ -26,7 +27,7 @@ import org.jetbrains.android.util.AndroidResourceUtil;
|
||||
*/
|
||||
public class AndroidGotoDeclarationHandler implements GotoDeclarationHandler {
|
||||
@Override
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement) {
|
||||
public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, Editor editor) {
|
||||
if (!(sourceElement instanceof PsiIdentifier)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+1
-3
@@ -33,7 +33,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
public class I18nMessageGotoDeclarationHandler extends GotoDeclarationHandlerBase {
|
||||
private static final Key<FoldingBuilder> KEY = CompositeFoldingBuilder.FOLDING_BUILDER;
|
||||
|
||||
public PsiElement getGotoDeclarationTarget(PsiElement element) {
|
||||
public PsiElement getGotoDeclarationTarget(PsiElement element, Editor editor) {
|
||||
if (!(element instanceof PsiJavaToken)) return null;
|
||||
|
||||
int i = 4; //some street magic
|
||||
@@ -56,8 +56,6 @@ public class I18nMessageGotoDeclarationHandler extends GotoDeclarationHandlerBas
|
||||
//case: MyBundle.message("literalAnnotatedWithPropertyKey", param1, param2)
|
||||
if (element instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)element;
|
||||
final Editor editor = FileEditorManager.getInstance(element.getProject()).getSelectedTextEditor();
|
||||
if (editor == null) return null;
|
||||
FoldRegion foldRegion = null;
|
||||
for (FoldRegion region : editor.getFoldingModel().getAllFoldRegions()) {
|
||||
final PsiElement psiElement = EditorFoldingInfo.get(editor).getPsiElement(region);
|
||||
|
||||
Reference in New Issue
Block a user