Compatible with old and new versions
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user