Fix warnings in rt modules

1. Generify everywhere
2. @Override
3. Redundant throws removed
4. Enhanced for
5. String concatenation to StringBuilder
6. Misc

GitOrigin-RevId: 1e4c9dd7a44360b187d23370586c81a78047cdaf
This commit is contained in:
Tagir Valeev
2020-06-03 11:17:36 +07:00
committed by intellij-monorepo-bot
parent 0968a5611f
commit d2ef69f336
40 changed files with 289 additions and 183 deletions

View File

@@ -26,20 +26,20 @@ public class AbstractExpectedPatterns {
private static final Pattern ASSERT_EQUALS_PATTERN = Pattern.compile("expected:<(.*)> but was:<(.*)>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
private static final Pattern ASSERT_EQUALS_CHAINED_PATTERN = Pattern.compile("but was:<(.*)>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
protected static void registerPatterns(String[] patternStrings, List patterns) {
for (int i = 0; i < patternStrings.length; i++) {
patterns.add(Pattern.compile(patternStrings[i], Pattern.DOTALL | Pattern.CASE_INSENSITIVE));
protected static void registerPatterns(String[] patternStrings, List<Pattern> patterns) {
for (String string : patternStrings) {
patterns.add(Pattern.compile(string, Pattern.DOTALL | Pattern.CASE_INSENSITIVE));
}
}
protected static ComparisonFailureData createExceptionNotification(String message, List patterns) {
protected static ComparisonFailureData createExceptionNotification(String message, List<Pattern> patterns) {
ComparisonFailureData assertEqualsNotification = createExceptionNotification(message, ASSERT_EQUALS_PATTERN);
if (assertEqualsNotification != null) {
return ASSERT_EQUALS_CHAINED_PATTERN.matcher(assertEqualsNotification.getExpected()).find() ? null : assertEqualsNotification;
}
for (int i = 0; i < patterns.size(); i++) {
ComparisonFailureData notification = createExceptionNotification(message, (Pattern)patterns.get(i));
for (Pattern pattern : patterns) {
ComparisonFailureData notification = createExceptionNotification(message, pattern);
if (notification != null) {
return notification;
}

View File

@@ -28,11 +28,11 @@ public abstract class ForkedByModuleSplitter {
protected final ForkedDebuggerHelper myForkedDebuggerHelper = new ForkedDebuggerHelper();
protected final String myWorkingDirsPath;
protected final String myForkMode;
protected final List myNewArgs;
protected final List<String> myNewArgs;
protected String myDynamicClasspath;
protected List myVMParameters;
protected List<String> myVMParameters;
public ForkedByModuleSplitter(String workingDirsPath, String forkMode, List newArgs) {
public ForkedByModuleSplitter(String workingDirsPath, String forkMode, List<String> newArgs) {
myWorkingDirsPath = workingDirsPath;
myForkMode = forkMode;
myNewArgs = newArgs;
@@ -44,7 +44,7 @@ public abstract class ForkedByModuleSplitter {
String repeatCount) throws Exception {
args = myForkedDebuggerHelper.excludeDebugPortFromArgs(args);
myVMParameters = new ArrayList();
myVMParameters = new ArrayList<String>();
final BufferedReader bufferedReader = new BufferedReader(new FileReader(commandLinePath));
myDynamicClasspath = bufferedReader.readLine();
try {
@@ -63,8 +63,12 @@ public abstract class ForkedByModuleSplitter {
}
//read output from wrappers
protected int startChildFork(final List args, File workingDir, String classpath, List moduleOptions, String repeatCount) throws IOException, InterruptedException {
List vmParameters = new ArrayList(myVMParameters);
protected int startChildFork(final List<String> args,
File workingDir,
String classpath,
List<String> moduleOptions,
String repeatCount) throws IOException, InterruptedException {
List<String> vmParameters = new ArrayList<String>(myVMParameters);
myForkedDebuggerHelper.setupDebugger(vmParameters);
final ProcessBuilder builder = new ProcessBuilder();
@@ -108,6 +112,7 @@ public abstract class ForkedByModuleSplitter {
private static Runnable createInputReader(final InputStream inputStream, final PrintStream outputStream) {
return new Runnable() {
@Override
public void run() {
try {
final BufferedReader inputReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
@@ -140,7 +145,7 @@ public abstract class ForkedByModuleSplitter {
while ((workingDir = perDirReader.readLine()) != null) {
final String moduleName = perDirReader.readLine();
final String classpath = perDirReader.readLine();
List moduleOptions = new ArrayList();
List<String> moduleOptions = new ArrayList<String>();
String modulePath = perDirReader.readLine();
if (modulePath != null && modulePath.length() > 0) {
moduleOptions.add("-p");
@@ -152,7 +157,7 @@ public abstract class ForkedByModuleSplitter {
}
try {
List classNames = new ArrayList();
List<String> classNames = new ArrayList<String>();
final int classNamesSize = Integer.parseInt(perDirReader.readLine());
for (int i = 0; i < classNamesSize; i++) {
String className = perDirReader.readLine();
@@ -182,11 +187,11 @@ public abstract class ForkedByModuleSplitter {
protected abstract int startSplitting(String[] args, String configName, String repeatCount) throws Exception;
protected abstract int startPerModuleFork(String moduleName,
List classNames,
List<String> classNames,
String packageName,
String workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount,
int result,
String filters) throws Exception;
@@ -197,25 +202,24 @@ public abstract class ForkedByModuleSplitter {
final Attributes attributes = manifest.getMainAttributes();
attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
String classpathForManifest = "";
StringBuilder classpathForManifest = new StringBuilder();
int idx = 0;
int endIdx = 0;
while (endIdx >= 0) {
endIdx = classpath.indexOf(File.pathSeparator, idx);
String path = endIdx < 0 ? classpath.substring(idx) : classpath.substring(idx, endIdx);
if (classpathForManifest.length() > 0) {
classpathForManifest += " ";
classpathForManifest.append(" ");
}
try {
//noinspection Since15
classpathForManifest += new File(path).toURI().toURL().toString();
classpathForManifest.append(new File(path).toURI().toURL().toString());
}
catch (NoSuchMethodError e) {
classpathForManifest += new File(path).toURL().toString();
classpathForManifest.append(new File(path).toURL().toString());
}
idx = endIdx + File.pathSeparator.length();
}
attributes.put(Attributes.Name.CLASS_PATH, classpathForManifest);
attributes.put(Attributes.Name.CLASS_PATH, classpathForManifest.toString());
File jarFile = File.createTempFile("classpath", ".jar");
ZipOutputStream jarPlugin = null;

View File

@@ -38,12 +38,12 @@ public class ForkedDebuggerHelper {
}
}
public void setupDebugger(List parameters) throws IOException {
public void setupDebugger(List<String> parameters) throws IOException {
if (myDebugPort > -1) {
int debugAddress = findAvailableSocketPort();
boolean found = false;
for (int i = 0; i < parameters.size(); i++) {
String parameter = (String)parameters.get(i);
String parameter = parameters.get(i);
final int indexOf = Math.max(parameter.indexOf("transport=dt_socket"), parameter.indexOf("transport=dt_shmem"));
if (indexOf >= 0) {
if (debugAddress > -1) {
@@ -80,9 +80,9 @@ public class ForkedDebuggerHelper {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.startsWith(DEBUG_SOCKET)) {
final List list = new ArrayList(Arrays.asList(args));
final List<String> list = new ArrayList<String>(Arrays.asList(args));
list.remove(arg);
args = (String[])list.toArray(new String[0]);
args = list.toArray(new String[0]);
myDebugPort = Integer.parseInt(arg.substring(DEBUG_SOCKET.length()));
break;
}

View File

@@ -31,6 +31,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
super(workingDirsPath, forkMode, newArgs);
}
@Override
protected int startSplitting(String[] args,
String configName,
String repeatCount) throws Exception {
@@ -41,7 +42,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
if (myWorkingDirsPath == null || new File(myWorkingDirsPath).length() == 0) {
final String classpath = System.getProperty("java.class.path");
final String modulePath = System.getProperty("jdk.module.path");
final List moduleOptions = new ArrayList();
final List<String> moduleOptions = new ArrayList<String>();
if (modulePath != null && modulePath.length() > 0) {
moduleOptions.add("-p");
moduleOptions.add(modulePath);
@@ -49,7 +50,7 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
if (repeatCount != null && RepeatCount.getCount(repeatCount) != 0 && myForkMode.equals("repeat")) {
return startChildFork(createChildArgs(myRootDescription), null, classpath, moduleOptions, repeatCount);
}
final List children = getChildren(myRootDescription);
final List<?> children = getChildren(myRootDescription);
final boolean forkTillMethod = myForkMode.equalsIgnoreCase("method");
return splitChildren(children, 0, forkTillMethod, null, classpath, moduleOptions, repeatCount);
}
@@ -58,22 +59,23 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
}
}
@Override
protected int startPerModuleFork(String moduleName,
List classNames,
List<String> classNames,
String packageName,
String workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount,
int result,
String filters) throws Exception {
if (myForkMode.equals("none")) {
final List childArgs = createPerModuleArgs(packageName, workingDir, classNames, myRootDescription, filters);
final List<String> childArgs = createPerModuleArgs(packageName, workingDir, classNames, myRootDescription, filters);
return startChildFork(childArgs, new File(workingDir), classpath, moduleOptions, repeatCount);
}
else {
final List children = new ArrayList(getChildren(myRootDescription));
for (Iterator iterator = children.iterator(); iterator.hasNext(); ) {
final List<?> children = new ArrayList<Object>(getChildren(myRootDescription));
for (Iterator<?> iterator = children.iterator(); iterator.hasNext(); ) {
if (!classNames.contains(getTestClassName(iterator.next()))) {
iterator.remove();
}
@@ -83,16 +85,15 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
}
}
protected int splitChildren(List children,
protected int splitChildren(List<?> children,
int result,
boolean forkTillMethod,
File workingDir,
String classpath,
List moduleOptions,
List<String> moduleOptions,
String repeatCount) throws IOException, InterruptedException {
for (int i = 0, argsLength = children.size(); i < argsLength; i++) {
final Object child = children.get(i);
final List childTests = getChildren(child);
for (final Object child : children) {
final List<?> childTests = getChildren(child);
final int childResult;
if (childTests.isEmpty() || !forkTillMethod) {
childResult = startChildFork(createChildArgs(child), workingDir, classpath, moduleOptions, repeatCount);
@@ -105,17 +106,17 @@ public abstract class ForkedSplitter extends ForkedByModuleSplitter {
return result;
}
protected abstract List createPerModuleArgs(String packageName,
String workingDir,
List classNames,
Object rootDescriptor,
String filters) throws IOException;
protected abstract List<String> createPerModuleArgs(String packageName,
String workingDir,
List<String> classNames,
Object rootDescriptor,
String filters) throws IOException;
protected abstract Object createRootDescription(String[] args, String configName) throws Exception;
protected abstract String getTestClassName(Object child);
protected abstract List createChildArgs(Object child);
protected abstract List<String> createChildArgs(Object child);
protected abstract List getChildren(Object child);
protected abstract List<?> getChildren(Object child);
}