KT-675 Translate accessible parameters as a var parameters
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package org.jetbrains.jet.j2k;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
@@ -439,10 +441,20 @@ public class Converter {
|
||||
public static Parameter parameterToParameter(@NotNull PsiParameter parameter) {
|
||||
return new Parameter(
|
||||
new IdentifierImpl(parameter.getName()), // TODO: remove
|
||||
typeToType(parameter.getType())
|
||||
typeToType(parameter.getType()),
|
||||
isReadOnly(parameter)
|
||||
);
|
||||
}
|
||||
|
||||
private static boolean isReadOnly(PsiParameter parameter) {
|
||||
for (PsiReference r : (ReferencesSearch.search(parameter))) {
|
||||
if (r instanceof PsiExpression && PsiUtil.isAccessedForWriting((PsiExpression) r)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Identifier identifierToIdentifier(@Nullable PsiIdentifier identifier) {
|
||||
if (identifier == null) return Identifier.EMPTY_IDENTIFIER;
|
||||
|
||||
@@ -8,16 +8,24 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class Parameter extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
private final Type myType;
|
||||
private boolean myReadOnly;
|
||||
|
||||
public Parameter(Identifier identifier, Type type) {
|
||||
myIdentifier = identifier;
|
||||
myType = type;
|
||||
myReadOnly = true;
|
||||
}
|
||||
|
||||
public Parameter(IdentifierImpl identifier, Type type, boolean readOnly) {
|
||||
this(identifier, type);
|
||||
myReadOnly = readOnly;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
String vararg = myType.getKind() == Kind.VARARG ? "vararg" + SPACE : EMPTY;
|
||||
return vararg + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
String var = myReadOnly ? EMPTY : "var" + SPACE;
|
||||
return vararg + var + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package demo;
|
||||
|
||||
class Test {
|
||||
void test(Object ... args) {
|
||||
args = new Integer[] {1, 2, 3};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace demo
|
||||
open class Test() {
|
||||
open fun test(vararg var args : Any?) : Unit {
|
||||
args = array(1, 2, 3)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package demo;
|
||||
|
||||
class Test {
|
||||
int test(int i) {
|
||||
i = 10;
|
||||
return i + 20;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace demo
|
||||
open class Test() {
|
||||
open fun test(var i : Int) : Int {
|
||||
i = 10
|
||||
return (i + 20)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user