Java 类com.intellij.util.containers.ConcurrentWeakHashMap 实例源码

项目:tools-idea    文件:VariableAccessFromInnerClassFix.java   
@NotNull
private Collection<PsiVariable> getVariablesToFix() {
  Map<PsiVariable, Boolean> vars = myClass.getUserData(VARS[myFixType]);
  if (vars == null) myClass.putUserData(VARS[myFixType], vars = new ConcurrentWeakHashMap<PsiVariable, Boolean>(1));
  final Map<PsiVariable, Boolean> finalVars = vars;
  return new AbstractCollection<PsiVariable>() {
    @Override
    public boolean add(PsiVariable psiVariable) {
      return finalVars.put(psiVariable, Boolean.TRUE) == null;
    }

    @Override
    public Iterator<PsiVariable> iterator() {
      return finalVars.keySet().iterator();
    }

    @Override
    public int size() {
      return finalVars.size();
    }
  };
}
项目:tools-idea    文件:TreeViewUtil.java   
private static boolean shouldAbbreviateName(PsiPackage aPackage) {
  final Project project = aPackage.getProject();
  ConcurrentMap<PsiPackage, Boolean> map = project.getUserData(SHOULD_ABBREV_PACK_KEY);
  if (map == null) {
    final ConcurrentWeakHashMap<PsiPackage, Boolean> newMap = new ConcurrentWeakHashMap<PsiPackage, Boolean>();
    map = ((UserDataHolderEx)project).putUserDataIfAbsent(SHOULD_ABBREV_PACK_KEY, newMap);
    if (map == newMap) {
      ((PsiManagerEx)PsiManager.getInstance(project)).registerRunnableToRunOnChange(new Runnable() {
        @Override
        public void run() {
          newMap.clear();
        }
      });
    }
  }

  Boolean ret = map.get(aPackage);
  if (ret != null) return ret;
  ret = scanPackages(aPackage, 1);
  map.put(aPackage, ret);
  return ret;
}
项目:tools-idea    文件:LoaderFactory.java   
public LoaderFactory(final Project project) {
  myProject = project;
  myModule2ClassLoader = new ConcurrentWeakHashMap<Module, ClassLoader>();
  myConnection = myProject.getMessageBus().connect();
  myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
    public void rootsChanged(final ModuleRootEvent event) {
      clearClassLoaderCache();
    }
  });

  Disposer.register(project, new Disposable() {
    public void dispose() {
      myConnection.disconnect();
      myModule2ClassLoader.clear();
    }
  });
}
项目:consulo-ui-designer    文件:LoaderFactory.java   
public LoaderFactory(final Project project) {
  myProject = project;
  myModule2ClassLoader = new ConcurrentWeakHashMap<Module, ClassLoader>();
  myConnection = myProject.getMessageBus().connect();
  myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
    public void rootsChanged(final ModuleRootEvent event) {
      clearClassLoaderCache();
    }
  });

  Disposer.register(project, new Disposable() {
    public void dispose() {
      myConnection.disconnect();
      myModule2ClassLoader.clear();
    }
  });
}
项目:consulo    文件:TreeViewUtil.java   
private static boolean shouldAbbreviateName(PsiPackage aPackage) {
  final Project project = aPackage.getProject();
  ConcurrentMap<PsiPackage, Boolean> map = project.getUserData(SHOULD_ABBREV_PACK_KEY);
  if (map == null) {
    final ConcurrentWeakHashMap<PsiPackage, Boolean> newMap = new ConcurrentWeakHashMap<PsiPackage, Boolean>();
    map = ((UserDataHolderEx)project).putUserDataIfAbsent(SHOULD_ABBREV_PACK_KEY, newMap);
    if (map == newMap) {
      ((PsiManagerEx)PsiManager.getInstance(project)).registerRunnableToRunOnChange(new Runnable() {
        @Override
        public void run() {
          newMap.clear();
        }
      });
    }
  }

  Boolean ret = map.get(aPackage);
  if (ret != null) return ret;
  ret = scanPackages(aPackage, 1);
  map.put(aPackage, ret);
  return ret;
}
项目:tools-idea    文件:CreateConstructorParameterFromFieldFix.java   
@NotNull
private Collection<SmartPsiElementPointer<PsiField>> getFieldsToFix() {
  Map<SmartPsiElementPointer<PsiField>, Boolean> fields = myClass.getUserData(FIELDS);
  if (fields == null) myClass.putUserData(FIELDS, fields = new ConcurrentWeakHashMap<SmartPsiElementPointer<PsiField>,Boolean>(1));
  final Map<SmartPsiElementPointer<PsiField>, Boolean> finalFields = fields;
  return new AbstractCollection<SmartPsiElementPointer<PsiField>>() {
    @Override
    public boolean add(SmartPsiElementPointer<PsiField> psiVariable) {
      PsiField field = psiVariable.getElement();
      if (field == null || !isAvailable(field)) return false;
      return finalFields.put(psiVariable, Boolean.TRUE) == null;
    }

    @Override
    public Iterator<SmartPsiElementPointer<PsiField>> iterator() {
      return finalFields.keySet().iterator();
    }

    @Override
    public int size() {
      return finalFields.size();
    }

    @Override
    public void clear() {
      finalFields.clear();
    }
  };
}
项目:tools-idea    文件:BindFieldsFromParametersAction.java   
@NotNull
private static Collection<SmartPsiElementPointer<PsiParameter>> getUnboundedParams(PsiMethod psiMethod) {
  Map<SmartPsiElementPointer<PsiParameter>, Boolean> params = psiMethod.getUserData(PARAMS);
  if (params == null) psiMethod.putUserData(PARAMS, params = new ConcurrentWeakHashMap<SmartPsiElementPointer<PsiParameter>, Boolean>(1));
  final Map<SmartPsiElementPointer<PsiParameter>, Boolean> finalParams = params;
  return new AbstractCollection<SmartPsiElementPointer<PsiParameter>>() {
    @Override
    public boolean add(SmartPsiElementPointer<PsiParameter> psiVariable) {
      return finalParams.put(psiVariable, Boolean.TRUE) == null;
    }

    @Override
    public Iterator<SmartPsiElementPointer<PsiParameter>> iterator() {
      return finalParams.keySet().iterator();
    }

    @Override
    public int size() {
      return finalParams.size();
    }

    @Override
    public void clear() {
      finalParams.clear();
    }
  };
}
项目:tools-idea    文件:MavenProjectsManagerWatcher.java   
private boolean xmlFileWasChanged(VirtualFile xmlFile, VFileEvent event) {
  if (!xmlFile.isValid() || !(event instanceof VFileContentChangeEvent)) return true;

  ConcurrentWeakHashMap<Project, Integer> map = xmlFile.getUserData(CRC_WITHOUT_SPACES);
  if (map == null) {
    map = xmlFile.putUserDataIfAbsent(CRC_WITHOUT_SPACES, new ConcurrentWeakHashMap<Project, Integer>());
  }

  Integer crc = map.get(myProject);
  Integer newCrc;

  try {
    newCrc = MavenUtil.crcWithoutSpaces(xmlFile);
  }
  catch (IOException ignored) {
    return true;
  }

  if (newCrc == -1 // XML is invalid
      || newCrc.equals(crc)) {
    return false;
  }
  else {
    map.put(myProject, newCrc);
    return true;
  }
}
项目:idea-gitignore    文件:HandleTrackedIgnoredFilesAction.java   
/**
 * Helper method to return tracked and ignored files map.
 *
 * @param event current event
 * @return map of files
 */
