diff options
author | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:11:12 +0200 |
---|---|---|
committer | Lars Grefer <eclipse@larsgrefer.de> | 2020-08-08 03:11:12 +0200 |
commit | c1c373f4278426308689db61f7758185e8f0401b (patch) | |
tree | 9e03af2feb69782c50464fc1e1e2ce0d6b6bb8c5 /util/src | |
parent | a508fd5315c6330f2057c219aebc35b15d0ea497 (diff) | |
download | aspectj-c1c373f4278426308689db61f7758185e8f0401b.tar.gz aspectj-c1c373f4278426308689db61f7758185e8f0401b.zip |
'String.indexOf()' expression is replaceable with 'contains()'
Reports any String.indexOf() expressions which can be replaced with a call to the String.contains() method available in Java 5 and newer.
Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
Diffstat (limited to 'util/src')
5 files changed, 8 insertions, 8 deletions
diff --git a/util/src/main/java/org/aspectj/util/FileUtil.java b/util/src/main/java/org/aspectj/util/FileUtil.java index 6e55742b1..1927f47a0 100644 --- a/util/src/main/java/org/aspectj/util/FileUtil.java +++ b/util/src/main/java/org/aspectj/util/FileUtil.java @@ -1404,7 +1404,7 @@ public class FileUtil { /** @return true if input is not null and contains no path separator */ private static boolean isValidFileName(String input) { - return ((null != input) && (-1 == input.indexOf(File.pathSeparator))); + return ((null != input) && (!input.contains(File.pathSeparator))); } private static void listFiles(final File baseDir, String dir, ArrayList<String> result) { diff --git a/util/src/main/java/org/aspectj/util/LangUtil.java b/util/src/main/java/org/aspectj/util/LangUtil.java index a0967cfcc..49a65df52 100644 --- a/util/src/main/java/org/aspectj/util/LangUtil.java +++ b/util/src/main/java/org/aspectj/util/LangUtil.java @@ -356,7 +356,7 @@ public class LangUtil { } ArrayList<String> result = new ArrayList<String>(); - if (LangUtil.isEmpty(delim) || (-1 == input.indexOf(delim))) { + if (LangUtil.isEmpty(delim) || (!input.contains(delim))) { result.add(input.trim()); } else { StringTokenizer st = new StringTokenizer(input, delim); @@ -1018,7 +1018,7 @@ public class LangUtil { boolean result = false; if (!LangUtil.isEmpty(input)) { for (int i = 0; !result && (i < infixes.length); i++) { - result = (-1 != input.indexOf(infixes[i])); + result = (input.contains(infixes[i])); } } return result; diff --git a/util/src/test/java/org/aspectj/util/FileUtilTest.java b/util/src/test/java/org/aspectj/util/FileUtilTest.java index 367c0ea5e..663352be6 100644 --- a/util/src/test/java/org/aspectj/util/FileUtilTest.java +++ b/util/src/test/java/org/aspectj/util/FileUtilTest.java @@ -162,7 +162,7 @@ public class FileUtilTest extends TestCase { * @param useSuffix if true, then use dir as suffix to path */ private static void doDirPaths(File dir, ArrayList<String> paths) { - if ((null == dir) || !dir.canRead() || (-1 != dir.getPath().indexOf("CVS"))) { + if ((null == dir) || !dir.canRead() || (dir.getPath().contains("CVS"))) { return; } File[] files = dir.listFiles(); diff --git a/util/src/test/java/org/aspectj/util/GenericSignatureParserTest.java b/util/src/test/java/org/aspectj/util/GenericSignatureParserTest.java index 73a272369..79cd0bbe9 100644 --- a/util/src/test/java/org/aspectj/util/GenericSignatureParserTest.java +++ b/util/src/test/java/org/aspectj/util/GenericSignatureParserTest.java @@ -189,7 +189,7 @@ public class GenericSignatureParserTest extends TestCase { GenericSignature.FieldTypeSignature cSig = parser.parseAsFieldSignature("Ljava/util/List</;"); fail("Expected IllegalStateException"); } catch (IllegalStateException ex) { - assertTrue(ex.getMessage().indexOf("Ljava/util/List</;") != -1); + assertTrue(ex.getMessage().contains("Ljava/util/List</;")); } } diff --git a/util/src/test/java/org/aspectj/util/LangUtilTest.java b/util/src/test/java/org/aspectj/util/LangUtilTest.java index 7e95858b9..545cdd904 100644 --- a/util/src/test/java/org/aspectj/util/LangUtilTest.java +++ b/util/src/test/java/org/aspectj/util/LangUtilTest.java @@ -229,7 +229,7 @@ public class LangUtilTest extends TestCase { LangUtil.elideEndingLines(LangUtil.StringChecker.TEST_PACKAGES, stackBuffer, 10); String result = stackBuffer.toString(); - if (-1 == result.indexOf("(... ")) { + if (!result.contains("(... ")) { // brittle - will fail under different top-level drivers String m = "when running under eclipse or Ant, expecting (... in trace: "; assertTrue(m + result, false); @@ -264,7 +264,7 @@ public class LangUtilTest extends TestCase { LangUtil.elideEndingLines(LangUtil.StringChecker.TEST_PACKAGES, stackBuffer, 25); result = stackBuffer.toString(); - assertTrue(result, -1 != result.indexOf("(... ")); - assertTrue(result, -1 == result.indexOf("org.aspectj.testing")); + assertTrue(result, result.contains("(... ")); + assertTrue(result, !result.contains("org.aspectj.testing")); } } |