public static String getLocalPackageName(@NotNull String importPath) { String fileName = !StringUtil.endsWithChar(importPath, '/') && !StringUtil.endsWithChar(importPath, '\\') ? PathUtil.getFileName(importPath) : ""; StringBuilder name = null; for (int i = 0; i < fileName.length(); i++) { char c = fileName.charAt(i); if (!(Character.isLetter(c) || c == '_' || i != 0 && Character.isDigit(c))) { if (name == null) { name = new StringBuilder(fileName.length()); name.append(fileName, 0, i); } name.append('_'); } else if (name != null) { name.append(c); } } return name == null ? fileName : name.toString(); }
} else { int slashes = StringUtil.countChars(glob, '/'); if (slashes == 0 || (slashes == 1 && StringUtil.endsWithChar(glob, '/'))) { sb.append("(?:[^/]*?/)*"); if (StringUtil.endsWithChar(sb, '/')) { sb.append(acceptChildren ? ".+" : "[^/]+/?"); } else { if (StringUtil.endsWithChar(sb, '/')) { if (acceptChildren) { sb.append("[^/]*");
private static File createDir(String... children) { try { File dir = FileUtil.createTempDirectory("goSdk", "test"); for (String child : children) { File file = new File(dir, child); FileUtil.createParentDirs(file); if (StringUtil.endsWithChar(child, '/')) { assertTrue(file.mkdir()); } else { assertTrue(file.createNewFile()); } } return dir; } catch (IOException e) { throw new RuntimeException(e); } } }
@NotNull @Contract(pure = true) public static String trimEnd(@NotNull String s, char suffix) { if (endsWithChar(s, suffix)) { return s.substring(0, s.length() - 1); } return s; }
@NotNull @Override public TextRange getRangeInElement(@NotNull PerlVariableNameElement element) { String elementText = element.getText(); if (StringUtil.endsWithChar(elementText, ':')) { return TextRange.EMPTY_RANGE; } int lastDelimiterOffset = elementText.lastIndexOf(':'); if (lastDelimiterOffset > -1) { return TextRange.create(lastDelimiterOffset + 1, elementText.length()); } return super.getRangeInElement(element); }
/** * Distincts sub_name from qualified sub_name by : * * @return guessed token */ @NotNull protected IElementType getIdentifierTokenWithoutIndex() { CharSequence tokenText = yytext(); int lastIndex; if (StringUtil.endsWithChar(tokenText, ':')) { return PACKAGE; } int tokenLength = tokenText.length(); if ((lastIndex = StringUtil.lastIndexOfAny(tokenText, ":'") + 1) > 0) { yypushback(tokenLength - lastIndex); pushStateAndBegin(LEX_SUB_NAME); return QUALIFYING_PACKAGE; } return SUB_NAME; }
private IElementType getVariableNameTokenBySigil() { IElementType nameToken = SIGILS_TO_TOKENS_MAP.get(myCurrentSigilToken).second; if (nameToken != SUB_NAME) { return nameToken; } CharSequence tokenText = yytext(); int tokenLength = tokenText.length(); if (tokenLength == 1) { return nameToken; } if (StringUtil.endsWithChar(tokenText, ':')) { return PACKAGE; } int nameIndex = StringUtil.lastIndexOfAny(tokenText, ":'") + 1; if (nameIndex == 0) { return nameToken; } yypushback(tokenLength - nameIndex); pushStateAndBegin(LEX_SUB_NAME); return QUALIFYING_PACKAGE; }
(tokenType = CUSTOM_TOKEN_TYPES.get(tokenText)) == null ) { if (StringUtil.endsWithChar(tokenText, ':')) { tokenType = PACKAGE;