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

The following examples show how to use com.intellij.util.ArrayUtil#mergeArrays() . 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: PsiViewerDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Action[] createActions() {
  AbstractAction copyPsi = new AbstractAction("Cop&y PSI") {
    @Override
    public void actionPerformed(ActionEvent e) {
      PsiElement element = parseText(myEditor.getDocument().getText());
      List<PsiElement> allToParse = new ArrayList<PsiElement>();
      if (element instanceof PsiFile) {
        allToParse.addAll(((PsiFile)element).getViewProvider().getAllFiles());
      }
      else if (element != null) {
        allToParse.add(element);
      }
      String data = "";
      for (PsiElement psiElement : allToParse) {
        data += DebugUtil.psiToString(psiElement, !myShowWhiteSpacesBox.isSelected(), true);
      }
      CopyPasteManager.getInstance().setContents(new StringSelection(data));
    }
  };
  return ArrayUtil.mergeArrays(new Action[]{copyPsi}, super.createActions());
}
 
Example 2
Source File: GutterIntentionMenuContributor.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addActions(@Nonnull Project project,
                               @Nonnull RangeHighlighterEx info,
                               @Nonnull List<? super HighlightInfo.IntentionActionDescriptor> descriptors,
                               @Nonnull DataContext dataContext) {
  final GutterIconRenderer r = info.getGutterIconRenderer();
  if (r == null || DumbService.isDumb(project) && !DumbService.isDumbAware(r)) {
    return;
  }
  List<HighlightInfo.IntentionActionDescriptor> list = new ArrayList<>();
  AtomicInteger order = new AtomicInteger();
  AnAction[] actions = new AnAction[]{r.getClickAction(), r.getMiddleButtonClickAction(), r.getRightButtonClickAction()};
  if (r.getPopupMenuActions() != null) {
    actions = ArrayUtil.mergeArrays(actions, r.getPopupMenuActions().getChildren(null));
  }
  for (AnAction action : actions) {
    if (action != null) {
      addActions(action, list, r, order, dataContext);
    }
  }
  descriptors.addAll(list);
}
 
Example 3
Source File: ConsoleViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void registerConsoleEditorActions() {
  Shortcut[] shortcuts = KeymapUtil.getActiveKeymapShortcuts(IdeActions.ACTION_GOTO_DECLARATION).getShortcuts();
  CustomShortcutSet shortcutSet = new CustomShortcutSet(ArrayUtil.mergeArrays(shortcuts, CommonShortcuts.ENTER.getShortcuts()));
  new HyperlinkNavigationAction().registerCustomShortcutSet(shortcutSet, myEditor.getContentComponent());


  if (!myIsViewer) {
    new EnterHandler().registerCustomShortcutSet(CommonShortcuts.ENTER, myEditor.getContentComponent());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_PASTE, new PasteHandler());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_BACKSPACE, new BackSpaceHandler());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_DELETE, new DeleteHandler());
    registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_TAB, new TabHandler());

    registerActionHandler(myEditor, EOFAction.ACTION_ID);
  }
}
 
Example 4
Source File: ConfigurableWrapper.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CompositeWrapper(ConfigurableEP ep, Configurable... kids) {
  super(ep);
  if (ep.dynamic) {
    kids = ((Composite)getConfigurable()).getConfigurables();
  }
  else if (ep.getChildren() != null) {
    kids = ContainerUtil.mapNotNull(ep.getChildren(), ep1 -> ep1.isAvailable() ? (ConfigurableWrapper)wrapConfigurable(ep1) : null, EMPTY_ARRAY);
  }
  if (ep.childrenEPName != null) {
    ExtensionPoint<Object> childrenEP = getProject(ep).getExtensionPoint(ExtensionPointName.create(ep.childrenEPName));
    Object[] extensions = childrenEP.getExtensions();
    if (extensions.length > 0) {
      if (extensions[0] instanceof ConfigurableEP) {
        Configurable[] children = ContainerUtil.mapNotNull(((ConfigurableEP<Configurable>[])extensions), CONFIGURABLE_FUNCTION, new Configurable[0]);
        kids = ArrayUtil.mergeArrays(kids, children);
      }
      else {
        kids = ArrayUtil.mergeArrays(kids, ((Composite)getConfigurable()).getConfigurables());
      }
    }
  }
  myKids = kids;
}
 
