Skip to content

Commit 7b221c1

Browse files
authored
Checkstyle: use SuppressWarnings instead of inline comments (#10182)
SuppressWarnings makes it easier to see which warnings are actually suppressed and removes the need for on/off toggles that might get mismatched. Moved out of #10176
1 parent e447217 commit 7b221c1

File tree

33 files changed

+76
-192
lines changed

33 files changed

+76
-192
lines changed

dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ protected String fillSelectionScriptTemplate(StringBuffer ss, TreeLogger logger,
118118
}
119119
}
120120
if (failIfScriptTags) {
121-
// CHECKSTYLE_OFF
122121
String msg =
123122
"The " + getDescription()
124123
+ " linker does not support <script> tags in the gwt.xml files, but the"
@@ -129,7 +128,6 @@ protected String fillSelectionScriptTemplate(StringBuffer ss, TreeLogger logger,
129128
+ " this error, you will need to remove the script tags from the"
130129
+ " gwt.xml file, or add this property to the gwt.xml file:"
131130
+ " <set-configuration-property name='xsiframe.failIfScriptTag' value='FALSE'/>";
132-
// CHECKSTYLE_ON
133131
logger.log(TreeLogger.ERROR, msg);
134132
throw new UnableToCompleteException();
135133
} else {
@@ -436,13 +434,15 @@ protected String getModulePrefix(TreeLogger logger, LinkerContext context, Strin
436434
out.print("function __gwtStartLoadingFragment(frag) {");
437435
out.newlineOpt();
438436
String fragDir = getFragmentSubdir(logger, context) + '/';
439-
out.print("var fragFile = '" + fragDir + "' + $strongName + '/' + frag + '" + FRAGMENT_EXTENSION + "';");
437+
out.print("var fragFile = '" + fragDir + "' + $strongName + '/' + frag + '"
438+
+ FRAGMENT_EXTENSION + "';");
440439
out.newlineOpt();
441440
out.print("return __gwtModuleFunction.__startLoadingFragment(fragFile);");
442441
out.newlineOpt();
443442
out.print("}");
444443
out.newlineOpt();
445-
out.print("function __gwtInstallCode(code) {return __gwtModuleFunction.__installRunAsyncCode(code);}");
444+
out.print("function __gwtInstallCode(code) {"
445+
+ "return __gwtModuleFunction.__installRunAsyncCode(code);}");
446446
out.newlineOpt();
447447

448448
// The functions for property access are set up in the bootstrap script however
@@ -617,9 +617,9 @@ protected void maybeOutputPropertyMap(TreeLogger logger, LinkerContext context,
617617
EmittedArtifact serializedMap;
618618
try {
619619
String mappings = mappingArtifact.getSerialized();
620-
// CHECKSTYLE_OFF
621-
mappings = mappings.concat("Devmode:" + getHostedFilename());
622-
// CHECKSTYLE_ON
620+
@SuppressWarnings("checkstyle:SpaceAfterColon")
621+
String str = "Devmode:" + getHostedFilename();
622+
mappings = mappings.concat(str);
623623
serializedMap = emitString(logger, mappings, "compilation-mappings.txt");
624624
// TODO(unnurg): make this Deploy
625625
serializedMap.setVisibility(Visibility.Public);
@@ -682,7 +682,6 @@ protected String wrapPrimaryFragment(TreeLogger logger, LinkerContext context, S
682682
out.append("if (" + context.getModuleFunctionName() + ".succeeded) {\n");
683683
}
684684

685-
686685
if (shouldInstallCode(context)) {
687686
// Rewrite the code so it can be installed with
688687
// __MODULE_FUNC__.onScriptDownloaded

dev/core/src/com/google/gwt/dev/cfg/ModuleDefSchema.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@
4343

4444
import javax.lang.model.SourceVersion;
4545

46-
// CHECKSTYLE_NAMING_OFF
47-
4846
/**
4947
* Configures a module definition object using XML.
5048
*/
49+
@SuppressWarnings({"checkstyle:MemberName", "checkstyle:MethodName"})
5150
public class ModuleDefSchema extends Schema {
5251

5352
private final class BodySchema extends Schema {
@@ -299,7 +298,7 @@ protected Schema __collapse_property_begin(PropertyName name,
299298
return null;
300299
}
301300

302-
@SuppressWarnings("unused") // called reflectively
301+
@SuppressWarnings({"unused", "checkstyle:ParameterName"}) // called reflectively
303302
protected Schema __define_configuration_property_begin(PropertyName name,
304303
String is_multi_valued) throws UnableToCompleteException {
305304
boolean isMultiValued = toPrimitiveBoolean(is_multi_valued);
@@ -1513,4 +1512,3 @@ private JsFunction parseJsBlock(int startLineNumber, String script)
15131512
return fn;
15141513
}
15151514
}
1516-
// CHECKSTYLE_NAMING_ON

dev/core/src/com/google/gwt/dev/jjs/impl/MethodInliner.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,8 @@ private InlineResult tryInlineBody(JMethodCall x, Context ctx,
439439
return InlineResult.DO_NOT_BLACKLIST;
440440
}
441441
}
442-
// CHECKSTYLE_OFF: Fall through!
442+
// fall through!
443443
case CORRECT_ORDER:
444-
// CHECKSTYLE_ON
445444
default:
446445
if (!x.hasSideEffects()) {
447446
markCallsAsSideEffectFree(bodyAsExpressionList);

dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
/**
8585
* Produces text output from a JavaScript AST.
8686
*/
87+
@SuppressWarnings("checkstyle:MethodName")
8788
public class JsToStringGenerationVisitor extends JsVisitor {
8889

8990
private static final char[] CHARS_BREAK = "break".toCharArray();
@@ -888,8 +889,6 @@ public boolean visit(JsWhile x, JsContext ctx) {
888889
return false;
889890
}
890891

891-
//CHECKSTYLE_NAMING_OFF
892-
893892
protected void _newline() {
894893
p.newline();
895894
}
@@ -1308,8 +1307,6 @@ private void _while() {
13081307
p.print(CHARS_WHILE);
13091308
}
13101309

1311-
// CHECKSTYLE_NAMING_ON
1312-
13131310
private void indent() {
13141311
p.indentIn();
13151312
}

dev/core/src/com/google/gwt/soyc/MakeTopLevelHtmlForPerm.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ private void printInternedDataAsJs(PrintWriter outFile) {
376376
+ "See why it's live</a></li>\");");
377377
outFile.println(" for (var sp = 1; sp <= "
378378
+ globalInformation.getNumFragments() + "; sp++) {");
379-
outFile.println(" var d2 = 'methodDependencies-sp' + sp + '-" + getPermutationId() + ".html';");
379+
outFile.println(" var d2 = 'methodDependencies-sp' + sp + '-"
380+
+ getPermutationId() + ".html';");
380381
outFile.println(" document.write(\"<li><a href='\" + d2 + \"#\" + className +\"'>"
381382
+ " See why it's not exclusive to s.p. #\" + sp + \" (\" + spl[sp - 1] + \")"
382383
+ "</a></li>\");");
@@ -786,10 +787,7 @@ public void makeCodeTypeClassesHtmls(SizeBreakdown breakdown)
786787
outFile.println("<td>" + className + "</a></td>");
787788
outFile.println("<td class=\"soyc-bargraph-col\">");
788789
outFile.println("<div class=\"soyc-bar-graph goog-inline-block\">");
789-
// CHECKSTYLE_OFF
790-
outFile.println("<div style=\"width:" + (perc * 100.0)
791-
+ "%;\" class=\"soyc-bar-graph-fill goog-inline-block\"></div>");
792-
// CHECKSTYLE_ON
790+
outFile.println(getProgressBarHtml(perc));
793791
outFile.println("</div>");
794792
outFile.println("</td>");
795793
outFile.println("<td class=\"soyc-numerical-col\">");
@@ -1137,10 +1135,7 @@ public void makePackageClassesHtmls(SizeBreakdown breakdown,
11371135
}
11381136
outFile.println("<td class=\"soyc-bargraph-col\">");
11391137
outFile.println("<div class=\"soyc-bar-graph goog-inline-block\">");
1140-
// CHECKSTYLE_OFF
1141-
outFile.println("<div style=\"width:" + (perc * 100.0)
1142-
+ "%;\" class=\"soyc-bar-graph-fill goog-inline-block\"></div>");
1143-
// CHECKSTYLE_ON
1138+
outFile.println(getProgressBarHtml(perc));
11441139
outFile.println("</div>");
11451140
outFile.println("</td>");
11461141
outFile.println("<td class=\"soyc-numerical-col\">");
@@ -1314,10 +1309,7 @@ public void makeTopLevelShell() throws IOException {
13141309
+ "</a></td>");
13151310
outFile.println("<td class=\"soyc-bargraph-col\">");
13161311
outFile.println("<div class=\"soyc-bar-graph goog-inline-block\">");
1317-
// CHECKSTYLE_OFF
1318-
outFile.println("<div style=\"width:" + (perc * 100.0)
1319-
+ "%;\" class=\"soyc-bar-graph-fill goog-inline-block\"></div>");
1320-
// CHECKSTYLE_ON
1312+
outFile.println(getProgressBarHtml(perc));
13211313
outFile.println("</div>");
13221314
outFile.println("</td>");
13231315
outFile.println("<td class=\"soyc-numerical-col\">");
@@ -1335,6 +1327,12 @@ public void makeTopLevelShell() throws IOException {
13351327
outFile.close();
13361328
}
13371329

1330+
@SuppressWarnings("checkstyle:SpaceAfterColon")
1331+
private String getProgressBarHtml(float perc) {
1332+
return "<div style=\"width:" + (perc * 100.0)
1333+
+ "%;\" class=\"soyc-bar-graph-fill goog-inline-block\"></div>";
1334+
}
1335+
13381336
private void addPopup(PrintWriter outFile, String popupName,
13391337
String popupTitle, String popupBody) {
13401338
outFile.println("<div class=\"soyc-popup\" id=\"" + popupName + "\">");
@@ -1391,7 +1389,8 @@ private String getPermutationId() {
13911389
private String[] getUnreferencedTypes(
13921390
PrecompilationMetricsArtifact precompilationMetrics) {
13931391
List<String> astTypes = Lists.newArrayList(precompilationMetrics.getAstTypes());
1394-
Set<String> unreferencedTypes = Sets.newHashSet(precompilationMetrics.getFinalTypeOracleTypes());
1392+
Set<String> unreferencedTypes = Sets.newHashSet(
1393+
precompilationMetrics.getFinalTypeOracleTypes());
13951394
unreferencedTypes.removeAll(astTypes);
13961395
String[] results = unreferencedTypes.toArray(new String[unreferencedTypes.size()]);
13971396
Arrays.sort(results);
@@ -1515,10 +1514,7 @@ private String makeCodeTypeHtml(SizeBreakdown breakdown,
15151514
+ "\" target=\"_top\">" + codeType + "</a></td>");
15161515
outFile.println("<td class=\"soyc-bargraph-col\">");
15171516
outFile.println("<div class=\"soyc-bar-graph goog-inline-block\">");
1518-
// CHECKSTYLE_OFF
1519-
outFile.println("<div style=\"width:" + (perc * 100.0)
1520-
+ "%;\" class=\"soyc-bar-graph-fill goog-inline-block\"></div>");
1521-
// CHECKSTYLE_ON
1517+
outFile.println(getProgressBarHtml(perc));
15221518
outFile.println("</div>");
15231519
outFile.println("</td>");
15241520
outFile.println("<td class=\"soyc-numerical-col\">");
@@ -1814,10 +1810,7 @@ private String makePackageHtml(SizeBreakdown breakdown) throws IOException {
18141810
+ "\" target=\"_top\">" + packageName + "</a></td>");
18151811
outFile.println("<td class=\"soyc-bargraph-col\">");
18161812
outFile.println("<div class=\"soyc-bar-graph goog-inline-block\">");
1817-
// CHECKSTYLE_OFF
1818-
outFile.println("<div style=\"width:" + (perc * 100.0)
1819-
+ "%;\" class=\"soyc-bar-graph-fill goog-inline-block\"></div>");
1820-
// CHECKSTYLE_ON
1813+
outFile.println(getProgressBarHtml(perc));
18211814
outFile.println("</div>");
18221815
outFile.println("</td>");
18231816
outFile.println("<td class=\"soyc-numerical-col\">");

dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Cast.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121

2222
import javaemul.internal.annotations.HasNoSideEffects;
2323

24-
// CHECKSTYLE_NAMING_OFF: Uses legacy conventions of underscore prefixes.
25-
2624
/**
2725
* This is a magic class the compiler uses to perform any cast operations that require code.<br />
2826
*
2927
* The cast operations are only as accurate as the contents of the castableTypeMaps and should not
3028
* be used directly by user code. The compiler takes care to record most cast operations in user
3129
* code so that it can build limited but accurate castableTypeMaps.
3230
*/
31+
@SuppressWarnings("checkstyle:MethodName")
3332
final class Cast {
3433

3534
/**
@@ -393,5 +392,3 @@ static native Class<?> getClass(Object array) /*-{
393392
|| @JavaScriptObject::class;
394393
}-*/;
395394
}
396-
397-
// CHECKSTYLE_NAMING_ON

dev/core/super/com/google/gwt/dev/jjs/intrinsic/com/google/gwt/lang/Exceptions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/**
2424
* This is a magic class the compiler uses to throw and check exceptions.
2525
*/
26+
@SuppressWarnings("checkstyle:MethodName")
2627
final class Exceptions {
2728

2829
@DoNotInline // This frame can be useful in understanding the native stack
@@ -59,7 +60,6 @@ static AssertionError makeAssertionError() {
5960
* We use nonstandard naming here so it's easy for the compiler to map to
6061
* method names based on primitive type name.
6162
*/
62-
// CHECKSTYLE_OFF
6363
static AssertionError makeAssertionError_boolean(boolean message) {
6464
return new AssertionError(message);
6565
}
@@ -131,5 +131,4 @@ static Throwable safeClose(AutoCloseable resource, Throwable mainException) {
131131
}
132132
return mainException;
133133
}
134-
// CHECKSTYLE_ON
135134
}

eclipse/settings/code-style/gwt-checkstyle-tests.xml

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ A more lenient set of style checks for test cases, needed because test often nee
1111
<module name="Checker">
1212
<property name="severity" value="warning"/>
1313
<module name="RegexpHeader">
14-
<property name="fileExtensions" value="java"/>
14+
<property name="fileExtensions" value="java"/>
1515
<property name="severity" value="error"/>
1616
<property name="header" value="^/\*[ ]*$\n^ \* Copyright 20(0[6789]|[12][0-9]) (Google Inc\.|GWT Project Authors)$\n^ \*[ ]*$\n^ \* Licensed under the Apache License, Version 2\.0 \(the &quot;License&quot;\); you may not( use this file except)?$\n^ \* (use this file except )?in compliance with the License\. You may obtain a copy of( the License at)?$\n^ \* the License at$\n^ \*[ ]*$\n^ \* http://www\.apache\.org/licenses/LICENSE-2\.0$\n^ \*[ ]*\n \* Unless required by applicable law or agreed to in writing, software( distributed under the License)?$\n^ \* (distributed under the License )?is distributed on an &quot;AS IS&quot; BASIS, WITHOUT( WARRANTIES OR CONDITIONS OF ANY KIND, either express)?$\n^ \* (WARRANTIES OR CONDITIONS OF ANY KIND, either express )?or implied\. See the( License for the specific language governing permissions and limitations under)?$\n^ \* License for the specific language governing permissions and limitations under$\n^ \* the License\.$\n^ \*/$"/>
1717
<property name="multiLines" value="6,13"/>
@@ -22,7 +22,8 @@ A more lenient set of style checks for test cases, needed because test often nee
2222
<property name="severity" value="error"/>
2323
</module>
2424
<module name="TreeWalker">
25-
<property name="fileExtensions" value="java"/>
25+
<property name="fileExtensions" value="java"/>
26+
<module name="SuppressWarningsHolder" />
2627
<module name="InterfaceIsType">
2728
<metadata name="com.atlassw.tools.eclipse.checkstyle.lastEnabledSeverity" value="error"/>
2829
<property name="severity" value="ignore"/>
@@ -53,7 +54,7 @@ A more lenient set of style checks for test cases, needed because test often nee
5354
<module name="LocalVariableName">
5455
<metadata name="com.atlassw.tools.eclipse.checkstyle.lastEnabledSeverity" value="error"/>
5556
<property name="severity" value="ignore"/>
56-
<property name="tokens" value="PARAMETER_DEF,VARIABLE_DEF"/>
57+
<property name="tokens" value="VARIABLE_DEF"/>
5758
</module>
5859
<module name="LeftCurly"/>
5960
<module name="RightCurly"/>
@@ -119,13 +120,6 @@ A more lenient set of style checks for test cases, needed because test often nee
119120
<property name="severity" value="ignore"/>
120121
<property name="classes" value="Boolean"/>
121122
</module>
122-
<module name="Regexp">
123-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="check that a space is left after a colon with an assembled error message"/>
124-
<property name="severity" value="info"/>
125-
<property name="format" value="[^:^&quot;]:&quot; .*+"/>
126-
<property name="message" value="check that a space is left after a colon on an assembled error message"/>
127-
<property name="illegalPattern" value="true"/>
128-
</module>
129123
<module name="Regexp">
130124
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="more than one blank line"/>
131125
<property name="severity" value="info"/>
@@ -211,24 +205,6 @@ A more lenient set of style checks for test cases, needed because test often nee
211205
</module>
212206
<module name="RedundantModifier"/>
213207
<module name="EqualsHashCode"/>
214-
<module name="SuppressionCommentFilter">
215-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/>
216-
<property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/>
217-
<property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/>
218-
<property name="checkFormat" value="MethodName"/>
219-
</module>
220-
<module name="SuppressionCommentFilter">
221-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/>
222-
<property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/>
223-
<property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/>
224-
<property name="checkFormat" value="MemberName"/>
225-
</module>
226-
<module name="SuppressionCommentFilter">
227-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/>
228-
<property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/>
229-
<property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/>
230-
<property name="checkFormat" value="ParameterName"/>
231-
</module>
232208
</module>
233209
<module name="SuppressWithPlainTextCommentFilter">
234210
<property name="offCommentFormat" value="CHECKSTYLE_OFF"/>
@@ -237,4 +213,5 @@ A more lenient set of style checks for test cases, needed because test often nee
237213
<module name="JavadocPackage">
238214
<property name="severity" value="ignore"/>
239215
</module>
216+
<module name="SuppressWarningsFilter" />
240217
</module>

eclipse/settings/code-style/gwt-checkstyle.xml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Description:
2727
</module>
2828
<module name="TreeWalker">
2929
<property name="fileExtensions" value="java"/>
30-
<module name="InterfaceIsType">
30+
<module name="SuppressWarningsHolder" />
31+
<module name="InterfaceIsType">
3132
<property name="severity" value="ignore"/>
3233
</module>
3334
<module name="RedundantImport">
@@ -115,6 +116,8 @@ Description:
115116
<module name="Regexp">
116117
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="check that a space is left after a colon with an assembled error message"/>
117118
<property name="severity" value="info"/>
119+
<property name="id" value="SpaceAfterColon"/>
120+
<property name="ignoreComments" value="true"/>
118121
<property name="format" value="[^:^&quot;]:&quot; .*+"/>
119122
<property name="message" value="check that a space is left after a colon on an assembled error message"/>
120123
<property name="illegalPattern" value="true"/>
@@ -195,25 +198,6 @@ Description:
195198
</module>
196199
<module name="RedundantModifier"/>
197200
<module name="EqualsHashCode"/>
198-
199-
<module name="SuppressionCommentFilter">
200-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/>
201-
<property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/>
202-
<property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/>
203-
<property name="checkFormat" value="MethodName"/>
204-
</module>
205-
<module name="SuppressionCommentFilter">
206-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/>
207-
<property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/>
208-
<property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/>
209-
<property name="checkFormat" value="MemberName"/>
210-
</module>
211-
<module name="SuppressionCommentFilter">
212-
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Avoid name checking"/>
213-
<property name="offCommentFormat" value="CHECKSTYLE_NAMING_OFF"/>
214-
<property name="onCommentFormat" value="CHECKSTYLE_NAMING_ON"/>
215-
<property name="checkFormat" value="ParameterName"/>
216-
</module>
217201
</module>
218202
<module name="SuppressWithPlainTextCommentFilter">
219203
<property name="offCommentFormat" value="CHECKSTYLE_OFF"/>
@@ -222,4 +206,5 @@ Description:
222206
<module name="JavadocPackage">
223207
<property name="severity" value="ignore"/>
224208
</module>
209+
<module name="SuppressWarningsFilter" />
225210
</module>

samples/dynatablerf/src/main/java/com/google/gwt/sample/dynatablerf/client/widgets/ZipPlusFourBox.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@ public String parse(CharSequence text) throws ParseException {
5252
switch (text.length()) {
5353
case 9:
5454
text = text.subSequence(0, 5) + "-" + text.subSequence(5, 9);
55-
// Fall-though intentional
56-
// CHECKSTYLE_OFF
55+
/* fall-through intentional */
5756
case 5:
58-
// Fall-through intentional
5957
case 10:
60-
// CHECKSTYLE_ON
6158
if (PATTERN.test(text.toString())) {
6259
return text.toString();
6360
} else {

0 commit comments

Comments
 (0)