diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2021-06-04 04:35:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-04 04:35:02 +0200 |
commit | 0ce8721960cefe32c01273e0e1b3a6f3a9eb474a (patch) | |
tree | 9f7c401efe07edc307bf27d627da8bba68818ab2 /src/utils/lombok/javac/TreeMirrorMaker.java | |
parent | 5523aca3b7a46072b4ecf9d836db7d0a84d3f731 (diff) | |
parent | 400e0f75441d4027c8ccdc5f18c1b06f7bc479d9 (diff) | |
download | lombok-0ce8721960cefe32c01273e0e1b3a6f3a9eb474a.tar.gz lombok-0ce8721960cefe32c01273e0e1b3a6f3a9eb474a.tar.bz2 lombok-0ce8721960cefe32c01273e0e1b3a6f3a9eb474a.zip |
Merge pull request #2816 from Rawi01/val-switch-expression
Resolve variables in switch expressions
Diffstat (limited to 'src/utils/lombok/javac/TreeMirrorMaker.java')
-rw-r--r-- | src/utils/lombok/javac/TreeMirrorMaker.java | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/utils/lombok/javac/TreeMirrorMaker.java b/src/utils/lombok/javac/TreeMirrorMaker.java index 3cb79412..a67a4ec1 100644 --- a/src/utils/lombok/javac/TreeMirrorMaker.java +++ b/src/utils/lombok/javac/TreeMirrorMaker.java @@ -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); + } + } } |