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

The following examples show how to use com.intellij.util.containers.ContainerUtil#addIfNotNull() . 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: CC0003.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public List<HighlightInfoFactory> check(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull CSharpIndexAccessExpressionImpl expression)
{
	DotNetExpression qualifier = expression.getQualifier();
	if(qualifier.toTypeRef(false) instanceof CSharpDynamicTypeRef)
	{
		return Collections.emptyList();
	}
	List<PsiElement> ranges = new ArrayList<>(2);
	CSharpCallArgumentList parameterList = expression.getParameterList();
	if(parameterList != null)
	{
		ContainerUtil.addIfNotNull(ranges, parameterList.getOpenElement());
		ContainerUtil.addIfNotNull(ranges, parameterList.getCloseElement());
	}

	if(ranges.isEmpty())
	{
		return Collections.emptyList();
	}
	return CC0001.checkReference(expression, ranges);
}
 
Example 2
Source File: ConfigUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
public static Collection<PsiElement> getTreeSignatureTargets(@NotNull Project project, @NotNull String key, @NotNull Collection<String> classes) {
    Collection<PsiElement> psiElements = new ArrayList<>();

    Collection<PhpClass> phpClasses = new HashSet<>();
    for (String aClass : classes) {
        ContainerUtil.addIfNotNull(phpClasses, PhpElementsUtil.getClass(project, aClass));
    }

    visitTreeSignatures(phpClasses, treeVisitor -> {
        if(key.equalsIgnoreCase(treeVisitor.contents)) {
            psiElements.add(treeVisitor.psiElement);
        }
    });

    return psiElements;
}
 
Example 3
Source File: ConfigUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
public static Collection<PsiElement> getTreeSignatureTargets(@NotNull Project project, @NotNull String key) {
    Map<String, Collection<String>> signatures = getTreeSignatures(project);
    if(!signatures.containsKey(key)) {
        return Collections.emptyList();
    }

    Collection<PhpClass> phpClasses = new HashSet<>();
    for (String aClass : signatures.get(key)) {
        ContainerUtil.addIfNotNull(phpClasses, PhpElementsUtil.getClass(project, aClass));
    }

    Collection<PsiElement> psiElements = new ArrayList<>();
    visitTreeSignatures(phpClasses, treeVisitor -> {
        if(key.equalsIgnoreCase(treeVisitor.contents)) {
            psiElements.add(treeVisitor.psiElement);
        }
    });

    return psiElements;
}
 
Example 4
Source File: RootIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static OrderEntry[] calcOrderEntries(@Nonnull RootInfo info,
                                             @Nonnull MultiMap<VirtualFile, OrderEntry> depEntries,
                                             @Nonnull MultiMap<VirtualFile, OrderEntry> libClassRootEntries,
                                             @Nonnull MultiMap<VirtualFile, OrderEntry> libSourceRootEntries,
                                             @Nonnull List<VirtualFile> hierarchy) {
  @Nullable VirtualFile libraryClassRoot = info.findLibraryRootInfo(hierarchy, false);
  @Nullable VirtualFile librarySourceRoot = info.findLibraryRootInfo(hierarchy, true);
  Set<OrderEntry> orderEntries = ContainerUtil.newLinkedHashSet();
  orderEntries.addAll(info.getLibraryOrderEntries(hierarchy, libraryClassRoot, librarySourceRoot, libClassRootEntries, libSourceRootEntries));
  for (VirtualFile root : hierarchy) {
    orderEntries.addAll(depEntries.get(root));
  }
  VirtualFile moduleContentRoot = info.findModuleRootInfo(hierarchy);
  if (moduleContentRoot != null) {
    ContainerUtil.addIfNotNull(orderEntries, info.getModuleSourceEntry(hierarchy, moduleContentRoot, libClassRootEntries));
  }
  if (orderEntries.isEmpty()) {
    return null;
  }

  OrderEntry[] array = orderEntries.toArray(new OrderEntry[orderEntries.size()]);
  Arrays.sort(array, RootIndex.BY_OWNER_MODULE);
  return array;
}
 
