Cedric Hippmann
01/12/2021, 12:56 PMDeclarationChecker
which extracts the assignmentPsi
from the `PropertyDescriptor`'s.
Is there another hook or a better way with which i can do this for all source files not just those that have changed since the last run?
I just need this to work on the JVM.aleksey.tomin
01/13/2021, 4:03 AMThe problem is i always need to be able to extract those assignments for all files.Do You want to extract all assignments in all files of the module? The project? All libraries in your classpath? It seems to me that your goal is not so good. What is your root goal?
Cedric Hippmann
01/13/2021, 7:07 AMaleksey.tomin
01/13/2021, 7:31 AMCedric Hippmann
01/13/2021, 7:40 AMCedric Hippmann
01/13/2021, 11:37 AMKotlinCoreEnvironment
uses to get the source files in the function `createSourceFilesFromSourceRoots`:
val localFileSystem = VirtualFileManager.getInstance()
.getFileSystem(StandardFileSystems.FILE_PROTOCOL)
val psiManager = PsiManager.getInstance(project)
val processedFiles = hashSetOf<VirtualFile>()
val result = mutableListOf<KtFile>()
val virtualFileCreator = PreprocessedFileCreator(project)
for ((sourceRootPath, isCommon) in sourceRoots) {
val vFile = localFileSystem.findFileByPath(sourceRootPath)
if (vFile == null) {
val message = "Source file or directory not found: $sourceRootPath"
val buildFilePath = configuration.get(JVMConfigurationKeys.MODULE_XML_FILE)
if (buildFilePath != null && Logger.isInitialized()) {
Logger.getInstance(KotlinCoreEnvironment::class.java)
.warn("$message\n\nbuild file path: $buildFilePath\ncontent:\n${buildFilePath.readText()}")
}
configuration.report(CompilerMessageSeverity.ERROR, message, reportLocation)
continue
}
if (!vFile.isDirectory && vFile.fileType != KotlinFileType.INSTANCE) {
configuration.report(CompilerMessageSeverity.ERROR, "Source entry is not a Kotlin file: $sourceRootPath", reportLocation)
continue
}
for (file in File(sourceRootPath).walkTopDown()) {
if (!file.isFile) continue
val virtualFile = localFileSystem.findFileByPath(file.absolutePath)?.let(virtualFileCreator::create)
if (virtualFile != null && processedFiles.add(virtualFile)) {
val psiFile = psiManager.findFile(virtualFile)
if (psiFile is KtFile) {
result.add(psiFile)
if (isCommon) {
psiFile.isCommonSource = true
}
}
}
}
}
return result
With this I'm able to access all assignment psi's from all properties that are annotated with our annotation.
But maybe someone has a better idea that does not involve the need to pass the sourcesDirs as an argument to the compiler plugin