Java Code Examples for com.intellij.util.ArrayUtil#toObjectArray()

The following examples show how to use com.intellij.util.ArrayUtil#toObjectArray() . 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: VcsSelectionHistoryDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull @NonNls Key<?> dataId) {
  if (CommonDataKeys.PROJECT == dataId) {
    return myProject;
  }
  else if (VcsDataKeys.VCS_VIRTUAL_FILE == dataId) {
    return myFile;
  }
  else if (VcsDataKeys.VCS_FILE_REVISION == dataId) {
    VcsFileRevision selectedObject = myList.getSelectedObject();
    return selectedObject instanceof CurrentRevision ? null : selectedObject;
  }
  else if (VcsDataKeys.VCS_FILE_REVISIONS == dataId) {
    List<VcsFileRevision> revisions = ContainerUtil.filter(myList.getSelectedObjects(), Conditions.notEqualTo(myLocalRevision));
    return ArrayUtil.toObjectArray(revisions, VcsFileRevision.class);
  }
  else if (VcsDataKeys.VCS == dataId) {
    return myActiveVcs.getKeyInstanceMethod();
  }
  else if (PlatformDataKeys.HELP_ID == dataId) {
    return myHelpId;
  }
  return null;
}
 
Example 2
Source File: PlatformTestUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static int doPrint(StringBuilder buffer,
                           int currentLevel,
                           Object node,
                           AbstractTreeStructure structure,
                           @javax.annotation.Nullable Comparator comparator,
                           int maxRowCount,
                           int currentLine,
                           char paddingChar,
                           @javax.annotation.Nullable Queryable.PrintInfo printInfo) {
  if (currentLine >= maxRowCount && maxRowCount != -1) return currentLine;

  StringUtil.repeatSymbol(buffer, paddingChar, currentLevel);
  buffer.append(toString(node, printInfo)).append("\n");
  currentLine++;
  Object[] children = structure.getChildElements(node);

  if (comparator != null) {
    ArrayList<?> list = new ArrayList<Object>(Arrays.asList(children));
    @SuppressWarnings({"UnnecessaryLocalVariable", "unchecked"}) Comparator<Object> c = comparator;
    Collections.sort(list, c);
    children = ArrayUtil.toObjectArray(list);
  }
  for (Object child : children) {
    currentLine = doPrint(buffer, currentLevel + 1, child, structure, comparator, maxRowCount, currentLine, paddingChar, printInfo);
  }

  return currentLine;
}
 
Example 3
Source File: ThriftUnresolvedSymbolInspection.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
  final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
  new ThriftVisitor() {
    @Override
    public void visitCustomType(@NotNull ThriftCustomType type) {
      for (PsiReference reference : type.getReferences()) {
        if (reference.resolve() == null) {
          result.add(manager.createProblemDescriptor(
            reference.getElement(),
            reference.getRangeInElement(),
            getDisplayName(),
            ProblemHighlightType.ERROR,
            isOnTheFly
          ));
        }
      }
    }

    public void visitElement(PsiElement element) {
      super.visitElement(element);
      element.acceptChildren(this);
    }
  }.visitFile(file);
  return ArrayUtil.toObjectArray(result, ProblemDescriptor.class);
}
 
Example 4
Source File: RouteList.java    From railways with MIT License 5 votes vote down vote up
/**
 * Returns an array of routes that have specified name. As several routes can have the same name (they
 * can differ by method - POST, GET, etc.) the method can return arrays with several elements.
 *
 * @param name Route name to search
 * @return Array of routes or empty route array if nothing is found.
 */
public Route[] getRoutesByName(String name) {
    if (namesIndex.size() == 0)
        reindexRouteNames();

    List<Route> value = namesIndex.get(name);
    if (value == null)
        return new Route[0];

    return ArrayUtil.toObjectArray(value, Route.class);
}
 
Example 5
Source File: UsefulPsiTreeUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nullable
public static <T extends PsiElement> T[] getChildrenOfType(@Nullable PsiElement element,
		@Nonnull Class<T> aClass,
		@Nullable PsiElement lastParent)
{
	if(element == null)
	{
		return null;
	}

	List<T> result = null;
	for(PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling())
	{
		if(lastParent == child)
		{
			break;
		}
		if(aClass.isInstance(child))
		{
			if(result == null)
			{
				result = new SmartList<T>();
			}
			//noinspection unchecked
			result.add((T) child);
		}
	}
	return result == null ? null : ArrayUtil.toObjectArray(result, aClass);
}
 
