Java 类com.intellij.util.containers.EmptyIterable 实例源码

项目:intellij-ce-playground    文件:PsiUtil.java   
@NotNull
public static Iterable<PsiTypeParameter> typeParametersIterable(@NotNull final PsiTypeParameterListOwner owner) {
  List<PsiTypeParameter> result = null;

  PsiTypeParameterListOwner currentOwner = owner;
  while (currentOwner != null) {
    PsiTypeParameter[] typeParameters = currentOwner.getTypeParameters();
    if (typeParameters.length > 0) {
      if (result == null) result = new ArrayList<PsiTypeParameter>(typeParameters.length);
      for (int i = typeParameters.length - 1; i >= 0; i--) {
        result.add(typeParameters[i]);
      }
    }

    if (currentOwner.hasModifierProperty(PsiModifier.STATIC)) break;
    currentOwner = currentOwner.getContainingClass();
  }

  if (result == null) return EmptyIterable.getInstance();
  return result;
}
项目:tools-idea    文件:PsiUtil.java   
@NotNull
public static Iterable<PsiTypeParameter> typeParametersIterable(@NotNull final PsiTypeParameterListOwner owner) {
  ArrayList<PsiTypeParameter> result = null;

  PsiTypeParameterListOwner currentOwner = owner;
  while (currentOwner != null) {
    PsiTypeParameter[] typeParameters = currentOwner.getTypeParameters();
    if (typeParameters.length > 0) {
      if (result == null) result = new ArrayList<PsiTypeParameter>(typeParameters.length);
      for (int i = typeParameters.length - 1; i >= 0; i--) {
        result.add(typeParameters[i]);
      }
    }

    if (currentOwner.hasModifierProperty(PsiModifier.STATIC)) break;
    currentOwner = currentOwner.getContainingClass();
  }

  if (result == null) return EmptyIterable.getInstance();
  return result;
}
项目:intellij-ce-playground    文件:PositionManagerImpl.java   
private static Iterable<PsiElement> getLineElements(final PsiFile file, int lineNumber) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
  if (document == null || lineNumber >= document.getLineCount()) {
    return EmptyIterable.getInstance();
  }
  final TextRange lineRange = DocumentUtil.getLineTextRange(document, lineNumber);
  return new Iterable<PsiElement>() {
    @Override
    public Iterator<PsiElement> iterator() {
      return new Iterator<PsiElement>() {
        PsiElement myElement = DebuggerUtilsEx.findElementAt(file, lineRange.getStartOffset());

        @Override
        public boolean hasNext() {
          return myElement != null;
        }

        @Override
        public PsiElement next() {
          PsiElement res = myElement;
          do {
            myElement = PsiTreeUtil.nextLeaf(myElement);
            if (myElement == null || myElement.getTextOffset() > lineRange.getEndOffset()) {
              myElement = null;
              break;
            }
          } while (myElement.getTextLength() == 0);
          return res;
        }

        @Override
        public void remove() {}
      };
    }
  };
}
项目:intellij-ce-playground    文件:PyImportElementImpl.java   
@NotNull
public Iterable<PyElement> iterateNames() {
  PyElement ret = getAsNameElement();
  if (ret == null) {
    final PyReferenceExpression importReference = getImportReferenceExpression();
    if (importReference != null) {
      ret = PyPsiUtils.getFirstQualifier(importReference);
    }
  }
  if (ret == null) {
    return EmptyIterable.getInstance();
  }
  return Collections.singleton(ret);
}
项目:consulo-java    文件:PsiUtil.java   
@NotNull
public static Iterable<PsiTypeParameter> typeParametersIterable(@NotNull final PsiTypeParameterListOwner owner)
{
    List<PsiTypeParameter> result = null;

    PsiTypeParameterListOwner currentOwner = owner;
    while(currentOwner != null)
    {
        PsiTypeParameter[] typeParameters = currentOwner.getTypeParameters();
        if(typeParameters.length > 0)
        {
            if(result == null)
            {
                result = new ArrayList<PsiTypeParameter>(typeParameters.length);
            }
            for(int i = typeParameters.length - 1; i >= 0; i--)
            {
                result.add(typeParameters[i]);
            }
        }

        if(currentOwner.hasModifierProperty(PsiModifier.STATIC))
        {
            break;
        }
        currentOwner = currentOwner.getContainingClass();
    }

    if(result == null)
    {
        return EmptyIterable.getInstance();
    }
    return result;
}
项目:consulo-java    文件:PositionManagerImpl.java   
private static Iterable<PsiElement> getLineElements(final PsiFile file, int lineNumber)
{
    ApplicationManager.getApplication().assertReadAccessAllowed();
    Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
    if(document == null || lineNumber < 0 || lineNumber >= document.getLineCount())
    {
        return EmptyIterable.getInstance();
    }
    final TextRange lineRange = DocumentUtil.getLineTextRange(document, lineNumber);
    return new Iterable<PsiElement>()
    {
        @Override
        public Iterator<PsiElement> iterator()
        {
            return new Iterator<PsiElement>()
            {
                PsiElement myElement = DebuggerUtilsEx.findElementAt(file, lineRange.getStartOffset());

                @Override
                public boolean hasNext()
                {
                    return myElement != null;
                }

                @Override
                public PsiElement next()
                {
                    PsiElement res = myElement;
                    do
                    {
                        myElement = PsiTreeUtil.nextLeaf(myElement);
                        if(myElement == null || myElement.getTextOffset() > lineRange.getEndOffset())
                        {
                            myElement = null;
                            break;
                        }
                    }
                    while(myElement.getTextLength() == 0);
                    return res;
                }

                @Override
                public void remove()
                {
                }
            };
        }
    };
}