boolean (@NotNull final PsiElement member, final int startLine, final int endLine, final LineRange lineRange, final Editor editor) { // if we positioned on member start or end we'll be able to move it if (startLine == lineRange.startLine || startLine == lineRange.endLine || endLine == lineRange.startLine || endLine == lineRange.endLine) { return true; } List<PsiElement> memberSuspects = new ArrayList<>(); PsiModifierList modifierList = member instanceof PsiMember ? ((PsiMember)member).getModifierList() : null; if (modifierList != null) memberSuspects.add(modifierList); if (member instanceof PsiClass aClass) { if (aClass instanceof PsiAnonymousClass) return false; // move new expression instead of anon class PsiIdentifier nameIdentifier = aClass.getNameIdentifier(); if (nameIdentifier != null) memberSuspects.add(nameIdentifier); } if (member instanceof PsiMethod method) { PsiIdentifier nameIdentifier = method.getNameIdentifier(); if (nameIdentifier != null) memberSuspects.add(nameIdentifier); PsiTypeElement returnTypeElement = method.getReturnTypeElement(); if (returnTypeElement != null) memberSuspects.add(returnTypeElement); } if (member instanceof PsiField field) { PsiIdentifier nameIdentifier = field.getNameIdentifier(); memberSuspects.add(nameIdentifier); PsiTypeElement typeElement = field.getTypeElement(); if (typeElement != null) memberSuspects.add(typeElement); } TextRange lineTextRange = new TextRange(editor.getDocument().getLineStartOffset(lineRange.startLine), editor.getDocument().getLineEndOffset(lineRange.endLine)); for (PsiElement suspect : memberSuspects) { TextRange textRange = suspect.getTextRange(); if (textRange != null && lineTextRange.intersects(textRange)) return true; } return false; }