Skip to content

Nested classes & logs #1447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ private val logger = KotlinLogging.logger { }

class RdInstrumenter(private val rdInstrumenterAdapter: RdInstrumenterAdapter) : InstrumenterAdapter() {
override fun computeSourceFileByClass(
className: String,
packageName: String?,
clazz: Class<*>,
directoryToSearchRecursively: Path
): File? {
logger.debug { "starting computeSourceFileByClass with classname - $className" }
val canonicalClassName = clazz.canonicalName
logger.debug { "starting computeSourceFileByClass for class - $canonicalClassName" }
val result = logger.logException {
val arguments = ComputeSourceFileByClassArguments(className, packageName)
val arguments = ComputeSourceFileByClassArguments(canonicalClassName)

rdInstrumenterAdapter.computeSourceFileByClass.startBlocking(arguments)
}
logger.debug { "computeSourceFileByClass result for $className from idea: $result" }
logger.debug { "computeSourceFileByClass result for $canonicalClassName from idea: $result" }
return result?.let { File(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic


/**
* #### Generated from [EngineProcessModel.kt:31]
* #### Generated from [EngineProcessModel.kt:30]
*/
class EngineProcessModel private constructor(
private val _setupUtContext: RdCall<SetupContextParams, Unit>,
Expand Down Expand Up @@ -177,7 +177,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel


/**
* #### Generated from [EngineProcessModel.kt:100]
* #### Generated from [EngineProcessModel.kt:99]
*/
data class FindMethodParamNamesArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -240,7 +240,7 @@ data class FindMethodParamNamesArguments (


/**
* #### Generated from [EngineProcessModel.kt:104]
* #### Generated from [EngineProcessModel.kt:103]
*/
data class FindMethodParamNamesResult (
val paramNames: ByteArray
Expand Down Expand Up @@ -297,7 +297,7 @@ data class FindMethodParamNamesResult (


/**
* #### Generated from [EngineProcessModel.kt:93]
* #### Generated from [EngineProcessModel.kt:92]
*/
data class FindMethodsInClassMatchingSelectedArguments (
val classId: ByteArray,
Expand Down Expand Up @@ -360,7 +360,7 @@ data class FindMethodsInClassMatchingSelectedArguments (


/**
* #### Generated from [EngineProcessModel.kt:97]
* #### Generated from [EngineProcessModel.kt:96]
*/
data class FindMethodsInClassMatchingSelectedResult (
val executableIds: ByteArray
Expand Down Expand Up @@ -417,7 +417,7 @@ data class FindMethodsInClassMatchingSelectedResult (


/**
* #### Generated from [EngineProcessModel.kt:43]
* #### Generated from [EngineProcessModel.kt:42]
*/
data class GenerateParams (
val mockInstalled: Boolean,
Expand Down Expand Up @@ -540,7 +540,7 @@ data class GenerateParams (


/**
* #### Generated from [EngineProcessModel.kt:61]
* #### Generated from [EngineProcessModel.kt:60]
*/
data class GenerateResult (
val notEmptyCases: Int,
Expand Down Expand Up @@ -603,7 +603,7 @@ data class GenerateResult (


/**
* #### Generated from [EngineProcessModel.kt:112]
* #### Generated from [EngineProcessModel.kt:111]
*/
data class GenerateTestReportArgs (
val eventLogMessage: String?,
Expand Down Expand Up @@ -696,7 +696,7 @@ data class GenerateTestReportArgs (


/**
* #### Generated from [EngineProcessModel.kt:121]
* #### Generated from [EngineProcessModel.kt:120]
*/
data class GenerateTestReportResult (
val notifyMessage: String,
Expand Down Expand Up @@ -765,7 +765,7 @@ data class GenerateTestReportResult (


/**
* #### Generated from [EngineProcessModel.kt:32]
* #### Generated from [EngineProcessModel.kt:31]
*/
data class JdkInfo (
val path: String,
Expand Down Expand Up @@ -828,7 +828,7 @@ data class JdkInfo (


/**
* #### Generated from [EngineProcessModel.kt:65]
* #### Generated from [EngineProcessModel.kt:64]
*/
data class RenderParams (
val testSetsId: Long,
Expand Down Expand Up @@ -969,7 +969,7 @@ data class RenderParams (


/**
* #### Generated from [EngineProcessModel.kt:82]
* #### Generated from [EngineProcessModel.kt:81]
*/
data class RenderResult (
val generatedCode: String,
Expand Down Expand Up @@ -1032,7 +1032,7 @@ data class RenderResult (


/**
* #### Generated from [EngineProcessModel.kt:86]
* #### Generated from [EngineProcessModel.kt:85]
*/
data class SetupContextParams (
val classpathForUrlsClassloader: List<String>
Expand Down Expand Up @@ -1089,7 +1089,7 @@ data class SetupContextParams (


/**
* #### Generated from [EngineProcessModel.kt:89]
* #### Generated from [EngineProcessModel.kt:88]
*/
data class Signature (
val name: String,
Expand Down Expand Up @@ -1152,7 +1152,7 @@ data class Signature (


/**
* #### Generated from [EngineProcessModel.kt:37]
* #### Generated from [EngineProcessModel.kt:36]
*/
data class TestGeneratorParams (
val buildDir: Array<String>,
Expand Down Expand Up @@ -1227,7 +1227,7 @@ data class TestGeneratorParams (


/**
* #### Generated from [EngineProcessModel.kt:107]
* #### Generated from [EngineProcessModel.kt:106]
*/
data class WriteSarifReportArguments (
val testSetsId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RdInstrumenterAdapter private constructor(

private val __StringNullableSerializer = FrameworkMarshallers.String.nullable()

const val serializationHash = -671974871925861655L
const val serializationHash = 1502978559314472937L

}
override val serializersOwner: ISerializersOwner get() = RdInstrumenterAdapter
Expand Down Expand Up @@ -97,8 +97,7 @@ val IProtocol.rdInstrumenterAdapter get() = getOrCreateExtension(RdInstrumenterA
* #### Generated from [EngineProcessModel.kt:8]
*/
data class ComputeSourceFileByClassArguments (
val className: String,
val packageName: String?
val canonicalClassName: String
) : IPrintable {
//companion

Expand All @@ -107,14 +106,12 @@ data class ComputeSourceFileByClassArguments (

@Suppress("UNCHECKED_CAST")
override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): ComputeSourceFileByClassArguments {
val className = buffer.readString()
val packageName = buffer.readNullable { buffer.readString() }
return ComputeSourceFileByClassArguments(className, packageName)
val canonicalClassName = buffer.readString()
return ComputeSourceFileByClassArguments(canonicalClassName)
}

override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: ComputeSourceFileByClassArguments) {
buffer.writeString(value.className)
buffer.writeNullable(value.packageName) { buffer.writeString(it) }
buffer.writeString(value.canonicalClassName)
}


Expand All @@ -130,24 +127,21 @@ data class ComputeSourceFileByClassArguments (

other as ComputeSourceFileByClassArguments

if (className != other.className) return false
if (packageName != other.packageName) return false
if (canonicalClassName != other.canonicalClassName) return false

return true
}
//hash code trait
override fun hashCode(): Int {
var __r = 0
__r = __r*31 + className.hashCode()
__r = __r*31 + if (packageName != null) packageName.hashCode() else 0
__r = __r*31 + canonicalClassName.hashCode()
return __r
}
//pretty print
override fun print(printer: PrettyPrinter) {
printer.println("ComputeSourceFileByClassArguments (")
printer.indent {
print("className = "); className.print(printer); println()
print("packageName = "); packageName.print(printer); println()
print("canonicalClassName = "); canonicalClassName.print(printer); println()
}
printer.print(")")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic


/**
* #### Generated from [EngineProcessModel.kt:17]
* #### Generated from [EngineProcessModel.kt:16]
*/
class RdSourceFindingStrategy private constructor(
private val _testsRelativePath: RdCall<Long, String>,
Expand Down Expand Up @@ -108,7 +108,7 @@ val IProtocol.rdSourceFindingStrategy get() = getOrCreateExtension(RdSourceFindi


/**
* #### Generated from [EngineProcessModel.kt:18]
* #### Generated from [EngineProcessModel.kt:17]
*/
data class SourceStrategyMethodArgs (
val testSetId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ open class InstrumenterAdapter {
computeSourceFileByClass(it, directoryToSearchRecursively)
}

fun computeSourceFileByClass(clazz: Class<*>, directoryToSearchRecursively: Path = Paths.get("")): File? {
val packageName = clazz.`package`?.name?.replace('.', File.separatorChar)
return computeSourceFileByClass(clazz.name, packageName, directoryToSearchRecursively)
}

open fun computeSourceFileByClass(
fun computeSourceFileByNameAndPackage(
className: String, packageName: String?, directoryToSearchRecursively: Path
): File? {
val sourceFileName = computeSourceFileName(className) ?: return null
Expand All @@ -73,4 +68,9 @@ open class InstrumenterAdapter {
}
return fileWithoutPackage
}

open fun computeSourceFileByClass(clazz: Class<*>, directoryToSearchRecursively: Path = Paths.get("")): File? {
val packageName = clazz.`package`?.name?.replace('.', File.separatorChar)
return computeSourceFileByNameAndPackage(clazz.name, packageName, directoryToSearchRecursively)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ object UtTestsDialogProcessor {
}

private val PsiClass.canonicalName: String
/*
This method calculates exactly name that is used by compiler convention,
i.e. result is the exact name of .class file for provided PsiClass.
This value is used to provide classes to engine process - follow usages for clarification.
Equivalent for Class.getCanonicalName.
P.S. We cannot load project class in IDEA jvm
*/
get() {
return if (packageName.isEmpty()) {
qualifiedName?.replace(".", "$") ?: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class EngineProcess private constructor(val project: Project, rdProcess: Process
private fun computeSourceFileByClass(params: ComputeSourceFileByClassArguments): String =
DumbService.getInstance(project).runReadActionInSmartMode<String?> {
val scope = GlobalSearchScope.allScope(project)
val psiClass = JavaFileManager.getInstance(project).findClass(params.className, scope)
// JavaFileManager requires canonical name as it is said in import
val psiClass = JavaFileManager.getInstance(project).findClass(params.canonicalClassName, scope)
val sourceFile = psiClass?.navigationElement?.containingFile?.virtualFile?.canonicalPath

logger.debug { "computeSourceFileByClass result: $sourceFile" }
Expand Down
29 changes: 1 addition & 28 deletions utbot-intellij/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<!-- Idea catches plugin stdout log and wraps it in its own format, so in IDE only message is logged-->
<Console name="IdeaAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%msg%n"/>
</Console>
<!-- When working as separate process - temporary log4j2.xml would be created, in which -->
<!-- substring `ref="IdeaAppender"` will be replaced with `ref="EngineProcessAppender"`-->
<Console name="EngineProcessAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} | %-5level | %-25c{1} | %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.utbot.intellij" level="info" additivity="false">
<AppenderRef ref="IdeaAppender"/>
</Logger>
<Logger name="org.utbot.IntelliJApiHelper" level="info" additivity="false">
<AppenderRef ref="IdeaAppender"/>
</Logger>
<Logger name="org.utbot" level="debug" additivity="false">
<AppenderRef ref="IdeaAppender"/>
</Logger>
<Root level="error">
<AppenderRef ref="IdeaAppender"/>
</Root>
</Loggers>
</Configuration>
<?xml version="1.0" encoding="UTF-8"?><Configuration> <Appenders><!-- Idea catches plugin stdout log and wraps it in its own format, so in IDE only message is logged--> <Console name="IdeaAppender" target="SYSTEM_OUT"> <PatternLayout pattern="| UtBot - %-25c{1} | %msg%n"/> </Console><!-- When working as separate process - temporary log4j2.xml would be created, in which --><!-- substring `ref="IdeaAppender"` will be replaced with `ref="EngineProcessAppender"`--> <Console name="EngineProcessAppender" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} | %-5level | %-25c{1} | %msg%n"/> </Console> </Appenders> <Loggers> <Logger name="org.utbot.intellij" level="info" additivity="false"> <AppenderRef ref="IdeaAppender"/> </Logger> <Logger name="org.utbot" level="info" additivity="false"> <AppenderRef ref="IdeaAppender"/> </Logger> <Root level="error"> <AppenderRef ref="IdeaAppender"/> </Root> </Loggers></Configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ object EngineProcessRoot : Root()

object RdInstrumenterAdapter: Ext(EngineProcessRoot) {
val computeSourceFileByClassArguments = structdef {
field("className", PredefinedType.string)
field("packageName", PredefinedType.string.nullable)
field("canonicalClassName", PredefinedType.string)
}
init {
call("computeSourceFileByClass", computeSourceFileByClassArguments, PredefinedType.string.nullable).async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private fun invokeDescriptions(testSet: UtMethodTestSet, searchDirectory: Path):
//TODO(SAT-1170)
.filterNot { "\$lambda" in it.declaringClass.name }
.mapNotNull { sootMethod ->
val methodFile = Instrumenter.adapter.computeSourceFileByClass(
val methodFile = Instrumenter.adapter.computeSourceFileByNameAndPackage(
sootMethod.declaringClass.name,
sootMethod.declaringClass.javaPackageName.replace(".", File.separator),
searchDirectory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.jetbrains.kotlin.idea.util.application.invokeLater
* This object is required to encapsulate Android API usage and grant safe access to it.
*/
object IntelliJApiHelper {
private val logger = KotlinLogging.logger {"org.utbot.IntelliJApiHelper"}
private val logger = KotlinLogging.logger {}
enum class Target { THREAD_POOL, READ_ACTION, WRITE_ACTION, EDT_LATER }

fun run(target: Target, indicator: ProgressIndicator? = null, logMessage : String, runnable: Runnable) {
Expand Down