1.5 Support find next loop when not comment | 支持没有注释时循环查找下一个对象

This commit is contained in:
林万程
2022-02-27 15:08:48 +08:00
parent 89a0c1cd60
commit 4789827a8b
7 changed files with 42 additions and 22 deletions

View File

@@ -23,4 +23,4 @@ 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 when not comment | 支持没有注释时查找下一个对象
- 1.5 Support find next loop when not comment | 支持没有注释时循环查找下一个对象

View File

@@ -42,7 +42,7 @@ patchPluginXml {
<li>1.2 Add end-of-line comment class prefix filter settings | 添加行末注释类前缀配置
<li>1.3 Support class in tree, constructor and field type in line end | 支持 class 树节点、构造方法和字段的行末注释
<li>1.4 Find element right to left for end-of-line comment | 从右往左查找行末注释对象
<li>1.5 Support find next when not comment | 支持没有注释时查找下一个对象
<li>1.5 Support find next loop when not comment | 支持没有注释时循环查找下一个对象
</ul>
"""
}

View File

@@ -50,7 +50,8 @@ public class LineEnd extends EditorLinePainter {
if (document == null) {
return null;
}
if (document.getLineCount() < lineNumber) {
// lineNumber start 0, as 1 <= 1 should return
if (document.getLineCount() <= lineNumber) {
return null;
}
int startOffset = document.getLineStartOffset(lineNumber);

View File

@@ -48,21 +48,20 @@ public class LineDocLeftToRightUtils {
startOffset = 0;
}
PsiElement element = viewProvider.findElementAt(offset, JavaLanguage.INSTANCE);
PsiIdentifier psiIdentifier = leftIdentifier(element, endOffset);
return LineDocUtils.elementDoc(psiIdentifier, psiIdentifier, startOffset, endOffset);
return nextDoc(element, startOffset, endOffset);
}
@Nullable
private static PsiIdentifier leftIdentifier(PsiElement element, int endOffset) {
if (element == null) {
return null;
}
while (!(element instanceof PsiIdentifier)) {
element = PsiTreeUtil.nextVisibleLeaf(element);
if (element == null || element.getTextRange().getEndOffset() > endOffset) {
return null;
private static PsiDocComment nextDoc(PsiElement element, int startOffset, int endOffset) {
while (element != null && element.getTextRange().getEndOffset() < endOffset) {
if (element instanceof PsiIdentifier) {
PsiDocComment psiDocComment = LineDocUtils.elementDoc(element, element, startOffset, endOffset);
if (psiDocComment != null) {
return psiDocComment;
}
}
element = PsiTreeUtil.nextVisibleLeaf(element);
}
return (PsiIdentifier) element;
return null;
}
}

View File

@@ -20,16 +20,22 @@ public class LineDocRightToLeftUtils {
return null;
}
PsiElement identifier;
while (!((identifier = PsiTreeUtil.prevVisibleLeaf(element)) instanceof PsiIdentifier)) {
if (identifier == null || identifier.getTextRange().getStartOffset() < startOffset) {
break;
PsiDocComment psiDocComment;
while (true) {
identifier = PsiTreeUtil.prevVisibleLeaf(element);
if (identifier != null && identifier.getTextRange().getStartOffset() < startOffset) {
identifier = null;
}
if (identifier == null || identifier instanceof PsiIdentifier) {
psiDocComment = LineDocUtils.elementDoc(element, identifier, startOffset, endOffset);
if (psiDocComment != null) {
return psiDocComment;
}
}
if (identifier == null) {
return null;
}
element = identifier;
}
// if in prev line, set it null.
if (identifier != null && identifier.getTextRange().getStartOffset() < startOffset) {
identifier = null;
}
return LineDocUtils.elementDoc(element, identifier, startOffset, endOffset);
}
}

View File

@@ -0,0 +1,11 @@
package io.github.linwancen.plugin.show.demo;
import io.github.linwancen.plugin.show.demo.method.Child;
public class Next {
public static void method() {
Child child = new Child(true);
child.haveNotDoc(null).haveNotDoc(new Child()).haveNotDoc(null);
child.haveNotDoc(null).getField().haveNotDoc(null);
}
}

View File

@@ -34,6 +34,9 @@ public class Child extends Parent implements Face {
return null;
}
public Child haveNotDoc(Face face) {
return null;
}
/**
* bool