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

The following examples show how to use com.intellij.util.containers.ContainerUtil#toArray() . 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: PsiPackageBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public PsiPackage[] getSubPackages(@Nonnull PsiPackage psiPackage, @Nonnull GlobalSearchScope scope) {
  final Map<String, PsiPackage> packagesMap = new HashMap<String, PsiPackage>();
  final String qualifiedName = psiPackage.getQualifiedName();
  for (PsiDirectory dir : psiPackage.getDirectories(scope)) {
    PsiDirectory[] subDirs = dir.getSubdirectories();
    for (PsiDirectory subDir : subDirs) {
      final PsiPackage aPackage = myPackageManager.findPackage(subDir, myExtensionClass);
      if (aPackage != null) {
        final String subQualifiedName = aPackage.getQualifiedName();
        if (subQualifiedName.startsWith(qualifiedName) && !packagesMap.containsKey(subQualifiedName)) {
          packagesMap.put(aPackage.getQualifiedName(), aPackage);
        }
      }
    }
  }

  packagesMap.remove(qualifiedName);    // avoid SOE caused by returning a package as a subpackage of itself
  return ContainerUtil.toArray(packagesMap.values(), getPackageArrayFactory());
}
 
Example 2
Source File: CSharpOperatorReferenceImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@RequiredReadAction
private ResolveResult[] multiResolveImpl(CSharpOperatorReferenceImpl reference)
{
	Object o = reference.resolveImpl();

	List<ResolveResult> elements = new SmartList<>();
	if(o instanceof MethodResolveResult[])
	{
		MethodResolveResult[] array = (MethodResolveResult[]) o;
		ContainerUtil.addAll(elements, array);
	}
	else if(o instanceof PsiElement)
	{
		elements.add(new CSharpResolveResult((PsiElement) o));
	}
	else if(o instanceof DotNetTypeRef)
	{
		elements.add(new StubElementResolveResult(reference, true, (DotNetTypeRef) o));
	}

	return ContainerUtil.toArray(elements, ResolveResult.EMPTY_ARRAY);
}
 
Example 3
Source File: CSharpOperatorReferenceImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
@RequiredReadAction
public ResolveResult[] resolve(@Nonnull CSharpOperatorReferenceImpl reference, boolean incompleteCode)
{
	if(incompleteCode)
	{
		return multiResolveImpl(reference);
	}
	else
	{
		ResolveResult[] resolveResults = multiResolveImpl(reference);

		List<ResolveResult> filter = new SmartList<>();
		for(ResolveResult resolveResult : resolveResults)
		{
			if(resolveResult.isValidResult())
			{
				filter.add(resolveResult);
			}
		}
		return ContainerUtil.toArray(filter, ResolveResult.EMPTY_ARRAY);
	}
}
 
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: MsilPropertyAsCSharpPropertyDeclaration.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
public static DotNetXAccessor[] buildAccessors(@Nonnull PsiElement parent, @Nonnull List<Pair<DotNetXAccessor, MsilMethodEntry>> pairs)
{
	List<DotNetXAccessor> accessors = new ArrayList<DotNetXAccessor>(2);

	for(Pair<DotNetXAccessor, MsilMethodEntry> pair : pairs)
	{
		accessors.add(new MsilXAccessorAsCSharpXAccessor(parent, pair.getFirst(), pair.getSecond()));
	}
	return ContainerUtil.toArray(accessors, DotNetXAccessor.ARRAY_FACTORY);
}
 
Example 6
Source File: CSharpAbstractLightAttributeBuilder.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public CSharpCallArgument[] getCallArguments()
{
	if(myCallArguments.isEmpty())
	{
		return CSharpCallArgument.EMPTY_ARRAY;
	}
	List<CSharpCallArgument> arguments = new ArrayList<>(myCallArguments.size());
	for(NotNullLazyValue<CSharpCallArgument> callArgument : myCallArguments)
	{
		arguments.add(callArgument.getValue());
	}
	return ContainerUtil.toArray(arguments, CSharpCallArgument.ARRAY_FACTORY);
}
 
Example 7
Source File: CSharpCompositeTypeDeclaration.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetNamedElement[] getMembers()
{
	List<DotNetNamedElement> elements = new ArrayList<>();
	for(CSharpTypeDeclaration typeDeclaration : myTypeDeclarations)
	{
		Collections.addAll(elements, typeDeclaration.getMembers());
	}
	return ContainerUtil.toArray(elements, DotNetNamedElement.ARRAY_FACTORY);
}
 
