Warn about bad options in usage parsers in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// PSI_ELEMENT: com.intellij.psi.PsiField
|
||||
// OPTIONS: readAccess
|
||||
// OPTIONS: skipWrite
|
||||
public class A {
|
||||
public String <caret>foo = "foo";
|
||||
}
|
||||
@@ -42,7 +42,7 @@ internal enum class OptionsParser {
|
||||
"functionUsages" -> isMethodsUsages = true
|
||||
"propertyUsages" -> isFieldsUsages = true
|
||||
"expected" -> searchExpected = true
|
||||
else -> throw IllegalStateException("Invalid option: " + s)
|
||||
else -> throw IllegalStateException("Invalid option: $s")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ internal enum class OptionsParser {
|
||||
searchExpected = true
|
||||
isUsages = true
|
||||
}
|
||||
else -> throw IllegalStateException("Invalid option: " + s)
|
||||
else -> throw IllegalStateException("Invalid option: $s")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ internal enum class OptionsParser {
|
||||
"skipRead" -> isReadAccess = false
|
||||
"skipWrite" -> isWriteAccess = false
|
||||
"expected" -> searchExpected = true
|
||||
else -> throw IllegalStateException("Invalid option: " + s)
|
||||
else -> throw IllegalStateException("Invalid option: $s")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ internal enum class OptionsParser {
|
||||
"implementingClasses" -> isImplementingClasses = true
|
||||
"methodUsages" -> isMethodsUsages = true
|
||||
"fieldUsages" -> isFieldsUsages = true
|
||||
else -> throw IllegalStateException("Invalid option: " + s)
|
||||
else -> throw IllegalStateException("Invalid option: $s")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ internal enum class OptionsParser {
|
||||
isOverridingMethods = true
|
||||
isImplementingMethods = true
|
||||
}
|
||||
else -> throw IllegalStateException("Invalid option: " + s)
|
||||
else -> throw IllegalStateException("Invalid option: $s")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,17 +132,39 @@ internal enum class OptionsParser {
|
||||
},
|
||||
JAVA_FIELD {
|
||||
override fun parse(text: String, project: Project): FindUsagesOptions {
|
||||
return JavaVariableFindUsagesOptions(project)
|
||||
return JavaVariableFindUsagesOptions(project).apply {
|
||||
for (s in InTextDirectivesUtils.findListWithPrefixes(text, "// OPTIONS: ")) {
|
||||
if (parseCommonOptions(this, s)) continue
|
||||
|
||||
when (s) {
|
||||
"skipRead" -> isReadAccess = false
|
||||
"skipWrite" -> isWriteAccess = false
|
||||
else -> throw IllegalStateException("Invalid option: `$s`")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
JAVA_PACKAGE {
|
||||
override fun parse(text: String, project: Project): FindUsagesOptions {
|
||||
return JavaPackageFindUsagesOptions(project)
|
||||
return JavaPackageFindUsagesOptions(project).apply {
|
||||
for (s in InTextDirectivesUtils.findListWithPrefixes(text, "// OPTIONS: ")) {
|
||||
if (parseCommonOptions(this, s)) continue
|
||||
|
||||
throw IllegalStateException("Invalid option: `$s`")
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
DEFAULT {
|
||||
override fun parse(text: String, project: Project): FindUsagesOptions {
|
||||
return FindUsagesOptions(project)
|
||||
return FindUsagesOptions(project).apply {
|
||||
for (s in InTextDirectivesUtils.findListWithPrefixes(text, "// OPTIONS: ")) {
|
||||
if (parseCommonOptions(this, s)) continue
|
||||
|
||||
throw IllegalStateException("Invalid option: `$s`")
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,22 +172,32 @@ internal enum class OptionsParser {
|
||||
|
||||
companion object {
|
||||
protected fun parseCommonOptions(options: JavaFindUsagesOptions, s: String): Boolean {
|
||||
when (s) {
|
||||
"usages" -> {
|
||||
options.isUsages = true
|
||||
return true
|
||||
}
|
||||
if (parseCommonOptions(options as FindUsagesOptions, s)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return when (s) {
|
||||
"skipImports" -> {
|
||||
options.isSkipImportStatements = true
|
||||
return true
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected fun parseCommonOptions(options: FindUsagesOptions, s: String): Boolean {
|
||||
return when (s) {
|
||||
"usages" -> {
|
||||
options.isUsages = true
|
||||
true
|
||||
}
|
||||
"textOccurrences" -> {
|
||||
options.isSearchForTextOccurrences = true
|
||||
return true
|
||||
true
|
||||
}
|
||||
else -> return false
|
||||
else -> false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun getParserByPsiElementClass(klass: Class<out PsiElement>): OptionsParser? {
|
||||
|
||||
Reference in New Issue
Block a user