Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69bb6bd

Browse files
blicklycopybara-github
authored andcommitted
Change statement switches to expression switches where possible
PiperOrigin-RevId: 819230432
1 parent c294bcd commit 69bb6bd

22 files changed

+414
-528
lines changed

‎src/com/google/debugging/sourcemap/SourceMapConsumerFactory.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ public static SourceMapping parse(String contents, @Nullable SourceMapSupplier s
4848

4949
// Check basic assertions about the format.
5050
switch (sourceMapObject.getVersion()) {
51-
case 3: {
52-
SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
51+
case 3 -> {
52+
SourceMapConsumerV3 consumer = new SourceMapConsumerV3();
5353
consumer.parse(sourceMapObject, supplier);
5454
return consumer;
5555
}
56-
default:
57-
throw new SourceMapParseException(
58-
"Unknown source map version:" + sourceMapObject.getVersion());
56+
default ->
57+
throw new SourceMapParseException(
58+
"Unknown source map version:" + sourceMapObject.getVersion());
5959
}
6060
}
6161

‎src/com/google/debugging/sourcemap/Util.java‎

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,13 @@ void appendForEscapedChar(String escaped) {
7474
for (int i = 0; i < length; i++) {
7575
char c = s.charAt(i);
7676
switch (c) {
77-
case '\n':
78-
region.appendForEscapedChar("\\n");
79-
break;
80-
case '\r':
81-
region.appendForEscapedChar("\\r");
82-
break;
83-
case '\t':
84-
region.appendForEscapedChar("\\t");
85-
break;
86-
case '\\':
87-
region.appendForEscapedChar(backslashEscape);
88-
break;
89-
case '\"':
90-
region.appendForEscapedChar(doublequoteEscape);
91-
break;
92-
case '\'':
93-
region.appendForEscapedChar(singlequoteEscape);
94-
break;
95-
case '>':
77+
case '\n' -> region.appendForEscapedChar("\\n");
78+
case '\r' -> region.appendForEscapedChar("\\r");
79+
case '\t' -> region.appendForEscapedChar("\\t");
80+
case '\\' -> region.appendForEscapedChar(backslashEscape);
81+
case '\"' -> region.appendForEscapedChar(doublequoteEscape);
82+
case '\'' -> region.appendForEscapedChar(singlequoteEscape);
83+
case '>' -> {
9684
// Unicode-escape the '>' in '-->' and ']]>'
9785
if (i >= 2
9886
&& ((s.charAt(i - 1) == '-' && s.charAt(i - 2) == '-')
@@ -101,23 +89,21 @@ void appendForEscapedChar(String escaped) {
10189
} else {
10290
region.incrementForNormalChar();
10391
}
104-
break;
105-
case '<':
92+
}
93+
case '<' -> {
10694
// Unicode-escape the '<' in '</script' and '<!--'
10795
final String END_SCRIPT = "/script";
10896
final String START_COMMENT = "!--";
10997

110-
if (s.regionMatches(true, i + 1, END_SCRIPT, 0,
111-
END_SCRIPT.length())) {
98+
if (s.regionMatches(true, i + 1, END_SCRIPT, 0, END_SCRIPT.length())) {
11299
region.appendForEscapedChar("\\u003c");
113-
} else if (s.regionMatches(false, i + 1, START_COMMENT, 0,
114-
START_COMMENT.length())) {
100+
} else if (s.regionMatches(false, i + 1, START_COMMENT, 0, START_COMMENT.length())) {
115101
region.appendForEscapedChar("\\u003c");
116102
} else {
117103
region.incrementForNormalChar();
118104
}
119-
break;
120-
default:
105+
}
106+
default -> {
121107
// No charsetEncoder provided - pass straight Latin characters
122108
// through, and escape the rest. Doing the explicit character
123109
// check is measurably faster than using the CharsetEncoder.
@@ -131,6 +117,7 @@ void appendForEscapedChar(String escaped) {
131117
region.incrementForEscapedChar();
132118
appendHexJavaScriptRepresentation(sb, c);
133119
}
120+
}
134121
}
135122
}
136123
region.appendUnescaped();

‎src/com/google/javascript/jscomp/ant/AntErrorManager.java‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.javascript.jscomp.CheckLevel;
2121
import com.google.javascript.jscomp.JSError;
2222
import com.google.javascript.jscomp.MessageFormatter;
23-
2423
import org.apache.tools.ant.Project;
2524
import org.apache.tools.ant.Task;
2625

@@ -41,14 +40,9 @@ public AntErrorManager(MessageFormatter formatter, Task task) {
4140
@Override
4241
public void println(CheckLevel level, JSError error) {
4342
switch (level) {
44-
case ERROR:
45-
this.task.log(error.format(level, this.formatter), Project.MSG_ERR);
46-
break;
47-
case WARNING:
48-
this.task.log(error.format(level, this.formatter), Project.MSG_WARN);
49-
break;
50-
case OFF:
51-
break;
43+
case ERROR -> this.task.log(error.format(level, this.formatter), Project.MSG_ERR);
44+
case WARNING -> this.task.log(error.format(level, this.formatter), Project.MSG_WARN);
45+
case OFF -> {}
5246
}
5347
}
5448

‎src/com/google/javascript/jscomp/colors/Color.java‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ public static Builder singleBuilder() {
7373

7474
public static Color createUnion(Set<Color> elements) {
7575
switch (elements.size()) {
76-
case 0:
77-
throw new IllegalStateException();
78-
case 1:
76+
case 0 -> throw new IllegalStateException();
77+
case 1 -> {
7978
return Iterables.getOnlyElement(elements);
80-
default:
81-
break;
79+
}
80+
default -> {}
8281
}
8382

8483
ImmutableSet.Builder<Color> instanceColors = ImmutableSet.builder();

‎src/com/google/javascript/jscomp/deps/DepsGenerator.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,14 @@ private void validateDependencies(Iterable<DependencyInfo> preparsedFileDependen
280280
boolean providerIsEs6Module = provider.isEs6Module();
281281

282282
switch (require.getType()) {
283-
case ES6_IMPORT:
283+
case ES6_IMPORT -> {
284284
if (!providerIsEs6Module) {
285285
reportEs6ImportForNonEs6Module(provider, depInfo);
286286
}
287-
break;
288-
case GOOG_REQUIRE_SYMBOL:
289-
case PARSED_FROM_DEPS:
290-
break;
291-
case COMMON_JS:
292-
case COMPILER_MODULE:
293-
throw new IllegalStateException("Unexpected import type: " + require.getType());
287+
}
288+
case GOOG_REQUIRE_SYMBOL, PARSED_FROM_DEPS -> {}
289+
case COMMON_JS, COMPILER_MODULE ->
290+
throw new IllegalStateException("Unexpected import type: " + require.getType());
294291
}
295292
}
296293
}

‎src/com/google/javascript/jscomp/deps/JsFileFullParser.java‎

Lines changed: 30 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,16 @@ protected void printSummary() {}
222222
info.loadFlags.put("module", "goog");
223223
}
224224
switch (module.moduleType()) {
225-
case GOOG_PROVIDE:
226-
info.moduleType = FileInfo.ModuleType.GOOG_PROVIDE;
227-
break;
228-
case GOOG_MODULE:
229-
info.moduleType = FileInfo.ModuleType.GOOG_MODULE;
230-
break;
231-
case LEGACY_GOOG_MODULE:
225+
case GOOG_PROVIDE -> info.moduleType = FileInfo.ModuleType.GOOG_PROVIDE;
226+
case GOOG_MODULE -> info.moduleType = FileInfo.ModuleType.GOOG_MODULE;
227+
case LEGACY_GOOG_MODULE -> {
232228
info.moduleType = FileInfo.ModuleType.GOOG_MODULE;
233229
info.isLegacyNamespace = true;
234-
break;
235-
case ES6_MODULE:
236-
info.moduleType = FileInfo.ModuleType.ES_MODULE;
237-
break;
238-
case COMMON_JS:
239-
case SCRIPT:
240-
// Treat these as unknown for now; we can extend the enum if we care about these.
241-
info.moduleType = FileInfo.ModuleType.UNKNOWN;
242-
break;
230+
}
231+
case ES6_MODULE -> info.moduleType = FileInfo.ModuleType.ES_MODULE;
232+
case COMMON_JS, SCRIPT ->
233+
// Treat these as unknown for now; we can extend the enum if we care about these.
234+
info.moduleType = FileInfo.ModuleType.UNKNOWN;
243235
}
244236
info.goog = module.usesClosure();
245237
recordModuleMetadata(info, module);
@@ -273,70 +265,56 @@ private static void parseComment(Comment comment, FileInfo info) {
273265
boolean fileOverview = comment.value.contains("@fileoverview");
274266
for (CommentAnnotation annotation : CommentAnnotation.parse(comment.value)) {
275267
switch (annotation.name) {
276-
case "@fileoverview":
277-
case "@author":
278-
case "@see":
279-
case "@link":
280-
break;
281-
case "@mods":
268+
case "@fileoverview", "@author", "@see", "@link" -> {}
269+
case "@mods" -> {
282270
if (!annotation.value.isEmpty()) {
283271
info.mods.add(annotation.value);
284272
}
285-
break;
286-
case "@visibility":
273+
}
274+
case "@visibility" -> {
287275
if (!annotation.value.isEmpty()) {
288276
info.visibility.add(annotation.value);
289277
}
290-
break;
291-
case "@modName":
278+
}
279+
case "@modName" -> {
292280
if (!annotation.value.isEmpty()) {
293281
info.modName.add(annotation.value);
294282
}
295-
break;
296-
case "@config":
297-
info.isConfig = true;
298-
break;
299-
case "@provideGoog":
300-
info.provideGoog = true;
301-
break;
302-
case "@requirecss":
283+
}
284+
case "@config" -> info.isConfig = true;
285+
case "@provideGoog" -> info.provideGoog = true;
286+
case "@requirecss" -> {
303287
if (!annotation.value.isEmpty()) {
304288
info.requiresCss.add(annotation.value);
305289
}
306-
break;
307-
case "@deltemplate":
308-
case "@hassoydeltemplate":
290+
}
291+
case "@deltemplate", "@hassoydeltemplate" -> {
309292
// TODO(b/210468818): Remove legacy @hassoydeltemplate annotation once Soy gencode has
310293
// been updated to use the new one.
311294
if (!annotation.value.isEmpty()) {
312295
info.deltemplates.add(annotation.value);
313296
}
314-
break;
315-
case "@delcall":
316-
case "@hassoydelcall":
297+
}
298+
case "@delcall", "@hassoydelcall" -> {
317299
// TODO(b/210468818): Remove legacy @hassoydelcall annotation once Soy gencode has
318300
// been updated to use the new one.
319301
if (!annotation.value.isEmpty()) {
320302
info.delcalls.add(annotation.value);
321303
}
322-
break;
323-
case "@externs":
324-
info.isExterns = true;
325-
break;
326-
case "@enhanceable":
327-
case "@pintomodule":
328-
case "@mayhaveextraedge":
329-
info.customAnnotations.put(annotation.name.substring(1), annotation.value);
330-
break;
331-
case "@enhance":
304+
}
305+
case "@externs" -> info.isExterns = true;
306+
case "@enhanceable", "@pintomodule", "@mayhaveextraedge" ->
307+
info.customAnnotations.put(annotation.name.substring(1), annotation.value);
308+
case "@enhance" -> {
332309
if (!annotation.value.isEmpty()) {
333310
info.customAnnotations.put(annotation.name.substring(1), annotation.value);
334311
}
335-
break;
336-
default:
312+
}
313+
default -> {
337314
if (fileOverview) {
338315
info.customAnnotations.put(annotation.name.substring(1), annotation.value);
339316
}
317+
}
340318
}
341319
}
342320
}

‎src/com/google/javascript/jscomp/deps/JsFileRegexParser.java‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,11 @@ private DependencyInfo parseReader(
203203

204204
Map<String, String> loadFlags = new LinkedHashMap<>();
205205
switch (moduleType) {
206-
case GOOG_MODULE:
207-
loadFlags.put("module", "goog");
208-
break;
209-
case ES6_MODULE:
210-
loadFlags.put("module", "es6");
211-
break;
212-
default:
206+
case GOOG_MODULE -> loadFlags.put("module", "goog");
207+
case ES6_MODULE -> loadFlags.put("module", "es6");
208+
default -> {
213209
// Nothing to do here.
210+
}
214211
}
215212

216213
DependencyInfo dependencyInfo =

‎src/com/google/javascript/jscomp/disambiguate/AmbiguateProperties.java‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -375,37 +375,36 @@ private class ProcessPropertiesAndConstructors extends AbstractPostOrderCallback
375375
@Override
376376
public void visit(NodeTraversal t, Node n, Node parent) {
377377
switch (n.getToken()) {
378-
case GETPROP:
379-
case OPTCHAIN_GETPROP:
378+
case GETPROP, OPTCHAIN_GETPROP -> {
380379
processGetProp(n);
381380
return;
382-
383-
case CALL:
381+
}
382+
case CALL -> {
384383
processCall(n);
385384
return;
386-
387-
case NAME:
385+
}
386+
case NAME -> {
388387
// handle ES5-style classes
389388
if (NodeUtil.isNameDeclaration(parent) || parent.isFunction()) {
390389
graphNodeFactory.createNode(getColor(n));
391390
}
392391
return;
393-
394-
case OBJECTLIT:
395-
case OBJECT_PATTERN:
392+
}
393+
case OBJECTLIT, OBJECT_PATTERN -> {
396394
processObjectLitOrPattern(n);
397395
return;
398-
399-
case GETELEM:
396+
}
397+
case GETELEM -> {
400398
processGetElem(n);
401399
return;
402-
403-
case CLASS:
400+
}
401+
case CLASS -> {
404402
processClass(n);
405403
return;
406-
407-
default:
404+
}
405+
default -> {
408406
// Nothing to do.
407+
}
409408
}
410409
}
411410

@@ -452,7 +451,7 @@ private void processCall(Node call) {
452451
private void processObjectProperty(Node objectLit, Node key, Color type) {
453452
checkArgument(objectLit.isObjectLit() || objectLit.isObjectPattern(), objectLit);
454453
switch (key.getToken()) {
455-
case COMPUTED_PROP:
454+
case COMPUTED_PROP -> {
456455
if (key.getFirstChild().isStringLit()) {
457456
// If this quoted prop name is statically determinable, ensure we don't rename some
458457
// other property in a way that could conflict with it.
@@ -461,27 +460,22 @@ private void processObjectProperty(Node objectLit, Node key, Color type) {
461460
// want to be consistent with how other quoted properties invalidate property names.
462461
quotedNames.add(key.getFirstChild().getString());
463462
}
464-
break;
465-
case MEMBER_FUNCTION_DEF:
466-
case GETTER_DEF:
467-
case SETTER_DEF:
468-
case STRING_KEY:
463+
}
464+
case MEMBER_FUNCTION_DEF, GETTER_DEF, SETTER_DEF, STRING_KEY -> {
469465
if (key.isQuotedStringKey()) {
470466
// If this quoted prop name is statically determinable, ensure we don't rename some
471467
// other property in a way that could conflict with it
472468
quotedNames.add(key.getString());
473469
} else {
474470
maybeMarkCandidate(key, type);
475471
}
476-
break;
477-
478-
case OBJECT_REST:
479-
case OBJECT_SPREAD:
480-
break; // Nothing to do.
481-
482-
default:
483-
throw new IllegalStateException(
484-
"Unexpected child of " + objectLit.getToken() + ": " + key.toStringTree());
472+
}
473+
case OBJECT_REST, OBJECT_SPREAD -> {
474+
// Nothing to do.
475+
}
476+
default ->
477+
throw new IllegalStateException(
478+
"Unexpected child of " + objectLit.getToken() + ": " + key.toStringTree());
485479
}
486480
}
487481

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /