From 9fe28c5e6f56bd44633283d8b8cb01c5791b7d2a Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Sat, 17 Aug 2013 00:38:28 +0200 Subject: [PATCH] Fix some quality flaws --- .../src/main/java/org/sonar/batch/DefaultSensorContext.java | 2 +- .../main/java/org/sonar/batch/phases/DecoratorsExecutor.java | 2 +- .../src/main/java/org/sonar/batch/phases/UpdateStatusJob.java | 4 ++-- .../batch/scan/filesystem/DeprecatedFileSystemAdapter.java | 4 ++-- .../src/main/java/org/sonar/colorizer/CodeColorizer.java | 2 +- .../src/main/java/org/sonar/colorizer/LiteralTokenizer.java | 2 +- .../src/main/java/org/sonar/core/component/ScanGraph.java | 2 +- .../java/org/sonar/core/dashboard/ActiveDashboardDao.java | 2 +- .../src/main/java/org/sonar/core/plugins/RemotePlugin.java | 4 ---- sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java | 2 +- .../src/main/java/org/sonar/duplications/block/ByteArray.java | 2 +- .../java/org/sonar/api/measures/CountDistributionBuilder.java | 2 +- .../src/main/java/org/sonar/api/measures/MeasureUtils.java | 2 +- .../org/sonar/server/plugins/ServerExtensionInstaller.java | 2 +- 14 files changed, 15 insertions(+), 19 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java index 9f20029e633..57c75b2551f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java @@ -182,6 +182,6 @@ public class DefaultSensorContext implements SensorContext { } private Resource resourceOrProject(Resource resource) { - return (resource != null ? resource : project); + return resource!=null ? resource : project; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java index 539fc1e4529..75b6cd54be0 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java @@ -61,7 +61,7 @@ public class DecoratorsExecutor implements BatchComponent { DecoratorContext decorateResource(Resource resource, Collection decorators, boolean executeDecorators) { List childrenContexts = Lists.newArrayList(); for (Resource child : index.getChildren(resource)) { - boolean isModule = (child instanceof Project); + boolean isModule = child instanceof Project; DefaultDecoratorContext childContext = (DefaultDecoratorContext) decorateResource(child, decorators, !isModule); childrenContexts.add(childContext.setReadOnly(true)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java index 0dd90eca8df..02056e53899 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/UpdateStatusJob.java @@ -74,7 +74,7 @@ public class UpdateStatusJob implements BatchComponent { private void enableCurrentSnapshot() { Snapshot previousLastSnapshot = resourcePersister.getLastSnapshot(snapshot, false); - boolean isLast = (previousLastSnapshot == null || previousLastSnapshot.getCreatedAt().before(snapshot.getCreatedAt())); + boolean isLast = previousLastSnapshot == null || previousLastSnapshot.getCreatedAt().before(snapshot.getCreatedAt()); setFlags(snapshot, isLast, Snapshot.STATUS_PROCESSED); logSuccess(LoggerFactory.getLogger(getClass())); } @@ -113,7 +113,7 @@ public class UpdateStatusJob implements BatchComponent { query.setParameter("last", last); query.setParameter("rootId", snapshot.getId()); query.setParameter("path", snapshot.getPath() + snapshot.getId() + ".%"); - query.setParameter("pathRootId", (snapshot.getRootId() == null ? snapshot.getId() : snapshot.getRootId())); + query.setParameter("pathRootId", snapshot.getRootId()==null ? snapshot.getId() : snapshot.getRootId()); query.executeUpdate(); session.commit(); diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapter.java index 4201a6b5bf1..4379089c86e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DeprecatedFileSystemAdapter.java @@ -176,7 +176,7 @@ public class DeprecatedFileSystemAdapter implements ProjectFileSystem { public File getFileFromBuildDirectory(String filename) { File file = new File(getBuildDir(), filename); - return (file.exists() ? file : null); + return file.exists() ? file : null; } public Resource toResource(File file) { @@ -187,7 +187,7 @@ public class DeprecatedFileSystemAdapter implements ProjectFileSystem { if (relativePath == null) { return null; } - return (file.isFile() ? new org.sonar.api.resources.File(relativePath.path()) : new org.sonar.api.resources.Directory(relativePath.path())); + return file.isFile() ? new org.sonar.api.resources.File(relativePath.path()) : new org.sonar.api.resources.Directory(relativePath.path()); } public List mainFiles(String... langs) { diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java index f7c651d1bfa..d64bba69530 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/CodeColorizer.java @@ -39,7 +39,7 @@ public class CodeColorizer { } public String toHtml(Reader code, HtmlOptions options) { - HtmlOptions opts = (options == null ? HtmlOptions.DEFAULT : options); + HtmlOptions opts = options == null ? HtmlOptions.DEFAULT : options; return new HtmlRenderer(opts).render(code, tokenizers); } diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java index 2ba72828e92..c230e9c21dd 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/LiteralTokenizer.java @@ -63,7 +63,7 @@ public class LiteralTokenizer extends Tokenizer { public boolean match(int endFlag) { literalValue.append((char) endFlag); - return (code.lastChar() == firstChar && evenNumberOfBackSlashBeforeDelimiter() && literalValue.length() > 1); + return code.lastChar()==firstChar && evenNumberOfBackSlashBeforeDelimiter() && literalValue.length()>1; } private boolean evenNumberOfBackSlashBeforeDelimiter() { diff --git a/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java b/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java index c7cca631716..91db3d7440e 100644 --- a/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java +++ b/sonar-core/src/main/java/org/sonar/core/component/ScanGraph.java @@ -55,7 +55,7 @@ public class ScanGraph extends BeanGraph implements BatchComponent { public ComponentVertex getComponent(String key) { Vertex vertex = GraphUtil.single(getUnderlyingGraph().getVertices("key", key)); - return (vertex != null ? wrapComponent(vertex) : null); + return vertex != null ? wrapComponent(vertex) : null; } public ComponentVertex addComponent(Resource resource, @Nullable Snapshot snapshot) { diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java b/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java index 9a41364b071..f0255c2cedb 100644 --- a/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java +++ b/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java @@ -48,7 +48,7 @@ public class ActiveDashboardDao implements BatchComponent, ServerComponent { ActiveDashboardMapper mapper = session.getMapper(ActiveDashboardMapper.class); try { Integer max = mapper.selectMaxOrderIndexForNullUser(); - return (max != null ? max.intValue() : 0); + return max != null ? max.intValue() : 0; } finally { session.close(); } diff --git a/sonar-core/src/main/java/org/sonar/core/plugins/RemotePlugin.java b/sonar-core/src/main/java/org/sonar/core/plugins/RemotePlugin.java index 467590c4c83..8000f3400ab 100644 --- a/sonar-core/src/main/java/org/sonar/core/plugins/RemotePlugin.java +++ b/sonar-core/src/main/java/org/sonar/core/plugins/RemotePlugin.java @@ -88,10 +88,6 @@ public class RemotePlugin { return files; } - public String getPluginFilename() { - return (!files.isEmpty() ? files.get(0).getFilename() : null); - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java b/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java index a0626f6ad50..de478043f7d 100644 --- a/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java +++ b/sonar-core/src/main/java/org/sonar/jpa/dao/MeasuresDao.java @@ -71,7 +71,7 @@ public class MeasuresDao extends BaseDao { return CollectionUtils.select(getMetricsByName().values(), new Predicate() { public boolean evaluate(Object o) { Metric m = (Metric) o; - return (m.getEnabled() && m.getOrigin() != Metric.Origin.JAV); + return m.getEnabled() && m.getOrigin() != Metric.Origin.JAV; } }); } diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java index 7b1c4e5936b..69034c3936e 100644 --- a/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java +++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/ByteArray.java @@ -96,7 +96,7 @@ public final class ByteArray { public String toHexString() { StringBuilder hex = new StringBuilder(2 * bytes.length); for (byte b : bytes) { - hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt((b & 0x0F))); + hex.append(HEXES.charAt((b & 0xF0) >> 4)).append(HEXES.charAt(b & 0x0F)); } return hex.toString(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java index 8a626cdfd96..bdca4449e65 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CountDistributionBuilder.java @@ -106,7 +106,7 @@ public class CountDistributionBuilder implements MeasureBuilder { Map map = KeyValueFormat.parse(measure.getData()); for (Map.Entry entry : map.entrySet()) { String key = entry.getKey(); - int value = (StringUtils.isBlank(entry.getValue()) ? 0 : Integer.parseInt(entry.getValue())); + int value = StringUtils.isBlank(entry.getValue()) ? 0 : Integer.parseInt(entry.getValue()); if (NumberUtils.isNumber(key)) { add(NumberUtils.toInt(key), value); } else { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java index 9f77587903c..f97e18a1ef2 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/MeasureUtils.java @@ -87,7 +87,7 @@ public final class MeasureUtils { if (measure != null) { result = measure.getVariation(periodIndex); } - return (result != null ? result : defaultValue); + return result != null ? result : defaultValue; } public static Long getVariationAsLong(Measure measure, int periodIndex) { diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java b/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java index c3b8ac9334a..391ca09ebe9 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/ServerExtensionInstaller.java @@ -92,7 +92,7 @@ public class ServerExtensionInstaller { } static boolean isType(Object extension, Class extensionClass) { - Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass()); + Class clazz = extension instanceof Class ? (Class) extension : extension.getClass(); return extensionClass.isAssignableFrom(clazz); } } -- 2.39.5