Get rid of FIELD_IDENTIFIER at syntax level, two errors dropped, a set of tests fixed / deleted #KT-9539 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-10-20 13:55:37 +03:00
parent 8ea0501a30
commit d6988ad69e
97 changed files with 177 additions and 792 deletions
@@ -52,9 +52,6 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
}
highlightProperty(expression, (PropertyDescriptor) target, false);
if (expression.getReferencedNameElementType() == KtTokens.FIELD_IDENTIFIER) {
NameHighlighter.highlightName(holder, expression, JetHighlightingColors.BACKING_FIELD_ACCESS);
}
}
@Override
@@ -84,16 +84,10 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere
}
val psiFactory = KtPsiFactory(expression)
val element = when (expression.getReferencedNameElementType()) {
KtTokens.FIELD_IDENTIFIER -> psiFactory.createFieldIdentifier(newElementName)
else -> {
Extensions.getArea(expression.getProject()).getExtensionPoint(SimpleNameReferenceExtension.EP_NAME).getExtensions()
val element = Extensions.getArea(expression.getProject()).getExtensionPoint(SimpleNameReferenceExtension.EP_NAME).extensions
.asSequence()
.map { it.handleElementRename(this, psiFactory, newElementName) }
.firstOrNull { it != null } ?: psiFactory.createNameIdentifier(newElementName)
}
}
val nameElement = expression.getReferencedNameElement()
@@ -37,7 +37,7 @@ val KOTLIN_NAMED_ARGUMENT_SEARCH_CONTEXT: Short = 0x20
class KotlinFilterLexer(private val occurrenceConsumer: OccurrenceConsumer): BaseFilterLexer(KotlinLexer(), occurrenceConsumer) {
private val codeTokens = TokenSet.orSet(
TokenSet.create(*ALL_SEARCHABLE_OPERATIONS.toTypedArray()),
TokenSet.create(KtTokens.IDENTIFIER, KtTokens.FIELD_IDENTIFIER)
TokenSet.create(KtTokens.IDENTIFIER)
)
private val commentTokens = TokenSet.orSet(KtTokens.COMMENTS, TokenSet.create(KDocTokens.KDOC))
@@ -1,9 +1,9 @@
val a: Int = 1
get() {
return $a
return field
}
set(v) {
$a = <caret>
field = <caret>
}
@@ -90,7 +90,6 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
ErrorsJvm.POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION,
Errors.DEPRECATION,
Errors.NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION,
Errors.BACKING_FIELD_OLD_SYNTAX,
Errors.OPERATOR_MODIFIER_REQUIRED,
Errors.DEPRECATED_UNARY_PLUS_MINUS,
Errors.DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION,
@@ -82,8 +82,6 @@ class IntroduceBackingPropertyIntention(): JetSelfTargetingIntention<KtProperty>
}
property.setInitializer(null)
replaceBackingFieldReferences(property)
}
private fun createGetter(element: KtProperty) {
@@ -136,17 +134,6 @@ class IntroduceBackingPropertyIntention(): JetSelfTargetingIntention<KtProperty>
}
})
}
// TODO: drop this when we get rid of backing field syntax
private fun replaceBackingFieldReferences(prop: KtProperty) {
val containingClass = prop.getStrictParentOfType<KtClassOrObject>()!!
ReferencesSearch.search(prop, LocalSearchScope(containingClass)).forEach {
val element = it.element as? KtNameReferenceExpression
if (element != null && element.getReferencedNameElementType() == KtTokens.FIELD_IDENTIFIER) {
element.replace(KtPsiFactory(element).createSimpleName("_${prop.name}"))
}
}
}
}
}
@@ -331,10 +331,6 @@ public class QuickFixRegistrar : QuickFixContributor {
NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION.registerFactory(ConstFixFactory)
BACKING_FIELD_OLD_SYNTAX.registerFactory(MigrateBackingFieldSyntaxFix)
BACKING_FIELD_USAGE_FORBIDDEN.registerFactory(MigrateBackingFieldUsageFix)
BACKING_FIELD_USAGE_FORBIDDEN.registerFactory(IntroduceBackingPropertyFix)
OPERATOR_MODIFIER_REQUIRED.registerFactory(AddModifierFixFactory(KtTokens.OPERATOR_KEYWORD))
INFIX_MODIFIER_REQUIRED.registerFactory(AddModifierFixFactory(KtTokens.INFIX_KEYWORD))
+1 -4
View File
@@ -11,10 +11,8 @@ interface NoC {
}
class WithC() {
val x : Int
val x : Int = 42
init {
<error>$x</error> = 1
<error>$y</error> = 2
val <warning>b</warning> = x
}
@@ -24,7 +22,6 @@ class WithC() {
init {
val <warning>z</warning> = <error>b</error>
val <warning>zz</warning> = x
val <warning>zzz</warning> = <error>$a</error>
}
}
-1
View File
@@ -28,7 +28,6 @@ class WithCPI_Dup(<warning>x</warning> : Int) {
class WithCPI(x : Int) {
val a = 1
val b : Int = <error>$a</error>
val xy : Int = x
}
-6
View File
@@ -1,6 +0,0 @@
// JET-17 Do not infer property types by the initializer before the containing scope is ready
class WithC() {
val a = 1
val b = <error>$a</error> // error here, but must not be
}
-6
View File
@@ -39,12 +39,6 @@ annotation class Fancy(val param: Int)
@Fancy(<caret>i) class D
class Foo {
var x: Int = 0
get = $x
set(value) { $x = value }
}
class CustomDelegate {
operator fun get(thisRef: Any?, prop: PropertyMetadata): String = ""
operator fun set(thisRef: Any?, prop: PropertyMetadata, value: String) {}
-6
View File
@@ -39,12 +39,6 @@ annotation class Fancy(val param: Int)
@Fancy(i) class D
class Foo {
var x: Int = 0
get = field
set(value) { field = value }
}
class CustomDelegate {
operator fun getValue(thisRef: Any?, prop: KProperty<*>): String = ""
operator fun setValue(thisRef: Any?, prop: KProperty<*>, value: String) {}
@@ -1,5 +1,5 @@
// "Remove getter and initializer from property" "true"
abstract class B {
abstract val i = <caret>0
get() = $i
get() = field
}
@@ -1,7 +0,0 @@
// "Migrate backing field syntax" "true"
class Foo {
var a: Int = 0
get() = 0
set(v) { $<caret>a = v }
}
@@ -1,7 +0,0 @@
// "Migrate backing field syntax" "true"
class Foo {
var a: Int = 0
get() = 0
set(v) { field = v }
}
@@ -1,11 +0,0 @@
// "Introduce backing property" "true"
class Foo {
var x = ""
get() = $x + "!"
set(value) { $x = value + "!" }
fun foo(): String {
return $<caret>x
}
}
@@ -1,12 +0,0 @@
// "Introduce backing property" "true"
class Foo {
private var _x = ""
var x: String
get() = _x + "!"
set(value) { _x = value + "!" }
fun foo(): String {
return _x
}
}
@@ -1,7 +0,0 @@
// "Replace with property access" "true"
class A {
var foo: Int = 0
fun bar() = $f<caret>oo
}
@@ -1,7 +0,0 @@
// "Replace with property access" "true"
class A {
var foo: Int = 0
fun bar() = foo
}
@@ -1,5 +0,0 @@
// "Change '$foo' to 'foo'" "true"
abstract class Foo {
abstract var foo : String
fun bar() = <caret>$foo + "bar"
}
@@ -1,5 +0,0 @@
// "Change '$foo' to 'foo'" "true"
abstract class Foo {
abstract var foo : String
fun bar() = <caret>foo + "bar"
}
@@ -1,5 +0,0 @@
// "Change '$bar' to 'bar'" "true"
abstract class Bar {
abstract var bar : String
fun foo() = "foo" + this.<caret>$bar
}
@@ -1,5 +0,0 @@
// "Change '$bar' to 'bar'" "true"
abstract class Bar {
abstract var bar : String
fun foo() = "foo" + this.<caret>bar
}
@@ -1,7 +0,0 @@
// "Change '$foo' to 'foo'" "true"
class A {
val foo : Int
get() = 5
val bar : Int
get() = $<caret>foo
}
@@ -1,7 +0,0 @@
// "Change '$foo' to 'foo'" "true"
class A {
val foo : Int
get() = 5
val bar : Int
get() = <caret>foo
}
@@ -1,5 +0,0 @@
// "Change '$a' to 'a'" "true"
val a = 5
class A {
val b = <caret>$a
}
@@ -1,5 +0,0 @@
// "Change '$a' to 'a'" "true"
val a = 5
class A {
val b = <caret>a
}
@@ -1,6 +0,0 @@
// "Change '$a' to 'a'" "true"
package foo
val a = 5
class A {
val b = foo.<caret>$a
}
@@ -1,6 +0,0 @@
// "Change '$a' to 'a'" "true"
package foo
val a = 5
class A {
val b = foo.<caret>a
}
@@ -1,6 +1,6 @@
class aClass(){
var myF<caret>ield: Int = 0;
set(value){
$myField=value
field=value
}
}
@@ -1,6 +1,6 @@
class aClass(){
var renamed: Int = 0;
set(value){
$renamed =value
field=value
}
}
@@ -1,6 +1,6 @@
class aClass(){
var myField: Int = 0;
set(value){
$myFi<caret>eld=value
fi<caret>eld=value
}
}
@@ -1,6 +1,6 @@
class aClass(){
var anotherRenamed: Int = 0;
set(value){
$anotherRenamed =value
field=value
}
}
@@ -442,12 +442,6 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
doTest(fileName);
}
@TestMetadata("Jet17.kt")
public void testJet17() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/regression/Jet17.kt");
doTest(fileName);
}
@TestMetadata("Jet183.kt")
public void testJet183() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/regression/Jet183.kt");
@@ -4250,33 +4250,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/migration/backingFieldSyntax")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class BackingFieldSyntax extends AbstractQuickFixTest {
@TestMetadata("accessor.kt")
public void testAccessor() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/backingFieldSyntax/accessor.kt");
doTest(fileName);
}
public void testAllFilesPresentInBackingFieldSyntax() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/backingFieldSyntax"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("introduceBackingField.kt")
public void testIntroduceBackingField() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/backingFieldSyntax/introduceBackingField.kt");
doTest(fileName);
}
@TestMetadata("usage.kt")
public void testUsage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/backingFieldSyntax/usage.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/quickfix/migration/conflictingExtension")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -6792,45 +6765,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
}
}
@TestMetadata("idea/testData/quickfix/variables/changeToPropertyName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ChangeToPropertyName extends AbstractQuickFixTest {
@TestMetadata("abstractProperty.kt")
public void testAbstractProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyName/abstractProperty.kt");
doTest(fileName);
}
@TestMetadata("abstractPropertyThis.kt")
public void testAbstractPropertyThis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyName/abstractPropertyThis.kt");
doTest(fileName);
}
public void testAllFilesPresentInChangeToPropertyName() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/variables/changeToPropertyName"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}
@TestMetadata("customAccessors.kt")
public void testCustomAccessors() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyName/customAccessors.kt");
doTest(fileName);
}
@TestMetadata("inaccessibleBackingField.kt")
public void testInaccessibleBackingField() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyName/inaccessibleBackingField.kt");
doTest(fileName);
}
@TestMetadata("inaccessibleBackingFieldQualified.kt")
public void testInaccessibleBackingFieldQualified() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyName/inaccessibleBackingFieldQualified.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/quickfix/variables/removeValVarFromParameter")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)