com.intellij.openapi.util.Factory Java Examples

The following examples show how to use com.intellij.openapi.util.Factory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FindUsagesImpl171.java    From Android-Resource-Usage-Count with MIT License 6 votes vote down vote up
int findUsage(XmlTag element) {
    final FindUsagesHandler handler = FindUsagesImpl171.getFindUsagesHandler(element, element.getProject());
    if (handler != null) {
        final FindUsagesOptions findUsagesOptions = handler.getFindUsagesOptions();
        final PsiElement[] primaryElements = handler.getPrimaryElements();
        final PsiElement[] secondaryElements = handler.getSecondaryElements();
        Factory factory = new Factory() {
            public UsageSearcher create() {
                return FindUsagesImpl171.createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, (PsiFile) null);
            }
        };
        UsageSearcher usageSearcher = (UsageSearcher)factory.create();
        final AtomicInteger mCount = new AtomicInteger(0);
        usageSearcher.generate(new Processor<Usage>() {
            @Override
            public boolean process(Usage usage) {
                if (ResourceUsageCountUtils.isUsefulUsageToCount(usage)) {
                    mCount.incrementAndGet();
                }
                return true;
            }
        });
        return mCount.get();
    }
    return 0;
}
 
Example #2
Source File: PantsCommonSourceRootModifier.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
public Map<ContentRoot, List<Pair<String, TargetInfo>>> getSourceRoot2TargetMapping(@NotNull ProjectInfo projectInfo) {
  final Factory<List<Pair<String, TargetInfo>>> listFactory = ArrayList::new;
  final Map<ContentRoot, List<Pair<String, TargetInfo>>> result = new HashMap<>();
  for (Map.Entry<String, TargetInfo> entry : projectInfo.getTargets().entrySet()) {
    final String targetName = entry.getKey();
    final TargetInfo targetInfo = entry.getValue();
    for (ContentRoot contentRoot : targetInfo.getRoots()) {
      ContainerUtil.getOrCreate(
        result,
        contentRoot,
        listFactory
      ).add(Pair.create(targetName, targetInfo));
    }
  }
  return result;
}
 
Example #3
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public UsageView doFindUsages(@Nonnull final PsiElement[] primaryElements,
                              @Nonnull final PsiElement[] secondaryElements,
                              @Nonnull final FindUsagesHandler handler,
                              @Nonnull final FindUsagesOptions findUsagesOptions,
                              final boolean toSkipUsagePanelWhenOneUsage) {
  if (primaryElements.length == 0) {
    throw new AssertionError(handler + " " + findUsagesOptions);
  }
  PsiElement2UsageTargetAdapter[] primaryTargets = convertToUsageTargets(Arrays.asList(primaryElements), findUsagesOptions);
  PsiElement2UsageTargetAdapter[] secondaryTargets = convertToUsageTargets(Arrays.asList(secondaryElements), findUsagesOptions);
  PsiElement2UsageTargetAdapter[] targets = ArrayUtil.mergeArrays(primaryTargets, secondaryTargets);
  Factory<UsageSearcher> factory = () -> createUsageSearcher(primaryTargets, secondaryTargets, handler, findUsagesOptions, null);
  UsageView usageView = myAnotherManager.searchAndShowUsages(targets, factory, !toSkipUsagePanelWhenOneUsage, true,
                                                             createPresentation(primaryElements[0], findUsagesOptions, shouldOpenInNewTab()), null);
  myHistory.add(targets[0]);
  return usageView;
}
 
Example #4
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void changeListUpdateDone() {
  scheduleRefresh();
  ChangeListManagerImpl changeListManager = ChangeListManagerImpl.getInstanceImpl(myProject);
  VcsException updateException = changeListManager.getUpdateException();
  setBusy(false);
  if (updateException == null) {
    Factory<JComponent> additionalUpdateInfo = changeListManager.getAdditionalUpdateInfo();

    if (additionalUpdateInfo != null) {
      updateProgressComponent(additionalUpdateInfo);
    }
    else {
      updateProgressText("", false);
    }
  }
  else {
    updateProgressText(VcsBundle.message("error.updating.changes", updateException.getMessage()), true);
  }
}
 
