@Null Annotations, etc
This commit is contained in:
@@ -10,6 +10,7 @@ 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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -27,16 +28,17 @@ public class CopyReferenceSimple extends CopyReferenceAction {
|
||||
|
||||
private static final Pattern QUALIFIED_PATTERN = Pattern.compile("[\\w.]+\\.");
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected String getQualifiedName(Editor editor, List<PsiElement> elements) {
|
||||
protected String getQualifiedName(@NotNull Editor editor, List<PsiElement> elements) {
|
||||
String qualifiedName = super.getQualifiedName(editor, elements);
|
||||
if (qualifiedName == null) {
|
||||
Document document = editor.getDocument();
|
||||
Project project = editor.getProject();
|
||||
@NotNull Document document = editor.getDocument();
|
||||
@Nullable Project project = editor.getProject();
|
||||
if (project == null) {
|
||||
return null;
|
||||
}
|
||||
PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
|
||||
@Nullable PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document);
|
||||
if (file != null) {
|
||||
// getFileFqn(file) => file.getName()
|
||||
return file.getName() + ":" + (editor.getCaretModel().getLogicalPosition().line + 1);
|
||||
|
||||
@@ -24,7 +24,7 @@ public class LineEnd extends EditorLinePainter {
|
||||
@Override
|
||||
public @Nullable Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project,
|
||||
@NotNull VirtualFile file, int lineNumber) {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
if (!settings.showLineEndComment) {
|
||||
return null;
|
||||
}
|
||||
@@ -34,30 +34,30 @@ public class LineEnd extends EditorLinePainter {
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
LineInfo lineInfo = LineInfo.of(file, project, lineNumber);
|
||||
String doc = lineDocSkipHave(lineInfo);
|
||||
@Nullable LineInfo lineInfo = LineInfo.of(file, project, lineNumber);
|
||||
@Nullable String doc = lineDocSkipHave(lineInfo);
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
TextAttributes textAttr = file.getFileType().equals(JsonFileType.INSTANCE)
|
||||
@NotNull TextAttributes textAttr = file.getFileType().equals(JsonFileType.INSTANCE)
|
||||
|| file.getFileType().equals(Json5FileType.INSTANCE)
|
||||
? settings.lineEndJsonTextAttr
|
||||
: settings.lineEndTextAttr;
|
||||
LineExtensionInfo info = new LineExtensionInfo(settings.lineEndPrefix + doc, textAttr);
|
||||
@NotNull LineExtensionInfo info = new LineExtensionInfo(settings.lineEndPrefix + doc, textAttr);
|
||||
return Collections.singletonList(info);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String textWithDoc(@NotNull FileInfo fileInfo, int startLine, int endLine) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
for (int i = startLine; i <= endLine; i++) {
|
||||
LineInfo lineInfo = LineInfo.of(fileInfo, i);
|
||||
@Nullable LineInfo lineInfo = LineInfo.of(fileInfo, i);
|
||||
if (lineInfo == null) {
|
||||
sb.append("\n");
|
||||
continue;
|
||||
}
|
||||
sb.append(lineInfo.text);
|
||||
String doc = lineDocSkipHave(lineInfo);
|
||||
@Nullable String doc = lineDocSkipHave(lineInfo);
|
||||
if (doc != null) {
|
||||
sb.append(lineInfo.appSettings.lineEndPrefix).append(doc);
|
||||
}
|
||||
@@ -70,11 +70,11 @@ public class LineEnd extends EditorLinePainter {
|
||||
}
|
||||
|
||||
private static @Nullable String lineDocSkipHave(@Nullable LineInfo lineInfo) {
|
||||
String doc = lineDoc(lineInfo);
|
||||
@Nullable String doc = lineDoc(lineInfo);
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
String trimDoc = doc.trim();
|
||||
@NotNull String trimDoc = doc.trim();
|
||||
if (lineInfo.text.trim().endsWith(trimDoc)) {
|
||||
return null;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class LineEnd extends EditorLinePainter {
|
||||
return null;
|
||||
}
|
||||
// override some text
|
||||
String doc = LineExt.doc(lineInfo);
|
||||
@Nullable String doc = LineExt.doc(lineInfo);
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileVisitor;
|
||||
import io.github.linwancen.plugin.show.bean.FileInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* on ProjectViewPopupMenu
|
||||
@@ -21,22 +22,22 @@ public class LineEndAdd extends DumbAwareAction {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent event) {
|
||||
Project project = event.getProject();
|
||||
@Nullable Project project = event.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
|
||||
@Nullable VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
ListPopup confirmation = JBPopupFactory.getInstance().createConfirmation(
|
||||
@NotNull ListPopup confirmation = JBPopupFactory.getInstance().createConfirmation(
|
||||
"Add Line Comment?", "Add and replace files!", "Don't add.",
|
||||
() -> ApplicationManager.getApplication().runReadAction(() -> addDocAll(project, files)), 2);
|
||||
confirmation.showInFocusCenter();
|
||||
}
|
||||
|
||||
private void addDocAll(@NotNull Project project, @NotNull VirtualFile[] files) {
|
||||
for (VirtualFile file : files) {
|
||||
for (@NotNull VirtualFile file : files) {
|
||||
VfsUtilCore.visitChildrenRecursively(file, new VirtualFileVisitor<Void>() {
|
||||
@Override
|
||||
public boolean visitFile(@NotNull VirtualFile file) {
|
||||
@@ -50,13 +51,13 @@ public class LineEndAdd extends DumbAwareAction {
|
||||
}
|
||||
|
||||
private void addDoc(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
FileInfo fileInfo = FileInfo.of(file, project);
|
||||
@Nullable FileInfo fileInfo = FileInfo.of(file, project);
|
||||
if (fileInfo == null) {
|
||||
return;
|
||||
}
|
||||
int startLine = 0;
|
||||
int endLine = fileInfo.document.getLineCount() - 1;
|
||||
String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine);
|
||||
@NotNull String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine);
|
||||
WriteCommandAction.runWriteCommandAction(project, () ->
|
||||
fileInfo.document.replaceString(0, fileInfo.document.getTextLength() - 1, textWithDoc)
|
||||
);
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.openapi.ide.CopyPasteManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import io.github.linwancen.plugin.show.bean.FileInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
|
||||
@@ -23,16 +24,16 @@ public class LineEndCopy extends DumbAwareAction {
|
||||
}
|
||||
|
||||
private void copyWithDoc(@NotNull AnActionEvent event) {
|
||||
FileInfo fileInfo = FileInfo.of(event);
|
||||
@Nullable FileInfo fileInfo = FileInfo.of(event);
|
||||
if (fileInfo == null) {
|
||||
return;
|
||||
}
|
||||
int startLine = 0;
|
||||
int endLine = fileInfo.document.getLineCount() - 1;
|
||||
// if select
|
||||
Editor editor = event.getData(CommonDataKeys.EDITOR);
|
||||
@Nullable Editor editor = event.getData(CommonDataKeys.EDITOR);
|
||||
if (editor != null) {
|
||||
Caret primaryCaret = editor.getCaretModel().getPrimaryCaret();
|
||||
@NotNull Caret primaryCaret = editor.getCaretModel().getPrimaryCaret();
|
||||
int start = primaryCaret.getSelectionStart();
|
||||
int end = primaryCaret.getSelectionEnd();
|
||||
try {
|
||||
@@ -42,8 +43,8 @@ public class LineEndCopy extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
}
|
||||
String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine);
|
||||
StringSelection content = new StringSelection(textWithDoc);
|
||||
@NotNull String textWithDoc = LineEnd.textWithDoc(fileInfo, startLine, endLine);
|
||||
@NotNull StringSelection content = new StringSelection(textWithDoc);
|
||||
CopyPasteManager.getInstance().setContents(content);
|
||||
}
|
||||
}
|
||||
@@ -25,11 +25,11 @@ import java.util.List;
|
||||
public class Tree implements ProjectViewNodeDecorator {
|
||||
|
||||
@Override
|
||||
public void decorate(ProjectViewNode node, PresentationData data) {
|
||||
public void decorate(@NotNull ProjectViewNode node, @NotNull PresentationData data) {
|
||||
if (!AppSettingsState.getInstance().showTreeComment) {
|
||||
return;
|
||||
}
|
||||
Project project = node.getProject();
|
||||
@Nullable Project project = node.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
@@ -37,11 +37,11 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
return;
|
||||
}
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
String doc = treeDoc(node, project);
|
||||
@Nullable String doc = treeDoc(node, project);
|
||||
if (doc == null) {
|
||||
return;
|
||||
}
|
||||
List<ColoredFragment> coloredText = data.getColoredText();
|
||||
@NotNull List<ColoredFragment> coloredText = data.getColoredText();
|
||||
if (coloredText.isEmpty()) {
|
||||
data.addText(data.getPresentableText(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
}
|
||||
@@ -50,23 +50,23 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String treeDoc(ProjectViewNode<?> node, @NotNull Project project) {
|
||||
String doc = TreeExt.doc(node);
|
||||
private String treeDoc(@NotNull ProjectViewNode<?> node, @NotNull Project project) {
|
||||
@Nullable String doc = TreeExt.doc(node);
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE);
|
||||
@NotNull SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE);
|
||||
Object value = node.getValue();
|
||||
if (value instanceof PsiElement) {
|
||||
PsiElement psiElement = (PsiElement) value;
|
||||
String docPrint = BaseLangDoc.resolveDoc(settingsInfo, psiElement);
|
||||
@NotNull PsiElement psiElement = (PsiElement) value;
|
||||
@Nullable String docPrint = BaseLangDoc.resolveDoc(settingsInfo, psiElement);
|
||||
if (docPrint != null) {
|
||||
return docPrint;
|
||||
}
|
||||
}
|
||||
Collection<BaseLangDoc> langDocs = BaseLangDoc.LANG_DOC_MAP.values();
|
||||
for (BaseLangDoc langDoc : langDocs) {
|
||||
String s = langDoc.treeDoc(settingsInfo, node, project);
|
||||
@NotNull Collection<BaseLangDoc> langDocs = BaseLangDoc.LANG_DOC_MAP.values();
|
||||
for (@NotNull BaseLangDoc langDoc : langDocs) {
|
||||
@Nullable String s = langDoc.treeDoc(settingsInfo, node, project);
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -27,30 +27,30 @@ public class FileInfo extends SettingsInfo {
|
||||
this.document = document;
|
||||
}
|
||||
|
||||
public static @Nullable FileInfo of(@NotNull VirtualFile file, @NotNull Project project){
|
||||
Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
public static @Nullable FileInfo of(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
@Nullable Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file);
|
||||
@Nullable FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file);
|
||||
if (viewProvider == null) {
|
||||
return null;
|
||||
}
|
||||
return new FileInfo(file, document, project, viewProvider, FuncEnum.LINE);
|
||||
}
|
||||
|
||||
public static @Nullable FileInfo of(@NotNull AnActionEvent event){
|
||||
PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE);
|
||||
public static @Nullable FileInfo of(@NotNull AnActionEvent event) {
|
||||
@Nullable PsiFile psiFile = event.getData(CommonDataKeys.PSI_FILE);
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
}
|
||||
FileViewProvider viewProvider = psiFile.getViewProvider();
|
||||
Document document = viewProvider.getDocument();
|
||||
@NotNull FileViewProvider viewProvider = psiFile.getViewProvider();
|
||||
@Nullable Document document = viewProvider.getDocument();
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
VirtualFile file = viewProvider.getVirtualFile();
|
||||
Project project = psiFile.getProject();
|
||||
@NotNull VirtualFile file = viewProvider.getVirtualFile();
|
||||
@NotNull Project project = psiFile.getProject();
|
||||
return new FileInfo(file, document, project, viewProvider, FuncEnum.LINE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package io.github.linwancen.plugin.show.bean;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public enum FuncEnum {
|
||||
/** tree: project view tree */
|
||||
/** tree: project view tree */
|
||||
TREE("tree", "project view tree"),
|
||||
/** line: code line end */
|
||||
LINE("line", "code line end"),
|
||||
@@ -17,16 +19,18 @@ public enum FuncEnum {
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return code + '-' + desc;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static final LinkedHashMap<String, FuncEnum> map;
|
||||
|
||||
static {
|
||||
map = new LinkedHashMap<>();
|
||||
for (FuncEnum value : values()) {
|
||||
for (@NotNull FuncEnum value : values()) {
|
||||
map.put(value.code, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class LineInfo extends FileInfo {
|
||||
}
|
||||
|
||||
public static @Nullable LineInfo of(@NotNull VirtualFile file, @NotNull Project project, int lineNumber) {
|
||||
FileInfo fileInfo = of(file, project);
|
||||
@Nullable FileInfo fileInfo = of(file, project);
|
||||
if (fileInfo == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class LineInfo extends FileInfo {
|
||||
if (startOffset == endOffset) {
|
||||
return null;
|
||||
}
|
||||
String text = fileInfo.document.getText(new TextRange(startOffset, endOffset));
|
||||
@NotNull String text = fileInfo.document.getText(new TextRange(startOffset, endOffset));
|
||||
return new LineInfo(fileInfo, text, lineNumber, startOffset, endOffset);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
||||
@@ -16,11 +16,12 @@ public class SettingsInfo {
|
||||
this.projectSettings = ProjectSettingsState.getInstance(project);
|
||||
}
|
||||
|
||||
public static @NotNull SettingsInfo of(@NotNull Project project, FuncEnum funcEnum) {
|
||||
public static @NotNull SettingsInfo of(@NotNull Project project, @NotNull FuncEnum funcEnum) {
|
||||
return new SettingsInfo(project, funcEnum);
|
||||
}
|
||||
|
||||
/** treeTags/lineTags */
|
||||
@NotNull
|
||||
public String[] tagNames() {
|
||||
return funcEnum == FuncEnum.TREE
|
||||
? appSettings.treeTags
|
||||
|
||||
@@ -13,7 +13,7 @@ class GetFromDocMap {
|
||||
|
||||
@Nullable
|
||||
static String get(@NotNull Map<String, Map<String, List<String>>> docMap, @NotNull String... words) {
|
||||
List<String> keywordDoc = list(docMap, words);
|
||||
@NotNull List<String> keywordDoc = list(docMap, words);
|
||||
if (keywordDoc.size() >= 2) {
|
||||
return keywordDoc.get(1);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class GetFromDocMap {
|
||||
|
||||
@NotNull
|
||||
private static List<String> list(@NotNull Map<String, Map<String, List<String>>> docMap, @NotNull String... words) {
|
||||
for (Map.Entry<String, Map<String, List<String>>> entry : docMap.entrySet()) {
|
||||
for (@NotNull Map.Entry<String, Map<String, List<String>>> entry : docMap.entrySet()) {
|
||||
Map<String, List<String>> map = entry.getValue();
|
||||
for (String word : words) {
|
||||
List<String> wordDoc = map.get(word);
|
||||
|
||||
@@ -16,8 +16,8 @@ public class LineExt {
|
||||
|
||||
public static @Nullable String doc(@NotNull LineInfo lineInfo) {
|
||||
int i = lineInfo.text.indexOf(lineInfo.appSettings.lineEndPrefix);
|
||||
String code = i <= 0 ? lineInfo.text : lineInfo.text.substring(0, i);
|
||||
String extDoc = LineExt.extDoc(lineInfo, code);
|
||||
@NotNull String code = i <= 0 ? lineInfo.text : lineInfo.text.substring(0, i);
|
||||
@Nullable String extDoc = LineExt.extDoc(lineInfo, code);
|
||||
if (extDoc == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -28,20 +28,21 @@ public class LineExt {
|
||||
return extDoc;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String extDoc(@NotNull LineInfo lineInfo, @NotNull String code) {
|
||||
String path = lineInfo.file.getPath();
|
||||
String name = lineInfo.file.getName();
|
||||
String ext = lineInfo.file.getExtension();
|
||||
Map<String, Map<String, List<String>>> keyMap = ConfCache.keyMap(path, name, ext);
|
||||
@NotNull String path = lineInfo.file.getPath();
|
||||
@NotNull String name = lineInfo.file.getName();
|
||||
@Nullable String ext = lineInfo.file.getExtension();
|
||||
@NotNull Map<String, Map<String, List<String>>> keyMap = ConfCache.keyMap(path, name, ext);
|
||||
if (keyMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
Pattern pattern = ConfCache.pattern(lineInfo.project, keyMap, path);
|
||||
@Nullable Pattern pattern = ConfCache.pattern(lineInfo.project, keyMap, path);
|
||||
if (pattern == null || pattern.pattern().length() == 0) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Map<String, List<String>>> docMap = ConfCache.docMap(path, name, ext);
|
||||
Map<String, Map<String, List<String>>> treeMap = ConfCache.treeMap(path, name, ext);
|
||||
@NotNull Map<String, Map<String, List<String>>> docMap = ConfCache.docMap(path, name, ext);
|
||||
@NotNull Map<String, Map<String, List<String>>> treeMap = ConfCache.treeMap(path, name, ext);
|
||||
if (docMap.isEmpty() && treeMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
@@ -49,7 +50,7 @@ public class LineExt {
|
||||
code = cblNotAndOr(code);
|
||||
}
|
||||
String[] words = pattern.split(code);
|
||||
Matcher matcher = pattern.matcher(code);
|
||||
@NotNull Matcher matcher = pattern.matcher(code);
|
||||
return extDoc(keyMap, matcher, docMap, words, treeMap);
|
||||
}
|
||||
|
||||
@@ -57,12 +58,12 @@ public class LineExt {
|
||||
private static final Pattern AND_OR_PATTERN = Pattern.compile("(AND|OR) ?'");
|
||||
|
||||
@NotNull
|
||||
private static String cblNotAndOr(String text) {
|
||||
private static String cblNotAndOr(@NotNull String text) {
|
||||
// maybe faster than regexp
|
||||
if (!text.contains("=")) {
|
||||
return text;
|
||||
}
|
||||
Matcher matcher = DICT_PATTERN.matcher(text);
|
||||
@NotNull Matcher matcher = DICT_PATTERN.matcher(text);
|
||||
if (!matcher.find()) {
|
||||
return text;
|
||||
}
|
||||
@@ -81,13 +82,13 @@ public class LineExt {
|
||||
@NotNull Map<String, Map<String, List<String>>> treeMap) {
|
||||
boolean haveDoc = false;
|
||||
boolean haveKey = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : words) {
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
for (@NotNull String s : words) {
|
||||
haveDoc |= appendDoc(sb, s, docMap, treeMap);
|
||||
haveKey = appendKeyDoc(sb, matcher, keyMap);
|
||||
}
|
||||
while (haveKey) {
|
||||
haveKey = appendKeyDoc(sb, matcher, keyMap);
|
||||
haveKey = appendKeyDoc(sb, matcher, keyMap);
|
||||
}
|
||||
if (!haveDoc) {
|
||||
return null;
|
||||
@@ -102,12 +103,12 @@ public class LineExt {
|
||||
if (word.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
String wordDoc = GetFromDocMap.get(docMap, word);
|
||||
@Nullable String wordDoc = GetFromDocMap.get(docMap, word);
|
||||
if (wordDoc != null) {
|
||||
sb.append(wordDoc);
|
||||
return true;
|
||||
}
|
||||
String treeDoc = GetFromDocMap.get(treeMap, word);
|
||||
@Nullable String treeDoc = GetFromDocMap.get(treeMap, word);
|
||||
if (treeDoc != null) {
|
||||
sb.append(treeDoc);
|
||||
return true;
|
||||
@@ -118,14 +119,14 @@ public class LineExt {
|
||||
}
|
||||
|
||||
private static boolean appendKeyDoc(@NotNull StringBuilder sb,
|
||||
@NotNull Matcher matcher,
|
||||
@NotNull Map<String, Map<String, List<String>>> keyMap) {
|
||||
@NotNull Matcher matcher,
|
||||
@NotNull Map<String, Map<String, List<String>>> keyMap) {
|
||||
if (!matcher.find()) {
|
||||
return false;
|
||||
}
|
||||
String keyword = matcher.group();
|
||||
// "" if no doc
|
||||
String keyDoc = GetFromDocMap.get(keyMap, keyword);
|
||||
@Nullable String keyDoc = GetFromDocMap.get(keyMap, keyword);
|
||||
if (keyDoc != null) {
|
||||
sb.append(" ").append(keyDoc);
|
||||
}
|
||||
|
||||
@@ -13,21 +13,23 @@ public class TreeExt {
|
||||
|
||||
private TreeExt() {}
|
||||
|
||||
public static @Nullable String doc(ProjectViewNode<?> node) {
|
||||
VirtualFile file = node.getVirtualFile();
|
||||
public static @Nullable String doc(@NotNull ProjectViewNode<?> node) {
|
||||
@Nullable VirtualFile file = node.getVirtualFile();
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
return TreeExt.extDoc(file);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String extDoc(@NotNull VirtualFile file) {
|
||||
Map<String, Map<String, List<String>>> docMap = ConfCache.treeMap(file.getPath(), file.getName(), file.getPath());
|
||||
String[] words = {
|
||||
@NotNull Map<String, Map<String, List<String>>> docMap = ConfCache.treeMap(
|
||||
file.getPath(), file.getName(), file.getPath());
|
||||
@NotNull String[] words = {
|
||||
file.getName(),
|
||||
file.getNameWithoutExtension(),
|
||||
};
|
||||
String extDoc = GetFromDocMap.get(docMap, words);
|
||||
@Nullable String extDoc = GetFromDocMap.get(docMap, words);
|
||||
if (extDoc == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ConfCache {
|
||||
TREE_CACHE.clear();
|
||||
}
|
||||
|
||||
static void remove(@NotNull VirtualFile file, String name) {
|
||||
static void remove(@NotNull VirtualFile file, @Nullable String name) {
|
||||
if (name != null) {
|
||||
int i = name.lastIndexOf('.');
|
||||
name = name.substring(0, i);
|
||||
@@ -93,7 +93,7 @@ public class ConfCache {
|
||||
}
|
||||
|
||||
static void copy(@NotNull VirtualFile file, @NotNull VirtualFile newFile) {
|
||||
String name = file.getNameWithoutExtension();
|
||||
@NotNull String name = file.getNameWithoutExtension();
|
||||
if (name.endsWith(KEY_MID_EXT)) {
|
||||
copyCache(file, newFile, KEY_CACHE);
|
||||
} else if (name.endsWith(DOC_MID_EXT)) {
|
||||
@@ -117,9 +117,9 @@ public class ConfCache {
|
||||
static void loadAll(@NotNull Project project) {
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(() ->
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project, EXT);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (VirtualFile file : files) {
|
||||
@NotNull Collection<VirtualFile> files = FilenameIndex.getAllFilesByExt(project, EXT);
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
for (@NotNull VirtualFile file : files) {
|
||||
load(project, file);
|
||||
sb.append(file.getName()).append("\n");
|
||||
}
|
||||
@@ -139,16 +139,16 @@ public class ConfCache {
|
||||
if (!ConfCache.EXT.equals(file.getExtension())) {
|
||||
return;
|
||||
}
|
||||
Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
@Nullable Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
if (document == null) {
|
||||
return;
|
||||
}
|
||||
String text = document.getText();
|
||||
String name = file.getNameWithoutExtension();
|
||||
@NotNull String text = document.getText();
|
||||
@NotNull String name = file.getNameWithoutExtension();
|
||||
// this pattern would skip empty line
|
||||
String[] lines = LINE_PATTERN.split(text);
|
||||
if (name.endsWith(KEY_MID_EXT)) {
|
||||
String matchName = name.substring(0, name.length() - KEY_MID_EXT.length());
|
||||
@NotNull String matchName = name.substring(0, name.length() - KEY_MID_EXT.length());
|
||||
int i = matchName.lastIndexOf(".");
|
||||
if (i > 0) {
|
||||
EXT_IN_KEY_CACHE.add(matchName.substring(i + 1));
|
||||
|
||||
@@ -32,13 +32,13 @@ class ConfCacheGetUtils {
|
||||
static <T> TreeMap<String, T> filterPathNameExt(@NotNull String confMidExt,
|
||||
@NotNull Map<VirtualFile, T> cache,
|
||||
@NotNull String path, @NotNull String name, @Nullable String ext) {
|
||||
TreeMap<String, T> map = new TreeMap<>();
|
||||
@NotNull TreeMap<String, T> map = new TreeMap<>();
|
||||
int max = path.length();
|
||||
int length = String.valueOf(max).length();
|
||||
for (Map.Entry<VirtualFile, T> entry : cache.entrySet()) {
|
||||
for (@NotNull Map.Entry<VirtualFile, T> entry : cache.entrySet()) {
|
||||
VirtualFile confFile = entry.getKey();
|
||||
String confName = confFile.getNameWithoutExtension();
|
||||
String confPath = confFile.getPath();
|
||||
@NotNull String confName = confFile.getNameWithoutExtension();
|
||||
@NotNull String confPath = confFile.getPath();
|
||||
int level = level(path, confPath);
|
||||
if (level == 0) {
|
||||
continue;
|
||||
@@ -76,12 +76,12 @@ class ConfCacheGetUtils {
|
||||
static <T> TreeMap<String, T> filterPath(@SuppressWarnings("SameParameterValue")
|
||||
@NotNull Map<VirtualFile, T> cache,
|
||||
@NotNull String path, String name, String ext) {
|
||||
TreeMap<String, T> map = new TreeMap<>();
|
||||
@NotNull TreeMap<String, T> map = new TreeMap<>();
|
||||
int max = path.length();
|
||||
int length = String.valueOf(max).length();
|
||||
for (Map.Entry<VirtualFile, T> entry : cache.entrySet()) {
|
||||
for (@NotNull Map.Entry<VirtualFile, T> entry : cache.entrySet()) {
|
||||
VirtualFile confFile = entry.getKey();
|
||||
String confPath = confFile.getPath();
|
||||
@NotNull String confPath = confFile.getPath();
|
||||
int level = level(path, confPath);
|
||||
if (level == 0) {
|
||||
continue;
|
||||
@@ -119,7 +119,7 @@ class ConfCacheGetUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String srcPath(String path) {
|
||||
private static String srcPath(@NotNull String path) {
|
||||
int i = path.indexOf('!');
|
||||
if (i != -1) {
|
||||
return path.substring(i + 1);
|
||||
@@ -131,7 +131,7 @@ class ConfCacheGetUtils {
|
||||
return path;
|
||||
}
|
||||
|
||||
private static boolean match(String path, String confPath) {
|
||||
private static boolean match(@NotNull String path, @NotNull String confPath) {
|
||||
if (confPath.equals(path) || SKIP_PATH.equals(confPath)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ class ConfFactory {
|
||||
@Nullable
|
||||
static Pattern buildPattern(@Nullable Project project, @NotNull String path,
|
||||
@NotNull Map<String, Map<String, List<String>>> map) {
|
||||
Set<String> exclude = new LinkedSet<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map<String, List<String>> keyMap : map.values()) {
|
||||
@NotNull Set<String> exclude = new LinkedSet<>();
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
for (@NotNull Map<String, List<String>> keyMap : map.values()) {
|
||||
// key() is escape
|
||||
for (List<String> list : keyMap.values()) {
|
||||
for (@NotNull List<String> list : keyMap.values()) {
|
||||
String key = list.get(0);
|
||||
if (key.startsWith("?")) {
|
||||
exclude.add(key.substring(1));
|
||||
@@ -45,7 +45,7 @@ class ConfFactory {
|
||||
if (sb.length() > 0) {
|
||||
sb.delete(sb.length() - 1, sb.length());
|
||||
}
|
||||
String regex = sb.toString();
|
||||
@NotNull String regex = sb.toString();
|
||||
Pattern pattern = PATTERN_CACHE.get(regex);
|
||||
if (pattern != null) {
|
||||
return pattern;
|
||||
@@ -54,7 +54,7 @@ class ConfFactory {
|
||||
sb.insert(0, path);
|
||||
sb.insert(0, "\n");
|
||||
try {
|
||||
Pattern compile = Pattern.compile(regex);
|
||||
@NotNull Pattern compile = Pattern.compile(regex);
|
||||
PATTERN_CACHE.put(regex, compile);
|
||||
REGEXP_LOG.createNotification("Ext doc keyword regexp compile success", regex.length() + " chars",
|
||||
sb.toString(), NotificationType.INFORMATION).notify(project);
|
||||
@@ -74,9 +74,9 @@ class ConfFactory {
|
||||
@NotNull
|
||||
static Map<String, List<String>> buildMap(@Nullable Project project, @NotNull String path,
|
||||
@NotNull String[] lines, boolean isKey) {
|
||||
Map<String, List<String>> map = new LinkedHashMap<>();
|
||||
for (String line : lines) {
|
||||
List<String> words = Splitter.on('\t').splitToList(line);
|
||||
@NotNull Map<String, List<String>> map = new LinkedHashMap<>();
|
||||
for (@NotNull String line : lines) {
|
||||
@NotNull List<String> words = Splitter.on('\t').splitToList(line);
|
||||
if (!words.isEmpty()) {
|
||||
String key = words.get(0);
|
||||
if (key.length() == 0) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* call ConfCache.loadFile
|
||||
@@ -12,7 +13,7 @@ public class ConfFileChangeListener implements FileEditorManagerListener {
|
||||
|
||||
@Override
|
||||
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
|
||||
VirtualFile file = event.getOldFile();
|
||||
@Nullable VirtualFile file = event.getOldFile();
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
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 java.util.List;
|
||||
|
||||
@@ -14,18 +15,18 @@ public class ConfFileListener implements BulkFileListener {
|
||||
|
||||
@Override
|
||||
public void after(@NotNull List<? extends VFileEvent> events) {
|
||||
for (VFileEvent event : events) {
|
||||
for (@NotNull VFileEvent event : events) {
|
||||
forEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
private static void forEvent(VFileEvent event) {
|
||||
VirtualFile file = event.getFile();
|
||||
private static void forEvent(@NotNull VFileEvent event) {
|
||||
@Nullable VirtualFile file = event.getFile();
|
||||
if (file == null) {
|
||||
return;
|
||||
}
|
||||
if (event instanceof VFilePropertyChangeEvent) {
|
||||
VFilePropertyChangeEvent changeEvent = (VFilePropertyChangeEvent) event;
|
||||
@NotNull VFilePropertyChangeEvent changeEvent = (VFilePropertyChangeEvent) event;
|
||||
if ("name".equals(changeEvent.getPropertyName())) {
|
||||
String oldName = changeEvent.getOldValue().toString();
|
||||
if (oldName.endsWith(ConfCache.EXT)) {
|
||||
@@ -45,8 +46,8 @@ public class ConfFileListener implements BulkFileListener {
|
||||
return;
|
||||
}
|
||||
if (event instanceof VFileCopyEvent) {
|
||||
VFileCopyEvent copyEvent = (VFileCopyEvent) event;
|
||||
VirtualFile newFile = copyEvent.findCreatedFile();
|
||||
@NotNull VFileCopyEvent copyEvent = (VFileCopyEvent) event;
|
||||
@Nullable VirtualFile newFile = copyEvent.findCreatedFile();
|
||||
if (newFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* call ConfCache.loadAll
|
||||
@@ -11,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class ReloadExtDocAction extends AnAction {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
@Nullable Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@ import java.util.List;
|
||||
|
||||
public class JsonRef<T extends PsiElement> extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference {
|
||||
|
||||
@NotNull
|
||||
final T psiField;
|
||||
@NotNull
|
||||
final List<T> tips;
|
||||
|
||||
public JsonRef(@NotNull PsiElement element, @NotNull T psiField, @NotNull List<T> tips) {
|
||||
|
||||
@@ -31,7 +31,7 @@ public class GoLangDoc extends BaseLangDoc {
|
||||
|
||||
@Override
|
||||
public @Nullable <T extends SettingsInfo> String resolveDocRaw(@NotNull T lineInfo, @NotNull PsiElement resolve) {
|
||||
List<PsiComment> comments = GoDocumentationProvider.getCommentsForElement(resolve);
|
||||
@NotNull List<PsiComment> comments = GoDocumentationProvider.getCommentsForElement(resolve);
|
||||
return GoDocumentationProvider.getCommentText(comments, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,12 @@ public class JsLangDoc extends BaseLangDoc {
|
||||
|
||||
@Override
|
||||
public @Nullable <T extends SettingsInfo> String resolveDocRaw(@NotNull T lineInfo, @NotNull PsiElement resolve) {
|
||||
PsiComment psiComment = JSDocumentationUtils.findOwnDocCommentForImplicitElement(resolve);
|
||||
@Nullable PsiComment psiComment = JSDocumentationUtils.findOwnDocCommentForImplicitElement(resolve);
|
||||
if (psiComment == null) {
|
||||
return null;
|
||||
}
|
||||
String text = psiComment.getText();
|
||||
if (text!=null) {
|
||||
if (text != null) {
|
||||
return text;
|
||||
}
|
||||
if (!lineInfo.appSettings.jsDoc) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class JsonLangDoc extends BaseLangDoc {
|
||||
|
||||
@Override
|
||||
public @Nullable String findRefDoc(@NotNull LineInfo lineInfo, @NotNull PsiElement element) {
|
||||
PsiElement start = lineInfo.viewProvider.findElementAt(lineInfo.startOffset);
|
||||
@Nullable PsiElement start = lineInfo.viewProvider.findElementAt(lineInfo.startOffset);
|
||||
if (start == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -41,10 +41,10 @@ public class JsonLangDoc extends BaseLangDoc {
|
||||
if (!(ref instanceof JsonProperty)) {
|
||||
return null;
|
||||
}
|
||||
JsonProperty jsonProperty = (JsonProperty) ref;
|
||||
PsiReference[] references = jsonProperty.getNameElement().getReferences();
|
||||
for (PsiReference reference : references) {
|
||||
PsiElement resolve = null;
|
||||
@NotNull JsonProperty jsonProperty = (JsonProperty) ref;
|
||||
@NotNull PsiReference[] references = jsonProperty.getNameElement().getReferences();
|
||||
for (@NotNull PsiReference reference : references) {
|
||||
@Nullable PsiElement resolve = null;
|
||||
try {
|
||||
resolve = reference.resolve();
|
||||
} catch (Throwable ignore) {
|
||||
@@ -53,7 +53,7 @@ public class JsonLangDoc extends BaseLangDoc {
|
||||
if (resolve == null) {
|
||||
continue;
|
||||
}
|
||||
String doc = BaseLangDoc.resolveDoc(lineInfo, resolve);
|
||||
@Nullable String doc = BaseLangDoc.resolveDoc(lineInfo, resolve);
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ public class SqlLangDoc extends BaseLangDoc {
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
for (DbElement dbElement : relatedDbElements) {
|
||||
String refDoc = dbElement.getComment();
|
||||
for (@NotNull DbElement dbElement : relatedDbElements) {
|
||||
@Nullable String refDoc = dbElement.getComment();
|
||||
if (refDoc != null && !DocSkip.skipDoc(lineInfo.appSettings, lineInfo.projectSettings, refDoc)) {
|
||||
return refDoc;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
}
|
||||
|
||||
public static @Nullable String langDoc(@NotNull LineInfo lineInfo) {
|
||||
PsiElement element = lineInfo.viewProvider.findElementAt(lineInfo.endOffset);
|
||||
@Nullable PsiElement element = lineInfo.viewProvider.findElementAt(lineInfo.endOffset);
|
||||
if (element == null) {
|
||||
// file end
|
||||
element = lineInfo.viewProvider.findElementAt(lineInfo.endOffset - 1);
|
||||
@@ -49,7 +49,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Language language = PsiElementTo.language(element);
|
||||
@NotNull Language language = PsiElementTo.language(element);
|
||||
BaseLangDoc lineEnd = LANG_DOC_MAP.get(language.getID());
|
||||
if (lineEnd != null && lineEnd.show(lineInfo)) {
|
||||
return lineEnd.findRefDoc(lineInfo, element);
|
||||
@@ -64,15 +64,15 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
*/
|
||||
@Nullable
|
||||
public String findRefDoc(@NotNull LineInfo lineInfo, @NotNull PsiElement element) {
|
||||
Class<? extends PsiElement> refClass = getRefClass();
|
||||
@Nullable Class<? extends PsiElement> refClass = getRefClass();
|
||||
if (refClass == null) {
|
||||
return null;
|
||||
}
|
||||
String doc = null;
|
||||
PsiElement refElement = element;
|
||||
@Nullable String doc = null;
|
||||
@Nullable PsiElement refElement = element;
|
||||
while ((refElement = Prev.prevRefChild(lineInfo, refElement, refClass)) != null) {
|
||||
PsiElement parent = refElement.getParent();
|
||||
String filterDoc = refElementDoc(lineInfo, parent);
|
||||
@Nullable String filterDoc = refElementDoc(lineInfo, parent);
|
||||
if (filterDoc != null) {
|
||||
doc = filterDoc;
|
||||
refElement = parent;
|
||||
@@ -90,7 +90,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
String text = refElement.getText();
|
||||
boolean set = text.startsWith("set");
|
||||
PsiElement parent = refElement.getParent();
|
||||
String before = refElementDoc(lineInfo, parent);
|
||||
@Nullable String before = refElementDoc(lineInfo, parent);
|
||||
if (before != null) {
|
||||
doc = mergeDoc(set, lineInfo.appSettings.getToSet, before, doc);
|
||||
}
|
||||
@@ -115,9 +115,10 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
/**
|
||||
* Override like SQL
|
||||
*/
|
||||
@Nullable
|
||||
protected <T extends SettingsInfo> String refElementDoc(@NotNull T lineInfo,
|
||||
@NotNull PsiElement refElement) {
|
||||
String refDoc = refDoc(lineInfo, refElement);
|
||||
@Nullable String refDoc = refDoc(lineInfo, refElement);
|
||||
if (refDoc != null && !DocSkip.skipDoc(lineInfo.appSettings, lineInfo.projectSettings, refDoc)) {
|
||||
return refDoc;
|
||||
}
|
||||
@@ -130,22 +131,23 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
@Nullable
|
||||
protected <T extends SettingsInfo> String refDoc(@NotNull T lineInfo, @NotNull PsiElement ref) {
|
||||
// kotlin ref.getReference() == null but ref.getReferences().length == 2
|
||||
PsiReference[] references = ref.getReferences();
|
||||
@NotNull PsiReference[] references = ref.getReferences();
|
||||
if (references.length < 1) {
|
||||
return null;
|
||||
}
|
||||
for (PsiReference reference : references) {
|
||||
PsiElement resolve;
|
||||
for (@NotNull PsiReference reference : references) {
|
||||
@Nullable PsiElement resolve;
|
||||
try {
|
||||
resolve = reference.resolve();
|
||||
} catch (Throwable e) {
|
||||
// 2021.3: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc.
|
||||
// 2021.3: Slow operations are prohibited on EDT.
|
||||
// See SlowOperations.assertSlowOperationsAreAllowed javadoc.
|
||||
return null;
|
||||
}
|
||||
if (resolve == null) {
|
||||
return null;
|
||||
}
|
||||
String resolveDoc = resolveDoc(lineInfo, resolve);
|
||||
@Nullable String resolveDoc = resolveDoc(lineInfo, resolve);
|
||||
if (resolveDoc != null) {
|
||||
return resolveDoc;
|
||||
}
|
||||
@@ -153,9 +155,10 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static @Nullable <T extends SettingsInfo> String resolveDoc(T settingsInfo, PsiElement psiElement) {
|
||||
public static @Nullable <T extends SettingsInfo> String resolveDoc(@NotNull T settingsInfo,
|
||||
@NotNull PsiElement psiElement) {
|
||||
// support like java <-> kotlin
|
||||
Language language = PsiElementTo.language(psiElement);
|
||||
@NotNull Language language = PsiElementTo.language(psiElement);
|
||||
BaseLangDoc lineEnd = LANG_DOC_MAP.get(language.getID());
|
||||
if (lineEnd == null) {
|
||||
return null;
|
||||
@@ -168,12 +171,12 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
*/
|
||||
@Nullable
|
||||
protected <T extends SettingsInfo> String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) {
|
||||
String s = resolveDocRaw(lineInfo, resolve);
|
||||
@Nullable String s = resolveDocRaw(lineInfo, resolve);
|
||||
if (s == null) {
|
||||
return null;
|
||||
}
|
||||
String cutDoc = DocFilter.cutDoc(s, lineInfo.appSettings, true);
|
||||
String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.appSettings, lineInfo.projectSettings);
|
||||
@NotNull String cutDoc = DocFilter.cutDoc(s, lineInfo.appSettings, true);
|
||||
@NotNull String filterDoc = DocFilter.filterDoc(cutDoc, lineInfo.appSettings, lineInfo.projectSettings);
|
||||
if (filterDoc.trim().length() == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -185,17 +188,18 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
*/
|
||||
@Nullable
|
||||
protected <T extends SettingsInfo> String resolveDocRaw(@NotNull T lineInfo, @NotNull PsiElement resolve) {
|
||||
FileViewProvider viewProvider = PsiElementTo.viewProvider(resolve);
|
||||
@Nullable FileViewProvider viewProvider = PsiElementTo.viewProvider(resolve);
|
||||
if (viewProvider == null) {
|
||||
return null;
|
||||
}
|
||||
String doc = ResolveDoc.fromLineEnd(lineInfo, resolve, viewProvider);
|
||||
@Nullable String doc = ResolveDoc.fromLineEnd(lineInfo, resolve, viewProvider);
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
return ResolveDoc.fromLineUp(lineInfo, resolve, viewProvider, keywords());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<String> keywords() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ public abstract class BaseTagLangDoc<DocElement> extends BaseLangDoc {
|
||||
|
||||
@Override
|
||||
public @Nullable <T extends SettingsInfo> String resolveDocPrint(@NotNull T lineInfo, @NotNull PsiElement resolve) {
|
||||
DocElement docElement = toDocElement(resolve);
|
||||
@Nullable DocElement docElement = toDocElement(resolve);
|
||||
if (docElement == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -22,12 +22,12 @@ public abstract class BaseTagLangDoc<DocElement> extends BaseLangDoc {
|
||||
return null;
|
||||
}
|
||||
// desc
|
||||
String descDoc = descDoc(lineInfo, docElement).trim();
|
||||
String desc = DocFilter.filterDoc(descDoc, lineInfo.appSettings, lineInfo.projectSettings);
|
||||
@NotNull String descDoc = descDoc(lineInfo, docElement).trim();
|
||||
@NotNull String desc = DocFilter.filterDoc(descDoc, lineInfo.appSettings, lineInfo.projectSettings);
|
||||
// tag
|
||||
StringBuilder tagStrBuilder = new StringBuilder();
|
||||
String[] names = lineInfo.tagNames();
|
||||
for (String name : names) {
|
||||
@NotNull StringBuilder tagStrBuilder = new StringBuilder();
|
||||
@NotNull String[] names = lineInfo.tagNames();
|
||||
for (@NotNull String name : names) {
|
||||
appendTag(lineInfo, tagStrBuilder, docElement, name);
|
||||
}
|
||||
if (desc.length() > 0) {
|
||||
@@ -36,7 +36,7 @@ public abstract class BaseTagLangDoc<DocElement> extends BaseLangDoc {
|
||||
}
|
||||
tagStrBuilder.insert(0, desc);
|
||||
}
|
||||
String text = tagStrBuilder.toString().trim();
|
||||
@NotNull String text = tagStrBuilder.toString().trim();
|
||||
if (text.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.github.linwancen.plugin.show.lang.base;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -33,10 +32,10 @@ public class DocFilter {
|
||||
*/
|
||||
@NotNull
|
||||
public static String cutDoc(String text,
|
||||
AppSettingsState appSettings, boolean deletePrefix) {
|
||||
@NotNull AppSettingsState appSettings, boolean deletePrefix) {
|
||||
String[] split = LINE_SEPARATOR_PATTERN.split(text);
|
||||
int lineCount = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
for (String s : split) {
|
||||
if (deletePrefix) {
|
||||
s = DOC_PATTERN.matcher(s).replaceAll("");
|
||||
@@ -64,8 +63,8 @@ public class DocFilter {
|
||||
*/
|
||||
@NotNull
|
||||
public static String filterDoc(@NotNull String text,
|
||||
AppSettingsState appSettings,
|
||||
ProjectSettingsState projectSettings) {
|
||||
@NotNull AppSettingsState appSettings,
|
||||
@NotNull ProjectSettingsState projectSettings) {
|
||||
// docGetEffect first because default false
|
||||
if (projectSettings.docGetEffect && projectSettings.projectFilterEffective) {
|
||||
return filterDoc(text, projectSettings.docGet);
|
||||
@@ -79,7 +78,7 @@ public class DocFilter {
|
||||
@NotNull
|
||||
public static String filterDoc(@NotNull String text, @NotNull Pattern docGet) {
|
||||
// if effect skip check empty
|
||||
Matcher m = docGet.matcher(text);
|
||||
@NotNull Matcher m = docGet.matcher(text);
|
||||
if (m.find()) {
|
||||
return m.group(m.groupCount());
|
||||
}
|
||||
@@ -93,7 +92,7 @@ public class DocFilter {
|
||||
* trim end with space
|
||||
*/
|
||||
public static void addHtml(@NotNull StringBuilder sb, @NotNull String s) {
|
||||
String deleteHtml = HTML_PATTERN.matcher(s).replaceAll("").trim();
|
||||
@NotNull String deleteHtml = HTML_PATTERN.matcher(s).replaceAll("").trim();
|
||||
if (deleteHtml.length() > 0) {
|
||||
sb.append(deleteHtml).append(" ");
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.linwancen.plugin.show.lang.base;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -10,7 +11,8 @@ public class DocSkip {
|
||||
|
||||
private DocSkip() {}
|
||||
|
||||
public static boolean skipSign(AppSettingsState appSettings, ProjectSettingsState projectSettings, String text) {
|
||||
public static boolean skipSign(@NotNull AppSettingsState appSettings,
|
||||
@NotNull ProjectSettingsState projectSettings, String text) {
|
||||
return skipText(text,
|
||||
projectSettings.globalFilterEffective, appSettings.lineInclude, appSettings.lineExclude,
|
||||
projectSettings.projectFilterEffective, projectSettings.lineInclude, projectSettings.lineExclude);
|
||||
@@ -18,7 +20,8 @@ public class DocSkip {
|
||||
|
||||
private static final Pattern NOT_ASCII_PATTERN = Pattern.compile("[^\u0000-\u007f]");
|
||||
|
||||
public static boolean skipDoc(AppSettingsState appSettings, ProjectSettingsState projectSettings, String text) {
|
||||
public static boolean skipDoc(@NotNull AppSettingsState appSettings,
|
||||
@NotNull ProjectSettingsState projectSettings, @NotNull String text) {
|
||||
if (appSettings.skipAscii && !NOT_ASCII_PATTERN.matcher(text).find()) {
|
||||
return true;
|
||||
}
|
||||
@@ -27,9 +30,10 @@ public class DocSkip {
|
||||
projectSettings.projectFilterEffective, projectSettings.docInclude, projectSettings.docExclude);
|
||||
}
|
||||
|
||||
static boolean skipText(String text,
|
||||
boolean appFilterEffective, Pattern appDocInclude, Pattern appDocExclude,
|
||||
boolean projectFilterEffective, Pattern projectDocInclude, Pattern projectDocExclude
|
||||
static boolean skipText(@Nullable String text,
|
||||
boolean appFilterEffective, @NotNull Pattern appDocInclude, @NotNull Pattern appDocExclude,
|
||||
boolean projectFilterEffective, @NotNull Pattern projectDocInclude,
|
||||
@NotNull Pattern projectDocExclude
|
||||
) {
|
||||
if (text == null) {
|
||||
return true;
|
||||
@@ -44,21 +48,21 @@ public class DocSkip {
|
||||
return false;
|
||||
}
|
||||
|
||||
static boolean skipText(@NotNull String text, Pattern include, Pattern exclude) {
|
||||
static boolean skipText(@NotNull String text, @NotNull Pattern include, @NotNull Pattern exclude) {
|
||||
if (exclude(text, exclude)) {
|
||||
return true;
|
||||
}
|
||||
return !include(text, include);
|
||||
}
|
||||
|
||||
static boolean include(@NotNull String text, Pattern include) {
|
||||
static boolean include(@NotNull String text, @NotNull Pattern include) {
|
||||
if (include.pattern().length() == 0) {
|
||||
return true;
|
||||
}
|
||||
return include.matcher(text).find();
|
||||
}
|
||||
|
||||
static boolean exclude(@NotNull String text, Pattern exclude) {
|
||||
static boolean exclude(@NotNull String text, @NotNull Pattern exclude) {
|
||||
if (exclude.pattern().length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class Prev {
|
||||
|
||||
private Prev() {}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement prevRefChild(@NotNull LineInfo lineInfo, @NotNull PsiElement element,
|
||||
@NotNull Class<? extends PsiElement> refClass) {
|
||||
PsiElement prevParent = element.getParent();
|
||||
@@ -22,7 +23,7 @@ public class Prev {
|
||||
if (element.getTextRange().getEndOffset() < lineInfo.startOffset) {
|
||||
return null;
|
||||
}
|
||||
PsiElement parent = refClassParent(element, refClass);
|
||||
@Nullable PsiElement parent = refClassParent(element, refClass);
|
||||
if (parent != null) {
|
||||
// skip b in a.b.c
|
||||
if (prevParent.getTextRange().getEndOffset() < lineInfo.endOffset
|
||||
@@ -42,6 +43,7 @@ public class Prev {
|
||||
"{-~" +
|
||||
"]++");
|
||||
|
||||
@Nullable
|
||||
private static PsiElement refClassParent(@NotNull PsiElement element,
|
||||
@NotNull Class<? extends PsiElement> refClass) {
|
||||
String text = element.getText();
|
||||
@@ -67,7 +69,7 @@ public class Prev {
|
||||
|
||||
public static @Nullable <T extends SettingsInfo> PsiElement prevCompactElement(
|
||||
@SuppressWarnings("unused") @NotNull T lineInfo, @NotNull PsiElement resolve, @NotNull Document document) {
|
||||
PsiElement element = PsiTreeUtil.prevVisibleLeaf(resolve);
|
||||
@Nullable PsiElement element = PsiTreeUtil.prevVisibleLeaf(resolve);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -79,7 +81,7 @@ public class Prev {
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
String replace = spaceText.replace("\n", "");
|
||||
@NotNull String replace = spaceText.replace("\n", "");
|
||||
if (spaceText.length() - replace.length() > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PsiElementTo {
|
||||
|
||||
private PsiElementTo() {}
|
||||
|
||||
public static @Nullable FileViewProvider viewProvider(PsiElement resolve) {
|
||||
public static @Nullable FileViewProvider viewProvider(@NotNull PsiElement resolve) {
|
||||
PsiFile psiFile = resolve.getContainingFile();
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
@@ -26,8 +26,8 @@ public class PsiElementTo {
|
||||
}
|
||||
|
||||
public static @NotNull Language language(@NotNull PsiElement element) {
|
||||
Language lang = element.getLanguage();
|
||||
Language base = lang.getBaseLanguage();
|
||||
@NotNull Language lang = element.getLanguage();
|
||||
@Nullable Language base = lang.getBaseLanguage();
|
||||
if (base != null) {
|
||||
return base;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ResolveDoc {
|
||||
public static <T extends SettingsInfo> String fromLineEnd(@SuppressWarnings("unused") @NotNull T lineInfo,
|
||||
@NotNull PsiElement resolve,
|
||||
@NotNull FileViewProvider resolveViewProvider) {
|
||||
Document document = resolveViewProvider.getDocument();
|
||||
@Nullable Document document = resolveViewProvider.getDocument();
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -33,11 +33,11 @@ public class ResolveDoc {
|
||||
return null;
|
||||
}
|
||||
// end over will return last
|
||||
PsiElement psiElement = resolveViewProvider.findElementAt(resolveEndOffset);
|
||||
@Nullable PsiElement psiElement = resolveViewProvider.findElementAt(resolveEndOffset);
|
||||
if (psiElement == null) {
|
||||
return null;
|
||||
}
|
||||
PsiElement docElement = PsiTreeUtil.prevVisibleLeaf(psiElement);
|
||||
@Nullable PsiElement docElement = PsiTreeUtil.prevVisibleLeaf(psiElement);
|
||||
if (!(docElement instanceof PsiComment)) {
|
||||
return null;
|
||||
}
|
||||
@@ -51,14 +51,14 @@ public class ResolveDoc {
|
||||
|
||||
@Nullable
|
||||
public static <T extends SettingsInfo> String fromLineUp(@NotNull T lineInfo,
|
||||
PsiElement resolve,
|
||||
@NotNull PsiElement resolve,
|
||||
@NotNull FileViewProvider resolveViewProvider,
|
||||
@NotNull List<String> keywords) {
|
||||
Document document = resolveViewProvider.getDocument();
|
||||
@Nullable Document document = resolveViewProvider.getDocument();
|
||||
if (document == null) {
|
||||
return null;
|
||||
}
|
||||
PsiElement psiElement = Prev.prevCompactElement(lineInfo, resolve, document);
|
||||
@Nullable PsiElement psiElement = Prev.prevCompactElement(lineInfo, resolve, document);
|
||||
if (!keywords.isEmpty()) {
|
||||
while (psiElement != null) {
|
||||
String text = psiElement.getText();
|
||||
@@ -69,7 +69,7 @@ public class ResolveDoc {
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
while (psiElement instanceof PsiComment) {
|
||||
String text = psiElement.getText();
|
||||
if (text != null) {
|
||||
|
||||
@@ -38,7 +38,8 @@ public abstract class AbstractSettingsComponent {
|
||||
return lineEndFilter;
|
||||
}
|
||||
|
||||
protected FormBuilder add(FormBuilder formBuilder, JBCheckBox jbCheckBox, JBTextField jbTextField, String tip) {
|
||||
protected FormBuilder add(@NotNull FormBuilder formBuilder, JBCheckBox jbCheckBox,
|
||||
@NotNull JBTextField jbTextField, @NotNull String tip) {
|
||||
return formBuilder.addLabeledComponent(JPanelFactory.of(jbCheckBox, new JBLabel(tip)), jbTextField, 1, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AbstractSettingsConfigurable {
|
||||
|
||||
private AbstractSettingsConfigurable() {}
|
||||
|
||||
static boolean isModified(AbstractSettingsState settings, AbstractSettingsComponent component, boolean modified) {
|
||||
static boolean isModified(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component,
|
||||
boolean modified) {
|
||||
modified |= !component.getLineInclude().equals(settings.getLineInclude());
|
||||
modified |= !component.getLineExclude().equals(settings.getLineExclude());
|
||||
modified |= !component.getDocInclude().equals(settings.getDocInclude());
|
||||
@@ -14,7 +17,7 @@ public class AbstractSettingsConfigurable {
|
||||
return modified;
|
||||
}
|
||||
|
||||
static void apply(AbstractSettingsState settings, AbstractSettingsComponent component) {
|
||||
static void apply(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
|
||||
settings.setLineInclude(component.getLineInclude());
|
||||
settings.setLineExclude(component.getLineExclude());
|
||||
settings.setDocInclude(component.getDocInclude());
|
||||
@@ -23,7 +26,7 @@ public class AbstractSettingsConfigurable {
|
||||
settings.setDocGet(component.getDocGet());
|
||||
}
|
||||
|
||||
static void reset(AbstractSettingsState settings, AbstractSettingsComponent component) {
|
||||
static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
|
||||
component.setLineInclude(settings.getLineInclude());
|
||||
component.setLineExclude(settings.getLineExclude());
|
||||
component.setDocInclude(settings.getDocInclude());
|
||||
|
||||
@@ -1,21 +1,28 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public abstract class AbstractSettingsState {
|
||||
|
||||
@NotNull
|
||||
public transient Pattern lineInclude = Pattern.compile("");
|
||||
@NotNull
|
||||
public transient Pattern lineExclude = Pattern.compile("^java");
|
||||
@NotNull
|
||||
public transient Pattern docInclude = Pattern.compile("");
|
||||
@NotNull
|
||||
public transient Pattern docExclude = Pattern.compile("");
|
||||
public transient boolean docGetEffect = false;
|
||||
@NotNull
|
||||
public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )");
|
||||
|
||||
public String getLineInclude() {
|
||||
return lineInclude.pattern();
|
||||
}
|
||||
|
||||
public void setLineInclude(String lineInclude) {
|
||||
public void setLineInclude(@NotNull String lineInclude) {
|
||||
this.lineInclude = Pattern.compile(lineInclude);
|
||||
}
|
||||
|
||||
@@ -23,7 +30,7 @@ public abstract class AbstractSettingsState {
|
||||
return lineExclude.pattern();
|
||||
}
|
||||
|
||||
public void setLineExclude(String lineExclude) {
|
||||
public void setLineExclude(@NotNull String lineExclude) {
|
||||
this.lineExclude = Pattern.compile(lineExclude);
|
||||
}
|
||||
|
||||
@@ -32,7 +39,7 @@ public abstract class AbstractSettingsState {
|
||||
return docInclude.pattern();
|
||||
}
|
||||
|
||||
public void setDocInclude(String docInclude) {
|
||||
public void setDocInclude(@NotNull String docInclude) {
|
||||
this.docInclude = Pattern.compile(docInclude);
|
||||
}
|
||||
|
||||
@@ -40,7 +47,7 @@ public abstract class AbstractSettingsState {
|
||||
return docExclude.pattern();
|
||||
}
|
||||
|
||||
public void setDocExclude(String docExclude) {
|
||||
public void setDocExclude(@NotNull String docExclude) {
|
||||
this.docExclude = Pattern.compile(docExclude);
|
||||
}
|
||||
|
||||
@@ -49,7 +56,7 @@ public abstract class AbstractSettingsState {
|
||||
return docGet.pattern();
|
||||
}
|
||||
|
||||
public void setDocGet(String docExclude) {
|
||||
public void setDocGet(@NotNull String docExclude) {
|
||||
this.docGet = Pattern.compile(docExclude);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.ui.components.JBLabel;
|
||||
import com.intellij.ui.components.JBTextField;
|
||||
import com.intellij.util.ui.FormBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -69,15 +70,13 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
|
||||
@NotNull
|
||||
protected JPanel lineEndFilterPanel() {
|
||||
JPanel text = JPanelFactory.of(
|
||||
@NotNull JPanel text = JPanelFactory.of(
|
||||
new JBLabel("line count: "), lineEndCount,
|
||||
new JBLabel("text color: "), lineEndColor,
|
||||
new JBLabel("json text color: "), lineEndJsonColor,
|
||||
new JBLabel("prefix: "), lineEndPrefix);
|
||||
FormBuilder formBuilder = FormBuilder.createFormBuilder()
|
||||
// .addComponent(JPanelFactory.of(findElementRightToLeft))
|
||||
.addSeparator()
|
||||
// .addComponent(JPanelFactory.of(fromCall, fromNew, fromRef, inJson, skipAnnotation, skipAscii, skipBlank), 1)
|
||||
.addComponent(JPanelFactory.of(fromNew, fromParam, getToSet, skipAnnotation, skipAscii, skipBlank), 1)
|
||||
.addSeparator()
|
||||
.addComponent(text)
|
||||
@@ -89,6 +88,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return showTreeComment;
|
||||
}
|
||||
@@ -248,6 +248,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
skipBlank.setSelected(newStatus);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Color getLineEndColor() {
|
||||
return lineEndColor.getSelectedColor();
|
||||
}
|
||||
@@ -256,6 +257,7 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
lineEndColor.setSelectedColor(color);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Color getLineEndJsonColor() {
|
||||
return lineEndJsonColor.getSelectedColor();
|
||||
}
|
||||
|
||||
@@ -2,19 +2,24 @@ package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.intellij.openapi.options.Configurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class AppSettingsConfigurable implements Configurable {
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NotNull
|
||||
private AppSettingsComponent mySettingsComponent;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Show Comment Global.";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return mySettingsComponent.getPreferredFocusedComponent();
|
||||
@@ -29,7 +34,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment;
|
||||
modified |= mySettingsComponent.getCompact() != settings.compact;
|
||||
|
||||
@@ -47,8 +52,8 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
modified |= !mySettingsComponent.getLineTags().equals(String.join("|", settings.lineTags));
|
||||
|
||||
modified |= !mySettingsComponent.getLineEndCount().equals(String.valueOf(settings.lineEndCount));
|
||||
modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndTextAttr.getForegroundColor());
|
||||
modified |= !mySettingsComponent.getLineEndJsonColor().equals(settings.lineEndJsonTextAttr.getForegroundColor());
|
||||
modified |= !settings.lineEndTextAttr.getForegroundColor().equals(mySettingsComponent.getLineEndColor());
|
||||
modified |= !settings.lineEndJsonTextAttr.getForegroundColor().equals(mySettingsComponent.getLineEndJsonColor());
|
||||
modified |= !mySettingsComponent.getLineEndPrefix().equals(settings.lineEndPrefix);
|
||||
|
||||
modified |= mySettingsComponent.getGetToSet() != settings.getToSet;
|
||||
@@ -65,7 +70,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
settings.showTreeComment = mySettingsComponent.getShowTreeComment();
|
||||
settings.compact = mySettingsComponent.getCompact();
|
||||
|
||||
@@ -103,7 +108,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
AppSettingsState settings = AppSettingsState.getInstance();
|
||||
@NotNull AppSettingsState settings = AppSettingsState.getInstance();
|
||||
mySettingsComponent.setShowTreeComment(settings.showTreeComment);
|
||||
mySettingsComponent.setCompact(settings.compact);
|
||||
|
||||
@@ -137,6 +142,7 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
//noinspection ConstantConditions
|
||||
mySettingsComponent = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten
|
||||
public boolean showLineEndCommentGo = true;
|
||||
public boolean showLineEndCommentKotlin = true;
|
||||
|
||||
@NotNull
|
||||
public String[] treeTags = {"author"};
|
||||
@NotNull
|
||||
public String[] lineTags = {};
|
||||
|
||||
public final TextAttributes lineEndTextAttr = new TextAttributes(
|
||||
@@ -43,6 +45,7 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten
|
||||
public final TextAttributes lineEndJsonTextAttr = new TextAttributes(new JBColor(Gray._140, Gray._140),
|
||||
null, null, null, Font.ITALIC);
|
||||
|
||||
@NotNull
|
||||
public String lineEndPrefix = " // ";
|
||||
public int lineEndCount = 2;
|
||||
public int lineEndLen = 0;
|
||||
@@ -53,6 +56,7 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten
|
||||
public boolean skipAscii = !"en".equals(Locale.getDefault().getLanguage());
|
||||
public boolean skipBlank = true;
|
||||
|
||||
@NotNull
|
||||
public static AppSettingsState getInstance() {
|
||||
AppSettingsState service = ApplicationManager.getApplication().getService(AppSettingsState.class);
|
||||
if (service == null) {
|
||||
@@ -72,20 +76,22 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten
|
||||
XmlSerializerUtil.copyBean(state, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLineEndColor() {
|
||||
return Integer.toHexString(lineEndTextAttr.getForegroundColor().getRGB()).toUpperCase();
|
||||
}
|
||||
|
||||
public void setLineEndColor(String s) {
|
||||
public void setLineEndColor(@NotNull String s) {
|
||||
int rgb = new BigInteger(s, 16).intValue();
|
||||
lineEndTextAttr.setForegroundColor(new JBColor(new Color(rgb), new Color(rgb)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLineEndJsonColor() {
|
||||
return Integer.toHexString(lineEndJsonTextAttr.getForegroundColor().getRGB()).toUpperCase();
|
||||
}
|
||||
|
||||
public void setLineEndJsonColor(String s) {
|
||||
public void setLineEndJsonColor(@NotNull String s) {
|
||||
int rgb = new BigInteger(s, 16).intValue();
|
||||
lineEndJsonTextAttr.setForegroundColor(new JBColor(new Color(rgb), new Color(rgb)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@@ -7,9 +10,10 @@ public class JPanelFactory {
|
||||
|
||||
private JPanelFactory() {}
|
||||
|
||||
public static JPanel of(Component... components) {
|
||||
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
for (Component component : components) {
|
||||
@NotNull
|
||||
public static JPanel of(@NotNull Component... components) {
|
||||
@NotNull JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
for (@Nullable Component component : components) {
|
||||
if (component != null) {
|
||||
jPanel.add(component);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ public class ProjectSettingsComponent extends AbstractSettingsComponent {
|
||||
return myMainPanel;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return projectFilterEffective;
|
||||
}
|
||||
|
||||
@@ -16,17 +16,21 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ProjectSettingsConfigurable createModuleConfigurable(Module module) {
|
||||
protected ProjectSettingsConfigurable createModuleConfigurable(@NotNull Module module) {
|
||||
return new ProjectSettingsConfigurable(module.getProject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@NotNull
|
||||
private ProjectSettingsComponent mySettingsComponent;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Show Comment Project.";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JComponent getPreferredFocusedComponent() {
|
||||
return mySettingsComponent.getPreferredFocusedComponent();
|
||||
@@ -41,7 +45,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
|
||||
@Override
|
||||
public boolean isModified() {
|
||||
ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
@NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
boolean modified = mySettingsComponent.getGlobalFilterEffective() != settings.globalFilterEffective;
|
||||
modified |= mySettingsComponent.getProjectFilterEffective() != settings.projectFilterEffective;
|
||||
modified = AbstractSettingsConfigurable.isModified(settings, mySettingsComponent, modified);
|
||||
@@ -50,7 +54,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
@NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
settings.globalFilterEffective = mySettingsComponent.getGlobalFilterEffective();
|
||||
settings.projectFilterEffective = mySettingsComponent.getProjectFilterEffective();
|
||||
AbstractSettingsConfigurable.apply(settings, mySettingsComponent);
|
||||
@@ -58,7 +62,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
@NotNull ProjectSettingsState settings = ProjectSettingsState.getInstance(getProject());
|
||||
mySettingsComponent.setGlobalFilterEffective(settings.globalFilterEffective);
|
||||
mySettingsComponent.setProjectFilterEffective(settings.projectFilterEffective);
|
||||
AbstractSettingsConfigurable.reset(settings, mySettingsComponent);
|
||||
@@ -66,6 +70,7 @@ public class ProjectSettingsConfigurable extends ModuleAwareProjectConfigurable<
|
||||
|
||||
@Override
|
||||
public void disposeUIResources() {
|
||||
//noinspection ConstantConditions
|
||||
mySettingsComponent = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,11 +12,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
name = "io.github.linwancen.plugin.show.settings.ProjectSettingsState",
|
||||
storages = @Storage("ShowCommentProject.xml")
|
||||
)
|
||||
public class ProjectSettingsState extends AbstractSettingsState implements PersistentStateComponent<ProjectSettingsState> {
|
||||
public class ProjectSettingsState extends AbstractSettingsState implements PersistentStateComponent<ProjectSettingsState> {
|
||||
|
||||
public boolean globalFilterEffective = true;
|
||||
public boolean projectFilterEffective = false;
|
||||
|
||||
@NotNull
|
||||
public static ProjectSettingsState getInstance(@NotNull Project project) {
|
||||
ProjectSettingsState service = project.getService(ProjectSettingsState.class);
|
||||
if (service == null) {
|
||||
|
||||
Reference in New Issue
Block a user