1.8 Add line-end-comment for json | 增加从同后缀的类中读取 json 行末注释
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package io.github.linwancen.plugin.show;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.EditorLinePainter;
|
||||
import com.intellij.openapi.editor.LineExtensionInfo;
|
||||
@@ -33,17 +32,17 @@ public class LineEnd extends EditorLinePainter {
|
||||
return null;
|
||||
}
|
||||
FileViewProvider viewProvider = PsiManager.getInstance(project).findViewProvider(file);
|
||||
PsiDocComment docComment = docOwnerFrom(viewProvider, lineNumber);
|
||||
PsiDocComment docComment = doc(project, viewProvider, lineNumber);
|
||||
String comment = DocTextUtils.text(docComment);
|
||||
if (comment == null) {
|
||||
return null;
|
||||
}
|
||||
LineExtensionInfo info = new LineExtensionInfo(" //" + comment, settings.lineEndTextAttr);
|
||||
LineExtensionInfo info = new LineExtensionInfo(settings.lineEndPrefix + comment, settings.lineEndTextAttr);
|
||||
return Collections.singletonList(info);
|
||||
}
|
||||
|
||||
private static @Nullable PsiDocComment docOwnerFrom(FileViewProvider viewProvider, int lineNumber) {
|
||||
if (viewProvider == null || !viewProvider.hasLanguage(JavaLanguage.INSTANCE)) {
|
||||
private static @Nullable PsiDocComment doc(Project project, FileViewProvider viewProvider, int lineNumber) {
|
||||
if (viewProvider == null) {
|
||||
return null;
|
||||
}
|
||||
Document document = viewProvider.getDocument();
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocToken;
|
||||
import com.intellij.psi.javadoc.PsiInlineDocTag;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -18,6 +19,7 @@ public class DocTextUtils {
|
||||
if (psiDocComment == null) {
|
||||
return null;
|
||||
}
|
||||
AppSettingsState appSettings = AppSettingsState.getInstance();
|
||||
List<String> comments = new ArrayList<>();
|
||||
PsiElement[] elements = psiDocComment.getDescriptionElements();
|
||||
for (PsiElement element : elements) {
|
||||
@@ -31,22 +33,17 @@ public class DocTextUtils {
|
||||
comments.add(children[2].getText());
|
||||
}
|
||||
}
|
||||
if (comments.size() > 1) {
|
||||
if (appSettings.lineEndCount > 0 && comments.size() >= appSettings.lineEndCount) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (comments.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder(comments.get(0).trim());
|
||||
if (sb.length() == 0) {
|
||||
return null;
|
||||
StringBuilder sb = new StringBuilder(" ");
|
||||
for (String s : comments) {
|
||||
sb.append(s.trim().replace("<br>", "")).append(" ");
|
||||
}
|
||||
if (comments.size() > 1) {
|
||||
sb.append(" ").append(comments.get(1).trim().replace("<br>", ""));
|
||||
}
|
||||
sb.insert(0, " ");
|
||||
sb.append(" ");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ public class DocUtils {
|
||||
|
||||
@Nullable
|
||||
public static PsiDocComment fileDoc(PsiFile psiFile) {
|
||||
if (!(psiFile instanceof PsiJavaFile)) {
|
||||
if (!(psiFile instanceof PsiClassOwner)) {
|
||||
return null;
|
||||
}
|
||||
PsiJavaFile psiJavaFile = (PsiJavaFile) psiFile;
|
||||
PsiClassOwner psiClassOwner = (PsiClassOwner) psiFile;
|
||||
if (PsiPackage.PACKAGE_INFO_FILE.equals(psiFile.getName())) {
|
||||
return PackageDocUtils.fromPackageInfoFile(psiFile);
|
||||
}
|
||||
PsiClass[] classes = psiJavaFile.getClasses();
|
||||
PsiClass[] classes = psiClassOwner.getClasses();
|
||||
if (classes.length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package io.github.linwancen.plugin.show.doc;
|
||||
|
||||
import com.intellij.json.psi.JsonProperty;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class JsonDocUtils {
|
||||
private static final Pattern JSON_PATTERN = Pattern.compile("[\\w.]*+$");
|
||||
|
||||
private JsonDocUtils() {}
|
||||
|
||||
@Nullable
|
||||
public static PsiDocComment jsonDoc(PsiElement element, int startOffset, int endOffset) {
|
||||
JsonProperty jsonProp = PsiTreeUtil.getParentOfType(element, JsonProperty.class, true, startOffset);
|
||||
if (jsonProp == null || jsonProp.getNameElement().getTextRange().getEndOffset() > endOffset) {
|
||||
return null;
|
||||
}
|
||||
String fileName = element.getContainingFile().getVirtualFile().getNameWithoutExtension();
|
||||
Matcher matcher = JSON_PATTERN.matcher(fileName);
|
||||
if (!matcher.find()) {
|
||||
return null;
|
||||
}
|
||||
String className = matcher.group();
|
||||
PsiClass[] psiClasses = classByName(className, element.getProject());
|
||||
PsiField psiField = psiField(psiClasses, element.getProject(), jsonProp);
|
||||
if (psiField != null) {
|
||||
return DocUtils.srcOrByteCodeDoc(psiField);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiClass[] classByName(String className, @NotNull Project project) {
|
||||
int i = className.indexOf('.');
|
||||
if (i > 0) {
|
||||
return classByFullName(className, project);
|
||||
}
|
||||
PsiShortNamesCache namesCache = PsiShortNamesCache.getInstance(project);
|
||||
return namesCache.getClassesByName(className, GlobalSearchScope.allScope(project));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static PsiClass[] classByFullName(String className, @NotNull Project project) {
|
||||
JavaPsiFacade javaPsiFacade = JavaPsiFacade.getInstance(project);
|
||||
return javaPsiFacade.findClasses(className, GlobalSearchScope.allScope(project));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiField psiField(PsiClass[] rootClasses, Project project, JsonProperty jsonProp) {
|
||||
JsonProperty parentJsonProp = PsiTreeUtil.getParentOfType(jsonProp, JsonProperty.class);
|
||||
if (parentJsonProp == null) {
|
||||
for (PsiClass c : rootClasses) {
|
||||
PsiField field = c.findFieldByName(jsonProp.getName(), true);
|
||||
if (field != null) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PsiField psiField = psiField(rootClasses, project, parentJsonProp);
|
||||
if (psiField == null) {
|
||||
return null;
|
||||
}
|
||||
String classFullName = psiField.getType().getCanonicalText();
|
||||
@NotNull PsiClass[] psiClasses = classByFullName(classFullName, project);
|
||||
for (PsiClass c : psiClasses) {
|
||||
PsiField field = c.findFieldByName(jsonProp.getName(), true);
|
||||
if (field != null) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.json.JsonLanguage;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
@@ -8,6 +8,8 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import io.github.linwancen.plugin.show.doc.JsonDocUtils;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LineDocLeftToRightUtils {
|
||||
@@ -44,16 +46,23 @@ public class LineDocLeftToRightUtils {
|
||||
offset++;
|
||||
}
|
||||
offset += startOffset;
|
||||
PsiElement element = viewProvider.findElementAt(offset);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
AppSettingsState instance = AppSettingsState.getInstance();
|
||||
if (instance.inJson && element.getLanguage().is(JsonLanguage.INSTANCE)) {
|
||||
return JsonDocUtils.jsonDoc(element, startOffset, endOffset);
|
||||
}
|
||||
if (startWithSymbol) {
|
||||
startOffset = 0;
|
||||
}
|
||||
PsiElement element = viewProvider.findElementAt(offset, JavaLanguage.INSTANCE);
|
||||
return nextDoc(element, startOffset, endOffset);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiDocComment nextDoc(PsiElement element, int startOffset, int endOffset) {
|
||||
while (element != null && element.getTextRange().getEndOffset() < endOffset) {
|
||||
while (element.getTextRange().getEndOffset() < endOffset) {
|
||||
if (element instanceof PsiIdentifier) {
|
||||
PsiDocComment psiDocComment = LineDocUtils.elementDoc(element, element, startOffset, endOffset);
|
||||
if (psiDocComment != null) {
|
||||
@@ -61,6 +70,9 @@ public class LineDocLeftToRightUtils {
|
||||
}
|
||||
}
|
||||
element = PsiTreeUtil.nextVisibleLeaf(element);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package io.github.linwancen.plugin.show.line;
|
||||
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.json.JsonLanguage;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiIdentifier;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import io.github.linwancen.plugin.show.doc.JsonDocUtils;
|
||||
import io.github.linwancen.plugin.show.settings.AppSettingsState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LineDocRightToLeftUtils {
|
||||
@@ -15,10 +17,11 @@ public class LineDocRightToLeftUtils {
|
||||
@Nullable
|
||||
public static PsiDocComment rightDoc(FileViewProvider viewProvider, int startOffset, int endOffset) {
|
||||
// End is always white, can not -1 because @see class.name need it
|
||||
PsiElement element = viewProvider.findElementAt(endOffset, JavaLanguage.INSTANCE);
|
||||
PsiElement element = viewProvider.findElementAt(endOffset);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
AppSettingsState instance = AppSettingsState.getInstance();
|
||||
PsiElement identifier;
|
||||
PsiDocComment psiDocComment;
|
||||
while (true) {
|
||||
@@ -27,6 +30,9 @@ public class LineDocRightToLeftUtils {
|
||||
identifier = null;
|
||||
}
|
||||
if (identifier == null || identifier instanceof PsiIdentifier) {
|
||||
if (instance.inJson && element.getLanguage().is(JsonLanguage.INSTANCE)) {
|
||||
return JsonDocUtils.jsonDoc(element, startOffset, endOffset);
|
||||
}
|
||||
psiDocComment = LineDocUtils.elementDoc(element, identifier, startOffset, endOffset);
|
||||
if (psiDocComment != null) {
|
||||
return psiDocComment;
|
||||
|
||||
@@ -16,32 +16,33 @@ class LineDocUtils {
|
||||
int startOffset, int endOffset) {
|
||||
AppSettingsState instance = AppSettingsState.getInstance();
|
||||
if (element != null) {
|
||||
PsiDocComment executableDoc = elementDoc(element, startOffset, endOffset, instance);
|
||||
if (executableDoc != null) {
|
||||
return executableDoc;
|
||||
PsiDocComment elementDoc = elementDoc(element, startOffset, endOffset, instance);
|
||||
if (elementDoc != null) {
|
||||
return elementDoc;
|
||||
}
|
||||
}
|
||||
if (instance.showLineEndCommentForRef) {
|
||||
if (instance.fromRef) {
|
||||
return refDoc(psiIdentifier, endOffset);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PsiDocComment elementDoc(PsiElement element, int startOffset, int endOffset, AppSettingsState instance) {
|
||||
if (instance.showLineEndCommentForCall) {
|
||||
private static PsiDocComment elementDoc(PsiElement element, int startOffset, int endOffset,
|
||||
AppSettingsState instance) {
|
||||
if (instance.fromCall) {
|
||||
PsiDocComment executableDoc = parentMethodDoc(element, startOffset, endOffset);
|
||||
if (executableDoc != null) {
|
||||
return executableDoc;
|
||||
}
|
||||
}
|
||||
if (instance.showLineEndCommentForNew) {
|
||||
if (instance.fromNew) {
|
||||
PsiDocComment newDoc = parentNewDoc(element, startOffset);
|
||||
if (newDoc != null) {
|
||||
return newDoc;
|
||||
}
|
||||
}
|
||||
if (instance.showLineEndCommentForRef) {
|
||||
if (instance.fromRef) {
|
||||
return docRefDoc(element);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -3,6 +3,8 @@ package io.github.linwancen.plugin.show.settings;
|
||||
import com.intellij.ui.ColorPanel;
|
||||
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;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,16 +16,18 @@ 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 JBCheckBox fromCall = new JBCheckBox("call ");
|
||||
private final JBCheckBox fromNew = new JBCheckBox("new ");
|
||||
private final JBCheckBox fromRef = new JBCheckBox("ref ");
|
||||
private final JBCheckBox inJson = new JBCheckBox("in json ");
|
||||
private final ColorPanel lineEndColor = new ColorPanel();
|
||||
private final JBCheckBox findElementRightToLeft = new JBCheckBox("Find element right to left");
|
||||
protected final JBTextField lineEndPrefix = new JBTextField();
|
||||
protected final JBTextField lineEndCount = new JBTextField();
|
||||
|
||||
public AppSettingsComponent() {
|
||||
myMainPanel = FormBuilder.createFormBuilder()
|
||||
.addComponent(showPanel(), 1)
|
||||
.addComponent(colorPanel(), 1)
|
||||
.addComponent(lineEndFilterPanel(), 1)
|
||||
.addComponentFillVertically(new JPanel(), 0)
|
||||
.getPanel();
|
||||
@@ -34,28 +38,23 @@ 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;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JPanel colorPanel() {
|
||||
JPanel color = FormBuilder.createFormBuilder()
|
||||
.addLabeledComponent(new JLabel("line end text color:"), lineEndColor)
|
||||
.getPanel();
|
||||
color.setBorder(IdeBorderFactory.createTitledBorder("Color"));
|
||||
return color;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JPanel lineEndFilterPanel() {
|
||||
JPanel text = JPanelFactory.of(
|
||||
new JBLabel("object count: "), lineEndCount,
|
||||
new JBLabel("text color: "), lineEndColor,
|
||||
new JBLabel("prefix: "), lineEndPrefix);
|
||||
FormBuilder formBuilder = FormBuilder.createFormBuilder()
|
||||
.addComponent(findElementRightToLeft)
|
||||
.addComponent(JPanelFactory.of(findElementRightToLeft))
|
||||
.addSeparator()
|
||||
.addComponent(JPanelFactory.of(fromCall, fromNew, fromRef, inJson), 1)
|
||||
.addSeparator()
|
||||
.addComponent(text)
|
||||
.addSeparator();
|
||||
return commonLineEndFilter(formBuilder);
|
||||
}
|
||||
@@ -85,28 +84,36 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
showLineEndComment.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getShowLineEndCommentForCall() {
|
||||
return showLineEndCommentForCall.isSelected();
|
||||
public boolean getFromCall() {
|
||||
return fromCall.isSelected();
|
||||
}
|
||||
|
||||
public void setShowLineEndCommentForCall(boolean newStatus) {
|
||||
showLineEndCommentForCall.setSelected(newStatus);
|
||||
public void setFromCall(boolean newStatus) {
|
||||
fromCall.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getShowLineEndCommentForNew() {
|
||||
return showLineEndCommentForNew.isSelected();
|
||||
public boolean getFromNew() {
|
||||
return fromNew.isSelected();
|
||||
}
|
||||
|
||||
public void setShowLineEndCommentForNew(boolean newStatus) {
|
||||
showLineEndCommentForNew.setSelected(newStatus);
|
||||
public void setFromNew(boolean newStatus) {
|
||||
fromNew.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getShowLineEndCommentForRef() {
|
||||
return showLineEndCommentForRef.isSelected();
|
||||
public boolean getFromRef() {
|
||||
return fromRef.isSelected();
|
||||
}
|
||||
|
||||
public void setShowLineEndCommentForRef(boolean newStatus) {
|
||||
showLineEndCommentForRef.setSelected(newStatus);
|
||||
public void setFromRef(boolean newStatus) {
|
||||
fromRef.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public boolean getInJson() {
|
||||
return inJson.isSelected();
|
||||
}
|
||||
|
||||
public void setInJson(boolean newStatus) {
|
||||
inJson.setSelected(newStatus);
|
||||
}
|
||||
|
||||
public Color getLineEndColor() {
|
||||
@@ -124,4 +131,22 @@ public class AppSettingsComponent extends AbstractSettingsComponent {
|
||||
public void setFindElementRightToLeft(boolean newStatus) {
|
||||
findElementRightToLeft.setSelected(newStatus);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLineEndPrefix() {
|
||||
return lineEndPrefix.getText();
|
||||
}
|
||||
|
||||
public void setLineEndPrefix(@NotNull String newText) {
|
||||
lineEndPrefix.setText(newText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLineEndCount() {
|
||||
return lineEndCount.getText();
|
||||
}
|
||||
|
||||
public void setLineEndCount(@NotNull String newText) {
|
||||
lineEndCount.setText(newText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,10 @@ 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;
|
||||
modified |= mySettingsComponent.getFromCall() != settings.fromCall;
|
||||
modified |= mySettingsComponent.getFromNew() != settings.fromNew;
|
||||
modified |= mySettingsComponent.getFromRef() != settings.fromRef;
|
||||
modified |= mySettingsComponent.getInJson() != settings.inJson;
|
||||
if (EditorColorsManager.getInstance().isDarkEditor()) {
|
||||
modified |= !mySettingsComponent.getLineEndColor().equals(settings.lineEndColorDark);
|
||||
} else {
|
||||
@@ -46,6 +47,8 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
modified |= mySettingsComponent.getFindElementRightToLeft() != settings.findElementRightToLeft;
|
||||
modified |= !mySettingsComponent.getLineEndInclude().equals(settings.lineEndInclude);
|
||||
modified |= !mySettingsComponent.getLineEndExclude().equals(settings.lineEndExclude);
|
||||
modified |= !mySettingsComponent.getLineEndPrefix().equals(settings.lineEndPrefix);
|
||||
modified |= !mySettingsComponent.getLineEndCount().equals(String.valueOf(settings.lineEndCount));
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -54,9 +57,10 @@ 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();
|
||||
settings.fromCall = mySettingsComponent.getFromCall();
|
||||
settings.fromNew = mySettingsComponent.getFromNew();
|
||||
settings.fromRef = mySettingsComponent.getFromRef();
|
||||
settings.inJson = mySettingsComponent.getInJson();
|
||||
if (EditorColorsManager.getInstance().isDarkEditor()) {
|
||||
settings.lineEndColorDark = mySettingsComponent.getLineEndColor();
|
||||
} else {
|
||||
@@ -69,6 +73,12 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
settings.lineEndExclude = mySettingsComponent.getLineEndExclude();
|
||||
settings.lineEndIncludeArray = SplitUtils.split(settings.lineEndInclude);
|
||||
settings.lineEndExcludeArray = SplitUtils.split(settings.lineEndExclude);
|
||||
settings.lineEndPrefix = mySettingsComponent.getLineEndPrefix();
|
||||
try {
|
||||
settings.lineEndCount = Integer.parseInt(mySettingsComponent.getLineEndCount());
|
||||
} catch (NumberFormatException e) {
|
||||
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,9 +86,10 @@ 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);
|
||||
mySettingsComponent.setFromCall(settings.fromCall);
|
||||
mySettingsComponent.setFromNew(settings.fromNew);
|
||||
mySettingsComponent.setFromRef(settings.fromRef);
|
||||
mySettingsComponent.setInJson(settings.inJson);
|
||||
if (EditorColorsManager.getInstance().isDarkEditor()) {
|
||||
mySettingsComponent.setLineEndColor(settings.lineEndColorDark);
|
||||
} else {
|
||||
@@ -87,6 +98,8 @@ public class AppSettingsConfigurable implements Configurable {
|
||||
mySettingsComponent.setFindElementRightToLeft(settings.findElementRightToLeft);
|
||||
mySettingsComponent.setLineEndInclude(settings.lineEndInclude);
|
||||
mySettingsComponent.setLineEndExclude(settings.lineEndExclude);
|
||||
mySettingsComponent.setLineEndPrefix(settings.lineEndPrefix);
|
||||
mySettingsComponent.setLineEndCount(String.valueOf(settings.lineEndCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,10 +21,6 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
||||
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);
|
||||
@SuppressWarnings("all")
|
||||
@@ -33,6 +29,13 @@ public class AppSettingsState implements PersistentStateComponent<AppSettingsSta
|
||||
null, null, null, Font.ITALIC);
|
||||
|
||||
public boolean findElementRightToLeft = true;
|
||||
public String lineEndPrefix = " //";
|
||||
public int lineEndCount = 2;
|
||||
public boolean fromCall = true;
|
||||
public boolean fromNew = true;
|
||||
public boolean fromRef = true;
|
||||
public boolean inJson = true;
|
||||
|
||||
public String lineEndInclude = "";
|
||||
public String lineEndExclude = "java.";
|
||||
public String[] lineEndIncludeArray = {};
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package io.github.linwancen.plugin.show.settings;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class JPanelFactory {
|
||||
|
||||
private JPanelFactory() {}
|
||||
|
||||
public static JPanel of(Component... components) {
|
||||
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
|
||||
for (Component component : components) {
|
||||
jPanel.add(component);
|
||||
}
|
||||
return jPanel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user