Example #5
Source File: SearchForUsagesRunnable.java    From consulo with Apache License 2.0 6 votes vote down vote up
SearchForUsagesRunnable(@Nonnull UsageViewManagerImpl usageViewManager,
                        @Nonnull Project project,
                        @Nonnull AtomicReference<UsageViewImpl> usageViewRef,
                        @Nonnull UsageViewPresentation presentation,
                        @Nonnull UsageTarget[] searchFor,
                        @Nonnull Factory<UsageSearcher> searcherFactory,
                        @Nonnull FindUsagesProcessPresentation processPresentation,
                        @Nonnull SearchScope searchScopeToWarnOfFallingOutOf,
                        @javax.annotation.Nullable UsageViewManager.UsageViewStateListener listener) {
  myProject = project;
  myUsageViewRef = usageViewRef;
  myPresentation = presentation;
  mySearchFor = searchFor;
  mySearcherFactory = searcherFactory;
  myProcessPresentation = processPresentation;
  mySearchScopeToWarnOfFallingOutOf = searchScopeToWarnOfFallingOutOf;
  myListener = listener;
  myUsageViewManager = usageViewManager;
}
 
Example #6
Source File: InspectionToolRegistrar.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@TestOnly
public List<InspectionToolWrapper> createTools() {
  ensureInitialized();

  final List<InspectionToolWrapper> tools = ContainerUtil.newArrayListWithCapacity(myInspectionToolFactories.size());
  final Set<Factory<InspectionToolWrapper>> broken = ContainerUtil.newHashSet();
  for (final Factory<InspectionToolWrapper> factory : myInspectionToolFactories) {
    ProgressManager.checkCanceled();
    final InspectionToolWrapper toolWrapper = factory.create();
    if (toolWrapper != null && checkTool(toolWrapper) == null) {
      tools.add(toolWrapper);
    }
    else {
      broken.add(factory);
    }
  }
  myInspectionToolFactories.removeAll(broken);

  return tools;
}
 
