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() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: consulo   File: SystemInfo.java    License: 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
@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
@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 Project: intellij-swagger   File: ApiDocumentProvider.java    License: 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
@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
@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 Project: consulo   File: OSProcessUtil.java    License: 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
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 Project: ok-gradle   File: GradleNameElement.java    License: 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 Project: camel-idea-plugin   File: CamelEndpoint.java    License: Apache License 2.0 4 votes vote down vote up
public CamelEndpoint(String uri) {
    this.uri = StringUtil.unquoteString(uri);
    processUri();
}
 
Example 11
@Nullable
@Override
protected String parseItem(ProjectViewParser parser, ParseContext parseContext, String rest) {
  return StringUtil.unquoteString(rest);
}
 
Example 12
Source Project: intellij-thrift   File: ThriftPsiUtil.java    License: 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());
}