Example 6
Source File: ThriftUnresolvedIncludeInspection.java    From intellij-thrift with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
  final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
  new ThriftVisitor() {

    @Override
    public void visitInclude(@NotNull ThriftInclude include) {
      if (ThriftPsiUtil.resolveInclude(include) == null) {
        PsiElement lastChild = include.getLastChild();
        result.add(manager.createProblemDescriptor(
          lastChild,
          TextRange.from(0, lastChild.getTextLength()),
          getDisplayName(),
          ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
          isOnTheFly
        ));
      }
    }

    public void visitElement(PsiElement element) {
      super.visitElement(element);
      element.acceptChildren(this);
    }
  }.visitFile(file);
  return ArrayUtil.toObjectArray(result, ProblemDescriptor.class);
}
 
Example 7
Source File: NotificationsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public <T extends Notification> T[] getNotificationsOfType(@Nonnull Class<T> klass, @Nullable final Project project) {
  final List<T> result = new ArrayList<T>();
  if (project == null || !project.isDefault() && !project.isDisposed()) {
    for (Notification notification : EventLog.getLogModel(project).getNotifications()) {
      if (klass.isInstance(notification)) {
        //noinspection unchecked
        result.add((T)notification);
      }
    }
  }
  return ArrayUtil.toObjectArray(result, klass);
}
 
Example 8
Source File: FileStructureDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] getChildElements(Object element) {
  Object[] childElements = super.getChildElements(element);

  if (!myShouldNarrowDown) {
    return childElements;
  }

  String enteredPrefix = myCommanderPanel.getEnteredPrefix();
  if (enteredPrefix == null) {
    return childElements;
  }

  ArrayList<Object> filteredElements = new ArrayList<Object>(childElements.length);
  SpeedSearchComparator speedSearchComparator = createSpeedSearchComparator();

  for (Object child : childElements) {
    if (child instanceof AbstractTreeNode) {
      Object value = ((AbstractTreeNode)child).getValue();
      if (value instanceof TreeElement) {
        String name = ((TreeElement)value).getPresentation().getPresentableText();
        if (name == null) {
          continue;
        }
        if (speedSearchComparator.matchingFragments(enteredPrefix, name) == null) {
          continue;
        }
      }
    }
    filteredElements.add(child);
  }
  return ArrayUtil.toObjectArray(filteredElements);
}
 
Example 9
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Object[] getSelectedElements() {
  if (myTreeBuilder == null || myTreeBuilder.isDisposed()) return ArrayUtil.EMPTY_OBJECT_ARRAY;
  final TreePath[] selectionPaths = myTreeBuilder.getTree().getSelectionPaths();
  if (selectionPaths == null) {
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
  }
  List<Object> elements = new ArrayList<Object>();
  for (TreePath selectionPath : selectionPaths) {
    final Object pathElement = getPathElement(selectionPath);
    if (pathElement != null) {
      elements.add(pathElement);
    }
  }
  return ArrayUtil.toObjectArray(elements);
}
 
Example 10
Source File: DuplexConsoleView.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AnAction[] createConsoleActions() {
  List<AnAction> actions = Lists.newArrayList();
  actions.addAll(
          mergeConsoleActions(Arrays.asList(myPrimaryConsoleView.createConsoleActions()), Arrays.asList(mySecondaryConsoleView.createConsoleActions())));
  actions.add(mySwitchConsoleAction);

  LanguageConsoleView langConsole = ContainerUtil.findInstance(Arrays.asList(myPrimaryConsoleView, mySecondaryConsoleView), LanguageConsoleView.class);
  ConsoleHistoryController controller = langConsole != null ? ConsoleHistoryController.getController(langConsole) : null;
  if (controller != null) actions.add(controller.getBrowseHistory());

  return ArrayUtil.toObjectArray(actions, AnAction.class);
}
 
