Java 类com.intellij.openapi.util.Factory 实例源码

项目:Android-Resource-Usage-Count    文件:UsageCountLineProvider.java   
private int findTagUsage(XmlTag element) {
    final FindUsagesHandler handler = FindUsageUtils.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 FindUsageUtils.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;
}
项目:Android-Resource-Usage-Count    文件:UsageCountLineProvider.java   
private int findTagUsage(XmlTag element) {
    final FindUsagesHandler handler = FindUsageUtils.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 FindUsageUtils.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;
}
项目:intellij-ce-playground    文件:JavaConstantExpressionEvaluator.java   
private JavaConstantExpressionEvaluator(Set<PsiVariable> visitedVars,
                                        final boolean throwExceptionOnOverflow,
                                        @NotNull Project project,
                                        final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) {
  myMapFactory = auxEvaluator == null ? new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      final Key<CachedValue<ConcurrentMap<PsiElement, Object>>> key =
        throwExceptionOnOverflow ? CONSTANT_VALUE_WITH_OVERFLOW_MAP_KEY : CONSTANT_VALUE_WO_OVERFLOW_MAP_KEY;
      return CachedValuesManager.getManager(myProject).getCachedValue(myProject, key, PROVIDER, false);
    }
  } : new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      return auxEvaluator.getCacheMap(throwExceptionOnOverflow);
    }
  };
  myProject = project;
  myConstantExpressionVisitor = new ConstantExpressionVisitor(visitedVars, throwExceptionOnOverflow, auxEvaluator);
}
项目:intellij-ce-playground    文件:InferNullityAnnotationsAction.java   
@NotNull
private Factory<UsageSearcher> rerunFactory(@NotNull final Project project, @NotNull final AnalysisScope scope) {
  return new Factory<UsageSearcher>() {
    @Override
    public UsageSearcher create() {
      return new UsageInfoSearcherAdapter() {
        @Override
        protected UsageInfo[] findUsages() {
          return InferNullityAnnotationsAction.this.findUsages(project, scope, scope.getFileCount());
        }

        @Override
        public void generate(@NotNull Processor<Usage> processor) {
          processUsages(processor, project);
        }
      };
    }
  };
}
项目:intellij-ce-playground    文件:SearchForUsagesRunnable.java   
SearchForUsagesRunnable(@NotNull UsageViewManagerImpl usageViewManager,
                        @NotNull Project project,
                        @NotNull AtomicReference<UsageViewImpl> usageViewRef,
                        @NotNull UsageViewPresentation presentation,
                        @NotNull UsageTarget[] searchFor,
                        @NotNull Factory<UsageSearcher> searcherFactory,
                        @NotNull FindUsagesProcessPresentation processPresentation,
                        @NotNull SearchScope searchScopeToWarnOfFallingOutOf,
                        @Nullable UsageViewManager.UsageViewStateListener listener) {
  myProject = project;
  myUsageViewRef = usageViewRef;
  myPresentation = presentation;
  mySearchFor = searchFor;
  mySearcherFactory = searcherFactory;
  myProcessPresentation = processPresentation;
  mySearchScopeToWarnOfFallingOutOf = searchScopeToWarnOfFallingOutOf;
  myListener = listener;
  myUsageViewManager = usageViewManager;
}
项目:intellij-ce-playground    文件:UsageViewManagerImpl.java   
private UsageView doSearchAndShow(@NotNull final UsageTarget[] searchFor,
                                  @NotNull final Factory<UsageSearcher> searcherFactory,
                                  @NotNull final UsageViewPresentation presentation,
                                  @NotNull final FindUsagesProcessPresentation processPresentation,
                                  @Nullable final UsageViewStateListener listener) {
  final SearchScope searchScopeToWarnOfFallingOutOf = getMaxSearchScopeToWarnOfFallingOutOf(searchFor);
  final AtomicReference<UsageViewImpl> usageViewRef = new AtomicReference<UsageViewImpl>();

  Task.Backgroundable task = new Task.Backgroundable(myProject, getProgressTitle(presentation), true, new SearchInBackgroundOption()) {
    @Override
    public void run(@NotNull final ProgressIndicator indicator) {
      new SearchForUsagesRunnable(UsageViewManagerImpl.this, UsageViewManagerImpl.this.myProject, usageViewRef, presentation, searchFor, searcherFactory,
                                  processPresentation, searchScopeToWarnOfFallingOutOf, listener).run();
    }

    @Override
    @Nullable
    public NotificationInfo getNotificationInfo() {
      String notification = usageViewRef.get() != null ? usageViewRef.get().getUsagesCount() + " Usage(s) Found" : "No Usages Found";
      return new NotificationInfo("Find Usages", "Find Usages Finished", notification);
    }
  };
  ProgressManager.getInstance().run(task);
  return usageViewRef.get();
}
项目:intellij-ce-playground    文件:FindUsagesManager.java   
public void findUsages(@NotNull final PsiElement[] primaryElements,
                       @NotNull final PsiElement[] secondaryElements,
                       @NotNull final FindUsagesHandler handler,
                       @NotNull final FindUsagesOptions findUsagesOptions,
                       final boolean toSkipUsagePanelWhenOneUsage) {
  if (primaryElements.length == 0) {
    throw new AssertionError(handler + " " + findUsagesOptions);
  }
  Iterable<PsiElement> allElements = ContainerUtil.concat(primaryElements, secondaryElements);
  final PsiElement2UsageTargetAdapter[] targets = convertToUsageTargets(allElements, findUsagesOptions);
  myAnotherManager.searchAndShowUsages(targets, new Factory<UsageSearcher>() {
    @Override
    public UsageSearcher create() {
      return createUsageSearcher(primaryElements, secondaryElements, handler, findUsagesOptions, null);
    }
  }, !toSkipUsagePanelWhenOneUsage, true, createPresentation(primaryElements[0], findUsagesOptions, shouldOpenInNewTab()), null);
  myHistory.add(targets[0]);
}
项目:intellij-ce-playground    文件:FindInProjectUtil.java   
@NotNull
public static FindUsagesProcessPresentation setupProcessPresentation(@NotNull final Project project,
                                                                     final boolean showPanelIfOnlyOneUsage,
                                                                     @NotNull final UsageViewPresentation presentation) {
  FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation(presentation);
  processPresentation.setShowNotFoundMessage(true);
  processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);
  processPresentation.setProgressIndicatorFactory(
    new Factory<ProgressIndicator>() {
      @NotNull
      @Override
      public ProgressIndicator create() {
        return new FindProgressIndicator(project, presentation.getScopeText());
      }
    }
  );
  return processPresentation;
}
项目:intellij-ce-playground    文件:NavigationGutterIconBuilder.java   
private static <T> NotNullLazyValue<List<SmartPsiElementPointer>> createPointersThunk(boolean lazy,
                                                                                      final Project project,
                                                                                      final Factory<Collection<T>> targets,
                                                                                      final NotNullFunction<T, Collection<? extends PsiElement>> converter) {
  if (!lazy) {
    return NotNullLazyValue.createConstantValue(calcPsiTargets(project, targets.create(), converter));
  }

  return new NotNullLazyValue<List<SmartPsiElementPointer>>() {
    @Override
    @NotNull
    public List<SmartPsiElementPointer> compute() {
      return calcPsiTargets(project, targets.create(), converter);
    }
  };
}
项目:intellij-ce-playground    文件:AbstractDomChildDescriptionImpl.java   
@Override
@NotNull
public final List<? extends DomElement> getStableValues(@NotNull final DomElement parent) {
  final List<? extends DomElement> list = getValues(parent);
  final ArrayList<DomElement> result = new ArrayList<DomElement>(list.size());
  final DomManager domManager = parent.getManager();
  for (int i = 0; i < list.size(); i++) {
    final int i1 = i;
    result.add(domManager.createStableValue(new Factory<DomElement>() {
      @Override
      @Nullable
      public DomElement create() {
        if (!parent.isValid()) return null;

        final List<? extends DomElement> domElements = getValues(parent);
        return domElements.size() > i1 ? domElements.get(i1) : null;
      }
    }));
  }
  return result;
}
项目:intellij-ce-playground    文件:DomFileEditor.java   
public static DomFileEditor createDomFileEditor(final String name,
                                                @Nullable final Icon icon,
                                                final DomElement element,
                                                final Factory<? extends CommittablePanel> committablePanel) {

  final XmlFile file = DomUtil.getFile(element);
  final Factory<BasicDomElementComponent> factory = new Factory<BasicDomElementComponent>() {
    @Override
    public BasicDomElementComponent create() {

      CaptionComponent captionComponent = new CaptionComponent(name, icon);
      captionComponent.initErrorPanel(element);
      BasicDomElementComponent component = createComponentWithCaption(committablePanel.create(), captionComponent, element);
      Disposer.register(component, captionComponent);
      return component;
    }
  };
  return new DomFileEditor<BasicDomElementComponent>(file.getProject(), file.getVirtualFile(), name, factory) {
    @Override
    public JComponent getPreferredFocusedComponent() {
      return null;
    }
  };
}
项目:intellij-ce-playground    文件:DomBasicsTest.java   
public void testStable_Revalidate() throws Throwable {
  final MyElement[] element = new MyElement[]{createElement("")};
  final MyElement stable = getDomManager().createStableValue(new Factory<MyElement>() {
    @Override
    public MyElement create() {
      return element[0];
    }
  });
  MyElement oldElement = element[0];
  ((StableElement) stable).revalidate();
  assertSame(oldElement, ((StableElement) stable).getWrappedElement());

  element[0] = createElement("");
  assertTrue(oldElement.isValid());
  ((StableElement) stable).revalidate();
  assertTrue(oldElement.isValid());
  assertNotSame(oldElement, ((StableElement) stable).getWrappedElement());
  assertSame(element[0], ((StableElement) stable).getWrappedElement());
}
项目:intellij-ce-playground    文件:AndroidInferNullityAnnotationAction.java   
@NotNull
private static Factory<UsageSearcher> rerunFactory(@NotNull final Project project, @NotNull final AnalysisScope scope) {
  return new Factory<UsageSearcher>() {
    @Override
    public UsageSearcher create() {
      return new UsageInfoSearcherAdapter() {
        @Override
        protected UsageInfo[] findUsages() {
          return AndroidInferNullityAnnotationAction.findUsages(project, scope, scope.getFileCount());
        }

        @Override
        public void generate(@NotNull Processor<Usage> processor) {
          processUsages(processor, project);
        }
      };
    }
  };
}
项目:intellij-ce-playground    文件:UIPropertyBinding.java   
public void addAddManyFacility(JButton button, final Factory<List<T>> factory) {
  button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      List<T> items = factory.create();
      getList().requestFocusInWindow();
      if (items == null || items.size() == 0) {
        return;
      }
      for (final T item : items) {
        getModel().addElement(item);
        ScrollingUtil.selectItem(getList(), item);
      }
    }
  });
  addComponent(button);
}
项目:intellij-ce-playground    文件:BranchInfo.java   
@NotNull
public SvnMergeInfoCache.MergeCheckResult checkList(@NotNull final SvnChangeList list, final String branchPath) {
  synchronized (myCalculatedLock) {
    SvnMergeInfoCache.MergeCheckResult result;
    final long revision = calculateCopyRevision(branchPath);
    if (revision != -1 && revision >= list.getNumber()) {
      result = SvnMergeInfoCache.MergeCheckResult.COMMON;
    }
    else {
      result = ContainerUtil.getOrCreate(myAlreadyCalculatedMap, list.getNumber(), new Factory<SvnMergeInfoCache.MergeCheckResult>() {
        @Override
        public SvnMergeInfoCache.MergeCheckResult create() {
          return checkAlive(list, branchPath);
        }
      });
    }
    return result;
  }
}
项目:intellij-ce-playground    文件:JavaLanguageInjectionSupport.java   
@Override
public AnAction createEditAction(final Project project, final Factory<BaseInjection> producer) {
  return new AnAction() {
    @Override
    public void actionPerformed(final AnActionEvent e) {
      final BaseInjection originalInjection = producer.create();
      final MethodParameterInjection injection = createFrom(project, originalInjection, null, false);
      if (injection != null) {
        final boolean mergeEnabled = !project.isInitialized() || 
          JavaPsiFacade.getInstance(project).findClass(injection.getClassName(), GlobalSearchScope.allScope(project)) == null;
        final BaseInjection newInjection = showInjectionUI(project, injection);
        if (newInjection != null) {
          newInjection.mergeOriginalPlacesFrom(originalInjection, mergeEnabled);
          originalInjection.copyFrom(newInjection);
        }
      }
      else {
        createDefaultEditAction(project, producer).actionPerformed(null);
      }
    }
  };
}
项目:intellij-ce-playground    文件:XmlLanguageInjectionSupport.java   
@Override
public AnAction createEditAction(final Project project, final Factory<BaseInjection> producer) {
  return new AnAction() {
    @Override
    public void actionPerformed(final AnActionEvent e) {
      final BaseInjection originalInjection = producer.create();
      final BaseInjection injection = createFrom(originalInjection);
      if (injection != null) {
        final BaseInjection newInjection = showInjectionUI(project, injection);
        if (newInjection != null) {
          originalInjection.copyFrom(newInjection);
        }
      }
      else {
        createDefaultEditAction(project, producer).actionPerformed(null);
      }
    }
  };
}
项目:intellij-ce-playground    文件:XPathEvalAction.java   
private void showUsageView(final Editor editor, final XPath xPath, final XmlElement contextNode, final List<?> result) {
    final Project project = editor.getProject();

    //noinspection unchecked
    final List<?> _result = new ArrayList(result);
    final Factory<UsageSearcher> searcherFactory = new Factory<UsageSearcher>() {
        @Override
        public UsageSearcher create() {
            return new MyUsageSearcher(_result, xPath, contextNode);
        }
    };
    final MyUsageTarget usageTarget = new MyUsageTarget(xPath.toString(), contextNode);

    showUsageView(project, usageTarget, searcherFactory, new EditExpressionAction() {
        final Config config = myComponent.getConfig();

        @Override
        protected void execute() {
            XPathEvalAction.this.execute(editor);
        }
    });
}
项目:intellij-pants-plugin    文件:PantsCommonSourceRootModifier.java   
@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;
}
项目:tools-idea    文件:JavaConstantExpressionEvaluator.java   
private JavaConstantExpressionEvaluator(Set<PsiVariable> visitedVars, final boolean throwExceptionOnOverflow, final Project project, final PsiConstantEvaluationHelper.AuxEvaluator auxEvaluator) {
  myMapFactory = auxEvaluator != null ? new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      return auxEvaluator.getCacheMap(throwExceptionOnOverflow);
    }
  } : new Factory<ConcurrentMap<PsiElement, Object>>() {
    @Override
    public ConcurrentMap<PsiElement, Object> create() {
      final Key<CachedValue<ConcurrentMap<PsiElement, Object>>> key =
        throwExceptionOnOverflow ? CONSTANT_VALUE_WITH_OVERFLOW_MAP_KEY : CONSTANT_VALUE_WO_OVERFLOW_MAP_KEY;
      return CachedValuesManager.getManager(myProject).getCachedValue(myProject, key, PROVIDER, false);
    }
  };
  myProject = project;
  myConstantExpressionVisitor = new ConstantExpressionVisitor(visitedVars, throwExceptionOnOverflow, auxEvaluator);

}
项目:tools-idea    文件:InspectionToolRegistrar.java   
@NotNull
@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;
}
项目:tools-idea    文件:FindInProjectUtil.java   
@NotNull
public static FindUsagesProcessPresentation setupProcessPresentation(final Project project,
                                                                     final boolean showPanelIfOnlyOneUsage,
                                                                     @NotNull final UsageViewPresentation presentation) {
  FindUsagesProcessPresentation processPresentation = new FindUsagesProcessPresentation();
  processPresentation.setShowNotFoundMessage(true);
  processPresentation.setShowFindOptionsPrompt(false);
  processPresentation.setShowPanelIfOnlyOneUsage(showPanelIfOnlyOneUsage);
  processPresentation.setProgressIndicatorFactory(
    new Factory<ProgressIndicator>() {
      @NotNull
      @Override
      public ProgressIndicator create() {
        return new FindProgressIndicator(project, presentation.getScopeText());
      }
    }
  );
  return processPresentation;
}
项目:tools-idea    文件:MapReduceIndex.java   
@Nullable
private PersistentHashMap<Integer, Collection<Key>> createInputsIndex() throws IOException {
  Factory<PersistentHashMap<Integer, Collection<Key>>> factory = myInputsIndexFactory;
  if (factory != null) {
    try {
      return factory.create();
    }
    catch (RuntimeException e) {
      if (e.getCause() instanceof IOException) {
        throw (IOException)e.getCause();
      }
      throw e;
    }
  }
  return null;
}
项目:tools-idea    文件:AbstractDomChildDescriptionImpl.java   
@NotNull
public final List<? extends DomElement> getStableValues(@NotNull final DomElement parent) {
  final List<? extends DomElement> list = getValues(parent);
  final ArrayList<DomElement> result = new ArrayList<DomElement>(list.size());
  final DomManager domManager = parent.getManager();
  for (int i = 0; i < list.size(); i++) {
    final int i1 = i;
    result.add(domManager.createStableValue(new Factory<DomElement>() {
      @Nullable
      public DomElement create() {
        if (!parent.isValid()) return null;

        final List<? extends DomElement> domElements = getValues(parent);
        return domElements.size() > i1 ? domElements.get(i1) : null;
      }
    }));
  }
  return result;
}
项目:tools-idea    文件:DomFileEditor.java   
public static DomFileEditor createDomFileEditor(final String name,
                                                @Nullable final Icon icon,
                                                final DomElement element,
                                                final Factory<? extends CommittablePanel> committablePanel) {

  final XmlFile file = DomUtil.getFile(element);
  final Factory<BasicDomElementComponent> factory = new Factory<BasicDomElementComponent>() {
    public BasicDomElementComponent create() {

      CaptionComponent captionComponent = new CaptionComponent(name, icon);
      captionComponent.initErrorPanel(element);
      BasicDomElementComponent component = createComponentWithCaption(committablePanel.create(), captionComponent, element);
      Disposer.register(component, captionComponent);
      return component;
    }
  };
  return new DomFileEditor<BasicDomElementComponent>(file.getProject(), file.getVirtualFile(), name, factory) {
    public JComponent getPreferredFocusedComponent() {
      return null;
    }
  };
}
项目:tools-idea    文件:DomBasicsTest.java   
public void testStable_Revalidate() throws Throwable {
  final MyElement[] element = new MyElement[]{createElement("")};
  final MyElement stable = getDomManager().createStableValue(new Factory<MyElement>() {
    @Override
    public MyElement create() {
      return element[0];
    }
  });
  MyElement oldElement = element[0];
  ((StableElement) stable).revalidate();
  assertSame(oldElement, ((StableElement) stable).getWrappedElement());

  element[0] = createElement("");
  assertTrue(oldElement.isValid());
  ((StableElement) stable).revalidate();
  assertTrue(oldElement.isValid());
  assertNotSame(oldElement, ((StableElement) stable).getWrappedElement());
  assertSame(element[0], ((StableElement) stable).getWrappedElement());
}
项目:tools-idea    文件:UIPropertyBinding.java   
public void addAddManyFacility(JButton button, final Factory<List<T>> factory) {
  button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      List<T> items = factory.create();
      getList().requestFocusInWindow();
      if (items == null || items.size() == 0) {
        return;
      }
      for (final T item : items) {
        getModel().addElement(item);
        ListScrollingUtil.selectItem(getList(), item);
      }
    }
  });
  addComponent(button);
}
项目:tools-idea    文件:JavaLanguageInjectionSupport.java   
@Override
public AnAction createEditAction(final Project project, final Factory<BaseInjection> producer) {
  return new AnAction() {
    @Override
    public void actionPerformed(final AnActionEvent e) {
      final BaseInjection originalInjection = producer.create();
      final MethodParameterInjection injection = createFrom(project, originalInjection, null, false);
      if (injection != null) {
        final boolean mergeEnabled = !project.isInitialized() || 
          JavaPsiFacade.getInstance(project).findClass(injection.getClassName(), GlobalSearchScope.allScope(project)) == null;
        final BaseInjection newInjection = showInjectionUI(project, injection);
        if (newInjection != null) {
          newInjection.mergeOriginalPlacesFrom(originalInjection, mergeEnabled);
          originalInjection.copyFrom(newInjection);
        }
      }
      else {
        createDefaultEditAction(project, producer).actionPerformed(null);
      }
    }
  };
}
项目:tools-idea    文件:XmlLanguageInjectionSupport.java   
@Override
public AnAction createEditAction(final Project project, final Factory<BaseInjection> producer) {
  return new AnAction() {
    @Override
    public void actionPerformed(final AnActionEvent e) {
      final BaseInjection originalInjection = producer.create();
      final BaseInjection injection = createFrom(originalInjection);
      if (injection != null) {
        final BaseInjection newInjection = showInjectionUI(project, injection);
        if (newInjection != null) {
          originalInjection.copyFrom(newInjection);
        }
      }
      else {
        createDefaultEditAction(project, producer).actionPerformed(null);
      }
    }
  };
}
项目:consulo-apache-ant    文件:UIPropertyBinding.java   
public void addAddManyFacility(JButton button, final Factory<List<T>> factory) {
  button.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      List<T> items = factory.create();
      getList().requestFocusInWindow();
      if (items == null || items.size() == 0) {
        return;
      }
      for (final T item : items) {
        getModel().addElement(item);
        ListScrollingUtil.selectItem(getList(), item);
      }
    }
  });
  addComponent(button);
}
项目:consulo-javaee    文件:JamCommonUtil.java   
public static <T extends JamElement> CachedValue<List<T>> createClassCachedValue(final Project project, final Factory<GlobalSearchScope> scope, final JamClassMeta<? extends T>... meta)
{
    return CachedValuesManager.getManager(project).createCachedValue(() ->
    {
        GlobalSearchScope searchScope = scope.create();
        final JamService jamService = JamService.getJamService(project);
        List<T> result = new ArrayList<>();
        if(!DumbService.isDumb(project))
        {
            for(JamClassMeta<? extends T> classMeta : meta)
            {
                for(JamAnnotationMeta annotationMeta : classMeta.getRootAnnotations())
                {
                    result.addAll(jamService.getJamClassElements(classMeta, annotationMeta.getAnnoName(), searchScope));
                }
            }
        }
        return new Result<>(result, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
    }, false);
}
项目:consulo    文件:SearchForUsagesRunnable.java   
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;
}
项目:consulo    文件:InspectionToolRegistrar.java   
@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;
}
项目:consulo    文件:ChangesViewManager.java   
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);
  }
}
项目:consulo    文件:FindUsagesManager.java   
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;
}
项目:consulo-xml    文件:AbstractDomChildDescriptionImpl.java   
@NotNull
public final List<? extends DomElement> getStableValues(@NotNull final DomElement parent) {
  final List<? extends DomElement> list = getValues(parent);
  final ArrayList<DomElement> result = new ArrayList<DomElement>(list.size());
  final DomManager domManager = parent.getManager();
  for (int i = 0; i < list.size(); i++) {
    final int i1 = i;
    result.add(domManager.createStableValue(new Factory<DomElement>() {
      @Nullable
      public DomElement create() {
        if (!parent.isValid()) return null;

        final List<? extends DomElement> domElements = getValues(parent);
        return domElements.size() > i1 ? domElements.get(i1) : null;
      }
    }));
  }
  return result;
}
项目:consulo-xml    文件:DomBasicsTest.java   
public void testStable_Revalidate() throws Throwable {
  final MyElement[] element = new MyElement[]{createElement("")};
  final MyElement stable = getDomManager().createStableValue(new Factory<MyElement>() {
    @Override
    public MyElement create() {
      return element[0];
    }
  });
  MyElement oldElement = element[0];
  ((StableElement) stable).revalidate();
  assertSame(oldElement, ((StableElement) stable).getWrappedElement());

  element[0] = createElement("");
  assertTrue(oldElement.isValid());
  ((StableElement) stable).revalidate();
  assertTrue(oldElement.isValid());
  assertNotSame(oldElement, ((StableElement) stable).getWrappedElement());
  assertSame(element[0], ((StableElement) stable).getWrappedElement());
}
项目:consulo-xml    文件:XmlLanguageInjectionSupport.java   
@Override
public AnAction createEditAction(final Project project, final Factory<BaseInjection> producer) {
  return new AnAction() {
    @Override
    public void actionPerformed(final AnActionEvent e) {
      final BaseInjection originalInjection = producer.create();
      final BaseInjection injection = createFrom(originalInjection);
      if (injection != null) {
        final BaseInjection newInjection = showInjectionUI(project, injection);
        if (newInjection != null) {
          originalInjection.copyFrom(newInjection);
        }
      }
      else {
        createDefaultEditAction(project, producer).actionPerformed(null);
      }
    }
  };
}
项目:consulo-xml    文件:DomFileEditor.java   
public static DomFileEditor createDomFileEditor(final String name,
                                                @Nullable final Icon icon,
                                                final DomElement element,
                                                final Factory<? extends CommittablePanel> committablePanel) {

  final XmlFile file = DomUtil.getFile(element);
  final Factory<BasicDomElementComponent> factory = new Factory<BasicDomElementComponent>() {
    public BasicDomElementComponent create() {

      CaptionComponent captionComponent = new CaptionComponent(name, icon);
      captionComponent.initErrorPanel(element);
      BasicDomElementComponent component = createComponentWithCaption(committablePanel.create(), captionComponent, element);
      Disposer.register(component, captionComponent);
      return component;
    }
  };
  return new DomFileEditor<BasicDomElementComponent>(file.getProject(), file.getVirtualFile(), name, factory) {
    public JComponent getPreferredFocusedComponent() {
      return null;
    }
  };
}
项目:consulo-javascript    文件:JsonObjectDescriptor.java   
@NotNull
public JsonPropertyDescriptor addProperty(@Nullable final String propertyName, @NotNull final Class<?> value)
{
    if(value == Object.class)
    {
        throw new IllegalArgumentException("We cant add object type, use JsonObjectDescriptor as parameter");
    }

    return ContainerUtil.getOrCreate(myProperties, propertyName, new Factory<JsonPropertyDescriptor>()
    {
        @Override
        public JsonPropertyDescriptor create()
        {
            return new JsonPropertyDescriptor(propertyName, value);
        }
    });
}