Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fix SonarQube - change 'String' to 'char' in string functions #2436

Merged
merged 1 commit into from
Sep 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private InheritanceModel readPom(String groupId, String artifactId, String versi
try {
InheritanceModel model = readPOM(depPath.toString(), null, m2RepositoryPath, sourceType, environment);
if (model == null) {
int buildIndex = version.indexOf("-");
int buildIndex = version.indexOf('-');
if (buildIndex != -1) {
String build = version.substring(buildIndex + 1);
folderVersion = version.replace(build, "SNAPSHOT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ private File getTopLevelJar() {
}
} else {
String tmp = version;
int buildIndex = version.indexOf("-");
int buildIndex = version.indexOf('-');
if (buildIndex != -1) {
String build = version.substring(buildIndex + 1);
tmp = version.replace(build, "SNAPSHOT");
} else {
buildIndex = version.indexOf("-");
buildIndex = version.indexOf('-');
}
depPath = Paths.get(m2RepositoryPath, groupId.replaceAll("\\.", "/"), artifactId, tmp);
depFile = depPath.toFile();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/internal/mavenlauncher/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Version implements Comparable<Version> {

Version(String version) {
this.version = version;
int buildIndex = version.indexOf("-");
int buildIndex = version.indexOf('-');
if (buildIndex != -1) {
String build = version.substring(buildIndex + 1);
try {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/reflect/factory/CodeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ public CtJavaDocTag createJavaDocTag(String content, CtJavaDocTag.TagType type)
}
CtJavaDocTag docTag = factory.Core().createJavaDocTag();
if (type != null && type.hasParam()) {
int firstWord = content.indexOf(" ");
int firstLine = content.indexOf("\n");
int firstWord = content.indexOf(' ');
int firstLine = content.indexOf('\n');
if (firstLine < firstWord && firstLine >= 0) {
firstWord = firstLine;
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/spoon/reflect/factory/ExecutableFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ public <T> CtExecutableReference<T> createReference(CtTypeReference<?> declaring
*/
public <T> CtExecutableReference<T> createReference(String signature) {
CtExecutableReference<T> executableRef = factory.Core().createExecutableReference();
String type = signature.substring(0, signature.indexOf(" "));
String declaringType = signature.substring(signature.indexOf(" ") + 1, signature.indexOf(CtExecutable.EXECUTABLE_SEPARATOR));
String executableName = signature.substring(signature.indexOf(CtExecutable.EXECUTABLE_SEPARATOR) + 1, signature.indexOf("("));
String type = signature.substring(0, signature.indexOf(' '));
String declaringType = signature.substring(signature.indexOf(' ') + 1, signature.indexOf(CtExecutable.EXECUTABLE_SEPARATOR));
String executableName = signature.substring(signature.indexOf(CtExecutable.EXECUTABLE_SEPARATOR) + 1, signature.indexOf('('));
executableRef.setSimpleName(executableName);
executableRef.setDeclaringType(factory.Type().createReference(declaringType));
CtTypeReference<T> typeRef = factory.Type().createReference(type);
executableRef.setType(typeRef);
String parameters = signature.substring(signature.indexOf("(") + 1, signature.indexOf(")"));
String parameters = signature.substring(signature.indexOf('(') + 1, signature.indexOf(')'));
List<CtTypeReference<?>> params = new ArrayList<>(PARAMETERS_CONTAINER_DEFAULT_CAPACITY);
StringTokenizer t = new StringTokenizer(parameters, ",");
while (t.hasMoreTokens()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/reflect/factory/FieldFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ public <T> CtFieldReference<T> createReference(Field field) {
*/
public <T> CtFieldReference<T> createReference(String signature) {
CtFieldReference<T> fieldRef = factory.Core().createFieldReference();
String type = signature.substring(0, signature.indexOf(" "));
String declaringType = signature.substring(signature.indexOf(" ") + 1, signature.indexOf(CtField.FIELD_SEPARATOR));
String type = signature.substring(0, signature.indexOf(' '));
String declaringType = signature.substring(signature.indexOf(' ') + 1, signature.indexOf(CtField.FIELD_SEPARATOR));
String fieldName = signature.substring(signature.indexOf(CtField.FIELD_SEPARATOR) + 1);
fieldRef.setSimpleName(fieldName);
fieldRef.setDeclaringType(factory.Type().createReference(declaringType));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/visitor/ImportScannerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private boolean isAlreadyInUsedImport(CtReference ref) {
CtWildcardStaticTypeMemberReferenceImpl importRef = (CtWildcardStaticTypeMemberReferenceImpl) ctImport.getReference();
String importRefStr = importRef.getQualifiedName();

importRefStr = importRefStr.substring(0, importRefStr.lastIndexOf("."));
importRefStr = importRefStr.substring(0, importRefStr.lastIndexOf('.'));
if (qualifiedName.equals(importRefStr)) {
return this.setImportUsed(ctImport);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private CtComment parseTags(CtComment comment, String commentContent) {
for (String aLine : lines) {
String line = aLine.trim();
if (line.startsWith(CtJavaDocTag.JAVADOC_TAG_PREFIX)) {
int endIndex = line.indexOf(" ");
int endIndex = line.indexOf(' ');
if (endIndex == -1) {
endIndex = line.length();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void build() {
String importName = importRef.toString();
if (!importRef.isStatic()) {
if (importName.endsWith("*")) {
int lastDot = importName.lastIndexOf(".");
int lastDot = importName.lastIndexOf('.');
String packageName = importName.substring(0, lastDot);

// only get package from the model by traversing from rootPackage the model
Expand All @@ -86,7 +86,7 @@ void build() {
}
}
} else {
int lastDot = importName.lastIndexOf(".");
int lastDot = importName.lastIndexOf('.');
String className = importName.substring(0, lastDot);
String methodOrFieldName = importName.substring(lastDot + 1);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/spoon/support/reflect/code/CtJavaDocImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public <E extends CtJavaDoc> E removeTag(CtJavaDocTag tag) {

@Override
public String getShortDescription() {
int indexEndSentence = this.getContent().indexOf(".");
int indexEndSentence = this.getContent().indexOf('.');
if (indexEndSentence == -1) {
indexEndSentence = this.getContent().indexOf("\n");
indexEndSentence = this.getContent().indexOf('\n');
}
if (indexEndSentence != -1) {
return this.getContent().substring(0, indexEndSentence + 1).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public CtType<?> getMainType() {
}
for (CtType<?> t : getDeclaredTypes()) {
String name = getFile().getName();
name = name.substring(0, name.lastIndexOf("."));
name = name.substring(0, name.lastIndexOf('.'));
if (t.getSimpleName().equals(name)) {
return t;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/imports/ImportScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testImportOnSpoon() throws IOException {
}

for (String computedImport : computedStaticImports) {
String typeOfStatic = computedImport.substring(0, computedImport.lastIndexOf("."));
String typeOfStatic = computedImport.substring(0, computedImport.lastIndexOf('.'));
if (!staticImports.contains(computedImport) && !typeImports.contains(typeOfStatic)) {
if (!unusedImports.containsKey(ctType)) {
unusedImports.put(ctType, new ArrayList<>());
Expand All @@ -119,7 +119,7 @@ public void testImportOnSpoon() throws IOException {
}

for (String anImport : staticImports) {
String typeOfStatic = anImport.substring(0, anImport.lastIndexOf("."));
String typeOfStatic = anImport.substring(0, anImport.lastIndexOf('.'));
if (!computedStaticImports.contains(anImport) && !computedTypeImports.contains(typeOfStatic)) {
if (!missingImports.containsKey(ctType)) {
missingImports.put(ctType, new ArrayList<>());
Expand Down