Example 5
Source File: TreeState.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void applySelectedTo(@Nonnull JTree tree) {
  List<TreePath> selection = new ArrayList<>();
  for (List<PathElement> path : mySelectedPaths) {
    TreeModel model = tree.getModel();
    TreePath treePath = new TreePath(model.getRoot());
    for (int i = 1; treePath != null && i < path.size(); i++) {
      treePath = findMatchedChild(model, treePath, path.get(i));
    }
    ContainerUtil.addIfNotNull(selection, treePath);
  }
  if (selection.isEmpty()) return;
  tree.setSelectionPaths(selection.toArray(TreeUtil.EMPTY_TREE_PATH));
  if (myScrollToSelection) {
    TreeUtil.showRowCentered(tree, tree.getRowForPath(selection.get(0)), true, true);
  }
}
 
Example 6
Source File: RouteHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
public static List<Route> getRoutesOnControllerAction(@NotNull Method method) {
    Set<String> routeNames = new HashSet<>();

    ContainerUtil.addIfNotNull(routeNames, RouteHelper.convertMethodToRouteControllerName(method));
    ContainerUtil.addIfNotNull(routeNames, RouteHelper.convertMethodToRouteShortcutControllerName(method));

    Map<String, Route> allRoutes = getAllRoutes(method.getProject());
    List<Route> routes = new ArrayList<>();

    // resolve indexed routes
    if(routeNames.size() > 0) {
        routes.addAll(allRoutes.values().stream()
            .filter(route -> route.getController() != null && routeNames.contains(route.getController()))
            .collect(Collectors.toList())
        );
    }

    // search for services
    routes.addAll(
        ServiceRouteContainer.build(allRoutes).getMethodMatches(method)
    );

    return routes;
}
 
Example 7
Source File: CSharpLookupElementBuilder.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
public static LookupElement[] buildToLookupElements(@Nonnull PsiElement[] arguments)
{
	if(arguments.length == 0)
	{
		return LookupElement.EMPTY_ARRAY;
	}

	List<LookupElement> list = new ArrayList<>(arguments.length);
	for(PsiElement argument : arguments)
	{
		ContainerUtil.addIfNotNull(list, buildLookupElementWithContextType(argument, null, DotNetGenericExtractor.EMPTY, null));
	}
	return list.toArray(new LookupElement[list.size()]);
}
 
Example 8
Source File: LibraryRootsComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Set<VirtualFile> getNotExcludedRoots() {
  Set<VirtualFile> roots = new LinkedHashSet<VirtualFile>();
  String[] excludedRootUrls = getLibraryEditor().getExcludedRootUrls();
  Set<VirtualFile> excludedRoots = new HashSet<VirtualFile>();
  for (String url : excludedRootUrls) {
    ContainerUtil.addIfNotNull(excludedRoots, VirtualFileManager.getInstance().findFileByUrl(url));
  }
  for (OrderRootType type : OrderRootType.getAllTypes()) {
    VirtualFile[] files = getLibraryEditor().getFiles(type);
    for (VirtualFile file : files) {
      if (!VfsUtilCore.isUnder(file, excludedRoots)) {
        roots.add(PathUtil.getLocalFile(file));
      }
    }
  }
  return roots;
}
 
