fix: un save text
This commit is contained in:
@@ -27,6 +27,7 @@ import io.github.linwancen.plugin.show.java.line.OwnerToPsiDocSkip;
|
||||
import io.github.linwancen.plugin.show.java.line.SkipUtils;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseTagLangDoc;
|
||||
import io.github.linwancen.plugin.show.lang.base.DocFilter;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -58,7 +59,7 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
|
||||
|
||||
@Override
|
||||
protected @Nullable String refDoc(@NotNull LineInfo info, @NotNull PsiElement ref) {
|
||||
if ("Override".equals(ref.getText())) {
|
||||
if ("Override".equals(info.getText(ref))) {
|
||||
@Nullable PsiMethod psiMethod = PsiTreeUtil.getParentOfType(ref, PsiMethod.class);
|
||||
if (psiMethod == null) {
|
||||
return null;
|
||||
@@ -154,11 +155,11 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
|
||||
@NotNull PsiElement[] children = element.getChildren();
|
||||
if (children.length > 0) {
|
||||
if (children.length >= 3) {
|
||||
DocFilter.addHtml(sb, children[children.length - 2].getText());
|
||||
DocFilter.addHtml(sb, PsiUnSaveUtils.getText(children[children.length - 2]));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
DocFilter.addHtml(sb, element.getText());
|
||||
DocFilter.addHtml(sb, PsiUnSaveUtils.getText(element));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -169,11 +170,11 @@ public class JavaLangDoc extends BaseTagLangDoc<PsiDocComment> {
|
||||
for (@NotNull PsiDocTag tag : tags) {
|
||||
@Nullable PsiDocTagValue value = tag.getValueElement();
|
||||
if (value != null) {
|
||||
DocFilter.addHtml(tagStrBuilder, value.getText());
|
||||
DocFilter.addHtml(tagStrBuilder, PsiUnSaveUtils.getText(value));
|
||||
} else {
|
||||
@NotNull PsiElement[] dataElements = tag.getDataElements();
|
||||
if (dataElements.length > 0) {
|
||||
DocFilter.addHtml(tagStrBuilder, dataElements[0].getText());
|
||||
DocFilter.addHtml(tagStrBuilder, PsiUnSaveUtils.getText(dataElements[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.java.line.OwnerToPsiDocSkip;
|
||||
import io.github.linwancen.plugin.show.lang.base.DocFilter;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.scala.ScalaLanguage;
|
||||
@@ -58,7 +59,7 @@ public class ScalaLangDoc extends JavaLangDoc {
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
for (@NotNull PsiElement element : elements) {
|
||||
if (!(element instanceof PsiDocTag)) {
|
||||
sb.append(element.getText());
|
||||
sb.append(PsiUnSaveUtils.getText(element));
|
||||
}
|
||||
}
|
||||
return DocFilter.cutDoc(sb.toString(), info, true);
|
||||
@@ -72,7 +73,7 @@ public class ScalaLangDoc extends JavaLangDoc {
|
||||
for (@NotNull PsiDocTag tag : tags) {
|
||||
if (tag instanceof ScDocTag) {
|
||||
@NotNull ScDocTag scDocTag = (ScDocTag) tag;
|
||||
String doc = scDocTag.getText();
|
||||
String doc = PsiUnSaveUtils.getText(scDocTag);
|
||||
doc = doc.replace(key, "");
|
||||
DocFilter.addHtml(tagStrBuilder, doc);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.linwancen.plugin.show.java.doc;
|
||||
import com.intellij.psi.PsiEnumConstant;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiExpressionList;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -27,7 +28,7 @@ public class EnumDoc {
|
||||
return null;
|
||||
}
|
||||
return Arrays.stream(exps)
|
||||
.map(exp -> exp.getText().replace("\"", ""))
|
||||
.map(exp -> PsiUnSaveUtils.getText(exp).replace("\"", ""))
|
||||
.collect(Collectors.joining("-"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.javadoc.PsiDocTagValue;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -28,10 +29,10 @@ public class ParamDoc {
|
||||
@NotNull PsiDocTag[] params = psiDocComment.findTagsByName("param");
|
||||
for (@NotNull PsiDocTag param : params) {
|
||||
@Nullable PsiDocTagValue value = param.getValueElement();
|
||||
if (value != null && name.equals(value.getText())) {
|
||||
if (value != null && name.equals(PsiUnSaveUtils.getText(value))) {
|
||||
@NotNull PsiElement[] dataElements = param.getDataElements();
|
||||
if (dataElements.length > 1) {
|
||||
return dataElements[1].getText();
|
||||
return PsiUnSaveUtils.getText(dataElements[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.linwancen.plugin.show.java.kt;
|
||||
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseAnnoDoc;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
@@ -70,7 +71,7 @@ public class AnnoDocKt extends BaseAnnoDoc<KtAnnotated> {
|
||||
if (arr[2].equals(method)) {
|
||||
KtExpression expression = argument.getArgumentExpression();
|
||||
if (expression instanceof KtStringTemplateExpression) {
|
||||
String text = expression.getText();
|
||||
String text = PsiUnSaveUtils.getText(expression);
|
||||
if (text.length() >= 2) {
|
||||
String s = text.substring(1, text.length() - 1);
|
||||
if (!s.isEmpty()) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import io.github.linwancen.plugin.show.bean.FuncEnum;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.lang.base.DocSkip;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -60,7 +61,7 @@ public class SkipUtils {
|
||||
if (info.appSettings.skipBlank && isBlank(doc)) {
|
||||
return null;
|
||||
}
|
||||
String text = doc.getText();
|
||||
String text = PsiUnSaveUtils.getText(doc);
|
||||
boolean skip = DocSkip.skipDoc(info, text);
|
||||
return skip ? null : doc;
|
||||
}
|
||||
@@ -68,7 +69,7 @@ public class SkipUtils {
|
||||
private static boolean isBlank(@NotNull PsiDocComment doc) {
|
||||
@NotNull PsiElement[] elements = doc.getDescriptionElements();
|
||||
for (@NotNull PsiElement element : elements) {
|
||||
String text = element.getText();
|
||||
String text = PsiUnSaveUtils.getText(element);
|
||||
if (StringUtils.isNotBlank(text)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.FileViewProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -53,4 +55,15 @@ public class FileInfo extends SettingsInfo {
|
||||
@NotNull Project project = psiFile.getProject();
|
||||
return new FileInfo(file, document, project, FuncEnum.LINE);
|
||||
}
|
||||
|
||||
public String getText(PsiElement element) {
|
||||
try {
|
||||
TextRange range = element.getTextRange();
|
||||
int startOffset = range.getStartOffset();
|
||||
int endOffset = range.getEndOffset();
|
||||
return document.getText().substring(startOffset, endOffset);
|
||||
} catch (Exception ignored) {
|
||||
return element.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.ext.listener.FileLoader;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import io.github.linwancen.plugin.show.lang.vue.VueRouterCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -76,6 +77,6 @@ public class JsLangDoc extends BaseLangDoc {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return psiComment.getText();
|
||||
return PsiUnSaveUtils.getText(psiComment);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class JsonLangDoc extends BaseLangDoc {
|
||||
}
|
||||
@NotNull GlobalSearchScope scope = GlobalSearchScope.allScope(info.project);
|
||||
@NotNull String jsonKey = prop.getName();
|
||||
String jsonValue = value.getText();
|
||||
String jsonValue = info.getText(value);
|
||||
// Read the json.path before if needed
|
||||
@Nullable String dictDoc = jsonDictDoc(info, scope, jsonKey, jsonValue);
|
||||
if (dictDoc != null) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseTagLangDoc;
|
||||
import io.github.linwancen.plugin.show.lang.base.DocFilter;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -47,7 +48,7 @@ public class PhpLangDoc extends BaseTagLangDoc<PhpDocComment> {
|
||||
for (PsiElement child : children) {
|
||||
@Nullable PsiComment comment = PsiTreeUtil.getChildOfType(child, PsiComment.class);
|
||||
if (comment != null) {
|
||||
String text = comment.getText();
|
||||
String text = PsiUnSaveUtils.getText(comment);
|
||||
return DocFilter.cutDoc(text, info, true);
|
||||
}
|
||||
}
|
||||
@@ -74,7 +75,7 @@ public class PhpLangDoc extends BaseTagLangDoc<PhpDocComment> {
|
||||
@NotNull
|
||||
@Override
|
||||
protected <T extends SettingsInfo> String descDoc(@NotNull T info, @NotNull PhpDocComment phpDocComment) {
|
||||
String text = phpDocComment.getText();
|
||||
String text = PsiUnSaveUtils.getText(phpDocComment);
|
||||
return DocFilter.cutDoc(text, info, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.psi.xml.XmlTag;
|
||||
import io.github.linwancen.plugin.show.bean.LineInfo;
|
||||
import io.github.linwancen.plugin.show.bean.SettingsInfo;
|
||||
import io.github.linwancen.plugin.show.lang.base.BaseLangDoc;
|
||||
import io.github.linwancen.plugin.show.lang.base.PsiUnSaveUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class XmlLangDoc extends BaseLangDoc {
|
||||
return null;
|
||||
}
|
||||
PsiElement psiElement = viewProvider.findElementAt(0);
|
||||
if (psiElement == null || !"<!--".equals(psiElement.getText())) {
|
||||
if (psiElement == null || !"<!--".equals(PsiUnSaveUtils.getText(psiElement))) {
|
||||
Document document = viewProvider.getDocument();
|
||||
if (document == null) {
|
||||
return null;
|
||||
@@ -62,7 +63,7 @@ public class XmlLangDoc extends BaseLangDoc {
|
||||
int i = document.getLineStartOffset(1);
|
||||
psiElement = viewProvider.findElementAt(i);
|
||||
}
|
||||
if (psiElement == null || !"<!--".equals(psiElement.getText())) {
|
||||
if (psiElement == null || !"<!--".equals(PsiUnSaveUtils.getText(psiElement))) {
|
||||
return null;
|
||||
}
|
||||
PsiElement parent = psiElement.getParent();
|
||||
@@ -73,7 +74,7 @@ public class XmlLangDoc extends BaseLangDoc {
|
||||
if (children.length < 2) {
|
||||
return null;
|
||||
}
|
||||
String doc = children[1].getText();
|
||||
String doc = PsiUnSaveUtils.getText(children[1]);
|
||||
// Copyright or copyright
|
||||
//noinspection SpellCheckingInspection
|
||||
if (doc == null || doc.contains("opyright")) {
|
||||
|
||||
@@ -106,7 +106,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
@Nullable String filterDoc = refElementDoc(info, parent);
|
||||
if (filterDoc != null) {
|
||||
doc = filterDoc;
|
||||
text = refElement.getText();
|
||||
text = info.getText(refElement);
|
||||
refElement = parent;
|
||||
break;
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public abstract class BaseLangDoc extends EditorLinePainter {
|
||||
PsiElement parent = beforeRefElement.getParent();
|
||||
@Nullable String beforeDoc = refElementDoc(info, parent);
|
||||
if (beforeDoc != null) {
|
||||
doc = MergeDoc.mergeDoc(beforeRefElement.getText(), text, beforeDoc, doc, info.appSettings.getToSet);
|
||||
doc = MergeDoc.mergeDoc(info.getText(beforeRefElement), text, beforeDoc, doc, info.appSettings.getToSet);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Prev {
|
||||
@Nullable
|
||||
private static PsiElement refClassParent(@NotNull PsiElement element,
|
||||
@NotNull List<Class<? extends PsiElement>> refClass) {
|
||||
String text = element.getText();
|
||||
String text = PsiUnSaveUtils.getText(element);
|
||||
if (!SYMBOL_PATTERN.matcher(text).find()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package io.github.linwancen.plugin.show.lang.base;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
|
||||
public class PsiUnSaveUtils {
|
||||
|
||||
public static String getText(PsiElement element) {
|
||||
try {
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(element.getProject());
|
||||
if (documentManager == null) {
|
||||
return element.getText();
|
||||
}
|
||||
if (element instanceof PsiFile) {
|
||||
Document document = documentManager.getDocument(((PsiFile) element));
|
||||
if (document == null) {
|
||||
return element.getText();
|
||||
}
|
||||
return document.getText();
|
||||
}
|
||||
PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile == null) {
|
||||
return element.getText();
|
||||
}
|
||||
Document document = documentManager.getDocument(containingFile);
|
||||
if (document == null) {
|
||||
return element.getText();
|
||||
}
|
||||
return document.getText(element.getTextRange());
|
||||
} catch (Exception ignored) {
|
||||
return element.getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class ResolveDoc {
|
||||
if (lineNumber != docLineNumber) {
|
||||
return null;
|
||||
}
|
||||
return docElement.getText();
|
||||
return PsiUnSaveUtils.getText(docElement);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -74,7 +74,7 @@ public class ResolveDoc {
|
||||
}
|
||||
if (!keywords.isEmpty()) {
|
||||
while (psiElement != null) {
|
||||
String text = psiElement.getText();
|
||||
String text = PsiUnSaveUtils.getText(psiElement);
|
||||
if (keywords.contains(text)) {
|
||||
psiElement = Prev.prevCompactElement(info, psiElement, document);
|
||||
} else {
|
||||
@@ -85,7 +85,7 @@ public class ResolveDoc {
|
||||
@NotNull StringBuilder sb = new StringBuilder();
|
||||
boolean isComment = psiElement instanceof PsiComment;
|
||||
while (isComment) {
|
||||
String text = psiElement.getText();
|
||||
String text = PsiUnSaveUtils.getText(psiElement);
|
||||
int thisStartOffset = psiElement.getTextRange().getStartOffset();
|
||||
psiElement = Prev.prevCompactElement(info, psiElement, document);
|
||||
isComment = psiElement instanceof PsiComment;
|
||||
|
||||
Reference in New Issue
Block a user