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;

src/main/java/io/appium/java_client/pagefactory/AppiumFieldDecorator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
*/
6363
public class AppiumFieldDecorator implements FieldDecorator {
6464

65-
private static final List<Class<? extends WebElement>> availableElementClasses = ImmutableList.of(
65+
private static final List<Class<? extends WebElement>> AVAILABLE_ELEMENT_CLASSES = ImmutableList.of(
6666
WebElement.class,
6767
RemoteWebElement.class
6868
);
@@ -169,7 +169,7 @@ protected boolean isDecoratableList(Field field) {
169169
List<Type> bounds = (listType instanceof TypeVariable)
170170
? Arrays.asList(((TypeVariable<?>) listType).getBounds())
171171
: Collections.emptyList();
172-
return availableElementClasses.stream()
172+
return AVAILABLE_ELEMENT_CLASSES.stream()
173173
.anyMatch(webElClass -> webElClass.equals(listType) || bounds.contains(webElClass));
174174
}
175175
};

src/main/java/io/appium/java_client/pagefactory/DefaultElementByBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected By buildMobileNativeBy() {
186186
@Override
187187
public boolean isLookupCached() {
188188
AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
189-
return (annotatedElement.getAnnotation(CacheLookup.class) != null);
189+
return annotatedElement.getAnnotation(CacheLookup.class) != null;
190190
}
191191

192192
private By returnMappedBy(By byDefault, By nativeAppBy) {

src/main/java/io/appium/java_client/pagefactory/OverrideWidgetReader.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.pagefactory;
1818

1919
import io.appium.java_client.pagefactory.bys.ContentType;
20-
import lombok.AccessLevel;
21-
import lombok.NoArgsConstructor;
2220

2321
import java.lang.reflect.AnnotatedElement;
2422
import java.lang.reflect.Constructor;
@@ -31,14 +29,16 @@
3129
import static io.appium.java_client.remote.MobilePlatform.IOS;
3230
import static io.appium.java_client.remote.MobilePlatform.WINDOWS;
3331

34-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3532
class OverrideWidgetReader {
3633
private static final Class<? extends Widget> EMPTY = Widget.class;
3734
private static final String HTML = "html";
3835
private static final String ANDROID_UI_AUTOMATOR = "androidUIAutomator";
3936
private static final String IOS_XCUIT_AUTOMATION = "iOSXCUITAutomation";
4037
private static final String WINDOWS_AUTOMATION = "windowsAutomation";
4138

39+
private OverrideWidgetReader() {
40+
}
41+
4242
@SuppressWarnings("unchecked")
4343
private static Class<? extends Widget> getConvenientClass(Class<? extends Widget> declaredClass,
4444
AnnotatedElement annotatedElement, String method) {

src/main/java/io/appium/java_client/pagefactory/ThrowableUtil.java

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

1717
package io.appium.java_client.pagefactory;
1818

19-
import lombok.AccessLevel;
20-
import lombok.NoArgsConstructor;
2119
import org.openqa.selenium.InvalidSelectorException;
2220
import org.openqa.selenium.StaleElementReferenceException;
2321

2422
import java.lang.reflect.InvocationTargetException;
2523

26-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2724
class ThrowableUtil {
2825
private static final String INVALID_SELECTOR_PATTERN = "Invalid locator strategy:";
2926

27+
private ThrowableUtil() {
28+
}
29+
3030
protected static boolean isInvalidSelectorRootCause(Throwable e) {
3131
if (e == null) {
3232
return false;

src/main/java/io/appium/java_client/pagefactory/WidgetInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected Object getObject(WebElement element, Method method, Object[] args) thr
6767
ContentType type = getCurrentContentType(element);
6868
WebElement cachedElement = cachedElementReference == null ? null : cachedElementReference.get();
6969
if (cachedElement == null || !cachedInstances.containsKey(type)
70-
|| (locator != null && !((CacheableLocator) locator).isLookUpCached())
70+
|| locator != null && !((CacheableLocator) locator).isLookUpCached()
7171
) {
7272
cachedElementReference = new WeakReference<>(element);
7373

src/main/java/io/appium/java_client/pagefactory/WidgetListInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected Object getObject(List<WebElement> elements, Method method, Object[] ar
7171
.filter(Objects::nonNull)
7272
.collect(Collectors.toList());
7373
if (cachedElements.size() != cachedWidgets.size()
74-
|| (locator != null && !((CacheableLocator) locator).isLookUpCached())) {
74+
|| locator != null && !((CacheableLocator) locator).isLookUpCached()) {
7575
cachedWidgets.clear();
7676
cachedElementReferences.clear();
7777

src/main/java/io/appium/java_client/pagefactory/WithTimeout.java

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

1717
package io.appium.java_client.pagefactory;
1818

19-
import lombok.AccessLevel;
20-
import lombok.NoArgsConstructor;
21-
2219
import java.lang.annotation.ElementType;
2320
import java.lang.annotation.Retention;
2421
import java.lang.annotation.RetentionPolicy;
@@ -46,8 +43,10 @@
4643
*/
4744
ChronoUnit chronoUnit();
4845

49-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
5046
class DurationBuilder {
47+
private DurationBuilder() {
48+
}
49+
5150
static Duration build(WithTimeout withTimeout) {
5251
return Duration.of(withTimeout.time(), withTimeout.chronoUnit());
5352
}

src/main/java/io/appium/java_client/pagefactory/utils/WebDriverUnpackUtility.java

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

1919
import io.appium.java_client.HasBrowserCheck;
2020
import io.appium.java_client.pagefactory.bys.ContentType;
21-
import lombok.AccessLevel;
22-
import lombok.NoArgsConstructor;
2321
import org.openqa.selenium.ContextAware;
2422
import org.openqa.selenium.SearchContext;
2523
import org.openqa.selenium.WebDriver;
@@ -33,10 +31,12 @@
3331
import static java.util.Optional.ofNullable;
3432
import static org.apache.commons.lang3.StringUtils.containsIgnoreCase;
3533

36-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3734
public final class WebDriverUnpackUtility {
3835
private static final String NATIVE_APP_PATTERN = "NATIVE_APP";
3936

37+
private WebDriverUnpackUtility() {
38+
}
39+
4040
/**
4141
* This method extract an instance of {@link WebDriver} from the given {@link SearchContext}.
4242
* @param searchContext is an instance of {@link SearchContext}. It may be the instance of

src/main/java/io/appium/java_client/proxy/Interceptor.java

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

1717
package io.appium.java_client.proxy;
1818

19-
import lombok.AccessLevel;
20-
import lombok.NoArgsConstructor;
2119
import net.bytebuddy.implementation.bind.annotation.AllArguments;
2220
import net.bytebuddy.implementation.bind.annotation.Origin;
2321
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
@@ -31,9 +29,11 @@
3129
import java.util.UUID;
3230
import java.util.concurrent.Callable;
3331

34-
@NoArgsConstructor(access = AccessLevel.PRIVATE)
3532
public class Interceptor {
36-
private static final Logger logger = LoggerFactory.getLogger(Interceptor.class);
33+
private static final Logger LOGGER = LoggerFactory.getLogger(Interceptor.class);
34+
35+
private Interceptor() {
36+
}
3737

3838
/**
3939
* A magic method used to wrap public method calls in classes
@@ -64,7 +64,7 @@ public static Object intercept(
6464
} catch (NotImplementedException e) {
6565
// ignore
6666
} catch (Exception e) {
67-
logger.atError()
67+
LOGGER.atError()
6868
.addArgument(() -> self.getClass().getName())
6969
.addArgument(method::getName)
7070
.log("Got an unexpected error in beforeCall listener of {}.{} method", e);
@@ -110,7 +110,7 @@ public static Object intercept(
110110
} catch (NotImplementedException e) {
111111
// ignore
112112
} catch (Exception e) {
113-
logger.atError()
113+
LOGGER.atError()
114114
.addArgument(() -> self.getClass().getName())
115115
.addArgument(method::getName)
116116
.log("Got an unexpected error in afterCall listener of {}.{} method", e);

0 commit comments

Comments
 (0)