Skip to content

Commit

Permalink
GH-47 remove internal and deprecated apis
Browse files Browse the repository at this point in the history
  • Loading branch information
akefirad committed Jan 20, 2025
1 parent 4b31af7 commit aad27e0
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.akefirad.groom.groovy

import com.akefirad.groom.intellij.PsiElementExtensions.endOffset
import com.akefirad.groom.intellij.PsiElementExtensions.startOffset
import com.intellij.lang.ASTNode
import com.intellij.lang.folding.CustomFoldingBuilder
import com.intellij.lang.folding.FoldingDescriptor
Expand Down Expand Up @@ -34,8 +36,8 @@ class GroovyFoldingBuilder : CustomFoldingBuilder() {
if (child.isSingleLine()) continue
if (child.hasLeftOpen()) continue

val start = child.textRange.startOffset
val end = child.textRange.endOffset
val start = child.startOffset
val end = child.endOffset
val range = TextRange(start, end)
d.add(FoldingDescriptor(e.node, range))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.akefirad.groom.intellij

import com.intellij.psi.PsiElement

object PsiElementExtensions {
val PsiElement.startOffset get() = textRange.startOffset
val PsiElement.endOffset get() = textRange.endOffset
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.akefirad.groom.spock

import com.akefirad.groom.intellij.PsiElementExtensions.startOffset
import com.akefirad.groom.spock.SpockSpecUtils.isSpeckLabel
import com.intellij.codeInsight.hints.declarative.InlayHintsProvider
import com.intellij.codeInsight.hints.declarative.InlayTreeSink
Expand Down Expand Up @@ -79,7 +80,7 @@ class AssertInlayHintsCollector : SharedBypassCollector {
val closure = e.lastChild as? GrClosableBlock ?: return
closure.children.forEach { collectFromExpectationBlockChildren(it, sink) }
} else {
val position = InlineInlayPosition(e.textRange.startOffset, relatedToPrevious = false)
val position = InlineInlayPosition(e.startOffset, relatedToPrevious = false)
sink.addPresentation(position, hasBackground = true, builder = AssertInlayHint())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.akefirad.groom.spock

import com.akefirad.groom.intellij.PsiElementExtensions.endOffset
import com.akefirad.groom.spock.SpockSpecUtils.isSpeckLabel
import com.intellij.lang.ASTNode
import com.intellij.lang.folding.CustomFoldingBuilder
Expand All @@ -8,7 +9,6 @@ import com.intellij.openapi.editor.Document
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.refactoring.suggested.endOffset
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrLabeledStatement
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.akefirad.groom.spock

import com.akefirad.groom.intellij.PsiElementExtensions.startOffset
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
Expand All @@ -19,7 +20,7 @@ class SpockLabelAnnotator : Annotator {

private fun annotate(e: GrLabeledStatement, h: AnnotationHolder) {
val label = SpecLabelElement.ofLabel(e)
val range = TextRange.from(e.textRange.startOffset, label.name.label.length + 1)
val range = TextRange.from(e.startOffset, label.name.label.length + 1)
.let { if (label.hasTitle) it.union(e.lastChild.textRange) else it }

h.newSilentAnnotation(HighlightSeverity.INFORMATION)
Expand Down
32 changes: 0 additions & 32 deletions src/main/kotlin/com/akefirad/groom/testing/InlayDumpUtil.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.akefirad.groom.spock

import com.akefirad.groom.testing.InlayDumpUtil
import com.intellij.codeInsight.hints.InlayDumpUtil
import com.intellij.codeInsight.hints.declarative.InlayHintsProvider
import com.intellij.codeInsight.hints.declarative.InlayProviderPassInfo
import com.intellij.codeInsight.hints.declarative.impl.DeclarativeInlayHintsPass
Expand Down Expand Up @@ -365,7 +365,6 @@ class AssertInlayHintsProviderTest extends LightPlatformCodeInsightFixture4TestC
doTestProvider("MySpec.groovy", code, new AssertInlayHintsProvider())
}

@SuppressWarnings("UnstableApiUsage")
private void doTestProvider(
String fileName,
String expectedText,
Expand All @@ -376,7 +375,7 @@ class AssertInlayHintsProviderTest extends LightPlatformCodeInsightFixture4TestC
if (verifyHintsPresence) {
InlayHintsProviderTestCase.Companion.verifyHintsPresence(expectedText)
}
def sourceText = InlayDumpUtil.removeHints(expectedText)
def sourceText = InlayDumpUtil.INSTANCE.removeHints(expectedText)
myFixture.configureByText(fileName, sourceText)
def file = myFixture.file
def editor = myFixture.editor
Expand All @@ -385,7 +384,6 @@ class AssertInlayHintsProviderTest extends LightPlatformCodeInsightFixture4TestC
applyPassAndCheckResult(pass, sourceText, expectedText)
}

@SuppressWarnings("UnstableApiUsage")
private void applyPassAndCheckResult(
DeclarativeInlayHintsPass pass,
String previewText,
Expand All @@ -396,13 +394,21 @@ class AssertInlayHintsProviderTest extends LightPlatformCodeInsightFixture4TestC
def file = myFixture.file
def doc = myFixture.getDocument(file)
def editor = myFixture.editor
def dump = InlayDumpUtil.dumpHintsInternal(previewText, file, editor, doc) { r, _ ->
(r as DeclarativeInlayRenderer).presentationList
.entries
.collect { it as TextInlayPresentationEntry }
.collect { it.text }
.join("|")
}
def dump = InlayDumpUtil.INSTANCE.dumpHintsInternal(
previewText,
null,
{ r, _ ->
(r as DeclarativeInlayRenderer).presentationList
.entries
.collect { it as TextInlayPresentationEntry }
.collect { it.text }
.join("|")
},
file,
editor,
doc,
0,
)
assertEquals(expectedText.trim(), dump.trim())
}
}

0 comments on commit aad27e0

Please sign in to comment.