KT-809 Add sure() for call invocation parameters
This commit is contained in:
@@ -208,7 +208,7 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
private static List<String> createConversions(@NotNull PsiCallExpression expression) {
|
||||
List<String> conversions = new LinkedList<String>();
|
||||
PsiExpressionList argumentList = expression.getArgumentList();
|
||||
PsiExpression[] arguments = argumentList != null? argumentList.getExpressions() : new PsiExpression[]{};
|
||||
PsiExpression[] arguments = argumentList != null ? argumentList.getExpressions() : new PsiExpression[]{};
|
||||
//noinspection UnusedDeclaration
|
||||
for (final PsiExpression a : arguments) {
|
||||
conversions.add("");
|
||||
@@ -230,16 +230,25 @@ public class ExpressionVisitor extends StatementVisitor {
|
||||
for (int i = 0; i < actualTypes.size(); i++) {
|
||||
PsiType actual = actualTypes.get(i);
|
||||
PsiType expected = expectedTypes.get(i);
|
||||
PsiExpression argument = arguments[i];
|
||||
|
||||
if (isConversionNeeded(actual, expected)) {
|
||||
conversions.set(i, getPrimitiveTypeConversion(expected.getCanonicalText()));
|
||||
}
|
||||
String conversion = "";
|
||||
if (isConversionNeeded(actual, expected))
|
||||
conversion += getPrimitiveTypeConversion(expected.getCanonicalText());
|
||||
|
||||
PsiType type = argument.getType();
|
||||
if (argument instanceof PsiReferenceExpression &&
|
||||
type != null && Node.PRIMITIVE_TYPES.contains(type.getCanonicalText()) &&
|
||||
((PsiReferenceExpression) argument).isQualified())
|
||||
conversion += ".sure()";
|
||||
|
||||
conversions.set(i, conversion);
|
||||
}
|
||||
}
|
||||
return conversions;
|
||||
}
|
||||
|
||||
static boolean isConversionNeeded(@Nullable final PsiType actual,@Nullable final PsiType expected) {
|
||||
static boolean isConversionNeeded(@Nullable final PsiType actual, @Nullable final PsiType expected) {
|
||||
if (actual == null || expected == null)
|
||||
return false;
|
||||
Map<String, String> typeMap = new HashMap<String, String>();
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package demo;
|
||||
|
||||
class Container {
|
||||
String myString = 1;
|
||||
}
|
||||
|
||||
class One {
|
||||
static Container myContainer = new Container();
|
||||
}
|
||||
|
||||
class StringContainer {
|
||||
StringContainer(String s) {}
|
||||
}
|
||||
|
||||
class Test {
|
||||
void putString(String s) { }
|
||||
void test() {
|
||||
putString(One.myContainer.myString);
|
||||
new StringContainer(One.myContainer.myString);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace demo
|
||||
open class Container() {
|
||||
var myString : String? = 1
|
||||
}
|
||||
open class One() {
|
||||
class object {
|
||||
var myContainer : Container? = Container()
|
||||
}
|
||||
}
|
||||
open class StringContainer(s : String?) {
|
||||
}
|
||||
open class Test() {
|
||||
open fun putString(s : String?) : Unit {
|
||||
}
|
||||
open fun test() : Unit {
|
||||
putString(One.myContainer?.myString)
|
||||
StringContainer(One.myContainer?.myString)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package demo;
|
||||
|
||||
class Container {
|
||||
int myInt = 1;
|
||||
}
|
||||
|
||||
class One {
|
||||
static Container myContainer = new Container();
|
||||
}
|
||||
|
||||
class IntContainer {
|
||||
IntContainer(int i) {}
|
||||
}
|
||||
|
||||
class Test {
|
||||
void putInt(int i) { }
|
||||
void test() {
|
||||
putInt(One.myContainer.myInt);
|
||||
new IntContainer(One.myContainer.myInt);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace demo
|
||||
open class Container() {
|
||||
var myInt : Int = 1
|
||||
}
|
||||
open class One() {
|
||||
class object {
|
||||
var myContainer : Container? = Container()
|
||||
}
|
||||
}
|
||||
open class IntContainer(i : Int) {
|
||||
}
|
||||
open class Test() {
|
||||
open fun putInt(i : Int) : Unit {
|
||||
}
|
||||
open fun test() : Unit {
|
||||
putInt((One.myContainer?.myInt).sure())
|
||||
IntContainer((One.myContainer?.myInt).sure())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user