KT-595 Don't create open functions in open classes
This commit is contained in:
@@ -274,6 +274,11 @@ public class Converter {
|
||||
modifiers.add(Modifier.OVERRIDE);
|
||||
if (method.getParent() instanceof PsiClass && ((PsiClass) method.getParent()).isInterface())
|
||||
modifiers.remove(Modifier.ABSTRACT);
|
||||
if (method.getParent() instanceof PsiClass) {
|
||||
final PsiModifierList parentModifierList = ((PsiClass) method.getParent()).getModifierList();
|
||||
if (parentModifierList != null && parentModifierList.hasExplicitModifier(Modifier.FINAL))
|
||||
modifiers.add(Modifier.NOT_OPEN);
|
||||
}
|
||||
|
||||
if (method.isConstructor()) { // TODO: simplify
|
||||
boolean isPrimary = isConstructorPrimary(method);
|
||||
|
||||
@@ -78,6 +78,9 @@ public class Function extends Member {
|
||||
if (!myModifiers.contains(Modifier.OVERRIDE) && !myModifiers.contains(Modifier.FINAL))
|
||||
modifierList.add(Modifier.OPEN);
|
||||
|
||||
if (myModifiers.contains(Modifier.NOT_OPEN))
|
||||
modifierList.remove(Modifier.OPEN);
|
||||
|
||||
modifierList.add(accessModifier());
|
||||
|
||||
if (modifierList.size() > 0)
|
||||
|
||||
@@ -12,5 +12,6 @@ public abstract class Modifier {
|
||||
public static final String ABSTRACT = "abstract";
|
||||
public static final String FINAL = "final";
|
||||
public static final String OPEN = "open";
|
||||
public static final String NOT_OPEN = "not open";
|
||||
public static final String OVERRIDE = "override";
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class JavaToKotlinConverterTest extends LightDaemonAnalyzerTestCase {
|
||||
static String statementToKotlin(String text) throws Exception {
|
||||
String result = methodToKotlin("void main() {" + text + "}");
|
||||
int pos = result.lastIndexOf("}");
|
||||
result = result.substring(0, pos).replaceFirst("open fun main\\(\\) : Unit \\{", "");
|
||||
result = result.substring(0, pos).replaceFirst("fun main\\(\\) : Unit \\{", "");
|
||||
return prettify(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun fromArrayToCollection(a : Array<Foo?>?) : Unit {
|
||||
fun fromArrayToCollection(a : Array<Foo?>?) : Unit {
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
class T() {
|
||||
open fun main() : Unit {
|
||||
fun main() : Unit {
|
||||
}
|
||||
open fun i() : Int {
|
||||
fun i() : Int {
|
||||
}
|
||||
open fun s() : String? {
|
||||
fun s() : String? {
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
class S() {
|
||||
open fun sB() : Boolean {
|
||||
fun sB() : Boolean {
|
||||
return true
|
||||
}
|
||||
class object {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class S() {
|
||||
class object {
|
||||
open fun staticF() : Boolean {
|
||||
fun staticF() : Boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class S() {
|
||||
open fun sB() : Boolean {
|
||||
fun sB() : Boolean {
|
||||
return true
|
||||
}
|
||||
class object {
|
||||
open fun sI() : Int {
|
||||
fun sI() : Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
class S() {
|
||||
class object {
|
||||
open fun sB() : Boolean {
|
||||
fun sB() : Boolean {
|
||||
return true
|
||||
}
|
||||
open fun sI() : Int {
|
||||
fun sI() : Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package demo;
|
||||
|
||||
final class Final {
|
||||
void test() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace demo
|
||||
class Final() {
|
||||
fun test() : Unit {
|
||||
}
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
abstract open fun getNoofGears() : Int
|
||||
abstract fun getNoofGears() : Int
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun getT() : T? {
|
||||
fun getT() : T? {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun main() : Unit {
|
||||
fun main() : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun test() : Unit {
|
||||
fun test() : Unit {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
class object {
|
||||
open public fun main(args : Array<String?>?) : Unit {
|
||||
public fun main(args : Array<String?>?) : Unit {
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun main() : String? {
|
||||
fun main() : String? {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun main() : Int {
|
||||
fun main() : Int {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun main() : Boolean {
|
||||
fun main() : Boolean {
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
open fun isTrue() : Boolean {
|
||||
fun isTrue() : Boolean {
|
||||
return true
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
open fun getString() : String? {
|
||||
fun getString() : String? {
|
||||
return ""
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun putU<U>(u : U?) : Unit {
|
||||
fun putU<U>(u : U?) : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun putUVW<U, V, W>(u : U?, v : V?, w : W?) : Unit {
|
||||
fun putUVW<U, V, W>(u : U?, v : V?, w : W?) : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open private fun test() : Unit {
|
||||
private fun test() : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open protected fun test() : Unit {
|
||||
protected fun test() : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open public fun test() : Unit {
|
||||
public fun test() : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun popAll(dst : Collection<in E?>?) : Unit {
|
||||
fun popAll(dst : Collection<in E?>?) : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun pushAll(src : Collection<out E?>?) : Unit {
|
||||
fun pushAll(src : Collection<out E?>?) : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun wtf(w : Collection<*>?) : Unit {
|
||||
fun wtf(w : Collection<*>?) : Unit {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun max<T : Any?, K : Node?>(coll : Collection<out T?>?) : T? where T : Comparable<in T?>?, K : Collection<in K?>? {
|
||||
fun max<T : Any?, K : Node?>(coll : Collection<out T?>?) : T? where T : Comparable<in T?>?, K : Collection<in K?>? {
|
||||
}
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun max<T : Any?>(coll : Collection<out T?>?) : T? where T : Comparable<in T?>? {
|
||||
fun max<T : Any?>(coll : Collection<out T?>?) : T? where T : Comparable<in T?>? {
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
open fun format(pattern : String?, vararg arguments : Any?) : String?
|
||||
fun format(pattern : String?, vararg arguments : Any?) : String?
|
||||
@@ -1,2 +1,2 @@
|
||||
open fun pushAll(vararg objs : Any?) : Unit {
|
||||
fun pushAll(vararg objs : Any?) : Unit {
|
||||
}
|
||||
Reference in New Issue
Block a user