Compatible with old and new versions
This commit is contained in:
@@ -7,7 +7,6 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -22,7 +21,7 @@ public class CopyReferenceSimple extends CopyReferenceAction {
|
||||
super.update(e);
|
||||
String tip = IdeBundle.message("copy.reference");
|
||||
if (tip != null && tip.replace("\u001B", "").equals(e.getPresentation().getText())) {
|
||||
e.getPresentation().setText("Copy Class.Method/File:Line");
|
||||
e.getPresentation().setText("Copy Class.Method / File:Line");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +29,9 @@ public class CopyReferenceSimple extends CopyReferenceAction {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String getQualifiedName(@NotNull Editor editor, List<PsiElement> elements) {
|
||||
protected String getQualifiedName(@NotNull Editor editor, List elements) {
|
||||
// because 2nd param is List<PsiElement> in 2020.1 and List<? extends PsiElement> in new version
|
||||
//noinspection unchecked
|
||||
String qualifiedName = super.getQualifiedName(editor, elements);
|
||||
if (qualifiedName == null) {
|
||||
@NotNull Document document = editor.getDocument();
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.github.linwancen.plugin.show.lang;
|
||||
|
||||
import com.intellij.database.psi.DbElement;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.sql.SqlDocumentationProvider;
|
||||
import com.intellij.sql.psi.SqlLanguage;
|
||||
import com.intellij.sql.psi.SqlReferenceExpression;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
@@ -13,6 +12,8 @@ import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class SqlLangDoc extends BaseLangDoc {
|
||||
|
||||
static {
|
||||
@@ -34,8 +35,22 @@ public class SqlLangDoc extends BaseLangDoc {
|
||||
protected @Nullable <T extends SettingsInfo> String refElementDoc(@NotNull T lineInfo,
|
||||
@NotNull PsiElement ref) {
|
||||
JBIterable<DbElement> relatedDbElements;
|
||||
Class<?> clazz;
|
||||
try {
|
||||
relatedDbElements = SqlDocumentationProvider.findRelatedDbElements(ref, false);
|
||||
// new version new Class
|
||||
clazz = Class.forName("com.intellij.sql.SqlNavigationUtils");
|
||||
} catch (Throwable e) {
|
||||
try {
|
||||
// old version
|
||||
clazz = Class.forName("com.intellij.sql.SqlDocumentationProvider");
|
||||
} catch (Throwable e2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Method method = clazz.getMethod("findRelatedDbElements", PsiElement.class, boolean.class);
|
||||
//noinspection unchecked
|
||||
relatedDbElements = (JBIterable<DbElement>) method.invoke(null, ref, false);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ Show doc comment at the Project view Tree, line End, json etc.
|
||||
<action
|
||||
id="io.github.linwancen.plugin.show.CopyReferenceSimple"
|
||||
class="io.github.linwancen.plugin.show.CopyReferenceSimple"
|
||||
text="Copy Class.Method/File:Line">
|
||||
text="Copy Class.Method / File:Line">
|
||||
<add-to-group group-id="EditorPopupMenu" anchor="after"
|
||||
relative-to-action="CopyReference"/>
|
||||
</action>
|
||||
|
||||
Reference in New Issue
Block a user