@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; }
@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; }
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() {} }; } }; }
@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); }
@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; }
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() { } }; } }; }