Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Support IntelliJ 2021.3 (#124)
Browse files Browse the repository at this point in the history
* Support IntelliJ 2021.3

* Suppress NoClassDefFoundError error message

* Resolve deprecation warning
  • Loading branch information
AdemJensen authored Dec 8, 2021
1 parent 9a800c0 commit b612e96
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ subprojects {
apply plugin: 'org.jetbrains.intellij'
intellij {
version project.property("ideaVersion")
plugins = ['copyright', 'java', 'org.intellij.scala:2021.1.16']
plugins = ['copyright', 'java', 'org.intellij.scala:2021.3.14']
downloadSources Boolean.valueOf(sources)
sameSinceUntilBuild Boolean.valueOf(isEAP)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ideaVersion = 2021.2
ideaVersion = 2021.3
sources = true
isEAP = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,17 @@ protected int getIconFlags() {

@NotNull
private List<ThriftDeclaration> getThriftDeclarations(PsiElement psiElement, Project project) {
if (psiElement instanceof PsiClass) {
PsiClass psiClassElement = (PsiClass) psiElement;
String name = psiClassElement.getName();
if (name != null) { // todo - handle multiple matches
return ThriftDeclarationIndex.findDeclaration(name, project, GlobalSearchScope.allScope(project));
// FIXME: The PsiClass might not valid in Non-Java editors such as GoLand
try {
if (psiElement instanceof PsiClass) {
PsiClass psiClassElement = (PsiClass) psiElement;
String name = psiClassElement.getName();
if (name != null) { // todo - handle multiple matches
return ThriftDeclarationIndex.findDeclaration(name, project, GlobalSearchScope.allScope(project));
}
}
} catch (NoClassDefFoundError e) {
logger.warn("NoClassDefFoundError at GoToThriftDefinition.java:90");
}
return Lists.newArrayList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.intellij.plugins.thrift.editor;

import com.intellij.codeHighlighting.Pass;
import com.intellij.codeInsight.daemon.DaemonBundle;
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator;
Expand All @@ -13,11 +11,9 @@
import com.intellij.plugins.thrift.util.ThriftPsiUtil;
import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.util.Function;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.awt.event.MouseEvent;
import java.util.List;

/**
Expand All @@ -26,43 +22,33 @@
public class ThriftLineMarkerProvider implements LineMarkerProvider {
@Nullable
@Override
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
public LineMarkerInfo<PsiElement> getLineMarkerInfo(@NotNull PsiElement element) {
if (element instanceof ThriftDefinitionName) {
return findImplementationsAndCreateMarker((ThriftDefinitionName)element);
}
return null;
}

@Nullable
private LineMarkerInfo findImplementationsAndCreateMarker(final ThriftDefinitionName definitionName) {
private LineMarkerInfo<PsiElement> findImplementationsAndCreateMarker(final ThriftDefinitionName definitionName) {
final List<NavigatablePsiElement> implementations = ThriftPsiUtil.findImplementations(definitionName);
if (implementations.isEmpty()) {
return null;
}
return new LineMarkerInfo<PsiElement>(
return new LineMarkerInfo<>(
definitionName,
definitionName.getTextRange(),
AllIcons.Gutter.ImplementedMethod,
Pass.UPDATE_ALL,
new Function<PsiElement, String>() {
@Override
public String fun(PsiElement element) {
return DaemonBundle.message("interface.is.implemented.too.many");
}
},
new GutterIconNavigationHandler<PsiElement>() {
@Override
public void navigate(MouseEvent e, PsiElement elt) {
PsiElementListNavigator.openTargets(
e,
implementations.toArray(new NavigatablePsiElement[implementations.size()]),
DaemonBundle.message("navigation.title.implementation.method", definitionName.getText(), implementations.size()),
"Implementations of " + definitionName.getText(),
new DefaultPsiElementCellRenderer()
);
}
},
GutterIconRenderer.Alignment.RIGHT
element -> DaemonBundle.message("interface.is.implemented.too.many"),
(e, elt) -> PsiElementListNavigator.openTargets(
e,
implementations.toArray(new NavigatablePsiElement[0]),
DaemonBundle.message("navigation.title.implementation.method", definitionName.getText(), implementations.size()),
"Implementations of " + definitionName.getText(),
new DefaultPsiElementCellRenderer()
),
GutterIconRenderer.Alignment.RIGHT,
() -> DaemonBundle.message("interface.is.implemented.too.many")
);
}
}

0 comments on commit b612e96

Please sign in to comment.