Example 9
Source File: BaseCSharpModuleExtension.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public PsiElement[] getEntryPointElements()
{
	final List<DotNetTypeDeclaration> typeDeclarations = new ArrayList<DotNetTypeDeclaration>();
	Collection<DotNetLikeMethodDeclaration> methods = MethodIndex.getInstance().get("Main", getProject(), GlobalSearchScope.moduleScope(getModule()));
	for(DotNetLikeMethodDeclaration method : methods)
	{
		if(method instanceof CSharpMethodDeclaration && DotNetRunUtil.isEntryPoint((DotNetMethodDeclaration) method))
		{
			Module moduleForPsiElement = ModuleUtilCore.findModuleForPsiElement(method);
			// scope is broken?
			if(!getModule().equals(moduleForPsiElement))
			{
				continue;
			}
			ContainerUtil.addIfNotNull(typeDeclarations, ObjectUtil.tryCast(method.getParent(), DotNetTypeDeclaration.class));
		}
	}
	return ContainerUtil.toArray(typeDeclarations, DotNetTypeDeclaration.ARRAY_FACTORY);
}
 
Example 10
Source File: CSharpTypeListElementType.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Override
public CSharpTypeListStub createStub(@Nonnull DotNetTypeList dotNetTypeList, StubElement stubElement)
{
	DotNetType[] types = dotNetTypeList.getTypes();
	List<String> typeRefs = new ArrayList<>(types.length);
	for(DotNetType type : types)
	{
		if(type instanceof CSharpUserType)
		{
			ContainerUtil.addIfNotNull(typeRefs, ((CSharpUserType) type).getReferenceExpression().getReferenceName());
		}
	}

	return new CSharpTypeListStub(stubElement, this, ArrayUtil.toStringArray(typeRefs));
}
 
Example 11
Source File: RelatedItemLineMarkerGotoAdapter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void addItemsForMarkers(List<RelatedItemLineMarkerInfo> markers,
                                       List<GotoRelatedItem> result) {
  Set<PsiFile> addedFiles = new HashSet<PsiFile>();
  for (RelatedItemLineMarkerInfo<?> marker : markers) {
    Collection<? extends GotoRelatedItem> items = marker.createGotoRelatedItems();
    for (GotoRelatedItem item : items) {
      PsiElement element = item.getElement();
      if (element instanceof PsiFile) {
        PsiFile file = (PsiFile)element;
        if (addedFiles.contains(file)) {
          continue;
        }
      }
      if (element != null) {
        ContainerUtil.addIfNotNull(element.getContainingFile(), addedFiles);
      }
      result.add(item);
    }
  }
}
 
Example 12
Source File: ModuleOutputPackagingElementImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Collection<VirtualFile> getSourceRoots(PackagingElementResolvingContext context) {
  Module module = NamedPointerUtil.get(myModulePointer);
  if (module == null) {
    return Collections.emptyList();
  }

  List<VirtualFile> roots = new SmartList<VirtualFile>();
  ModuleRootModel rootModel = context.getModulesProvider().getRootModel(module);
  for (ContentEntry entry : rootModel.getContentEntries()) {
    for (ContentFolder folder : entry.getFolders(ContentFolderScopes.of(myContentFolderType))) {
      ContainerUtil.addIfNotNull(folder.getFile(), roots);
    }
  }
  return roots;
}
 
Example 13
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
static List<TreeVisitor> createVisitors(@Nonnull Object... objects) {
  List<TreeVisitor> list = new ArrayList<>();
  for (Object object : objects) {
    TreeVisitor visitor = createVisitor(object);
    ContainerUtil.addIfNotNull(list, visitor);
  }
  return ContainerUtil.immutableList(list);
}
 
Example 14
Source File: ApplyPatchChange.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void createOperations() {
  if (myViewer.isReadOnly()) return;
  if (isResolved()) return;

  if (myStatus == HunkStatus.EXACTLY_APPLIED) {
    ContainerUtil.addIfNotNull(myOperations, createOperation(OperationType.APPLY));
  }
  ContainerUtil.addIfNotNull(myOperations, createOperation(OperationType.IGNORE));
}
 
Example 15
Source File: ScratchTreeStructureProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Collection<? extends AbstractTreeNode<?>> getChildren() {
  List<AbstractTreeNode<?>> list = new ArrayList<>();
  Project project = Objects.requireNonNull(getProject());
  for (RootType rootType : RootType.getAllRootTypes()) {
    ContainerUtil.addIfNotNull(list, createRootTypeNode(project, rootType, getSettings()));
  }
  return list;
}
 
