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 /runtime | |
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 'runtime')
4 files changed, 10 insertions, 10 deletions
diff --git a/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java b/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java index c658bbbd0..b953fa1ce 100644 --- a/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java +++ b/runtime/src/main/java/org/aspectj/internal/lang/reflect/StringToType.java @@ -40,7 +40,7 @@ public class StringToType { public static Type stringToType(String typeName, Class classScope) throws ClassNotFoundException { try { - if (typeName.indexOf("<") == -1) { + if (!typeName.contains("<")) { return AjTypeSystem.getAjType(Class.forName(typeName,false,classScope.getClassLoader())); } else { return makeParameterizedType(typeName,classScope); diff --git a/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeTest.java b/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeTest.java index 542de36d5..9ddb5c0dc 100644 --- a/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeTest.java +++ b/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeTest.java @@ -139,8 +139,8 @@ public class AjTypeTest extends TestCase { assertEquals(2,fooTypes.length); // Alex -> Adrian: looks like you can not make assumption on the ordering String s = " " + fooTypes[0].getName() + " " + fooTypes[1].getName(); - assertTrue(s.indexOf(" org.aspectj.internal.lang.reflect.Foo$Z") >= 0); - assertTrue(s.indexOf(" org.aspectj.internal.lang.reflect.Foo$XX") >= 0); + assertTrue(s.contains(" org.aspectj.internal.lang.reflect.Foo$Z")); + assertTrue(s.contains(" org.aspectj.internal.lang.reflect.Foo$XX")); } public void testGetConstructor() throws Exception { diff --git a/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java b/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java index a2f33f91b..5431a7457 100644 --- a/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java +++ b/runtime/src/test/java/org/aspectj/internal/lang/reflect/AjTypeWithAspectsTest.java @@ -149,7 +149,7 @@ public class AjTypeWithAspectsTest extends TestCase { for (Method m : ms) { match = match + "--" + m.getName(); } - assertTrue(match.indexOf("aMethod") >=0); + assertTrue(match.contains("aMethod")); } public void testGetDeclaredPointcut() throws Exception { @@ -200,8 +200,8 @@ public class AjTypeWithAspectsTest extends TestCase { assertEquals(2,pcs.length); // AV was corrupted, cannot rely on ordering String match = "simpleAspectMethodExecution--simpleAspectCall"; - assertTrue(match.indexOf(pcs[0].getName()) >= 0); - assertTrue(match.indexOf(pcs[1].getName()) >= 0); + assertTrue(match.contains(pcs[0].getName())); + assertTrue(match.contains(pcs[1].getName())); } public void testGetPointcuts() { diff --git a/runtime/src/test/java/org/aspectj/runtime/RuntimeTest.java b/runtime/src/test/java/org/aspectj/runtime/RuntimeTest.java index a908a8ae0..2eb92e97b 100644 --- a/runtime/src/test/java/org/aspectj/runtime/RuntimeTest.java +++ b/runtime/src/test/java/org/aspectj/runtime/RuntimeTest.java @@ -69,9 +69,9 @@ public class RuntimeTest extends TestCase { static void checkSoftExceptionString(String s) { - assertTrue(-1 != s.indexOf("SoftException")); - assertTrue(-1 != s.indexOf("Caused by: java.lang.Error")); - assertTrue(-1 != s.indexOf("xyz")); - assertTrue(-1 != s.indexOf("testSoftExceptionPrintStackTrace")); + assertTrue(s.contains("SoftException")); + assertTrue(s.contains("Caused by: java.lang.Error")); + assertTrue(s.contains("xyz")); + assertTrue(s.contains("testSoftExceptionPrintStackTrace")); } } |