diff --git a/README.md b/README.md index 2bf2a03..91a43a4 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,5 @@ Change Log: - 1.2 Add end-of-line comment class prefix filter settings | 添加行末注释类前缀过滤配置 - 1.3 support class in tree, constructor and field type in line end | 支持 class 树节点、构造方法和字段的行末注释 - 1.4 Find element right to left for end-of-line comment | 从右往左查找行末注释对象 -- 1.5 Support find next loop when not comment | 支持没有注释时循环查找下一个对象 \ No newline at end of file +- 1.5 Support find next loop when not comment | 支持没有注释时循环查找下一个对象 +- 1.6 Add end-of-line comment independent switch for call,new,ref | 增加行末调用,new,引用注释独立开关 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 844e300..ca65c13 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'io.github.linwancen' -version '1.5.0.' + (new Date().format('yyyy.MM.dd_HH.mm')) +version '1.6.0.' + (new Date().format('yyyy.MM.dd_HH.mm')) apply plugin: 'java' @@ -43,6 +43,7 @@ patchPluginXml {
  • 1.3 Support class in tree, constructor and field type in line end | 支持 class 树节点、构造方法和字段的行末注释
  • 1.4 Find element right to left for end-of-line comment | 从右往左查找行末注释对象
  • 1.5 Support find next loop when not comment | 支持没有注释时循环查找下一个对象 +
  • 1.6 Add end-of-line comment independent switch for call,new,ref | 增加行末调用,new,引用注释独立开关 """ } diff --git a/src/main/java/io/github/linwancen/plugin/show/Tree.java b/src/main/java/io/github/linwancen/plugin/show/Tree.java index c0e1dc6..b8a2f54 100644 --- a/src/main/java/io/github/linwancen/plugin/show/Tree.java +++ b/src/main/java/io/github/linwancen/plugin/show/Tree.java @@ -13,8 +13,8 @@ import com.intellij.psi.*; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; -import io.github.linwancen.plugin.show.doc.DocUtils; import io.github.linwancen.plugin.show.doc.DocTextUtils; +import io.github.linwancen.plugin.show.doc.DocUtils; import io.github.linwancen.plugin.show.settings.AppSettingsState; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/io/github/linwancen/plugin/show/line/LineDocUtils.java b/src/main/java/io/github/linwancen/plugin/show/line/LineDocUtils.java index 0792680..678688d 100644 --- a/src/main/java/io/github/linwancen/plugin/show/line/LineDocUtils.java +++ b/src/main/java/io/github/linwancen/plugin/show/line/LineDocUtils.java @@ -4,6 +4,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.util.PsiTreeUtil; +import io.github.linwancen.plugin.show.settings.AppSettingsState; import org.jetbrains.annotations.Nullable; class LineDocUtils { @@ -13,21 +14,37 @@ class LineDocUtils { @Nullable static PsiDocComment elementDoc(PsiElement element, PsiElement psiIdentifier, int startOffset, int endOffset) { + AppSettingsState instance = AppSettingsState.getInstance(); if (element != null) { + PsiDocComment executableDoc = elementDoc(element, startOffset, endOffset, instance); + if (executableDoc != null) { + return executableDoc; + } + } + if (instance.showLineEndCommentForRef) { + return refDoc(psiIdentifier, endOffset); + } + return null; + } + + @Nullable + private static PsiDocComment elementDoc(PsiElement element, int startOffset, int endOffset, AppSettingsState instance) { + if (instance.showLineEndCommentForCall) { PsiDocComment executableDoc = parentMethodDoc(element, startOffset, endOffset); if (executableDoc != null) { return executableDoc; } + } + if (instance.showLineEndCommentForNew) { PsiDocComment newDoc = parentNewDoc(element, startOffset); if (newDoc != null) { return newDoc; } - PsiDocComment docRefDoc = docRefDoc(element); - if (docRefDoc != null) { - return docRefDoc; - } } - return refDoc(psiIdentifier, endOffset); + if (instance.showLineEndCommentForRef) { + return docRefDoc(element); + } + return null; } @Nullable diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java index e5f07c0..a93e4a8 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsComponent.java @@ -14,6 +14,9 @@ public class AppSettingsComponent extends AbstractSettingsComponent { private final JPanel myMainPanel; private final JBCheckBox showTreeComment = new JBCheckBox("Show tree comment "); private final JBCheckBox showLineEndComment = new JBCheckBox("Show line end comment "); + private final JBCheckBox showLineEndCommentForCall = new JBCheckBox("Show line end comment for call "); + private final JBCheckBox showLineEndCommentForNew = new JBCheckBox("Show line end comment for new "); + private final JBCheckBox showLineEndCommentForRef = new JBCheckBox("Show line end comment for ref "); private final ColorPanel lineEndColor = new ColorPanel(); private final JBCheckBox findElementRightToLeft = new JBCheckBox("Find element right to left"); @@ -31,6 +34,10 @@ public class AppSettingsComponent extends AbstractSettingsComponent { JPanel comment = FormBuilder.createFormBuilder() .addComponent(showTreeComment, 1) .addComponent(showLineEndComment, 1) + .addSeparator() + .addComponent(showLineEndCommentForCall, 1) + .addComponent(showLineEndCommentForNew, 1) + .addComponent(showLineEndCommentForRef, 1) .getPanel(); comment.setBorder(IdeBorderFactory.createTitledBorder("Show")); return comment; @@ -78,6 +85,30 @@ public class AppSettingsComponent extends AbstractSettingsComponent { showLineEndComment.setSelected(newStatus); } + public boolean getShowLineEndCommentForCall() { + return showLineEndCommentForCall.isSelected(); + } + + public void setShowLineEndCommentForCall(boolean newStatus) { + showLineEndCommentForCall.setSelected(newStatus); + } + + public boolean getShowLineEndCommentForNew() { + return showLineEndCommentForNew.isSelected(); + } + + public void setShowLineEndCommentForNew(boolean newStatus) { + showLineEndCommentForNew.setSelected(newStatus); + } + + public boolean getShowLineEndCommentForRef() { + return showLineEndCommentForRef.isSelected(); + } + + public void setShowLineEndCommentForRef(boolean newStatus) { + showLineEndCommentForRef.setSelected(newStatus); + } + public Color getLineEndColor() { return lineEndColor.getSelectedColor(); } diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java index 7d19ea1..00f105e 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsConfigurable.java @@ -35,6 +35,9 @@ public class AppSettingsConfigurable implements Configurable { AppSettingsState settings = AppSettingsState.getInstance(); boolean modified = mySettingsComponent.getShowTreeComment() != settings.showTreeComment; modified |= mySettingsComponent.getShowLineEndComment() != settings.showLineEndComment; + modified |= mySettingsComponent.getShowLineEndCommentForCall() != settings.showLineEndCommentForCall; + modified |= mySettingsComponent.getShowLineEndCommentForNew() != settings.showLineEndCommentForNew; + modified |= mySettingsComponent.getShowLineEndCommentForRef() != settings.showLineEndCommentForRef; if (EditorColorsManager.getInstance().isDarkEditor()) { modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndColorDark); } else { @@ -51,6 +54,9 @@ public class AppSettingsConfigurable implements Configurable { AppSettingsState settings = AppSettingsState.getInstance(); settings.showTreeComment = mySettingsComponent.getShowTreeComment(); settings.showLineEndComment = mySettingsComponent.getShowLineEndComment(); + settings.showLineEndCommentForCall = mySettingsComponent.getShowLineEndCommentForCall(); + settings.showLineEndCommentForNew = mySettingsComponent.getShowLineEndCommentForNew(); + settings.showLineEndCommentForRef = mySettingsComponent.getShowLineEndCommentForRef(); if (EditorColorsManager.getInstance().isDarkEditor()) { settings.lineEndColorDark = mySettingsComponent.getLineEndColor(); } else { @@ -70,6 +76,9 @@ public class AppSettingsConfigurable implements Configurable { AppSettingsState settings = AppSettingsState.getInstance(); mySettingsComponent.setShowTreeComment(settings.showTreeComment); mySettingsComponent.setShowLineEndComment(settings.showLineEndComment); + mySettingsComponent.setShowLineEndCommentForCall(settings.showLineEndCommentForCall); + mySettingsComponent.setShowLineEndCommentForNew(settings.showLineEndCommentForNew); + mySettingsComponent.setShowLineEndCommentForRef(settings.showLineEndCommentForRef); if (EditorColorsManager.getInstance().isDarkEditor()) { mySettingsComponent.setLineEndColor(settings.lineEndColorDark); } else { diff --git a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java index a7d3f73..00080e5 100644 --- a/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java +++ b/src/main/java/io/github/linwancen/plugin/show/settings/AppSettingsState.java @@ -18,8 +18,12 @@ import java.awt.*; ) public class AppSettingsState implements PersistentStateComponent { - public boolean showLineEndComment = true; public boolean showTreeComment = true; + public boolean showLineEndComment = true; + + public boolean showLineEndCommentForCall = true; + public boolean showLineEndCommentForNew = true; + public boolean showLineEndCommentForRef = true; @SuppressWarnings("all") public Color lineEndColorBright = new Color(98, 151, 85);