private ConcurrentMap<VirtualFile, VcsRoot> getTrackedIgnoredFiles(@NotNull AnActionEvent event) {
    final Project project = event.getProject();

    if (project != null) {
        return IgnoreManager.getInstance(project).getConfirmedIgnoredFiles();
    }

    return new ConcurrentWeakHashMap<VirtualFile, VcsRoot>();
}
项目:consulo-java    文件:CreateConstructorParameterFromFieldFix.java   
@NotNull
private Collection<SmartPsiElementPointer<PsiField>> getFieldsToFix() {
  Map<SmartPsiElementPointer<PsiField>, Boolean> fields = myClass.getUserData(FIELDS);
  if (fields == null) myClass.putUserData(FIELDS, fields = new ConcurrentWeakHashMap<SmartPsiElementPointer<PsiField>,Boolean>(1));
  final Map<SmartPsiElementPointer<PsiField>, Boolean> finalFields = fields;
  return new AbstractCollection<SmartPsiElementPointer<PsiField>>() {
    @Override
    public boolean add(SmartPsiElementPointer<PsiField> psiVariable) {
      PsiField field = psiVariable.getElement();
      if (field == null || !isAvailable(field)) return false;
      return finalFields.put(psiVariable, Boolean.TRUE) == null;
    }

    @Override
    public Iterator<SmartPsiElementPointer<PsiField>> iterator() {
      return finalFields.keySet().iterator();
    }

    @Override
    public int size() {
      return finalFields.size();
    }

    @Override
    public void clear() {
      finalFields.clear();
    }
  };
}
项目:consulo-java    文件:BindFieldsFromParametersAction.java   
@NotNull
private static Collection<SmartPsiElementPointer<PsiParameter>> getUnboundedParams(PsiMethod psiMethod) {
  Map<SmartPsiElementPointer<PsiParameter>, Boolean> params = psiMethod.getUserData(PARAMS);
  if (params == null) psiMethod.putUserData(PARAMS, params = new ConcurrentWeakHashMap<SmartPsiElementPointer<PsiParameter>, Boolean>(1));
  final Map<SmartPsiElementPointer<PsiParameter>, Boolean> finalParams = params;
  return new AbstractCollection<SmartPsiElementPointer<PsiParameter>>() {
    @Override
    public boolean add(SmartPsiElementPointer<PsiParameter> psiVariable) {
      return finalParams.put(psiVariable, Boolean.TRUE) == null;
    }

    @Override
    public Iterator<SmartPsiElementPointer<PsiParameter>> iterator() {
      return finalParams.keySet().iterator();
    }

    @Override
    public int size() {
      return finalParams.size();
    }

    @Override
    public void clear() {
      finalParams.clear();
    }
  };
}
项目:tools-idea    文件:ResolveCache.java   
private static <K,V> ConcurrentWeakHashMap<K, V> createWeakMap() {
  return new ConcurrentWeakHashMap<K,V>(100, 0.75f, Runtime.getRuntime().availableProcessors(), ContainerUtil.<K>canonicalStrategy());
}
项目:consulo-haxe    文件:HaxeClassResolveCache.java   
private static <K, V> ConcurrentWeakHashMap<K, V> createWeakMap() {
  return new ConcurrentWeakHashMap<K, V>(7, 0.75f, Runtime.getRuntime().availableProcessors(),
                                        TObjectHashingStrategy.CANONICAL);
}
项目:idea-gitignore    文件:CachedConcurrentMap.java   
/**
 * Default constructor.
 *
 * @param fetcher data fetcher
 */
private CachedConcurrentMap(@NotNull DataFetcher<K, V> fetcher) {
    this.map = new ConcurrentWeakHashMap<K, V>();
    this.fetcher = fetcher;
}