Java Code Examples for com.intellij.openapi.util.Factory

The following are top voted examples for showing how to use com.intellij.openapi.util.Factory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Android-Resource-Usage-Count   File: UsageCountLineProvider.java   View source code 6 votes vote down vote up
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;
}
 
Example 2
Project: Android-Resource-Usage-Count   File: UsageCountLineProvider.java   View source code 6 votes vote down vote up
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;
}
 
Example 3
Project: intellij-ce-playground   File: JavaConstantExpressionEvaluator.java   View source code 6 votes vote down vote up
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);
}
 
Example 4
Project: intellij-ce-playground   File: InferNullityAnnotationsAction.java   View source code 6 votes vote down vote up
@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);
        }
      };
    }
  };
}
 
Example 5
Project: intellij-ce-playground   File: SearchForUsagesRunnable.java   View source code 6 votes vote down vote up
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;
}
 
Example 6
Project: intellij-ce-playground   File: UsageViewManagerImpl.java   View source code 6 votes vote down vote up
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();
}
 
Example 7
Project: intellij-ce-playground   File: FindUsagesManager.java   View source code 6 votes vote down vote up
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]);
}
 
Example 8
Project: intellij-ce-playground   File: FindInProjectUtil.java   View source code 6 votes vote down vote up
@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;
}
 
Example 9
Project: intellij-ce-playground   File: NavigationGutterIconBuilder.java   View source code 6 votes vote down vote up
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);
    }
  };
}
 
Example 10
Project: intellij-ce-playground   File: AbstractDomChildDescriptionImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 11
Project: intellij-ce-playground   File: DomFileEditor.java   View source code 6 votes vote down vote up
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;
    }
  };
}
 
Example 12
Project: intellij-ce-playground   File: DomBasicsTest.java   View source code 6 votes vote down vote up
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());
}
 
Example 13
Project: intellij-ce-playground   File: AndroidInferNullityAnnotationAction.java   View source code 6 votes vote down vote up
@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);
        }
      };
    }
  };
}
 
Example 14
Project: intellij-ce-playground   File: UIPropertyBinding.java   View source code 6 votes vote down vote up
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);
}
 
Example 15
Project: intellij-ce-playground   File: BranchInfo.java   View source code 6 votes vote down vote up
@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;
  }
}
 
Example 16
Project: intellij-ce-playground   File: JavaLanguageInjectionSupport.java   View source code 6 votes vote down vote up
@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);
      }
    }
  };
}
 
Example 17
Project: intellij-ce-playground   File: XmlLanguageInjectionSupport.java   View source code 6 votes vote down vote up
@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);
      }
    }
  };
}
 
Example 18
Project: intellij-pants-plugin   File: PantsCommonSourceRootModifier.java   View source code 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 19
Project: tools-idea   File: JavaConstantExpressionEvaluator.java   View source code 6 votes vote down vote up
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);

}
 
Example 20
Project: tools-idea   File: InspectionToolRegistrar.java   View source code 6 votes vote down vote up
@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;
}
 
Example 21
Project: tools-idea   File: FindInProjectUtil.java   View source code 6 votes vote down vote up
@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;
}
 
Example 22
Project: tools-idea   File: MapReduceIndex.java   View source code 6 votes vote down vote up
@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;
}
 
Example 23
Project: tools-idea   File: AbstractDomChildDescriptionImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 24
Project: tools-idea   File: DomFileEditor.java   View source code 6 votes vote down vote up
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;
    }
  };
}
 
Example 25
Project: tools-idea   File: DomBasicsTest.java   View source code 6 votes vote down vote up
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());
}
 
Example 26
Project: tools-idea   File: UIPropertyBinding.java   View source code 6 votes vote down vote up
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);
}
 
Example 27
Project: tools-idea   File: JavaLanguageInjectionSupport.java   View source code 6 votes vote down vote up
@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);
      }
    }
  };
}
 
Example 28
Project: tools-idea   File: XmlLanguageInjectionSupport.java   View source code 6 votes vote down vote up
@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);
      }
    }
  };
}
 
Example 29
Project: consulo-apache-ant   File: UIPropertyBinding.java   View source code 6 votes vote down vote up
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);
}
 
Example 30
Project: consulo-javaee   File: JamCommonUtil.java   View source code 6 votes vote down vote up
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);
}
 
Example 31
Project: consulo   File: SearchForUsagesRunnable.java   View source code 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 32
Project: consulo   File: InspectionToolRegistrar.java   View source code 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 33
Project: consulo   File: ChangesViewManager.java   View source code 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 34
Project: consulo   File: FindUsagesManager.java   View source code 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 35
Project: consulo-xml   File: AbstractDomChildDescriptionImpl.java   View source code 6 votes vote down vote up
@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;
}
 
Example 36
Project: consulo-xml   File: DomBasicsTest.java   View source code 6 votes vote down vote up
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());
}
 
Example 37
Project: consulo-xml   File: XmlLanguageInjectionSupport.java   View source code 6 votes vote down vote up
@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);
      }
    }
  };
}
 
Example 38
Project: consulo-xml   File: DomFileEditor.java   View source code 6 votes vote down vote up
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;
    }
  };
}
 
Example 39
Project: consulo-javascript   File: JsonObjectDescriptor.java   View source code 6 votes vote down vote up
@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);
		}
	});
}
 
Example 40
Project: consulo-java   File: JavaConstantExpressionEvaluator.java   View source code 6 votes vote down vote up
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);

}