コード例 #1
0
 /**
  * Enumerates places in name that could be matched by the pattern at patternIndex position and
  * invokes {@link #matchFragment(String, int, int,
  * com.intellij.psi.codeStyle.MinusculeMatcher.MatchingState)} at those candidate positions
  */
 @Nullable
 private FList<TextRange> matchSkippingWords(
     @NotNull String name,
     final int patternIndex,
     int nameIndex,
     boolean allowSpecialChars,
     MatchingState matchingState) {
   boolean star = isPatternChar(patternIndex - 1, '*');
   final char p = myPattern[patternIndex];
   while (true) {
     int nextOccurrence =
         star
             ? indexOfIgnoreCase(name, nameIndex + 1, p, patternIndex, matchingState.isAsciiName)
             : indexOfWordStart(name, patternIndex, nameIndex);
     if (nextOccurrence < 0) {
       return null;
     }
     // pattern humps are allowed to match in words separated by " ()", lowercase characters aren't
     if (!allowSpecialChars
         && !myHasSeparators
         && !myHasHumps
         && StringUtil.containsAnyChar(name, HARD_SEPARATORS, nameIndex, nextOccurrence)) {
       return null;
     }
     // if the user has typed a dot, don't skip other dots between humps
     if (!allowSpecialChars
         && myHasDots
         && StringUtil.contains(name, nameIndex, nextOccurrence, '.')) {
       return null;
     }
     // uppercase should match either uppercase or a word start
     if (!isUpperCase[patternIndex]
         || Character.isUpperCase(name.charAt(nextOccurrence))
         || isWordStart(name, nextOccurrence)
         ||
         // accept uppercase matching lowercase if the whole prefix is uppercase and case
         // sensitivity allows that
         !myHasHumps && myOptions != NameUtil.MatchingCaseSensitivity.ALL) {
       FList<TextRange> ranges = matchFragment(name, patternIndex, nextOccurrence, matchingState);
       if (ranges != null) {
         return ranges;
       }
     }
     nameIndex = nextOccurrence;
   }
 }
コード例 #2
0
    @Override
    @NotNull
    public Pair<Point, Short> getBestPointPosition(
        LightweightHint hint,
        final PsiElement list,
        int offset,
        final boolean awtTooltip,
        short preferredPosition) {
      if (list != null) {
        TextRange range = list.getTextRange();
        if (!range.contains(offset)) {
          offset = range.getStartOffset() + 1;
        }
      }
      if (previousOffset == offset) return Pair.create(previousBestPoint, previousBestPosition);

      final boolean isMultiline =
          list != null && StringUtil.containsAnyChar(list.getText(), "\n\r");
      final LogicalPosition pos = myEditor.offsetToLogicalPosition(offset);
      Pair<Point, Short> position;

      if (!isMultiline) {
        position =
            chooseBestHintPosition(
                myEditor.getProject(),
                myEditor,
                pos.line,
                pos.column,
                hint,
                awtTooltip,
                preferredPosition);
      } else {
        Point p = HintManagerImpl.getHintPosition(hint, myEditor, pos, HintManager.ABOVE);
        position = new Pair<Point, Short>(p, HintManager.ABOVE);
      }
      previousBestPoint = position.getFirst();
      previousBestPosition = position.getSecond();
      previousOffset = offset;
      return position;
    }
コード例 #3
0
  // please keep an implementation in sync with [junit-rt] ProcessBuilder.createProcess()
  @NotNull
  public static List<String> toCommandLine(
      @NotNull String command, @NotNull List<String> parameters, @NotNull Platform platform) {
    List<String> commandLine = ContainerUtil.newArrayListWithExpectedSize(parameters.size() + 1);

    commandLine.add(FileUtilRt.toSystemDependentName(command, platform.fileSeparator));

    boolean isWindows = platform == Platform.WINDOWS;
    boolean winShell =
        isWindows
            && ("cmd".equalsIgnoreCase(command) || "cmd.exe".equalsIgnoreCase(command))
            && parameters.size() > 1
            && "/c".equalsIgnoreCase(parameters.get(0));

    for (String parameter : parameters) {
      if (isWindows) {
        if (parameter.contains("\"")) {
          parameter = StringUtil.replace(parameter, "\"", "\\\"");
        } else if (parameter.isEmpty()) {
          parameter = "\"\"";
        }
      }

      if (winShell && StringUtil.containsAnyChar(parameter, WIN_SHELL_SPECIALS)) {
        parameter = quote(parameter, SPECIAL_QUOTE);
      }

      if (isQuoted(parameter, SPECIAL_QUOTE)) {
        parameter = quote(parameter.substring(1, parameter.length() - 1), '"');
      }

      commandLine.add(parameter);
    }

    return commandLine;
  }
コード例 #4
0
  public boolean canClose(String inputString) {
    final String subDirName = inputString;

    if (subDirName.length() == 0) {
      Messages.showMessageDialog(
          myProject,
          IdeBundle.message("error.name.should.be.specified"),
          CommonBundle.getErrorTitle(),
          Messages.getErrorIcon());
      return false;
    }

    final boolean multiCreation = StringUtil.containsAnyChar(subDirName, myDelimiters);
    if (!multiCreation) {
      try {
        myDirectory.checkCreateSubdirectory(subDirName);
      } catch (IncorrectOperationException ex) {
        Messages.showMessageDialog(
            myProject,
            CreateElementActionBase.filterMessage(ex.getMessage()),
            CommonBundle.getErrorTitle(),
            Messages.getErrorIcon());
        return false;
      }
    }

    Runnable command =
        new Runnable() {
          public void run() {
            final Runnable run =
                new Runnable() {
                  public void run() {
                    LocalHistoryAction action = LocalHistoryAction.NULL;
                    try {
                      String actionName;
                      String dirPath = myDirectory.getVirtualFile().getPresentableUrl();
                      actionName =
                          IdeBundle.message(
                              "progress.creating.directory", dirPath, File.separator, subDirName);
                      action = LocalHistory.getInstance().startAction(actionName);

                      createDirectories(subDirName);

                    } catch (final IncorrectOperationException ex) {
                      ApplicationManager.getApplication()
                          .invokeLater(
                              new Runnable() {
                                public void run() {
                                  Messages.showMessageDialog(
                                      myProject,
                                      CreateElementActionBase.filterMessage(ex.getMessage()),
                                      CommonBundle.getErrorTitle(),
                                      Messages.getErrorIcon());
                                }
                              });
                    } finally {
                      action.finish();
                    }
                  }
                };
            ApplicationManager.getApplication().runWriteAction(run);
          }
        };
    CommandProcessor.getInstance()
        .executeCommand(
            myProject,
            command,
            myIsDirectory
                ? IdeBundle.message("command.create.directory")
                : IdeBundle.message("command.create.package"),
            null);

    return myCreatedElement != null;
  }