/** * Checks whether the <code>inputString</code> is valid. It is invoked each time * input changes. * * @param inputString the input to check * @return true if input string is valid */ @Override public boolean checkInput(String inputString) { return !StringUtil.isEmpty(inputString); }
/** * This method is invoked just before message dialog is closed with OK code. * If <code>false</code> is returned then then the message dialog will not be closed. * * @param inputString the input to check * @return true if the dialog could be closed, false otherwise. */ @Override public boolean canClose(String inputString) { return !StringUtil.isEmpty(inputString); }
@NotNull private static String getElementFqn(@NotNull GoNamedElement element, @NotNull String name, boolean includePackageName) { if (includePackageName) { String packageName = element.getContainingFile().getPackageName(); if (!StringUtil.isEmpty(packageName)) { return packageName + "." + name; } } return name; }
@Override public void processTerminated(ProcessEvent event) { super.processTerminated(event); if (StringUtil.isEmpty(myConfiguration.getOutputFilePath())) { File file = new File(myOutputFilePath); if (file.exists()) { //noinspection ResultOfMethodCallIgnored file.delete(); } } } });
@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; }
@Nullable public static LookupElement createFieldLookupElement(@NotNull GoFieldDefinition v) { String name = v.getName(); if (StringUtil.isEmpty(name)) return null; return createVariableLikeLookupElement(v, name, Lazy.FIELD_DEFINITION_INSERT_HANDLER, FIELD_PRIORITY); }
@Nullable public static LookupElement createVariableLikeLookupElement(@NotNull GoNamedElement v) { String name = v.getName(); if (StringUtil.isEmpty(name)) return null; return createVariableLikeLookupElement(v, name, Lazy.VARIABLE_OR_FUNCTION_INSERT_HANDLER, VAR_PRIORITY); }
@Override protected void addFilterParameter(@NotNull GoExecutor executor, String pattern) { executor.withParameters("-bench", StringUtil.isEmpty(pattern) ? "." : pattern); executor.withParameters("-run", "^$"); } }
@NotNull public static String unquote(@Nullable String s) { if (StringUtil.isEmpty(s)) return ""; char quote = s.charAt(0); int startOffset = isQuote(quote) ? 1 : 0; int endOffset = s.length(); if (s.length() > 1) { char lastChar = s.charAt(s.length() - 1); if (isQuote(quote) && lastChar == quote) { endOffset = s.length() - 1; } if (!isQuote(quote) && isQuote(lastChar)) { endOffset = s.length() - 1; } } return s.substring(startOffset, endOffset); }
@Override public String toString() { String name = getName(); String str = super.toString(); return StringUtil.isEmpty(name) ? str : str + ": " + name; } }
@Override public void indexStub(@NotNull GoMethodDeclarationStub stub, @NotNull IndexSink sink) { super.indexStub(stub, sink); String typeName = stub.getTypeName(); if (!StringUtil.isEmpty(typeName)) { StubElement parent = stub.getParentStub(); if (parent instanceof GoFileStub) { String packageName = ((GoFileStub)parent).getPackageName(); if (!StringUtil.isEmpty(typeName)) { sink.occurrence(GoMethodIndex.KEY, packageName + "." + typeName); } } } }
@Override public boolean execute(@NotNull PsiElement e, @NotNull ResolveState state) { if (e instanceof GoFunctionOrMethodDeclaration) return false; if (!(e instanceof GoNamedElement)) return true; String name = ((GoNamedElement)e).getName(); if (StringUtil.isEmpty(name) || !myIsCompletion && !myRequestedNameElement.textMatches(name)) return true; if (crossOff(e)) return true; if (e.equals(myOrigin)) return true; return add((GoNamedElement)e) || myIsCompletion; }
@NotNull public static List<GoFile> getAllPackageFiles(@NotNull GoFile file) { String packageName = file.getPackageName(); PsiDirectory parent = file.getParent(); if (parent == null || StringUtil.isEmpty(packageName)) return ContainerUtil.list(file); return getAllPackageFiles(parent, packageName); }
@Override public String toString() { String name = getName(); String str = super.toString(); return StringUtil.isEmpty(name) ? str : str + ": " + name; } }
@NotNull private static List<GoMethodDeclaration> calcMethods(@NotNull GoTypeSpec o) { PsiFile file = o.getContainingFile().getOriginalFile(); if (file instanceof GoFile) { String packageName = ((GoFile)file).getPackageName(); String typeName = o.getName(); if (StringUtil.isEmpty(packageName) || StringUtil.isEmpty(typeName)) return Collections.emptyList(); String key = packageName + "." + typeName; Project project = ((GoFile)file).getProject(); GlobalSearchScope scope = GoPackageUtil.packageScope((GoFile)file); Collection<GoMethodDeclaration> declarations = GoMethodIndex.find(key, project, scope, GoIdFilter.getFilesFilter(scope)); return ContainerUtil.newArrayList(declarations); } return Collections.emptyList(); }
private void addExcludedPackage(@Nullable String packageName) { if (StringUtil.isEmpty(packageName)) return; int index = -Arrays.binarySearch(myExcludePackagesModel.toArray(), packageName) - 1; if (index >= 0) { myExcludePackagesModel.add(index, packageName); ScrollingUtil.ensureIndexIsVisible(myExcludePackagesList, index, 0); } myExcludePackagesList.clearSelection(); myExcludePackagesList.setSelectedValue(packageName, true); myExcludePackagesList.requestFocus(); } }
@NotNull public static Set<PsiElement> findRedundantImportIdentifiers(@NotNull MultiMap<String, GoImportSpec> importMap) { Set<PsiElement> importIdentifiersToDelete = ContainerUtil.newLinkedHashSet(); for (PsiElement importEntry : importMap.values()) { GoImportSpec importSpec = getImportSpec(importEntry); if (importSpec != null) { String localPackageName = importSpec.getLocalPackageName(); if (!StringUtil.isEmpty(localPackageName)) { if (Comparing.equal(importSpec.getAlias(), localPackageName)) { importIdentifiersToDelete.add(importSpec.getIdentifier()); } } } } return importIdentifiersToDelete; }
@Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (file.getFileType() != GoFileType.INSTANCE) return null; PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file); if (psiFile == null) return null; if (psiFile.getLanguage() != GoLanguage.INSTANCE) return null; Module module = ModuleUtilCore.findModuleForPsiElement(psiFile); if (module == null) return null; String sdkHomePath = GoSdkService.getInstance(myProject).getSdkHomePath(module); if (StringUtil.isEmpty(sdkHomePath)) { return createMissingSdkPanel(myProject, module); } if (!PropertiesComponent.getInstance().getBoolean(DO_NOT_SHOW_NOTIFICATION_ABOUT_EMPTY_GOPATH, false)) { String goPath = GoSdkUtil.retrieveGoPath(myProject, module); if (StringUtil.isEmpty(goPath.trim())) { return createEmptyGoPathPanel(myProject); } } return null; }
public static void applyFix(@NotNull Project project, @Nullable Module module, @NotNull String packageName, boolean startInBackground) { String sdkPath = GoSdkService.getInstance(project).getSdkHomePath(module); if (StringUtil.isEmpty(sdkPath)) return; CommandProcessor.getInstance().runUndoTransparentAction(() -> { Consumer<Boolean> consumer = aBoolean -> VirtualFileManager.getInstance().asyncRefresh(null); GoExecutor.in(project, module).withPresentableName("go get -t " + packageName + "/...") .withParameters("get", "-t", packageName+"/...").showNotifications(false, true).showOutputOnError() .executeWithProgress(!startInBackground, consumer); }); }
private static void autoImport(@NotNull InsertionContext context, @NotNull GoNamedElement element) { PsiFile file = context.getFile(); boolean vendoringEnabled = GoVendoringUtil.isVendoringEnabled(ModuleUtilCore.findModuleForPsiElement(file)); String importPath = element.getContainingFile().getImportPath(vendoringEnabled); if (StringUtil.isEmpty(importPath)) return; PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getEditor().getDocument()); PsiReference reference = file.findReferenceAt(context.getStartOffset()); if (reference != null) { PsiElement referenceElement = reference.getElement(); GoImportPackageQuickFix fix = new GoImportPackageQuickFix(referenceElement, importPath); fix.invoke(context.getProject(), file, context.getEditor(), referenceElement, referenceElement); } } }