Example 5
Source File: FindUsagesManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
public UsageView doFindUsages(@Nonnull final PsiElement[] primaryElements,
                              @Nonnull final PsiElement[] secondaryElements,
                              @Nonnull final FindUsagesHandler handler,
                              @Nonnull final FindUsagesOptions findUsagesOptions,
                              final boolean toSkipUsagePanelWhenOneUsage) {
  if (primaryElements.length == 0) {
    throw new AssertionError(handler + " " + findUsagesOptions);
  }
  PsiElement2UsageTargetAdapter[] primaryTargets = convertToUsageTargets(Arrays.asList(primaryElements), findUsagesOptions);
  PsiElement2UsageTargetAdapter[] secondaryTargets = convertToUsageTargets(Arrays.asList(secondaryElements), findUsagesOptions);
  PsiElement2UsageTargetAdapter[] targets = ArrayUtil.mergeArrays(primaryTargets, secondaryTargets);
  Factory<UsageSearcher> factory = () -> createUsageSearcher(primaryTargets, secondaryTargets, handler, findUsagesOptions, null);
  UsageView usageView = myAnotherManager.searchAndShowUsages(targets, factory, !toSkipUsagePanelWhenOneUsage, true,
                                                             createPresentation(primaryElements[0], findUsagesOptions, shouldOpenInNewTab()), null);
  myHistory.add(targets[0]);
  return usageView;
}
 
Example 6
Source File: Unity3dRootModuleExtension.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public File[] getFilesForLibraries()
{
	Sdk sdk = getSdk();
	if(sdk == null)
	{
		return EMPTY_FILE_ARRAY;
	}

	String homePath = sdk.getHomePath();
	if(homePath == null)
	{
		return EMPTY_FILE_ARRAY;
	}

	List<String> pathsForLibraries = getPathsForLibraries(homePath, sdk);

	File[] array = EMPTY_FILE_ARRAY;
	for(String pathsForLibrary : pathsForLibraries)
	{
		File dir = new File(pathsForLibrary);
		if(dir.exists())
		{
			File[] files = dir.listFiles();
			if(files != null)
			{
				array = ArrayUtil.mergeArrays(array, files);
			}
		}
	}
	return array;
}
 
Example 7
Source File: HaxeFindUsagesHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@NotNull
@Override
public PsiElement[] getPrimaryElements() {
  // Return the element.  In Java, this checks for the named parameter in overriding methods (and lamdas) and adds them to to search scope.
  // See @{JavaFindUsagesProvider#getPrimaryElements}

  // We check for the presence of overriding methods, et cetera, before we create this handler.
  return ArrayUtil.mergeArrays(super.getPrimaryElements(), extraElementsToSearch);
}
 
Example 8
Source File: LibrariesContainerFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Library[] getAllLibraries() {
  Library[] libraries = getLibraries(LibraryLevel.GLOBAL);
  Library[] projectLibraries = getLibraries(LibraryLevel.PROJECT);
  if (projectLibraries.length > 0) {
    libraries = ArrayUtil.mergeArrays(libraries, projectLibraries);
  }
  Library[] moduleLibraries = getLibraries(LibraryLevel.MODULE);
  if (moduleLibraries.length > 0) {
    libraries = ArrayUtil.mergeArrays(libraries, moduleLibraries);
  }
  return libraries;
}
 
