@Nullable @Override public String getUserNotificationInfo() { int entriesToDelete = importEntriesToDelete.size(); int identifiersToDelete = importIdentifiersToDelete.size(); String result = ""; if (entriesToDelete > 0) { result = "Removed " + entriesToDelete + " import" + (entriesToDelete > 1 ? "s" : ""); } if (identifiersToDelete > 0) { result += result.isEmpty() ? "Removed " : " and "; result += identifiersToDelete + " alias" + (identifiersToDelete > 1 ? "es" : ""); } return StringUtil.nullize(result); }
public static void printGoEnvVariables(@NotNull GeneralCommandLine commandLine, @NotNull ProcessHandler handler) { Map<String, String> environment = commandLine.getEnvironment(); handler.notifyTextAvailable("GOROOT=" + StringUtil.nullize(environment.get(GoConstants.GO_ROOT)) + '\n', ProcessOutputTypes.SYSTEM); handler.notifyTextAvailable("GOPATH=" + StringUtil.nullize(environment.get(GoConstants.GO_PATH)) + '\n', ProcessOutputTypes.SYSTEM); } }
@Nullable public static String getTestTargetPackage(@Nullable PsiFile file) { if (isTestFile(file)) { String packageName = ((GoFile)file).getPackageName(); if (packageName != null && packageName.endsWith(GoConstants.TEST_SUFFIX)) { return StringUtil.nullize(StringUtil.trimEnd(packageName, GoConstants.TEST_SUFFIX)); } } return null; }
@Override protected void applyEditorTo(@NotNull GoAppEngineRunConfiguration configuration) throws ConfigurationException { configuration.setHost(StringUtil.nullize(myHostField.getText().trim())); configuration.setPort(StringUtil.nullize(myPortField.getText().trim())); configuration.setAdminPort(StringUtil.nullize(myAdminPortField.getText().trim())); configuration.setConfigFile(StringUtil.nullize(myConfigFileField.getText().trim())); myCommonSettingsPanel.applyEditorTo(configuration); }
@NotNull @Override public GoFileStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { return new GoFileStub(null, StringRef.fromNullableString(StringUtil.nullize(dataStream.readUTF()))); }
@NotNull @Override public GoImportSpecStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException { return new GoImportSpecStub(parentStub, this, StringUtil.nullize(dataStream.readUTFFast()), dataStream.readUTFFast(), dataStream.readBoolean()); }
/** * Returns path to the {@link IgnoreLanguage} binary or null if not available. * Currently only {@link GitLanguage} is supported. * * @param language current language * @return path to binary */ @Nullable private static String bin(@NotNull IgnoreLanguage language) { if (GitLanguage.INSTANCE.equals(language) && GIT_ENABLED) { final String bin = GitExecutableManager.getInstance().getPathToGit(); return StringUtil.nullize(bin); } return null; }
@Nullable private static String getValue(@Nullable GoExpression expression) { if (expression instanceof GoStringLiteral) { return ElementManipulators.getValueText(expression); } if (expression instanceof GoAddExpr) { StringBuilder result = new StringBuilder(); for (GoExpression expr : ((GoAddExpr)expression).getExpressionList()) { String value = getValue(expr); if (value == null) return null; result.append(value); } return StringUtil.nullize(result.toString()); } if (expression instanceof GoParenthesesExpr) { return getValue(((GoParenthesesExpr)expression).getExpression()); } return null; }}
@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; }
@Override protected void applyEditorTo(@NotNull GoApplicationConfiguration configuration) throws ConfigurationException { configuration.setFilePath(myFileField.getText()); configuration.setPackage(myPackageField.getText()); configuration.setKind((GoApplicationConfiguration.Kind)myRunKindComboBox.getSelectedItem()); configuration.setFileOutputPath(StringUtil.nullize(myOutputFilePathField.getText())); myCommonSettingsPanel.applyEditorTo(configuration); }
@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; }
@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; }
@NotNull public GeneralCommandLine createCommandLine() throws ExecutionException { GeneralCommandLine commandLine = !myPtyDisabled && PtyCommandLine.isEnabled() ? new PtyCommandLine() : new GeneralCommandLine(); commandLine.setExePath(ObjectUtils.notNull(myExePath, ObjectUtils.notNull(BallerinaSdkService .getBallerinaExecutablePath(myBallerinaPath)))); commandLine.getEnvironment().putAll(myExtraEnvironment); //Todo - Add BALLERINA_REPOSITORY // commandLine.getEnvironment().put(BallerinaConstants.BALLERINA_REPOSITORY, // StringUtil.notNullize(myBallerinaPath)); Collection<String> paths = ContainerUtil.newArrayList(); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(commandLine.getEnvironment().get( BallerinaConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(EnvironmentUtil.getValue(BallerinaConstants.PATH), true)); ContainerUtil.addIfNotNull(paths, StringUtil.nullize(myEnvPath, true)); commandLine.getEnvironment().put(BallerinaConstants.PATH, StringUtil.join(paths, File.pathSeparator)); commandLine.withWorkDirectory(myWorkDirectory); commandLine.addParameters(myParameterList.getList()); commandLine.withParentEnvironmentType(myParentEnvironmentType); commandLine.withCharset(CharsetToolkit.UTF8_CHARSET); return commandLine; }
@Nullable @Contract(pure = true) public static String nullize(@Nullable final String s) { return nullize(s, false); }
public GenOptions(BnfFile myFile) { Map<String, String> genOptions = getRootAttribute(myFile, KnownAttribute.GENERATE).asMap(); names = Names.forName(genOptions.get("names")); generatePsi = getGenerateOption(myFile, KnownAttribute.GENERATE_PSI, genOptions, "psi"); generatePsiFactory = !"no".equals(genOptions.get("psi-factory")); generatePsiClassesMap = "yes".equals(genOptions.get("psi-classes-map")); generateTokenTypes = getGenerateOption(myFile, KnownAttribute.GENERATE_TOKENS, genOptions, "tokens"); generateTokenSets = generateTokenTypes && "yes".equals(genOptions.get("token-sets")); generateElementTypes = !"no".equals(genOptions.get("elements")); generateExactTypes = StringUtil.notNullize(genOptions.get("exact-types")); generateFirstCheck = getGenerateOption(myFile, KnownAttribute.GENERATE_FIRST_CHECK, genOptions, "first-check", "firstCheck"); generateExtendedPin = getGenerateOption(myFile, KnownAttribute.EXTENDED_PIN, genOptions, "extended-pin", "extendedPin"); generateTokenAccessors = getGenerateOption(myFile, KnownAttribute.GENERATE_TOKEN_ACCESSORS, genOptions, "token-accessors", "tokenAccessors"); generateTokenAccessorsSet = genOptions.containsKey("token-accessors") || genOptions.containsKey("tokenAccessors"); generateRootRules = PatternUtil.compileSafe(genOptions.get("root-rules"), null); generateVisitor = !"no".equals(genOptions.get("visitor")); visitorValue = "void".equals(genOptions.get("visitor-value")) ? null : StringUtil.nullize(genOptions.get("visitor-value")); generateTokenCase = ParserGeneratorUtil.enumFromString(genOptions.get("token-case"), Case.UPPER); generateElementCase = ParserGeneratorUtil.enumFromString(genOptions.get("element-case"), Case.UPPER); javaVersion = JavaVersion.fromString(genOptions.get("java")); } }
@NotNull private static Map<IElementType, String> collectOptions(@NotNull PsiFile file) { PsiElement declarationsSection = PsiTreeUtil.findChildOfType(file, JFlexDeclarationsSection.class); if (declarationsSection == null) return Collections.emptyMap(); Map<IElementType, String> result = ContainerUtil.newLinkedHashMap(); for (JFlexOption o : SyntaxTraverser.psiApi().children(declarationsSection).filter(JFlexOption.class)) { IElementType key = PsiUtilCore.getElementType(o.getFirstChild()); String value = TextRange.create(o.getFirstChild().getTextLength(), o.getTextLength()).substring(o.getText()).trim(); String prevValue = StringUtil.nullize(result.get(key)); result.put(key, prevValue == null ? value : value.isEmpty() ? prevValue : prevValue +", " + value); } return result; } }
boolean isPublic = options.containsKey(JFlexTypes.FLEX_OPT_PUBLIC); boolean isFinal = options.containsKey(JFlexTypes.FLEX_OPT_FINAL); String lexerClass = ObjectUtils.notNull(StringUtil.nullize(options.get(JFlexTypes.FLEX_OPT_CLASS)), "Lexer"); String returnType = ObjectUtils.notNull(StringUtil.nullize(options.get(JFlexTypes.FLEX_OPT_TYPE)), "int"); String implementsStr = ObjectUtils.notNull(StringUtil.nullize(options.get(JFlexTypes.FLEX_OPT_IMPLEMENTS)), "");
@Override protected void applyEditorTo(@NotNull PerlRunConfiguration perlRunConfiguration) throws ConfigurationException { perlRunConfiguration.setScriptPath(myScriptField.getText()); myParametersPanel.applyTo(perlRunConfiguration); perlRunConfiguration.setConsoleCharset(StringUtil.nullize((String)myConsoleCharset.getSelectedItem(), true)); perlRunConfiguration.setPerlParameters(myPerlParametersPanel.getText()); perlRunConfiguration.setUseAlternativeSdk(myAlternativeSdkCheckbox.isSelected()); mySdkConfigurable.apply(); perlRunConfiguration.setAlternativeSdkName(ObjectUtils.doIfNotNull(mySdkProxy, Sdk::getName)); super.applyEditorTo(perlRunConfiguration); }
javaParameters.setJarPath(jflex.get(0).getAbsolutePath()); javaParameters.getVMParametersList().add("-Xmx512m"); javaParameters.getProgramParametersList().addParametersString(StringUtil.nullize(Options.GEN_JFLEX_ARGS.get())); javaParameters.getProgramParametersList().add("-skel", jflex.get(1).getAbsolutePath()); javaParameters.getProgramParametersList().add("-d", VfsUtil.virtualToIoFile(virtualDir).getAbsolutePath());