1.20 get doc first sentence checkbox | 获取第一句注释选项

This commit is contained in:
林万程
2022-06-28 01:44:37 +08:00
parent db6c1963bf
commit 13d96d4b49
8 changed files with 95 additions and 14 deletions

View File

@@ -56,6 +56,7 @@ Thanks JetBrains Licenses for Open Source.
<h2>English Change Notes:</h2>
<ul>
<li>1.20 Add get doc first sentence checkbox
<li>1.19 Add supper doc at @Override, support doc tag like @author
<li>1.18 Add External Comment effect at previous layer when folder named -1
<li>1.17 Add line-end-comment skip doc text or class/member name by regexp
@@ -79,6 +80,7 @@ Thanks JetBrains Licenses for Open Source.
<h2>中文更新说明:</h2>
<ul>
<li>1.20 增加 获取第一句注释选项
<li>1.19 增加 @Override 显示父方法注释,支持 @author 等注释标签
<li>1.18 增加 外部注释 文件夹名为 -1 时配置在上一层文件夹生效
<li>1.17 增加 行末注释 根据正则表达式跳过指定注释文本或类成员名字的注释

View File

@@ -4,7 +4,7 @@ plugins {
}
group 'io.github.linwancen'
version '1.19.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
version '1.20.0.' + (new Date().format('yyyy.MM.dd_HH.mm'))
apply plugin: 'java'
@@ -39,6 +39,7 @@ patchPluginXml {
changeNotes = """
<h2>English Change Notes:</h2>
<ul>
<li>1.20 Add get doc first sentence checkbox
<li>1.19 Add supper doc at @Override, support doc tag like @author
<li>1.18 Add External Comment effect at previous layer when folder named -1
<li>1.17 Add line-end-comment skip doc text or class/member name by regexp
@@ -62,6 +63,7 @@ patchPluginXml {
<h2>中文更新说明:</h2>
<ul>
<li>1.20 增加 获取第一句注释选项
<li>1.19 增加 @Override 显示父方法注释,支持 @author 等注释标签
<li>1.18 增加 外部注释 文件夹名为 -1 时配置在上一层文件夹生效
<li>1.17 增加 行末注释 根据正则表达式跳过指定注释文本或类成员名字的注释

View File

@@ -4,9 +4,11 @@ import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.javadoc.*;
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;
public class PsiDocToStrDoc {
@@ -39,15 +41,42 @@ public class PsiDocToStrDoc {
}
sb.append(tags);
}
if (sb.length() == 0) {
String text = sb.toString();
if (text.trim().length() == 0) {
return null;
}
return sb.toString();
ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(psiDocComment.getProject());
return getDocBySetting(text, appSettings, projectSettings);
}
@Nullable
private static String getDocBySetting(String text,
AppSettingsState appSettings,
ProjectSettingsState projectSettings) {
// docGetEffect first because default false
if (appSettings.docGetEffect && projectSettings.globalFilterEffective) {
return getDoc(text, appSettings.docGet);
} else if (projectSettings.docGetEffect && projectSettings.projectFilterEffective) {
return getDoc(text, projectSettings.docGet);
} else {
return text;
}
}
@Nullable
static String getDoc(String text, Pattern docGet) {
// if effect skip check empty
Matcher m = docGet.matcher(text);
if (m.find()) {
return m.group(m.groupCount());
}
// one line
return text;
}
@NotNull
private static StringBuilder tags(@NotNull PsiDocComment psiDocComment, boolean isTree,
AppSettingsState appSettings) {
AppSettingsState appSettings) {
StringBuilder sb = new StringBuilder();
PsiDocTag[] tags = psiDocComment.getTags();
for (PsiDocTag tag : tags) {

View File

@@ -1,6 +1,7 @@
package io.github.linwancen.plugin.show.settings;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.util.ui.FormBuilder;
@@ -10,15 +11,18 @@ import javax.swing.*;
public abstract class AbstractSettingsComponent {
protected final JBTextField lineInclude = new JBTextField();
protected final JBTextField lineExclude = new JBTextField();
private final JBTextField lineInclude = new JBTextField();
private final JBTextField lineExclude = new JBTextField();
public final JBTextField docInclude = new JBTextField();
public final JBTextField docExclude = new JBTextField();
private final JBTextField docInclude = new JBTextField();
private final JBTextField docExclude = new JBTextField();
private final JBCheckBox docGetEffect = new JBCheckBox("");
private final JBTextField docGet = new JBTextField();
@NotNull
protected JPanel commonLineEndFilter(FormBuilder formBuilder) {
JPanel lineEndFilter = formBuilder
formBuilder = formBuilder
.addComponent(new JBLabel("Separated by '|' (Regexp), use '' to include all or exclude none."))
.addSeparator()
.addLabeledComponent(new JBLabel("className#memberName include Regexp: "), lineInclude, 1, true)
@@ -26,12 +30,18 @@ public abstract class AbstractSettingsComponent {
.addSeparator()
.addLabeledComponent(new JBLabel("comment include Regexp: "), docInclude, 1, true)
.addLabeledComponent(new JBLabel("comment exclude Regexp: "), docExclude, 1, true)
.getPanel();
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder(
"Line End Comment"));
.addSeparator();
formBuilder = add(formBuilder, docGetEffect, this.docGet,
"get doc Regexp, last () when had, default is first sentence .+?(?:[。\\r\\n]|\\. ) :");
JPanel lineEndFilter = formBuilder.getPanel();
lineEndFilter.setBorder(IdeBorderFactory.createTitledBorder("Line End Comment"));
return lineEndFilter;
}
protected FormBuilder add(FormBuilder formBuilder, JBCheckBox jbCheckBox, JBTextField jbTextField, String tip) {
return formBuilder.addLabeledComponent(JPanelFactory.of(jbCheckBox, new JBLabel(tip)), jbTextField, 1, true);
}
@NotNull
public String getLineInclude() {
return lineInclude.getText();
@@ -68,4 +78,22 @@ public abstract class AbstractSettingsComponent {
public void setDocExclude(@NotNull String newText) {
docExclude.setText(newText);
}
public boolean getDocGetEffect() {
return docGetEffect.isSelected();
}
public void setDocGetEffect(boolean newStatus) {
docGetEffect.setSelected(newStatus);
}
@NotNull
public String getDocGet() {
return docGet.getText();
}
public void setDocGet(@NotNull String newText) {
docGet.setText(newText);
}
}

View File

@@ -9,6 +9,8 @@ public class AbstractSettingsConfigurable {
modified |= !component.getLineExclude().equals(settings.getLineExclude());
modified |= !component.getDocInclude().equals(settings.getDocInclude());
modified |= !component.getDocExclude().equals(settings.getDocExclude());
modified |= component.getDocGetEffect() != settings.docGetEffect;
modified |= !component.getDocGet().equals(settings.getDocGet());
return modified;
}
@@ -17,6 +19,8 @@ public class AbstractSettingsConfigurable {
settings.setLineExclude(component.getLineExclude());
settings.setDocInclude(component.getDocInclude());
settings.setDocExclude(component.getDocExclude());
settings.docGetEffect = component.getDocGetEffect();
settings.setDocGet(component.getDocGet());
}
static void reset(AbstractSettingsState settings, AbstractSettingsComponent component) {
@@ -24,5 +28,7 @@ public class AbstractSettingsConfigurable {
component.setLineExclude(settings.getLineExclude());
component.setDocInclude(settings.getDocInclude());
component.setDocExclude(settings.getDocExclude());
component.setDocGetEffect(settings.docGetEffect);
component.setDocGet(settings.getDocGet());
}
}

View File

@@ -8,6 +8,8 @@ public abstract class AbstractSettingsState {
public transient Pattern lineExclude = Pattern.compile("^java");
public transient Pattern docInclude = Pattern.compile("");
public transient Pattern docExclude = Pattern.compile("");
public transient boolean docGetEffect = false;
public transient Pattern docGet = Pattern.compile(".+?(?:[。\\r\\n]|\\. )");
public String getLineInclude() {
return lineInclude.pattern();
@@ -25,6 +27,7 @@ public abstract class AbstractSettingsState {
this.lineExclude = Pattern.compile(lineExclude);
}
public String getDocInclude() {
return docInclude.pattern();
}
@@ -40,4 +43,13 @@ public abstract class AbstractSettingsState {
public void setDocExclude(String docExclude) {
this.docExclude = Pattern.compile(docExclude);
}
public String getDocGet() {
return docGet.pattern();
}
public void setDocGet(String docExclude) {
this.docGet = Pattern.compile(docExclude);
}
}

View File

@@ -10,7 +10,9 @@ public class JPanelFactory {
public static JPanel of(Component... components) {
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
for (Component component : components) {
jPanel.add(component);
if (component != null) {
jPanel.add(component);
}
}
return jPanel;
}

View File

@@ -33,7 +33,7 @@ public class ProjectSettingsComponent extends AbstractSettingsComponent {
}
public JComponent getPreferredFocusedComponent() {
return lineInclude;
return projectFilterEffective;
}