Warn about bad options in usage parsers in tests
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// PSI_ELEMENT: com.intellij.psi.PsiField
|
// PSI_ELEMENT: com.intellij.psi.PsiField
|
||||||
// OPTIONS: readAccess
|
// OPTIONS: skipWrite
|
||||||
public class A {
|
public class A {
|
||||||
public String <caret>foo = "foo";
|
public String <caret>foo = "foo";
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ internal enum class OptionsParser {
|
|||||||
"functionUsages" -> isMethodsUsages = true
|
"functionUsages" -> isMethodsUsages = true
|
||||||
"propertyUsages" -> isFieldsUsages = true
|
"propertyUsages" -> isFieldsUsages = true
|
||||||
"expected" -> searchExpected = 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
|
searchExpected = true
|
||||||
isUsages = 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
|
"skipRead" -> isReadAccess = false
|
||||||
"skipWrite" -> isWriteAccess = false
|
"skipWrite" -> isWriteAccess = false
|
||||||
"expected" -> searchExpected = true
|
"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
|
"implementingClasses" -> isImplementingClasses = true
|
||||||
"methodUsages" -> isMethodsUsages = true
|
"methodUsages" -> isMethodsUsages = true
|
||||||
"fieldUsages" -> isFieldsUsages = 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
|
isOverridingMethods = true
|
||||||
isImplementingMethods = 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 {
|
JAVA_FIELD {
|
||||||
override fun parse(text: String, project: Project): FindUsagesOptions {
|
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 {
|
JAVA_PACKAGE {
|
||||||
override fun parse(text: String, project: Project): FindUsagesOptions {
|
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 {
|
DEFAULT {
|
||||||
override fun parse(text: String, project: Project): FindUsagesOptions {
|
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 {
|
companion object {
|
||||||
protected fun parseCommonOptions(options: JavaFindUsagesOptions, s: String): Boolean {
|
protected fun parseCommonOptions(options: JavaFindUsagesOptions, s: String): Boolean {
|
||||||
when (s) {
|
if (parseCommonOptions(options as FindUsagesOptions, s)) {
|
||||||
"usages" -> {
|
return true
|
||||||
options.isUsages = true
|
}
|
||||||
return true
|
|
||||||
}
|
return when (s) {
|
||||||
"skipImports" -> {
|
"skipImports" -> {
|
||||||
options.isSkipImportStatements = true
|
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" -> {
|
"textOccurrences" -> {
|
||||||
options.isSearchForTextOccurrences = true
|
options.isSearchForTextOccurrences = true
|
||||||
return true
|
true
|
||||||
}
|
}
|
||||||
else -> return false
|
else -> false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getParserByPsiElementClass(klass: Class<out PsiElement>): OptionsParser? {
|
fun getParserByPsiElementClass(klass: Class<out PsiElement>): OptionsParser? {
|
||||||
|
|||||||
Reference in New Issue
Block a user