ItemPresentation () { return new ItemPresentation() { @NotNull private String getRefName(String default_name) { PyReferenceExpression ref = getImportReferenceExpression(); if (ref != null) { String refName = ref.getName(); if (refName != null) return refName; } return default_name; } @Override public String getPresentableText() { return getRefName("<none>"); } @Override public String getLocationString() { PyElement elt = PsiTreeUtil.getParentOfType(PyImportElementImpl.this, PyImportStatement.class, PyFromImportStatement.class); final StringBuilder buf = new StringBuilder("| "); if (elt != null) { // always? who knows :) if (elt instanceof PyFromImportStatement) { // from ... import ... buf.append("from "); PyReferenceExpression imp_src = ((PyFromImportStatement)elt).getImportSource(); if (imp_src != null) { buf.append(PyPsiUtils.toPath(imp_src)); } else { buf.append("<?>"); } buf.append(" import "); } else { // "import ... " buf.append("import "); } buf.append(getRefName("<?>")); } else { buf.append("import?.. "); } // are we the name or the 'as'? PyTargetExpression as_part = getAsNameElement(); if (as_part != null) { buf.append(" as ").append(as_part.getName()); } return buf.toString(); } @Override public Icon getIcon(final boolean open) { return null; } }; }