J2K: fixed conversion of Throwable.getMessage(), Throwable.getCause(), Map.Entry.getKey() and Map.Entry.getValue()

This commit is contained in:
Valentin Kipyatkov
2015-10-20 13:59:17 +03:00
parent 8dde7497e0
commit 36ea9cfbfc
4 changed files with 50 additions and 7 deletions
@@ -109,6 +109,26 @@ enum class SpecialMethod(val qualifiedClassName: String?, val methodName: String
= convertWithChangedName("removeAt", qualifier, arguments, typeArgumentsConverted, codeConverter)
},
THROWABLE_GET_MESSAGE(Throwable::class.java.name, "getMessage", 0) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= convertMethodCallToPropertyUse(codeConverter, qualifier, "message")
},
THROWABLE_GET_CAUSE(Throwable::class.java.name, "getCause", 0) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= convertMethodCallToPropertyUse(codeConverter, qualifier, "cause")
},
MAP_ENTRY_GET_KEY(Map::class.java.name + ".Entry", "getKey", 0) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= convertMethodCallToPropertyUse(codeConverter, qualifier, "key")
},
MAP_ENTRY_GET_VALUE(Map::class.java.name + ".Entry", "getValue", 0) {
override fun convertCall(qualifier: PsiExpression?, arguments: Array<PsiExpression>, typeArgumentsConverted: List<Type>, codeConverter: CodeConverter)
= convertMethodCallToPropertyUse(codeConverter, qualifier, "value")
},
OBJECT_EQUALS(null, "equals", 1) {
override fun matches(method: PsiMethod, superMethodsSearcher: SuperMethodsSearcher): Boolean
= super.matches(method, superMethodsSearcher) && method.getParameterList().getParameters().single().getType().getCanonicalText() == JAVA_LANG_OBJECT
+1 -1
View File
@@ -16,7 +16,7 @@ internal object FileRead {
}
`in`.close()
} catch (e: Exception) {
System.err.println("Error: " + e.getMessage())
System.err.println("Error: " + e.message)
}
}
@@ -16,7 +16,7 @@ class A {
int h = map.entrySet().size();
}
void bar(List<String> list) {
void bar(List<String> list, HashMap<String, Integer> map) {
char c = "a".charAt(0);
byte b = new Integer(10).byteValue();
int i = new Double(10.1).intValue();
@@ -24,7 +24,19 @@ class A {
long l = new Double(10.1).longValue();
short s = new Double(10.1).shortValue();
String removed = list.remove(10);
Boolean isRemoved = list.remove("a");
try {
String removed = list.remove(10);
Boolean isRemoved = list.remove("a");
}
catch(Exception e) {
System.err.println(e.getMessage());
throw new RuntimeException(e.getCause());
}
for (Map.Entry<String, Integer> entry : map.entrySet()) {
String key = entry.getKey();
Integer value = entry.getValue();
entry.setValue(value + 1);
}
}
}
@@ -16,7 +16,7 @@ internal class A {
val h = map.entries.size
}
fun bar(list: MutableList<String>) {
fun bar(list: MutableList<String>, map: HashMap<String, Int>) {
val c = "a"[0]
val b = 10.toByte()
val i = 10.1.toInt()
@@ -24,7 +24,18 @@ internal class A {
val l = 10.1.toLong()
val s = 10.1.toShort()
val removed = list.removeAt(10)
val isRemoved = list.remove("a")
try {
val removed = list.removeAt(10)
val isRemoved = list.remove("a")
} catch (e: Exception) {
System.err.println(e.message)
throw RuntimeException(e.cause)
}
for (entry in map.entries) {
val key = entry.key
val value = entry.value
entry.setValue(value + 1)
}
}
}