Example #7
Source File: FindUsagesImpl.java    From Android-Resource-Usage-Count with MIT License 5 votes vote down vote up
int findUsage(XmlTag element) {
    final AtomicInteger mCount = new AtomicInteger(0);
    try {
        com.intellij.find.findUsages.FindUsagesHandler handler = this.getFindUsagesHandler(element);
        if (handler != null) {
            AbstractFindUsagesDialog dialog = handler.getFindUsagesDialog(false, false, false);
            dialog.close(0);
            FindUsagesOptions findUsagesOptions = dialog.calcFindUsagesOptions();
            PsiElement[] primaryElements = handler.getPrimaryElements();
            PsiElement[] secondaryElements = handler.getSecondaryElements();
            PsiElement2UsageTargetAdapter[] primaryTargets = convertToUsageTargets(Arrays.asList(primaryElements), findUsagesOptions);
            PsiElement2UsageTargetAdapter[] secondaryTargets = convertToUsageTargets(Arrays.asList(secondaryElements), findUsagesOptions);
            final Factory<UsageSearcher> factory = new Factory<UsageSearcher>() {
                @Override
                public UsageSearcher create() {
                    return createUsageSearcher(primaryTargets, secondaryTargets, handler, findUsagesOptions, (PsiFile) null);
                }
            };

            UsageSearcher usageSearcher = (UsageSearcher)factory.create();
            usageSearcher.generate((usage) -> {
                if (ResourceUsageCountUtils.isUsefulUsageToCount(usage)) {
                    mCount.incrementAndGet();
                }
                return true;
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return mCount.get();
}
 
Example #8
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showUsageView(@Nonnull UsageViewDescriptor viewDescriptor, @Nonnull Factory<UsageSearcher> factory, @Nonnull UsageInfo[] usageInfos) {
  UsageViewManager viewManager = UsageViewManager.getInstance(myProject);

  final PsiElement[] initialElements = viewDescriptor.getElements();
  final UsageTarget[] targets = PsiElement2UsageTargetAdapter.convert(initialElements);
  final Ref<Usage[]> convertUsagesRef = new Ref<>();
  if (!ProgressManager.getInstance()
          .runProcessWithProgressSynchronously(() -> ApplicationManager.getApplication().runReadAction(() -> convertUsagesRef.set(UsageInfo2UsageAdapter.convert(usageInfos))), "Preprocess Usages",
                                               true, myProject)) return;

  if (convertUsagesRef.isNull()) return;

  final Usage[] usages = convertUsagesRef.get();

  final UsageViewPresentation presentation = createPresentation(viewDescriptor, usages);
  if (myUsageView == null) {
    myUsageView = viewManager.showUsages(targets, usages, presentation, factory);
    customizeUsagesView(viewDescriptor, myUsageView);
  }
  else {
    myUsageView.removeUsagesBulk(myUsageView.getUsages());
    ((UsageViewImpl)myUsageView).appendUsagesInBulk(Arrays.asList(usages));
  }
  Set<UnloadedModuleDescription> unloadedModules = computeUnloadedModulesFromUseScope(viewDescriptor);
  if (!unloadedModules.isEmpty()) {
    myUsageView.appendUsage(new UnknownUsagesInUnloadedModules(unloadedModules));
  }
}
 
Example #9
Source File: BaseRefactoringProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void previewRefactoring(@Nonnull UsageInfo[] usages) {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    if (!PREVIEW_IN_TESTS) throw new RuntimeException("Unexpected preview in tests: " + StringUtil.join(usages, UsageInfo::toString, ", "));
    ensureElementsWritable(usages, createUsageViewDescriptor(usages));
    execute(usages);
    return;
  }
  final UsageViewDescriptor viewDescriptor = createUsageViewDescriptor(usages);
  final PsiElement[] elements = viewDescriptor.getElements();
  final PsiElement2UsageTargetAdapter[] targets = PsiElement2UsageTargetAdapter.convert(elements);
  Factory<UsageSearcher> factory = () -> new UsageInfoSearcherAdapter() {
    @Override
    public void generate(@Nonnull final Processor<Usage> processor) {
      ApplicationManager.getApplication().runReadAction(() -> {
        for (int i = 0; i < elements.length; i++) {
          elements[i] = targets[i].getElement();
        }
        refreshElements(elements);
      });
      processUsages(processor, myProject);
    }

    @Nonnull
    @Override
    protected UsageInfo[] findUsages() {
      return BaseRefactoringProcessor.this.findUsages();
    }
  };

  showUsageView(viewDescriptor, factory, usages);
}
 
Example #10
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Factory<JComponent> createTextStatusFactory(final String text, final boolean isError) {
  return new Factory<JComponent>() {
    @Override
    public JComponent create() {
      JLabel label = new JLabel(text);
      label.setForeground(isError ? JBColor.RED : UIUtil.getLabelForeground());
      return label;
    }
  };
}
 
Example #11
Source File: ChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updateProgressComponent(@Nonnull final Factory<JComponent> progress) {
  //noinspection SSBasedInspection
  SwingUtilities.invokeLater(new Runnable() {
    public void run() {
      if (myProgressLabel != null) {
        myProgressLabel.removeAll();
        myProgressLabel.add(progress.create());
        myProgressLabel.setMinimumSize(JBUI.emptySize());
      }
    }
  });
}
 
Example #12
Source File: InspectionToolRegistrar.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * make sure that it is not too late
 */
@Nonnull
public Factory<InspectionToolWrapper> registerInspectionToolFactory(@Nonnull Factory<InspectionToolWrapper> factory, boolean store) {
  if (store) {
    myInspectionToolFactories.add(factory);
  }
  return factory;
}
 
Example #13
Source File: InspectionToolRegistrar.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private Factory<InspectionToolWrapper> registerInspectionTool(@Nonnull final Class aClass) {
  if (LocalInspectionTool.class.isAssignableFrom(aClass)) {
    return registerLocalInspection(aClass, true);
  }
  if (GlobalInspectionTool.class.isAssignableFrom(aClass)) {
    return registerGlobalInspection(aClass, true);
  }
  throw new RuntimeException("unknown inspection class: " + aClass);
}
 
Example #14
Source File: SettingsEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
public SettingsEditor(Factory<Settings> settingsFactory) {
  mySettingsFactory = settingsFactory;
  Disposer.register(this, () -> {
    disposeEditor();
    uninstallWatcher();
  });
}
 
Example #15
Source File: UsageViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return returns null in case of no usages found or usage view not shown for one usage
 */
@javax.annotation.Nullable
public abstract UsageView searchAndShowUsages(@Nonnull UsageTarget[] searchFor,
                                              @Nonnull Factory<UsageSearcher> searcherFactory,
                                              boolean showPanelIfOnlyOneUsage,
                                              boolean showNotFoundMessage,
                                              @Nonnull UsageViewPresentation presentation,
                                              @javax.annotation.Nullable UsageViewStateListener listener);
 
Example #16
Source File: UsageViewManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public UsageView showUsages(@Nonnull UsageTarget[] searchedFor, @Nonnull Usage[] foundUsages, @Nonnull UsageViewPresentation presentation, Factory<UsageSearcher> factory) {
  UsageView usageView = createUsageView(searchedFor, foundUsages, presentation, factory);
  addContent((UsageViewImpl)usageView, presentation);
  showToolWindow(true);
  UIUtil.invokeLaterIfNeeded(() -> {
    if (!((UsageViewImpl)usageView).isDisposed()) {
      ((UsageViewImpl)usageView).expandRoot();
    }
  });
  return usageView;
}
 
Example #17
Source File: UsageViewManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void searchAndShowUsages(@Nonnull UsageTarget[] searchFor,
                                @Nonnull Factory<UsageSearcher> searcherFactory,
                                @Nonnull FindUsagesProcessPresentation processPresentation,
                                @Nonnull UsageViewPresentation presentation,
                                @Nullable UsageViewStateListener listener) {
  doSearchAndShow(searchFor, searcherFactory, presentation, processPresentation, listener);
}
 
Example #18
Source File: UsageViewManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public UsageView searchAndShowUsages(@Nonnull final UsageTarget[] searchFor,
                                     @Nonnull final Factory<UsageSearcher> searcherFactory,
                                     final boolean showPanelIfOnlyOneUsage,
                                     final boolean showNotFoundMessage,
                                     @Nonnull final UsageViewPresentation presentation,
                                     @Nullable final UsageViewStateListener listener) {
  final FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
  processPresentation.setShowNotFoundMessage(showNotFoundMessage);
  processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);

  return doSearchAndShow(searchFor, searcherFactory, presentation, processPresentation, listener);
}
 
Example #19
Source File: CSharpPartialElementManager.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
public CSharpTypeDeclaration getOrCreateCompositeType(@Nonnull final GlobalSearchScope scope, @Nonnull final String vmQName, @Nonnull final Collection<CSharpTypeDeclaration> typeDeclarations)
{
	Map<String, CSharpTypeDeclaration> scopeMap = ContainerUtil.getOrCreate(myCache, scope, (Factory<Map<String, CSharpTypeDeclaration>>) ContainerUtil::createConcurrentWeakValueMap);

	return ContainerUtil.getOrCreate(scopeMap, vmQName, (Factory<CSharpTypeDeclaration>) () -> new CSharpCompositeTypeDeclaration(myProject, scope, ContainerUtil.toArray(typeDeclarations,
			CSharpTypeDeclaration.ARRAY_FACTORY)));
}
 
Example #20
Source File: UsageViewManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private UsageView doSearchAndShow(@Nonnull final UsageTarget[] searchFor,
                                  @Nonnull final Factory<UsageSearcher> searcherFactory,
                                  @Nonnull final UsageViewPresentation presentation,
                                  @Nonnull final FindUsagesProcessPresentation processPresentation,
                                  @Nullable final UsageViewStateListener listener) {
  final SearchScope searchScopeToWarnOfFallingOutOf = getMaxSearchScopeToWarnOfFallingOutOf(searchFor);
  final AtomicReference<UsageViewImpl> usageViewRef = new AtomicReference<>();
  long start = System.currentTimeMillis();
  Task.Backgroundable task = new Task.Backgroundable(myProject, getProgressTitle(presentation), true, new SearchInBackgroundOption()) {
    @Override
    public void run(@Nonnull final ProgressIndicator indicator) {
      new SearchForUsagesRunnable(UsageViewManagerImpl.this, UsageViewManagerImpl.this.myProject, usageViewRef, presentation, searchFor, searcherFactory, processPresentation,
                                  searchScopeToWarnOfFallingOutOf, listener).run();
    }

    @Nonnull
    @Override
    public NotificationInfo getNotificationInfo() {
      UsageViewImpl usageView = usageViewRef.get();
      int count = usageView == null ? 0 : usageView.getUsagesCount();
      String notification = StringUtil.capitalizeWords(UsageViewBundle.message("usages.n", count), true);
      LOG.debug(notification + " in " + (System.currentTimeMillis() - start) + "ms.");
      return new NotificationInfo("Find Usages", "Find Usages Finished", notification);
    }
  };
  ProgressManager.getInstance().run(task);
  return usageViewRef.get();
}
 
Example #21
Source File: UsageViewManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public UsageView createUsageView(@Nonnull UsageTarget[] targets, @Nonnull Usage[] usages, @Nonnull UsageViewPresentation presentation, Factory<UsageSearcher> usageSearcherFactory) {
  UsageViewImpl usageView = new UsageViewImpl(myProject, presentation, targets, usageSearcherFactory);
  appendUsages(usages, usageView);
  usageView.setSearchInProgress(false);
  return usageView;
}
 
Example #22
Source File: FindUsagesProcessPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Factory<ProgressIndicator> getProgressIndicatorFactory() {
  return myProgressIndicatorFactory;
}
 
Example #23
Source File: InspectionToolRegistrar.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private Factory<InspectionToolWrapper> registerGlobalInspection(@Nonnull final Class aClass, boolean store) {
  return registerInspectionToolFactory(() -> new GlobalInspectionToolWrapper((GlobalInspectionTool) InspectionToolsRegistrarCore.instantiateTool(aClass)), store);
}
 
Example #24
Source File: EmptyChangelistBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void reportAdditionalInfo(Factory<JComponent> infoComponent) {
}
 
Example #25
Source File: UpdatingChangeListBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void reportAdditionalInfo(Factory<JComponent> infoComponent) {
  if (myAdditionalInfo == null) {
    myAdditionalInfo = infoComponent;
  }
}
 
Example #26
Source File: UpdatingChangeListBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
public Factory<JComponent> getAdditionalInfo() {
  return myAdditionalInfo;
}
 
Example #27
Source File: FindUsagesProcessPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void setProgressIndicatorFactory(@Nonnull Factory<ProgressIndicator> progressIndicatorFactory) {
  myProgressIndicatorFactory = progressIndicatorFactory;
}
 
Example #28
Source File: MockChangelistBuilder.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public void reportAdditionalInfo(Factory<JComponent> infoComponent) {
    throw new IllegalStateException("not implemented");
}
 
Example #29
Source File: MockChangelistBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void reportAdditionalInfo(Factory<JComponent> infoComponent) {
}
 
Example #30
Source File: PostfixTemplatesSettings.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void disableTemplate(PostfixTemplate template, String langForProvider) {
  Set<String> state = ContainerUtil.getOrCreate(myLangToDisabledTemplates, langForProvider, (Factory<Set<String>>)ContainerUtil::newHashSet);
  state.add(template.getKey());
}