From 30a24ed6a8a21410cfee957c450c6d3529ea39a7 Mon Sep 17 00:00:00 2001 From: Kun Li Date: Sun, 5 Nov 2023 08:46:08 -0800 Subject: [PATCH] Remove debug log --- .../org/openrewrite/kotlin/KotlinParser.java | 11 --- .../kotlin/internal/PsiElementAssociations.kt | 67 ------------------- 2 files changed, 78 deletions(-) diff --git a/src/main/java/org/openrewrite/kotlin/KotlinParser.java b/src/main/java/org/openrewrite/kotlin/KotlinParser.java index c7c594fd9..e2f24880b 100644 --- a/src/main/java/org/openrewrite/kotlin/KotlinParser.java +++ b/src/main/java/org/openrewrite/kotlin/KotlinParser.java @@ -179,23 +179,12 @@ public Stream parseInputs(Iterable sources, @Nullable Path re return ParseError.build(KotlinParser.this, kotlinSource.getInput(), relativeTo, ctx, new RuntimeException()); } - // Turn this flag on locally only to develop psi-based-parser - boolean printTrees = true; - KotlinTypeMapping typeMapping = new KotlinTypeMapping(typeCache, firSession, kotlinSource.getFirFile()); PsiElementAssociations associations = new PsiElementAssociations(typeMapping, kotlinSource.getFirFile()); associations.initialize(); KotlinTreeParserVisitor psiParser = new KotlinTreeParserVisitor(kotlinSource, associations, styles, relativeTo, ctx); SourceFile cu = psiParser.parse(); - // debug purpose only, to be removed - if (printTrees) { - System.out.println(PsiTreePrinter.print(kotlinSource.getInput())); - System.out.println(PsiTreePrinter.print(kotlinSource.getKtFile())); - System.out.println(PsiTreePrinter.print(kotlinSource.getFirFile())); - System.out.println(PsiTreePrinter.print(cu)); - } - parsingListener.parsed(kotlinSource.getInput(), cu); return requirePrintEqualsInput(cu, kotlinSource.getInput(), relativeTo, ctx); } catch (Throwable t) { diff --git a/src/main/kotlin/org/openrewrite/kotlin/internal/PsiElementAssociations.kt b/src/main/kotlin/org/openrewrite/kotlin/internal/PsiElementAssociations.kt index 11251219e..ac3404cb7 100644 --- a/src/main/kotlin/org/openrewrite/kotlin/internal/PsiElementAssociations.kt +++ b/src/main/kotlin/org/openrewrite/kotlin/internal/PsiElementAssociations.kt @@ -62,73 +62,6 @@ class PsiElementAssociations(val typeMapping: KotlinTypeMapping, val file: FirFi depth-- } }.visitFile(file, elementMap) - - validate() - } - - private fun validate() { - var found1ToNMapping = false - elementMap.forEach { (psi, firList) -> - var fakeCount = 0 - var realCount = 0 - var otherCount = 0 - for (firElement in firList) { - if (firElement.fir.source is KtRealPsiSourceElement) { - realCount++ - } else if (firElement.fir.source is KtFakeSourceElement) { - fakeCount++ - } else { - otherCount++ - } - } - - // print out logs, debug purpose only, to be removed after complete parser - if (false) { - found1ToNMapping = realCount > 1 - - println("---------") - println("PSI: $psi") - println("FIR: $firList") - - println("Found 1 to $realCount Real mapping!") - println(" types from $realCount Real elements:") - var firstUnknown = false - var hasNonUnknown = false - for ((index, firElement) in firList.withIndex()) { - if (firElement.fir.source is KtRealPsiSourceElement) { - val type = typeMapping.type(firElement.fir).toString() - if (index == 0 && type.equals("Unknown")) { - firstUnknown = true - } - - if (!type.equals("Unknown")) { - hasNonUnknown = true - } - - val padded = " -$type".padEnd(30, ' ') - println("$padded - $firElement") - } - } - - if (firstUnknown && hasNonUnknown) { - throw IllegalArgumentException("First type is Unknown!") - } - - println(" types from $fakeCount Fake elements:") - for (firElement in firList) { - if (firElement.fir.source is KtFakeSourceElement) { - val type = typeMapping.type(firElement.fir).toString() - val padded = " -$type".padEnd(30, ' ') - println("$padded - $firElement") - - } - } - } - } - - if (found1ToNMapping) { - // throw IllegalArgumentException("Found 1 to N real mapping!") - } } fun type(psiElement: PsiElement, owner: FirElement?): JavaType? {