如何让 Eclipse 像 java 文件一样处理没有扩展名的文件?

How to make eclipse treat a file with no extension like a java file?

我有一个 eclipse 项目,一些 java 来源没有扩展名。当我在 Java 编辑器 中打开它们时,eclipse 会突出显示关键字但没有 syntax/error 检查器。

问题:如何让eclipse Java编辑器处理任何文件,作为 .java 文件?

我无法重命名文件的原因是我的目录中有一些外部文件,没有扩展名。我在项目中导入了该目录作为源文件夹,但我现在只需要编辑文件,我不能重命名它们。

我认为没有简单的方法可以做到这一点。

我会写一个这样的脚本。

public static void reExtensionize(File dir) {
    for (File f : dir.listFiles()) {
        if (f.isDirectory()) reExtensionize(f);
        if (isJavaFile(f)) {// Check the file to see if it contains Java
                        // code
            Files.move(f.toPath(), new File(f.getAbsolutePath()
                    + ".java").toPath());
        }
    }
}

我想以下内容会有所帮助:

更新:

如评论中所述,无扩展文件的关联被报告了很长时间bug,直到现在才解决。

但是,如果您使用的是 Zend Studio for Eclipse,您可以在其中找到建议 article:

What a trick, indeed. Do this at your own risk. If you bork your install, I'll try to help, but ultimately you're on your own.

  1. Go to your Zend > Zend Studio for Exclipse 6.x > Plugins folder and look for org.eclipse.php.core. Mine was actually a .jar file. If it is a jar file, simply rename the .jar to .zip and decompress. The resulting directory will work the same as the .jar file. (keep the .zip as a backup)
  2. Search for the string: file-extensions
  3. Add a comma inside the extension list. Mine looks like this: file-extensions="php,php3,php4,php5,,phtml,inc"
  4. Save the file and start Zend Studio for Eclipse It turns out that the double comma is interpreted as an empty string, as it should be. But this is dirty, yep. Expect it to be overwritten by your next install, etc. But all files that don't have an extension will now be handled as PHP by Eclipse.

注意: php 代码在图像中,不幸的是,那篇文章就是这样嵌入代码的。