Skip to content

Commit

Permalink
Remove debug log
Browse files Browse the repository at this point in the history
  • Loading branch information
kunli2 committed Nov 5, 2023
1 parent 9c4fdb8 commit 30a24ed
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 78 deletions.
11 changes: 0 additions & 11 deletions src/main/java/org/openrewrite/kotlin/KotlinParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,23 +179,12 @@ public Stream<SourceFile> parseInputs(Iterable<Input> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down

0 comments on commit 30a24ed

Please sign in to comment.