mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
Extracted line comment handling logic to base analyzer class
This commit is contained in:
+21
@@ -19,6 +19,9 @@ package com.itsaky.androidide.language.incremental;
|
||||
|
||||
import static com.itsaky.androidide.language.incremental.LineState.INCOMPLETE;
|
||||
import static com.itsaky.androidide.language.incremental.LineState.NORMAL;
|
||||
import static com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.FIXME_COMMENT;
|
||||
import static com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.TODO_COMMENT;
|
||||
import static com.itsaky.androidide.syntax.colorschemes.SchemeAndroidIDE.withoutCompletion;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -158,6 +161,24 @@ public abstract class BaseIncrementalAnalyzeManager
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleLineCommentSpan(
|
||||
@NonNull IncrementalToken token, @NonNull List<Span> spans, int offset) {
|
||||
var commentType = SchemeAndroidIDE.COMMENT;
|
||||
|
||||
// highlight special line comments
|
||||
var commentText = token.getText();
|
||||
if (commentText.length() > 2) {
|
||||
commentText = commentText.substring(2);
|
||||
commentText = commentText.trim();
|
||||
if ("todo".equalsIgnoreCase(commentText.substring(0, 4))) {
|
||||
commentType = TODO_COMMENT;
|
||||
} else if ("fixme".equalsIgnoreCase(commentText.substring(0, 5))) {
|
||||
commentType = FIXME_COMMENT;
|
||||
}
|
||||
}
|
||||
spans.add(Span.obtain(offset, withoutCompletion(commentType)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LineState getInitialState() {
|
||||
return new LineState();
|
||||
|
||||
@@ -41,8 +41,7 @@ import io.github.rosemoe.sora.text.Content
|
||||
import org.antlr.v4.runtime.CharStreams
|
||||
|
||||
/** @author Akash Yadav */
|
||||
class JavaAnalyzer :
|
||||
BaseIncrementalAnalyzeManager(JavaLexer(CharStreams.fromString(""))) {
|
||||
class JavaAnalyzer : BaseIncrementalAnalyzeManager(JavaLexer(CharStreams.fromString(""))) {
|
||||
|
||||
private val log = ILogger.newInstance(javaClass.simpleName)
|
||||
|
||||
@@ -175,36 +174,7 @@ class JavaAnalyzer :
|
||||
JavaLexer.LONG,
|
||||
JavaLexer.SHORT, -> spans.add(Span.obtain(offset, makeStyle(TYPE_NAME)))
|
||||
JavaLexer.BLOCK_COMMENT -> spans.add(Span.obtain(offset, forComment()))
|
||||
JavaLexer.LINE_COMMENT -> {
|
||||
var commentType = COMMENT
|
||||
|
||||
// highlight special line comments
|
||||
var commentText = token.text
|
||||
if (commentText.length > 2) {
|
||||
commentText = commentText.substring(2)
|
||||
commentText = commentText.trim { it <= ' ' }
|
||||
var mark = true
|
||||
if ("todo".equals(commentText.substring(0, 4), ignoreCase = true)) {
|
||||
commentType = TODO_COMMENT
|
||||
} else if ("fixme".equals(commentText.substring(0, 5), ignoreCase = true)) {
|
||||
commentType = FIXME_COMMENT
|
||||
} else {
|
||||
mark = false
|
||||
}
|
||||
if (mark) {
|
||||
// val diagnostic =
|
||||
// DiagnosticItem(
|
||||
// severity = WARNING,
|
||||
// message = commentText,
|
||||
// code = "special.comment",
|
||||
// range = Range(Position(0, offset), Position(0, offset + tokenLength)),
|
||||
// source = commentText
|
||||
// )
|
||||
// ideDiagnostics.add(diagnostic)
|
||||
}
|
||||
}
|
||||
spans.add(Span.obtain(offset, withoutCompletion(commentType)))
|
||||
}
|
||||
JavaLexer.LINE_COMMENT -> handleLineCommentSpan(token, spans, offset)
|
||||
JavaLexer.AT -> spans.add(Span.obtain(offset, makeStyle(ANNOTATION)))
|
||||
JavaLexer.IDENTIFIER -> {
|
||||
var colorId = TEXT_NORMAL
|
||||
@@ -220,7 +190,7 @@ class JavaAnalyzer :
|
||||
|
||||
return spans
|
||||
}
|
||||
|
||||
|
||||
override fun getMultilineTokenStartEndTypes(): Array<IntArray> {
|
||||
val start = intArrayOf(JavaLexer.DIV, JavaLexer.MUL)
|
||||
val end = intArrayOf(JavaLexer.MUL, JavaLexer.DIV)
|
||||
|
||||
Reference in New Issue
Block a user