public static Collection<RunContentDescriptor> findRunningConsole(
      final Project project,
      @NotNull final NotNullFunction<RunContentDescriptor, Boolean> descriptorMatcher) {
    final ExecutionManager executionManager = ExecutionManager.getInstance(project);

    final RunContentDescriptor selectedContent =
        executionManager.getContentManager().getSelectedContent();
    if (selectedContent != null) {
      final ToolWindow toolWindow =
          ExecutionManager.getInstance(project)
              .getContentManager()
              .getToolWindowByDescriptor(selectedContent);
      if (toolWindow != null && toolWindow.isVisible()) {
        if (descriptorMatcher.fun(selectedContent)) {
          return Collections.singletonList(selectedContent);
        }
      }
    }

    final ArrayList<RunContentDescriptor> result = Lists.newArrayList();
    final RunContentDescriptor[] runContentDescriptors =
        ((RunContentManagerImpl) executionManager.getContentManager()).getAllDescriptors();
    for (RunContentDescriptor runContentDescriptor : runContentDescriptors) {
      if (descriptorMatcher.fun(runContentDescriptor)) {
        result.add(runContentDescriptor);
      }
    }
    return result;
  }
  public boolean isMain(@NotNull JetNamedFunction function) {
    if (!"main".equals(function.getName())) return false;

    FunctionDescriptor functionDescriptor = getFunctionDescriptor.fun(function);
    List<ValueParameterDescriptor> parameters = functionDescriptor.getValueParameters();
    if (parameters.size() != 1) return false;

    ValueParameterDescriptor parameter = parameters.get(0);
    JetType parameterType = parameter.getType();
    if (!KotlinBuiltIns.isArray(parameterType)) return false;

    List<TypeProjection> typeArguments = parameterType.getArguments();
    if (typeArguments.size() != 1) return false;

    JetType typeArgument = typeArguments.get(0).getType();
    if (!JetTypeChecker.DEFAULT.equalTypes(
        typeArgument, getBuiltIns(functionDescriptor).getStringType())) return false;

    if (DescriptorUtils.isTopLevelDeclaration(functionDescriptor)) return true;

    DeclarationDescriptor containingDeclaration = functionDescriptor.getContainingDeclaration();
    return containingDeclaration instanceof ClassDescriptor
        && ((ClassDescriptor) containingDeclaration).getKind().isSingleton()
        && AnnotationsPackage.hasPlatformStaticAnnotation(functionDescriptor);
  }
 @NotNull
 private ColumnInfo[] generateColumns(@NotNull List<PostfixTemplate> templates) {
   String longestTemplateName = "";
   String longestDescription = "";
   String longestExample = "";
   for (PostfixTemplate template : templates) {
     longestTemplateName = longestString(longestTemplateName, GET_SHORTCUT_FUNCTION.fun(template));
     longestDescription =
         longestString(longestDescription, GET_DESCRIPTION_FUNCTION.fun(template));
     longestExample = longestString(longestExample, GET_EXAMPLE_FUNCTION.fun(template));
   }
   return new ColumnInfo[] {
     new BooleanColumnInfo(),
     new StringColumnInfo("Shortcut", GET_SHORTCUT_FUNCTION, longestTemplateName),
     new StringColumnInfo("Description", GET_DESCRIPTION_FUNCTION, longestDescription),
     new StringColumnInfo("Example", GET_EXAMPLE_FUNCTION, longestExample),
   };
 }
 @NotNull
 private TIntObjectHashMap<SmartList<VcsRef>> prepareRefsToIndicesMap(
     @NotNull Collection<VcsRef> refs) {
   TIntObjectHashMap<SmartList<VcsRef>> map = new TIntObjectHashMap<SmartList<VcsRef>>();
   for (VcsRef ref : refs) {
     int index = myIndexGetter.fun(ref.getCommitHash());
     SmartList<VcsRef> list = map.get(index);
     if (list == null) map.put(index, list = new SmartList<VcsRef>());
     list.add(ref);
   }
   return map;
 }
 public V getCachedValue(T key) {
   SofterReference<ConcurrentMap<T, V>> ref = myCache;
   ConcurrentMap<T, V> map = ref == null ? null : ref.get();
   if (map == null) {
     myCache = new SofterReference<ConcurrentMap<T, V>>(map = ContainerUtil.newConcurrentMap());
   }
   V value = map.get(key);
   if (value == null) {
     map.put(key, value = myValueProvider.fun(key));
   }
   return value;
 }
示例#6
0
 public static <T, U, S extends U> List<S> convert(
     @NotNull final Collection<T> in,
     final Convertor<T, S> convertor,
     @Nullable final NotNullFunction<U, Boolean> outFilter) {
   final List<S> out = new ArrayList<S>();
   for (T t : in) {
     final S converted = convertor.convert(t);
     if ((outFilter != null) && (!Boolean.TRUE.equals(outFilter.fun(converted)))) continue;
     out.add(converted);
   }
   return out;
 }
 public static List<RunContentDescriptor> collectConsolesByDisplayName(
     final Project project, @NotNull NotNullFunction<String, Boolean> titleMatcher) {
   List<RunContentDescriptor> result = Lists.newArrayList();
   final ExecutionManager executionManager = ExecutionManager.getInstance(project);
   final RunContentDescriptor[] runContentDescriptors =
       ((RunContentManagerImpl) executionManager.getContentManager()).getAllDescriptors();
   for (RunContentDescriptor runContentDescriptor : runContentDescriptors) {
     if (titleMatcher.fun(runContentDescriptor.getDisplayName())) {
       result.add(runContentDescriptor);
     }
   }
   return result;
 }
 private boolean isEmptyRefs(@NotNull Collection<VcsRef> refs, int head) {
   if (refs.isEmpty()) {
     if (!myErrorWasReported.containsKey(head)) {
       myErrorWasReported.put(head, head);
       LOG.error(
           "No references found at head "
               + head
               + " which corresponds to hash "
               + myHashGetter.fun(head));
     }
     return true;
   }
   return false;
 }
 @NotNull
 public GrExpression getElementToReplace(@NotNull GrMethodCallExpression call) {
   return myElementToReplace == null ? call : myElementToReplace.fun(call);
 }