Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
ris58h committed Jul 18, 2023
1 parent 8ef96cc commit f090e5e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/main/kotlin/ris58h/webcalm/css/psi/CssFile.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package ris58h.webcalm.css.psi

import com.intellij.extapi.psi.PsiFileBase
import com.intellij.openapi.fileTypes.FileType
import com.intellij.psi.FileViewProvider
import com.intellij.psi.util.PsiTreeUtil
import ris58h.webcalm.css.CssFileType
import ris58h.webcalm.css.CssLanguage

class CssFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, CssLanguage) {
override fun getFileType(): FileType = CssFileType.INSTANCE
override fun getFileType() = CssFileType.INSTANCE

override fun toString(): String = "CSS file"
override fun toString() = "CSS file"

val statements: List<CssNestedStatement>
get() = PsiTreeUtil.getChildrenOfTypeAsList(this, CssNestedStatement::class.java)
Expand Down
13 changes: 5 additions & 8 deletions src/main/kotlin/ris58h/webcalm/css/psi/CssVariable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.intellij.psi.PsiNamedElement
import com.intellij.psi.PsiReference
import com.intellij.psi.impl.source.tree.LeafPsiElement
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.SearchScope

class CssVariable(text: CharSequence) : LeafPsiElement(CssTypes.VARIABLE, text), PsiNamedElement, PsiNameIdentifierOwner {
val isDeclaration: Boolean
Expand All @@ -20,19 +19,17 @@ class CssVariable(text: CharSequence) : LeafPsiElement(CssTypes.VARIABLE, text),
}
}

override fun getName(): String = text
override fun getName() = text

override fun setName(name: String): PsiElement {
val newVariable: PsiElement = CssElementFactory.createVariableFromText(project, name)
val newVariable = CssElementFactory.createVariableFromText(project, name)
return replace(newVariable)
}

override fun toString(): String = "CSS_VARIABLE"
override fun toString() = "CSS_VARIABLE"

override fun getUseScope(): SearchScope {
return LocalSearchScope(containingFile)
}
override fun getUseScope() = LocalSearchScope(containingFile)

// TODO a hack to make InplaceRefactoring.getSelectedInEditorElement work.
override fun getNameIdentifier(): PsiElement = this
override fun getNameIdentifier() = this
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ris58h.webcalm.javascript.psi

import com.intellij.extapi.psi.PsiFileBase
import com.intellij.openapi.fileTypes.FileType
import com.intellij.psi.FileViewProvider
import ris58h.webcalm.javascript.JavaScriptFileType
import ris58h.webcalm.javascript.JavaScriptLanguage

class JavaScriptFile(viewProvider: FileViewProvider) :
PsiFileBase(viewProvider, JavaScriptLanguage), JavaScriptStatementsOwner {
override fun getFileType(): FileType = JavaScriptFileType.INSTANCE
override fun getFileType() = JavaScriptFileType.INSTANCE

override fun toString(): String = "JavaScript file"
override fun toString() = "JavaScript file"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class JavaScriptIdentifier(node: ASTNode) : ASTWrapperPsiElement(node), PsiNameI

override fun setName(name: String): PsiElement {
val idLeaf = nameIdentifier
val newIdLeaf: PsiElement = JavaScriptElementFactory.createIdentifierTokenFromText(project, name)
val newIdLeaf = JavaScriptElementFactory.createIdentifierTokenFromText(project, name)
return idLeaf.replace(newIdLeaf)
}

override fun getTextOffset(): Int = nameIdentifier.textOffset
override fun getTextOffset() = nameIdentifier.textOffset

override fun getNameIdentifier(): PsiElement = firstChild

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package ris58h.webcalm.javascript.psi

import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.lang.ASTNode
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiNameIdentifierOwner

open class JavaScriptIdentifierOwner(node: ASTNode) : ASTWrapperPsiElement(node), PsiNameIdentifierOwner {
val identifier: JavaScriptIdentifier?
get() = this.findChildByClass(JavaScriptIdentifier::class.java)

override fun getName(): String? = identifier?.name
override fun getName() = identifier?.name

override fun setName(name: String): PsiElement = identifier?.setName(name) ?: this
override fun setName(name: String) = identifier?.setName(name) ?: this

override fun getTextOffset(): Int = identifier?.textOffset ?: super.getTextOffset()
override fun getTextOffset() = identifier?.textOffset ?: super.getTextOffset()

override fun getNameIdentifier(): PsiElement? = identifier?.nameIdentifier
override fun getNameIdentifier() = identifier?.nameIdentifier
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package ris58h.webcalm.javascript.psi

import com.intellij.lang.ASTNode
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.SearchScope

class JavaScriptLabeledStatement(node: ASTNode) : JavaScriptIdentifierOwner(node), JavaScriptStatement {
val statement: JavaScriptStatement?
get() = this.findChildByClass(JavaScriptStatement::class.java)

override fun getUseScope(): SearchScope = LocalSearchScope(this)
override fun getUseScope() = LocalSearchScope(this)
}

0 comments on commit f090e5e

Please sign in to comment.