refactor(Sonar): Extract method to another Class
This commit is contained in:
@@ -10,7 +10,7 @@ import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.java.doc.AnnoDoc;
|
||||
import io.github.linwancen.plugin.show.java.doc.EnumDoc;
|
||||
import io.github.linwancen.plugin.show.java.doc.OwnerToPsiDocUtils;
|
||||
import io.github.linwancen.plugin.show.java.doc.NewDoc;
|
||||
import io.github.linwancen.plugin.show.java.doc.ParamDoc;
|
||||
import io.github.linwancen.plugin.show.java.doc.PsiMethodToPsiDoc;
|
||||
import io.github.linwancen.plugin.show.java.line.OwnerToPsiDocSkip;
|
||||
@@ -57,23 +57,11 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
|
||||
return docElementToStr(info, psiDocComment);
|
||||
}
|
||||
if (info.appSettings.fromNew) {
|
||||
PsiElement parent = ref.getParent();
|
||||
if (parent instanceof PsiNewExpression) {
|
||||
@NotNull PsiNewExpression psiNewExpression = (PsiNewExpression) parent;
|
||||
try {
|
||||
@Nullable PsiMethod resolve = psiNewExpression.resolveMethod();
|
||||
if (resolve != null) {
|
||||
PsiElement navElement = resolve.getNavigationElement();
|
||||
if (navElement instanceof PsiMethod) {
|
||||
resolve = (PsiMethod) navElement;
|
||||
}
|
||||
@Nullable String s = resolveDocPrint(info, resolve);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
// ignore
|
||||
@Nullable PsiMethod resolve = NewDoc.newMethod(ref);
|
||||
if (resolve != null) {
|
||||
@Nullable String s = resolveDocPrint(info, resolve);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package io.github.linwancen.plugin.show.java.doc;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiNewExpression;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class NewDoc {
|
||||
@Nullable
|
||||
public static PsiMethod newMethod(@NotNull PsiElement ref) {
|
||||
PsiElement parent = ref.getParent();
|
||||
if (!(parent instanceof PsiNewExpression)) {
|
||||
return null;
|
||||
}
|
||||
@NotNull PsiNewExpression psiNewExpression = (PsiNewExpression) parent;
|
||||
try {
|
||||
@Nullable PsiMethod resolve = psiNewExpression.resolveMethod();
|
||||
if (resolve == null) {
|
||||
return null;
|
||||
}
|
||||
PsiElement navElement = resolve.getNavigationElement();
|
||||
if (navElement instanceof PsiMethod) {
|
||||
return (PsiMethod) navElement;
|
||||
}
|
||||
return resolve;
|
||||
} catch (Throwable ignore) {
|
||||
// ignore
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -2,23 +2,20 @@ package io.github.linwancen.plugin.show;
|
||||
|
||||
import com.intellij.json.JsonFileType;
|
||||
import com.intellij.json.json5.Json5FileType;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.EditorLinePainter;
|
||||
import com.intellij.openapi.editor.LineExtensionInfo;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import io.github.linwancen.plugin.show.bean.FileInfo;
|
||||
import io.github.linwancen.plugin.show.bean.FuncEnum;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.cache.LineEndCacheUtils;
|
||||
import io.github.linwancen.plugin.show.ext.LineExt;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
|
||||
import io.github.linwancen.plugin.show.line.LineSelect;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@@ -46,31 +43,18 @@ public class LineEnd extends EditorLinePainter {
|
||||
@Nullable
|
||||
private static Collection<LineExtensionInfo> getLineExtensionInfos(@NotNull Project project,
|
||||
@NotNull VirtualFile file, int lineNumber) {
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
if (!settings.showLineEndComment) {
|
||||
@NotNull SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.LINE);
|
||||
if (!settingsInfo.appSettings.showLineEndComment) {
|
||||
return null;
|
||||
}
|
||||
@NotNull GlobalSettingsState globalSettingsState = GlobalSettingsState.getInstance();
|
||||
if (globalSettingsState.onlySelectLine) {
|
||||
@Nullable Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
|
||||
if (editor != null) {
|
||||
@NotNull SelectionModel select = editor.getSelectionModel();
|
||||
@Nullable VisualPosition start = select.getSelectionStartPosition();
|
||||
int lineNum = lineNumber + 1;
|
||||
if (start != null && lineNum < start.getLine()) {
|
||||
return null;
|
||||
}
|
||||
@Nullable VisualPosition end = select.getSelectionEndPosition();
|
||||
if (end != null && lineNum > end.getLine()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (settingsInfo.globalSettings.onlySelectLine && LineSelect.notSelectLine(project, lineNumber)) {
|
||||
return null;
|
||||
}
|
||||
@Nullable LineInfo info = LineInfo.of(file, project, lineNumber);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
if (settings.lineEndCache) {
|
||||
if (settingsInfo.appSettings.lineEndCache) {
|
||||
return LineEndCacheUtils.get(info);
|
||||
} else {
|
||||
@Nullable LineExtensionInfo lineExt = lineExt(info);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.SelectionModel;
|
||||
import com.intellij.openapi.editor.VisualPosition;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LineSelect {
|
||||
/**
|
||||
* can not work
|
||||
*/
|
||||
public static boolean notSelectLine(@NotNull Project project, int lineNumber) {
|
||||
@Nullable Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
|
||||
if (editor == null) {
|
||||
return false;
|
||||
}
|
||||
@NotNull SelectionModel select = editor.getSelectionModel();
|
||||
@Nullable VisualPosition start = select.getSelectionStartPosition();
|
||||
int lineNum = lineNumber + 1;
|
||||
if (start != null && lineNum < start.getLine()) {
|
||||
return true;
|
||||
}
|
||||
@Nullable VisualPosition end = select.getSelectionEndPosition();
|
||||
return end != null && lineNum > end.getLine();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user