com.intellij.util.ArrayFactory Java Examples

The following examples show how to use com.intellij.util.ArrayFactory. 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: StubBasedPsiElementBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
 */
@Nonnull
public <S extends StubElement, Psi extends PsiElement> Psi[] getStubOrPsiChildren(@Nonnull IStubElementType<S, ? extends Psi> elementType, @Nonnull ArrayFactory<? extends Psi> f) {
  T stub = getGreenStub();
  if (stub != null) {
    //noinspection unchecked
    return (Psi[])stub.getChildrenByType(elementType, f);
  }
  else {
    final ASTNode[] nodes = SharedImplUtil.getChildrenOfType(getNode(), elementType);
    Psi[] psiElements = f.create(nodes.length);
    for (int i = 0; i < nodes.length; i++) {
      //noinspection unchecked
      psiElements[i] = (Psi)nodes[i].getPsi();
    }
    return psiElements;
  }
}
 
Example #2
Source File: StubBasedPsiElementBase.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * @return children of specified type, taken from stubs (if this element is currently stub-based) or AST (otherwise).
 */
@Nonnull
public <Psi extends PsiElement> Psi[] getStubOrPsiChildren(@Nonnull TokenSet filter, @Nonnull ArrayFactory<? extends Psi> f) {
  T stub = getGreenStub();
  if (stub != null) {
    //noinspection unchecked
    return (Psi[])stub.getChildrenByType(filter, f);
  }
  else {
    final ASTNode[] nodes = getNode().getChildren(filter);
    Psi[] psiElements = f.create(nodes.length);
    for (int i = 0; i < nodes.length; i++) {
      //noinspection unchecked
      psiElements[i] = (Psi)nodes[i].getPsi();
    }
    return psiElements;
  }
}
 
Example #3
Source File: CompositeElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public <T extends PsiElement> T[] getChildrenAsPsiElements(@Nullable TokenSet filter, @Nonnull ArrayFactory<? extends T> constructor) {
  assertReadAccessAllowed();
  int count = countChildren(filter);
  T[] result = constructor.create(count);
  if (count == 0) {
    return result;
  }
  int idx = 0;
  for (ASTNode child = getFirstChildNode(); child != null && idx < count; child = child.getTreeNext()) {
    if (filter == null || filter.contains(child.getElementType())) {
      @SuppressWarnings("unchecked") T element = (T)child.getPsi();
      LOG.assertTrue(element != null, child);
      result[idx++] = element;
    }
  }
  return result;
}
 
Example #4
Source File: CompositeElement.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public <T extends PsiElement> T[] getChildrenAsPsiElements(@Nonnull IElementType type, @Nonnull ArrayFactory<? extends T> constructor) {
  assertReadAccessAllowed();
  int count = countChildren(type);
  T[] result = constructor.create(count);
  if (count == 0) {
    return result;
  }
  int idx = 0;
  for (ASTNode child = getFirstChildNode(); child != null && idx < count; child = child.getTreeNext()) {
    if (type == child.getElementType()) {
      @SuppressWarnings("unchecked") T element = (T)child.getPsi();
      LOG.assertTrue(element != null, child);
      result[idx++] = element;
    }
  }
  return result;
}
 
Example #5
Source File: Sand2PackageProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public PsiPackage createPackage(@Nonnull PsiManager psiManager,
                                @Nonnull PsiPackageManager packageManager,
                                @Nonnull Class<? extends ModuleExtension> extensionClass,
                                @Nonnull String packageName) {
  return new PsiPackageBase(psiManager, packageManager, extensionClass, packageName) {
    @Override
    protected ArrayFactory<? extends PsiPackage> getPackageArrayFactory() {
      return PsiPackage.ARRAY_FACTORY;
    }

    @RequiredReadAction
    @Nonnull
    @Override
    public Language getLanguage() {
      return SandLanguage.INSTANCE;
    }
  };
}
 
Example #6
Source File: StubBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <E extends PsiElement> E[] getChildrenByType(@Nonnull final IElementType elementType, @Nonnull final ArrayFactory<E> f) {
  List<StubElement> childrenStubs = getChildrenStubs();
  int count = countChildren(elementType, childrenStubs);

  E[] result = f.create(count);
  if (count > 0) fillFilteredChildren(elementType, result, childrenStubs);

  return result;
}
 
Example #7
Source File: StubBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public <E extends PsiElement> E[] getChildrenByType(@Nonnull final TokenSet filter, @Nonnull final ArrayFactory<E> f) {
  List<StubElement> childrenStubs = getChildrenStubs();
  int count = countChildren(filter, childrenStubs);

  E[] array = f.create(count);
  if (count == 0) return array;

  fillFilteredChildren(filter, array, childrenStubs);

  return array;
}
 
Example #8
Source File: StubElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
<E extends PsiElement> E[] getChildrenByType(@Nonnull IElementType elementType, @Nonnull ArrayFactory<E> f);
 
Example #9
Source File: StubElement.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
<E extends PsiElement> E[] getChildrenByType(@Nonnull TokenSet filter, @Nonnull ArrayFactory<E> f);
 
Example #10
Source File: LockFreeCOWSortedArray.java    From consulo with Apache License 2.0 4 votes vote down vote up
LockFreeCOWSortedArray(@Nonnull Comparator<? super T> comparator, @Nonnull ArrayFactory<T> arrayFactory) {
  this.comparator = comparator;
  this.arrayFactory = arrayFactory;
  listeners = arrayFactory.create(0);
}
 
Example #11
Source File: PsiPackageBase.java    From consulo with Apache License 2.0 votes vote down vote up
protected abstract ArrayFactory<? extends PsiPackage> getPackageArrayFactory();