Substring (@NotNull Substring name) { final String superString = name.getSuperString(); int startWithStars = name.getStartOffset(); int prevNonWhitespace = skipSpacesBackward(superString, name.getStartOffset() - 1); if (prevNonWhitespace >= 0 && superString.charAt(prevNonWhitespace) == '*') { startWithStars = CharArrayUtil.shiftBackward(superString, prevNonWhitespace, "*") + 1; prevNonWhitespace = skipSpacesBackward(superString, startWithStars - 1); } if (prevNonWhitespace >= 0 && superString.charAt(prevNonWhitespace) == ',') { return new Substring(superString, prevNonWhitespace, name.getEndOffset()); } // end offset is always exclusive final int nextNonWhitespace = skipSpacesForward(superString, name.getEndOffset()); if (nextNonWhitespace < superString.length() && superString.charAt(nextNonWhitespace) == ',') { // if we remove parameter with trailing comma (i.e. first parameter) remove whitespaces after it as well return new Substring(superString, startWithStars, skipSpacesForward(superString, nextNonWhitespace + 1)); } return name; }