Example 9
Source File: GlobalSearchScope.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public GlobalSearchScope uniteWith(@Nonnull GlobalSearchScope scope) {
  if (scope instanceof UnionScope) {
    GlobalSearchScope[] newScopes = ArrayUtil.mergeArrays(myScopes, ((UnionScope)scope).myScopes);
    return new UnionScope(newScopes);
  }
  return super.uniteWith(scope);
}
 
Example 10
Source File: LabelReference.java    From intellij with Apache License 2.0 5 votes vote down vote up
private BuildLookupElement[] getNonLocalFileLookups(String labelString) {
  BuildLookupElement[] skylarkExtLookups = getSkylarkExtensionLookups(labelString);
  FileLookupData lookupData = FileLookupData.nonLocalFileLookup(labelString, myElement);
  BuildLookupElement[] packageLookups =
      lookupData != null
          ? getReferenceManager().resolvePackageLookupElements(lookupData)
          : BuildLookupElement.EMPTY_ARRAY;
  return ArrayUtil.mergeArrays(skylarkExtLookups, packageLookups);
}
 
Example 11
Source File: ToolWindowLayout.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @return <code>WindowInfo</code>s of all (registered and unregistered) tool windows.
 */
@Nonnull
private WindowInfoImpl[] getAllInfos() {
  final WindowInfoImpl[] registeredInfos = getInfos();
  final WindowInfoImpl[] unregisteredInfos = getUnregisteredInfos();
  myAllInfos = ArrayUtil.mergeArrays(registeredInfos, unregisteredInfos);
  return myAllInfos;
}
 
Example 12
Source File: EncodingUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static Magic8 isSafeToReloadIn(@Nonnull VirtualFile virtualFile, @Nonnull CharSequence text, @Nonnull byte[] bytes, @Nonnull Charset charset) {
  // file has BOM but the charset hasn't
  byte[] bom = virtualFile.getBOM();
  if (bom != null && !CharsetToolkit.canHaveBom(charset, bom)) return Magic8.NO_WAY;

  // the charset has mandatory BOM (e.g. UTF-xx) but the file hasn't or has wrong
  byte[] mandatoryBom = CharsetToolkit.getMandatoryBom(charset);
  if (mandatoryBom != null && !ArrayUtil.startsWith(bytes, mandatoryBom)) return Magic8.NO_WAY;

  String loaded = LoadTextUtil.getTextByBinaryPresentation(bytes, charset).toString();

  String separator = FileDocumentManager.getInstance().getLineSeparator(virtualFile, null);
  String toSave = StringUtil.convertLineSeparators(loaded, separator);

  LoadTextUtil.AutoDetectionReason failReason = LoadTextUtil.getCharsetAutoDetectionReason(virtualFile);
  if (failReason != null && StandardCharsets.UTF_8.equals(virtualFile.getCharset()) && !StandardCharsets.UTF_8.equals(charset)) {
    return Magic8.NO_WAY; // can't reload utf8-autodetected file in another charset
  }

  byte[] bytesToSave;
  try {
    bytesToSave = toSave.getBytes(charset);
  }
  // turned out some crazy charsets have incorrectly implemented .newEncoder() returning null
  catch (UnsupportedOperationException | NullPointerException e) {
    return Magic8.NO_WAY;
  }
  if (bom != null && !ArrayUtil.startsWith(bytesToSave, bom)) {
    bytesToSave = ArrayUtil.mergeArrays(bom, bytesToSave); // for 2-byte encodings String.getBytes(Charset) adds BOM automatically
  }

  return !Arrays.equals(bytesToSave, bytes) ? Magic8.NO_WAY : StringUtil.equals(loaded, text) ? Magic8.ABSOLUTELY : Magic8.WELL_IF_YOU_INSIST;
}
 
