Use multi-catch when possible

This commit is contained in:
Alexander Udalov
2017-04-01 00:33:19 +03:00
parent 34f0576135
commit 6aa0f7bb65
14 changed files with 16 additions and 68 deletions
@@ -111,10 +111,7 @@ public class RunUtils {
}
close(handler.getProcessInput());
}
catch (ExecutionException e) {
return new RunResult(false, getStackTrace(e));
}
catch (IOException e) {
catch (ExecutionException | IOException e) {
return new RunResult(false, getStackTrace(e));
}
@@ -313,10 +313,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return genNotNullAssertions(state, stackValue, runtimeAssertionInfo);
}
catch (ProcessCanceledException e) {
throw e;
}
catch (CompilationException e) {
catch (ProcessCanceledException | CompilationException e) {
throw e;
}
catch (Throwable error) {
@@ -381,10 +381,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
generateSecondaryConstructor(secondaryConstructor);
}
}
catch (CompilationException e) {
throw e;
}
catch (ProcessCanceledException e) {
catch (CompilationException | ProcessCanceledException e) {
throw e;
}
catch (RuntimeException e) {
@@ -193,10 +193,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
try {
functionCodegen.gen((KtNamedFunction) declaration);
}
catch (ProcessCanceledException e) {
throw e;
}
catch (CompilationException e) {
catch (ProcessCanceledException | CompilationException e) {
throw e;
}
catch (Exception e) {
@@ -207,10 +204,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
try {
propertyCodegen.gen((KtProperty) declaration);
}
catch (ProcessCanceledException e) {
throw e;
}
catch (CompilationException e) {
catch (ProcessCanceledException | CompilationException e) {
throw e;
}
catch (Exception e) {
@@ -99,15 +99,12 @@ public class ModuleXmlParser {
});
return new ModuleScriptData(modules);
}
catch (ParserConfigurationException e) {
catch (ParserConfigurationException | IOException e) {
MessageCollectorUtil.reportException(messageCollector, e);
}
catch (SAXException e) {
messageCollector.report(ERROR, OutputMessageUtil.renderException(e), NO_LOCATION);
}
catch (IOException e) {
MessageCollectorUtil.reportException(messageCollector, e);
}
return ModuleScriptData.EMPTY;
}
@@ -145,10 +145,7 @@ public class ConstraintsUtil {
sb.append("\n");
}
}
catch (IllegalAccessException e) {
sb.append(e.getMessage());
}
catch (InvocationTargetException e) {
catch (IllegalAccessException | InvocationTargetException e) {
sb.append(e.getMessage());
}
}
@@ -216,10 +216,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends KtVisitor<Kotlin
}
return result;
}
catch (ProcessCanceledException e) {
throw e;
}
catch (KotlinFrontEndException e) {
catch (ProcessCanceledException | KotlinFrontEndException e) {
throw e;
}
catch (Throwable e) {
@@ -227,10 +227,7 @@ public class InterceptionInstrumenter {
method.invoke(interceptor, out);
}
}
catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
catch (InvocationTargetException e) {
catch (IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
out.println(">>>");
@@ -184,10 +184,7 @@ public abstract class AbstractWriteFlagsTest extends CodegenTestCase {
Field field = klass.getDeclaredField(flag);
expectedAccess |= field.getInt(klass);
}
catch (NoSuchFieldException e) {
throw new IllegalArgumentException("Cannot find " + flag + " field in Opcodes class", e);
}
catch (IllegalAccessException e) {
catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalArgumentException("Cannot find " + flag + " field in Opcodes class", e);
}
}
@@ -87,20 +87,13 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
}
public void assertPropertyCoherent(KtLightClass lightClass, String methodName) {
Class<?> reflect = PsiClass.class;
try {
Method method = reflect.getMethod(methodName);
Method method = PsiClass.class.getMethod(methodName);
Object lightResult = method.invoke(lightClass);
Object delegateResult = method.invoke(lightClass.getClsDelegate());
assertEquals("Result of method " + methodName + "() differs in light class and its delegate", delegateResult, lightResult);
}
catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
catch (InvocationTargetException e) {
throw new AssertionError(e);
}
catch (IllegalAccessException e) {
catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
}
}
@@ -142,12 +142,9 @@ public class StdlibTest extends KotlinTestWithEnvironment {
return TestCase.class.isAssignableFrom(aClass) ? new TestSuite(aClass) :
TestRunnerUtil.isJUnit4TestClass(aClass) ? new JUnit4TestAdapter(aClass) : null;
}
catch (NoSuchMethodException e) {
catch (NoSuchMethodException | ClassNotFoundException e) {
// Ignore test classes we can't instantiate
return null;
}
catch (ClassNotFoundException e) {
return null;
}
}
}
@@ -165,13 +165,7 @@ public abstract class KotlinDebuggerTestCase extends DescriptorTestCase {
ourOutputRootField.set(null, LOCAL_CACHE_APP_DIR);
}
catch (NoSuchFieldException e) {
throw ExceptionUtilsKt.rethrow(e);
}
catch (IllegalAccessException e) {
throw ExceptionUtilsKt.rethrow(e);
}
catch (IOException e) {
catch (NoSuchFieldException | IOException | IllegalAccessException e) {
throw ExceptionUtilsKt.rethrow(e);
}
}
@@ -54,10 +54,7 @@ public final class PackageDeclarationTranslator extends AbstractTranslator {
catch (TranslationRuntimeException e) {
throw e;
}
catch (RuntimeException e) {
throw new TranslationRuntimeException(file, e);
}
catch (AssertionError e) {
catch (RuntimeException | AssertionError e) {
throw new TranslationRuntimeException(file, e);
}
}
@@ -168,10 +168,7 @@ public final class Translation {
catch (TranslationRuntimeException e) {
throw e;
}
catch (RuntimeException e) {
throw new TranslationRuntimeException(expression, e);
}
catch (AssertionError e) {
catch (RuntimeException | AssertionError e) {
throw new TranslationRuntimeException(expression, e);
}
}