russhwolf
05/06/2020, 8:03 PMval Meta.demoPlugin: CliPlugin get() = "Demo" {
meta(
property({ true }) { ktProperty ->
val type = ktProperty.typeReference?.name // name is null
Transform.empty
}
)
}
melatonina
05/06/2020, 8:05 PMtext
property. The actual type is unknown, yet, and so its actual name. The only thing that is known is the piece of source code used to identify that type.melatonina
05/06/2020, 8:06 PMrusshwolf
05/06/2020, 8:07 PMmelatonina
05/06/2020, 8:08 PMmelatonina
05/06/2020, 8:08 PMmelatonina
05/06/2020, 8:09 PMmelatonina
05/06/2020, 8:15 PMrusshwolf
05/06/2020, 8:19 PMmelatonina
05/06/2020, 8:20 PMraulraja
05/06/2020, 9:00 PMraulraja
05/06/2020, 9:01 PMraulraja
05/06/2020, 9:01 PMraulraja
05/06/2020, 9:01 PMrusshwolf
05/06/2020, 9:03 PMraulraja
05/06/2020, 9:12 PMraulraja
05/06/2020, 9:14 PMraulraja
05/06/2020, 9:14 PMraulraja
05/06/2020, 9:15 PMraulraja
05/06/2020, 9:16 PMraulraja
05/06/2020, 9:16 PMraulraja
05/06/2020, 9:17 PMraulraja
05/06/2020, 9:17 PMraulraja
05/06/2020, 9:17 PMmelatonina
05/06/2020, 9:19 PMrusshwolf
05/06/2020, 9:28 PMraulraja
05/06/2020, 10:05 PMrusshwolf
05/07/2020, 5:40 PMKtProperty
reference I want in a property()
call, then doing an analysis()
call to try and check that property's type. Not sure what the correct API to call is, but all of the below are still giving me null inside the analysisCompleted
lambda (and I don't know if any of them are what I should be doing anyway):
bindingTrace.getType(ktProperty)
bindingTrace.bindingContext.getType(ktProperty)
ktProperty.kotlinType(bindingTrace.bindingContext)
russhwolf
05/07/2020, 5:41 PMnull
in the doAnalysis
lambda which might also be causing issues. What's the correct default to use there to skip straight to analysisCompleted
?raulraja
05/07/2020, 6:18 PMraulraja
05/07/2020, 6:18 PMraulraja
05/07/2020, 6:18 PMraulraja
05/07/2020, 6:20 PMraulraja
05/07/2020, 6:20 PMraulraja
05/07/2020, 6:20 PMraulraja
05/07/2020, 6:21 PMraulraja
05/07/2020, 6:22 PMraulraja
05/07/2020, 6:22 PMraulraja
05/07/2020, 6:22 PMrusshwolf
05/07/2020, 6:53 PMbindingTrace.bindingContext.getKeys(<http://BindingContext.XXX|BindingContext.XXX>)
are throwing with "Keys are not collected for slice XXX"raulraja
05/07/2020, 6:57 PMrusshwolf
05/07/2020, 7:03 PMbindingTrace.bindingContext.getKeys(BindingContext.TYPE)
I get java.lang.AssertionError: Keys are not collected for slice TYPE
raulraja
05/07/2020, 7:07 PMraulraja
05/07/2020, 7:07 PMraulraja
05/07/2020, 7:08 PMraulraja
05/07/2020, 7:08 PMraulraja
05/07/2020, 7:09 PMrusshwolf
05/07/2020, 7:11 PMrusshwolf
05/07/2020, 7:13 PMWritableSlice
raulraja
05/07/2020, 7:13 PMrusshwolf
05/07/2020, 7:16 PMval Meta.demoPlugin: CliPlugin get() = "Demo" {
val properties = mutableSetOf<KtProperty>()
meta(
property({ true }) { ktProperty ->
properties += ktProperty
Transform.empty
},
analysis(
doAnalysis =
{ project: Project,
moduleDescriptor: ModuleDescriptor,
projectContext: ProjectContext,
collection: Collection<KtFile>,
bindingTrace: BindingTrace,
componentProvider: ComponentProvider ->
null
},
analysisCompleted =
{ project: Project,
moduleDescriptor: ModuleDescriptor,
bindingTrace: BindingTrace,
collection: Collection<KtFile> ->
properties.forEach { ktProperty ->
// Looking for the type of ktProperty here
}
null
}
),
)
}
raulraja
05/07/2020, 7:20 PMraulraja
05/07/2020, 7:22 PMdoAnalysis
and have raw power to whatever you want to do thererusshwolf
05/07/2020, 7:27 PMgetSliceContents()
is what I was missingrusshwolf
05/07/2020, 7:28 PMdoAnalysis
? Or can I call one of the quotes APIs next and have that run after?raulraja
05/07/2020, 8:15 PMraulraja
05/07/2020, 8:15 PMrusshwolf
05/07/2020, 8:16 PMrusshwolf
05/07/2020, 8:16 PMrusshwolf
05/07/2020, 8:17 PMraulraja
05/07/2020, 8:18 PMrusshwolf
05/07/2020, 8:24 PMraulraja
05/07/2020, 8:33 PMraulraja
05/07/2020, 8:34 PMraulraja
05/07/2020, 8:34 PMraulraja
05/07/2020, 8:35 PMrusshwolf
05/07/2020, 8:35 PMraulraja
05/07/2020, 8:36 PMraulraja
05/07/2020, 8:36 PMrusshwolf
05/07/2020, 8:37 PMraulraja
05/07/2020, 8:37 PMraulraja
05/07/2020, 8:39 PMbloder
05/07/2020, 9:13 PMraulraja
05/07/2020, 9:19 PMraulraja
05/07/2020, 9:20 PMraulraja
05/07/2020, 9:21 PMrusshwolf
05/07/2020, 9:21 PMraulraja
05/07/2020, 9:21 PMbloder
05/07/2020, 9:47 PM...
meta(
analysis(...) + namedFunction({ name == "helloWorld" }) { c -> }
)
...
bloder
05/07/2020, 9:56 PMrusshwolf
05/07/2020, 10:00 PMrusshwolf
05/07/2020, 10:00 PMbloder
05/07/2020, 11:18 PMbloder
05/07/2020, 11:19 PMraulraja
05/08/2020, 8:55 AMraulraja
05/08/2020, 8:55 AMProperty.descriptor?
russhwolf
05/08/2020, 6:51 PMprocessFiles()
and `updateFiles()`calls that the quotes system uses internally in doAnalysis
, and move them to analysisCompleted
with a RetryWithAdditionalRoots
return, then things work.raulraja
05/09/2020, 5:41 PMraulraja
05/09/2020, 5:41 PMAhmed Mourad
05/09/2020, 9:24 PMbloder
05/09/2020, 10:50 PMAhmed Mourad
05/10/2020, 1:24 AMAhmed Mourad
06/06/2020, 1:23 PMraulraja
06/06/2020, 1:52 PMAhmed Mourad
06/06/2020, 2:23 PMImran/Malic
06/06/2020, 2:25 PMImran/Malic
06/06/2020, 2:28 PMAhmed Mourad
06/06/2020, 3:56 PMdephinera
06/13/2020, 4:04 PMraulraja
06/13/2020, 4:06 PMbloder
06/13/2020, 4:08 PMdephinera
06/13/2020, 4:53 PMraulraja
06/13/2020, 5:22 PMdephinera
06/13/2020, 5:22 PMraulraja
06/13/2020, 7:17 PMbloder
06/13/2020, 8:14 PMname
property but Quotes has its type reference and I can get kt property reference by text
property:
meta(
property(this, { true }) { ktProperty ->
messageCollector?.report(CompilerMessageSeverity.ERROR, "KtProperty - ${ktProperty.name} - ${ktProperty.typeReference?.name}")
messageCollector?.report(CompilerMessageSeverity.ERROR, "KtProperty ${ktProperty.name} - ${ktProperty.typeReference?.text}")
messageCollector?.report(CompilerMessageSeverity.ERROR, "Quote - ${this.name} - ${this.typeReference}")
Transform.empty
}
)
val x: Repository = Repository()
class Repository
// e: KtProperty - x - null
// e: KtProperty x - Repository
// e: Quote - x - Repository
bloder
06/13/2020, 8:17 PMbloder
06/13/2020, 8:17 PMraulraja
06/13/2020, 8:19 PMraulraja
06/13/2020, 8:20 PMbloder
06/13/2020, 9:14 PMbloder
06/13/2020, 9:16 PManalysis(
doAnalysis = { project, module, projectContext, files, bindingTrace, componentProvider ->
messageCollector?.report(CompilerMessageSeverity.WARNING, "PASSED HERE!")
null
},
analysisCompleted = { project, module, bindingTrace, files ->
val slice: ImmutableMap<PsiElement, DeclarationDescriptor> =
bindingTrace.bindingContext.getSliceContents(BindingContext.DECLARATION_TO_DESCRIPTOR)
messageCollector?.report(CompilerMessageSeverity.WARNING, "PASSED HERE22! -- ${slice}")
slice.forEach { (psi, descriptor) ->
if (psi is KtProperty && descriptor is PropertyDescriptor) {
messageCollector?.report(
CompilerMessageSeverity.ERROR,
"${psi.text} -> Type: ${descriptor.returnType}"
)
}
}
AnalysisResult.RetryWithAdditionalRoots(bindingTrace.bindingContext, module, additionalJavaRoots = listOf(), additionalKotlinRoots = listOf())
}
)
bloder
06/13/2020, 9:16 PMval x: Repository = Repository()
class Repository
fun main() {
println(x)
}
dephinera
06/14/2020, 7:54 AMval Meta.example: CliPlugin
get() =
"Example" {
meta(
analysis(
doAnalysis = { project, module, projectContext, files, bindingTrace, componentProvider ->
null
},
analysisCompleted = { project, module, bindingTrace, files ->
val slice: ImmutableMap<FqNameUnsafe, ClassDescriptor> = bindingTrace.bindingContext.getSliceContents(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR)
messageCollector?.report(
CompilerMessageSeverity.WARNING,
"slice empty: ${slice.isEmpty()}"
)
null
}
)
)
}
I can see that he experienced the same problem. @bloder can I extract properties information from FQNAME_TO_CLASS_DESCRIPTOR? I'm playing around with the information from it but I can't find an api that will do the jobdephinera
06/14/2020, 8:18 AMFQNAME_TO_CLASS_DESCRIPTOR
analysisCompleted = { project, module, bindingTrace, files ->
val slice: ImmutableMap<FqNameUnsafe, ClassDescriptor> = bindingTrace.bindingContext.getSliceContents(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR)
slice.forEach { (fqName, descriptor) ->
descriptor.getMemberScope(TypeSubstitution.EMPTY).getDescriptorsFiltered { true }.forEach {
if (it is PropertyDescriptor) {
messageCollector?.report(
CompilerMessageSeverity.WARNING,
"property name: ${it.name}"
)
messageCollector?.report(
CompilerMessageSeverity.WARNING,
"property return type: ${it.returnType}"
)
it.annotations.forEach {
messageCollector?.report(
CompilerMessageSeverity.WARNING,
"property annotation: ${it.fqName}"
)
}
}
}
}
null
}
dephinera
06/14/2020, 10:03 AMRetryWithAdditionalRoots
needs new files in order to work and skips the already analyzed files, how are we going to perform modifications on the already analyzed files. @bloder what's your plan to apply modifications after you resolved the types in analysisCompleted
?dephinera
06/14/2020, 12:53 PManalysisCompleted
. There I generate a dummy file, which I pass to RetryWithAdditionalRoots
. In the property phase I apply a transformation only if the property name is present in the map. The transformation itself is replacing the property with itself and another one. The behavior is not consistent from run to run. It appears that it works every second run but I wouldn't rely on that.
Another thing that I'm observing is that all my messages from all phases are printed only once.bloder
06/14/2020, 1:17 PMbloder
06/14/2020, 1:20 PMdephinera
06/14/2020, 1:21 PMbloder
06/14/2020, 3:17 PMBindingContext.DECLARATIONS_TO_DESCRIPTORS.flatMap {
it.makeRawValueVersion().let<ReadOnlySlice<Any, Any>, ImmutableMap<Any, Any>>(bindingTrace.bindingContext::getSliceContents).toList()
}
russhwolf
06/14/2020, 7:27 PMbindingTrace.bindingContext.getSliceContents(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL
. I was never able to read anything out of DECLARATIONS_TO_DESCRIPTORS
but I had some stuff sort of working using the TYPES
slice. Problem there was I didn’t always get a fully-qualified name.bloder
06/14/2020, 7:37 PMDECLARATIONS_TO_DESCRIPTORS
that gives me all descriptors from analysed code and pattern matching them with quotes, I`m creating right now a new type of quote that support descriptors, once I have an example I can show you, there are tests missing yet, but I think I`m making progress here 🙂dephinera
06/15/2020, 7:09 PMbloder
06/15/2020, 7:20 PMdephinera
06/15/2020, 7:29 PMdephinera
06/15/2020, 7:29 PMdephinera
06/15/2020, 7:36 PManalysisCompleted
will be called twice and I will remove the dummy file I created during the second run, while it's actually called once. There's a check that's basically does if (file.exists) file.delete
so therefore every second run it's working, because the previous one has deleted the file... I still don't get why analysisCompeted
seems to be called only once. Should it be called twice due to rewinding?russhwolf
06/15/2020, 7:41 PMdephinera
06/15/2020, 7:44 PMrusshwolf
06/15/2020, 7:45 PM