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 /org.aspectj.matcher | |
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 'org.aspectj.matcher')
10 files changed, 14 insertions, 14 deletions
diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/NameMangler.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/NameMangler.java index f9162684a..a2b2f5d1c 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/NameMangler.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/NameMangler.java @@ -72,7 +72,7 @@ public class NameMangler { return false; // body of an itd-m } return true; - } else if (methodName.indexOf("_aroundBody") != -1) { + } else if (methodName.contains("_aroundBody")) { return true; } // these aren't the droids you're looking for...move along...... pr148727 diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedMemberImpl.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedMemberImpl.java index 90fd3ece3..bb609f104 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedMemberImpl.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedMemberImpl.java @@ -755,7 +755,7 @@ public class ResolvedMemberImpl extends MemberImpl implements IHasPosition, Reso // check going bang in this case we check for $ (crap...) - we can't check the outer because the declaring type // is considered unresolved... if (// isParameterized && <-- might need this bit... - !getDeclaringType().isGenericType() && getDeclaringType().getName().indexOf("$") == -1) { + !getDeclaringType().isGenericType() && !getDeclaringType().getName().contains("$")) { throw new IllegalStateException("Can't ask to parameterize a member of non-generic type: " + getDeclaringType() + " kind(" + getDeclaringType().typeKind + ")"); } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java index a5a5eea5d..8e48b02d4 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedType.java @@ -975,7 +975,7 @@ public abstract class ResolvedType extends UnresolvedType implements AnnotatedEl } public boolean isSynthetic() { - return signature.indexOf("$ajc") != -1; + return signature.contains("$ajc"); } public final boolean isFinal() { diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ShadowMunger.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ShadowMunger.java index a0e49becc..809cc58de 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ShadowMunger.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/ShadowMunger.java @@ -213,7 +213,7 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH // grab javaclass... but it doesnt know the originating file // } } - if (binaryPath.indexOf("!") == -1) { + if (!binaryPath.contains("!")) { File f = getDeclaringType().getSourceLocation().getSourceFile(); // Replace the source file suffix with .class int i = f.getPath().lastIndexOf('.'); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java index 155bc0955..19f1ca5ce 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/UnresolvedType.java @@ -380,7 +380,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { * @return a type object represnting that JVM bytecode signature. */ public static UnresolvedType forSignature(String signature) { - assert !(signature.startsWith("L") && signature.indexOf("<") != -1); + assert !(signature.startsWith("L") && signature.contains("<")); switch (signature.charAt(0)) { case 'B': return UnresolvedType.BYTE; @@ -753,7 +753,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { return name.replace('.','/'); } - if (name.indexOf("<") == -1) { + if (!name.contains("<")) { // not parameterized return new StringBuilder("L").append(name.replace('.', '/')).append(';').toString(); } else { @@ -903,7 +903,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { public String getClassName() { if (className == null) { String name = getName(); - if (name.indexOf("<") != -1) { + if (name.contains("<")) { name = name.substring(0, name.indexOf("<")); } int index = name.lastIndexOf('.'); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Utils.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Utils.java index 501ffa418..2ca0173be 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Utils.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/Utils.java @@ -32,7 +32,7 @@ public class Utils { // 2. there are values specified (i.e. @SuppressAjWarnings("A") or @SuppressAjWarnings({"A","B"}) String value = ann.getStringFormOfValue("value"); // Slightly lazy, just doing a string indexof - if (value == null || value.indexOf(lintkey) != -1) { + if (value == null || value.contains(lintkey)) { return true; } } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/World.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/World.java index 4e625d841..3b69a5d73 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/World.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/World.java @@ -991,10 +991,10 @@ public abstract class World implements Dump.INode { if (jps == null) { return; } - if (jps.indexOf("arrayconstruction") != -1) { + if (jps.contains("arrayconstruction")) { optionalJoinpoint_ArrayConstruction = true; } - if (jps.indexOf("synchronization") != -1) { + if (jps.contains("synchronization")) { optionalJoinpoint_Synchronization = true; } } diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java index 35f2dc674..531b3d09f 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java @@ -212,7 +212,7 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { break; } else { if (t.isAnnotation()) { - if (v.indexOf("(") != -1) { + if (v.contains("(")) { throw new RuntimeException( "Compiler limitation: annotation values can only currently be marker annotations (no values): " + v); @@ -297,7 +297,7 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern { if (typePattern instanceof WildTypePattern && (annotationValues == null || annotationValues.isEmpty())) { WildTypePattern wildTypePattern = (WildTypePattern) typePattern; String fullyQualifiedName = wildTypePattern.maybeGetCleanName(); - if (fullyQualifiedName != null && fullyQualifiedName.indexOf(".") != -1) { + if (fullyQualifiedName != null && fullyQualifiedName.contains(".")) { ResolvedType resolvedType = world.resolve(UnresolvedType.forName(fullyQualifiedName)); if (resolvedType != null && !resolvedType.isMissing()) { typePattern = new ExactTypePattern(resolvedType, false, false); diff --git a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java index 3dad2ce6b..39d4a387b 100644 --- a/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java +++ b/org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java @@ -1164,7 +1164,7 @@ public class WildTypePattern extends TypePattern { ret.add(possibleMatch); continue; } - if (possibleMatch.indexOf("$") != -1) { + if (possibleMatch.contains("$")) { names = splitNames(possibleMatch, false); // ??? not most efficient if (namePatterns[0].matches(names[names.length - 1])) { ret.add(possibleMatch); diff --git a/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/BindingTestCase.java b/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/BindingTestCase.java index 7303191dd..132512e5a 100644 --- a/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/BindingTestCase.java +++ b/org.aspectj.matcher/src/test/java/org/aspectj/weaver/patterns/BindingTestCase.java @@ -102,7 +102,7 @@ public class BindingTestCase extends PatternsTestCase { // System.out.println("expected exception: " + re); return; } catch (Throwable t) { - assertTrue(prefix, t.getMessage().indexOf(prefix) != -1); + assertTrue(prefix, t.getMessage().contains(prefix)); return; } assertTrue("should have failed", false); |