Example 16
Source File: ExecutionOutputParser.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Handles single output line.
 *
 * @param text       execution response
 * @param outputType output type
 */
public void onTextAvailable(@NotNull String text, @NotNull Key outputType) {
    if (outputType == ProcessOutputTypes.SYSTEM) {
        return;
    }

    if (outputType == ProcessOutputTypes.STDERR) {
        errorsReported = true;
        return;
    }

    ContainerUtil.addIfNotNull(outputs, parseOutput(StringUtil.trimEnd(text, "\n").trim()));
}
 
Example 17
Source File: AnnotationsSettings.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public List<Color> getOrderedColors(@Nullable EditorColorsScheme scheme) {
  if (scheme == null) scheme = EditorColorsManager.getInstance().getGlobalScheme();

  List<Color> anchorColors = new ArrayList<>();
  for (ColorKey key : ANCHOR_COLOR_KEYS) {
    ContainerUtil.addIfNotNull(anchorColors, scheme.getColor(key));
  }

  return ColorGenerator.generateLinearColorSequence(anchorColors, COLORS_BETWEEN_ANCHORS);
}
 
Example 18
Source File: RelatedItemLineMarkerGotoAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public List<? extends GotoRelatedItem> getItems(@Nonnull PsiElement context) {
  List<PsiElement> parents = new ArrayList<PsiElement>();
  PsiElement current = context;
  Set<Language> languages = new HashSet<Language>();
  while (current != null) {
    parents.add(current);
    languages.add(current.getLanguage());
    if (current instanceof PsiFile) break;
    current = current.getParent();
  }

  List<LineMarkerProvider> providers = new ArrayList<LineMarkerProvider>();
  for (Language language : languages) {
    providers.addAll(LineMarkersPass.getMarkerProviders(language, context.getProject()));
  }
  List<GotoRelatedItem> items = new ArrayList<GotoRelatedItem>();
  for (LineMarkerProvider provider : providers) {
    if (provider instanceof RelatedItemLineMarkerProvider) {
      List<RelatedItemLineMarkerInfo> markers = new ArrayList<RelatedItemLineMarkerInfo>();
      RelatedItemLineMarkerProvider relatedItemLineMarkerProvider = (RelatedItemLineMarkerProvider)provider;
      for (PsiElement parent : parents) {
        ContainerUtil.addIfNotNull(relatedItemLineMarkerProvider.getLineMarkerInfo(parent), markers);
      }
      relatedItemLineMarkerProvider.collectNavigationMarkers(parents, markers, true);

      addItemsForMarkers(markers, items);
    }
  }

  return items;
}
 
Example 19
Source File: OrderEnumeratorBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
boolean addCustomRootsForLibrary(OrderEntry forOrderEntry, OrderRootType type, Collection<VirtualFile> result) {
  for (OrderEnumerationHandler handler : myCustomHandlers) {
    final List<String> urls = new ArrayList<>();
    final boolean added =
      handler.addCustomRootsForLibrary(forOrderEntry, type, urls);
    for (String url : urls) {
      ContainerUtil.addIfNotNull(result, VirtualFileManager.getInstance().findFileByUrl(url));
    }
    if (added) {
      return true;
    }
  }
  return false;
}
 
Example 20
Source File: ScratchFileServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Collection<VirtualFile> additionalRoots(Project project) {
  Set<VirtualFile> result = ContainerUtil.newLinkedHashSet();
  LocalFileSystem fileSystem = LocalFileSystem.getInstance();
  ScratchFileService app = ScratchFileService.getInstance();
  for (RootType r : RootType.getAllRootTypes()) {
    ContainerUtil.addIfNotNull(result, fileSystem.findFileByPath(app.getRootPath(r)));
  }
  return result;
}