Java Code Examples for com.intellij.util.containers.ContainerUtil#addAllNotNull()

The following examples show how to use com.intellij.util.containers.ContainerUtil#addAllNotNull() . 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: PhpGotoDeclarationHandler.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
    if(psiElement == null) {
        return null;
    }

    Set<PsiElement> psiElements = new HashSet<>();
    for (final GotoCompletionContributor contributor : CONTRIBUTORS) {
        if(!contributor.getPattern().accepts(psiElement)) {
            continue;
        }

        PsiElement[] targets = contributor.getGotoDeclarationTargets(psiElement, i, editor);
        if(targets != null && targets.length > 0) {
            ContainerUtil.addAllNotNull(psiElements, targets);
        }
    }

    return psiElements.toArray(new PsiElement[psiElements.size()]);    }
 
Example 2
Source File: PhpGotoDeclarationHandler.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
@Nullable
@Override
public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement psiElement, int i, Editor editor) {
    if(psiElement == null) {
        return null;
    }

    Set<PsiElement> psiElements = new HashSet<>();
    for (final GotoCompletionContributor contributor : CONTRIBUTORS) {
        if(!contributor.getPattern().accepts(psiElement)) {
            continue;
        }

        PsiElement[] targets = contributor.getGotoDeclarationTargets(psiElement, i, editor);
        if(targets != null && targets.length > 0) {
            ContainerUtil.addAllNotNull(psiElements, targets);
        }
    }

    return psiElements.toArray(new PsiElement[psiElements.size()]);    }
 
Example 3
Source File: GitLanguage.java    From idea-gitignore with MIT License 6 votes vote down vote up
/**
 * Returns outer files for the current language.
 *
 * @param project current project
 * @return outer files
 */
@NotNull
@Override
public Set<VirtualFile> getOuterFiles(@NotNull final Project project, boolean dumb) {
    final int key = new HashCodeBuilder().append(project).append(getFileType()).toHashCode();

    if (dumb || (fetched && outerFiles.get(key) != null)) {
        return super.getOuterFiles(project, true);
    }

    fetched = true;
    final Set<VirtualFile> parentFiles = super.getOuterFiles(project, false);
    final ArrayList<VirtualFile> files = new ArrayList<>(ContainerUtil.filter(
            IgnoreFilesIndex.getFiles(project, GitExcludeFileType.INSTANCE),
            virtualFile -> Utils.isInProject(virtualFile, project)
    ));

    ContainerUtil.addAllNotNull(parentFiles, files);
    return outerFiles.getOrElse(key, new HashSet<>());
}
 
Example 4
Source File: FoldingModelSupport.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addRange(int[] starts, int[] ends) {
  List<FoldedBlock> result = new ArrayList<FoldedBlock>(3);
  int[] rangeStarts = new int[myCount];
  int[] rangeEnds = new int[myCount];

  for (int number = 0; ; number++) {
    int shift = getRangeShift(mySettings.range, number);
    if (shift == -1) break;

    for (int i = 0; i < myCount; i++) {
      rangeStarts[i] = bound(starts[i] + shift, i);
      rangeEnds[i] = bound(ends[i] - shift, i);
    }
    ContainerUtil.addAllNotNull(result, createRange(rangeStarts, rangeEnds, myExpandSuggester.isExpanded(rangeStarts, rangeEnds)));
  }

  if (result.size() > 0) {
    FoldedBlock[] block = ContainerUtil.toArray(result, new FoldedBlock[result.size()]);
    for (FoldedBlock folding : block) {
      folding.installHighlighter(block);
    }
    myFoldings.add(block);
  }
}
 
Example 5
Source File: AbstractModelBuilderTest.java    From intellij-quarkus with Eclipse Public License 2.0 5 votes vote down vote up
@NotNull
private Set<Class> getToolingExtensionClasses() {
  final Set<Class> classes = ContainerUtil.set(
    ExternalProject.class,
    // gradle-tooling-extension-api jar
    ProjectImportAction.class,
    // gradle-tooling-extension-impl jar
    ModelBuildScriptClasspathBuilderImpl.class,
    Multimap.class,
    ShortTypeHandling.class
  );

  ContainerUtil.addAllNotNull(classes, doGetToolingExtensionClasses());
  return classes;
}
 
