Skip to content
This repository has been archived by the owner on Dec 28, 2019. It is now read-only.

Commit

Permalink
Provide a way to work with other file name extensions #49
Browse files Browse the repository at this point in the history
  • Loading branch information
shalupov committed Feb 8, 2016
1 parent 22d5a99 commit 95bf005
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import com.google.common.base.Charsets;
import com.intellij.icons.AllIcons;
import com.intellij.json.JsonFileType;
import com.intellij.json.JsonLanguage;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.fileTypes.ex.FileTypeIdentifiableByVirtualFile;
import com.intellij.openapi.util.io.ByteSequence;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileSystem;
import com.intellij.openapi.vfs.newvfs.FileSystemInterface;
import com.intellij.openapi.vfs.newvfs.impl.StubVirtualFile;
import com.intellij.util.Processor;
import org.apache.commons.lang.ArrayUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -58,7 +57,12 @@ public Icon getIcon() {

@Override
public boolean isMyFileType(@NotNull VirtualFile file) {
return CloudFormationFileType.EXTENSION.equalsIgnoreCase(file.getExtension()) && detectFromContent(file);
String extension = file.getExtension();

return extension != null &&
(FileTypeManager.getInstance().getFileTypeByExtension(extension) == JsonFileType.INSTANCE ||
CloudFormationFileType.EXTENSION.equalsIgnoreCase(extension)) &&
detectFromContent(file);
}

private boolean detectFromContent(@NotNull VirtualFile file) {
Expand Down
5 changes: 5 additions & 0 deletions testData/inspections/expected.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<line>2</line>
<description>Unknown AWS CloudFormation template version &quot;2010-09-09 + 1&quot;. Supported versions: 2010-09-09</description>
</problem>
<problem>
<file>wrongVersion.json</file>
<line>2</line>
<description>Unknown AWS CloudFormation template version &quot;2010-09-09 + 1&quot;. Supported versions: 2010-09-09</description>
</problem>
<problem>
<file>noResourceType.template</file>
<line>6</line>
Expand Down
7 changes: 7 additions & 0 deletions testData/inspections/src/wrongVersion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"AWSTemplateFormatVersion": "2010-09-09 + 1",
"Description": "desc",

"Resources": {
}
}

0 comments on commit 95bf005

Please sign in to comment.