Java to Kotlin converter: supported try-with-resource construct, fixed anonymous class generation + fixed a bug with method return type
#KT-4488 Fixed
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() throws IOException {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
// reading something
|
||||
int c = stream.read();
|
||||
System.out.println(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
FileInputStream("foo").use { stream ->
|
||||
// reading something
|
||||
val c = stream.read()
|
||||
System.out.println(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() throws IOException {
|
||||
try(InputStream input = new FileInputStream("foo");
|
||||
OutputStream output = new FileOutputStream("bar")) {
|
||||
output.write(input.read());
|
||||
output.write(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
FileInputStream("foo").use { input ->
|
||||
FileOutputStream("bar").use { output ->
|
||||
output.write(input.read())
|
||||
output.write(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() throws IOException {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
System.out.println(stream.read());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
FileInputStream("foo").use { stream -> System.out.println(stream.read()) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
// reading something
|
||||
int c = stream.read();
|
||||
System.out.println(c);
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
try {
|
||||
FileInputStream("foo").use { stream ->
|
||||
// reading something
|
||||
val c = stream.read()
|
||||
System.out.println(c)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
System.out.println(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
// reading something
|
||||
int c = stream.read();
|
||||
System.out.println(c);
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
finally {
|
||||
System.out.println("Finally!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
try {
|
||||
FileInputStream("foo").use { stream ->
|
||||
// reading something
|
||||
val c = stream.read()
|
||||
System.out.println(c)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
System.out.println(e)
|
||||
} finally {
|
||||
System.out.println("Finally!")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
// reading something
|
||||
int c = stream.read();
|
||||
System.out.println(c);
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
try {
|
||||
FileInputStream("foo").use { stream ->
|
||||
// reading something
|
||||
val c = stream.read()
|
||||
System.out.println(c)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
System.out.println(e)
|
||||
} catch (e: Exception) {
|
||||
System.err.println(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
void foo() throws IOException {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
// reading something
|
||||
int c = stream.read();
|
||||
System.out.println(c);
|
||||
}
|
||||
finally {
|
||||
// dispose something else
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
try {
|
||||
FileInputStream("foo").use { stream ->
|
||||
// reading something
|
||||
val c = stream.read()
|
||||
System.out.println(c)
|
||||
}
|
||||
} finally {
|
||||
// dispose something else
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
int foo() {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
while(true) {
|
||||
int c = stream.read();
|
||||
if (c < 0 || c > 127) return c;
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
public class C {
|
||||
int foo() {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
// reading something
|
||||
int c = stream.read();
|
||||
return c;
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println(e);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.io.*
|
||||
|
||||
public class C() {
|
||||
fun foo(): Int {
|
||||
try {
|
||||
return FileInputStream("foo").use { stream ->
|
||||
// reading something
|
||||
val c = stream.read()
|
||||
c
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
System.out.println(e)
|
||||
return -1
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
interface I {
|
||||
int doIt(InputStream stream) throws IOException;
|
||||
}
|
||||
|
||||
public class C {
|
||||
void foo() throws IOException {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
bar(new I() {
|
||||
@Override
|
||||
public int doIt(InputStream stream) throws IOException {
|
||||
return stream.available();
|
||||
}
|
||||
}, stream);
|
||||
}
|
||||
}
|
||||
|
||||
int bar(I i, InputStream stream) throws IOException {
|
||||
return i.doIt(stream);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.io.*
|
||||
|
||||
trait I {
|
||||
public fun doIt(stream: InputStream): Int
|
||||
}
|
||||
|
||||
public class C() {
|
||||
fun foo() {
|
||||
FileInputStream("foo").use { stream ->
|
||||
bar(object : I {
|
||||
override fun doIt(stream: InputStream): Int {
|
||||
return stream.available()
|
||||
}
|
||||
}, stream)
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(i: I, stream: InputStream): Int {
|
||||
return i.doIt(stream)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
interface I {
|
||||
int doIt(InputStream stream) throws IOException;
|
||||
}
|
||||
|
||||
public class C {
|
||||
int foo() throws IOException {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
return bar(new I() {
|
||||
@Override
|
||||
public int doIt(InputStream stream) throws IOException {
|
||||
return stream.available();
|
||||
}
|
||||
}, stream);
|
||||
}
|
||||
}
|
||||
|
||||
int bar(I i, InputStream stream) throws IOException {
|
||||
return i.doIt(stream);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.io.*
|
||||
|
||||
trait I {
|
||||
public fun doIt(stream: InputStream): Int
|
||||
}
|
||||
|
||||
public class C() {
|
||||
fun foo(): Int {
|
||||
return FileInputStream("foo").use { stream ->
|
||||
bar(object : I {
|
||||
override fun doIt(stream: InputStream): Int {
|
||||
return stream.available()
|
||||
}
|
||||
}, stream)
|
||||
}
|
||||
}
|
||||
|
||||
fun bar(i: I, stream: InputStream): Int {
|
||||
return i.doIt(stream)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//file
|
||||
import java.io.*;
|
||||
|
||||
interface I {
|
||||
int doIt(InputStream stream) throws IOException;
|
||||
}
|
||||
|
||||
public class C {
|
||||
int foo() throws IOException {
|
||||
try(InputStream stream = new FileInputStream("foo")) {
|
||||
if (stream.read() >= 0) {
|
||||
return bar(new I() {
|
||||
@Override
|
||||
public int doIt(InputStream stream) throws IOException {
|
||||
return stream.available();
|
||||
}
|
||||
}, stream);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bar(I i, InputStream stream) throws IOException {
|
||||
return i.doIt(stream);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user