Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support split strings within inspections & method target references #2358

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading