add recovery policy for api dump parser

GitOrigin-RevId: 12d92f74ec28d07e1f0c3c5392879528eda25edd
This commit is contained in:
Max Medvedev
2025-05-25 17:22:49 +02:00
committed by intellij-monorepo-bot
parent c4dd7b9e83
commit 931eb4c151
9 changed files with 236 additions and 2 deletions

View File

@@ -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')
}

View File

@@ -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>>

View File

@@ -0,0 +1,4 @@
c:com.intellij.execution.ExecutionException
- java.lang.Exception foo
Fa:com.intellij.execution.ExecutionExceptionWithAttachments
- com.intellij.execution.ExecutionException

View 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')

View 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

View 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')

View File

@@ -0,0 +1,5 @@
c:com.intellij.execution.ExecutionException
- java.lang.Exception foo
Fa:com.intellij.execution.ExecutionExceptionWithAttachments
- com.intellij.execution.ExecutionException
---

View 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)('-')

View File

@@ -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)
}