Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6947699

Browse files
authored
Merge pull request HtmlUnit#824 from csware/directly-call-log
Directly call logging methods for static strings
2 parents 00a8920 + 7ff5343 commit 6947699

18 files changed

+44
-121
lines changed

src/main/java/org/htmlunit/TopLevelWindow.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ public void close(final boolean ignoreOnbeforeunloadAccepted) {
127127
final HtmlPage htmlPage = (HtmlPage) page;
128128
final boolean accepted = ignoreOnbeforeunloadAccepted || htmlPage.isOnbeforeunloadAccepted();
129129
if (!accepted) {
130-
if (LOG.isDebugEnabled()) {
131-
LOG.debug("The registered OnbeforeunloadHandler rejected the window close event.");
132-
}
130+
LOG.debug("The registered OnbeforeunloadHandler rejected the window close event.");
133131
rejected = true;
134132
}
135133
}

src/main/java/org/htmlunit/WaitingRefreshHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ public void handleRefresh(final Page page, final URL url, final int requestedWai
8181
* ignore it since this is the thread now doing the navigation. Eventually we should
8282
* refactor to force all navigation to happen back on the main thread.
8383
*/
84-
if (LOG.isDebugEnabled()) {
85-
LOG.debug("Waiting thread was interrupted. Ignoring interruption to continue navigation.");
86-
}
84+
LOG.debug("Waiting thread was interrupted. Ignoring interruption to continue navigation.");
8785

8886
// restore interrupted status
8987
Thread.currentThread().interrupt();

src/main/java/org/htmlunit/WebClient.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,7 @@ <P extends Page> P getPage(final WebWindow webWindow, final WebRequest webReques
429429
if (page.isHtmlPage()) {
430430
final HtmlPage htmlPage = (HtmlPage) page;
431431
if (!htmlPage.isOnbeforeunloadAccepted()) {
432-
if (LOG.isDebugEnabled()) {
433-
LOG.debug("The registered OnbeforeunloadHandler rejected to load a new page.");
434-
}
432+
LOG.debug("The registered OnbeforeunloadHandler rejected to load a new page.");
435433
return (P) page;
436434
}
437435
}

src/main/java/org/htmlunit/WebWindowImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ public void addChildWindow(final WebWindowImpl child) {
219219
* Destroy our children.
220220
*/
221221
protected void destroyChildren() {
222-
if (LOG.isDebugEnabled()) {
223-
LOG.debug("destroyChildren");
224-
}
222+
LOG.debug("destroyChildren");
225223
getJobManager().removeAllJobs();
226224

227225
// try to deal with js thread adding a new window in between

src/main/java/org/htmlunit/css/CssStyleSheet.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,7 @@ private static boolean isActive(final MediaQuery mediaQuery, final WebWindow web
13491349
case "orientation":
13501350
final CSSValueImpl cssValue = property.getValue();
13511351
if (cssValue == null) {
1352-
if (LOG.isWarnEnabled()) {
1353-
LOG.warn("CSSValue is null not supported for feature 'orientation'");
1354-
}
1352+
LOG.warn("CSSValue is null not supported for feature 'orientation'");
13551353
return true;
13561354
}
13571355

@@ -1392,10 +1390,8 @@ else if ("print".equalsIgnoreCase(mediaType)) {
13921390
@SuppressWarnings("PMD.UselessParentheses")
13931391
private static double pixelValue(final CSSValueImpl cssValue, final WebWindow webWindow) {
13941392
if (cssValue == null) {
1395-
if (LOG.isWarnEnabled()) {
1396-
LOG.warn("CSSValue is null but has to be a 'px', 'em', '%', 'ex', 'ch', "
1397-
+ "'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.");
1398-
}
1393+
LOG.warn("CSSValue is null but has to be a 'px', 'em', '%', 'ex', 'ch', "
1394+
+ "'vw', 'vh', 'vmin', 'vmax', 'rem', 'mm', 'cm', 'Q', or 'pt' value.");
13991395
return -1;
14001396
}
14011397

@@ -1460,9 +1456,7 @@ private static double pixelValue(final CSSValueImpl cssValue, final WebWindow we
14601456

14611457
private static double resolutionValue(final CSSValueImpl cssValue) {
14621458
if (cssValue == null) {
1463-
if (LOG.isWarnEnabled()) {
1464-
LOG.warn("CSSValue is null but has to be a 'dpi', 'dpcm', or 'dppx' value.");
1465-
}
1459+
LOG.warn("CSSValue is null but has to be a 'dpi', 'dpcm', or 'dppx' value.");
14661460
return -1;
14671461
}
14681462

src/main/java/org/htmlunit/html/DomElement.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,18 +1222,14 @@ public <P extends Page> P dblClick(final boolean shiftKey, final boolean ctrlKey
12221222
// call click event first
12231223
P clickPage = click(shiftKey, ctrlKey, altKey);
12241224
if (clickPage != getPage()) {
1225-
if (LOG.isDebugEnabled()) {
1226-
LOG.debug("dblClick() is ignored, as click() loaded a different page.");
1227-
}
1225+
LOG.debug("dblClick() is ignored, as click() loaded a different page.");
12281226
return clickPage;
12291227
}
12301228

12311229
// call click event a second time
12321230
clickPage = click(shiftKey, ctrlKey, altKey);
12331231
if (clickPage != getPage()) {
1234-
if (LOG.isDebugEnabled()) {
1235-
LOG.debug("dblClick() is ignored, as click() loaded a different page.");
1236-
}
1232+
LOG.debug("dblClick() is ignored, as click() loaded a different page.");
12371233
return clickPage;
12381234
}
12391235

@@ -1407,17 +1403,13 @@ public Page rightClick() {
14071403
public Page rightClick(final boolean shiftKey, final boolean ctrlKey, final boolean altKey) {
14081404
final Page mouseDownPage = mouseDown(shiftKey, ctrlKey, altKey, MouseEvent.BUTTON_RIGHT);
14091405
if (mouseDownPage != getPage()) {
1410-
if (LOG.isDebugEnabled()) {
1411-
LOG.debug("rightClick() is incomplete, as mouseDown() loaded a different page.");
1412-
}
1406+
LOG.debug("rightClick() is incomplete, as mouseDown() loaded a different page.");
14131407
return mouseDownPage;
14141408
}
14151409

14161410
final Page mouseUpPage = mouseUp(shiftKey, ctrlKey, altKey, MouseEvent.BUTTON_RIGHT);
14171411
if (mouseUpPage != getPage()) {
1418-
if (LOG.isDebugEnabled()) {
1419-
LOG.debug("rightClick() is incomplete, as mouseUp() loaded a different page.");
1420-
}
1412+
LOG.debug("rightClick() is incomplete, as mouseUp() loaded a different page.");
14211413
return mouseUpPage;
14221414
}
14231415

src/main/java/org/htmlunit/html/HtmlButton.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ public NameValuePair[] getSubmitNameValuePairs() {
156156
*/
157157
@Override
158158
public void reset() {
159-
if (LOG.isDebugEnabled()) {
160-
LOG.debug("reset() not implemented for this element");
161-
}
159+
LOG.debug("reset() not implemented for this element");
162160
}
163161

164162
/**
@@ -168,9 +166,7 @@ public void reset() {
168166
*/
169167
@Override
170168
public void setDefaultValue(final String defaultValue) {
171-
if (LOG.isDebugEnabled()) {
172-
LOG.debug("setDefaultValue() not implemented for this element");
173-
}
169+
LOG.debug("setDefaultValue() not implemented for this element");
174170
}
175171

176172
/**
@@ -180,9 +176,7 @@ public void setDefaultValue(final String defaultValue) {
180176
*/
181177
@Override
182178
public String getDefaultValue() {
183-
if (LOG.isDebugEnabled()) {
184-
LOG.debug("getDefaultValue() not implemented for this element");
185-
}
179+
LOG.debug("getDefaultValue() not implemented for this element");
186180
return "";
187181
}
188182

src/main/java/org/htmlunit/html/HtmlPage.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,7 @@ public String getTitleText() {
11551155
public void setTitleText(final String message) {
11561156
HtmlTitle titleElement = getTitleElement();
11571157
if (titleElement == null) {
1158-
if (LOG.isDebugEnabled()) {
1159-
LOG.debug("No title element, creating one");
1160-
}
1158+
LOG.debug("No title element, creating one");
11611159
final HtmlHead head = (HtmlHead) getFirstChildElement(getDocumentElement(), HtmlHead.class);
11621160
if (head == null) {
11631161
// perhaps should we create head too?
@@ -1333,10 +1331,8 @@ private boolean isOnbeforeunloadAccepted(final HtmlPage page, final Event event)
13331331
if (beforeUnloadEvent.isBeforeUnloadMessageSet()) {
13341332
final OnbeforeunloadHandler handler = getWebClient().getOnbeforeunloadHandler();
13351333
if (handler == null) {
1336-
if (LOG.isWarnEnabled()) {
1337-
LOG.warn("document.onbeforeunload() returned a string in event.returnValue,"
1338-
+ " but no onbeforeunload handler installed.");
1339-
}
1334+
LOG.warn("document.onbeforeunload() returned a string in event.returnValue,"
1335+
+ " but no onbeforeunload handler installed.");
13401336
}
13411337
else {
13421338
final String message = JavaScriptEngine.toString(beforeUnloadEvent.getReturnValue());

src/main/java/org/htmlunit/html/ScriptElementSupport.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ public static void onAllChildrenAddedToPage(final DomElement element, final bool
7575
}
7676

7777
if (!element.getPage().getWebClient().isJavaScriptEngineEnabled()) {
78-
if (LOG.isDebugEnabled()) {
79-
LOG.debug("Script found but not executed because javascript engine is disabled");
80-
}
78+
LOG.debug("Script found but not executed because javascript engine is disabled");
8179
return;
8280
}
8381

src/main/java/org/htmlunit/javascript/DefaultJavaScriptErrorListener.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public class DefaultJavaScriptErrorListener implements JavaScriptErrorListener,
3838
*/
3939
@Override
4040
public void scriptException(final HtmlPage page, final ScriptException scriptException) {
41-
if (LOG.isErrorEnabled()) {
42-
LOG.error("Error during JavaScript execution", scriptException);
43-
}
41+
LOG.error("Error during JavaScript execution", scriptException);
4442
}
4543

4644
/**

0 commit comments

Comments
 (0)