mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[evaluation-plugin] check correctness of collected tokens after traversing step (ML-2950)
GitOrigin-RevId: aa1a2d2a685f9fc9c1441303406d6cd74bd0619c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e90b9f9c64
commit
49b964a3ac
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.cce.visitor
|
||||
|
||||
import com.intellij.cce.core.CodeFragment
|
||||
@@ -17,6 +17,7 @@ class LineCompletionVisitorHelper {
|
||||
fun getFile(): CodeFragment {
|
||||
codeFragment?.let { file ->
|
||||
lines.filter { it.getChildren().isNotEmpty() }.forEach { file.addChild(it) }
|
||||
file.validateCorrectness()
|
||||
return file
|
||||
}
|
||||
throw PsiConverterException("Invoke 'accept' with visitor on PSI first")
|
||||
@@ -40,6 +41,18 @@ class LineCompletionVisitorHelper {
|
||||
?.addChild(CodeToken(text, element.startOffset))
|
||||
}
|
||||
}
|
||||
|
||||
private fun CodeFragment.validateCorrectness() {
|
||||
var lastEndOffset = 0
|
||||
for (line in getChildren()) {
|
||||
assert(line is CodeLine) { "Code fragment should only contain code lines" }
|
||||
val tokens = (line as CodeLine).getChildren()
|
||||
for (token in tokens) {
|
||||
assert(lastEndOffset <= token.offset) { "Code tokens shouldn't overlap" }
|
||||
lastEndOffset = token.offset + token.text.length
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val MAX_PREFIX_LENGTH: Int = 4
|
||||
|
||||
Reference in New Issue
Block a user