mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
add recovery policy for api dump parser
GitOrigin-RevId: 12d92f74ec28d07e1f0c3c5392879528eda25edd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c4dd7b9e83
commit
931eb4c151
@@ -1,5 +1,30 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:JvmName("ADParserUtil")
|
||||
|
||||
package com.intellij.devkit.apiDump.lang.parser
|
||||
|
||||
internal class ADParserUtil {
|
||||
import com.intellij.lang.PsiBuilder
|
||||
import com.intellij.psi.TokenType
|
||||
|
||||
internal fun consumeUntilNextLineImpl(builder: PsiBuilder, level: Int) {
|
||||
while (!builder.eof()) {
|
||||
if (isLineFeed(builder, level)) break
|
||||
builder.advanceLexer()
|
||||
}
|
||||
}
|
||||
|
||||
/** Check if there is a line feed before the current token */
|
||||
private fun isLineFeed(builder: PsiBuilder, level: Int): Boolean {
|
||||
if (builder.eof()) return true
|
||||
|
||||
var steps = 0
|
||||
while (builder.rawLookup(steps - 1) === TokenType.WHITE_SPACE) {
|
||||
steps--
|
||||
}
|
||||
|
||||
if (builder.rawLookup(steps - 1) == null) return true
|
||||
val start = builder.rawTokenTypeStart(steps)
|
||||
val end = builder.getCurrentOffset()
|
||||
val originalText = builder.getOriginalText()
|
||||
return originalText.subSequence(start, end).contains('\n')
|
||||
}
|
||||
@@ -46,9 +46,12 @@ File ::= ClassDeclaration*
|
||||
|
||||
ClassDeclaration ::= ClassHeader Member* {
|
||||
methods = [ resolvePsiClass getNavigationElement ]
|
||||
recoverWhile = consumeUntilNextLine
|
||||
}
|
||||
|
||||
Member ::= Method | Constructor | Field | Companion | SuperType
|
||||
Member ::= Method | Constructor | Field | Companion | SuperType {
|
||||
recoverWhile = consumeUntilNextLine
|
||||
}
|
||||
|
||||
ClassHeader ::= Modifiers? TypeReference
|
||||
|
||||
@@ -115,3 +118,5 @@ ConstructorReference ::= LESS 'init' MORE
|
||||
SuperType ::= MINUS TypeReference
|
||||
|
||||
Companion ::= MemberStart 'Companion' COLON TypeReference
|
||||
|
||||
private consumeUntilNextLine ::= <<consumeUntilNextLineImpl>>
|
||||
4
plugins/devkit/api-dump-lang/testData/parser/recover.ad
Normal file
4
plugins/devkit/api-dump-lang/testData/parser/recover.ad
Normal file
@@ -0,0 +1,4 @@
|
||||
c:com.intellij.execution.ExecutionException
|
||||
- java.lang.Exception foo
|
||||
Fa:com.intellij.execution.ExecutionExceptionWithAttachments
|
||||
- com.intellij.execution.ExecutionException
|
||||
57
plugins/devkit/api-dump-lang/testData/parser/recover.txt
Normal file
57
plugins/devkit/api-dump-lang/testData/parser/recover.txt
Normal file
@@ -0,0 +1,57 @@
|
||||
FILE
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(MODIFIERS)
|
||||
PsiElement(MODIFIER)
|
||||
PsiElement(IDENTIFIER)('c')
|
||||
PsiElement(COLON)(':')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionException')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('java')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('lang')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('Exception')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(MODIFIERS)
|
||||
PsiElement(MODIFIER)
|
||||
PsiElement(IDENTIFIER)('Fa')
|
||||
PsiElement(COLON)(':')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionExceptionWithAttachments')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionException')
|
||||
5
plugins/devkit/api-dump-lang/testData/parser/recover1.ad
Normal file
5
plugins/devkit/api-dump-lang/testData/parser/recover1.ad
Normal file
@@ -0,0 +1,5 @@
|
||||
c:com.intellij.execution.ExecutionException
|
||||
- java.lang.Exception foo
|
||||
- java.lang.Exception
|
||||
Fa:com.intellij.execution.ExecutionExceptionWithAttachments
|
||||
- com.intellij.execution.ExecutionException
|
||||
67
plugins/devkit/api-dump-lang/testData/parser/recover1.txt
Normal file
67
plugins/devkit/api-dump-lang/testData/parser/recover1.txt
Normal file
@@ -0,0 +1,67 @@
|
||||
FILE
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(MODIFIERS)
|
||||
PsiElement(MODIFIER)
|
||||
PsiElement(IDENTIFIER)('c')
|
||||
PsiElement(COLON)(':')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionException')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('java')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('lang')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('Exception')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('java')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('lang')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('Exception')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(MODIFIERS)
|
||||
PsiElement(MODIFIER)
|
||||
PsiElement(IDENTIFIER)('Fa')
|
||||
PsiElement(COLON)(':')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionExceptionWithAttachments')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionException')
|
||||
5
plugins/devkit/api-dump-lang/testData/parser/recover2.ad
Normal file
5
plugins/devkit/api-dump-lang/testData/parser/recover2.ad
Normal file
@@ -0,0 +1,5 @@
|
||||
c:com.intellij.execution.ExecutionException
|
||||
- java.lang.Exception foo
|
||||
Fa:com.intellij.execution.ExecutionExceptionWithAttachments
|
||||
- com.intellij.execution.ExecutionException
|
||||
---
|
||||
62
plugins/devkit/api-dump-lang/testData/parser/recover2.txt
Normal file
62
plugins/devkit/api-dump-lang/testData/parser/recover2.txt
Normal file
@@ -0,0 +1,62 @@
|
||||
FILE
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(MODIFIERS)
|
||||
PsiElement(MODIFIER)
|
||||
PsiElement(IDENTIFIER)('c')
|
||||
PsiElement(COLON)(':')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionException')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('java')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('lang')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('Exception')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(CLASS_DECLARATION)
|
||||
PsiElement(CLASS_HEADER)
|
||||
PsiElement(MODIFIERS)
|
||||
PsiElement(MODIFIER)
|
||||
PsiElement(IDENTIFIER)('Fa')
|
||||
PsiElement(COLON)(':')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionExceptionWithAttachments')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(SUPER_TYPE)
|
||||
PsiElement(MINUS)('-')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(TYPE_REFERENCE)
|
||||
PsiElement(IDENTIFIER)('com')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('intellij')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('execution')
|
||||
PsiElement(DOT)('.')
|
||||
PsiElement(IDENTIFIER)('ExecutionException')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(MINUS)('-')
|
||||
PsiErrorElement:<modifiers>, Companion, IDENTIFIER or LESS expected, got '-'
|
||||
PsiElement(MINUS)('-')
|
||||
PsiElement(MINUS)('-')
|
||||
@@ -12,6 +12,10 @@ internal class ADParsingTest : ParsingTestCase(
|
||||
fun testSimple() = doTest()
|
||||
fun testField() = doTest()
|
||||
|
||||
fun testRecover() = doTest()
|
||||
fun testRecover1() = doTest()
|
||||
fun testRecover2() = doTest()
|
||||
|
||||
private fun doTest() {
|
||||
doTest(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user