aboutsummaryrefslogtreecommitdiffstats
path: root/bcel-builder
diff options
context:
space:
mode:
authorLars Grefer <eclipse@larsgrefer.de>2020-08-08 03:11:12 +0200
committerLars Grefer <eclipse@larsgrefer.de>2020-08-08 03:11:12 +0200
commitc1c373f4278426308689db61f7758185e8f0401b (patch)
tree9e03af2feb69782c50464fc1e1e2ce0d6b6bb8c5 /bcel-builder
parenta508fd5315c6330f2057c219aebc35b15d0ea497 (diff)
downloadaspectj-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 'bcel-builder')
-rw-r--r--bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java2
-rw-r--r--bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java4
-rw-r--r--bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java2
-rw-r--r--bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java8
-rw-r--r--bcel-builder/src/test/java/org/aspectj/apache/bcel/util/ClassPathTests.java2
5 files changed, 9 insertions, 9 deletions
diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java
index 2d4b2a81f..9168847b0 100644
--- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java
+++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/classfile/Utility.java
@@ -243,7 +243,7 @@ public abstract class Utility {
StringBuffer buf = new StringBuffer("(");
String type;
int index;
- int var_index = (access.indexOf("static") >= 0) ? 0 : 1;
+ int var_index = (access.contains("static")) ? 0 : 1;
try { // Read all declarations between for `(' and `)'
if (signature.charAt(0) != '(') {
diff --git a/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java b/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
index 426ebbea9..d9a4ce780 100644
--- a/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
+++ b/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/AnnotationGenTest.java
@@ -60,7 +60,7 @@ public class AnnotationGenTest extends BcelTestCase {
NameValuePair nvGen = new NameValuePair("id", evg, cp);
// Check it looks right
- assertTrue("Should include string 'id=4' but says: " + nvGen.toString(), nvGen.toString().indexOf("id=4") != -1);
+ assertTrue("Should include string 'id=4' but says: " + nvGen.toString(), nvGen.toString().contains("id=4"));
ObjectType t = new ObjectType("SimpleAnnotation");
@@ -87,7 +87,7 @@ public class AnnotationGenTest extends BcelTestCase {
NameValuePair nvGen = new NameValuePair("id", evg, cp);
// Check it looks right
- assertTrue("Should include string 'id=4' but says: " + nvGen.toString(), nvGen.toString().indexOf("id=4") != -1);
+ assertTrue("Should include string 'id=4' but says: " + nvGen.toString(), nvGen.toString().contains("id=4"));
ObjectType t = new ObjectType("SimpleAnnotation");
diff --git a/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java b/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java
index 7d91bd7d3..ec7645aeb 100644
--- a/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java
+++ b/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ElementValueGenTest.java
@@ -187,7 +187,7 @@ public class ElementValueGenTest extends BcelTestCase {
ClassElementValue evg = new ClassElementValue(classType, cp);
assertTrue("Unexpected value for contained class: '" + evg.getClassString() + "'",
- evg.getClassString().indexOf("Integer") != -1);
+ evg.getClassString().contains("Integer"));
checkSerialize(evg, cp);
}
diff --git a/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java b/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java
index f49b4fb46..351caa002 100644
--- a/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java
+++ b/bcel-builder/src/test/java/org/aspectj/apache/bcel/classfile/tests/ParameterAnnotationsTest.java
@@ -75,9 +75,9 @@ public class ParameterAnnotationsTest extends BcelTestCase {
AnnotationGen[] annos = mainMethod.getAnnotationsOnParameter(0);
assertTrue("Should be two annotation on the 'argv' parameter to main() but there are "+annos.length,annos.length==2);
assertTrue("This annotation should contain the string 'fruit=Apples' but it is "+annos[0].toString(),
- annos[0].toString().indexOf("fruit=Apples")!=-1);
+ annos[0].toString().contains("fruit=Apples"));
assertTrue("This annotation should contain the string 'fruit=Oranges' but it is "+annos[1].toString(),
- annos[1].toString().indexOf("fruit=Oranges")!=-1);
+ annos[1].toString().contains("fruit=Oranges"));
}
@@ -105,9 +105,9 @@ public class ParameterAnnotationsTest extends BcelTestCase {
AnnotationGen[] annos = mainMethod.getAnnotationsOnParameter(0);
assertTrue("Should be two annotation on the 'argv' parameter to main() but there are "+annos.length,annos.length==2);
assertTrue("This annotation should contain the string 'fruit=Apples' but it is "+annos[0].toString(),
- annos[0].toString().indexOf("fruit=Apples")!=-1);
+ annos[0].toString().contains("fruit=Apples"));
assertTrue("This annotation should contain the string 'fruit=Oranges' but it is "+annos[1].toString(),
- annos[1].toString().indexOf("fruit=Oranges")!=-1);
+ annos[1].toString().contains("fruit=Oranges"));
assertTrue(wipe("temp5","HelloWorld.class"));
}
diff --git a/bcel-builder/src/test/java/org/aspectj/apache/bcel/util/ClassPathTests.java b/bcel-builder/src/test/java/org/aspectj/apache/bcel/util/ClassPathTests.java
index 711011213..53488df0e 100644
--- a/bcel-builder/src/test/java/org/aspectj/apache/bcel/util/ClassPathTests.java
+++ b/bcel-builder/src/test/java/org/aspectj/apache/bcel/util/ClassPathTests.java
@@ -9,7 +9,7 @@ public class ClassPathTests extends BcelTestCase {
public void testJava9ImageFile() throws IOException {
String sunbootClasspath = System.getProperty("sun.boot.class.path");
- if (sunbootClasspath==null || sunbootClasspath.indexOf(".jimage")==-1) {
+ if (sunbootClasspath==null || !sunbootClasspath.contains(".jimage")) {
// Not java9
return;
}