deprecating types after colon

This commit is contained in:
Dmitry Jemerov
2015-04-21 18:32:31 +02:00
parent b7a4b3c17d
commit f374eec8f1
268 changed files with 1055 additions and 769 deletions
@@ -32,7 +32,6 @@ remove.parts.from.property=Remove {0} from property
remove.parts.from.property.family=Remove Parts from Property
remove.psi.element.family=Remove Element
remove.right.part.of.binary.expression=Remove right part of a binary expression
remove.cast=Remove cast
remove.elvis.operator=Remove elvis operator
remove.redundant.nullable=Remove redundant '?'
remove.supertype=Remove supertype ''{0}''
@@ -54,7 +54,7 @@ public class J2kPostProcessor(private val formatCode: Boolean) : PostProcessor {
override fun fixForProblem(problem: Diagnostic): (() -> Unit)? {
val psiElement = problem.getPsiElement()
return when (problem.getFactory()) {
Errors.USELESS_CAST, Errors.USELESS_CAST_STATIC_ASSERT_IS_FINE -> { ->
Errors.USELESS_CAST -> { ->
val expression = RemoveRightPartOfBinaryExpressionFix(psiElement as JetBinaryExpressionWithTypeRHS, "").invoke()
val variable = expression.getParent() as? JetProperty
@@ -17,11 +17,11 @@
package org.jetbrains.kotlin.idea.quickfix;
import org.jetbrains.kotlin.idea.core.codeInsight.ImplementMethodsHandler;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.*;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.CreateClassFromCallWithConstructorCalleeActionFactory;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.CreateClassFromConstructorCallActionFactory;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.CreateClassFromReferenceExpressionActionFactory;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.CreateClassFromTypeReferenceActionFactory;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable.*;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateLocalVariableActionFactory;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterActionFactory;
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable.CreateParameterByNamedArgumentActionFactory;
@@ -88,9 +88,10 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(NOTHING_TO_OVERRIDE, AddFunctionToSupertypeFix.createFactory());
QuickFixes.factories.put(VIRTUAL_MEMBER_HIDDEN, AddModifierFix.createFactory(OVERRIDE_KEYWORD));
QuickFixes.factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
QuickFixes.factories.put(USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
QuickFixes.factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
QuickFixes.factories.put(USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveTypeFromBinaryExpressionFactory(
"Remove cast"));
QuickFixes.factories.put(DEPRECATED_STATIC_ASSERT, RemoveRightPartOfBinaryExpressionFix.createRemoveTypeFromBinaryExpressionFactory(
"Remove static type assertion"));
JetSingleIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
QuickFixes.factories.put(WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
@@ -69,13 +69,13 @@ public class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> exten
return newExpression;
}
public static JetSingleIntentionActionFactory createRemoveCastFactory() {
public static JetSingleIntentionActionFactory createRemoveTypeFromBinaryExpressionFactory(final String message) {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
if (expression == null) return null;
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>(expression, JetBundle.message("remove.cast"));
return new RemoveRightPartOfBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>(expression, message);
}
};
}
@@ -20,9 +20,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.idea.JetBundle;
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
import org.jetbrains.kotlin.psi.JetBinaryExpressionWithTypeRHS;
import org.jetbrains.kotlin.psi.JetExpression;
import org.jetbrains.kotlin.psi.JetFile;
@@ -55,22 +53,4 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
}
}
}
public static JetSingleIntentionActionFactory createChangeCastToStaticAssertFactory() {
return new JetSingleIntentionActionFactory() {
@Override
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil
.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
if (expression == null) return null;
return new ReplaceOperationInBinaryExpressionFix<JetBinaryExpressionWithTypeRHS>(expression, " : ") {
@NotNull
@Override
public String getText() {
return JetBundle.message("replace.cast.with.static.assert");
}
};
}
};
}
}
+12 -10
View File
@@ -1,16 +1,18 @@
fun <T> checkSubtype(t: T) = t
fun test() : Unit {
var x : Int? = 0
var y : Int = 0
x : Int?
y : Int
x as Int : Int
y <warning>as Int</warning> : Int
x <warning>as Int?</warning> : Int?
y <warning>as Int?</warning> : Int?
x <warning>as Int?</warning> : Int?
y <warning>as? Int</warning> : Int?
x <warning>as? Int?</warning> : Int?
y <warning>as? Int?</warning> : Int?
checkSubtype<Int?>(x)
checkSubtype<Int>(y)
checkSubtype<Int>(x as Int)
checkSubtype<Int>(y <warning>as Int</warning>)
checkSubtype<Int?>(x <warning>as Int?</warning>)
checkSubtype<Int?>(y <warning>as Int?</warning>)
checkSubtype<Int?>(x <warning>as Int?</warning>)
checkSubtype<Int?>(y <warning>as? Int</warning>)
checkSubtype<Int?>(x <warning>as? Int?</warning>)
checkSubtype<Int?>(y <warning>as? Int?</warning>)
Unit
}
+5 -3
View File
@@ -1,7 +1,9 @@
fun <T> checkSubtype(t: T) = t
fun test() {
1 : Byte
1 : Int
<error>1</error> : Double
checkSubtype<Byte>(1)
checkSubtype<Int>(1)
checkSubtype<Double>(<error>1</error>)
1 <warning>as</warning> Byte
1 <warning>as Int</warning>
1 <warning>as</warning> Double
+3 -1
View File
@@ -1,5 +1,7 @@
import java.util.*;
fun <T> checkSubtype(t: T) = t
class NotRange1() {
}
@@ -76,6 +78,6 @@ fun test(notRange1: NotRange1, notRange2: NotRange2, notRange3: NotRange3, notRa
for (i in range0);
for (i in range1);
for (i in (ArrayList<Int>() : List<Int>));
for (i in (checkSubtype<List<Int>>(ArrayList<Int>())));
}
@@ -1,16 +1,18 @@
class A(val a:Int) {
fun <T> checkSubtype(t: T) = t
class A(val a:Int) {
inner class B() {
val x = this@B : B
val y = this@A : A
val z = this : B
val Int.xx : Int get() = this : Int
val x = checkSubtype<B>(this@B)
val y = checkSubtype<A>(this@A)
val z = checkSubtype<B>(this)
val Int.xx : Int get() = checkSubtype<Int>(this)
fun Char.xx() : Double.() -> Unit {
this : Char
val <warning>a</warning>: Double.() -> Unit = { this : Double + this@xx : Char}
val <warning>b</warning>: Double.() -> Unit = a@{this@a : Double + this@xx : Char}
val <warning>c</warning> = a@{<error>this@a</error> <error>+</error> this@xx : Char}
return (a@{this@a : Double + this@xx : Char})
checkSubtype<Char>(this)
val <warning>a</warning>: Double.() -> Unit = { checkSubtype<Double>(this) + checkSubtype<Char>(this@xx) }
val <warning>b</warning>: Double.() -> Unit = a@{checkSubtype<Double>(this@a) + checkSubtype<Char>(this@xx) }
val <warning>c</warning> = a@{<error>this@a</error> <error>+</error> checkSubtype<Char>(this@xx) }
return (a@{checkSubtype<Double>(this@a) + checkSubtype<Char>(this@xx) })
}
}
}
+4 -2
View File
@@ -6,6 +6,8 @@ import <error>utils</error>.*
import java.io.PrintStream
import <warning>java.lang.Comparable</warning> as Com
fun <T> checkSubtype(t: T) = t
val l : MutableList<in Int> = ArrayList<Int>()
fun test(<warning>l</warning> : List<Int>) {
@@ -22,7 +24,7 @@ fun test(<warning>l</warning> : List<Int>) {
Collections.emptyList<Int>()
Collections.<error>emptyList</error>()
Collections.singleton<Int>(1) : Set<Int>?
checkSubtype<Set<Int>?>(Collections.singleton<Int>(1))
Collections.singleton<Int>(<error>1.0</error>)
<error>List</error><Int>
@@ -41,7 +43,7 @@ fun test(<warning>l</warning> : List<Int>) {
val c : <warning>Com<Int></warning>? = null
c : <warning>java.lang.Comparable<Int></warning>?
checkSubtype<<warning>java.lang.Comparable<Int></warning>?>(c)
// Collections.sort<Integer>(ArrayList<Integer>())
}
-1
View File
@@ -1,7 +1,6 @@
fun test(<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">unusedParam</warning>: Int) { // UNUSED_PARAMETER
val str = ":)"
str <warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">as String</warning> // USELESS_CAST
str <warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">as Any</warning> // USELESS_CAST_STATIC_ASSERT_IS_FINE
// UNUSED_FUNCTION_LITERAL
<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">{
+3 -1
View File
@@ -1,3 +1,5 @@
import java.util.Collections
val ab = Collections.emptyList<Int>() : List<Int>?
fun <T> checkSubtype(t: T) = t
val ab = checkSubtype<List<Int>?>(Collections.emptyList<Int>())
@@ -1,18 +1,20 @@
class Foo(var bar : Int, var barr : Int, var barrr : Int) {
init {
bar = 1
barr = 1
barrr = 1
1 : Int
this : Foo
}
fun <T> checkSubtype(t: T) = t
init {
bar = 1
this.bar
1 : Int
val <warning>a</warning> : Int =1
this : Foo
}
class Foo(var bar : Int, var barr : Int, var barrr : Int) {
init {
bar = 1
barr = 1
barrr = 1
checkSubtype<Int>(1)
checkSubtype<Foo>(this)
}
init {
bar = 1
this.bar
checkSubtype<Int>(1)
val <warning>a</warning> : Int =1
checkSubtype<Foo>(this)
}
}
@@ -0,0 +1,4 @@
// "Remove static type assertion" "true"
fun foo(a: String) {
val b = a
}
@@ -1,4 +0,0 @@
// "Replace a cast with a static assert" "true"
fun foo(a: String) {
val b = a : Any
}
@@ -0,0 +1,4 @@
// "Remove static type assertion" "true"
fun foo(a: String) {
val b = a <caret>: Any
}
@@ -1,4 +0,0 @@
// "Replace a cast with a static assert" "true"
fun foo(a: String) {
val b = a <caret>as Any
}
@@ -1,5 +0,0 @@
// "Cast expression 'x' to 'String'" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.String</td></tr><tr><td>Found:</td><td>kotlin.Int</td></tr></table></html>
fun foo(x: Int) {
x<caret>: String
}
@@ -1,5 +1,4 @@
// "Change parameter 'z' type of function 'foo' to '(Int) -> String'" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
// ACTION: Disable 'Move Lambda Function Into Parentheses'
// ACTION: Edit intention settings
@@ -7,7 +6,7 @@
fun foo(y: Int = 0, z: (Int) -> String = {""}) {
foo {
""<caret>: Int
""<caret> as Int
""
}
}
@@ -2866,6 +2866,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/expressions"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeRemoveStaticTypeAssertion.kt")
public void testRemoveStaticTypeAssertion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeRemoveStaticTypeAssertion.kt");
doTest(fileName);
}
@TestMetadata("beforeRemoveUselessCast.kt")
public void testRemoveUselessCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeRemoveUselessCast.kt");
@@ -2884,12 +2890,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("beforeReplaceUselessCastWithStaticAssert.kt")
public void testReplaceUselessCastWithStaticAssert() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeReplaceUselessCastWithStaticAssert.kt");
doTest(fileName);
}
@TestMetadata("beforeUnnecessaryNonNullAssertion1.kt")
public void testUnnecessaryNonNullAssertion1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/expressions/beforeUnnecessaryNonNullAssertion1.kt");
@@ -4916,12 +4916,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("beforeTypeMismatch5.kt")
public void testTypeMismatch5() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeTypeMismatch5.kt");
doTest(fileName);
}
@TestMetadata("beforeTypeMismatchLongNameRuntime.kt")
public void testTypeMismatchLongNameRuntime() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeTypeMismatchLongNameRuntime.kt");