How do you import a reference to a dart file when you only know the file name? Extension methods and others - intellij-idea

To import a file in Dart (using IntelliJ) I will usually use start typing the name of a function, class or variable and select enter. Alternatively I might type the name of the class and press alt+enter on it. This will then give me an option to import the file reference.
For extension methods this doesn't work and sometimes I know the name of the package (file) I want to import but can't remember the name of the function.
Is there a way to use the filename to lookup and insert an import statement with the full package address?
Edit
Unfortunately my originally accepted answer doesn't always work. For example with extension methods. I'm trying to add a reference and it seems impossible to do without typing the full reference to the extension.
Edit2
Found out there is an open issue to fix this
https://github.com/dart-lang/sdk/issues/40365

You can write import 'som...' and ctrl+space for auto-complete and get IntelliJ to make suggestion across all packages imported with pubspec and files across the project. If the file is inside a package, it will automatically insert the full path.

Related

Intellij Flutter - Import via Alt+Enter not working

My team members and me often face the problem in Intellij that we cannot import some classes via Alt+Enter because Intellij hasn't indexed them successfully.
Our set up
We have different Flutter projects which belong and work together.
ProjectFolder:
our_project/customer_app
our_project/provider_app
our_project/server_app
our_project/model_app
Some of these projects have dependencies to other projects which are declared in the pubspec.yaml file.
Problem
E.g. the customer_app has a dependency to the model_app.
Now we add this new class in model_app such as class MyModel.
Later in the process we want to use MyModel inside of the customer_app.
If we type something like MyModel() and try to press Alt+Enter it doesn't find the class immediately. (it works miracously only sometimes)
What we have to do then is to copy the path of MyModel and do the import manually. Which is often time consuming.
We even tried to run flutter packages get which also doesn't help to find this import of MyModel. Ideally we want that Intellij find the import automatically by indexing it without copying the path out of the other project.
This is a known issue and planned to be fixed eventually.
You can upvote https://github.com/dart-lang/sdk/issues/25820

intellij cannot resolve symbol "File"

I have this in my script
import groovy.io.FileType
.....
derp = new File("blah")
The script works but inetillij complains it cant resolve "File" and it suggested I import a totally different wrong library for it (com.jidesoft.icons.IconSet)
I already tried invalidating cache and restarting
How do I get intelllij to import groovy.io.FileType? I cant even find a way to suppress error either it doesnt give me that option
groovy.io.FileType is an enum class. It appears your variable derp would be of type File, not FileType.
You can statically import enums from the FileType class (for example):
import static groovy.io.FileType.*
In my Intellij on Java 8 the File class comes from the java.io package in a .groovy file.

How to use .swift file in Objective-C?

I have added (by drag n drop) a .swift file in my objective-C code, Now I want to use it into my Objective-C code. I tried importing like:
#import "MyProductModuleName-Swift.h"
But file not found appears.
You need to go to your target Build Settings and change Define Module to Yes and also you need to change Product Module Name to some value.
Now it will show the YourProductModuleName but if you click on it it shows $(PRODUCT_NAME:c99extidentifier), replace it with your module name and use it in import as in the example in your question.
Hope this help
The file is created automatically (talking about Xcode 6.3.2 here). But you won't see it, since it's in your Derived Data folder. After marking your swift class with #objc, compile, then search for Swift.h in your Derived Data folder. You should find the Swift header there.
I had the problem, that Xcode renamed my my-Project-Swift.h to my_Project_Swift.h Xcode doesn't like "." "-" etc. symbols. With the method above you can find the filename and import it to a Objective-C class.
And you should also need to change the target of your project to 10.9
Try this hope it helps.

Xcode:How to import parent's header in a sub-project

I've a project that has a subproject (an XPC worker). Here I need to import one header from the main(parent) project. How do I do this?
I tried by setting(Sub project's) Header Search Path, User Header Search Path with values like $(SRCROOT) & $(SRCROOT)/../Interface.h. Also tried by changing the settings Recursive and Non-Recursive.
The way to solve these issues is to look at the actual compiler line when building the target to see what folders are being specified in the -I options and work from there. You need to go to the Build Log, find a file being compiled and then expand the command using the dropdown button thing on the right of the line.
The structure for all projects is fairly unique, so it's almost impossible to provide a one-size-fits-all fix for this.

python: from modules import abc.py does not work

I have recently switched from python 2.7 to python 3.2
considering following folder structure:
~/my_program
~/my_program/modules
where *my_program* is the root of the application, containing main script called main.py
*my_program/modules* is used to store all additional classes and subscripts
in python2.x I was able to import any file "module" the same way I do import standard modules
from modules import abc.py
however, while I try to launch the same program in python3.2 I get the error message saying:
File "/my_program/modules/__init__.py" line 1
import abc, def
ImportError: No module named abc
Please advise
It's a good example you are using, because "abc" is in fact a module in the standard library. So in fact, if you in Python 3 do import abc that will work just fine, but you will get the standard library module.
In Python 2, if you had a local module called abc.py, that import abc would import the local module instead. That means you couldn't import the module from the standard library.
In Python 3, this has been changed, and you now need to use the fully qualified name, in your case probably from modules import abc.
Where are you storing the module you created? When I create a module, I do the following:
Create a folder in the lib\sitepackages folder in your python folder ex: myModules
Save a blank python file named init.py in this folder. The file does not have to contain any syntax. Later on, you can set module requirements in this file if you wish.
Save your module into this folder ex: myGamesModule.py
In idle (or whichever python connected IDE you use) type:
from myModules import myGamesModule or from myModules import myGamesModule as myGmMod
That should import your module and then you can call the classes etc ex myGmMod.Player()
I am sure that this is correct, as I have just done it and it was ok.
I have found that sometimes, if I create a blank text file in the module folder and rename it to init.py, it has caused me problems before. I usually just open IDLE and save a init.py file from there into my module folder and then use whichever IDE I use (sublime) to create and save the rest of the files.
Also, for some reason, the text box has disallowed the underscores I am using in this text so where you see init.py, it should be (underscoreunderscore*init*underscoreunderscore.py without any asterix