From c1c373f4278426308689db61f7758185e8f0401b Mon Sep 17 00:00:00 2001 From: Lars Grefer Date: Sat, 8 Aug 2020 03:11:12 +0200 Subject: '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 --- .../org/aspectj/tools/ajdoc/HtmlDecorator.java | 8 ++--- .../org/aspectj/tools/ajdoc/StubFileGenerator.java | 2 +- .../aspectj/tools/ajdoc/AjdocOutputChecker.java | 38 +++++++++++----------- 3 files changed, 24 insertions(+), 24 deletions(-) (limited to 'ajdoc') diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java index 35e84ca5a..44708bb01 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -192,7 +192,7 @@ class HtmlDecorator { } // only add aspect documentation if we're in the correct // file for the given IProgramElement - if (file.getName().indexOf(fullname + ".html") != -1) { + if (file.getName().contains(fullname + ".html")) { addAspectDocumentation(decl, fileContents, index); } } else { @@ -202,7 +202,7 @@ class HtmlDecorator { // moved this here because then can use the IProgramElement.Kind // rather than checking to see if there's advice - this fixes // the case with an inner aspect not having the title "Aspect" - if (decl.getKind().equals(IProgramElement.Kind.ASPECT) && file.getName().indexOf(decl.toSignatureString()) != -1) { + if (decl.getKind().equals(IProgramElement.Kind.ASPECT) && file.getName().contains(decl.toSignatureString())) { // only want to change "Class" to "Aspect" if we're in the // file corresponding to the IProgramElement String fullname = ""; @@ -212,7 +212,7 @@ class HtmlDecorator { } else { fullname += decl.toSignatureString(); } - if (file.getName().indexOf(fullname + ".html") == -1) { + if (!file.getName().contains(fullname + ".html")) { // we're still in the file for a parent IPE continue; } @@ -746,7 +746,7 @@ class HtmlDecorator { */ private static String getRelativePathFromHere(String packagePath) { StringBuffer result = new StringBuffer(""); - if (packagePath != null && (packagePath.indexOf("/") != -1)) { + if (packagePath != null && (packagePath.contains("/"))) { StringTokenizer sTok = new StringTokenizer(packagePath, "/", false); while (sTok.hasMoreTokens()) { sTok.nextToken(); // don't care about the token value diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java index cd8a01e26..4b9301ce8 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/StubFileGenerator.java @@ -153,7 +153,7 @@ class StubFileGenerator { if (member.getKind().equals(IProgramElement.Kind.METHOD) || member.getKind().equals(IProgramElement.Kind.CONSTRUCTOR)) { - if (member.getParent().getKind().equals(IProgramElement.Kind.INTERFACE) || signature.indexOf("abstract ") != -1) { + if (member.getParent().getKind().equals(IProgramElement.Kind.INTERFACE) || signature.contains("abstract ")) { writer.println(";"); } else { writer.println(" { }"); diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java index b22d1250d..797c76660 100644 --- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java +++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java @@ -41,7 +41,7 @@ public class AjdocOutputChecker { BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); String line = reader.readLine(); while (line != null) { - if (line.indexOf(requiredString) != -1) { + if (line.contains(requiredString)) { reader.close(); return true; } @@ -89,11 +89,11 @@ public class AjdocOutputChecker { BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); String line = reader.readLine(); while (line != null) { - if (line.indexOf(sectionHeader) != -1) { + if (line.contains(sectionHeader)) { String nextLine = reader.readLine(); while (nextLine != null && - (nextLine.indexOf("========") == -1)) { - if (nextLine.indexOf(requiredString) != -1) { + (!nextLine.contains("========"))) { + if (nextLine.contains(requiredString)) { reader.close(); return true; } @@ -151,11 +151,11 @@ public class AjdocOutputChecker { BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); String line = reader.readLine(); while (line != null) { - if (line.indexOf("START OF CLASS DATA") != -1) { + if (line.contains("START OF CLASS DATA")) { // found the required class data section String subLine = reader.readLine(); while(subLine != null - && (subLine.indexOf("========") == -1)){ + && (!subLine.contains("========"))){ int relIndex = subLine.indexOf(relationship.toString()); int targetIndex = subLine.indexOf(target); if ((relIndex != -1) && (targetIndex != -1)) { @@ -195,24 +195,24 @@ public class AjdocOutputChecker { if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) { return false; } - if (sectionHeader.indexOf("DETAIL") == -1) { + if (!sectionHeader.contains("DETAIL")) { return false; } BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); String line = reader.readLine(); while (line != null) { - if (line.indexOf(sectionHeader) != -1) { + if (line.contains(sectionHeader)) { // found the required main section String nextLine = reader.readLine(); - while (nextLine != null && (nextLine.indexOf("========") == -1)) { + while (nextLine != null && (!nextLine.contains("========"))) { // On JDK11 it looks like on earlier JDKs it can look like - if ((LangUtil.is11VMOrGreater() && nextLine.indexOf("ID=\""+source+"\"") != -1 || nextLine.indexOf("id=\""+source+"\"") != -1) || - nextLine.indexOf("NAME=\""+source+"\"") != -1 || nextLine.indexOf("name=\""+source+"\"") != -1) { + if ((LangUtil.is11VMOrGreater() && nextLine.contains("ID=\"" + source + "\"") || nextLine.contains("id=\"" + source + "\"")) || + nextLine.contains("NAME=\"" + source + "\"") || nextLine.contains("name=\"" + source + "\"")) { // found the required subsection String subLine = reader.readLine(); while(subLine != null - && (subLine.indexOf("========") == -1) - && (subLine.indexOf("NAME") == -1 && subLine.indexOf("name") == -1)) { + && (!subLine.contains("========")) + && (!subLine.contains("NAME") && !subLine.contains("name"))) { int relIndex = subLine.indexOf(relationship.toString()); int targetIndex = subLine.indexOf(target); if ((relIndex != -1) && (targetIndex != -1)) { @@ -259,22 +259,22 @@ public class AjdocOutputChecker { if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) { return false; } - if (sectionHeader.indexOf("SUMMARY") == -1) { + if (!sectionHeader.contains("SUMMARY")) { return false; } BufferedReader reader = new BufferedReader(new FileReader(htmlFile)); String line = reader.readLine(); while (line != null) { - if (line.indexOf(sectionHeader) != -1) { + if (line.contains(sectionHeader)) { // found the required main section String nextLine = reader.readLine(); - while (nextLine != null && (nextLine.indexOf("========") == -1)) { - if (nextLine.indexOf(source) != -1) { + while (nextLine != null && (!nextLine.contains("========"))) { + if (nextLine.contains(source)) { // found the required subsection String subLine = nextLine; while(subLine != null - && (subLine.indexOf("========") == -1) - && (subLine.indexOf("") == -1)) { + && (!subLine.contains("========")) + && (!subLine.contains(""))) { int relIndex = subLine.indexOf(relationship.toString()); int targetIndex = subLine.indexOf(target); if ((relIndex != -1) && (targetIndex != -1)) { -- cgit v1.2.3