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 /tests | |
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 'tests')
13 files changed, 39 insertions, 40 deletions
diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc121/Ajc121Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc121/Ajc121Tests.java index 000a72010..8bc4ad814 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc121/Ajc121Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc121/Ajc121Tests.java @@ -88,17 +88,17 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { public void test016_ByteConversionInstructions() { runTest("RuntimeException thrown: Could not find instruction: org.apache.bcel.generic.B2I"); String output = getLastRunResult().getStdErr(); - assertTrue("Expected to find [b2] in this output but didn't:"+output,output.indexOf("[b2]")!=-1); - assertTrue("Expected to find [b127] in this output but didn't:"+output,output.indexOf("[b127]")!=-1); - assertTrue("Expected to find [b0] in this output but didn't:"+output,output.indexOf("[b0]")!=-1); + assertTrue("Expected to find [b2] in this output but didn't:"+output, output.contains("[b2]")); + assertTrue("Expected to find [b127] in this output but didn't:"+output, output.contains("[b127]")); + assertTrue("Expected to find [b0] in this output but didn't:"+output, output.contains("[b0]")); - assertTrue("Expected to find [c65] in this output but didn't:"+output,output.indexOf("[c65]")!=-1); - assertTrue("Expected to find [c66] in this output but didn't:"+output,output.indexOf("[c66]")!=-1); - assertTrue("Expected to find [c67] in this output but didn't:"+output,output.indexOf("[c67]")!=-1); + assertTrue("Expected to find [c65] in this output but didn't:"+output, output.contains("[c65]")); + assertTrue("Expected to find [c66] in this output but didn't:"+output, output.contains("[c66]")); + assertTrue("Expected to find [c67] in this output but didn't:"+output, output.contains("[c67]")); - assertTrue("Expected to find [s1] in this output but didn't:"+output,output.indexOf("[s1]")!=-1); - assertTrue("Expected to find [s32767] in this output but didn't:"+output,output.indexOf("[s32767]")!=-1); - assertTrue("Expected to find [b0] in this output but didn't:"+output,output.indexOf("[b0]")!=-1); + assertTrue("Expected to find [s1] in this output but didn't:"+output, output.contains("[s1]")); + assertTrue("Expected to find [s32767] in this output but didn't:"+output, output.contains("[s32767]")); + assertTrue("Expected to find [b0] in this output but didn't:"+output, output.contains("[b0]")); } public void test017_PrivateMethodCallsInAroundAdvice() { @@ -229,7 +229,7 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase { runTest("proper handling of ExceptionInIntializer inside clinit in presence of after throwing advice"); String s = getLastRunResult().getStdErr(); assertTrue("Output should contain java.lang.ExceptionInInitializerError but is '"+s+"'", - s.indexOf("java.lang.ExceptionInInitializerError")!=-1); + s.contains("java.lang.ExceptionInInitializerError")); // No getCause on 1.3 JVMs // assertTrue("Output should contain 'CAUSE=org.aspectj.lang.NoAspectBoundException' but is '"+s+"'", // s.indexOf("CAUSE=org.aspectj.lang.NoAspectBoundException")!=-1); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java index c105e881d..8dcb8c34d 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -412,7 +412,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase { AsmManager.dumptree(pw, AsmManager.lastActiveStructureModel.getHierarchy().getRoot(), 0); pw.flush(); String tree = baos.toString(); - assertTrue("Expected 'Red [enumvalue]' somewhere in here:" + tree, tree.indexOf("Red [enumvalue]") != -1); + assertTrue("Expected 'Red [enumvalue]' somewhere in here:" + tree, tree.contains("Red [enumvalue]")); } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java index f03ebe3f0..8c277a906 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc152/SynchronizationTransformTests.java @@ -243,7 +243,7 @@ public class SynchronizationTransformTests extends XMLBasedAjcTestCase { String[] lines = ls.getLines(); for (int i = 0; i < lines.length; i++) { String existingLine = lines[i]; - if (fileContents[i].indexOf("MethodDeclarationLineNumber") == -1 && !fileContents[i].equals(existingLine)) { + if (!fileContents[i].contains("MethodDeclarationLineNumber") && !fileContents[i].equals(existingLine)) { dump("File contents:", fileContents); dump("Actual:", lines); fail("\nDifference in method " + m.getName() + " on line " + i + " between the expected:\n" + fileContents[i] diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java index 5e9e5b25e..b728b8862 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc153/JDTLikeHandleProviderTests.java @@ -300,11 +300,11 @@ public class JDTLikeHandleProviderTests extends XMLBasedAjcTestCase { String warning = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_WARNING, "declare warning: \"warning\"").getHandleIdentifier(); assertTrue("shouldn't have incremented counter for declare warning handle " + "because only one declare warning statement", - warning.indexOf("!0") == -1 && warning.indexOf("!2") == -1); + !warning.contains("!0") && !warning.contains("!2")); String error = top.findElementForLabel(top.getRoot(), IProgramElement.Kind.DECLARE_ERROR, "declare error: \"error\"") .getHandleIdentifier(); assertTrue("shouldn't have incremented counter for declare error handle " + "because only one declare error statement", - error.indexOf("!0") == -1 && error.indexOf("!2") == -1); + !error.contains("!0") && !error.contains("!2")); } // public void testOnlyIncrementSameAdviceKindFromInjar_pr159896() { diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java index bba565a3a..621c1917c 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc161/Ajc161Tests.java @@ -143,7 +143,7 @@ public class Ajc161Tests extends org.aspectj.testing.XMLBasedAjcTestCase { String expected = "<recursivepackage{RecursiveCatcher.java'RecursiveCatcher~recursiveCall~I?method-call(void recursivepackage.RecursiveCatcher.recursiveCall(int))"; for (Object entry : entries) { String str = (String) entry; - if (str.indexOf(expected) != -1) { + if (str.contains(expected)) { gotSomethingValid = true; } } diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java b/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java index 762865c57..46d2c9038 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc165/Ajc165Tests.java @@ -87,7 +87,7 @@ public class Ajc165Tests extends org.aspectj.testing.XMLBasedAjcTestCase { // Look for the message relating to 'List' and check the offsets for (IMessage iMessage : ms) { LintMessage m = (LintMessage) iMessage; - if (m.toString().indexOf("List") != -1) { + if (m.toString().contains("List")) { // 225/228 on windows - 237/240 on linux if (!(m.getSourceStart() == 225 || m.getSourceStart() == 237)) { fail("Did not get expected start position, was:" + m.getSourceStart()); diff --git a/tests/src/test/java/org/aspectj/systemtest/ajc169/IntertypeTests.java b/tests/src/test/java/org/aspectj/systemtest/ajc169/IntertypeTests.java index a91b3a13e..7278a35be 100644 --- a/tests/src/test/java/org/aspectj/systemtest/ajc169/IntertypeTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/ajc169/IntertypeTests.java @@ -156,8 +156,8 @@ public class IntertypeTests extends org.aspectj.testing.XMLBasedAjcTestCase { pw.write(irm.toString()); pw.flush(); String model = baos.toString(); - assertTrue(model.indexOf("<{Choice.java[Choice=[aspect declarations]") != -1); - assertTrue(model.indexOf("<{Choice.java'X[Keys=[declared on]") != -1); + assertTrue(model.contains("<{Choice.java[Choice=[aspect declarations]")); + assertTrue(model.contains("<{Choice.java'X[Keys=[declared on]")); } public void testGenerics1() throws Exception { diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/IncrementalTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/IncrementalTests.java index fc1fa68d8..1d0a546dd 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/IncrementalTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/IncrementalTests.java @@ -179,7 +179,7 @@ public class IncrementalTests extends org.aspectj.testing.XMLBasedAjcTestCase { public void testIncrementalResourceAdditionToInPath() throws Exception { runTest("incremental with addition of resource to inpath directory"); RunResult result = run("Hello"); - assertTrue("Should have been advised",result.getStdOut().indexOf("World") != -1); + assertTrue("Should have been advised", result.getStdOut().contains("World")); nextIncrement(false); assertFalse("Resource file should not exist yet",new File(ajc.getSandboxDirectory(),"AResourceFile.txt").exists()); copyFileAndDoIncrementalBuild("changes/AResourceFile.txt", "indir/AResourceFile.txt"); diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java index 916801690..dd032b3a4 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AbstractMultiProjectIncrementalAjdeInteractionTestbed.java @@ -238,9 +238,9 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI BufferedReader reader = new BufferedReader(new FileReader(aopXML)); String line = reader.readLine(); while (line != null) { - if (aspectName.equals("") && line.indexOf("aspect name=\"") != -1) { + if (aspectName.equals("") && line.contains("aspect name=\"")) { aspectCount++; - } else if (line.indexOf("aspect name=\"" + aspectName + "\"") != -1) { + } else if (line.contains("aspect name=\"" + aspectName + "\"")) { aspectCount++; } line = reader.readLine(); @@ -257,7 +257,7 @@ public class AbstractMultiProjectIncrementalAjdeInteractionTestbed extends AjdeI protected void assertContains(String expectedSubstring, Object object) { String actualString = object.toString(); - if (actualString.indexOf(expectedSubstring) == -1) { + if (!actualString.contains(expectedSubstring)) { fail("Expected to find '" + expectedSubstring + "' in '" + actualString + "'"); } } diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 9c5770ef8..ec1965ca5 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -364,7 +364,7 @@ public class AjdeInteractionTestbed extends TestCase { AjCompiler compiler = CompilerFactory.getCompilerForProjectWithDir(sandboxDir + File.separator + projectName); List<IMessage> messages = ((MultiProjTestMessageHandler) compiler.getMessageHandler()).getErrorMessages(); for (IMessage element : messages) { - if (element.getMessage().indexOf(anError) != -1) { + if (element.getMessage().contains(anError)) { return; } } diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java index 538d2dcbd..3c13ccb71 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MoreOutputLocationManagerTests.java @@ -113,7 +113,7 @@ public class MoreOutputLocationManagerTests extends AbstractMultiProjectIncremen // the unwovenClassFiles should have filenames that point to the output dir // (which in this case is the sandbox dir) and not where they came from. for (UnwovenClassFile ucf: unwovenClassFiles) { - if (ucf.getFilename().indexOf(expectedOutputDir) == -1) { + if (!ucf.getFilename().contains(expectedOutputDir)) { fileNames.add(ucf.getFilename()); } } @@ -152,7 +152,7 @@ public class MoreOutputLocationManagerTests extends AbstractMultiProjectIncremen // the unwovenClassFiles should have filenames that point to the output dir // (which in this case is the sandbox dir) and not where they came from. for (UnwovenClassFile ucf: unwovenClassFiles) { - if (ucf.getFilename().indexOf(expectedOutputDir) == -1) { + if (!ucf.getFilename().contains(expectedOutputDir)) { fileNames.add(ucf.getFilename()); } } @@ -182,7 +182,7 @@ public class MoreOutputLocationManagerTests extends AbstractMultiProjectIncremen List<String> fileNames = new ArrayList<>(); for (UnwovenClassFile ucf: unwovenClassFiles) { - if (ucf.getFilename().indexOf(expectedOutputDir) == -1) { + if (!ucf.getFilename().contains(expectedOutputDir)) { fileNames.add(ucf.getFilename()); } } diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java index 75600dded..c4ea8f120 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/MultiProjectIncrementalTests.java @@ -707,7 +707,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa // 2 errors are reported when there is a clash - one against the aspect, one against the affected target type. // each of the two errors are recorded against the compilation result for the aspect and the target // So it comes out as 4 - but for now I am tempted to leave it because at least it shows there is a problem... - assertTrue("Was:" + getErrorMessages(p).get(0), getErrorMessages(p).get(0).toString().indexOf("conflicts") != -1); + assertTrue("Was:" + getErrorMessages(p).get(0), getErrorMessages(p).get(0).toString().contains("conflicts")); } public void testOutputLocationCallbacks2() { @@ -789,8 +789,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa build(p); checkWasFullBuild(); assertEquals(1, getErrorMessages(p).size()); - assertTrue(((Message) getErrorMessages(p).get(0)).getMessage().indexOf( - "Syntax error on token \")\", \"name pattern\" expected") != -1); + assertTrue(((Message) getErrorMessages(p).get(0)).getMessage().contains("Syntax error on token \")\", \"name pattern\" expected")); } public void testIncrementalMixin() { @@ -1160,15 +1159,15 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa initialiseProject(p); build(p); List<IMessage> l = getErrorMessages(p); - assertTrue(l.toString().indexOf("ManagedResource cannot be resolved to a type") != -1); + assertTrue(l.toString().contains("ManagedResource cannot be resolved to a type")); // checkWasFullBuild(); alter(p, "inc1"); build(p); // checkWasntFullBuild(); List<String> compilerErrors = getCompilerErrorMessages(p); - assertTrue(compilerErrors.toString().indexOf("NullPointerException") == -1); + assertTrue(!compilerErrors.toString().contains("NullPointerException")); l = getErrorMessages(p); - assertTrue(l.toString().indexOf("ManagedResource cannot be resolved to a type") != -1); + assertTrue(l.toString().contains("ManagedResource cannot be resolved to a type")); } public void testIncrementalAnnoStyle_pr286341() { @@ -1514,13 +1513,13 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa private IProgramElement findFile(IProgramElement whereToLook, String filesubstring) { if (whereToLook.getSourceLocation() != null && whereToLook.getKind().isSourceFile() - && whereToLook.getSourceLocation().getSourceFile().toString().indexOf(filesubstring) != -1) { + && whereToLook.getSourceLocation().getSourceFile().toString().contains(filesubstring)) { return whereToLook; } for (IProgramElement element : whereToLook.getChildren()) { Kind k = element.getKind(); ISourceLocation sloc = element.getSourceLocation(); - if (sloc != null && k.isSourceFile() && sloc.getSourceFile().toString().indexOf(filesubstring) != -1) { + if (sloc != null && k.isSourceFile() && sloc.getSourceFile().toString().contains(filesubstring)) { return element; } if (k.isSourceFile()) { @@ -2961,7 +2960,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa List<String> files = getCompiledFiles(projectName); boolean found = false; for (String object: files) { - if (object.indexOf(typeNameSubstring) != -1) { + if (object.contains(typeNameSubstring)) { found = true; } } @@ -3053,7 +3052,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa List<IMessage> warnings = getWarningMessages("PR133117"); List<IMessage> noGuardWarnings = new ArrayList<>(); for (IMessage warning: warnings) { - if (warning.getMessage().indexOf("Xlint:noGuardForLazyTjp") != -1) { + if (warning.getMessage().contains("Xlint:noGuardForLazyTjp")) { noGuardWarnings.add(warning); } } @@ -3137,7 +3136,7 @@ public class MultiProjectIncrementalTests extends AbstractMultiProjectIncrementa String decisions = AjdeInteractionTestbed.MyStateListener.getDecisions(); String expect = "Need to recompile 'A.aj'"; assertTrue("Couldn't find build decision: '" + expect + "' in the list of decisions made:\n" + decisions, - decisions.indexOf(expect) != -1); + decisions.contains(expect)); } public void testPr133532_3() { diff --git a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/OutputLocationManagerTests.java b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/OutputLocationManagerTests.java index 333495399..6f6be1256 100644 --- a/tests/src/test/java/org/aspectj/systemtest/incremental/tools/OutputLocationManagerTests.java +++ b/tests/src/test/java/org/aspectj/systemtest/incremental/tools/OutputLocationManagerTests.java @@ -114,11 +114,11 @@ public class OutputLocationManagerTests extends AbstractMultiProjectIncrementalA public File getOutputLocationForClass(File compilationUnit) { String relativePath = ""; String compilationUnitName = compilationUnit.getAbsolutePath(); - if (compilationUnitName.indexOf("srcRootOne") != -1) { + if (compilationUnitName.contains("srcRootOne")) { relativePath = "target/main/classes"; - } else if (compilationUnitName.indexOf("srcRootTwo") != -1) { + } else if (compilationUnitName.contains("srcRootTwo")) { relativePath = "target/test/classes"; - } else if (compilationUnitName.indexOf("srcRootThree") != -1) { + } else if (compilationUnitName.contains("srcRootThree")) { relativePath = "target/anotherTest/classes"; } File ret = new File(projectHome, relativePath); |