@NotNull
 private InspectionTreeNode getToolParentNode(
     @NotNull String groupName, HighlightDisplayLevel errorLevel, boolean groupedBySeverity) {
   if (groupName.isEmpty()) {
     return getRelativeRootNode(groupedBySeverity, errorLevel);
   }
   ConcurrentMap<String, InspectionGroupNode> map = myGroups.get(errorLevel);
   if (map == null) {
     map =
         ConcurrencyUtil.cacheOrGet(
             myGroups, errorLevel, ContainerUtil.<String, InspectionGroupNode>newConcurrentMap());
   }
   InspectionGroupNode group;
   if (groupedBySeverity) {
     group = map.get(groupName);
   } else {
     group = null;
     for (Map<String, InspectionGroupNode> groupMap : myGroups.values()) {
       if ((group = groupMap.get(groupName)) != null) break;
     }
   }
   if (group == null) {
     group = ConcurrencyUtil.cacheOrGet(map, groupName, new InspectionGroupNode(groupName));
     addChildNodeInEDT(getRelativeRootNode(groupedBySeverity, errorLevel), group);
   }
   return group;
 }
  public PsiJavaPackage findPackage(@NotNull String qualifiedName, GlobalSearchScope searchScope) {
    PackageCache cache = SoftReference.dereference(packageCache);
    if (cache == null) {
      packageCache = new SoftReference<PackageCache>(cache = new PackageCache());
    }

    Pair<String, GlobalSearchScope> key =
        new Pair<String, GlobalSearchScope>(qualifiedName, searchScope);
    PsiJavaPackage aPackage = cache.packageInScopeCache.get(key);
    if (aPackage != null) {
      return aPackage;
    }

    KotlinPsiElementFinderWrapper[] finders = filteredFinders();

    Boolean packageFoundInAllScope = cache.hasPackageInAllScopeCache.get(qualifiedName);
    if (packageFoundInAllScope != null) {
      if (!packageFoundInAllScope.booleanValue()) return null;

      // Package was found in AllScope with some of finders but is absent in packageCache for
      // current scope.
      // We check only finders that depend on scope.
      for (KotlinPsiElementFinderWrapper finder : finders) {
        if (!finder.isSameResultForAnyScope()) {
          aPackage = finder.findPackage(qualifiedName, searchScope);
          if (aPackage != null) {
            return ConcurrencyUtil.cacheOrGet(cache.packageInScopeCache, key, aPackage);
          }
        }
      }
    } else {
      for (KotlinPsiElementFinderWrapper finder : finders) {
        aPackage = finder.findPackage(qualifiedName, searchScope);

        if (aPackage != null) {
          return ConcurrencyUtil.cacheOrGet(cache.packageInScopeCache, key, aPackage);
        }
      }

      boolean found = false;
      for (KotlinPsiElementFinderWrapper finder : finders) {
        if (!finder.isSameResultForAnyScope()) {
          aPackage = finder.findPackage(qualifiedName, GlobalSearchScope.allScope(project));
          if (aPackage != null) {
            found = true;
            break;
          }
        }
      }

      cache.hasPackageInAllScopeCache.put(qualifiedName, found);
    }

    return null;
  }
 @Override
 protected PsiFile getPsiInner(@NotNull final Language target) {
   PsiFileImpl file = myRoots.get(target);
   if (file == null) {
     if (isPhysical()) {
       VirtualFile virtualFile = getVirtualFile();
       if (isIgnored()) return null;
       VirtualFile parent = virtualFile.getParent();
       if (parent != null) {
         getManager().findDirectory(parent);
       }
     }
     if (target != getBaseLanguage() && !getLanguages().contains(target)) {
       return null;
     }
     file = (PsiFileImpl) createFile(target);
     if (file == null) return null;
     if (myOriginal != null) {
       final PsiFile originalFile = myOriginal.getPsi(target);
       if (originalFile != null) {
         file.setOriginalFile(originalFile);
       }
     }
     file = ConcurrencyUtil.cacheOrGet(myRoots, target, file);
   }
   return file;
 }
 @Override
 public RefModule getRefModule(Module module) {
   if (module == null) {
     return null;
   }
   RefModule refModule = myModules.get(module);
   if (refModule == null) {
     refModule = ConcurrencyUtil.cacheOrGet(myModules, module, new RefModuleImpl(module, this));
   }
   return refModule;
 }
