mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 12:19:00 +00:00
[fixes #2624] Resolve variables in switch expressions
This commit is contained in:
1 parent
5120abe474
commit
400e0f7544
4 files changed
+52
-6
No files matched your search
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2015 The Project Lombok Authors.
|
||||
* Copyright (C) 2010-2021 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -56,14 +56,14 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
|
||||
@Override public <T extends JCTree> T copy(T original) {
|
||||
T copy = super.copy(original);
|
||||
originalToCopy.put(original, copy);
|
||||
putIfAbsent(originalToCopy, original, copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override public <T extends JCTree> T copy(T original, Void p) {
|
||||
T copy = super.copy(original, p);
|
||||
originalToCopy.put(original, copy);
|
||||
return copy;
|
||||
putIfAbsent(originalToCopy, original, copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
@Override public <T extends JCTree> List<T> copy(List<T> originals) {
|
||||
@@ -71,7 +71,7 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
if (originals != null) {
|
||||
Iterator<T> it1 = originals.iterator();
|
||||
Iterator<T> it2 = copies.iterator();
|
||||
while (it1.hasNext()) originalToCopy.put(it1.next(), it2.next());
|
||||
while (it1.hasNext()) putIfAbsent(originalToCopy, it1.next(), it2.next());
|
||||
}
|
||||
return copies;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
if (originals != null) {
|
||||
Iterator<T> it1 = originals.iterator();
|
||||
Iterator<T> it2 = copies.iterator();
|
||||
while (it1.hasNext()) originalToCopy.put(it1.next(), it2.next());
|
||||
while (it1.hasNext()) putIfAbsent(originalToCopy, it1.next(), it2.next());
|
||||
}
|
||||
return copies;
|
||||
}
|
||||
@@ -120,4 +120,10 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
|
||||
@Override public JCTree visitLabeledStatement(LabeledStatementTree node, Void p) {
|
||||
return node.getStatement().accept(this, p);
|
||||
}
|
||||
|
||||
private <K, V> void putIfAbsent(Map<K, V> map, K key, V value) {
|
||||
if (!map.containsKey(key)) {
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// version 14:
|
||||
public class ValSwitchExpression {
|
||||
public void method(int arg) {
|
||||
final int x = switch (arg) {
|
||||
default -> {
|
||||
final java.lang.String s = "string";
|
||||
yield arg;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// version 14:
|
||||
import lombok.val;
|
||||
public class ValSwitchExpression {
|
||||
public ValSwitchExpression() {
|
||||
super();
|
||||
}
|
||||
public void method(int arg) {
|
||||
final @val int x = switch (arg) {
|
||||
default ->
|
||||
{
|
||||
final @val java.lang.String s = "string";
|
||||
yield arg;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// version 14:
|
||||
import lombok.val;
|
||||
|
||||
public class ValSwitchExpression {
|
||||
public void method(int arg) {
|
||||
val x = switch (arg) {
|
||||
default -> {
|
||||
val s = "string";
|
||||
yield arg;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user