@Nullable public static GoTestFunctionType fromName(@Nullable String functionName) { if (StringUtil.isEmpty(functionName)) return null; if (GoConstants.TEST_MAIN.equals(functionName)) return TEST_MAIN; for (GoTestFunctionType type : values()) { if (checkPrefix(functionName, type.myPrefix)) return type; } return null; }
@Override public String getText() { return StringUtil.join(getTypeList(), PsiElement::getText, ", "); } }
@Override protected void addFilterParameter(@NotNull GoExecutor executor, String pattern) { if (StringUtil.isNotEmpty(pattern)) { executor.withParameters("-check.f", pattern); } } }
@NotNull private static String prepareVarOrConstDeclarationText(@NotNull String name, @Nullable String type, @Nullable String value) { type = StringUtil.trim(type); value = StringUtil.trim(value); type = StringUtil.isNotEmpty(type) ? " " + type : ""; value = StringUtil.isNotEmpty(value) ? " = " + value : ""; return name + type + value; }
private static void checkPortValue(@Nullable String port, @NotNull String errorMessage) throws RuntimeConfigurationError { if (StringUtil.isNotEmpty(port)) { int intPort = StringUtil.parseInt(port, -1); if (intPort < 0 || intPort > Short.MAX_VALUE * 2) { throw new RuntimeConfigurationError(errorMessage); } } }
public boolean matchFileName(@NotNull String fileName) { String name = StringUtil.substringAfter(fileName, "_"); if (StringUtil.isEmpty(name)) { return true; } name = StringUtil.trimEnd(FileUtil.getNameWithoutExtension(name), GoConstants.TEST_SUFFIX); List<String> parts = StringUtil.split(name, "_"); int n = parts.size(); if (n >= 2 && GoConstants.KNOWN_OS.contains(parts.get(n - 2)) && GoConstants.KNOWN_ARCH.contains(parts.get(n - 1))) { if (!myTarget.arch.equals(parts.get(n - 1))) { return false; } return matchOS(parts.get(n - 2)); } if (n >= 1) { if (GoConstants.KNOWN_OS.contains(parts.get(n - 1))) { return matchOS(parts.get(n - 1)); } if (GoConstants.KNOWN_ARCH.contains(parts.get(n - 1))) { return myTarget.arch.equals(parts.get(n - 1)); } } return true; }
continue; relativePath = StringUtil.trimStart(file.getPath(), workingDirectory.getPath()); } else { final VirtualFile vcsRoot = getVcsRootFor(file); if (!StringUtil.startsWith(file.getPath(), parentPath) && !ExternalIndexableSetContributor.getAdditionalFiles(myProject).contains(entryFile)) { continue; relativePath = StringUtil.trimStart(file.getPath(), parentPath); relativePath = StringUtil.trimEnd(StringUtil.trimStart(relativePath, "/"), "/"); if (StringUtil.isEmpty(relativePath)) { continue;
@Nullable public String getBuildFlags() { GoFileStub stub = getStub(); if (stub != null) { return stub.getBuildFlags(); } // https://code.google.com/p/go/source/browse/src/pkg/go/build/build.go?r=2449e85a115014c3d9251f86d499e5808141e6bc#790 Collection<String> buildFlags = ContainerUtil.newArrayList(); int buildFlagLength = GoConstants.BUILD_FLAG.length(); for (PsiComment comment : getCommentsToConsider(this)) { String commentText = StringUtil.trimStart(comment.getText(), "//").trim(); if (commentText.startsWith(GoConstants.BUILD_FLAG) && commentText.length() > buildFlagLength && StringUtil.isWhiteSpace(commentText.charAt(buildFlagLength))) { ContainerUtil.addIfNotNull(buildFlags, StringUtil.nullize(commentText.substring(buildFlagLength).trim(), true)); } } return !buildFlags.isEmpty() ? StringUtil.join(buildFlags, "|") : null; }
FileReferenceFilter(@NotNull Project project, @NonNls @NotNull String expression) { myProject = project; if (StringUtil.isEmpty(expression)) { throw new InvalidExpressionException("expression is empty."); String regex = StringUtil.replace(expression, PATH_MACROS, FILE_PATH_REGEXP); regex = StringUtil.replace(regex, LINE_MACROS, NUMBER_REGEXP); map.put(lineIndex, LINE_MACROS); regex = StringUtil.replace(regex, COLUMN_MACROS, NUMBER_REGEXP); map.put(columnIndex, COLUMN_MACROS);
private void processStdOut(@NotNull String testName, Key outputType, ServiceMessageVisitor visitor) throws ParseException { if (myStdOut == null) { return; } String allStdOut = StringUtil.join(myStdOut, ""); if (!StringUtil.isEmptyOrSpaces(allStdOut)) { String testStdOutMsg = ServiceMessageBuilder.testStdOut(testName).addAttribute("out", allStdOut).toString(); super.processServiceMessages(testStdOutMsg, outputType, visitor); } myStdOut = null; }
@Override protected void textChanged(DocumentEvent e) { String sdkPath = StringUtil.notNullize(textField.getText()); String prevPath = prevPathRef.get(); if (!prevPath.equals(sdkPath)) { asyncUpdateSdkVersion(sdkPath); prevPathRef.set(sdkPath); } } });
@Nullable @Contract(pure = true) public static String nullize(@Nullable final String s, boolean nullizeSpaces) { if (nullizeSpaces) { if (isEmptyOrSpaces(s)) return null; } else { if (isEmpty(s)) return null; } return s; }
public boolean matchBuildFlag(@NotNull String name) { if (name.isEmpty()) return false; if (StringUtil.containsChar(name, ',')) { // comma separated list for (String tag : StringUtil.split(name, ",")) { if (!matchBuildFlag(tag)) { return false; } } return true; } // bad syntax, reject always if (name.startsWith("!!")) return false; // negation if (name.startsWith("!")) return !matchBuildFlag(name.substring(1)); if (matchOS(name)) return true; if (GoConstants.KNOWN_COMPILERS.contains(name)) { return myTarget.compiler == null || name.equals(myTarget.compiler); } if (GoConstants.KNOWN_VERSIONS.contains(name)) { return myTarget.goVersion == null || GoSdkUtil.compareVersions(myTarget.goVersion, StringUtil.trimStart(name, "go")) >= 0; } if ("cgo".equals(name)) { return myTarget.cgoEnabled == ThreeState.YES; } return myTarget.supportsFlag(name); }
/** * Escape comment text for HTML. If nice is set, also turn `` into “ and '' into ”. */ private static String emphasize(@NotNull String text, boolean nice) { text = XmlStringUtil.escapeString(text); StringBuilder textWithLinks = null; Matcher matcher = URLUtil.URL_PATTERN.matcher(text); while (matcher.find()) { if (textWithLinks == null) { textWithLinks = new StringBuilder(); } textWithLinks.append(text.substring(0, matcher.start())) .append("<a href=\"").append(matcher.group()).append("\">").append(matcher.group()).append("</a>"); } if (textWithLinks != null) { text = textWithLinks.toString(); } return nice ? StringUtil.replace(text, new String[]{"``", "''"}, new String[]{"“", "”"}) : text; }
@Override public boolean isBlank() { return StringUtil.equals(getName(), "_"); }
int beginIndex = 0; if (StringUtil.startsWith(glob, Constants.DOUBLESTAR)) { sb.append("(?:[^/]*?/)*"); beginIndex = 2; doubleStar = true; } else if (StringUtil.startsWith(glob, "*/")) { sb.append("[^/]*"); beginIndex = 1; star = true; } else if (StringUtil.equals(Constants.STAR, glob)) { sb.append(".*"); } else if (StringUtil.startsWithChar(glob, '*')) { sb.append(".*?"); } else if (StringUtil.startsWithChar(glob, '/')) { beginIndex = 1; } 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("[^/]*");
@NotNull public List<GoExpression> getExpressionList() { if (myList == null) { String text = getExpressionsText(); if (!StringUtil.isNotEmpty(text)) return myList = ContainerUtil.emptyList(); Project project = getPsi().getProject(); List<String> split = StringUtil.split(text, ";"); myList = ContainerUtil.map(split, s -> GoElementFactory.createExpression(project, s)); } return myList; } }
public String getCanonicalPackageName() { String packageName = getPackageName(); if (StringUtil.isNotEmpty(packageName) && GoTestFinder.isTestFile(this)) { return StringUtil.trimEnd(packageName, GoConstants.TEST_SUFFIX); } return packageName; }