Reinforce vars and function typing, fix some build warnings

GitOrigin-RevId: abd96e0f684034b37b320a925e9fb1433afc712e
This commit is contained in:
Thomas ROTSAERT
2021-11-01 15:24:18 +00:00
committed by intellij-monorepo-bot
parent e276c64cec
commit 2e24c0d14b
9 changed files with 37 additions and 27 deletions
@@ -27,7 +27,7 @@ public final class AntMain2 {
// as we build classpath ourselves, and ensure all libraries are added to classpath,
// preferred way for us to run ant will be using the traditional ant entry point, via the "Main" class
try {
final Class antMain = Class.forName("org.apache.tools.ant.Main");
final Class<?> antMain = Class.forName("org.apache.tools.ant.Main");
antMain.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
return;
}
@@ -38,7 +38,7 @@ public final class AntMain2 {
// fallback: try the newer approach, launcher
// This approach is less preferred in our case, but still...
// From the ant documentation: "You should start the launcher with the most minimal classpath possible, generally just the ant-launcher.jar."
final Class antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher");
final Class<?> antLauncher = Class.forName("org.apache.tools.ant.launch.Launcher");
antLauncher.getMethod("main", new Class[]{args.getClass()}).invoke(null, new Object[]{args});
}
catch (UnsupportedClassVersionError ucv) {
@@ -48,6 +48,7 @@ public final class AntMain2 {
"unpack it and specify the path to it on the 'Execution' tab in the 'Build File Properties' dialog " +
"(accessible via the 'Ant Build' tool window -> Properties button).";
throw new IllegalStateException(message) {
@Override
public synchronized Throwable fillInStackTrace() {
return this;
}
@@ -21,25 +21,30 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
/**
* @noinspection HardCodedStringLiteral
*/
public class ComparisonDetailsExtractor {
private static final Map EXPECTED = new HashMap();
private static final Map ACTUAL = new HashMap();
protected String myActual = "";
protected String myExpected = "";
private static final Map<Class<?>, Field> EXPECTED = new HashMap<Class<?>, Field>();
private static final Map<Class<?>, Field> ACTUAL = new HashMap<Class<?>, Field>();
protected final String myActual;
protected final String myExpected;
private final Throwable myAssertion;
public ComparisonDetailsExtractor(Throwable assertion, String expected, String actual) {
myAssertion = assertion;
myActual = actual;
myExpected = expected;
}
static {
try {
init(ComparisonFailure.class);
init(org.junit.ComparisonFailure.class);
}
catch (Throwable e) {
System.err.println(e.getMessage());
}
}
private static void init(Class exceptionClass) throws NoSuchFieldException {
private static void init(Class<?> exceptionClass) throws NoSuchFieldException {
final Field expectedField = exceptionClass.getDeclaredField("fExpected");
expectedField.setAccessible(true);
EXPECTED.put(exceptionClass, expectedField);
@@ -49,12 +54,6 @@ public class ComparisonDetailsExtractor {
ACTUAL.put(exceptionClass, actualField);
}
public ComparisonDetailsExtractor(Throwable assertion, String expected, String actual) {
myAssertion = assertion;
myActual = actual;
myExpected = expected;
}
public static String getActual(Throwable assertion) throws IllegalAccessException, NoSuchFieldException {
return get(assertion, ACTUAL, "fActual");
}
@@ -63,14 +62,14 @@ public class ComparisonDetailsExtractor {
return get(assertion, EXPECTED, "fExpected");
}
private static String get(final Throwable assertion, final Map staticMap, final String fieldName)
private static String get(final Throwable assertion, final Map<Class<?>, Field> staticMap, final String fieldName)
throws IllegalAccessException, NoSuchFieldException {
String actual;
if (assertion instanceof ComparisonFailure) {
actual = (String)((Field)staticMap.get(ComparisonFailure.class)).get(assertion);
actual = (String)staticMap.get(ComparisonFailure.class).get(assertion);
}
else if (assertion instanceof org.junit.ComparisonFailure) {
actual = (String)((Field)staticMap.get(org.junit.ComparisonFailure.class)).get(assertion);
actual = (String)staticMap.get(org.junit.ComparisonFailure.class).get(assertion);
}
else {
Field field = assertion.getClass().getDeclaredField(fieldName);