Skip to content

Commit f875c3b

Browse files
authored
chore: Automate more static code checks (#2028)
1 parent a5a25b5 commit f875c3b

31 files changed

+77
-60
lines changed

config/checkstyle/appium-style.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
<message key="name.invalidPattern"
129129
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
130130
</module>
131+
<module name="ConstantName"/>
131132
<module name="GenericWhitespace">
132133
<message key="ws.followed"
133134
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
@@ -198,6 +199,12 @@
198199

199200
</module>
200201
<module name="CommentsIndentation"/>
202+
<module name="MissingOverride"/>
203+
<module name="UnnecessaryParentheses"/>
204+
<module name="HideUtilityClassConstructor"/>
205+
206+
<!-- Make the @SuppressWarnings annotations available to Checkstyle -->
207+
<module name="SuppressWarningsHolder"/>
201208
</module>
202209
<module name="LineLength">
203210
<property name="max" value="120"/>
@@ -208,4 +215,7 @@
208215
<property name="file" value="${config_loc}/suppressions.xml"/>
209216
<property name="optional" value="false"/>
210217
</module>
218+
219+
<!-- Filter out Checkstyle warnings that have been suppressed with the @SuppressWarnings annotation -->
220+
<module name="SuppressWarningsFilter"/>
211221
</module>

src/main/java/io/appium/java_client/AppiumDriver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class AppiumDriver extends RemoteWebDriver implements
7070
CanRememberExtensionPresence,
7171
HasSettings {
7272

73-
private static final ErrorHandler errorHandler = new ErrorHandler(new ErrorCodesMobile(), true);
73+
private static final ErrorHandler ERROR_HANDLER = new ErrorHandler(new ErrorCodesMobile(), true);
7474
// frequently used command parameters
7575
private final URL remoteAddress;
7676
protected final RemoteLocationContext locationContext;
@@ -89,7 +89,7 @@ public AppiumDriver(HttpCommandExecutor executor, Capabilities capabilities) {
8989
super(executor, capabilities);
9090
this.executeMethod = new AppiumExecutionMethod(this);
9191
locationContext = new RemoteLocationContext(executeMethod);
92-
super.setErrorHandler(errorHandler);
92+
super.setErrorHandler(ERROR_HANDLER);
9393
this.remoteAddress = executor.getAddressOfRemoteServer();
9494
}
9595

@@ -167,7 +167,7 @@ public AppiumDriver(URL remoteSessionAddress, String platformName, String automa
167167
setCommandExecutor(executor);
168168
this.executeMethod = new AppiumExecutionMethod(this);
169169
locationContext = new RemoteLocationContext(executeMethod);
170-
super.setErrorHandler(errorHandler);
170+
super.setErrorHandler(ERROR_HANDLER);
171171
this.remoteAddress = executor.getAddressOfRemoteServer();
172172

173173
setSessionId(sessionAddress.getId());

src/main/java/io/appium/java_client/CommandExecutionHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package io.appium.java_client;
1818

1919
import com.google.common.collect.ImmutableMap;
20-
import lombok.AccessLevel;
21-
import lombok.NoArgsConstructor;
2220
import org.openqa.selenium.remote.Response;
2321

2422
import javax.annotation.Nullable;
@@ -28,9 +26,11 @@
2826

2927
import static org.openqa.selenium.remote.DriverCommand.EXECUTE_SCRIPT;
3028

31-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3229
public final class CommandExecutionHelper {
3330

31+
private CommandExecutionHelper() {
32+
}
33+
3434
@Nullable
3535
public static <T> T execute(
3636
ExecutesMethod executesMethod, Map.Entry<String, Map<String, ?>> keyValuePair

src/main/java/io/appium/java_client/LogsEvents.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ default ServerEvents getEvents() {
6363
.stream()
6464
.map((Map<String, Object> cmd) -> new CommandEvent(
6565
(String) cmd.get("cmd"),
66-
((Long) cmd.get("startTime")),
67-
((Long) cmd.get("endTime"))
66+
(Long) cmd.get("startTime"),
67+
(Long) cmd.get("endTime")
6868
))
6969
.collect(Collectors.toList());
7070

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* Most of these commands are platform-specific obsolete things and should eventually be replaced with
3939
* calls to corresponding `mobile:` extensions, so we don't abuse non-w3c APIs
4040
*/
41+
@SuppressWarnings({"checkstyle:HideUtilityClassConstructor", "checkstyle:ConstantName"})
4142
public class MobileCommand {
4243
//General
4344
@Deprecated
@@ -434,7 +435,7 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
434435
Object[] values) {
435436
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
436437
for (int i = 0; i < params.length; i++) {
437-
if (!StringUtils.isBlank(params[i]) && (values[i] != null)) {
438+
if (!StringUtils.isBlank(params[i]) && values[i] != null) {
438439
builder.put(params[i], values[i]);
439440
}
440441
}

src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
214214
String intentAction, String intentCategory, String intentFlags,
215215
String optionalIntentArguments, boolean stopApp) throws IllegalArgumentException {
216216

217-
checkArgument((!StringUtils.isBlank(appPackage)
218-
&& !StringUtils.isBlank(appActivity)),
217+
checkArgument(!StringUtils.isBlank(appPackage) && !StringUtils.isBlank(appActivity),
219218
String.format("'%s' and '%s' are required.", "appPackage", "appActivity"));
220219

221220
String targetWaitPackage = !StringUtils.isBlank(appWaitPackage) ? appWaitPackage : "";

src/main/java/io/appium/java_client/internal/CapabilityHelpers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package io.appium.java_client.internal;
1818

19-
import lombok.AccessLevel;
20-
import lombok.NoArgsConstructor;
2119
import org.openqa.selenium.Capabilities;
2220

2321
import javax.annotation.Nullable;
@@ -28,10 +26,12 @@
2826
import java.util.List;
2927
import java.util.function.Function;
3028

31-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3229
public class CapabilityHelpers {
3330
public static final String APPIUM_PREFIX = "appium:";
3431

32+
private CapabilityHelpers() {
33+
}
34+
3535
/**
3636
* Helper that is used for capability values retrieval.
3737
* Supports both prefixed W3C and "classic" capability names.

src/main/java/io/appium/java_client/internal/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
public class Config {
1212
private static Config mainInstance = null;
1313
private static final String MAIN_CONFIG = "main.properties";
14-
private static final Map<String, Properties> cache = new ConcurrentHashMap<>();
14+
private static final Map<String, Properties> CACHE = new ConcurrentHashMap<>();
1515
private final String configName;
1616

1717
/**
@@ -58,7 +58,7 @@ public <T> T getValue(String key, Class<T> valueType) {
5858
* @throws ClassCastException if the retrieved value cannot be cast to `valueType` type
5959
*/
6060
public <T> Optional<T> getOptionalValue(String key, Class<T> valueType) {
61-
final Properties cachedProps = cache.computeIfAbsent(configName, k -> {
61+
final Properties cachedProps = CACHE.computeIfAbsent(configName, k -> {
6262
try (InputStream configFileStream = getClass().getClassLoader().getResourceAsStream(configName)) {
6363
final Properties p = new Properties();
6464
p.load(configFileStream);

src/main/java/io/appium/java_client/internal/ReflectionHelpers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616

1717
package io.appium.java_client.internal;
1818

19-
import lombok.AccessLevel;
20-
import lombok.NoArgsConstructor;
2119
import org.openqa.selenium.WebDriverException;
2220

2321
import java.lang.reflect.Field;
2422

25-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2623
public class ReflectionHelpers {
2724

25+
private ReflectionHelpers() {
26+
}
27+
2828
/**
2929
* Sets the given value to a private instance field.
3030
*

src/main/java/io/appium/java_client/internal/SessionHelpers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
package io.appium.java_client.internal;
1818

19-
import lombok.AccessLevel;
2019
import lombok.Data;
21-
import lombok.NoArgsConstructor;
2220
import org.openqa.selenium.InvalidArgumentException;
2321
import org.openqa.selenium.WebDriverException;
2422

@@ -27,10 +25,12 @@
2725
import java.util.regex.Matcher;
2826
import java.util.regex.Pattern;
2927

30-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3128
public class SessionHelpers {
3229
private static final Pattern SESSION = Pattern.compile("/session/([^/]+)");
3330

31+
private SessionHelpers() {
32+
}
33+
3434
@Data public static class SessionAddress {
3535
private final URL serverUrl;
3636
private final String id;

0 commit comments

Comments
 (0)