Example 13
Source File: FileTemplateManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public FileTemplate[] getTemplates(String category) {
  if (DEFAULT_TEMPLATES_CATEGORY.equals(category)) return ArrayUtil.mergeArrays(getInternalTemplates(), getAllTemplates());
  if (INCLUDES_TEMPLATES_CATEGORY.equals(category)) return getAllPatterns();
  if (CODE_TEMPLATES_CATEGORY.equals(category)) return getAllCodeTemplates();
  if (J2EE_TEMPLATES_CATEGORY.equals(category)) return getAllJ2eeTemplates();
  throw new IllegalArgumentException("Unknown category: " + category);
}
 
Example 14
Source File: ScopePaneSelectInTarget.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canSelect(PsiFileSystemItem fileSystemItem) {
  if (!super.canSelect(fileSystemItem)) return false;
  if (!(fileSystemItem instanceof PsiFile)) return false;
  PsiFile file = (PsiFile) fileSystemItem;
  NamedScopesHolder scopesHolder = DependencyValidationManager.getInstance(myProject);
  NamedScope[] allScopes = scopesHolder.getScopes();
  allScopes = ArrayUtil.mergeArrays(allScopes, NamedScopeManager.getInstance(myProject).getScopes());
  for (NamedScope scope : allScopes) {
    PackageSet packageSet = scope.getValue();
    if (packageSet != null && packageSet.contains(file, scopesHolder)) return true;
  }
  return false;
}
 
Example 15
Source File: ScopeViewPane.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public String[] getSubIds() {
  NamedScope[] scopes = myDependencyValidationManager.getScopes();
  scopes = ArrayUtil.mergeArrays(scopes, myNamedScopeManager.getScopes());
  scopes = NonProjectFilesScope.removeFromList(scopes);
  String[] ids = new String[scopes.length];
  for (int i = 0; i < scopes.length; i++) {
    final NamedScope scope = scopes[i];
    ids[i] = scope.getName();
  }
  return ids;
}
 
Example 16
Source File: GenerateByPatternAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  PatternDescriptor[] patterns = new PatternDescriptor[0];
  PatternProvider[] extensions = Extensions.getExtensions(PatternProvider.EXTENSION_POINT_NAME);
  for (PatternProvider extension : extensions) {
    if (extension.isAvailable(e.getDataContext())) {
      patterns = ArrayUtil.mergeArrays(patterns, extension.getDescriptors());
    }
  }
  GenerateByPatternDialog dialog = new GenerateByPatternDialog(e.getProject(), patterns, e.getDataContext());
  dialog.show();
  if (dialog.isOK()) {
    dialog.getSelectedDescriptor().actionPerformed(e.getDataContext());
  }
}
 
Example 17
Source File: ViewHelperXmlElementDescriptor.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Override
public XmlAttributeDescriptor[] getAttributesDescriptors(@Nullable XmlTag context) {
    Collection<XmlAttributeDescriptor> attributeDescriptors = new ArrayList<>();

    viewHelper.arguments.forEach((s, viewHelperArgument) -> {
        attributeDescriptors.add(new ViewHelperArgumentDescriptor(viewHelper, viewHelperArgument));
    });

    final XmlAttributeDescriptor[] commonAttributes = HtmlNSDescriptorImpl.getCommonAttributeDescriptors(context);

    return ArrayUtil.mergeArrays(attributeDescriptors.toArray(new XmlAttributeDescriptor[0]), commonAttributes);
}
 
