Replace Map operations with computeIfAbsent
This commit is contained in:
@@ -177,11 +177,7 @@ public class ClassFileFactory implements OutputFileCollection {
|
||||
private PackagePartRegistry buildNewPackagePartRegistry(@NotNull FqName packageFqName) {
|
||||
String packageFqNameAsString = packageFqName.asString();
|
||||
return (partShortName, facadeShortName) -> {
|
||||
PackageParts packageParts = partsGroupedByPackage.get(packageFqNameAsString);
|
||||
if (packageParts == null) {
|
||||
packageParts = new PackageParts(packageFqNameAsString);
|
||||
partsGroupedByPackage.put(packageFqNameAsString, packageParts);
|
||||
}
|
||||
PackageParts packageParts = partsGroupedByPackage.computeIfAbsent(packageFqNameAsString, PackageParts::new);
|
||||
packageParts.addPart(partShortName, facadeShortName);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,11 +56,8 @@ public abstract class FieldOwnerContext<T extends DeclarationDescriptor> extends
|
||||
|
||||
String defaultPropertyName = KotlinTypeMapper.mapDefaultFieldName(descriptor, isDelegated);
|
||||
|
||||
Map<PropertyDescriptor, String> descriptor2Name = fieldNames.get(defaultPropertyName);
|
||||
if (descriptor2Name == null) {
|
||||
descriptor2Name = new HashMap<PropertyDescriptor, String>();
|
||||
fieldNames.put(defaultPropertyName, descriptor2Name);
|
||||
}
|
||||
Map<PropertyDescriptor, String> descriptor2Name =
|
||||
fieldNames.computeIfAbsent(defaultPropertyName, unused -> new HashMap<PropertyDescriptor, String>());
|
||||
|
||||
String actualName = descriptor2Name.get(descriptor);
|
||||
if (actualName != null) return actualName;
|
||||
|
||||
+1
-5
@@ -524,11 +524,7 @@ public class AnonymousObjectTransformer extends ObjectTransformer<AnonymousObjec
|
||||
|
||||
@NotNull
|
||||
private String addUniqueField(@NotNull String name) {
|
||||
List<String> existNames = fieldNames.get(name);
|
||||
if (existNames == null) {
|
||||
existNames = new LinkedList<String>();
|
||||
fieldNames.put(name, existNames);
|
||||
}
|
||||
List<String> existNames = fieldNames.computeIfAbsent(name, unused -> new LinkedList<String>());
|
||||
String suffix = existNames.isEmpty() ? "" : "$" + existNames.size();
|
||||
String newName = name + suffix;
|
||||
existNames.add(newName);
|
||||
|
||||
@@ -48,12 +48,7 @@ public class NameGenerator {
|
||||
}
|
||||
|
||||
public NameGenerator subGenerator(String inliningMethod) {
|
||||
NameGenerator generator = subGenerators.get(inliningMethod);
|
||||
if (generator == null) {
|
||||
generator = new NameGenerator(generatorClass + "$" + inliningMethod);
|
||||
subGenerators.put(inliningMethod, generator);
|
||||
}
|
||||
return generator;
|
||||
return subGenerators.computeIfAbsent(inliningMethod, method -> new NameGenerator(generatorClass + "$" + method));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user