Example 11
Source File: ExtractSuperclassHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkConflicts(final ExtractSuperclassDialog dialog) {
  final MemberInfo[] infos = ArrayUtil.toObjectArray(dialog.getSelectedMemberInfos(), MemberInfo.class);
  final PsiDirectory targetDirectory = dialog.getTargetDirectory();
  final PsiPackage targetPackage;
  if (targetDirectory != null) {
    targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
  }
  else {
    targetPackage = null;
  }
  final MultiMap<PsiElement,String> conflicts = new MultiMap<PsiElement, String>();
  if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override
        public void run() {
          final PsiClass superClass =
            mySubclass.getExtendsListTypes().length > 0 || mySubclass instanceof PsiAnonymousClass ? mySubclass.getSuperClass() : null;
          conflicts.putAllValues(PullUpConflictsUtil.checkConflicts(infos, mySubclass, superClass, targetPackage, targetDirectory,
                                                                    dialog.getContainmentVerifier(), false));
        }
      });
    }
  }, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) return false;
  ExtractSuperClassUtil.checkSuperAccessible(targetDirectory, conflicts, mySubclass);
  return ExtractSuperClassUtil.showConflicts(dialog, conflicts, myProject);
}
 
Example 12
Source File: PackagingElementNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Object[] getEqualityObjects() {
  return ArrayUtil.toObjectArray(myPackagingElements);
}
 
Example 13
Source File: ThriftDuplicatesInspection.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
  final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
  final Set<String> topLevelNames = new HashSet<String>();
  new ThriftVisitor() {
    @Override
    public void visitTopLevelDeclaration(@NotNull ThriftTopLevelDeclaration o) {
      ThriftDefinitionName topIdentifier = o.getIdentifier();
      if (topIdentifier != null && !topLevelNames.add(topIdentifier.getText())) {
        // Repeated top level names
        result.add(manager.createProblemDescriptor(
          topIdentifier,
          getDisplayName(),
          true,
          ProblemHighlightType.ERROR,
          isOnTheFly
        ));
      }

      Set<String> fieldNames = new HashSet<String>();
      Set<String> fieldIds = new HashSet<String>();
      for (ThriftDeclaration d : o.findSubDeclarations()) {
        ThriftDefinitionName identifier = d.getIdentifier();
        if (identifier != null && !fieldNames.add(identifier.getText())) {
          // Repeated field names
          result.add(manager.createProblemDescriptor(
            identifier,
            getDisplayName(),
            true,
            ProblemHighlightType.ERROR,
            isOnTheFly
          ));
        }

        ThriftFieldID fieldID = PsiTreeUtil.getChildOfType(d, ThriftFieldID.class);
        if (fieldID != null && !fieldIds.add(fieldID.getText())) {
          //Reapted fieldIDs
          result.add(manager.createProblemDescriptor(
            fieldID,
            getDisplayName(),
            true,
            ProblemHighlightType.ERROR,
            isOnTheFly
          ));
        }
      }
    }

    public void visitElement(PsiElement element) {
      super.visitElement(element);
      element.acceptChildren(this);
    }
  }.visitFile(file);
  return ArrayUtil.toObjectArray(result, ProblemDescriptor.class);
}
 
Example 14
Source File: ExtractSuperclassDialog.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
protected ExtractSuperBaseProcessor createProcessor() {
  return new ExtractSuperClassProcessor(myProject, getTargetDirectory(), getExtractedSuperName(),
                                        mySourceClass, ArrayUtil.toObjectArray(getSelectedMemberInfos(), MemberInfo.class), false,
                                        new DocCommentPolicy(getDocCommentPolicy()));
}
 
