aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Grefer <eclipse@larsgrefer.de>2020-08-15 16:25:42 +0200
committerLars Grefer <eclipse@larsgrefer.de>2020-08-15 16:36:00 +0200
commit2debfa05f43a6fe71e7bc141f4f78c66f85c95b0 (patch)
tree0b536ac7ef2a5222c7382bc3d03f7023fb5c295d
parentd66bec041a857bc3076a20dfeb1aa6037b020db1 (diff)
downloadaspectj-2debfa05f43a6fe71e7bc141f4f78c66f85c95b0.tar.gz
aspectj-2debfa05f43a6fe71e7bc141f4f78c66f85c95b0.zip
Single Map method can be used
Reports common usage patterns of java.util.Map that could be replaced with Java 8 methods: getOrDefault(), computeIfAbsent(), putIfAbsent(), merge(), or replaceAll(). Signed-off-by: Lars Grefer <eclipse@larsgrefer.de>
-rw-r--r--bcel-builder/src/main/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java6
-rw-r--r--org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java6
-rw-r--r--org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/PushinCollector.java18
-rw-r--r--weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java6
4 files changed, 6 insertions, 30 deletions
diff --git a/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java b/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java
index a7689b108..f07b8f22e 100644
--- a/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java
+++ b/bcel-builder/src/main/java/org/aspectj/apache/bcel/util/NonCachingClassLoaderRepository.java
@@ -211,11 +211,7 @@ public class NonCachingClassLoaderRepository implements Repository {
*/
public JavaClass findClass(String className) {
synchronized (loadedClasses) {
- if (loadedClasses.containsKey(className)) {
- return loadedClasses.get(className);
- } else {
- return null;
- }
+ return loadedClasses.getOrDefault(className, null);
}
}
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java
index 68fc6f74f..a8be5eee7 100644
--- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java
+++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/ast/AccessForInlineVisitor.java
@@ -172,11 +172,7 @@ public class AccessForInlineVisitor extends ASTVisitor {
}
// Avoid repeatedly building ResolvedMembers by using info on any done previously in this visitor
- Map<FieldBinding, ResolvedMember> alreadyResolvedMembers = alreadyProcessedReceivers.get(receiverType);
- if (alreadyResolvedMembers == null) {
- alreadyResolvedMembers = new HashMap<>();
- alreadyProcessedReceivers.put(receiverType, alreadyResolvedMembers);
- }
+ Map<FieldBinding, ResolvedMember> alreadyResolvedMembers = alreadyProcessedReceivers.computeIfAbsent(receiverType, k -> new HashMap<>());
ResolvedMember m = alreadyResolvedMembers.get(binding);
if (m == null) {
m = world.makeResolvedMember(binding, receiverType);
diff --git a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/PushinCollector.java b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/PushinCollector.java
index 894492bf3..2730b5b58 100644
--- a/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/PushinCollector.java
+++ b/org.aspectj.ajdt.core/src/main/java/org/aspectj/ajdt/internal/compiler/lookup/PushinCollector.java
@@ -253,20 +253,12 @@ public class PushinCollector {
// can be null for binary weave (there is no source method)
return;
}
- List<AbstractMethodDeclaration> amds = newDeclarations.get(sourceType);
- if (amds == null) {
- amds = new ArrayList<>();
- newDeclarations.put(sourceType, amds);
- }
+ List<AbstractMethodDeclaration> amds = newDeclarations.computeIfAbsent(sourceType, k -> new ArrayList<>());
amds.add(sourceMethod);
}
public void tagAsMunged(SourceTypeBinding sourceType, String annotationString) {
- List<String> annos = additionalAnnotations.get(sourceType);
- if (annos == null) {
- annos = new ArrayList<>();
- additionalAnnotations.put(sourceType, annos);
- }
+ List<String> annos = additionalAnnotations.computeIfAbsent(sourceType, k -> new ArrayList<>());
annos.add(annotationString);
}
@@ -320,11 +312,7 @@ public class PushinCollector {
public void tagAsMunged(SourceTypeBinding sourceType, TypePattern typePattern) {
if (typePattern instanceof ExactTypePattern) {
- List<ExactTypePattern> annos = additionalParents.get(sourceType);
- if (annos == null) {
- annos = new ArrayList<>();
- additionalParents.put(sourceType, annos);
- }
+ List<ExactTypePattern> annos = additionalParents.computeIfAbsent(sourceType, k -> new ArrayList<>());
annos.add((ExactTypePattern) typePattern);
}
}
diff --git a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java
index 1fb2812bb..62674dedf 100644
--- a/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java
+++ b/weaver/src/main/java/org/aspectj/weaver/bcel/BcelTypeMunger.java
@@ -167,11 +167,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
}
String tname = target.getName();
String pname = newParent.getName();
- List<String> newparents = declareParentsMap.get(tname);
- if (newparents == null) {
- newparents = new ArrayList<>();
- declareParentsMap.put(tname, newparents);
- }
+ List<String> newparents = declareParentsMap.computeIfAbsent(tname, k -> new ArrayList<>());
newparents.add(pname);
AsmRelationshipProvider.addRelationship(model, weaver.getLazyClassGen().getType(), munger, declaringAspect);
}