mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
surround with try/catch: replace var with explicit type (IDEA-191069)
when declaration has to be split
This commit is contained in:
+6
@@ -78,6 +78,12 @@ public class SurroundWithUtil {
|
||||
PsiVariable var = (PsiVariable)element1;
|
||||
PsiExpression initializer = var.getInitializer();
|
||||
if (initializer != null) {
|
||||
PsiTypeElement typeElement = var.getTypeElement();
|
||||
if (typeElement != null &&
|
||||
typeElement.isInferredType() &&
|
||||
PsiTypesUtil.replaceWithExplicitType(typeElement) == null) {
|
||||
continue;
|
||||
}
|
||||
if (!generateInitializers || var.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
initializer.delete();
|
||||
}
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Surround with try/catch" "true"
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
Object foo = null;
|
||||
try {
|
||||
foo = bar();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
foo.toString();
|
||||
}
|
||||
|
||||
private static Object bar() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Surround with try/catch" "true"
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
var foo = b<caret>ar();
|
||||
foo.toString();
|
||||
}
|
||||
|
||||
private static Object bar() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user