Example 15
Source File: FileTreeStructure.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Object[] getChildElements(Object nodeElement) {
  if (!(nodeElement instanceof FileElement)) {
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
  }

  FileElement element = (FileElement)nodeElement;
  VirtualFile file = element.getFile();

  if (file == null || !file.isValid()) {
    if (element == myRootElement) {
      return myRootElement.getChildren();
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
  }

  VirtualFile[] children = null;

  if (element.isArchive() && myChooserDescriptor.isChooseJarContents()) {
    String path = file.getPath();
    if (!(file.getFileSystem() instanceof ArchiveFileSystem)) {
      file = ((ArchiveFileType)file.getFileType()).getFileSystem().findLocalVirtualFileByPath(path);
    }
    if (file != null) {
      children = file.getChildren();
    }
  }
  else {
    children = file.getChildren();
  }

  if (children == null) {
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
  }

  Set<FileElement> childrenSet = new HashSet<FileElement>();
  for (VirtualFile child : children) {
    if (myChooserDescriptor.isFileVisible(child, myShowHidden)) {
      final FileElement childElement = new FileElement(child, child.getName());
      childElement.setParent(element);
      childrenSet.add(childElement);
    }
  }
  return ArrayUtil.toObjectArray(childrenSet);
}
 
Example 16
Source File: HaxeCalleeMethodsTreeStructure.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@NotNull
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
  final HaxeHierarchyTimeoutHandler timeoutHandler = new HaxeHierarchyTimeoutHandler();

  try {
    final PsiMember enclosingElement = ((CallHierarchyNodeDescriptor)descriptor).getEnclosingElement();
    if (!(enclosingElement instanceof PsiMethod)) {
      return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final PsiMethod method = (PsiMethod)enclosingElement;

    final ArrayList<PsiMethod> methods = new ArrayList<PsiMethod>();

    final PsiCodeBlock body = method.getBody();
    if (body != null) {
      visitor(body, methods);
    }

    final PsiMethod baseMethod = (PsiMethod)((CallHierarchyNodeDescriptor)getBaseDescriptor()).getTargetElement();
    final PsiClass baseClass = baseMethod.getContainingClass();

    final HashMap<PsiMethod, CallHierarchyNodeDescriptor> methodToDescriptorMap = new HashMap<PsiMethod, CallHierarchyNodeDescriptor>();

    final ArrayList<CallHierarchyNodeDescriptor> result = new ArrayList<CallHierarchyNodeDescriptor>();

    for (final PsiMethod calledMethod : methods) {
      if (timeoutHandler.checkAndCancelIfNecessary()) {
        break;
      }

      if (!isInScope(baseClass, calledMethod, myScopeType)) continue;

      CallHierarchyNodeDescriptor d = methodToDescriptorMap.get(calledMethod);
      if (d == null) {
        d = new CallHierarchyNodeDescriptor(myProject, descriptor, calledMethod, false, false);
        methodToDescriptorMap.put(calledMethod, d);
        result.add(d);
      }
      else {
        d.incrementUsageCount();
      }
    }

    // also add overriding methods as children
    if (!timeoutHandler.isCanceled()) {
      Query<PsiMethod> query = HaxeMethodsSearch.search(method, timeoutHandler);
      query.forEach(new Processor<PsiMethod>() {
        @Override
        public boolean process(PsiMethod overridingMethod) {
          if (isInScope(baseClass, overridingMethod, myScopeType)) {
            final CallHierarchyNodeDescriptor node =
              new CallHierarchyNodeDescriptor(myProject, descriptor, overridingMethod, false, false);
            if (!result.contains(node)) result.add(node);
          }
          return timeoutHandler.checkAndCancelIfNecessary();
        }
      });
    }

    return ArrayUtil.toObjectArray(result);

  } finally {
    // This is in a finally clause because a cancellation would otherwise throw
    // right past us.

    timeoutHandler.stop(); // Clean up.
    if (timeoutHandler.isCanceled()) {
      timeoutHandler.postCanceledDialog(myProject);
    }
  }
}
 
Example 17
Source File: UpdaterTreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Object[] getToExpand() {
  return ArrayUtil.toObjectArray(myToExpand.keySet());
}
 
Example 18
Source File: UpdaterTreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Object[] getToSelect() {
  return ArrayUtil.toObjectArray(myToSelect.keySet());
}
 
Example 19
Source File: LogConsoleManagerBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void dispose() {
  for (AdditionalTabComponent component : ArrayUtil.toObjectArray(myAdditionalContent.keySet(), AdditionalTabComponent.class)) {
    removeAdditionalTabComponent(component);
  }
}
 
Example 20
Source File: CachedValueProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static <T> Result<T> create(@Nullable T value, Collection<?> dependencies) {
  return new Result<T>(value, ArrayUtil.toObjectArray(dependencies));
}