@NotNull public static String getLibraryName(@NotNull Library library) { final String result = library.getName(); if (result != null) { return result; } String[] endingsToStrip = {"/", "!", ".jar"}; StringBuilder buffer = new StringBuilder(); for (OrderRootType type : OrderRootType.getAllTypes()) { for (String url : library.getUrls(type)) { buffer.setLength(0); buffer.append(url); for (String ending : endingsToStrip) { if (buffer.lastIndexOf(ending) == buffer.length() - ending.length()) { buffer.setLength(buffer.length() - ending.length()); } } final int i = buffer.lastIndexOf(PATH_SEPARATOR); if (i < 0 || i >= buffer.length() - 1) { continue; } String candidate = buffer.substring(i + 1); if (!StringUtil.isEmpty(candidate)) { return candidate; } } } assert false; return "unknown-lib"; }
protected String doCalculateSignature(PsiMethod method) { final StringBuilder buffer = new StringBuilder(); final PsiModifierList modifierList = method.getModifierList(); String modifiers = modifierList.getText(); final String oldModifier = VisibilityUtil.getVisibilityModifier(modifierList); final String newModifier = getVisibility(); String newModifierStr = VisibilityUtil.getVisibilityString(newModifier); if (!newModifier.equals(oldModifier)) { int index = modifiers.indexOf(oldModifier); if (index >= 0) { final StringBuilder buf = new StringBuilder(modifiers); buf.replace( index, index + oldModifier.length() + ("".equals(newModifierStr) ? 1 : 0), newModifierStr); modifiers = buf.toString(); } else { if (!StringUtil.isEmpty(newModifierStr)) { newModifierStr += " "; } modifiers = newModifierStr + modifiers; } } buffer.append(modifiers); if (modifiers.length() > 0 && !StringUtil.endsWithChar(modifiers, '\n') && !StringUtil.endsWithChar(modifiers, '\r') && !StringUtil.endsWithChar(modifiers, ' ')) { buffer.append(" "); } if (!method.isConstructor()) { final CanonicalTypes.Type type = getReturnType(); if (type != null) { buffer.append(type.getTypeText()); } buffer.append(" "); } buffer.append(getMethodName()); buffer.append("("); final int lineBreakIdx = buffer.lastIndexOf("\n"); String indent = StringUtil.repeatSymbol( ' ', lineBreakIdx >= 0 ? buffer.length() - lineBreakIdx - 1 : buffer.length()); List<ParameterTableModelItemBase<ParameterInfoImpl>> items = myParametersTableModel.getItems(); int curIndent = indent.length(); for (int i = 0; i < items.size(); i++) { final ParameterTableModelItemBase<ParameterInfoImpl> item = items.get(i); if (i > 0) { buffer.append(","); buffer.append("\n"); buffer.append(indent); } final String text = item.typeCodeFragment.getText(); buffer.append(text).append(" "); final String name = item.parameter.getName(); buffer.append(name); curIndent = indent.length() + text.length() + 1 + name.length(); } // if (!items.isEmpty()) { // buffer.append("\n"); // } buffer.append(")"); PsiTypeCodeFragment[] thrownExceptionsFragments = myExceptionsModel.getTypeCodeFragments(); if (thrownExceptionsFragments.length > 0) { // buffer.append("\n"); buffer.append(" throws "); curIndent += 9; // ") throws ".length() indent = StringUtil.repeatSymbol(' ', curIndent); for (int i = 0; i < thrownExceptionsFragments.length; i++) { String text = thrownExceptionsFragments[i].getText(); if (i != 0) buffer.append(indent); buffer.append(text); if (i < thrownExceptionsFragments.length - 1) { buffer.append(","); } buffer.append("\n"); } } return buffer.toString(); }