2.12 Markdown and Asciidoc | 文件内容正则注释
This commit is contained in:
@@ -112,6 +112,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.12 Add project-view-tree support Markdown and Asciidoc
|
||||
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
|
||||
<li>2.10 Add line-end-comment not doc comment
|
||||
<li>2.09 Add line-end-comment support Python doc strings
|
||||
@@ -152,6 +153,7 @@ Show doc comment at the Project view Tree, line End, json, other
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
|
||||
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
|
||||
<li>2.10 增加 行末注释 非文档注释
|
||||
<li>2.09 增加 行末注释 支持 Python 文档字符串
|
||||
|
||||
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'io.github.linwancen'
|
||||
version '2.11.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
version '2.12.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -87,6 +87,7 @@ patchPluginXml {
|
||||
changeNotes = """
|
||||
<h2>English Change Notes:</h2>
|
||||
<ul>
|
||||
<li>2.12 Add project-view-tree support Markdown and Asciidoc
|
||||
<li>2.11 Add project-view-tree description from pom.xml and build.gradle
|
||||
<li>2.10 Add line-end-comment not doc comment
|
||||
<li>2.09 Add line-end-comment support Python doc strings
|
||||
@@ -127,6 +128,7 @@ patchPluginXml {
|
||||
|
||||
<h2>中文更新说明:</h2>
|
||||
<ul>
|
||||
<li>2.12 增加 文件树注释 支持 Markdown and Asciidoc
|
||||
<li>2.11 增加 文件树注释 模块描述 来自 pom.xml 和 build.gradle
|
||||
<li>2.10 增加 行末注释 非文档注释
|
||||
<li>2.09 增加 行末注释 支持 Python 文档字符串
|
||||
|
||||
@@ -16,7 +16,7 @@ import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.ext.TreeExt;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import io.github.linwancen.plugin.show.tree.ProjectDoc;
|
||||
import io.github.linwancen.plugin.show.tree.RelFileDoc;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@@ -49,7 +49,7 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
if (DumbService.isDumb(project)) {
|
||||
return;
|
||||
}
|
||||
DumbService.getInstance(project).smartInvokeLater(() ->
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(() ->
|
||||
ApplicationManager.getApplication().runReadAction(() -> {
|
||||
@Nullable String doc = treeDoc(node, project);
|
||||
if (doc == null) {
|
||||
@@ -59,13 +59,7 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
if (coloredText.isEmpty()) {
|
||||
data.addText(data.getPresentableText(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
|
||||
}
|
||||
@NotNull String text = " " + doc;
|
||||
for (@NotNull ColoredFragment fragment : coloredText) {
|
||||
if (text.equals(fragment.getText())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
data.addText(text, SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
data.addText(" " + doc, SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -76,9 +70,9 @@ public class Tree implements ProjectViewNodeDecorator {
|
||||
return doc;
|
||||
}
|
||||
@NotNull SettingsInfo settingsInfo = SettingsInfo.of(project, FuncEnum.TREE);
|
||||
@Nullable String projectDoc = ProjectDoc.projectDoc(node, settingsInfo);
|
||||
if (projectDoc != null) {
|
||||
return projectDoc;
|
||||
@Nullable String relFileDoc = RelFileDoc.relFileDoc(node, settingsInfo);
|
||||
if (relFileDoc != null) {
|
||||
return relFileDoc;
|
||||
}
|
||||
Object value = node.getValue();
|
||||
if (value instanceof PsiElement) {
|
||||
|
||||
@@ -24,8 +24,10 @@ public abstract class AbstractSettingsComponent {
|
||||
|
||||
private final JBCheckBox docGetEffect = new JBCheckBox("");
|
||||
private final JBTextField docGet = new JBTextField();
|
||||
private final JBCheckBox projectDocEffect = new JBCheckBox("");
|
||||
private final JBTextArea projectDoc = new JBTextArea();
|
||||
private final JBCheckBox dirDocEffect = new JBCheckBox("");
|
||||
private final JBTextArea dirDoc = new JBTextArea();
|
||||
private final JBCheckBox fileDocEffect = new JBCheckBox("");
|
||||
private final JBTextArea fileDoc = new JBTextArea();
|
||||
|
||||
@NotNull
|
||||
protected JPanel commonPanel() {
|
||||
@@ -57,9 +59,12 @@ public abstract class AbstractSettingsComponent {
|
||||
|
||||
@NotNull
|
||||
private JPanel treePanel() {
|
||||
@NotNull JPanel label = JPanelFactory.of(projectDocEffect, new JBLabel(ShowBundle.message("project.doc.regexp")));
|
||||
@NotNull JPanel dirLabel = JPanelFactory.of(dirDocEffect, new JBLabel(ShowBundle.message("dir.doc.regexp")));
|
||||
@NotNull JPanel fileLabel = JPanelFactory.of(fileDocEffect, new JBLabel(ShowBundle.message("file.doc.regexp")));
|
||||
JPanel panel = FormBuilder.createFormBuilder()
|
||||
.addLabeledComponent(label, projectDoc, 1, true).getPanel();
|
||||
.addLabeledComponent(dirLabel, dirDoc, 1, true)
|
||||
.addLabeledComponent(fileLabel, fileDoc, 1, true)
|
||||
.getPanel();
|
||||
panel.setBorder(IdeBorderFactory.createTitledBorder(ShowBundle.message("tree.comment")));
|
||||
return panel;
|
||||
}
|
||||
@@ -137,20 +142,38 @@ public abstract class AbstractSettingsComponent {
|
||||
}
|
||||
|
||||
|
||||
public boolean getProjectEffect() {
|
||||
return projectDocEffect.isSelected();
|
||||
public boolean getDirEffect() {
|
||||
return dirDocEffect.isSelected();
|
||||
}
|
||||
|
||||
public void setProjectEffect(boolean newStatus) {
|
||||
projectDocEffect.setSelected(newStatus);
|
||||
public void setDirEffect(boolean newStatus) {
|
||||
dirDocEffect.setSelected(newStatus);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getProjectDoc() {
|
||||
return projectDoc.getText();
|
||||
public String getDirDoc() {
|
||||
return dirDoc.getText();
|
||||
}
|
||||
|
||||
public void setProjectDoc(@NotNull String newText) {
|
||||
projectDoc.setText(newText);
|
||||
public void setDirDoc(@NotNull String newText) {
|
||||
dirDoc.setText(newText);
|
||||
}
|
||||
|
||||
|
||||
public boolean getFileEffect() {
|
||||
return fileDocEffect.isSelected();
|
||||
}
|
||||
|
||||
public void setFileEffect(boolean newStatus) {
|
||||
fileDocEffect.setSelected(newStatus);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFileDoc() {
|
||||
return fileDoc.getText();
|
||||
}
|
||||
|
||||
public void setFileDoc(@NotNull String newText) {
|
||||
fileDoc.setText(newText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,10 @@ public class AbstractSettingsConfigurable {
|
||||
modified |= !component.getDocExclude().equals(settings.getDocExclude());
|
||||
modified |= component.getDocGetEffect() != settings.docGetEffect;
|
||||
modified |= !component.getDocGet().equals(settings.getDocGet());
|
||||
modified |= component.getProjectEffect() != settings.projectDocEffect;
|
||||
modified |= !component.getProjectDoc().equals(settings.getProjectDoc());
|
||||
modified |= component.getDirEffect() != settings.dirDocEffect;
|
||||
modified |= !component.getDirDoc().equals(settings.getDirDoc());
|
||||
modified |= component.getFileEffect() != settings.fileDocEffect;
|
||||
modified |= !component.getFileDoc().equals(settings.getFileDoc());
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -34,8 +36,10 @@ public class AbstractSettingsConfigurable {
|
||||
settings.setDocExclude(component.getDocExclude());
|
||||
settings.docGetEffect = component.getDocGetEffect();
|
||||
settings.setDocGet(component.getDocGet());
|
||||
settings.projectDocEffect = component.getProjectEffect();
|
||||
settings.setProjectDoc(component.getProjectDoc());
|
||||
settings.dirDocEffect = component.getDirEffect();
|
||||
settings.setDirDoc(component.getDirDoc());
|
||||
settings.fileDocEffect = component.getFileEffect();
|
||||
settings.setFileDoc(component.getFileDoc());
|
||||
}
|
||||
|
||||
static void reset(@NotNull AbstractSettingsState settings, @NotNull AbstractSettingsComponent component) {
|
||||
@@ -47,7 +51,9 @@ public class AbstractSettingsConfigurable {
|
||||
component.setDocExclude(settings.getDocExclude());
|
||||
component.setDocGetEffect(settings.docGetEffect);
|
||||
component.setDocGet(settings.getDocGet());
|
||||
component.setProjectEffect(settings.projectDocEffect);
|
||||
component.setProjectDoc(settings.getProjectDoc());
|
||||
component.setDirEffect(settings.dirDocEffect);
|
||||
component.setDirDoc(settings.getDirDoc());
|
||||
component.setFileEffect(settings.fileDocEffect);
|
||||
component.setFileDoc(settings.getFileDoc());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class AbstractSettingsState {
|
||||
|
||||
public int lineEndCount = 2;
|
||||
public int lineEndLen = 0;
|
||||
public boolean onlySelectLine = false;
|
||||
|
||||
@NotNull
|
||||
public transient Pattern lineInclude = Pattern.compile("");
|
||||
@NotNull
|
||||
@@ -20,21 +20,32 @@ public abstract class AbstractSettingsState {
|
||||
public transient Pattern docInclude = Pattern.compile("");
|
||||
@NotNull
|
||||
public transient Pattern docExclude = Pattern.compile("");
|
||||
|
||||
public boolean docGetEffect = false;
|
||||
@NotNull
|
||||
public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )");
|
||||
public boolean projectDocEffect = true;
|
||||
|
||||
public boolean dirDocEffect = true;
|
||||
@NotNull
|
||||
public transient Pattern[][] projectDoc = {
|
||||
{
|
||||
Pattern.compile("pom.xml"),
|
||||
Pattern.compile("<description>([^<]++)</description>"),
|
||||
Pattern.compile("<name>\\$\\{[^}]*+\\}([^<]++)</name>"),
|
||||
},
|
||||
{Pattern.compile("build.gradle"), Pattern.compile("^description[^'\"]*+['\"]([^'\"]++)['\"]")},
|
||||
{Pattern.compile("build.gradle.kts"), Pattern.compile("^description[^'\"]*+['\"]([^'\"]++)['\"]")},
|
||||
{Pattern.compile("README.md"), Pattern.compile("^# (.*)")},
|
||||
};
|
||||
public transient Map<String, Pattern[]> dirDoc = new LinkedHashMap<>() {{
|
||||
put("pom.xml", new Pattern[]{
|
||||
Pattern.compile("<description>([^<]++)</description>"),
|
||||
Pattern.compile("<name>\\$\\{[^}]*+\\}([^<]++)</name>"),
|
||||
});
|
||||
put("build.gradle", new Pattern[]{Pattern.compile("(?m)^description[^'\"]*+['\"]([^'\"]++)['\"]")});
|
||||
put("build.gradle.kts", new Pattern[]{Pattern.compile("(?m)^description[^'\"]*+['\"]([^'\"]++)['\"]")});
|
||||
put("README.md", new Pattern[]{Pattern.compile("(?m)^#++ (.*)")});
|
||||
}};
|
||||
|
||||
public boolean fileDocEffect = true;
|
||||
@NotNull
|
||||
public transient Map<String, Pattern[]> fileDoc = new LinkedHashMap<>() {{
|
||||
put("md", new Pattern[]{Pattern.compile("(?m)^#++ (.*)")});
|
||||
put("ad", new Pattern[]{Pattern.compile("(?m)^=++ (.*)")});
|
||||
put("adoc", new Pattern[]{Pattern.compile("(?m)^=++ (.*)")});
|
||||
put("asciidoc", new Pattern[]{Pattern.compile("(?m)^=++ (.*)")});
|
||||
}};
|
||||
|
||||
|
||||
public String getLineInclude() {
|
||||
return lineInclude.pattern();
|
||||
@@ -79,30 +90,21 @@ public abstract class AbstractSettingsState {
|
||||
}
|
||||
|
||||
|
||||
public static final Function<Pattern[], String> TO_LINE = patterns -> Stream.of(patterns)
|
||||
.map(Pattern::pattern)
|
||||
.collect(Collectors.joining("||"));
|
||||
|
||||
public String getProjectDoc() {
|
||||
return Stream.of(projectDoc)
|
||||
.map(TO_LINE)
|
||||
.collect(Collectors.joining("\n"));
|
||||
@NotNull
|
||||
public String getDirDoc() {
|
||||
return PatternMapUtils.toString(dirDoc);
|
||||
}
|
||||
|
||||
private static final Pattern LINE_PATTERN = Pattern.compile("[\\r\\n]++");
|
||||
public void setDirDoc(@NotNull String dirDoc) {
|
||||
this.dirDoc = PatternMapUtils.toMap(dirDoc);
|
||||
}
|
||||
|
||||
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\|\\|");
|
||||
@NotNull
|
||||
public String getFileDoc() {
|
||||
return PatternMapUtils.toString(fileDoc);
|
||||
}
|
||||
|
||||
public void setProjectDoc(@NotNull String projectDoc) {
|
||||
String[] projectDocLines = LINE_PATTERN.split(projectDoc);
|
||||
@NotNull Pattern[][] patterns = new Pattern[projectDocLines.length][];
|
||||
for (int i = 0; i < projectDocLines.length; i++) {
|
||||
String[] projectDocs = SPLIT_PATTERN.split(projectDocLines[i]);
|
||||
patterns[i] = new Pattern[projectDocs.length];
|
||||
for (int j = 0; j < projectDocs.length; j++) {
|
||||
patterns[i][j] = Pattern.compile(projectDocs[j]);
|
||||
}
|
||||
}
|
||||
this.projectDoc = patterns;
|
||||
public void setFileDoc(@NotNull String fileDoc) {
|
||||
this.fileDoc = PatternMapUtils.toMap(fileDoc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class PatternMapUtils {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PatternMapUtils.class);
|
||||
|
||||
public static final Pattern LINE_PATTERN = Pattern.compile("[\\r\\n]++");
|
||||
public static final Pattern SPLIT_PATTERN = Pattern.compile("\\|\\|");
|
||||
|
||||
@NotNull
|
||||
public static Map<String, Pattern[]> toMap(@NotNull String fileDoc) {
|
||||
String[] lines = LINE_PATTERN.split(fileDoc);
|
||||
@NotNull Map<String, Pattern[]> map = new LinkedHashMap<>(lines.length, 1);
|
||||
for (String line : lines) {
|
||||
String[] split = SPLIT_PATTERN.split(line);
|
||||
if (split.length > 1) {
|
||||
@NotNull ArrayList<Pattern> patterns = new ArrayList<>(split.length - 1);
|
||||
for (int i = 1; i < split.length; i++) {
|
||||
try {
|
||||
patterns.add(Pattern.compile(split[i]));
|
||||
} catch (Exception ignore) {}
|
||||
}
|
||||
map.put(split[0], patterns.toArray(new Pattern[0]));
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toString(@NotNull Map<String, Pattern[]> patternMap) {
|
||||
return patternMap.entrySet().stream().map(entry ->
|
||||
entry.getKey() + "||" + Stream.of(entry.getValue())
|
||||
.map(Pattern::pattern)
|
||||
.collect(Collectors.joining("||"))
|
||||
).collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@State(
|
||||
@@ -18,8 +19,10 @@ public class ProjectSettingsState extends AbstractSettingsState implements Persi
|
||||
|
||||
public ProjectSettingsState() {
|
||||
this.lineExclude = Pattern.compile("");
|
||||
this.projectDocEffect = false;
|
||||
this.projectDoc = new Pattern[][]{};
|
||||
this.dirDocEffect = false;
|
||||
this.dirDoc = Collections.emptyMap();
|
||||
this.fileDocEffect = false;
|
||||
this.fileDoc = Collections.emptyMap();
|
||||
}
|
||||
|
||||
public static final ProjectSettingsState DEFAULT_SETTING = new ProjectSettingsState();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.github.linwancen.plugin.show.tree;
|
||||
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import io.github.linwancen.plugin.show.settings.AbstractSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class DirDoc {
|
||||
|
||||
@Nullable
|
||||
static String dirDoc(PsiDirectoryNode node, @NotNull AbstractSettingsState settings) {
|
||||
if (!settings.dirDocEffect) {
|
||||
return null;
|
||||
}
|
||||
@NotNull Map<String, Pattern[]> patternMap = settings.dirDoc;
|
||||
@NotNull PsiDirectoryNode psiDirectoryNode = node;
|
||||
@Nullable PsiDirectory psiDirectory = psiDirectoryNode.getValue();
|
||||
if (psiDirectory == null) {
|
||||
return null;
|
||||
}
|
||||
for (@NotNull Map.Entry<String, Pattern[]> patterns : patternMap.entrySet()) {
|
||||
@Nullable PsiFile psiFile = psiDirectory.findFile(patterns.getKey());
|
||||
if (psiFile != null) {
|
||||
@Nullable String doc = FilePatternsDoc.filePatternsDoc(psiFile, patterns.getValue());
|
||||
if (doc != null) {
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package io.github.linwancen.plugin.show.tree;
|
||||
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import io.github.linwancen.plugin.show.settings.AbstractSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class FileDoc {
|
||||
|
||||
@Nullable
|
||||
static String fileDoc(PsiFileNode node, @NotNull AbstractSettingsState settings) {
|
||||
if (!settings.fileDocEffect) {
|
||||
return null;
|
||||
}
|
||||
@NotNull Map<String, Pattern[]> patternMap = settings.fileDoc;
|
||||
@NotNull PsiFileNode psiFileNode = node;
|
||||
@Nullable PsiFile psiFile = psiFileNode.getValue();
|
||||
if (psiFile == null) {
|
||||
return null;
|
||||
}
|
||||
@Nullable VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
if (virtualFile == null) {
|
||||
return null;
|
||||
}
|
||||
@Nullable String extension = virtualFile.getExtension();
|
||||
if (extension == null) {
|
||||
extension = virtualFile.getName();
|
||||
}
|
||||
@Nullable Pattern[] patterns = patternMap.get(extension);
|
||||
if (patterns == null) {
|
||||
return null;
|
||||
}
|
||||
return FilePatternsDoc.filePatternsDoc(psiFile, patterns);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.github.linwancen.plugin.show.tree;
|
||||
|
||||
import com.intellij.lang.FileASTNode;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
class FilePatternsDoc {
|
||||
|
||||
@Nullable
|
||||
static String filePatternsDoc(@NotNull PsiFile psiFile, @NotNull Pattern[] patterns) {
|
||||
@Nullable FileASTNode fileNode = psiFile.getNode();
|
||||
if (fileNode == null) {
|
||||
return null;
|
||||
}
|
||||
@NotNull String text = fileNode.getText();
|
||||
for (@NotNull Pattern pattern : patterns) {
|
||||
@NotNull Matcher matcher = pattern.matcher(text);
|
||||
if (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
if (group != null) {
|
||||
group = group.trim();
|
||||
if (!group.isEmpty()) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package io.github.linwancen.plugin.show.tree;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
|
||||
import com.intellij.lang.FileASTNode;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
|
||||
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;
|
||||
|
||||
public class ProjectDoc {
|
||||
|
||||
public static String projectDoc(ProjectViewNode<?> node, @NotNull SettingsInfo settingsInfo) {
|
||||
if (!(node instanceof PsiDirectoryNode)) {
|
||||
return null;
|
||||
}
|
||||
@NotNull PsiDirectoryNode psiDirectoryNode = (PsiDirectoryNode) node;
|
||||
@Nullable PsiDirectory psiDirectory = psiDirectoryNode.getValue();
|
||||
if (psiDirectory == null) {
|
||||
return null;
|
||||
}
|
||||
@NotNull ProjectSettingsState projectSettings = settingsInfo.projectSettings;
|
||||
@NotNull GlobalSettingsState globalSettings = settingsInfo.globalSettings;
|
||||
if (projectSettings.projectFilterEffective && projectSettings.projectDocEffect) {
|
||||
return projectDirDoc(psiDirectory, projectSettings.projectDoc);
|
||||
} else if (projectSettings.globalFilterEffective && globalSettings.projectDocEffect) {
|
||||
return projectDirDoc(psiDirectory, globalSettings.projectDoc);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String projectDirDoc(@NotNull PsiDirectory psiDirectory, @NotNull Pattern[][] projectDoc) {
|
||||
for (@NotNull Pattern[] patterns : projectDoc) {
|
||||
@Nullable String patternsDoc = patternsDoc(psiDirectory, patterns);
|
||||
if (patternsDoc != null) {
|
||||
return patternsDoc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String patternsDoc(@NotNull PsiDirectory psiDirectory, @NotNull Pattern[] patterns) {
|
||||
if (patterns.length < 2) {
|
||||
return null;
|
||||
}
|
||||
Pattern filePattern = patterns[0];
|
||||
String fileName = filePattern.pattern();
|
||||
@Nullable PsiFile file = psiDirectory.findFile(fileName);
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
@Nullable FileASTNode fileNode = file.getNode();
|
||||
if (fileNode == null) {
|
||||
return null;
|
||||
}
|
||||
@NotNull String text = fileNode.getText();
|
||||
for (int i = 1; i < patterns.length; i++) {
|
||||
@NotNull Matcher matcher = patterns[i].matcher(text);
|
||||
if (matcher.find()) {
|
||||
String group = matcher.group(1);
|
||||
if (group != null) {
|
||||
group = group.trim();
|
||||
if (!group.isEmpty()) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.github.linwancen.plugin.show.tree;
|
||||
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.settings.AbstractSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.GlobalSettingsState;
|
||||
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class RelFileDoc {
|
||||
|
||||
@Nullable
|
||||
public static String relFileDoc(ProjectViewNode<?> node, @NotNull SettingsInfo settingsInfo) {
|
||||
@NotNull ProjectSettingsState projectSettings = settingsInfo.projectSettings;
|
||||
@NotNull GlobalSettingsState globalSettings = settingsInfo.globalSettings;
|
||||
if (projectSettings.projectFilterEffective) {
|
||||
return relDoc(node, projectSettings);
|
||||
} else if (projectSettings.globalFilterEffective) {
|
||||
return relDoc(node, globalSettings);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String relDoc(ProjectViewNode<?> node, @NotNull AbstractSettingsState settings) {
|
||||
if (node instanceof PsiFileNode) {
|
||||
return FileDoc.fileDoc((PsiFileNode) node, settings);
|
||||
}
|
||||
if (node instanceof PsiDirectoryNode) {
|
||||
return DirDoc.dirDoc((PsiDirectoryNode) node, settings);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ sign.exclude.regexp=className#memberName exclude Regexp:
|
||||
comment.include.regexp=comment include Regexp:
|
||||
comment.exclude.regexp=comment exclude Regexp:
|
||||
get.doc.regexp=get doc Regexp, last () when had, default is first sentence .+?(?:[\u3002\r\n]|. ) :
|
||||
project.doc.regexp=project doc, fileName||Regexp1||Regexp2\\n:
|
||||
dir.doc.regexp=dir doc, fileName||Regexp1||Regexp2\\n:
|
||||
file.doc.regexp=file doc, fileName||Regexp1||Regexp2\\n:
|
||||
|
||||
global.settings.effective=Global Settings Effective
|
||||
project.settings.effective=Project Settings Effective
|
||||
|
||||
@@ -28,7 +28,8 @@ sign.exclude.regexp=\u7C7B#\u65B9\u6CD5 \u6392\u9664 \u6B63\u5219\uFF1A
|
||||
comment.include.regexp=\u6CE8\u91CA \u5305\u542B \u6B63\u5219\uFF1A
|
||||
comment.exclude.regexp=\u6CE8\u91CA \u6392\u9664 \u6B63\u5219\uFF1A
|
||||
get.doc.regexp=\u6CE8\u91CA\u63D0\u53D6\u6B63\u5219\uFF0C\u82E5\u6709 () \u5219\u53D6\u6700\u540E\u4E00\u4E2A\uFF0C\u9ED8\u8BA4\u6B63\u5219\u662F\u7B2C\u4E00\u53E5 .+?(?:[\u3002\r\n]|. ) :
|
||||
project.doc.regexp=\u9879\u76EE\u6CE8\u91CA, \u6587\u4EF6\u540D||\u6B63\u52191||\u6B63\u52192\\n:
|
||||
dir.doc.regexp=\u76EE\u5F55\u6CE8\u91CA, \u6587\u4EF6\u540D||\u6B63\u52191||\u6B63\u52192\\n:
|
||||
file.doc.regexp=\u6587\u4EF6\u6CE8\u91CA, \u6587\u4EF6\u540D||\u6B63\u52191||\u6B63\u52192\\n:
|
||||
|
||||
global.settings.effective=\u5168\u5C40\u914D\u7F6E\u751F\u6548
|
||||
project.settings.effective=\u9879\u76EE\u914D\u7F6E\u751F\u6548
|
||||
|
||||
Reference in New Issue
Block a user