@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; }
protected void addFilterParameter(@NotNull GoExecutor executor, String pattern) { if (StringUtil.isNotEmpty(pattern)) { executor.withParameters("-run", pattern); } }
State append(@Nullable String text, boolean nice) { if (StringUtil.isNotEmpty(text)) { currentBlock.append(emphasize(text, nice)); } return this; }
@Override protected void addFilterParameter(@NotNull GoExecutor executor, String pattern) { if (StringUtil.isNotEmpty(pattern)) { executor.withParameters("-check.f", pattern); } } }
@Nullable public static String getRelativePathToRoots(@NotNull VirtualFile file, @NotNull Collection<VirtualFile> sourceRoots) { for (VirtualFile root : sourceRoots) { String relativePath = VfsUtilCore.getRelativePath(file, root, '/'); if (StringUtil.isNotEmpty(relativePath)) { return relativePath; } } return null; }
protected void addNonEmptyElement(@NotNull Element element, @NotNull String attributeName, @Nullable String value) { if (StringUtil.isNotEmpty(value)) { JDOMExternalizerUtil.addElementWithValueAttribute(element, attributeName, value); } }
@NotNull private static File dlv() { String dlvPath = System.getProperty("dlv.path"); if (StringUtil.isNotEmpty(dlvPath)) return new File(dlvPath); return new File(GoUtil.getPlugin().getPath(), "lib/dlv/" + (SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux") + "/" + GoConstants.DELVE_EXECUTABLE_NAME + (SystemInfo.isWindows ? ".exe" : "")); }
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); } } }
@Nullable @Override public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) { if (element instanceof GoNamedElement) { String result = getSignature(element, originalElement); if (StringUtil.isNotEmpty(result)) return result; } return super.getQuickNavigateInfo(element, originalElement); }
@Override public void indexStub(@NotNull GoFileStub stub, @NotNull IndexSink sink) { super.indexStub(stub, sink); String packageName = stub.getPackageName(); if (StringUtil.isNotEmpty(packageName)) { sink.occurrence(GoPackagesIndex.KEY, packageName); } }
@Nullable @Override public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) { String name = ContainerUtil.getFirstItem(fieldNames(context)); return StringUtil.isNotEmpty(name) ? new TextResult(name) : null; }
@Override public boolean shouldCreateStub(@NotNull ASTNode node) { if (!super.shouldCreateStub(node)) return false; PsiElement psi = node.getPsi(); return psi instanceof GoNamedElement && StringUtil.isNotEmpty(((GoNamedElement)psi).getName()); }
@Override public List<String> getUrlFor(PsiElement element, PsiElement originalElement) { String referenceText = getReferenceText(adjustDocElement(element), false); if (StringUtil.isNotEmpty(referenceText)) { return Collections.singletonList("https://godoc.org/" + referenceText); } return super.getUrlFor(element, originalElement); }
private static void check(@NotNull GoNamedElement element, @NotNull ProblemsHolder holder) { String name = element.getName(); if (StringUtil.isNotEmpty(name) && !"_".equals(name) && element.getContainingFile().getImportMap().containsKey(name)) { registerProblem(holder, element); } }
@Nullable private static String calcTailTextForFields(@NotNull GoNamedElement v) { String name = null; if (v instanceof GoFieldDefinition) { GoFieldDefinitionStub stub = ((GoFieldDefinition)v).getStub(); GoTypeSpec spec = stub != null ? stub.getParentStubOfType(GoTypeSpec.class) : PsiTreeUtil.getParentOfType(v, GoTypeSpec.class); name = spec != null ? spec.getName() : null; } return StringUtil.isNotEmpty(name) ? " " + UIUtil.rightArrow() + " " + name : null; }
public String getCanonicalPackageName() { String packageName = getPackageName(); if (StringUtil.isNotEmpty(packageName) && GoTestFinder.isTestFile(this)) { return StringUtil.trimEnd(packageName, GoConstants.TEST_SUFFIX); } return packageName; }
@Override public boolean canExecuteTask(RunConfiguration configuration, GoCommandBeforeRunTask task) { if (configuration instanceof GoRunConfigurationBase) { Module module = ((GoRunConfigurationBase)configuration).getConfigurationModule().getModule(); GoSdkService sdkService = GoSdkService.getInstance(configuration.getProject()); if (sdkService.isGoModule(module)) { return StringUtil.isNotEmpty(sdkService.getSdkHomePath(module)) && StringUtil.isNotEmpty(task.getCommand()); } } return false; }
@Override public void visitFunctionDeclaration(@NotNull GoFunctionDeclaration o) { String functionName = o.getName(); if (StringUtil.isNotEmpty(functionName) && !"_".equals(functionName) && o.getContainingFile().getImportMap().containsKey(functionName)) { holder.registerProblem(o.getIdentifier(), "import \"" + functionName + "\" redeclared in this block", new GoRenameQuickFix(o)); } } };
@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; } }
@Override public String generateDoc(PsiElement element, PsiElement originalElement) { element = adjustDocElement(element); if (element instanceof GoNamedElement) { String signature = getSignature(element, originalElement); signature = StringUtil.isNotEmpty(signature) ? "<b>" + signature + "</b>\n" : signature; return StringUtil.nullize(signature + getCommentText(getCommentsForElement(element), true)); } if (element instanceof PsiDirectory) { return getPackageComment(findDocFileForDirectory((PsiDirectory)element)); } return null; }