Example 18
Source File: HaxeReferenceImpl.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public Object[] getVariants() {
  final Set<HaxeComponentName> suggestedVariants = new HashSet<>();
  final Set<HaxeComponentName> suggestedVariantsExtensions = new HashSet<>();

  // if not first in chain
  // foo.bar.baz
  final HaxeReference leftReference = HaxeResolveUtil.getLeftReference(this);
  HaxeClassResolveResult result = null;
  HaxeClass haxeClass = null;
  String name = null;
  HaxeGenericResolver resolver = null;
  if (leftReference != null) {
    result = leftReference.resolveHaxeClass();
    if (result != HaxeClassResolveResult.EMPTY) {
      haxeClass = result.getHaxeClass();
      if (haxeClass != null) {
        name = haxeClass.getName();
      }
      resolver = result.getSpecialization().toGenericResolver(haxeClass);
    }
  }

  boolean isThis = leftReference instanceof HaxeThisExpression;
  if (leftReference != null && name != null &&
      HaxeResolveUtil.splitQName(leftReference.getText()).getSecond().equals(name)) {

    if (!isInUsingStatement() && !(isInImportStatement() && (haxeClass.isEnum() || haxeClass instanceof HaxeAbstractClassDeclaration))) {
      addClassStaticMembersVariants(suggestedVariants, haxeClass, !(isThis));
    }

    addChildClassVariants(suggestedVariants, haxeClass);
  } else if (leftReference != null && !result.isFunctionType()) {
    if (null == haxeClass) {
      // TODO: fix haxeClass by type inference. Use compiler code assist?!
    }
    if (haxeClass != null) {
      boolean isSuper = leftReference instanceof HaxeSuperExpression;
      PsiElement resolvedValue = leftReference.resolve();
      if (!isSuper && (resolvedValue instanceof HaxeClassDeclaration ||
                       resolvedValue instanceof HaxeAbstractClassDeclaration ||
                       resolvedValue instanceof HaxeInterfaceDeclaration ||
                       resolvedValue instanceof HaxeExternClassDeclaration)) {
        List<HaxeModel> models = HaxeProjectModel.fromElement(this).resolve(new FullyQualifiedInfo("", "Class", null, null));
        if (models != null && !models.isEmpty() && models.get(0) instanceof HaxeClassModel) {
          haxeClass = ((HaxeClassModel)models.get(0)).haxeClass;
        } else {
          haxeClass = null;
        }
      }

      addClassNonStaticMembersVariants(suggestedVariants, haxeClass, resolver,
                                       !(isThis || isSuper));
      addUsingVariants(suggestedVariants, suggestedVariantsExtensions, haxeClass, this);
    }
  } else {
    if (leftReference == null) {
      final boolean isElementInForwardMeta = HaxeAbstractForwardUtil.isElementInForwardMeta(this);
      if (isElementInForwardMeta) {
        addAbstractUnderlyingClassVariants(suggestedVariants, PsiTreeUtil.getParentOfType(this, HaxeClass.class), resolver);
      } else {
        PsiTreeUtil.treeWalkUp(new ComponentNameScopeProcessor(suggestedVariants), this, null, new ResolveState());
        addClassVariants(suggestedVariants, PsiTreeUtil.getParentOfType(this, HaxeClass.class), false);
      }
    }
  }

  Object[] variants = HaxeLookupElement.convert(result, suggestedVariants, suggestedVariantsExtensions).toArray();
  PsiElement leftTarget = leftReference != null ? leftReference.resolve() : null;

  if (leftTarget instanceof PsiPackage) {
    return ArrayUtil.mergeArrays(variants, ((PsiPackage)leftTarget).getSubPackages());
  } else if (leftTarget instanceof HaxeFile) {
    return ArrayUtil.mergeArrays(variants, ((HaxeFile)leftTarget).getClasses());
  } else if (leftReference == null) {
    PsiPackage rootPackage = JavaPsiFacade.getInstance(getElement().getProject()).findPackage("");
    return rootPackage == null ? variants : ArrayUtil.mergeArrays(variants, rootPackage.getSubPackages());
  }
  return variants;
}
 
Example 19
Source File: ConfirmingTrustManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public X509Certificate[] getAcceptedIssuers() {
  return ArrayUtil.mergeArrays(mySystemManager.getAcceptedIssuers(), myCustomManager.getAcceptedIssuers());
}
 
Example 20
Source File: FindInProjectRecents.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public String[] getRecentFindStrings() {
  return ArrayUtil.mergeArrays(FindSettings.getInstance().getRecentFindStrings(), super.getRecentFindStrings());
}