Example 8
Source File: CSharpLightTypeDeclarationBuilder.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nonnull
@Override
public DotNetTypeRef[] getExtendTypeRefs()
{
	return ContainerUtil.toArray(myExtendTypes, DotNetTypeRef.ARRAY_FACTORY);
}
 
Example 9
Source File: DiffIterableUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static <T> FairDiffIterable diff(@Nonnull List<T> objects1, @Nonnull List<T> objects2, @Nonnull ProgressIndicator indicator)
        throws DiffTooBigException {
  indicator.checkCanceled();

  // TODO: compare lists instead of arrays in Diff
  Object[] data1 = ContainerUtil.toArray((List)objects1, new Object[objects1.size()]);
  Object[] data2 = ContainerUtil.toArray((List)objects2, new Object[objects2.size()]);
  return diff(data1, data2, indicator);
}
 
Example 10
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Module[] getModules() {
  if (myModulesCache == null) {
    myModulesCache = ContainerUtil.toArray(myModules, Module.ARRAY_FACTORY);
  }
  return myModulesCache;
}
 
Example 11
Source File: CSharpResolveUtil.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ResolveResult[] filterValidResults(@Nonnull ResolveResult[] resolveResults)
{
	List<ResolveResult> filter = new SmartList<ResolveResult>();
	for(ResolveResult resolveResult : resolveResults)
	{
		if(resolveResult.isValidResult() && isAssignable(resolveResult))
		{
			filter.add(resolveResult);
		}
	}
	return ContainerUtil.toArray(filter, ResolveResult.EMPTY_ARRAY);
}
 
Example 12
Source File: PsiPackageBase.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public PsiDirectory[] getDirectories() {
  final Collection<PsiDirectory> collection = getAllDirectories(false);
  return ContainerUtil.toArray(collection, new PsiDirectory[collection.size()]);
}
 
Example 13
Source File: CSharpExtractMethodHandler.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
private DotNetStatement[] getStatements(PsiFile file, int startOffset, int endOffset)
{
	Set<DotNetStatement> set = new ArrayListSet<DotNetStatement>();

	PsiElement element1 = file.findElementAt(startOffset);
	PsiElement element2 = file.findElementAt(endOffset - 1);
	if(element1 instanceof PsiWhiteSpace)
	{
		startOffset = element1.getTextRange().getEndOffset();
		element1 = file.findElementAt(startOffset);
	}
	if(element2 instanceof PsiWhiteSpace)
	{
		endOffset = element2.getTextRange().getStartOffset();
		element2 = file.findElementAt(endOffset - 1);
	}

	PsiElement statement1 = getTopmostParentOfType(element1, DotNetStatement.class);
	if(statement1 == null)
	{
		return EMPTY_ARRAY;
	}

	PsiElement statement2 = getTopmostParentOfType(element2, DotNetStatement.class);
	if(statement2 == null)
	{
		return EMPTY_ARRAY;
	}

	PsiElement temp = statement1;
	while(temp != null)
	{
		if(temp instanceof DotNetStatement)
		{
			set.add((DotNetStatement) temp);
		}

		if(temp == statement2)
		{
			return ContainerUtil.toArray(set, EMPTY_ARRAY);
		}

		temp = temp.getNextSibling();
	}
	return EMPTY_ARRAY;
}
 
