Hello, Is there a way to overwrite an already genr...
# ksp
d
Hello, Is there a way to overwrite an already genrated file. My usecase is that i want to generate a single class which implents multiple interface generated throughout the multiple rounds of ksp and this Generated class is also used by another KSP processor(Not under my control) so i can't generate the class in finish as well. Is there any way to do this, Any help would be appreciated.
j
No you can’t overwrite an already generated file. you can use other mechanism to achieve that, like generating intermediate files.
d
But the problem is i never know whether this is the last round of ksp and if i generate my file based on intermediate file in the
finish
of ksp processor then they the generated file is not picked by other processor because all the rounds of KSP are finished.
Could you please suggest a workaround?
j
Generated class is also used by another KSP processor
suggests that the other processor is waiting on your generated class right? Then as long as you hold on generating your class until all necessary interfaces are generated, it should be fine. The only issue remaining is how to figure out all necessary interfaces are generated, since you have control over it, you should be able to figure it out.
d
I can certainly figure out when to generate the my final file by checking if there any inputs in the current round that can genrate my interfaces or not but the main problem is that let's say a
Processor3
generates some file which results in generating interfaces by my processor then my Processor will have next round in which it will generate some more interfaces(Please correct me if my understanding of incremental processing in ksp is wrong).
j
incremental does not apply to the same KSP task, it is for dealing with changes across different KSP tasks.
d
I am new to ksp So can you please clear if the Processor3 is of a different library even then will there be no incremental processing or multiple rounds of processing?
j
multiple round processing happens within a same KSP task, incremental is there to avoid duplicate work across multiple invokations of same KSP tasks.
d
Then I think I should ask about multiple round processing rather than incremental processing, But the problem still remains defined above, I am not able to think of any solution, your help would be much appreciated.
j
if the Processor3 is of a different library
as long as you apply all processors in same KSP task, they will be executed together in the same multiple round environment.
d
Can you clarify one thing, let's say MyProcessor doesn't generate any output in round 1 but other processor does then MyProcessor will have a next round of processing even though it didn't generate any output in previous round right?
j
yes, all processor will be invoked in every round even if they don’t generated anything in last round.
d
So then how can I ever identify whether the current round can ever be last round because I can never conclude or be sure I will not have any interfaces generated in the next round based on the current round processing and inputs?
j
there is no way for you to know it by KSP’s mechanism, you should try to figure it out with the behavior from the processor you are waiting output on. ideally your processor should be waiting on certain classes to be generated in order for it to start generating code.
d
So ideally we can't really create a processor for such a case where we can expect any other processor to generate the code on which our processor might depend. We can only assume it right?
j
so what you are trying to do here is to gather whatever being generated from another processor and combine them all together? Doesn’t sound like a good case for annotation processing tbh.. One solution I can think of is if the said
Processor3
generates a marker interface as the last output, then you can try to wait for that interface to start your work.
d
Yes, this is actually the case. This is a good workaround but I will have to write the guidelines for the library on top of it to work properly. Can you tell me what this would be a good case of just curious?
If someone wants to build something on top of this lib.
j
There might be other solutions but I can’t immediately think of one right now, the solution I mentioned above is just my first intuition.
d
Yeah but thanks for the help. But can you tell me why is this not a good case for annotation processing?
j
because there is no deterministic way to know if another processor has reached end of processing (there shouldn’t be because you never know if the end user will apply a
Processor4
just to trigger a round of
processor3
to generate stuff again).
d
Yeah I agree but it is a valid case to consider because even though we don't know the end of processing we should be able to process all data from the current and upcoming rounds. Why can we not introduce overwriting of the file the main problem is that?
j
overwriting file will cause potential invalidation of the result of other processors, that will be an spiral of cases to be addressed.
d
Okay got it. Thank you. Will try to look further into this.