mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
[Java. Logging] Exclude lombok and common logger independently
IDEA-345098 GitOrigin-RevId: 6d9ae6ffbd032a15567505b6e949bd4bba58ef80
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9dc1305050
commit
7ac54248fe
@@ -1,21 +1,28 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.generation
|
||||
|
||||
import com.intellij.codeInsight.completion.JavaCompletionUtil
|
||||
import com.intellij.lang.logging.JvmLogger
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.psi.PsiAnonymousClass
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiImplicitClass
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.psi.util.parentsOfType
|
||||
|
||||
object GenerateLoggerUtil {
|
||||
fun findSuitableLoggers(module: Module?, filterByImportExclusion : Boolean = false): List<JvmLogger> {
|
||||
val project = module?.project ?: return emptyList()
|
||||
return JvmLogger.getAllLoggers(false).filter {
|
||||
it.isAvailable(module) && !(filterByImportExclusion && it.isExcludedFromImport(module?.project))
|
||||
it.isAvailable(module) && !(filterByImportExclusion && isLoggerExcluded(project, it))
|
||||
}
|
||||
}
|
||||
|
||||
private fun isLoggerExcluded(project: Project, logger: JvmLogger) : Boolean {
|
||||
val clazz = JavaPsiFacade.getInstance(project).findClass(logger.loggerTypeName, GlobalSearchScope.everythingScope(project))
|
||||
?: return true
|
||||
return JavaCompletionUtil.isInExcludedPackage(clazz, false)
|
||||
}
|
||||
|
||||
fun getAllNestedClasses(element: PsiElement) = element.parentsOfType(PsiClass::class.java, true)
|
||||
.filter { clazz -> clazz !is PsiAnonymousClass && clazz !is PsiImplicitClass }
|
||||
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.lang.logging
|
||||
|
||||
import com.intellij.codeInsight.completion.JavaCompletionUtil
|
||||
import com.intellij.lang.logging.UnspecifiedLogger.Companion.UNSPECIFIED_LOGGER_NAME
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
/**
|
||||
@@ -62,14 +59,6 @@ interface JvmLogger {
|
||||
*/
|
||||
fun isAvailable(module: Module?): Boolean
|
||||
|
||||
/**
|
||||
* Determines if the logger is excluded from import in the current project.
|
||||
*
|
||||
* @param project the project context
|
||||
* @return true if the logger class is excluded for import in the project, false otherwise
|
||||
*/
|
||||
fun isExcludedFromImport(project: Project?): Boolean
|
||||
|
||||
/**
|
||||
* Determines if it is possible to place a logger at the specified class.
|
||||
*
|
||||
@@ -102,14 +91,5 @@ interface JvmLogger {
|
||||
if (loggerName == UNSPECIFIED_LOGGER_NAME) return null
|
||||
return EP_NAME.extensionList.find { it.toString() == loggerName }
|
||||
}
|
||||
|
||||
fun areLoggerTypesExcluded(project: Project?, loggerTypes: List<String>): Boolean {
|
||||
if (project == null) return true
|
||||
val facade = JavaPsiFacade.getInstance(project)
|
||||
return loggerTypes.any { classFqn ->
|
||||
val clazz = facade.findClass(classFqn, GlobalSearchScope.everythingScope(project)) ?: return true
|
||||
JavaCompletionUtil.isInExcludedPackage(clazz, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,6 @@ class JvmLoggerFieldDelegate(
|
||||
|
||||
override fun isAvailable(module: Module?): Boolean = JavaLibraryUtil.hasLibraryClass(module, loggerTypeName)
|
||||
|
||||
override fun isExcludedFromImport(project: Project?): Boolean =
|
||||
JvmLogger.areLoggerTypesExcluded(project, listOf(factoryName, loggerTypeName))
|
||||
|
||||
override fun isPossibleToPlaceLoggerAtClass(clazz: PsiClass): Boolean = clazz
|
||||
.fields.any { it.name == LOGGER_IDENTIFIER || it.type.canonicalText == loggerTypeName }.not()
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ class UnspecifiedLogger : JvmLogger {
|
||||
|
||||
override fun isAvailable(module: Module?): Boolean = false
|
||||
|
||||
override fun isExcludedFromImport(project: Project?): Boolean = true
|
||||
|
||||
override fun isPossibleToPlaceLoggerAtClass(clazz: PsiClass): Boolean = false
|
||||
|
||||
override fun createLogger(project: Project, clazz: PsiClass): PsiElement = throw UnsupportedOperationException()
|
||||
|
||||
@@ -40,9 +40,6 @@ class JvmLoggerAnnotationDelegate(
|
||||
return module != null && JavaLibraryUtil.hasLibraryClass(module, fieldLoggerName) && LombokLibraryUtil.hasLombokClasses(module)
|
||||
}
|
||||
|
||||
override fun isExcludedFromImport(project: Project?): Boolean =
|
||||
JvmLogger.areLoggerTypesExcluded(project, listOf(fieldLoggerName, loggerTypeName))
|
||||
|
||||
override fun isPossibleToPlaceLoggerAtClass(clazz: PsiClass): Boolean = clazz.hasAnnotation(loggerTypeName).not()
|
||||
|
||||
override fun createLogger(project: Project, clazz: PsiClass): PsiAnnotation {
|
||||
|
||||
Reference in New Issue
Block a user