delete old impl

This commit is contained in:
林万程
2022-10-23 19:34:30 +08:00
parent 432e58d658
commit 032b50b23f
9 changed files with 3 additions and 592 deletions

View File

@@ -40,23 +40,9 @@ public class JavaTree {
return dirDoc(psiDirectory);
}
// if (node instanceof PsiMethodNode) {
// // On Show Members
// PsiMethod psiMethod = ((PsiMethodNode) node).getValue();
// PsiDocComment psiDocComment = OwnerToPsiDocUtils.methodDoc(psiMethod);
// if (psiDocComment != null) {
// System.out.println("PsiMethodNode" + PsiDocToStrDoc.text(psiDocComment, true));
// }
// return psiDocComment;
// }
if (node instanceof PsiFieldNode) {
// On Show Members
PsiField psiField = ((PsiFieldNode) node).getValue();
// PsiDocComment docComment = OwnerToPsiDocUtils.srcOrByteCodeDoc(psiField);
// if (docComment != null) {
// System.out.println("PsiFieldNode" + PsiDocToStrDoc.text(docComment, true));
// return docComment;
// }
// for @Autowire Bean
PsiType type = psiField.getType();
if (type instanceof PsiClassReferenceType) {
@@ -66,15 +52,6 @@ public class JavaTree {
}
}
// if (node instanceof ClassTreeNode) {
// // On Packages View, Project Files View, Show Members
// PsiClass psiClass = ((ClassTreeNode) node).getValue();
// PsiDocComment psiDocComment = OwnerToPsiDocUtils.srcOrByteCodeDoc(psiClass);
// if (psiDocComment != null) {
// System.out.println("ClassTreeNode" + PsiDocToStrDoc.text(psiDocComment, true));
// }
// return psiDocComment;
// }
if (node instanceof PackageElementNode) {
// On Packages View
PsiPackage psiPackage = ((PackageElementNode) node).getValue().getPackage();

View File

@@ -1,104 +0,0 @@
package io.github.linwancen.plugin.show.java.doc;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.javadoc.*;
import io.github.linwancen.plugin.show.lang.base.DocFilter;
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.Pattern;
/**
* @deprecated BaseTagLangDoc
*/
public class PsiDocToStrDoc {
private PsiDocToStrDoc() {}
@Nullable
public static String text(@Nullable PsiDocComment psiDocComment, boolean isTree) {
if (psiDocComment == null) {
return null;
}
AppSettingsState appSettings = AppSettingsState.getInstance();
int lineCount = 0;
// JavaLangDoc.descDoc
StringBuilder sb = new StringBuilder();
PsiElement[] elements = psiDocComment.getDescriptionElements();
for (PsiElement element : elements) {
if (appendElementText(sb, element)) {
lineCount++;
}
boolean countOver = appSettings.lineEndCount > 0 && lineCount >= appSettings.lineEndCount;
boolean lenOver = appSettings.lineEndLen > 0 && sb.length() >= appSettings.lineEndLen;
if (countOver || lenOver) {
break;
}
}
StringBuilder tags = tags(psiDocComment, isTree, appSettings);
// BaseTagLangDoc.docElementToStr
if (tags.length() > 0) {
if (sb.length() > 0) {
sb.append("@ ");
}
sb.append(tags);
}
String text = sb.toString();
if (text.trim().length() == 0) {
return null;
}
ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(psiDocComment.getProject());
return DocFilter.filterDoc(text, appSettings, projectSettings);
}
@NotNull
private static StringBuilder tags(@NotNull PsiDocComment psiDocComment, boolean isTree,
AppSettingsState appSettings) {
// JavaLangDoc.descDoc
StringBuilder sb = new StringBuilder();
String[] names = isTree ? appSettings.treeTags : appSettings.lineTags;
for (String name : names) {
PsiDocTag[] tags = psiDocComment.findTagsByName(name);
for (PsiDocTag tag : tags) {
// @see @param should use getDataElements()
PsiDocTagValue value = tag.getValueElement();
if (value != null) {
addHtml(sb, value.getText());
}
}
}
return sb;
}
/**
* @return is new line
*/
private static boolean appendElementText(StringBuilder sb, PsiElement element) {
// JavaLangDoc.appendElementText
if (element instanceof PsiDocToken) {
PsiDocToken psiDocToken = (PsiDocToken) element;
addHtml(sb, psiDocToken.getText());
}
if (element instanceof PsiInlineDocTag) {
PsiInlineDocTag psiInlineDocTag = (PsiInlineDocTag) element;
PsiElement[] children = psiInlineDocTag.getChildren();
if (children.length > 3) {
addHtml(sb, children[3].getText());
}
}
return element instanceof PsiWhiteSpace && sb.length() > 0;
}
private static final Pattern HTML_PATTERN = Pattern.compile("<[^>]++>");
private static void addHtml(StringBuilder sb, String s) {
// DocFilter.addHtml
String deleteHtml = HTML_PATTERN.matcher(s.trim()).replaceAll("");
if (deleteHtml.length() > 0) {
sb.append(deleteHtml).append(" ");
}
}
}

View File

@@ -1,92 +0,0 @@
package io.github.linwancen.plugin.show.java.line;
import com.intellij.openapi.editor.Document;
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.javadoc.PsiDocComment;
import io.github.linwancen.plugin.show.java.doc.PsiDocToStrDoc;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* call LineExt, ~LeftToRight, ~RightToLeft
* @deprecated JavaLangDoc
*/
public class FileViewToDocStrUtils {
private FileViewToDocStrUtils() {}
/**
* From Ext Or PsiDoc
*/
@Nullable
public static String doc(@NotNull Document document,
@Nullable Project project,
@Nullable VirtualFile file,
@Nullable FileViewProvider viewProvider,
int startOffset, int endOffset, @NotNull String text) {
AppSettingsState setting = AppSettingsState.getInstance();
if (file != null) {
int i = text.indexOf(setting.lineEndPrefix);
String code = i <= 0 ? text : text.substring(0, i);
String extDoc = "LineExt.extDoc(project, file.getPath(), file.getName(), file.getExtension(), code)";
if (extDoc != null) {
extDoc = extDoc.trim();
// LineEnd.lineDocSkipHave
if (text.endsWith(extDoc)) {
return null;
}
return extDoc;
}
}
if (viewProvider == null) {
return null;
}
PsiDocComment docComment = setting.findElementRightToLeft
? FileViewToPsiDocRightToLeft.rightDoc(viewProvider, startOffset, endOffset)
: FileViewToPsiDocLeftToRight.leftDoc(viewProvider, document, startOffset, endOffset);
String strDoc = PsiDocToStrDoc.text(docComment, false);
if (strDoc == null) {
return null;
}
strDoc = strDoc.trim();
if (text.endsWith(strDoc)) {
return null;
}
return strDoc;
}
@NotNull
public static String textWithDoc(@NotNull AppSettingsState settings, @NotNull Document document,
int startLine, int endLine,
@Nullable Project project,
@Nullable VirtualFile file,
@Nullable FileViewProvider viewProvider) {
// textWithDoc
StringBuilder sb = new StringBuilder();
for (int i = startLine; i <= endLine; i++) {
int startOffset;
int endOffset;
try {
startOffset = document.getLineStartOffset(i);
endOffset = document.getLineEndOffset(i);
} catch (Exception e) {
continue;
}
if (startOffset != endOffset) {
String text = document.getText(new TextRange(startOffset, endOffset));
sb.append(text);
String doc = doc(document, project, file, viewProvider, startOffset, endOffset, text);
if (doc != null && !text.endsWith(doc)) {
sb.append(settings.lineEndPrefix).append(doc);
}
}
sb.append("\n");
}
sb.delete(sb.length() - 1, sb.length());
return sb.toString();
}
}

View File

@@ -1,83 +0,0 @@
package io.github.linwancen.plugin.show.java.line;
import com.intellij.json.JsonLanguage;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.TextRange;
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.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* call JsonToPsiDoc, NewCallRefToPsiDoc
* @deprecated JavaLangDoc
*/
public class FileViewToPsiDocLeftToRight {
private FileViewToPsiDocLeftToRight() {}
static final String[] KEYS = {
"=",
};
@Nullable
public static PsiDocComment leftDoc(@NotNull FileViewProvider viewProvider, @NotNull Document document,
int startOffset, int endOffset) {
String text = document.getText(new TextRange(startOffset, endOffset));
int offset = 0;
for (String s : KEYS) {
int i = text.indexOf(s);
if (i > 0) {
offset += (i + s.length());
break;
}
}
text = text.substring(offset);
boolean startWithSymbol = false;
char[] chars = text.toCharArray();
// skip symbol and space
for (char c : chars) {
if (Character.isLetter(c)) {
break;
}
if (!Character.isSpaceChar(c)) {
startWithSymbol = true;
}
offset++;
}
offset += startOffset;
PsiElement element = viewProvider.findElementAt(offset);
if (element == null) {
return null;
}
AppSettingsState instance = AppSettingsState.getInstance();
if (instance.showLineEndCommentJson && element.getLanguage().is(JsonLanguage.INSTANCE)) {
return JsonToPsiDoc.jsonDoc(element, startOffset, endOffset);
}
if (startWithSymbol) {
startOffset = 0;
}
return nextDoc(element, startOffset, endOffset);
}
@Nullable
private static PsiDocComment nextDoc(@NotNull PsiElement element, int startOffset, int endOffset) {
while (element.getTextRange().getEndOffset() <= endOffset) {
if (element instanceof PsiIdentifier) {
PsiDocComment psiDocComment = NewCallRefToPsiDoc.elementDoc(element, element, startOffset, endOffset);
if (psiDocComment != null) {
return psiDocComment;
}
}
element = PsiTreeUtil.nextVisibleLeaf(element);
if (element == null) {
return null;
}
}
return null;
}
}

View File

@@ -1,57 +0,0 @@
package io.github.linwancen.plugin.show.java.line;
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.settings.AppSettingsState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* call JsonToPsiDoc, NewCallRefToPsiDoc
* @deprecated JavaLangDoc
*/
public class FileViewToPsiDocRightToLeft {
private FileViewToPsiDocRightToLeft() {}
@Nullable
public static PsiDocComment rightDoc(@NotNull FileViewProvider viewProvider, int startOffset, int endOffset) {
// End is always white, can not -1 because @see class.name need it
PsiElement element = viewProvider.findElementAt(endOffset);
if (element == null) {
// one line end
return null;
}
AppSettingsState setting = AppSettingsState.getInstance();
while (true) {
PsiElement identifier = PsiTreeUtil.prevVisibleLeaf(element);
if (identifier != null && identifier.getTextRange().getStartOffset() < startOffset) {
identifier = null;
}
PsiDocComment docComment = psiDoc(setting, identifier, element, startOffset, endOffset);
if (docComment != null) {
return docComment;
}
if (identifier == null) {
return null;
}
element = identifier;
}
}
private static PsiDocComment psiDoc(AppSettingsState setting,
PsiElement identifier, PsiElement element,
int startOffset, int endOffset) {
if (identifier != null && !(identifier instanceof PsiIdentifier)) {
return null;
}
if (setting.showLineEndCommentJson && element.getLanguage().is(JsonLanguage.INSTANCE)) {
return JsonToPsiDoc.jsonDoc(element, startOffset, endOffset);
}
return NewCallRefToPsiDoc.elementDoc(element, identifier, startOffset, endOffset);
}
}

View File

@@ -1,46 +0,0 @@
package io.github.linwancen.plugin.show.java.line;
import com.intellij.json.psi.JsonProperty;
import com.intellij.psi.PsiDocCommentOwner;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiTreeUtil;
import io.github.linwancen.plugin.show.java.doc.OwnerToPsiDocUtils;
import org.jetbrains.annotations.Nullable;
/**
* @deprecated JsonLangDoc
*/
public class JsonToPsiDoc {
private JsonToPsiDoc() {}
/**
* depend on JsonJump
*/
@Nullable
public static PsiDocComment jsonDoc(PsiElement element, int startOffset, int endOffset) {
// JsonLangDoc.refDoc
JsonProperty jsonProp = PsiTreeUtil.getParentOfType(element, JsonProperty.class, true, startOffset);
if (jsonProp == null || jsonProp.getNameElement().getTextRange().getEndOffset() > endOffset) {
return null;
}
for (PsiReference reference : jsonProp.getNameElement().getReferences()) {
PsiElement resolve = null;
try {
resolve = reference.resolve();
} catch (Throwable ignore) {
// ignore
}
if (resolve instanceof PsiDocCommentOwner) {
PsiDocCommentOwner owner = (PsiDocCommentOwner) resolve;
PsiDocComment docComment = OwnerToPsiDocUtils.srcOrByteCodeDoc(owner);
if (docComment != null) {
return docComment;
}
}
}
return null;
}
}

View File

@@ -1,12 +1,9 @@
package io.github.linwancen.plugin.show.java.line;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
import com.intellij.psi.PsiDocCommentOwner;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaCodeReferenceElement;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.util.PsiTreeUtil;
import io.github.linwancen.plugin.show.java.doc.OwnerToPsiDocUtils;
import io.github.linwancen.plugin.show.settings.AppSettingsState;
import io.github.linwancen.plugin.show.settings.ProjectSettingsState;
import org.jetbrains.annotations.Nullable;
/**
@@ -16,150 +13,6 @@ public class NewCallRefToPsiDoc {
private NewCallRefToPsiDoc() {}
/**
* @deprecated
*/
@Nullable
static PsiDocComment elementDoc(PsiElement element, PsiElement psiIdentifier,
int startOffset, int endOffset) {
// JavaLangDoc.refDoc
AppSettingsState instance = AppSettingsState.getInstance();
if (psiIdentifier != null && "Override".equals(psiIdentifier.getText())) {
ProjectSettingsState projectSettings = ProjectSettingsState.getInstance(psiIdentifier.getProject());
PsiMethod psiMethod = PsiTreeUtil.getParentOfType(psiIdentifier, PsiMethod.class);
if (psiMethod == null) {
return null;
}
PsiDocComment docComment = OwnerToPsiDocUtils.supperMethodDoc(psiMethod);
return SkipUtils.skipDoc(docComment, instance, projectSettings);
}
if (element != null) {
PsiDocComment elementDoc = elementDoc(element, startOffset, endOffset, instance);
if (elementDoc != null) {
return elementDoc;
}
}
if (instance.fromRef) {
return refDoc(psiIdentifier, endOffset);
}
return null;
}
/**
* @deprecated
*/
@Nullable
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;
}
}
// JavaLangDoc.refDoc
if (instance.fromNew) {
PsiDocComment newDoc = parentNewDoc(element, startOffset);
if (newDoc != null) {
return newDoc;
}
}
if (instance.fromRef) {
return docRefDoc(element);
}
return null;
}
/**
* @deprecated
*/
@Nullable
private static PsiDocComment parentMethodDoc(PsiElement element, int startOffset, int endOffset) {
// method call
// JavaLangDoc.resolveDocPrint
PsiMethodCallExpression call =
PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class, false, startOffset);
if (call == null) {
return null;
}
if ((call.getNode().getStartOffset() + call.getNode().getTextLength()) > endOffset) {
return null;
}
try {
PsiDocComment methodComment = OwnerToPsiDocSkip.refDoc(call.resolveMethod());
if (methodComment != null) {
return methodComment;
}
} catch (Throwable ignored) {
// ignored
}
return null;
}
/**
* @deprecated
*/
@Nullable
private static PsiDocComment parentNewDoc(PsiElement element, int startOffset) {
// new and Class should same line, so not need if endOffset
PsiNewExpression newExp = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false, startOffset);
if (newExp == null) {
return null;
}
try {
PsiDocComment methodComment = OwnerToPsiDocSkip.refDoc(newExp.resolveMethod());
if (methodComment != null) {
return methodComment;
}
} catch (Throwable ignore) {
// ignore
}
PsiJavaCodeReferenceElement classReference = newExp.getClassReference();
return javaCodeDoc(classReference);
}
/**
* ::/class/field
* @deprecated
*/
@Nullable
private static PsiDocComment refDoc(PsiElement element, int endOffset) {
if (element == null) {
return null;
}
// while for xx.xx.xx... when left to right, only once when right to left
PsiElement parent;
while ((parent = element.getParent()) instanceof PsiReference) {
if (parent.getTextRange().getEndOffset() > endOffset) {
break;
}
element = parent;
}
if (element instanceof PsiReference) {
PsiElement resolve = null;
try {
resolve = ((PsiReference) element).resolve();
} catch (Throwable ignore) {
// ignore
}
if (resolve instanceof PsiDocCommentOwner) {
return OwnerToPsiDocSkip.refDoc(((PsiDocCommentOwner) resolve));
}
}
// for right to left for
if (parent instanceof PsiForeachStatement) {
PsiParameter iterationParameter = ((PsiForeachStatement) parent).getIterationParameter();
PsiTypeElement typeElement = iterationParameter.getTypeElement();
if (typeElement == null) {
return null;
}
PsiJavaCodeReferenceElement ref = typeElement.getInnermostComponentReferenceElement();
return javaCodeDoc(ref);
}
return null;
}
@Nullable
public static PsiDocComment javaCodeDoc(PsiJavaCodeReferenceElement ref) {
if (ref == null) {
@@ -176,34 +29,4 @@ public class NewCallRefToPsiDoc {
}
return null;
}
/**
* @deprecated
*/
@Nullable
private static PsiDocComment docRefDoc(PsiElement element) {
PsiElement parent = element.getParent();
if (parent instanceof PsiDocMethodOrFieldRef) {
element = parent;
}
if (element instanceof PsiDocMethodOrFieldRef) {
PsiReference reference = element.getReference();
if (reference == null) {
return null;
}
PsiElement resolve = null;
try {
resolve = reference.resolve();
} catch (Throwable ignore) {
// ignore
}
if (resolve instanceof PsiMethod) {
return OwnerToPsiDocSkip.refDoc(((PsiMethod) resolve));
}
if (resolve instanceof PsiDocCommentOwner) {
return OwnerToPsiDocSkip.refDoc(((PsiDocCommentOwner) resolve));
}
}
return null;
}
}

View File

@@ -23,8 +23,6 @@ class ConfFactory {
private static final Map<String, Pattern> PATTERN_CACHE = new ConcurrentHashMap<>();
private static final NotificationGroup REGEXP_LOG =
new NotificationGroup("Ext Doc Keyword Regexp Compile", NotificationDisplayType.TOOL_WINDOW, true);
private static final NotificationGroup DATA_LOG =
new NotificationGroup("Ext Doc Data", NotificationDisplayType.BALLOON, true);
private ConfFactory() {}

View File

@@ -43,16 +43,11 @@ public class AppSettingsState extends AbstractSettingsState implements Persisten
public final TextAttributes lineEndJsonTextAttr = new TextAttributes(new JBColor(Gray._140, Gray._140),
null, null, null, Font.ITALIC);
public boolean findElementRightToLeft = true;
public String lineEndPrefix = " // ";
public int lineEndCount = 2;
public int lineEndLen = 0;
public boolean getToSet = true;
@Deprecated
public boolean fromCall = true;
public boolean fromNew = true;
@Deprecated
public boolean fromRef = true;
public boolean fromParam = false;
public boolean skipAnnotation = true;
public boolean skipAscii = !"en".equals(Locale.getDefault().getLanguage());