Skip to content

Commit

Permalink
refactor: impl getNameIdentifier()
Browse files Browse the repository at this point in the history
  • Loading branch information
BFergerson committed Aug 22, 2022
1 parent a6d4443 commit 6164dbe
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,11 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider {
sourceMark.triggerEvent(SourceMarkEvent(sourceMark, SourceMarkEventCode.MARK_BEFORE_ADDED))
if (sourceMarks.add(sourceMark)) {
when (sourceMark) {
is ClassGutterMark -> sourceMark.getPsiElement().nameIdentifier!!.putUserData(
SourceKey.GutterMark,
sourceMark
)
is ClassGuideMark -> sourceMark.getPsiElement().nameIdentifier!!.putUserData(
SourceKey.GuideMark,
sourceMark
)
is MethodGutterMark -> sourceMark.getPsiElement().nameIdentifier!!.putUserData(
SourceKey.GutterMark,
sourceMark
)
is MethodInlayMark -> sourceMark.getPsiElement().nameIdentifier!!.putUserData(
SourceKey.InlayMark,
sourceMark
)
is MethodGuideMark -> sourceMark.getPsiElement().nameIdentifier!!.putUserData(
SourceKey.GuideMark,
sourceMark
)
is ClassGutterMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GutterMark, sourceMark)
is ClassGuideMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GuideMark, sourceMark)
is MethodGutterMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GutterMark, sourceMark)
is MethodInlayMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.InlayMark, sourceMark)
is MethodGuideMark -> sourceMark.getNameIdentifier().putUserData(SourceKey.GuideMark, sourceMark)
is ExpressionGutterMark -> sourceMark.getPsiElement().putUserData(SourceKey.GutterMark, sourceMark)
is ExpressionInlayMark -> sourceMark.getPsiElement().putUserData(SourceKey.InlayMark, sourceMark)
is ExpressionGuideMark -> sourceMark.getPsiElement().putUserData(SourceKey.GuideMark, sourceMark)
Expand Down Expand Up @@ -227,43 +212,25 @@ open class SourceFileMarker(val psiFile: PsiFile) : SourceMarkProvider {
override fun createExpressionSourceMark(psiExpression: PsiElement, type: SourceMark.Type): ExpressionSourceMark {
log.trace("Creating source mark. Expression: $psiExpression - Type: $type")
return when (type) {
SourceMark.Type.GUTTER -> {
ExpressionGutterMark(this, psiExpression)
}
SourceMark.Type.INLAY -> {
ExpressionInlayMark(this, psiExpression)
}
SourceMark.Type.GUIDE -> {
ExpressionGuideMark(this, psiExpression)
}
SourceMark.Type.GUTTER -> ExpressionGutterMark(this, psiExpression)
SourceMark.Type.INLAY -> ExpressionInlayMark(this, psiExpression)
SourceMark.Type.GUIDE -> ExpressionGuideMark(this, psiExpression)
}
}

override fun createMethodSourceMark(psiMethod: PsiNameIdentifierOwner, type: SourceMark.Type): MethodSourceMark {
return when (type) {
SourceMark.Type.GUTTER -> {
MethodGutterMark(this, psiMethod)
}
SourceMark.Type.INLAY -> {
MethodInlayMark(this, psiMethod)
}
SourceMark.Type.GUIDE -> {
MethodGuideMark(this, psiMethod)
}
SourceMark.Type.GUTTER -> MethodGutterMark(this, psiMethod)
SourceMark.Type.INLAY -> MethodInlayMark(this, psiMethod)
SourceMark.Type.GUIDE -> MethodGuideMark(this, psiMethod)
}
}

override fun createClassSourceMark(psiClass: PsiNameIdentifierOwner, type: SourceMark.Type): ClassSourceMark {
return when (type) {
SourceMark.Type.GUTTER -> {
ClassGutterMark(this, psiClass)
}
SourceMark.Type.INLAY -> {
TODO("Not yet implemented")
}
SourceMark.Type.GUIDE -> {
ClassGuideMark(this, psiClass)
}
SourceMark.Type.GUTTER -> ClassGutterMark(this, psiClass)
SourceMark.Type.INLAY -> TODO("Not yet implemented")
SourceMark.Type.GUIDE -> ClassGuideMark(this, psiClass)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package spp.jetbrains.marker.source.mark.api
import com.intellij.openapi.Disposable
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiInvalidElementAccessException
import com.intellij.psi.PsiNameIdentifierOwner
import spp.jetbrains.marker.impl.ArtifactNamingService
Expand Down Expand Up @@ -133,6 +134,11 @@ abstract class ClassSourceMark(
return psiClass
}

fun getNameIdentifier(): PsiElement {
return psiClass.nameIdentifier
?: throw PsiInvalidElementAccessException(psiClass, "No name identifier. Artifact: $artifactQualifiedName")
}

fun updatePsiClass(psiClass: PsiNameIdentifierOwner): Boolean {
this.psiClass = psiClass
val newArtifactQualifiedName = ArtifactNamingService.getFullyQualifiedName(psiClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package spp.jetbrains.marker.source.mark.api
import com.intellij.openapi.Disposable
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiInvalidElementAccessException
import com.intellij.psi.PsiNameIdentifierOwner
import spp.jetbrains.marker.impl.ArtifactNamingService
Expand Down Expand Up @@ -138,6 +139,11 @@ abstract class MethodSourceMark(
return psiMethod
}

fun getNameIdentifier(): PsiElement {
return psiMethod.nameIdentifier
?: throw PsiInvalidElementAccessException(psiMethod, "No name identifier. Artifact: $artifactQualifiedName")
}

fun updatePsiMethod(psiMethod: PsiNameIdentifierOwner): Boolean {
this.psiMethod = psiMethod
val newArtifactQualifiedName = ArtifactNamingService.getFullyQualifiedName(psiMethod)
Expand Down

0 comments on commit 6164dbe

Please sign in to comment.