mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[java-console] IDEA-344708 JVM Log navigation doesn't support nested classes
- support double nested classes GitOrigin-RevId: 169c1c30bc895a838bdedd941d6397fe6de5c0ef
This commit is contained in:
committed by
intellij-monorepo-bot
parent
4b75221526
commit
fd0e68a470
@@ -30,7 +30,10 @@ class ClassInfoResolver(val project: Project, private val mySearchScope: GlobalS
|
||||
for (cache in list) {
|
||||
val classes = cache.getClassesByName(shortClassName, scope)
|
||||
for (clazz in classes) {
|
||||
if (!canBeShortenedPackages(clazz, targetPackageName)) {
|
||||
val qualifiedName = clazz.qualifiedName
|
||||
if (!canBeShortenedPackages(qualifiedName, targetPackageName) &&
|
||||
!(targetPackageName.contains("$") &&
|
||||
canBeShortenedPackages(qualifiedName?.replace('$', '.'), targetPackageName.replace('$', '.')))) {
|
||||
continue
|
||||
}
|
||||
result.add(clazz)
|
||||
@@ -38,8 +41,9 @@ class ClassInfoResolver(val project: Project, private val mySearchScope: GlobalS
|
||||
}
|
||||
if (result.isEmpty()) {
|
||||
val newShortClassName = findSubclassName(shortClassName)
|
||||
if (newShortClassName != null) {
|
||||
val newTargetPackageName = targetPackageName + "." + shortClassName.substring(0, newShortClassName.length + 1)
|
||||
if (newShortClassName?.isNotBlank() == true) {
|
||||
val newTargetPackageName = "$targetPackageName." +
|
||||
shortClassName.substring(0, shortClassName.length - newShortClassName.length - 1)
|
||||
return findClasses(project, scope, newShortClassName, newTargetPackageName)
|
||||
}
|
||||
}
|
||||
@@ -47,15 +51,15 @@ class ClassInfoResolver(val project: Project, private val mySearchScope: GlobalS
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clazz The class to check.
|
||||
* @param qualifiedName The class qualified name to check.
|
||||
* @param targetPackageName The target package name.
|
||||
* @return True, if clazz package can be shortened to targetPackageName, false otherwise.
|
||||
* There are two popular ways to shorten:
|
||||
* 1. Keep only n last characters of the package: aaa.bbb.ccc -> b.ccc
|
||||
* 2. Keep only the first n characters of each directory: abc.bcd.cef -> a.b.c
|
||||
*/
|
||||
private fun canBeShortenedPackages(clazz: PsiClass, targetPackageName: String): Boolean {
|
||||
val qualifiedName = clazz.qualifiedName ?: return false
|
||||
private fun canBeShortenedPackages(qualifiedName: String?, targetPackageName: String): Boolean {
|
||||
if (qualifiedName == null) return false
|
||||
val actualPackageName = StringUtil.getPackageName(qualifiedName)
|
||||
if (actualPackageName.endsWith(targetPackageName)) return true
|
||||
val actualPackageNames = actualPackageName.split(".")
|
||||
|
||||
@@ -320,4 +320,41 @@ public final class UpperClass {
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun testNestedClasses2() {
|
||||
LoggingTestUtils.addSlf4J(myFixture)
|
||||
checkColumnFinderJava(
|
||||
fileName = "UpperClass",
|
||||
classText = """
|
||||
package com.example;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public final class UpperClass {
|
||||
public static class Inner{
|
||||
public static class Inner2{
|
||||
private static final Logger log = org.slf4j.LoggerFactory.getLogger(Inner2.class);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
request1("1");
|
||||
}
|
||||
|
||||
|
||||
private static void request1(String number) {
|
||||
System.out.println("com.example.UpperClass${"\$Inner"}${"\$Inner2"} test");
|
||||
Inner.Inner2.log.info("new request1 {}", number);
|
||||
}
|
||||
}
|
||||
""".trimIndent(),
|
||||
logItems = listOf(
|
||||
LogItem("java.exe", null),
|
||||
LogItem("1", null),
|
||||
LogItem("com.example.UpperClass${"\$Inner"}${"\$Inner2"} test", LogicalPosition(7, 26)),
|
||||
LogItem("[main] INFO com.example.UpperClass${"\$Inner"}${"\$Inner2"} -- new request1 1", LogicalPosition(19, 8)),
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user