and then find whatever PSI you need in the created PsiFile. But I'm not sure that's what you actually need. What are you trying to accomplish and why do you think you need an artificial PSI?
Thanks so much for your reply! I'm trying to add some methods to a dart class. My base class is like this:
class S { Locale locale;
S(this.locale);
static S of(BuildContext context) => Localizations.of<S>(context, S); static final GeneratedLocalizationsDelegate delegate = new GeneratedLocalizationsDelegate();
String get backButtonTooltip => localizations[locale.languageCode]["backButtonTooltip"]; }
And I want to add more getters like this
String get name => localizations[locale.languageCode]["name"];
String get back => localizations[locale.languageCode]["back"];
First of all, you seem to be writing a plugin :). Just curious what kind of plugin is it?
You may try an alternative way to modify file content, instead of PSI modification you may modify `Document` text. Just take an instance of Document and call `insertString()`.
Thanks again for your reply. Your are so helpful. I'll make it open source this week. I just have to as some actions and I'm done. I'll update here when it's ready.
Another question. I'm using this to listen when the file changes but I get the instance of the file just after the change is commited. Any suggestions?
valuesFolder.children.forEach { documentManager.getDocument(psiManager.findFile(it)!!)!!.addDocumentListener(object : DocumentListener { override fun documentChanged(event: DocumentEvent?) { //generate my files } }) }
I'm trying to update only the part that changed in the arb file. After I generate the new class and retrieve the old one, I'm trying to make the change like this:
UPDATE on my last post. I was creating the new class using the PsiFactoryFactory and extracted the class from there. That file was not committed. So I changed to the string replace way.
Hi Lung,
You may use
and then find whatever PSI you need in the created PsiFile. But I'm not sure that's what you actually need. What are you trying to accomplish and why do you think you need an artificial PSI?
Alex
Thanks so much for your reply! I'm trying to add some methods to a dart class. My base class is like this:
First of all, you seem to be writing a plugin :). Just curious what kind of plugin is it?
You may try an alternative way to modify file content, instead of PSI modification you may modify `Document` text. Just take an instance of Document and call `insertString()`.
More about PSI, Document, etc. here: https://www.jetbrains.org/intellij/sdk/docs/basics/architectural_overview.html
I'm writing and plugin for Flutter i18n. Thanks again for your help!
Another question. Once I've build the class and saved it to the file as you helped me, how can I format the file to standard Dart?
> I'm writing and plugin for Flutter i18n.
Interesting! Is it open source / publicly available? Are you working for Google?
To reformat the whole file using the canonical dartfmt tool (via Dart Analysis Server) you may use
Thanks again for your reply. Your are so helpful. I'll make it open source this week. I just have to as some actions and I'm done. I'll update here when it's ready.
Another question. I'm using this to listen when the file changes but I get the instance of the file just after the change is commited. Any suggestions?
I'm afraid I do not get the question.
The documentChanged is called just BEFORE the document is commited. When I generate my files they are using the document just BEFORE the edit.
Ok.
Feel free to PR if you have the time. Thanks again for your help.
https://github.com/long1eu/flutter_i18n
Hi!
I'm trying to update only the part that changed in the arb file. After I generate the new class and retrieve the old one, I'm trying to make the change like this:
But I'm getting this:
UPDATE on my last post. I was creating the new class using the PsiFactoryFactory and extracted the class from there. That file was not committed. So I changed to the string replace way.