Skip to content

Commit

Permalink
SplitString: Support split strings within inspections & method target…
Browse files Browse the repository at this point in the history
… references
  • Loading branch information
FxMorin committed Aug 14, 2024
1 parent 5273bb3 commit 8b41280
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiAnnotationMemberValue
import com.intellij.psi.PsiArrayInitializerMemberValue
import com.intellij.psi.PsiBinaryExpression
import com.intellij.psi.PsiLiteral

class AmbiguousReferenceInspection : MixinAnnotationAttributeInspection("method") {

Expand All @@ -53,8 +52,8 @@ class AmbiguousReferenceInspection : MixinAnnotationAttributeInspection("method"
}

when (value) {
is PsiLiteral -> checkMember(value, holder)
is PsiArrayInitializerMemberValue -> value.initializers.forEach { checkMember(it, holder) }
else -> checkMember(value, holder)
}
}

Expand All @@ -80,7 +79,7 @@ class AmbiguousReferenceInspection : MixinAnnotationAttributeInspection("method"

val elementFactory = JavaPsiFacade.getElementFactory(project)

if (constantValue != null && element is PsiLiteral) {
if (constantValue != null) {
val newLiteral = "\"${StringUtil.escapeStringCharacters("$constantValue*")}\""
element.replace(elementFactory.createExpressionFromText(newLiteral, null))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.PsiArrayInitializerMemberValue
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiLiteral
import com.intellij.psi.PsiNameValuePair

class InvalidMemberReferenceInspection : MixinInspection() {
Expand Down Expand Up @@ -68,10 +67,10 @@ class InvalidMemberReferenceInspection : MixinInspection() {

// Attempt to parse the reference
when (value) {
is PsiLiteral -> checkMemberReference(value, value.constantStringValue)
is PsiArrayInitializerMemberValue -> value.initializers.forEach {
checkMemberReference(it, it.constantStringValue)
}
else -> checkMemberReference(value, value.constantStringValue)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiAnnotationMemberValue
import com.intellij.psi.PsiArrayInitializerMemberValue
import com.intellij.psi.PsiLiteral

class UnnecessaryQualifiedMemberReferenceInspection : MixinAnnotationAttributeInspection("method") {

Expand All @@ -51,8 +50,8 @@ class UnnecessaryQualifiedMemberReferenceInspection : MixinAnnotationAttributeIn
}

when (value) {
is PsiLiteral -> checkMemberReference(value, holder)
is PsiArrayInitializerMemberValue -> value.initializers.forEach { checkMemberReference(it, holder) }
else -> checkMemberReference(value, holder)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiArrayInitializerMemberValue
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiLiteral
import com.intellij.psi.PsiSubstitutor
import com.intellij.psi.ResolveResult
import com.intellij.psi.util.parentOfType
Expand Down Expand Up @@ -111,9 +110,8 @@ abstract class AbstractMethodReference : PolyReferenceResolver(), MixinReference
private fun resolve(context: PsiElement): Sequence<ClassAndMethodNode>? {
val targets = getTargets(context) ?: return null
val targetedMethods = when (context) {
is PsiLiteral -> context.constantStringValue?.let { listOf(it) } ?: emptyList()
is PsiArrayInitializerMemberValue -> context.initializers.mapNotNull { it.constantStringValue }
else -> emptyList()
else -> context.constantStringValue?.let { listOf(it) } ?: emptyList()
}

return targetedMethods.asSequence().flatMap { method ->
Expand Down Expand Up @@ -141,9 +139,8 @@ abstract class AbstractMethodReference : PolyReferenceResolver(), MixinReference
val targets = getTargets(context) ?: return null

val targetedMethods = when (context) {
is PsiLiteral -> context.constantStringValue?.let { listOf(it) } ?: emptyList()
is PsiArrayInitializerMemberValue -> context.initializers.mapNotNull { it.constantStringValue }
else -> emptyList()
else -> context.constantStringValue?.let { listOf(it) } ?: emptyList()
}

return targetedMethods.asSequence().flatMap { method ->
Expand Down

0 comments on commit 8b41280

Please sign in to comment.