Example 6
Source File: GlobalStringClassGoto.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
public static PsiElement[] getPsiElements(@NotNull Project project, @NotNull String contents) {

    Collection<PsiElement> psiElements = new HashSet<>();
    contents = contents.replaceAll("\\\\+", "\\\\");

    // DateTime
    // date
    Matcher matcher = Pattern.compile("^([\\w\\\\-]+)$").matcher(contents);
    if (matcher.find()) {
        PhpIndex phpIndex = PhpIndex.getInstance(project);

        ContainerUtil.addAllNotNull(psiElements, phpIndex.getAnyByFQN(contents));
        ContainerUtil.addAllNotNull(psiElements, phpIndex.getFunctionsByName(contents));

        return psiElements.toArray(new PsiElement[psiElements.size()]);
    }

    // DateTime:format
    // DateTime::format
    matcher = Pattern.compile("^([\\w\\\\-]+):+([\\w_\\-]+)$").matcher(contents);
    if (matcher.find()) {
        for (PhpClass phpClass : PhpIndex.getInstance(project).getAnyByFQN(matcher.group(1))) {
            ContainerUtil.addIfNotNull(psiElements, phpClass.findMethodByName(matcher.group(2)));
        }
        return psiElements.toArray(new PsiElement[psiElements.size()]);
    }

    return psiElements.toArray(new PsiElement[psiElements.size()]);
}
 
Example 7
Source File: GlobalStringClassGoto.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@NotNull
public static PsiElement[] getPsiElements(@NotNull Project project, @NotNull String contents) {

    Collection<PsiElement> psiElements = new HashSet<>();
    contents = contents.replaceAll("\\\\+", "\\\\");

    // DateTime
    // date
    Matcher matcher = Pattern.compile("^([\\w\\\\-]+)$").matcher(contents);
    if (matcher.find()) {
        PhpIndex phpIndex = PhpIndex.getInstance(project);

        ContainerUtil.addAllNotNull(psiElements, phpIndex.getAnyByFQN(contents));
        ContainerUtil.addAllNotNull(psiElements, phpIndex.getFunctionsByName(contents));

        return psiElements.toArray(new PsiElement[psiElements.size()]);
    }

    // DateTime:format
    // DateTime::format
    matcher = Pattern.compile("^([\\w\\\\-]+):+([\\w_\\-]+)$").matcher(contents);
    if (matcher.find()) {
        for (PhpClass phpClass : PhpIndex.getInstance(project).getAnyByFQN(matcher.group(1))) {
            ContainerUtil.addIfNotNull(psiElements, phpClass.findMethodByName(matcher.group(2)));
        }
        return psiElements.toArray(new PsiElement[psiElements.size()]);
    }

    return psiElements.toArray(new PsiElement[psiElements.size()]);
}
 
Example 8
Source File: IgnoreLanguage.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Returns outer files for the current language.
 *
 * @param project current project
 * @return outer files
 */
@NotNull
public Set<VirtualFile> getOuterFiles(@NotNull final Project project, boolean dumb) {
    final int key = new HashCodeBuilder().append(project).append(getFileType()).toHashCode();
    if (outerFiles.get(key) == null) {
        final Set<VirtualFile> files = new HashSet<>();
        for (OuterIgnoreLoaderComponent.OuterFileFetcher fetcher : getOuterFileFetchers()) {
            ContainerUtil.addAllNotNull(files, fetcher.fetch(project));
        }
        outerFiles.set(key, files);
    }
    return outerFiles.getOrElse(key, new HashSet<>());
}
 
Example 9
Source File: FileManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<PsiFile> getAllCachedFiles() {
  List<PsiFile> files = new ArrayList<>();
  for (VirtualFile file : new ArrayList<>(getVFileToViewProviderMap().keySet())) {
    FileViewProvider provider = findCachedViewProvider(file);
    if (provider != null) {
      ContainerUtil.addAllNotNull(files, ((AbstractFileViewProvider)provider).getCachedPsiFiles());
    }
  }
  return files;
}
 
Example 10
Source File: Problems.java    From intellij-haskforce with Apache License 2.0 4 votes vote down vote up
public void addAllNotNull(Iterable<? extends HaskellProblem> elements) {
    if (elements != null) {
        ContainerUtil.addAllNotNull(this, elements);
    }
}
 
Example 11
Source File: SmartEnterProcessorWithFixers.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void addEnterProcessors(FixEnterProcessor... processors) {
  ContainerUtil.addAllNotNull(myEnterProcessors, processors);
}
 
Example 12
Source File: SmartEnterProcessorWithFixers.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected void addFixers(Fixer<? extends SmartEnterProcessorWithFixers>... fixers) {
  ContainerUtil.addAllNotNull(myFixers, fixers);
}