Skip to content

Commit

Permalink
not using deprecated FileTypeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
ghik committed Oct 22, 2019
1 parent c0368f7 commit 7aa6618
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 21 deletions.
3 changes: 2 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
</change-notes>

<extensions defaultExtensionNs="com.intellij">
<fileTypeFactory implementation="org.jetbrains.plugins.hocon.lang.HoconFileTypeFactory"/>
<fileType implementationClass="org.jetbrains.plugins.hocon.lang.HoconFileType"
name="HOCON" language="HOCON" extensions="conf"/>
<lang.syntaxHighlighterFactory language="HOCON"
implementationClass="org.jetbrains.plugins.hocon.highlight.HoconSyntaxHighlighterFactory"/>
<lang.parserDefinition language="HOCON"
Expand Down
2 changes: 1 addition & 1 deletion src/org/jetbrains/plugins/hocon/indexing/indices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ abstract class HKeyIndex[K](companion: HKeyIndexCompanion[K])
def getValueExternalizer: DataExternalizer[HKeyOccurrences] = HKeyOccurrences.Externalizer

def acceptInput(file: VirtualFile): Boolean =
file.getFileType == HoconFileType
HoconFileType.isHocon(file.getFileType)

def map(inputData: FileContent): JMap[K, HKeyOccurrences] = inputData.getPsiFile match {
case hf: HoconPsiFile =>
Expand Down
16 changes: 11 additions & 5 deletions src/org/jetbrains/plugins/hocon/lang/HoconFileType.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package org.jetbrains.plugins.hocon
package lang

import com.intellij.openapi.fileTypes.LanguageFileType
import com.intellij.openapi.fileTypes.{FileType, LanguageFileType}
import javax.swing.Icon

object HoconFileType extends LanguageFileType(HoconLanguage) {
val DefaultExtension = "conf"

final class HoconFileType extends LanguageFileType(HoconLanguage) {
def getIcon: Icon = HoconIcon
def getDefaultExtension: String = DefaultExtension
def getDefaultExtension: String = HoconFileType.DefaultExtension
def getDescription = "HOCON"
def getName = "HOCON"
}
object HoconFileType {
val DefaultExtension = "conf"

def isHocon(fileType: FileType): Boolean = fileType match {
case _: HoconFileType => true
case _ => false
}
}
11 changes: 0 additions & 11 deletions src/org/jetbrains/plugins/hocon/lang/HoconFileTypeFactory.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class HoconUseScopeAdjuster extends UseScopeEnlarger with ScopeOptimizer {
new EverythingGlobalScope(project) {
// HOCON files in library sources are just duplicates of the same HOCON files in regular library jars
override def contains(file: VirtualFile): Boolean =
!(file.getFileType == HoconFileType && pfi.isInLibrarySource(file))
!(HoconFileType.isHocon(file.getFileType) && pfi.isInLibrarySource(file))
}
case _ =>
super.getRestrictedUseScope(element)
Expand Down
2 changes: 1 addition & 1 deletion src/org/jetbrains/plugins/hocon/psi/HoconPsiElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class HoconPsiFile(provider: FileViewProvider)
visitor.visitFile(this)

def getFileType: FileType =
HoconFileType
new HoconFileType

def toplevelChild: HoconPsiElement =
findChildByClass(classOf[HoconPsiElement])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object HoconPsiElementFactory {

private def createElement[T <: HoconPsiElement : ClassTag](manager: PsiManager, text: String, offset: Int): Option[T] = {
val element = PsiFileFactory.getInstance(manager.getProject)
.createFileFromText(Dummy + HoconFileType.DefaultExtension, HoconFileType, text).findElementAt(offset)
.createFileFromText(Dummy + HoconFileType.DefaultExtension, new HoconFileType, text).findElementAt(offset)
Iterator.iterate(element)(_.getParent).takeWhile(_ != null).collectFirst({ case t: T => t })
}

Expand Down

0 comments on commit 7aa6618

Please sign in to comment.