Resource Bundles: Inspections on invalid property key/resource bundle references

#KT-6946 In Progress
This commit is contained in:
Alexey Sedunov
2015-09-17 20:11:02 +03:00
parent 44fd9d17ed
commit 594e4e5c31
14 changed files with 244 additions and 0 deletions
@@ -0,0 +1,5 @@
package org.jetbrains.annotations
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FIELD)
public annotation class PropertyKey(public val resourceBundle: String)
@@ -0,0 +1,2 @@
foo.bar = test: {0}
foo.bar2 = test: {0}, {1}
@@ -0,0 +1,7 @@
import org.jetbrains.annotations.PropertyKey;
class J {
static String message(@PropertyKey(resourceBundle = "TestBundle") String key, Object... args) {
return key;
}
}
@@ -0,0 +1,6 @@
import org.jetbrains.annotations.PropertyKey
object K {
fun message(@PropertyKey(resourceBundle = "TestBundle") key: String, vararg args: Any) = key
fun message2(@PropertyKey(resourceBundle = "TestBundle") key: String, n: Int, vararg args: Any) = key
}
@@ -0,0 +1,7 @@
fun test() {
K.message("foo.bar")
J.message("foo.bar")
K.message(key = "foo.bar", args = 1)
K.message("foo.bar2", *arrayOf(1, 2))
K.message2("foo.bar", 1)
}
@@ -0,0 +1,6 @@
import org.jetbrains.annotations.PropertyKey
private val TEST_BUNDLE2 = "TestBundle2"
fun message(@PropertyKey(resourceBundle = "TestBundle2") key: String, vararg args: Any) = key
fun message2(@PropertyKey(resourceBundle = TEST_BUNDLE2) key: String, vararg args: Any) = key
@@ -0,0 +1,6 @@
fun test() {
K.message("foo.baz", "arg")
K.message("foo.baz")
J.message("foo.baz", "arg")
J.message("foo.baz")
}
@@ -0,0 +1,6 @@
fun test() {
K.message("foo.bar", "arg")
K.message("foo.bar", "arg1", "arg2")
J.message("foo.bar", "arg")
J.message("foo.bar", "arg1", "arg2")
}
@@ -0,0 +1,73 @@
<problems>
<problem>
<file>unresolvedPropertyReference.kt</file>
<line>2</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="unresolvedPropertyReference.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>String literal 'foo.baz' doesn't appear to be valid property key</description>
</problem>
<problem>
<file>unresolvedPropertyReference.kt</file>
<line>3</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="unresolvedPropertyReference.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>String literal 'foo.baz' doesn't appear to be valid property key</description>
</problem>
<problem>
<file>unresolvedPropertyReference.kt</file>
<line>4</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="unresolvedPropertyReference.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>String literal 'foo.baz' doesn't appear to be valid property key</description>
</problem>
<problem>
<file>unresolvedPropertyReference.kt</file>
<line>5</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="unresolvedPropertyReference.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>String literal 'foo.baz' doesn't appear to be valid property key</description>
</problem>
<problem>
<file>tooFewArguments.kt</file>
<line>2</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="tooFewArguments.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>Property 'foo.bar' expected 1 parameter, passed 0</description>
</problem>
<problem>
<file>tooFewArguments.kt</file>
<line>3</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="tooFewArguments.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>Property 'foo.bar' expected 1 parameter, passed 0</description>
</problem>
<problem>
<file>unresolvedBundleReference.kt</file>
<line>3</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="unresolvedBundleReference.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>Invalid resource bundle reference 'TestBundle2'</description>
</problem>
<problem>
<file>unresolvedBundleReference.kt</file>
<line>5</line>
<module>testInvalidBundleOrProperty_InvalidBundleOrProperty_0</module>
<entry_point TYPE="file" FQNAME="unresolvedBundleReference.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Invalid property key</problem_class>
<description>Invalid resource bundle reference 'TestBundle2'</description>
</problem>
</problems>
@@ -0,0 +1,4 @@
{
"inspectionClass": "org.jetbrains.kotlin.idea.inspections.KotlinInvalidBundleOrPropertyInspection",
"withRuntime": "true"
}