126

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
ktamlyn
  • 4,519
  • 2
  • 30
  • 41
  • possible duplicate of [Pycharm utils.py not getting syntax highlight](http://stackoverflow.com/questions/13374533/pycharm-utils-py-not-getting-syntax-highlight) – CrazyCoder Apr 10 '13 at 07:10
  • 2
    It does appear to be a duplicate but someone like myself would NEVER have found it because its not properly tagged to be found in this manner. I was not aware that Pycharm was a JetBrains product. How do you think these two questions should be linked symantically? There is a problem with how Jetbrains brands their products separately so that, for example, PHPStorm sounds like something completely different than Pycharm. I appreciate your help though!!! – ktamlyn Apr 10 '13 at 14:24
  • 1
    In other words, this question / answer stands on its own. From the perspective of people seeking this answer for IntelliJ this question / answer is unique. – ktamlyn Apr 10 '13 at 14:31

14 Answers14

369

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.

Vic
  • 21,473
  • 11
  • 76
  • 97
  • 20
    Although I thought this sounded strange, somehow my exact named file ended up under here (instead of a wildcard mapping it was the file name). Not sure how that happened. – Nick Spacek Feb 06 '14 at 20:10
  • 8
    As a note for googlers happening upon this, I had the exact same issue (with a Java file) with the same resolution; IntelliJ 13. When trying to create the file, I encountered the error 'Unable to parse template "Interface" Selected class file name mapped to not java'. Couldn't find that error message anywhere in Google, so posting it here in case someone else needs it. – Knetic Sep 22 '14 at 17:08
  • 3
    In y case, the file was not under `Text Files`. So it is better to check other file types too. – Lahiru Chandima Mar 29 '19 at 09:15
  • This is the correct answer. I accidentally set .php files (using PHPStorm) to be detected as text files. I had to remove the `*.php` extension from text files and re-added the `*.php` extension under PHP files (it should be the same for people using any other IDEA editor). – AnonymousAngelo Nov 11 '19 at 10:24
  • For me, when I was creating a file named `Memory.java` it was identified as XML schema and with icon as DTD. When I removed `Memory.java` under XML schema it started recognizing it as Java file. – Ganesh Satpute Apr 07 '20 at 17:18
  • This saved me, was not able to understand what is going wrong. Thanks a ton! – Khatri Apr 14 '20 at 12:23
  • Can someone *please* explain how on Earth the exact file names magically appear under the text files like `*myFileName.sql`? Is it some shortcut or IntelliJ action that might unintentionally put them there? – Snackoverflow Jul 28 '20 at 11:34
  • 12
    Mine has to be removed from `Auto-detect file type by content` – Calamar Jan 19 '21 at 13:48
  • As a side-note, I knew that only `variables.tf` was acting in this way, but I had difficulty finding where the setting was. So I tried to create a new wildcard mapping with that filename and found that the resulting error message told me where to look ... – Cognitiaclaeves Jun 01 '22 at 16:07
41

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

solbs
  • 940
  • 3
  • 15
  • 29
EvilInside
  • 795
  • 10
  • 13
32

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
kmoney12
  • 4,413
  • 5
  • 37
  • 59
17

OSX:

Preferences > Editor > File Types > Text

Windows:

Settings > Editor > File Types > Text Files
isherwood
  • 58,414
  • 16
  • 114
  • 157
matt burns
  • 24,742
  • 13
  • 105
  • 107
  • 1
    I had somehow accidentally added the entire name of a specific file to the list of registered patterns under Editor > Filetypes > Text. Removing it from that list solved the mystery. – ReLeaf Aug 01 '17 at 12:50
6

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

isaac.hazan
  • 3,772
  • 6
  • 46
  • 76
5

I solved the same issue by

Right-click on the file ->  "Override File Type" -> Select the extension type the file has.
Hernan
  • 81
  • 2
  • 6
2

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
ToddEmon
  • 1,140
  • 1
  • 12
  • 16
0

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 :)

Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
0

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.

YDZOGODOQ
  • 71
  • 1
  • 4
0

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

IamVickyAV
  • 1,495
  • 1
  • 17
  • 15
0

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

C. Peck
  • 3,641
  • 3
  • 19
  • 36
0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Node Noodler
  • 116
  • 7
-1

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.

-1

Workaround: Rename the file without changing the file extension.

FileName.java
NewDifferentFileName.java
Carolus
  • 477
  • 4
  • 16
CoffeeTime
  • 305
  • 1
  • 6
  • 17