Java Code Examples for com.intellij.openapi.util.text.StringUtil#unquoteString()

The following examples show how to use com.intellij.openapi.util.text.StringUtil#unquoteString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SystemInfo.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
protected Map<String, String> compute() {
  if (isUnix && !isMac) {
    try {
      List<String> lines = FileUtil.loadLines("/etc/os-release");
      Map<String, String> info = ContainerUtil.newHashMap();
      for (String line : lines) {
        int p = line.indexOf('=');
        if (p > 0) {
          String name = line.substring(0, p);
          String value = StringUtil.unquoteString(line.substring(p + 1));
          if (!StringUtil.isEmptyOrSpaces(name) && !StringUtil.isEmptyOrSpaces(value)) {
            info.put(name, value);
          }
        }
      }
      return info;
    }
    catch (IOException ignored) {
    }
  }

  return Collections.emptyMap();
}
 
Example 2
Source File: DartTestLocationProviderZ.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
public static String getTestLabel(@NotNull final DartCallExpression testCallExpression) {
  final DartArguments arguments = testCallExpression.getArguments();
  final DartArgumentList argumentList = arguments == null ? null : arguments.getArgumentList();
  final List<DartExpression> argExpressions = argumentList == null ? null : argumentList.getExpressionList();
  return argExpressions != null && !argExpressions.isEmpty() && argExpressions.get(0) instanceof DartStringLiteralExpression
         ? StringUtil.unquoteString(argExpressions.get(0).getText())
         : null;
}
 
Example 3
Source File: DartTestLocationProviderZ.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
public static String getTestLabel(@NotNull final DartCallExpression testCallExpression) {
  final DartArguments arguments = testCallExpression.getArguments();
  final DartArgumentList argumentList = arguments == null ? null : arguments.getArgumentList();
  final List<DartExpression> argExpressions = argumentList == null ? null : argumentList.getExpressionList();
  return argExpressions != null && !argExpressions.isEmpty() && argExpressions.get(0) instanceof DartStringLiteralExpression
         ? StringUtil.unquoteString(argExpressions.get(0).getText())
         : null;
}
 
Example 4
Source File: ApiDocumentProvider.java    From intellij-swagger with MIT License 5 votes vote down vote up
private Optional<String> getType(
    final PsiElement targetElement, final PsiElement originalElement) {
  final String unquotedText = StringUtil.unquoteString(originalElement.getText());

  final Optional<String> refName =
      Optional.of(StringUtils.substringAfterLast(unquotedText, "/"))
          .map(v -> v.isEmpty() ? unquotedText : v);

  return refName.map(
      name -> {
        String type = getUnquotedFieldValue(targetElement, "type").orElse("undefined type");
        return String.format("%s: %s", name, type);
      });
}
 
Example 5
Source File: JsonReferenceInspection.java    From intellij-swagger with MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {
  final PsiFile file = holder.getFile();
  final VirtualFile virtualFile = file.getVirtualFile();
  final Project project = holder.getProject();

  boolean checkRefs =
      indexFacade.isMainSpecFile(virtualFile, project)
          || indexFacade.isPartialSpecFile(virtualFile, project);

  return new JsonElementVisitor() {
    @Override
    public void visitProperty(@NotNull JsonProperty o) {
      if (!checkRefs) {
        return;
      }
      if ("$ref".equals(o.getName())) {
        JsonValue value = o.getValue();

        if (!(value instanceof JsonStringLiteral)) {
          return;
        }

        final String unquotedValue = StringUtil.unquoteString(value.getText());

        if (!unquotedValue.startsWith("http")) {
          doCheck(holder, value, new CreateJsonReferenceIntentionAction(unquotedValue));
        }
      }
      super.visitProperty(o);
    }
  };
}
 