Exemplo n.º 5
0
 @Nullable
 public static Icon findIcon(URL url, boolean useCache) {
   if (url == null) {
     return null;
   }
   CachedImageIcon icon = ourIconsCache.get(url);
   if (icon == null) {
     icon = new CachedImageIcon(url);
     if (useCache) {
       icon = ConcurrencyUtil.cacheOrGet(ourIconsCache, url, icon);
     }
   }
   return icon;
 }
    static void registerDisposable(
        @NotNull Disposable parentDisposable, @NotNull VirtualFilePointerImpl pointer) {
      DelegatingDisposable result = ourInstances.get(parentDisposable);
      if (result == null) {
        DelegatingDisposable newDisposable = new DelegatingDisposable(parentDisposable);
        result = ConcurrencyUtil.cacheOrGet(ourInstances, parentDisposable, newDisposable);
        if (result == newDisposable) {
          Disposer.register(parentDisposable, result);
        }
      }

      synchronized (result) {
        result.myCounts.put(pointer, result.myCounts.get(pointer) + 1);
      }
    }
 @NotNull
 private InspectionTreeNode getRelativeRootNode(
     boolean isGroupedBySeverity, HighlightDisplayLevel level) {
   if (isGroupedBySeverity) {
     InspectionSeverityGroupNode severityGroupNode = mySeverityGroupNodes.get(level);
     if (severityGroupNode == null) {
       InspectionSeverityGroupNode newNode = new InspectionSeverityGroupNode(myProject, level);
       severityGroupNode = ConcurrencyUtil.cacheOrGet(mySeverityGroupNodes, level, newNode);
       if (severityGroupNode == newNode) {
         InspectionTreeNode root = myTree.getRoot();
         addChildNodeInEDT(root, severityGroupNode);
       }
     }
     return severityGroupNode;
   }
   return myTree.getRoot();
 }
 protected PsiFile getPsiInner(final Language target) {
   PsiFile file = myRoots.get(target);
   if (file == null) {
     if (isPhysical()) {
       VirtualFile virtualFile = getVirtualFile();
       VirtualFile parent = virtualFile.getParent();
       if (parent != null) {
         getManager().findDirectory(parent);
       }
     }
     file = createFile(target);
     if (file == null) return null;
     if (myOriginal != null) {
       final PsiFile originalFile = myOriginal.getPsi(target);
       if (originalFile != null) {
         ((PsiFileImpl) file).setOriginalFile(originalFile);
       }
     }
     file = ConcurrencyUtil.cacheOrGet(myRoots, target, file);
   }
   return file;
 }
 @NotNull
 @Override
 public PsiClassType createTypeByFQClassName(
     @NotNull final String qName, @NotNull final GlobalSearchScope resolveScope) {
   if (CommonClassNames.JAVA_LANG_OBJECT.equals(qName)) {
     PsiClassType cachedObjectType = myCachedObjectType.get(resolveScope);
     if (cachedObjectType != null) {
       return cachedObjectType;
     }
     PsiClass aClass =
         JavaPsiFacade.getInstance(myManager.getProject())
             .findClass(CommonClassNames.JAVA_LANG_OBJECT, resolveScope);
     if (aClass != null) {
       cachedObjectType = new PsiImmediateClassType(aClass, PsiSubstitutor.EMPTY);
       cachedObjectType =
           ConcurrencyUtil.cacheOrGet(myCachedObjectType, resolveScope, cachedObjectType);
       return cachedObjectType;
     }
   }
   return new PsiClassReferenceType(
       createReferenceElementByFQClassName(qName, resolveScope), null);
 }
Exemplo n.º 10
0
 private static int getThreadNum() {
   return ConcurrencyUtil.cacheOrGet(threads, Thread.currentThread(), threads.size());
 }