From 1b3b42ebbec7dd582ab2d551bf4cb30eb52c25f0 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Tue, 8 Jun 2021 00:17:08 +0300 Subject: [PATCH 1/4] [1.0.4-SNAPSHOT] RawMarker concurrent hash map to avoid concurrent modification exception EmptyMarkerFilter and MarkerAnnotationFilter minor update and improvements BaseFilter cleanup (cherry picked from commit f371210b7ca68288197b45aafdd8db4608a75ff0) --- .../dummymapper/filter/impl/AnnotationFilter.java | 3 +-- .../dummymapper/filter/impl/BaseFilter.java | 9 +++++++-- .../dummymapper/filter/impl/EmptyMarkerFilter.java | 13 +++++++------ .../filter/impl/MarkerAnnotationFilter.java | 3 +-- .../goodforgod/dummymapper/marker/EnumMarker.java | 4 +++- .../io/goodforgod/dummymapper/marker/RawMarker.java | 5 ++++- 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/main/java/io/goodforgod/dummymapper/filter/impl/AnnotationFilter.java b/src/main/java/io/goodforgod/dummymapper/filter/impl/AnnotationFilter.java index 370f4ea..7d9e7a0 100644 --- a/src/main/java/io/goodforgod/dummymapper/filter/impl/AnnotationFilter.java +++ b/src/main/java/io/goodforgod/dummymapper/filter/impl/AnnotationFilter.java @@ -5,7 +5,6 @@ import io.goodforgod.dummymapper.model.AnnotationMarker; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.function.Predicate; @@ -28,8 +27,8 @@ public abstract class AnnotationFilter extends BaseFilter { @Override public RawMarker filter(@NotNull RawMarker marker) { final Predicate allowed = allowed(); + final Map structure = marker.getStructure(); - final Map structure = new HashMap<>(marker.getStructure()); structure.forEach((k, v) -> { final Set left = v.getAnnotations().stream() .filter(a -> allowed.test(a) || a.isInternal()) diff --git a/src/main/java/io/goodforgod/dummymapper/filter/impl/BaseFilter.java b/src/main/java/io/goodforgod/dummymapper/filter/impl/BaseFilter.java index 3fded36..ca1b7ea 100644 --- a/src/main/java/io/goodforgod/dummymapper/filter/impl/BaseFilter.java +++ b/src/main/java/io/goodforgod/dummymapper/filter/impl/BaseFilter.java @@ -33,9 +33,14 @@ public RawMarker filterRecursive(@NotNull RawMarker marker) { marker.addAnnotation(AnnotationMarkerBuilder.get().ofInternal().withName(visited).build()); final Map structure = marker.getStructure(); - MarkerUtils.streamRawMarkers(structure).filter(m -> !isVisited.test(m)).forEach(this::filter); - MarkerUtils.streamCollectionRawMarkers(structure).filter(m -> !isVisited.test((RawMarker) m.getErasure())) + MarkerUtils.streamRawMarkers(structure) + .filter(m -> !isVisited.test(m)) + .forEach(this::filter); + + MarkerUtils.streamCollectionRawMarkers(structure) + .filter(m -> !isVisited.test((RawMarker) m.getErasure())) .forEach(m -> filter((RawMarker) m.getErasure())); + MarkerUtils.streamMapRawMarkers(structure).forEach(m -> { if (m.getKeyErasure() instanceof RawMarker && !isVisited.test(((RawMarker) m.getKeyErasure()))) filter((RawMarker) m.getKeyErasure()); diff --git a/src/main/java/io/goodforgod/dummymapper/filter/impl/EmptyMarkerFilter.java b/src/main/java/io/goodforgod/dummymapper/filter/impl/EmptyMarkerFilter.java index 69720b1..f83c787 100644 --- a/src/main/java/io/goodforgod/dummymapper/filter/impl/EmptyMarkerFilter.java +++ b/src/main/java/io/goodforgod/dummymapper/filter/impl/EmptyMarkerFilter.java @@ -6,7 +6,7 @@ import io.goodforgod.dummymapper.marker.RawMarker; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; +import java.util.Map; /** * Filters out empty {@link RawMarker} or if any {@link CollectionMarker} or {@link MapMarker} have empty {@link RawMarker} @@ -23,11 +23,12 @@ public RawMarker filter(@NotNull RawMarker marker) { return RawMarker.EMPTY; final RawMarker recursive = filterRecursive(marker); - final HashMap structure = new HashMap<>(recursive.getStructure()); - structure.forEach((k, v) -> { - if (v.isEmpty()) - recursive.getStructure().remove(k); - }); + final Map structure = recursive.getStructure(); + + structure.entrySet().stream() + .filter(e -> e.getValue().isEmpty()) + .map(Map.Entry::getKey) + .forEach(key -> marker.getStructure().remove(key)); return recursive; } diff --git a/src/main/java/io/goodforgod/dummymapper/filter/impl/MarkerAnnotationFilter.java b/src/main/java/io/goodforgod/dummymapper/filter/impl/MarkerAnnotationFilter.java index a8b1f91..6f6a52e 100644 --- a/src/main/java/io/goodforgod/dummymapper/filter/impl/MarkerAnnotationFilter.java +++ b/src/main/java/io/goodforgod/dummymapper/filter/impl/MarkerAnnotationFilter.java @@ -5,7 +5,6 @@ import io.goodforgod.dummymapper.model.AnnotationMarker; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.Map; import java.util.function.Predicate; @@ -26,8 +25,8 @@ public abstract class MarkerAnnotationFilter extends BaseFilter { @Override public RawMarker filter(@NotNull RawMarker marker) { final Predicate predicate = predicate(); + final Map structure = marker.getStructure(); - final HashMap structure = new HashMap<>(marker.getStructure()); structure.entrySet().stream() .filter(e -> e.getValue().getAnnotations().stream().anyMatch(predicate)) .map(Map.Entry::getKey) diff --git a/src/main/java/io/goodforgod/dummymapper/marker/EnumMarker.java b/src/main/java/io/goodforgod/dummymapper/marker/EnumMarker.java index 507d5f4..b65fc48 100644 --- a/src/main/java/io/goodforgod/dummymapper/marker/EnumMarker.java +++ b/src/main/java/io/goodforgod/dummymapper/marker/EnumMarker.java @@ -20,7 +20,9 @@ public EnumMarker(@NotNull String root, @NotNull String source, @Nullable Collection values) { super(root, source); - this.values = CollectionUtils.isEmpty(values) ? Collections.emptyList() : new ArrayList<>(values); + this.values = CollectionUtils.isEmpty(values) + ? Collections.emptyList() + : new ArrayList<>(values); } @Override diff --git a/src/main/java/io/goodforgod/dummymapper/marker/RawMarker.java b/src/main/java/io/goodforgod/dummymapper/marker/RawMarker.java index 55a2690..093f7b1 100644 --- a/src/main/java/io/goodforgod/dummymapper/marker/RawMarker.java +++ b/src/main/java/io/goodforgod/dummymapper/marker/RawMarker.java @@ -6,6 +6,7 @@ import java.util.Collections; import java.util.Map; import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; /** * Marker for unknown Java type (custom class) @@ -23,7 +24,9 @@ public RawMarker(@NotNull String root, @NotNull String source, @Nullable Map structure) { super(root, source); - this.structure = (structure == null || structure.isEmpty()) ? Collections.emptyMap() : structure; + this.structure = (structure == null || structure.isEmpty()) + ? Collections.emptyMap() + : new ConcurrentHashMap<>(structure); } public String getSourcePackage() { From ddf0cc30201c3f47da4a8219c2f50317b856b037 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Thu, 10 Jun 2021 23:16:29 +0300 Subject: [PATCH 2/4] [1.0.4] [1.0.4] Changelog added (cherry picked from commit 6f20e2b62b75efb51818c7a7e643d2760580a12a) --- gradle.properties | 2 +- src/main/resources/META-INF/plugin.xml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index a5e8ba9..6fc2881 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ groupId=com.github.goodforgod artifactId=dummymapper -artifactVersion=1.0.3 +artifactVersion=1.0.4 ##### GRADLE ##### diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index e7a9218..8f5c95f 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -24,7 +24,8 @@ Features or changes in this release:
    -
  • Compatibility with IDEA 2021.1+
  • +
  • Fixed concurrent modification when filters try to clean structure
  • +
  • Ability select inner static class and map only that class
]]>
From 074c7441f2aa06a41dd1eaa49f1d721830f92f7c Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Thu, 10 Jun 2021 23:18:28 +0300 Subject: [PATCH 3/4] [1.0.4] Plugin updated to 0.7.3 (cherry picked from commit 2d49deb2bd759280653d455069e37ef6709a02e5) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 5bfa99b..a2ad218 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { id 'java-library' id 'maven-publish' - id 'org.jetbrains.intellij' version '0.7.2' + id 'org.jetbrains.intellij' version '0.7.3' id 'org.sonarqube' version '3.1.1' id 'com.diffplug.spotless' version '5.11.0' } From d008c9c717322596f526a4e92ab43847bbcef256 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Fri, 11 Jun 2021 23:40:50 +0300 Subject: [PATCH 4/4] [1.0.4] plugin.xml changelog fixed --- src/main/resources/META-INF/plugin.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 8f5c95f..686e4fc 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -25,7 +25,6 @@ Features or changes in this release:
  • Fixed concurrent modification when filters try to clean structure
  • -
  • Ability select inner static class and map only that class
]]>