IntelliJ 代码完成不适用于新的 Java 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23462940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ Code Completion not working for new Java classes
提问by PNS
IntelliJ IDEA
13 has started exhibiting a very weird behavior in my local setup.
IntelliJ IDEA
13 开始在我的本地设置中表现出非常奇怪的行为。
Namely, in any new Java
class added to an existing project, Code Completion
does not work. So, after declaring an object variable of any type in the new class and then typing the name of that variable, followed by the dot (.), no suggestions come up for any of the methods of the corresponding object.
即,在Java
添加到现有项目的任何新类中,Code Completion
都不起作用。因此,在新类中声明任何类型的对象变量,然后键入该变量的名称,后跟点 (.) 后,不会出现对应对象的任何方法的建议。
For example, after declaring
例如,声明后
File f = new File("/home");
typing f.
does not bring up a list of all the methods in the File
class, to select one from. As a matter of fact, when typing the dot (.), no suggestions appear and at the bottom left (in the status bar) of the IDE window, the message "Identifier expected. Identifier expected." is displayed. Sometimes, a long list of totally irrelevant methods from irrelevant components or libraries are proposed.
键入f.
不会显示File
类中所有方法的列表,以从中选择一个。事实上,在输入点 (.) 时,不会出现任何建议,并且在 IDE 窗口的左下方(在状态栏中)会显示消息“需要标识符。需要标识符”。被陈列。有时,会提出一长串来自不相关组件或库的完全不相关的方法。
Strangely, Code Completion
works as expected if the above declaration happens in any of the existing classes.
奇怪的是,Code Completion
如果上述声明发生在任何现有类中,则按预期工作。
This behavior persists after many combinations of machine restart, IDE restart, project re-importing, closing/reopening, or rebuilding.
在机器重启、IDE 重启、项目重新导入、关闭/重新打开或重建的多种组合后,此行为仍然存在。
Any ideas?
有任何想法吗?
采纳答案by rogerdpack
For followers, one thing that helped me (auto complete only showed cast field instanceof etc.) was that I had opened a maven module that didn't link correctly to its children (it had a commented out submodules section), so IntelliJ just showed the maven java files as basically "text" files with a tiny "j" in their icon in the project pane. Fixing up the root maven pom.xml file to include the children dirs as modules and voila, they are treated as real java files again, woot!
对于追随者,帮助我的一件事(自动完成仅显示强制转换字段 instanceof 等)是我打开了一个没有正确链接到其子模块的 Maven 模块(它有一个注释掉的子模块部分),所以 IntelliJ 只是显示maven java 文件基本上是“文本”文件,在项目窗格的图标中带有一个小“j”。修复根 maven pom.xml 文件以将子目录包含为模块,瞧,它们再次被视为真正的 java 文件,哇!
回答by Makoto
Ensure that you are not in Power Save Mode while running IntelliJ (File [menu] -> Power Save Mode checked or not). If Power Save Mode is enabled, IntelliJ will not run background tasks, including code completion.
确保您在运行 IntelliJ 时未处于省电模式(文件 [菜单] -> 省电模式是否选中)。如果启用了省电模式,IntelliJ 将不会运行后台任务,包括代码完成。
回答by Hubert
Make sure you mark all your Source directories as such in File -> Project Structure -> Modules.
确保在文件 -> 项目结构 -> 模块中标记所有源目录。
回答by user1792551
There could be 2 reasons for your problem
您的问题可能有两个原因
- Either the the source folder is not properly configured in the your build java build path. If the source folder is not properly configured the autocomplete wont get the required class definitions and autocomplete would fail for your project.
- Restoring the default options in 'Windows > Preferences > Java > Editor > Content Assist > Advanced'
- 源文件夹未在您的构建 java 构建路径中正确配置。如果源文件夹配置不正确,自动完成将无法获得所需的类定义,并且自动完成将无法为您的项目完成。
- 恢复“Windows > Preferences > Java > Editor > Content Assist > Advanced”中的默认选项
回答by BludShot
Right click on project -> Add framework support -> Select Maven -> Click OK
右键项目 -> 添加框架支持 -> 选择 Maven -> 点击 OK
回答by Andrei C
The only thing that worked for me was killing IntelliJ (on Ubuntu) and starting it again.
唯一对我有用的是杀死 IntelliJ(在 Ubuntu 上)并重新启动它。
回答by Purushothaman
I was facing this issue while coding for eclipse-che client extension. Eclipse che modules are all of maven type. My client extension project was an independent module which can be compiled independent of the parent project. When I imported the same structure to Intellij my client-side extension project was not giving suggestions. After I include the client-extension project to the parent module (adding it to pom.xml) the suggestions started showing up.
我在为 eclipse-che 客户端扩展编码时遇到了这个问题。Eclipse che 模块都是 maven 类型的。我的客户端扩展项目是一个独立的模块,可以独立于父项目进行编译。当我将相同的结构导入 Intellij 时,我的客户端扩展项目没有给出建议。在我将客户端扩展项目包含到父模块(将它添加到 pom.xml)之后,建议开始出现。
回答by activedecay
Remove your package from the Settings>Editor>General>Auto Import>Java>Exclude from Import and Completion
从“设置”>“编辑器”>“常规”>“自动导入”>“Java”>“从导入和完成中排除”中删除您的包
I had run into this problem. None of the solutions from this post worked, but I was able to fix it because I accidentally put my project's package in the "Exclude from Import and Completion" settings.
我遇到了这个问题。这篇文章中的解决方案都没有奏效,但我能够修复它,因为我不小心将我的项目包放在“从导入和完成中排除”设置中。
回答by ?lker
Cut the folder .idea and the files *.iml in the root folder and paste somewhere else out of project. when you re-open the project , auto import will work again magically.
剪切根文件夹中的文件夹 .idea 和文件 *.iml 并粘贴到项目之外的其他位置。当您重新打开项目时,自动导入将再次神奇地工作。
回答by Sander
I had a groovy project where somehow the jdk was not set as a dependency, so jdk classes would not autocomplete.
我有一个 groovy 项目,其中 jdk 以某种方式未设置为依赖项,因此 jdk 类不会自动完成。
Fix:
使固定:
- project structure
- modules
- (your module)
- tab Dependencies.
- In the field Module SDK, add a jdk.
- 项目结构
- 模块
- (你的模块)
- 选项卡依赖项。
- 在 Module SDK 字段中,添加一个 jdk。