Question

There is a freemarker file (ftl) in my IntelliJ project that is incorrectly recognized as a text file. There are many of the same type that are correct.

I am aware of the "Mark as text" option. This may be the original reason this file was marked as text but I am not provided with a "mark as ftl file" option to turn it back, if indeed this is the problem. If I mark other ftl files as txt, I am able to turn them back into ftl files as expected.

Was it helpful?

Solution

Please ensure that this file (or a pattern that represents it) is not listed under

SettingsEditorFile TypesText

For OS X

PreferencesEditorFile TypesText

Sometimes the file or pattern are stuck under File type auto-detected by file content instead of Text.

OTHER TIPS

Step 1: Click "File" ==> "Settings" for Windows or "InterlliJ IDEA" ==> "Preferences" for Mac

Step 2: Expand "Editor" & Click "File Types"

Step 3: You will see all file types on Right. Navigate to the "Text" entry and click it

Step 4: You should able to see your file name on the bottom of "Registered Patterns" (lower box)

Step 5: Remove your file from the "Registered Patterns". The problem should be solved and let you rename with fileName.java

Step 6: If not, delete the file from the project and create it again with name fileName

Source

In 2020 none of the posted answers worked, here's what did:

  1. Left click the file
  2. On the top toolbar, select File -> File Properties -> Associate with File Type

OSX:

Preferences > Editor > File Types > Text

Windows:

Settings > Editor > File Types > Text Files

I had the same problem and none of the above solution solved it. The thing that at the end solved it was by selecting the module and going to the module settings(press F4 on the module name)

Then in the Sources tab, select the "java" folder and press on the Sources button. That tells IntelliJ that the folder in question is a source code folder.

Then select the Test folder and press Tests.

That's it. Then it will recognize correctly the files and show errors as needed.

See below the screenshot.

enter image description here

I solved the same issue by

Right-click on the file ->  "Override File Type" -> Select the extension type the file has.

I had this problem with a single SQL file. Thanks to kmoney12's answer, I was able to solve it following these steps (I'm using IntelliJ IDEA 2021.3.2 Ultimate Edition, so the steps are not exactly the same) :

  1. Right-click on the file
  2. In the contextual menu, find and choose Override File Type
  3. Select the correct file type in the list

You might have by accident edited the template in File and Code Template. Press Ctrl+Alt+S

Under

 Settings -> Editor -> File and Code Templates

For me I changed the FileHeader.java file in includes tab.

Recall which type of template you might have changed earlier and revert it back to default.

Hope it works :)

My specific java filename was not listed in 'Text files' (IntelliJ 2019.3).

After shutting down IntelliJ, then grepping for the filename in .Intellij2019.3, I found a match here: .Intellij2019.3\config\options\filetypes.xml.

After removing the name, IntelliJ sees the file as Java file again.

This is what worked for me

Go to

File -> Settings -> Editor -> File Types

Removed my file from File name patterns under Auto-detect file type by content option

I got this error when I created a new interface BenefitService.java it take as a simple text file. The error looks like this:

Unable to parse template “Interface”

Error message: Selected class file name ‘BenefitService.java’ mapped to not java file type ‘Auto-detect file type by content`

So just go IntellJ File -> Settings -> Editor -> File Types->Auto detect file type content and remove your file name eg in my case BenefitService.java it will work

There's another reason for a file not being coloured in. I've found RubyMine can get stuck analyzing a file, and then it doesn't colour it in. For me this happens on .html.slim files when RubyMine gets confused translating/fetching keys from yml files, for example when implying yml files in both views and controller on a single view file.

Renaming the file appears to fix it, but that's because it no longer gets stuck resolving the yml files, but you think it's the file association problem.

Another way to test it is to comment everything out, using / in the case of slim. Then close file and re-open. It is then coloured for being commented. Remove the comments and it works because Rubymine doesn't try to resolve yml data after the file is opened. But closing then re-open and it gets stuck again as it gets confused.

I had the same problem to creat a new class java, the issue was on Header.java that can be access with the command crt+alt+s and go to Editor/FileAndCodeTemplates/Includes and this may be on this format:

/** * Created by Alex Leporoni on ${DATE}. */

This is solved my issue, now I can create classes again :) I hope that this article can help others that have the same problems to creat classes on IntelliJIdea... hugs to all.

Workaround: Rename the file without changing the file extension.

FileName.java
NewDifferentFileName.java
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top