Option to manually add an import
See original GitHub issueHi, I am aware that JavaPoet is automatically managing imports, but I would appreciate possibility to manually add non-static import.
The need occurs when I copy method implementation from an existing class to a class I build with JavaPoet. I don’t really know what the method implementation looks like, nor I care. But the implementation may be depending on an import statement, which JavaPoet is not and can’t be aware of.
Note that parsing method implementation is heroic task, which I want to avoid. Thanks
poor man’s workaround
This one is for field initializers, but same applies to code in methods.
initializerString = initializerString.replaceAll("HashSet", "java.util.HashSet"); // etc.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:21 (8 by maintainers)
Top Results From Across the Web
Auto import | IntelliJ IDEA Documentation - JetBrains
In the Settings/Preferences dialog ( Ctrl+Alt+S ), click Editor | General | Auto Import. Select the Add unambiguous imports on the fly checkbox ......
Read more >Text Import Wizard - Microsoft Support
Once enabled, go to the Data tab > Get & Transform Data > Get Data > Legacy Wizards > From Text (Legacy). Then,...
Read more >Manually Add or Import Users - SocialChorus Knowledge Base
Hover over Add User to expand the menu and select Import Users. If you have a file prepared, confirm that it has the...
Read more >Any way (or shortcut) to auto import the classes in IntelliJ IDEA ...
Save this answer. Show activity on this post. Use Alt + Enter for importing a single package or use Alt + Shift +...
Read more >Import photos and videos on iPhone - Apple Support
Insert an SD memory card into the card reader: Don't force the card into the slot on the reader; it fits only one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This feature would not help your issue. To add an import you need the package name and the class name which means you could call ClassName.get(packageName, className) and emit the reference normally.
On Thu, Sep 7, 2017 at 7:12 AM Thomas Bigger notifications@github.com wrote:
You get a TypeName for it like so:
ClassName.get("android.graphics.drawable", "ColorDrawable")Then you can use that wherever
$Tis accepted, and it will import it for you. If you want to explicitly reference theClassfor it, you can do$T.classand pass theClassName.