import org.jetbrains.jps.util.JpsPathUtil;
import java.io.File;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
/**
* @author nik
*/
public class JpsLibraryImpl<P extends JpsElement> extends JpsNamedCompositeElementBase<JpsLibraryImpl<P>> implements JpsTypedLibrary<P> {
+ private static final ConcurrentMap<JpsOrderRootType, JpsElementCollectionRole<JpsLibraryRoot>> ourRootRoles = ContainerUtil.newConcurrentMap();
private final JpsLibraryType<P> myLibraryType;
public JpsLibraryImpl(@NotNull String name, @NotNull JpsLibraryType<P> type, @NotNull P properties) {
}
private static JpsElementCollectionRole<JpsLibraryRoot> getRole(JpsOrderRootType type) {
- return JpsElementCollectionRole.create(new JpsLibraryRootRole(type));
+ JpsElementCollectionRole<JpsLibraryRoot> role = ourRootRoles.get(type);
+ if (role != null) return role;
+ ourRootRoles.putIfAbsent(type, JpsElementCollectionRole.create(new JpsLibraryRootRole(type)));
+ return ourRootRoles.get(type);
}
@Override
*/
package org.jetbrains.jps.model.module.impl;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.library.sdk.JpsSdkType;
import org.jetbrains.jps.model.module.JpsSdkReferencesTable;
+import java.util.concurrent.ConcurrentMap;
+
/**
* @author nik
*/
public class JpsSdkReferencesTableImpl extends JpsCompositeElementBase<JpsSdkReferencesTableImpl> implements JpsSdkReferencesTable {
public static final JpsSdkReferencesTableRole ROLE = new JpsSdkReferencesTableRole();
+ private static final ConcurrentMap<JpsSdkType, JpsSdkReferenceRole> ourReferenceRoles = ContainerUtil.newConcurrentMap();
public JpsSdkReferencesTableImpl() {
super();
@Override
public <P extends JpsElement> void setSdkReference(@NotNull JpsSdkType<P> type, @Nullable JpsSdkReference<P> sdkReference) {
- JpsSdkReferenceRole<P> role = new JpsSdkReferenceRole<P>(type);
+ JpsSdkReferenceRole<P> role = getSdkReferenceRole(type);
if (sdkReference != null) {
myContainer.setChild(role, sdkReference);
}
@Override
public <P extends JpsElement> JpsSdkReference<P> getSdkReference(@NotNull JpsSdkType<P> type) {
- return myContainer.getChild(new JpsSdkReferenceRole<P>(type));
+ return myContainer.getChild(getSdkReferenceRole(type));
+ }
+
+ @SuppressWarnings("unchecked")
+ @NotNull
+ private static <P extends JpsElement> JpsSdkReferenceRole<P> getSdkReferenceRole(@NotNull JpsSdkType<P> type) {
+ JpsSdkReferenceRole<P> role = ourReferenceRoles.get(type);
+ if (role != null) return role;
+ ourReferenceRoles.putIfAbsent(type, new JpsSdkReferenceRole<P>(type));
+ return ourReferenceRoles.get(type);
}
private static class JpsSdkReferencesTableRole extends JpsElementChildRoleBase<JpsSdkReferencesTable> implements JpsElementCreator<JpsSdkReferencesTable> {