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.ajdt.core/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 'org.aspectj.ajdt.core/src')
14 files changed, 36 insertions, 38 deletions
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/AjdtCommand.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/AjdtCommand.java index 25de41c2d..7fa4e9c36 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/AjdtCommand.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/ajc/AjdtCommand.java @@ -168,9 +168,9 @@ public class AjdtCommand implements ICommand { /** @return IMessage.WARNING unless message contains error or info */ protected static IMessage.Kind inferKind(String message) { // XXX dubious - if (-1 != message.indexOf("error")) { + if (message.contains("error")) { return IMessage.ERROR; - } else if (-1 != message.indexOf("info")) { + } else if (message.contains("info")) { return IMessage.INFO; } else { return IMessage.WARNING; diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java index 70a610950..365f56940 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java @@ -139,7 +139,7 @@ public class PointcutDeclaration extends AjMethodDeclaration { public String getPointcutText() { String text = getPointcut().toString(); - if (text.indexOf("BindingTypePattern") == -1) + if (!text.contains("BindingTypePattern")) return text; // has been wrecked by resolution, try to reconstruct from tokens if (pointcutDesignator != null) { diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java index ec5a2a545..c42a503c6 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java @@ -325,25 +325,25 @@ public class AjProblemReporter extends ProblemReporter { String name = new String(binding.selector); if (name.startsWith("ajc$")) { long metaTagBits = annotation.resolvedType.getAnnotationTagBits(); // could be forward reference - if (name.indexOf("interField") != -1) { + if (name.contains("interField")) { if ((metaTagBits & TagBits.AnnotationForField) != 0) return; - } else if (name.indexOf("interConstructor") != -1) { + } else if (name.contains("interConstructor")) { if ((metaTagBits & TagBits.AnnotationForConstructor) != 0) return; - } else if (name.indexOf("interMethod") != -1) { + } else if (name.contains("interMethod")) { if ((metaTagBits & TagBits.AnnotationForMethod) != 0) return; - } else if (name.indexOf("declare_" + DeclareAnnotation.AT_TYPE + "_") != -1) { + } else if (name.contains("declare_" + DeclareAnnotation.AT_TYPE + "_")) { if ((metaTagBits & TagBits.AnnotationForAnnotationType) != 0 || (metaTagBits & TagBits.AnnotationForType) != 0) return; - } else if (name.indexOf("declare_" + DeclareAnnotation.AT_FIELD + "_") != -1) { + } else if (name.contains("declare_" + DeclareAnnotation.AT_FIELD + "_")) { if ((metaTagBits & TagBits.AnnotationForField) != 0) return; - } else if (name.indexOf("declare_" + DeclareAnnotation.AT_CONSTRUCTOR + "_") != -1) { + } else if (name.contains("declare_" + DeclareAnnotation.AT_CONSTRUCTOR + "_")) { if ((metaTagBits & TagBits.AnnotationForConstructor) != 0) return; - } else if (name.indexOf("declare_eow") != -1) { + } else if (name.contains("declare_eow")) { if ((metaTagBits & TagBits.AnnotationForField) != 0) return; } @@ -685,7 +685,7 @@ public class AjProblemReporter extends ProblemReporter { this.delegate = aProblem; // if this was a problem that came via the weaver, it will already have // pinpoint info, don't do it twice... - if (delegate.getMessage().indexOf("message issued...") == -1) { + if (!delegate.getMessage().contains("message issued...")) { this.message = delegate.getMessage() + "\n" + pinpoint; } else { this.message = delegate.getMessage(); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java index 219f2fd48..4cd844590 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java @@ -579,7 +579,7 @@ public class AjBuildConfig implements CompilerConfigurationChangeFlags { lintValue = AjCompilerOptions.ERROR; } else { // Possibly a name=value comma separated list of configurations - if (lintMode.indexOf("=")!=-1) { + if (lintMode.contains("=")) { this.lintMode = AJLINT_DEFAULT; lintOptionsMap = new HashMap<String,String>(); StringTokenizer tokenizer = new StringTokenizer(lintMode,","); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 98c115190..dfdcba12c 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -640,9 +640,9 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour } private boolean acceptResource(String resourceName, boolean fromFile) { - if ((resourceName.startsWith("CVS/")) || (resourceName.indexOf("/CVS/") != -1) || (resourceName.endsWith("/CVS")) + if ((resourceName.startsWith("CVS/")) || (resourceName.contains("/CVS/")) || (resourceName.endsWith("/CVS")) || (resourceName.endsWith(".class")) || (resourceName.startsWith(".svn/")) - || (resourceName.indexOf("/.svn/") != -1) || (resourceName.endsWith("/.svn")) || + || (resourceName.contains("/.svn/")) || (resourceName.endsWith("/.svn")) || // Do not copy manifests if either they are coming from a jar or we are writing to a jar (resourceName.toUpperCase().equals(MANIFEST_NAME) && (!fromFile || zos != null))) { return false; @@ -1382,7 +1382,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider, IBinarySour } return null; // this is the "OK" return value! } - else if (p.isFile() && p.getName().indexOf("org.aspectj.runtime") != -1) { + else if (p.isFile() && p.getName().contains("org.aspectj.runtime")) { // likely to be a variant from the springsource bundle repo b272591 return null; } diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjState.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjState.java index 833ce2382..7e08c02a7 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjState.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AjState.java @@ -1429,7 +1429,7 @@ public class AjState implements CompilerConfigurationChangeFlags, TypeDelegateRe if (compiledTypes != null) { for (char[] className : (Iterable<char[]>) compiledTypes.keySet()) { String typeName = new String(className).replace('/', '.'); - if (typeName.indexOf(BcelWeaver.SYNTHETIC_CLASS_POSTFIX) == -1) { + if (!typeName.contains(BcelWeaver.SYNTHETIC_CLASS_POSTFIX)) { ResolvedType rt = world.resolve(typeName); if (rt.isMissing()) { // This can happen in a case where another problem has occurred that prevented it being diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java index 77862dddf..776696aff 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java @@ -174,7 +174,7 @@ public class AsmElementFormatter { } else if (methodDeclaration instanceof InterTypeDeclaration) { InterTypeDeclaration itd = (InterTypeDeclaration) methodDeclaration; String fqname = itd.getOnType().toString(); - if (fqname.indexOf(".") != -1) { + if (fqname.contains(".")) { // TODO the string handling round here is embarrassing node.addFullyQualifiedName(fqname + "." + new String(itd.getDeclaredSelector())); fqname = fqname.substring(fqname.lastIndexOf(".") + 1); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java index 8a3acaec8..795176c61 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/core/builder/EclipseAdapterUtils.java @@ -161,7 +161,7 @@ public class EclipseAdapterUtils { declared = true; extraDetails = extraDetails.substring(0, extraDetails.length() - "[deow=true]".length()); } - if (extraDetails != null && extraDetails.indexOf("[Xlint:") != -1) { + if (extraDetails != null && extraDetails.contains("[Xlint:")) { isLintMessage = true; lintkey = extraDetails.substring(extraDetails.indexOf("[Xlint:")); lintkey = lintkey.substring("[Xlint:".length()); diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java index 6f7a1dd7c..88558fed0 100644 --- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java +++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/tools/ajc/Main.java @@ -570,7 +570,7 @@ public class Main { File file = loc.getSourceFile(); if (null != file) { String name = file.getName(); - if (!toString || (-1 == text.indexOf(name))) { + if (!toString || (!text.contains(name))) { sb.append(FileUtil.getBestPath(file)); if (loc.getLine() > 0) { sb.append(":" + loc.getLine()); diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/AjdtCommandTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/AjdtCommandTestCase.java index 9c504a300..57c2f8e4c 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/AjdtCommandTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/AjdtCommandTestCase.java @@ -122,7 +122,7 @@ public class AjdtCommandTestCase extends TestCase { public void testIncrementalOption() throws InvalidInputException { AjdtCommand.genBuildConfig(new String[] { "-incremental" }, counter); - assertTrue("didn't specify source root", outputWriter.getContents().indexOf("specify a source root") != -1); + assertTrue("didn't specify source root", outputWriter.getContents().contains("specify a source root")); outputWriter.flushBuffer(); AjdtCommand.genBuildConfig(new String[] { "-incremental", "-sourceroots", Constants.TESTDATA_PATH + "/src1" }, counter); @@ -132,8 +132,7 @@ public class AjdtCommandTestCase extends TestCase { outputWriter.flushBuffer(); AjdtCommand.genBuildConfig(new String[] { "-incremental", "testdata/src1/Hello.java" }, counter); - assertTrue("specified a file", outputWriter.getContents().indexOf( - "incremental mode only handles source files using -sourceroots") != -1); + assertTrue("specified a file", outputWriter.getContents().contains("incremental mode only handles source files using -sourceroots")); } public void testBadOptionAndUsagePrinting() throws InvalidInputException { @@ -143,7 +142,7 @@ public class AjdtCommandTestCase extends TestCase { } // usage printed by caller to genBuildConfig now... assertTrue(outputWriter.getContents() + " contains? " + "Usage", - outputWriter.getContents().indexOf("-mubleBadOption") != -1); + outputWriter.getContents().contains("-mubleBadOption")); } @@ -166,7 +165,7 @@ public class AjdtCommandTestCase extends TestCase { } String text = byteArrayOut.toString(); - assertTrue(text + " contains? " + "Usage", text.indexOf("Usage") != -1); + assertTrue(text + " contains? " + "Usage", text.contains("Usage")); } public void q() throws InvalidInputException { @@ -194,14 +193,13 @@ public class AjdtCommandTestCase extends TestCase { String text = byteArrayOut.toString(); // String text2 = byteArrayErr.toString(); - assertTrue("version output does not include 'AspectJ Compiler', output was:\n'" + text + "'", text - .indexOf("AspectJ Compiler") != -1); + assertTrue("version output does not include 'AspectJ Compiler', output was:\n'" + text + "'", text.contains("AspectJ Compiler")); } public void testNonExistingLstFile() { AjdtCommand.genBuildConfig(new String[] { "@mumbleDoesNotExist" }, counter); - assertTrue(outputWriter.getContents(), outputWriter.getContents().indexOf("file does not exist") != -1); + assertTrue(outputWriter.getContents(), outputWriter.getContents().contains("file does not exist")); } protected void setUp() throws Exception { diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java index 1f936661e..c4439c9f7 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/ajc/BuildArgParserTestCase.java @@ -99,8 +99,8 @@ public class BuildArgParserTestCase extends TestCase { boolean jar2Found = false; for (Object o : cp) { String element = (String) o; - if (element.indexOf("1.jar") != -1) jar1Found = true; - if (element.indexOf("2.jar") != -1) jar2Found = true; + if (element.contains("1.jar")) jar1Found = true; + if (element.contains("2.jar")) jar2Found = true; } assertTrue( config.getClasspath().toString(), @@ -312,7 +312,7 @@ public class BuildArgParserTestCase extends TestCase { "-bootclasspath", PATH }, messageWriter); assertTrue("Should find '" + PATH + "' contained in the first entry of '" + config.getBootclasspath().toString(), - config.getBootclasspath().get(0).indexOf(PATH) != -1); + config.getBootclasspath().get(0).contains(PATH)); config = genBuildConfig(new String[] { }, @@ -375,8 +375,8 @@ public class BuildArgParserTestCase extends TestCase { boolean jar2Found = false; for (Object o : cp) { String element = (String) o; - if (element.indexOf("1.jar") != -1) jar1Found = true; - if (element.indexOf("2.jar") != -1) jar2Found = true; + if (element.contains("1.jar")) jar1Found = true; + if (element.contains("2.jar")) jar2Found = true; } assertTrue( config.getClasspath().toString(), diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/DumpTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/DumpTestCase.java index dad021a7c..4f40922d6 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/DumpTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/compiler/batch/DumpTestCase.java @@ -123,7 +123,7 @@ public class DumpTestCase extends TestCase { String record; while ((null != (record = reader.readLine())) && (result == false)) { if (record.startsWith("----")) currentHeading = record; - else if ((record.indexOf(contents) != -1) && currentHeading.indexOf(heading) != -1) result = true; + else if ((record.contains(contents)) && currentHeading.contains(heading)) result = true; } reader.close(); } diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java index 6887d79fe..1dc118283 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java @@ -43,7 +43,7 @@ public class AjBuildManagerTest extends TestCase { final int numMessages = handler.numMessages(IMessage.WARNING, true); if (1 == numMessages) { // permit aspectjrt.jar warning IMessage m = handler.getMessages(IMessage.WARNING, true)[0]; - if (!(m.isWarning() && (-1 != m.getMessage().indexOf("aspectjrt.jar")))) { + if (!(m.isWarning() && (m.getMessage().contains("aspectjrt.jar")))) { assertTrue(handler.toString(), false); } } else if (0 != numMessages) { diff --git a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java index a9442de73..7aa97ad1e 100644 --- a/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java +++ b/org.aspectj.ajdt.core/src/test/java/org/aspectj/tools/ajc/AjcTestCase.java @@ -224,7 +224,7 @@ public abstract class AjcTestCase extends TestCase { } } if (text != null) { - if (message.getMessage().indexOf(text) == -1) { + if (!message.getMessage().contains(text)) { return false; } } @@ -891,7 +891,7 @@ public abstract class AjcTestCase extends TestCase { private String substituteSandbox(String path) { // the longhand form of the non 1.3 API: path.replace("$sandbox", ajc.getSandboxDirectory().getAbsolutePath()); - while (path.indexOf("$sandbox") != -1) { + while (path.contains("$sandbox")) { int pos = path.indexOf("$sandbox"); String firstbit = path.substring(0, pos); String endbit = path.substring(pos + 8); @@ -918,7 +918,7 @@ public abstract class AjcTestCase extends TestCase { cpIndex = i; args[i + 1] = substituteSandbox(args[i + 1]); String next = args[i + 1]; - hasruntime = ((null != next) && (-1 != next.indexOf("aspectjrt.jar"))); + hasruntime = ((null != next) && (next.contains("aspectjrt.jar"))); } else if ("-p".equals(args[i]) || "--module-path".equals(args[i])) { args[i + 1] = substituteSandbox(args[i + 1]); } @@ -941,7 +941,7 @@ public abstract class AjcTestCase extends TestCase { } boolean needsJRTFS = LangUtil.is19VMOrGreater(); if (needsJRTFS) { - if (args[cpIndex].indexOf(LangUtil.JRT_FS) == -1) { + if (!args[cpIndex].contains(LangUtil.JRT_FS)) { String jrtfsPath = LangUtil.getJrtFsFilePath(); args[cpIndex] = jrtfsPath + File.pathSeparator + args[cpIndex]; } |