@NotNull private String getPresentableName() { return ObjectUtils.notNull(myPresentableName, "go"); } }
@NotNull private String getPresentableName() { return ObjectUtils.notNull(myPresentableName, "Ballerina Executor"); } }
@NotNull private static GoExpression getTopmostExpression(@NotNull GoExpression expression) { return ObjectUtils.notNull(PsiTreeUtil.getTopmostParentOfType(expression, GoExpression.class), expression); }
@NotNull private static TextRange getTextRange(@NotNull PsiElement o) { return ObjectUtils.notNull(PsiTreeUtil.getParentOfType(o, GoTopLevelDeclaration.class), o).getTextRange(); } }
@NotNull public static GoType getUnderlyingType(@NotNull GoType o) { GoType type = RecursionManager.doPreventingRecursion(o, true, () -> getTypeInner(o)); return ObjectUtils.notNull(type, o); }
@NotNull public static LookupElement createTypeConversionLookupElement(@NotNull GoTypeSpec t, @NotNull String lookupString, @Nullable InsertHandler<LookupElement> insertHandler, @Nullable String importPath, double priority) { // todo: check context and place caret in or outside {} InsertHandler<LookupElement> handler = ObjectUtils.notNull(insertHandler, Lazy.TYPE_CONVERSION_INSERT_HANDLER); return createTypeLookupElement(t, lookupString, handler, importPath, priority); }
@Nullable public static LookupElement createPackageLookupElement(@NotNull GoImportSpec spec, @Nullable String name, boolean vendoringEnabled) { name = name != null ? name : ObjectUtils.notNull(spec.getAlias(), spec.getLocalPackageName()); return createPackageLookupElement(name, spec.getImportString().resolve(), spec, vendoringEnabled, true); }
@NotNull public static Collection<VirtualFile> getYamlFiles(@NotNull Project project, @Nullable Module module) { UserDataHolder dataHolder = ObjectUtils.notNull(module, project); return CachedValuesManager.getManager(project).getCachedValue(dataHolder, () -> { Collection<VirtualFile> yamlFiles = ApplicationManager.getApplication().runReadAction(new Computable<Collection<VirtualFile>>() { @Override public Collection<VirtualFile> compute() { return FilenameIndex.getAllFilesByExt(project, "yaml", GoUtil.moduleScopeWithoutLibraries(project, module)); } }); return CachedValueProvider.Result.create(yamlFiles, getInstance(project)); }); } }
@NotNull public static GoType getActualType(@NotNull GoParType o) { return ObjectUtils.notNull(SyntaxTraverser.psiTraverser(o).filter(Conditions.notInstanceOf(GoParType.class)) .filter(GoType.class).first(), o.getType()); }
@Override public String getSdkHomePath(@Nullable Module module) { ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> { Sdk sdk = getGoSdk(module); return CachedValueProvider.Result.create(sdk != null ? sdk.getHomePath() : null, this); }); }
@Nullable @Override public String getSdkVersion(@Nullable Module module) { String parentVersion = super.getSdkVersion(module); if (parentVersion != null) { return parentVersion; } ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> { Sdk sdk = getGoSdk(module); return CachedValueProvider.Result.create(sdk != null ? sdk.getVersionString() : null, this); }); }
@Override public String getSdkHomePath(@Nullable Module module) { ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> { Sdk sdk = getBallerinaSdk(module); return CachedValueProvider.Result.create(sdk != null ? sdk.getHomePath() : null, this); }); }
@Nullable @Override public String getSdkVersion(@Nullable Module module) { String parentVersion = super.getSdkVersion(module); if (parentVersion != null) { return parentVersion; } ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> { String result = null; String sdkHomePath = getSdkHomePath(module); if (sdkHomePath != null) { result = GoSdkUtil.retrieveGoVersion(sdkHomePath); } return CachedValueProvider.Result.create(result, this); }); }
@Override public boolean isInContext(@NotNull PsiFile file, int offset) { if (PsiUtilCore.getLanguageAtOffset(file, offset).isKindOf(GoLanguage.INSTANCE)) { PsiElement psiElement = ObjectUtils.notNull(file.findElementAt(offset), file); if (!acceptLeaf()) { psiElement = getFirstCompositeElement(psiElement); } return psiElement != null && isInContext(psiElement); } return false; }
@Nullable @Override public String getSdkHomePath(@Nullable Module module) { ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> CachedValueProvider.Result .create(ApplicationManager.getApplication().runReadAction(new Computable<String>() { @Nullable @Override public String compute() { LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject); for (Library library : table.getLibraries()) { String libraryName = library.getName(); if (libraryName != null && libraryName.startsWith(LIBRARY_NAME)) { for (VirtualFile root : library.getFiles(OrderRootType.CLASSES)) { if (isGoSdkLibRoot(root)) { return libraryRootToSdkPath(root); } } } } return null; } }), this)); }
@Nullable @Override public String getSdkVersion(@Nullable Module module) { String parentVersion = super.getSdkVersion(module); if (parentVersion != null) { return parentVersion; } ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> { Sdk sdk = getBallerinaSdk(module); return CachedValueProvider.Result.create(sdk != null ? sdk.getVersionString() : null, this); }); }
@Nullable @Override public String getSdkVersion(@Nullable Module module) { String parentVersion = super.getSdkVersion(module); if (parentVersion != null) { return parentVersion; } ComponentManager holder = ObjectUtils.notNull(module, myProject); return CachedValuesManager.getManager(myProject).getCachedValue(holder, () -> { String result = null; String sdkHomePath = getSdkHomePath(module); if (sdkHomePath != null) { result = BallerinaSdkUtil.retrieveBallerinaVersion(sdkHomePath); } return CachedValueProvider.Result.create(result, this); }); }
@NotNull public static GoVarSpec addSpec(@NotNull GoVarDeclaration declaration, @NotNull String name, @Nullable String type, @Nullable String value, @Nullable GoVarSpec specAnchor) { Project project = declaration.getProject(); GoVarSpec newSpec = GoElementFactory.createVarSpec(project, name, type, value); PsiElement rParen = declaration.getRparen(); if (rParen == null) { GoVarSpec item = ContainerUtil.getFirstItem(declaration.getVarSpecList()); assert item != null; boolean updateAnchor = specAnchor == item; declaration = (GoVarDeclaration)declaration.replace(GoElementFactory.createVarDeclaration(project, "(" + item.getText() + ")")); rParen = declaration.getRparen(); if (updateAnchor) { specAnchor = ContainerUtil.getFirstItem(declaration.getVarSpecList()); } } assert rParen != null; PsiElement anchor = ObjectUtils.notNull(specAnchor, rParen); if (!hasNewLineBefore(anchor)) { declaration.addBefore(GoElementFactory.createNewLine(declaration.getProject()), anchor); } GoVarSpec spec = (GoVarSpec)declaration.addBefore(newSpec, anchor); declaration.addBefore(GoElementFactory.createNewLine(declaration.getProject()), anchor); return spec; }
@NotNull public GeneralCommandLine createCommandLine() throws ExecutionException { if (myGoRoot == null) { throw new ExecutionException("Sdk is not set or Sdk home path is empty for module"); } GeneralCommandLine commandLine = !myPtyDisabled && PtyCommandLine.isEnabled() ? new PtyCommandLine() : new GeneralCommandLine(); commandLine.setExePath(ObjectUtils.notNull(myExePath, GoSdkService.getGoExecutablePath(myGoRoot))); commandLine.getEnvironment().putAll(myExtraEnvironment); commandLine.getEnvironment().put(GoConstants.GO_ROOT, StringUtil.notNullize(myGoRoot)); commandLine.getEnvironment().put(GoConstants.GO_PATH, StringUtil.notNullize(myGoPath)); if (myVendoringEnabled != null) { commandLine.getEnvironment().put(GoConstants.GO_VENDORING_EXPERIMENT, myVendoringEnabled ? "1" : "0"); } Collection<String> paths = ContainerUtil.newArrayList(); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(commandLine.getEnvironment().get(GoConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(EnvironmentUtil.getValue(GoConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(myEnvPath, true)); commandLine.getEnvironment().put(GoConstants.PATH, StringUtil.join(paths, File.pathSeparator)); commandLine.withWorkDirectory(myWorkDirectory); commandLine.addParameters(myParameterList.getList()); commandLine.withParentEnvironmentType(myParentEnvironmentType); commandLine.withCharset(CharsetToolkit.UTF8_CHARSET); return commandLine; }
@Nullable public static GoFile findBuiltinFile(@NotNull PsiElement context) { Project project = context.getProject(); // it's important to ask module on file, otherwise module won't be found for elements in libraries files [zolotov] Module moduleFromContext = ModuleUtilCore.findModuleForPsiElement(context.getContainingFile()); if (moduleFromContext == null) { for (Module module : ModuleManager.getInstance(project).getModules()) { if (GoSdkService.getInstance(project).isGoModule(module)) { moduleFromContext = module; break; } } } Module module = moduleFromContext; UserDataHolder holder = ObjectUtils.notNull(module, project); VirtualFile file = CachedValuesManager.getManager(context.getProject()).getCachedValue(holder, () -> { VirtualFile sdkSrcDir = getSdkSrcDir(project, module); VirtualFile result = sdkSrcDir != null ? sdkSrcDir.findFileByRelativePath(GoConstants.BUILTIN_FILE_PATH) : null; return CachedValueProvider.Result.create(result, getSdkAndLibrariesCacheDependencies(project, module, result)); }); if (file == null) return null; PsiFile psiBuiltin = context.getManager().findFile(file); return psiBuiltin instanceof GoFile ? (GoFile)psiBuiltin : null; }