add try catch

This commit is contained in:
林万程
2023-06-13 07:45:15 +08:00
parent 2c6f96712b
commit 83e0a0a5ee
13 changed files with 138 additions and 20 deletions

View File

@@ -12,6 +12,8 @@ import io.github.linwancen.plugin.show.java.doc.PsiClassUtils;
import io.github.linwancen.plugin.show.jump.JsonRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
@@ -19,8 +21,18 @@ import java.util.List;
public class JsonJumpJava extends PsiReferenceContributor {
private static final Logger LOG = LoggerFactory.getLogger(JsonJumpJava.class);
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
try {
register(registrar);
} catch (Exception e) {
LOG.info("JsonJumpJava catch Throwable but log to record.", e);
}
}
private static void register(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(JsonStringLiteral.class),
new PsiReferenceProvider() {
@Override

View File

@@ -15,7 +15,12 @@ public class OwnerToPsiDocUtils {
@Nullable
public static PsiDocComment srcOrByteCodeDoc(@NotNull PsiDocCommentOwner psiDocCommentOwner) {
PsiElement navElement = psiDocCommentOwner.getNavigationElement();
PsiElement navElement;
try {
navElement = psiDocCommentOwner.getNavigationElement();
} catch (Exception e) {
return null;
}
if (navElement instanceof PsiDocCommentOwner) {
psiDocCommentOwner = (PsiDocCommentOwner) navElement;
}

View File

@@ -15,7 +15,12 @@ class PsiMethodToPsiDoc {
@Nullable
static PsiDocComment methodSupperNewPropDoc(@NotNull PsiMethod psiMethod) {
// .class
PsiElement navElement = psiMethod.getNavigationElement();
PsiElement navElement = null;
try {
navElement = psiMethod.getNavigationElement();
} catch (Exception e) {
return null;
}
if (navElement instanceof PsiMethod) {
psiMethod = (PsiMethod) navElement;
}

View File

@@ -28,6 +28,15 @@ public class CopyReferenceSimple extends CopyReferenceAction {
@Nullable
@Override
protected String getQualifiedName(@NotNull Editor editor, List elements) {
try {
return simpleName(editor, elements);
} catch (Exception e) {
return e.toString();
}
}
@Nullable
private String simpleName(@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);

View File

@@ -15,15 +15,31 @@ import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class LineEnd extends EditorLinePainter {
private static final Logger LOG = LoggerFactory.getLogger(LineEnd.class);
@Override
public @Nullable Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project,
@NotNull VirtualFile file, int lineNumber) {
try {
return getLineExtensionInfos(project, file, lineNumber);
} catch (Throwable e) {
LOG.info("LineEnd catch Throwable but log to record.", e);
return null;
}
}
@Nullable
private static List<LineExtensionInfo> getLineExtensionInfos(@NotNull Project project,
@NotNull VirtualFile file, int lineNumber) {
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
if (!settings.showLineEndComment) {
return null;

View File

@@ -15,12 +15,16 @@ import io.github.linwancen.plugin.show.bean.FileInfo;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* on ProjectViewPopupMenu
*/
public class LineEndAdd extends DumbAwareAction {
private static final Logger LOG = LoggerFactory.getLogger(LineEndAdd.class);
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
@@ -29,6 +33,14 @@ public class LineEndAdd extends DumbAwareAction {
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
try {
action(event);
} catch (Throwable e) {
LOG.info("LineEndAdd catch Throwable but log to record.", e);
}
}
private void action(@NotNull AnActionEvent event) {
@Nullable Project project = event.getProject();
if (project == null) {
return;

View File

@@ -11,6 +11,8 @@ import io.github.linwancen.plugin.show.bean.FileInfo;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.datatransfer.StringSelection;
@@ -19,6 +21,8 @@ import java.awt.datatransfer.StringSelection;
*/
public class LineEndCopy extends DumbAwareAction {
private static final Logger LOG = LoggerFactory.getLogger(LineEndCopy.class);
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
@@ -27,7 +31,11 @@ public class LineEndCopy extends DumbAwareAction {
@Override
public void actionPerformed(@NotNull AnActionEvent event) {
ApplicationManager.getApplication().runReadAction(() -> copyWithDoc(event));
try {
ApplicationManager.getApplication().runReadAction(() -> copyWithDoc(event));
} catch (Throwable e) {
LOG.info("LineEndCopy catch Throwable but log to record.", e);
}
}
private void copyWithDoc(@NotNull AnActionEvent event) {

View File

@@ -18,14 +18,26 @@ import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collection;
import java.util.List;
public class Tree implements ProjectViewNodeDecorator {
private static final Logger LOG = LoggerFactory.getLogger(Tree.class);
@Override
public void decorate(@NotNull ProjectViewNode node, @NotNull PresentationData data) {
try {
decorateImpl(node, data);
} catch (Throwable e) {
LOG.info("Tree catch Throwable but log to record.", e);
}
}
private void decorateImpl(@NotNull ProjectViewNode node, @NotNull PresentationData data) {
if (!AppSettingsState.getInstance().showTreeComment) {
return;
}

View File

@@ -5,12 +5,16 @@ import com.intellij.openapi.fileEditor.FileEditorManagerListener;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* call ConfCache.loadFile
*/
public class ConfFileChangeListener implements FileEditorManagerListener {
private static final Logger LOG = LoggerFactory.getLogger(ConfFileChangeListener.class);
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
@Nullable VirtualFile file = event.getOldFile();
@@ -18,7 +22,11 @@ public class ConfFileChangeListener implements FileEditorManagerListener {
return;
}
if (file.exists()) {
ConfCache.loadFile(file);
try {
ConfCache.loadFile(file);
} catch (Throwable e) {
LOG.info("ConfFileChangeListener catch Throwable but log to record.", e);
}
}
}
}

View File

@@ -3,15 +3,22 @@ package io.github.linwancen.plugin.show.ext.conf;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManagerListener;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* call ConfCache.loadAll
*/
public class ConfFileInitListener implements ProjectManagerListener {
private static final Logger LOG = LoggerFactory.getLogger(ConfFileInitListener.class);
@Override
public void projectOpened(@NotNull Project project) {
ConfCache.loadAll(project);
try {
ConfCache.loadAll(project);
} catch (Throwable e) {
LOG.info("ConfFileInitListener catch Throwable but log to record.", e);
}
}
}

View File

@@ -5,6 +5,8 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
@@ -13,10 +15,16 @@ import java.util.List;
*/
public class ConfFileListener implements BulkFileListener {
private static final Logger LOG = LoggerFactory.getLogger(ConfFileListener.class);
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
for (@NotNull VFileEvent event : events) {
forEvent(event);
try {
for (@NotNull VFileEvent event : events) {
forEvent(event);
}
} catch (Throwable e) {
LOG.info("ConfFileListener catch Throwable but log to record.", e);
}
}

View File

@@ -8,12 +8,16 @@ import com.intellij.openapi.project.Project;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* call ConfCache.loadAll
*/
public class ReloadExtDocAction extends AnAction {
private static final Logger LOG = LoggerFactory.getLogger(ReloadExtDocAction.class);
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
@@ -22,12 +26,16 @@ public class ReloadExtDocAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
@Nullable Project project = e.getProject();
if (project == null) {
return;
try {
@Nullable Project project = e.getProject();
if (project == null) {
return;
}
ConfCache.loadAll(project);
ApplicationManager.getApplication().invokeLater(() ->
ProjectView.getInstance(project).refresh());
} catch (Throwable t) {
LOG.info("ReloadExtDocAction catch Throwable but log to record.", t);
}
ConfCache.loadAll(project);
ApplicationManager.getApplication().invokeLater(() ->
ProjectView.getInstance(project).refresh());
}
}

View File

@@ -8,6 +8,8 @@ import com.intellij.openapi.project.Project;
import io.github.linwancen.plugin.show.settings.ShowBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* call ConfCache.clearAll
@@ -15,6 +17,8 @@ import org.jetbrains.annotations.Nullable;
*/
public class ResetExtDocAction extends AnAction {
private static final Logger LOG = LoggerFactory.getLogger(ResetExtDocAction.class);
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
@@ -23,12 +27,16 @@ public class ResetExtDocAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
ConfCache.clearAll();
@Nullable Project project = e.getProject();
if (project == null) {
return;
try {
ConfCache.clearAll();
@Nullable Project project = e.getProject();
if (project == null) {
return;
}
ApplicationManager.getApplication().invokeLater(() ->
ProjectView.getInstance(project).refresh());
} catch (Throwable t) {
LOG.info("ConfFileChangeListener catch Throwable but log to record.", t);
}
ApplicationManager.getApplication().invokeLater(() ->
ProjectView.getInstance(project).refresh());
}
}