Example 6
Source File: YamlReferenceInspection.java    From intellij-swagger with MIT License 5 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildVisitor(
    @NotNull final ProblemsHolder holder,
    final boolean isOnTheFly,
    @NotNull final LocalInspectionToolSession session) {
  final PsiFile file = holder.getFile();
  final VirtualFile virtualFile = file.getVirtualFile();
  final Project project = holder.getProject();

  boolean checkRefs =
      indexFacade.isMainSpecFile(virtualFile, project)
          || indexFacade.isPartialSpecFile(virtualFile, project);

  return new YamlPsiElementVisitor() {
    @Override
    public void visitKeyValue(@NotNull YAMLKeyValue keyValue) {
      if (!checkRefs) {
        return;
      }
      if ("$ref".equals(keyValue.getKeyText())) {
        YAMLValue value = keyValue.getValue();

        if (!(value instanceof YAMLScalar)) {
          return;
        }

        final String unquotedValue = StringUtil.unquoteString(value.getText());

        if (!unquotedValue.startsWith("http")) {
          doCheck(holder, value, new CreateYamlReferenceIntentionAction(unquotedValue));
        }
      }
      super.visitKeyValue(keyValue);
    }
  };
}
 
Example 7
Source File: OSProcessUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ProcessInfo[] getProcessList() {
  JavaSysMon javaSysMon = new JavaSysMon();
  com.jezhumble.javasysmon.ProcessInfo[] processInfos = javaSysMon.processTable();
  ProcessInfo[] infos = new ProcessInfo[processInfos.length];
  for (int i = 0; i < processInfos.length; i++) {
    com.jezhumble.javasysmon.ProcessInfo info = processInfos[i];

    String executable;
    String args;
    List<String> commandLineList = StringUtil.splitHonorQuotes(info.getCommand(), ' ');
    if (commandLineList.isEmpty()) {
      executable = info.getName();
      args = "";
    }
    else {
      executable = commandLineList.get(0);
      if (commandLineList.size() > 1) {
        args = StringUtil.join(commandLineList.subList(1, commandLineList.size()), " ");
      }
      else {
        args = "";
      }
    }

    infos[i] = new ProcessInfo(info.getPid(), info.getCommand(), StringUtil.unquoteString(executable, '\"'), args);
  }
  return infos;
}
 
Example 8
Source File: BaseRunConfigurationAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private AnAction[] getChildren(DataContext dataContext) {
  final ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
  final RunnerAndConfigurationSettings existing = context.findExisting();
  if (existing == null) {
    final List<ConfigurationFromContext> producers = getConfigurationsFromContext(context);
    if (producers.size() > 1) {
      final AnAction[] children = new AnAction[producers.size()];
      int chldIdx = 0;
      for (final ConfigurationFromContext fromContext : producers) {
        final ConfigurationType configurationType = fromContext.getConfigurationType();
        final RunConfiguration configuration = fromContext.getConfiguration();
        final String actionName = configuration instanceof LocatableConfiguration
                                  ? StringUtil.unquoteString(suggestRunActionName((LocatableConfiguration)configuration))
                                  : configurationType.getDisplayName();
        final AnAction anAction = new AnAction(actionName, configurationType.getDisplayName(), configurationType.getIcon()) {
          @Override
          public void actionPerformed(AnActionEvent e) {
            perform(fromContext, context);
          }
        };
        anAction.getTemplatePresentation().setText(actionName, false);
        children[chldIdx++] = anAction;
      }
      return children;
    }
  }
  return EMPTY_ARRAY;
}
 
Example 9
Source File: GradleNameElement.java    From ok-gradle with Apache License 2.0 4 votes vote down vote up
@NotNull
public static String convertNameToKey(@NotNull String str) {
  return StringUtil.unquoteString(str);
}
 
Example 10
Source File: CamelEndpoint.java    From camel-idea-plugin with Apache License 2.0 4 votes vote down vote up
public CamelEndpoint(String uri) {
    this.uri = StringUtil.unquoteString(uri);
    processUri();
}
 
Example 11
Source File: AndroidSdkPlatformSection.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
protected String parseItem(ProjectViewParser parser, ParseContext parseContext, String rest) {
  return StringUtil.unquoteString(rest);
}
 
Example 12
Source File: ThriftPsiUtil.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@NotNull
public static String getPath(ThriftInclude include) {
  PsiElement element = include.getLastChild();
  return StringUtil.unquoteString(element.getText());
}