Example 14
Source File: CSharpCompositeTypeDeclaration.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
public static Collection<PsiElement> wrapPartialTypes(@Nonnull GlobalSearchScope scope, @Nonnull Project project, @Nonnull Collection<PsiElement> elements)
{
	MultiMap<String, CSharpTypeDeclaration> partialTypes = null;

	List<PsiElement> newElementList = null;

	PsiElement[] psiElements = ContainerUtil.toArray(elements, PsiElement.ARRAY_FACTORY);

	for(int i = 0; i < psiElements.length; i++)
	{
		ProgressManager.checkCanceled();

		PsiElement psiElement = psiElements[i];
		if(psiElement instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) psiElement).hasModifier(CSharpModifier.PARTIAL))
		{
			String vmQName = ((CSharpTypeDeclaration) psiElement).getVmQName();
			if(vmQName != null)
			{
				if(partialTypes == null)
				{
					partialTypes = MultiMap.create();
				}

				if(newElementList == null)
				{
					newElementList = new ArrayList<>(psiElements.length);
					// we need copy head to new list
					newElementList.addAll(Arrays.asList(psiElements).subList(0, i));
				}

				partialTypes.putValue(vmQName, (CSharpTypeDeclaration) psiElement);
				continue;
			}
		}

		if(newElementList != null)
		{
			newElementList.add(psiElement);
		}
	}

	if(partialTypes == null)
	{
		return elements;
	}

	for(Map.Entry<String, Collection<CSharpTypeDeclaration>> entry : partialTypes.entrySet())
	{
		ProgressManager.checkCanceled();

		Collection<CSharpTypeDeclaration> value = entry.getValue();
		// partial modifier is useless, only one class with name
		if(value.size() == 1)
		{
			newElementList.add(value.iterator().next());
		}
		else
		{
			CSharpTypeDeclaration compositeType = CSharpPartialElementManager.getInstance(project).getOrCreateCompositeType(scope, entry.getKey(), value);

			newElementList.add(compositeType);
		}
	}
	return newElementList;
}
 
Example 15
Source File: CSharpGenericExtractor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
private CSharpGenericExtractor(Map<DotNetGenericParameter, DotNetTypeRef> map)
{
	this(ContainerUtil.toArray(map.keySet(), DotNetGenericParameter.ARRAY_FACTORY), ContainerUtil.toArray(map.values(), DotNetTypeRef.ARRAY_FACTORY));
}
 
Example 16
Source File: OptionsTree.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
protected SimpleNode[] buildChildren() {
  return ContainerUtil.toArray(map(myConfigurables), EMPTY_EN_ARRAY);
}
 
Example 17
Source File: CSharpLightLikeMethodDeclarationBuilder.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DotNetParameter[] getParameters()
{
	return ContainerUtil.toArray(myParameters, DotNetParameter.ARRAY_FACTORY);
}
 
Example 18
Source File: CSharpLightLikeMethodDeclarationBuilder.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DotNetGenericParameter[] getGenericParameters()
{
	return ContainerUtil.toArray(myGenericParameters, DotNetGenericParameter.ARRAY_FACTORY);
}
 
Example 19
Source File: DefaultSdksModel.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public Sdk[] getSdks() {
  return ContainerUtil.toArray(mySdks.values(), Sdk.ARRAY_FACTORY);
}
 
Example 20
Source File: OperatorsProvider.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@RequiredReadAction
private DotNetElement[] buildNullableOperators(@Nonnull Project project,
		@Nonnull GlobalSearchScope resolveScope,
		@Nonnull DotNetTypeRef selfTypeRef,
		@Nonnull CSharpTypeDeclaration typeDeclaration,
		@Nonnull DotNetGenericExtractor extractor,
		@Nonnull Consumer<PsiElement> consumer)
{
	DotNetGenericParameter[] genericParameters = typeDeclaration.getGenericParameters();
	if(genericParameters.length == 0)
	{
		return DotNetElement.EMPTY_ARRAY;
	}
	DotNetGenericParameter genericParameter = genericParameters[0];

	DotNetTypeRef extract = extractor.extract(genericParameter);
	if(extract == null)
	{
		return DotNetElement.EMPTY_ARRAY;
	}

	DotNetTypeResolveResult typeResolveResult = extract.resolve();
	PsiElement typeResolveResultElement = typeResolveResult.getElement();
	if(!(typeResolveResultElement instanceof DotNetTypeDeclaration))
	{
		return DotNetElement.EMPTY_ARRAY;
	}

	List<DotNetElement> elements = new ArrayList<DotNetElement>();

	DotNetTypeDeclaration forAddOperatorsElement = (DotNetTypeDeclaration) typeResolveResultElement;

	buildOperators(project, resolveScope, selfTypeRef, forAddOperatorsElement, OperatorStubsLoader.INSTANCE.myTypeOperators.get(forAddOperatorsElement.getVmQName()), consumer);

	if(forAddOperatorsElement.isEnum())
	{
		buildOperators(project, resolveScope, selfTypeRef, forAddOperatorsElement, OperatorStubsLoader.INSTANCE.myEnumOperators, consumer);
	}
	return ContainerUtil.toArray(elements, DotNetElement.ARRAY_FACTORY);
}