Java 类com.intellij.openapi.fileTypes.FileTypes 实例源码

项目:idea-php-typo3-plugin    文件:ExtensionFileGenerationUtil.java   
/**
 * @param templateFile        Name of the generated file
 * @param destinationPath     Relative path to the target file system entry
 * @param extensionDefinition Extension definition containing all relevant metadata
 * @param context             Template Context variables
 * @param project             Project in context
 */
public static PsiElement fromTemplate(@NotNull String templateFile, @NotNull String destinationPath, @NotNull String destinationFileName, @NotNull TYPO3ExtensionDefinition extensionDefinition, @NotNull Map<String, String> context, Project project) {
    String template = readTemplateToString(templateFile, context);

    VirtualFile targetDirectory = getOrCreateDestinationPath(extensionDefinition.getRootDirectory(), destinationPath);

    LanguageFileType fileType = FileTypes.PLAIN_TEXT;
    if (templateFile.endsWith(".php")) {
        fileType = PhpFileType.INSTANCE;
    }

    PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText(destinationFileName, fileType, template);
    CodeStyleManager.getInstance(project).reformat(fileFromText);
    return PsiDirectoryFactory
            .getInstance(project)
            .createDirectory(targetDirectory)
            .add(fileFromText);
}
项目:idea-php-typo3-plugin    文件:ExtensionFileGenerationUtil.java   
/**
 * @param templateFile           Name of the generated file
 * @param destinationPath        Relative path to the target file system entry
 * @param extensionRootDirectory Extension definition containing all relevant metadata
 * @param context                Template Context variables
 * @param project                Project in context
 */
public static PsiElement fromTemplate(@NotNull String templateFile, @NotNull String destinationPath, @NotNull String destinationFileName, @NotNull PsiDirectory extensionRootDirectory, @NotNull Map<String, String> context, Project project) {
    String template = readTemplateToString(templateFile, context);

    VirtualFile targetDirectory = getOrCreateDestinationPath(extensionRootDirectory.getVirtualFile(), destinationPath);

    LanguageFileType fileType = FileTypes.PLAIN_TEXT;
    if (templateFile.endsWith(".php")) {
        fileType = PhpFileType.INSTANCE;
    }

    PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText(destinationFileName, fileType, template);
    CodeStyleManager.getInstance(project).reformat(fileFromText);
    return PsiDirectoryFactory
            .getInstance(project)
            .createDirectory(targetDirectory)
            .add(fileFromText);
}
项目:intellij-nette-tester    文件:TesterNewTestCaseDialog.java   
private void createUIComponents() {
    testTargetTextField = new EditorTextField("", getProject(), FileTypes.PLAIN_TEXT);
    namespaceComboBox = new PhpNamespaceComboBox(getProject(), "", getDisposable());
    directoryComboBox = new PhpPsrDirectoryComboBox(getProject()) {
        @Override
        public void init(@NotNull VirtualFile baseDir, @NotNull String namespace) {
            super.init(baseDir, namespace);
            ProjectFileIndex index = ProjectRootManager.getInstance(TesterNewTestCaseDialog.this.getProject()).getFileIndex();
            this.setDirectoriesFilter(index::isInTestSourceContent);

            this.updateDirectories(TesterNewTestCaseDialog.this.getNamespace());
        }
    };

    classToTestLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.classToTest"));
    testClassLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.testClass"));
    namespaceLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.namespace"));
    fileNameLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.fileName"));
    directoryLabel = new JBLabel(TesterBundle.message("dialog.newTestCase.label.directory"));

    testTargetCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI);
    namespaceCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI);
    directoryCompletionHint = new JBLabel(UIUtil.ComponentStyle.MINI);
}
项目:intellij-ce-playground    文件:FindManagerTest.java   
public void testReplaceRegexp() {
  FindModel findModel = new FindModel();
  findModel.setStringToFind("bug_(?=here)");
  findModel.setStringToReplace("x_$0t");
  findModel.setWholeWordsOnly(false);
  findModel.setFromCursor(false);
  findModel.setGlobal(true);
  findModel.setMultipleFiles(false);
  findModel.setProjectScope(true);
  findModel.setRegularExpressions(true);
  findModel.setPromptOnReplace(false);

  myFindManager.setFindNextModel(null);
  myFindManager.getFindInFileModel().copyFrom(findModel);

  String text = "bug_here\nbug_here";
  configureByText(FileTypes.PLAIN_TEXT, text);
  assertTrue(FindUtil.replace(getProject(), getEditor(), 0, findModel));

  assertEquals("x_bug_there\nx_bug_there", getEditor().getDocument().getText());
}
项目:intellij-ce-playground    文件:FindManagerTest.java   
public void testReplaceRegexp1() {
  FindModel findModel = new FindModel();
  findModel.setStringToFind("bug_(?=here)");
  findModel.setStringToReplace("$0");
  findModel.setWholeWordsOnly(false);
  findModel.setFromCursor(false);
  findModel.setGlobal(true);
  findModel.setMultipleFiles(false);
  findModel.setProjectScope(true);
  findModel.setRegularExpressions(true);
  findModel.setPromptOnReplace(false);

  myFindManager.setFindNextModel(null);
  myFindManager.getFindInFileModel().copyFrom(findModel);

  String text = "bug_here\nbug_here";
  configureByText(FileTypes.PLAIN_TEXT, text);
  assertTrue(FindUtil.replace(getProject(), getEditor(), 0, findModel));

  assertEquals(text, getEditor().getDocument().getText());
}
项目:intellij-ce-playground    文件:FindManagerTest.java   
public void testReplaceRegexpWithNewLine() {
  FindModel findModel = new FindModel();
  findModel.setStringToFind("xxx");
  findModel.setStringToReplace("xxx\\n");
  findModel.setWholeWordsOnly(false);
  findModel.setFromCursor(false);
  findModel.setGlobal(true);
  findModel.setMultipleFiles(false);
  findModel.setProjectScope(true);
  findModel.setRegularExpressions(true);
  findModel.setPromptOnReplace(false);

  myFindManager.setFindNextModel(null);
  myFindManager.getFindInFileModel().copyFrom(findModel);

  String text = "xxx";
  configureByText(FileTypes.PLAIN_TEXT, text);
  assertTrue(FindUtil.replace(getProject(), getEditor(), 0, findModel));

  assertEquals(text+"\n", getEditor().getDocument().getText());
}
项目:intellij-ce-playground    文件:FindManagerTest.java   
public void testReplacePreserveCase() {
  configureByText(FileTypes.PLAIN_TEXT, "Bar bar BAR");
  FindModel model = new FindModel();
  model.setStringToFind("bar");
  model.setStringToReplace("foo");
  model.setPromptOnReplace(false);
  model.setPreserveCase(true);

  FindUtil.replace(myProject, myEditor, 0, model);
  assertEquals("Foo foo FOO", myEditor.getDocument().getText());

  configureByText(FileTypes.PLAIN_TEXT, "Bar bar");

  model.setStringToFind("bar");
  model.setStringToReplace("fooBar");

  FindUtil.replace(myProject, myEditor, 0, model);
  assertEquals("FooBar fooBar", myEditor.getDocument().getText());
}
项目:intellij-ce-playground    文件:ErrorDiffTool.java   
@NotNull
private JComponent createComponent(@NotNull DiffRequest request) {
  if (request instanceof MessageDiffRequest) {
    // TODO: explain some of ErrorDiffRequest exceptions ?
    String message = ((MessageDiffRequest)request).getMessage();
    return DiffUtil.createMessagePanel(message);
  }
  if (request instanceof ComponentDiffRequest) {
    return ((ComponentDiffRequest)request).getComponent(myContext);
  }
  if (request instanceof ContentDiffRequest) {
    List<DiffContent> contents = ((ContentDiffRequest)request).getContents();
    for (final DiffContent content : contents) {
      if (content instanceof FileContent && FileTypes.UNKNOWN.equals(content.getContentType())) {
        final VirtualFile file = ((FileContent)content).getFile();

        UnknownFileTypeDiffRequest unknownFileTypeRequest = new UnknownFileTypeDiffRequest(file, myRequest.getTitle());
        return unknownFileTypeRequest.getComponent(myContext);
      }
    }
  }

  return DiffUtil.createMessagePanel("Can't show diff");
}
项目:intellij-ce-playground    文件:FileChooserDescriptor.java   
@Nullable
public final VirtualFile getFileToSelect(VirtualFile file) {
  if (file.isDirectory() && (myChooseFolders || isFileSelectable(file))) {
    return file;
  }
  boolean isJar = file.getFileType() == FileTypes.ARCHIVE;
  if (!isJar) {
    return acceptAsGeneralFile(file) ? file : null;
  }
  if (myChooseJarsAsFiles) {
    return file;
  }
  if (!acceptAsJarFile(file)) {
    return null;
  }
  String path = file.getPath();
  return JarFileSystem.getInstance().findFileByPath(path + JarFileSystem.JAR_SEPARATOR);
}
项目:intellij-ce-playground    文件:EncodingUtil.java   
@NotNull
static Pair<Charset, String> checkHardcodedCharsetFileType(@NotNull VirtualFile virtualFile) {
  FileType fileType = virtualFile.getFileType();
  if (fileType.isBinary()) return Pair.create(null, "binary file");
  // in lesser IDEs all special file types are plain text so check for that first
  if (fileType == FileTypes.PLAIN_TEXT) return Pair.create(null, null);
  if (fileType == StdFileTypes.GUI_DESIGNER_FORM) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA GUI Designer form");
  if (fileType == StdFileTypes.IDEA_MODULE) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA module file");
  if (fileType == StdFileTypes.IDEA_PROJECT) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA project file");
  if (fileType == StdFileTypes.IDEA_WORKSPACE) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA workspace file");

  if (fileType == StdFileTypes.PROPERTIES) return Pair.create(virtualFile.getCharset(), ".properties file");

  if (fileType == StdFileTypes.XML || fileType == StdFileTypes.JSPX) {
    return Pair.create(virtualFile.getCharset(), "XML file");
  }
  return Pair.create(null, null);
}
项目:intellij-ce-playground    文件:ExportToFileUtil.java   
protected JComponent createCenterPanel() {
  final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true);
  ((DocumentImpl)document).setAcceptSlashR(true);

  myTextArea = EditorFactory.getInstance().createEditor(document, myProject, FileTypes.PLAIN_TEXT, true);
  final EditorSettings settings = myTextArea.getSettings();
  settings.setLineNumbersShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setRightMarginShown(false);
  settings.setAdditionalLinesCount(0);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalPageAtBottom(false);
  ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor());
  myTextArea.getComponent().setPreferredSize(new Dimension(700, 400));
  return myTextArea.getComponent();
}
项目:intellij-ce-playground    文件:SelectionQuotingTypedHandlerTest.java   
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(FileTypes.PLAIN_TEXT, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
项目:intellij-ce-playground    文件:PathEditor.java   
private static boolean isJarFile(final VirtualFile file) {
  return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      VirtualFile tempFile = file;
      if ((file.getFileSystem() instanceof JarFileSystem) && file.getParent() == null) {
        //[myakovlev] It was bug - directories with *.jar extensions was saved as files of JarFileSystem.
        //    so we can not just return true, we should filter such directories.
        String path = file.getPath().substring(0, file.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
        tempFile = LocalFileSystem.getInstance().findFileByPath(path);
      }
      if (tempFile != null && !tempFile.isDirectory()) {
        return Boolean.valueOf(tempFile.getFileType().equals(FileTypes.ARCHIVE));
      }
      return Boolean.FALSE;
    }
  }).booleanValue();
}
项目:intellij-ce-playground    文件:ReplacementPreviewDialog.java   
public ReplacementPreviewDialog(final Project project, UsageInfo info, String replacementString) {
  super(project,true);

  setTitle(SSRBundle.message("structural.replace.preview.dialog.title"));
  setOKButtonText(SSRBundle.message("replace.preview.oktext"));
  this.project = project;
  final PsiElement element = info.getElement();
  final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
  myFileType = virtualFile != null ? virtualFile.getFileType() : FileTypes.PLAIN_TEXT;
  init();

  Segment range = info.getSegment();
  hilight(virtualFile, range.getStartOffset(), range.getEndOffset());
  UIUtil.setContent(replacement, replacementString,0,-1,project);

  final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByPsiElement(element);
  if (profile != null) {
    UIUtil.updateHighlighter(replacement, profile);
  }
}
项目:intellij-ce-playground    文件:CommitMessage.java   
/**
 * Creates a text editor appropriate for creating commit messages.
 *
 * @param project project this commit message editor is intended for
 * @param forceSpellCheckOn if false, {@link com.intellij.openapi.vcs.VcsConfiguration#CHECK_COMMIT_MESSAGE_SPELLING} will control
 *                          whether or not the editor has spell check enabled
 * @return a commit message editor
 */
public static EditorTextField createCommitTextEditor(final Project project, boolean forceSpellCheckOn) {
  Set<EditorCustomization> features = new HashSet<EditorCustomization>();

  VcsConfiguration configuration = VcsConfiguration.getInstance(project);
  if (configuration != null) {
    boolean enableSpellChecking = forceSpellCheckOn || configuration.CHECK_COMMIT_MESSAGE_SPELLING;
    ContainerUtil.addIfNotNull(features, SpellCheckingEditorCustomizationProvider.getInstance().getCustomization(enableSpellChecking));
    features.add(new RightMarginEditorCustomization(configuration.USE_COMMIT_MESSAGE_MARGIN, configuration.COMMIT_MESSAGE_MARGIN_SIZE));
    features.add(WrapWhenTypingReachesRightMarginCustomization.getInstance(configuration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN));
  } else {
    ContainerUtil.addIfNotNull(features, SpellCheckingEditorCustomizationProvider.getInstance().getEnabledCustomization());
    features.add(new RightMarginEditorCustomization(false, -1));
  }

  features.add(SoftWrapsEditorCustomization.ENABLED);
  features.add(AdditionalPageAtBottomEditorCustomization.DISABLED);

  EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  return service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, features);
}
项目:intellij-ce-playground    文件:NewEditChangelistPanel.java   
private static EditorTextField createEditorField(final Project project, final int defaultLines) {
  final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  final EditorTextField editorField;

  final Set<EditorCustomization> editorFeatures = ContainerUtil.newHashSet();
  ContainerUtil.addIfNotNull(editorFeatures, SpellCheckingEditorCustomizationProvider.getInstance().getEnabledCustomization());

  if (defaultLines == 1) {
    editorFeatures.add(HorizontalScrollBarEditorCustomization.DISABLED);
    editorFeatures.add(OneLineEditorCustomization.ENABLED);
  } else {
    editorFeatures.add(SoftWrapsEditorCustomization.ENABLED);
  }
  editorField = service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, editorFeatures);
  final int height = editorField.getFontMetrics(editorField.getFont()).getHeight();
  editorField.getComponent().setMinimumSize(new Dimension(100, (int)(height * 1.3)));
  return editorField;
}
项目:intellij-ce-playground    文件:PatchApplier.java   
private boolean fileTypesAreOk(final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches) {
  for (Pair<VirtualFile, ApplyTextFilePatch> textPatch : textPatches) {
    final VirtualFile file = textPatch.getFirst();
    if (! file.isDirectory()) {
      FileType fileType = file.getFileType();
      if (fileType == FileTypes.UNKNOWN) {
        fileType = FileTypeChooser.associateFileType(file.getName());
        if (fileType == null) {
          showError(myProject, "Cannot apply patch. File " + file.getPresentableName() + " type not defined.", true);
          return false;
        }
      }
    }
  }
  return true;
}
项目:intellij-ce-playground    文件:FileTypeBasedRootFilter.java   
@Override
public boolean isAccepted(@NotNull VirtualFile rootCandidate, @NotNull final ProgressIndicator progressIndicator) {
  if (isJarDirectory()) {
    if (!rootCandidate.isDirectory() || !rootCandidate.isInLocalFileSystem()) {
      return false;
    }
    for (VirtualFile child : rootCandidate.getChildren()) {
      if (!child.isDirectory() && child.getFileType().equals(FileTypes.ARCHIVE)) {
        final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(child);
        if (jarRoot != null && containsFileOfType(jarRoot, progressIndicator)) {
          return true;
        }
      }
    }
    return false;
  }
  else {
    return containsFileOfType(rootCandidate, progressIndicator);
  }
}
项目:intellij-ce-playground    文件:FileIncludeManagerImpl.java   
@Nullable
private PsiFileSystemItem doResolve(@NotNull final FileIncludeInfo info, @NotNull final PsiFile context) {
  if (info instanceof FileIncludeInfoImpl) {
    String id = ((FileIncludeInfoImpl)info).providerId;
    FileIncludeProvider provider = id == null ? null : myProviderMap.get(id);
    final PsiFileSystemItem resolvedByProvider = provider == null ? null : provider.resolveIncludedFile(info, context);
    if (resolvedByProvider != null) {
      return resolvedByProvider;
    }
  }

  PsiFileImpl psiFile = (PsiFileImpl)myPsiFileFactory.createFileFromText("dummy.txt", FileTypes.PLAIN_TEXT, info.path);
  psiFile.setOriginalFile(context);
  return new FileReferenceSet(psiFile) {
    @Override
    protected boolean useIncludingFileAsContext() {
      return false;
    }
  }.resolve();
}
项目:intellij-ce-playground    文件:GotoFileAction.java   
/**
 * {@inheritDoc}
 */
@Override
public int compare(final FileType o1, final FileType o2) {
  if (o1 == o2) {
    return 0;
  }
  if (o1 == FileTypes.UNKNOWN) {
    return 1;
  }
  if (o2 == FileTypes.UNKNOWN) {
    return -1;
  }
  if (o1.isBinary() && !o2.isBinary()) {
    return 1;
  }
  if (!o1.isBinary() && o2.isBinary()) {
    return -1;
  }
  return o1.getName().compareToIgnoreCase(o2.getName());
}
项目:intellij-ce-playground    文件:AssociateFileTypeAction.java   
@Override
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  DataContext dataContext = e.getDataContext();
  VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  boolean haveSmthToDo;
  if (project == null || file == null || file.isDirectory()) {
    haveSmthToDo = false;
  }
  else {
    // the action should also be available for files which have been auto-detected as text or as a particular language (IDEA-79574)
    haveSmthToDo = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()) == FileTypes.UNKNOWN &&
                   !ScratchRootType.getInstance().isScratchFile(file);
  }
  presentation.setVisible(haveSmthToDo || ActionPlaces.isMainMenuOrActionSearch(e.getPlace()));
  presentation.setEnabled(haveSmthToDo);
}
项目:intellij-ce-playground    文件:RenameDialog.java   
protected void createNewNameComponent() {
  String[] suggestedNames = getSuggestedNames();
  myOldName = UsageViewUtil.getShortName(myPsiElement);
  myNameSuggestionsField = new NameSuggestionsField(suggestedNames, myProject, FileTypes.PLAIN_TEXT, myEditor) {
    @Override
    protected boolean shouldSelectAll() {
      return myEditor == null || myEditor.getSettings().isPreselectRename();
    }
  };
  if (myPsiElement instanceof PsiFile && myEditor == null) {
    myNameSuggestionsField.selectNameWithoutExtension();
  }
  myNameChangedListener = new NameSuggestionsField.DataChanged() {
    @Override
    public void dataChanged() {
      processNewNameChanged();
    }
  };
  myNameSuggestionsField.addDataChangedListener(myNameChangedListener);

}
项目:intellij-ce-playground    文件:XmlTagRenameDialog.java   
private void createNewNameComponent() {
  myNameSuggestionsField = new NameSuggestionsField(new String[] { myTag.getName() }, myProject, FileTypes.PLAIN_TEXT, myEditor);
  myNameChangedListener = new NameSuggestionsField.DataChanged() {
    @Override
    public void dataChanged() {
      validateButtons();
    }
  };
  myNameSuggestionsField.addDataChangedListener(myNameChangedListener);

  myNameSuggestionsField.getComponent().registerKeyboardAction(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
      completeVariable(myNameSuggestionsField.getEditor());
    }
  }, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.CTRL_MASK), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
项目:intellij-ce-playground    文件:ResourceFilteringTest.java   
public void testDoNotFilterButCopyBigFiles() throws Exception {
  assertEquals(FileTypeManager.getInstance().getFileTypeByFileName("file.xyz"), FileTypes.UNKNOWN);

  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      createProjectSubFile("resources/file.xyz").setBinaryContent(new byte[1024 * 1024 * 20]);
    }
  }.execute().throwException();

  importProject("<groupId>test</groupId>" +
                "<artifactId>project</artifactId>" +
                "<version>1</version>" +

                "<build>" +
                "  <resources>" +
                "    <resource>" +
                "      <directory>resources</directory>" +
                "      <filtering>true</filtering>" +
                "    </resource>" +
                "  </resources>" +
                "</build>");
  compileModules("project");

  assertNotNull(myProjectPom.getParent().findFileByRelativePath("target/classes/file.xyz"));
}
项目:tools-idea    文件:FindManagerTest.java   
public void testReplaceRegexp() throws Throwable {
  FindManager findManager = FindManager.getInstance(myProject);

  FindModel findModel = new FindModel();
  findModel.setStringToFind("bug(?=here)");
  findModel.setStringToReplace("x$0y");
  findModel.setWholeWordsOnly(false);
  findModel.setFromCursor(false);
  findModel.setGlobal(true);
  findModel.setMultipleFiles(false);
  findModel.setProjectScope(true);
  findModel.setRegularExpressions(true);
  findModel.setPromptOnReplace(false);

  findManager.setFindNextModel(null);
  findManager.getFindInFileModel().copyFrom(findModel);

  String text = "bughere\n" + "bughere";
  configureByText(FileTypes.PLAIN_TEXT, text);
  boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
  assertTrue(succ);

  assertEquals("xbugyhere\n" + "xbugyhere", getEditor().getDocument().getText());
}
项目:tools-idea    文件:FindManagerTest.java   
public void testReplaceRegexp1() throws Throwable {
  FindManager findManager = FindManager.getInstance(myProject);

  FindModel findModel = new FindModel();
  findModel.setStringToFind("bug(?=here)");
  findModel.setStringToReplace("$0");
  findModel.setWholeWordsOnly(false);
  findModel.setFromCursor(false);
  findModel.setGlobal(true);
  findModel.setMultipleFiles(false);
  findModel.setProjectScope(true);
  findModel.setRegularExpressions(true);
  findModel.setPromptOnReplace(false);

  findManager.setFindNextModel(null);
  findManager.getFindInFileModel().copyFrom(findModel);

  String text = "bughere\n" + "bughere";
  configureByText(FileTypes.PLAIN_TEXT, text);
  boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
  assertTrue(succ);

  assertEquals(text, getEditor().getDocument().getText());
}
项目:tools-idea    文件:FindManagerTest.java   
public void testReplaceRegexpWithNewLine() throws Throwable {
  FindManager findManager = FindManager.getInstance(myProject);

  FindModel findModel = new FindModel();
  findModel.setStringToFind("xxx");
  findModel.setStringToReplace("xxx\\n");
  findModel.setWholeWordsOnly(false);
  findModel.setFromCursor(false);
  findModel.setGlobal(true);
  findModel.setMultipleFiles(false);
  findModel.setProjectScope(true);
  findModel.setRegularExpressions(true);
  findModel.setPromptOnReplace(false);

  findManager.setFindNextModel(null);
  findManager.getFindInFileModel().copyFrom(findModel);

  String text = "xxx";
  configureByText(FileTypes.PLAIN_TEXT, text);
  boolean succ = FindUtil.replace(getProject(), getEditor(), 0, findModel);
  assertTrue(succ);

  assertEquals(text+"\n", getEditor().getDocument().getText());
}
项目:tools-idea    文件:FileChooserDescriptor.java   
@Nullable
public final VirtualFile getFileToSelect(VirtualFile file) {
  if (file.isDirectory() && (myChooseFolders || isFileSelectable(file))) {
    return file;
  }
  boolean isJar = file.getFileType() == FileTypes.ARCHIVE;
  if (!isJar) {
    return acceptAsGeneralFile(file) ? file : null;
  }
  if (myChooseJarsAsFiles) {
    return file;
  }
  if (!acceptAsJarFile(file)) {
    return null;
  }
  String path = file.getPath();
  return JarFileSystem.getInstance().findFileByPath(path + JarFileSystem.JAR_SEPARATOR);
}
项目:tools-idea    文件:EncodingUtil.java   
@NotNull
static Pair<Charset, String> checkHardcodedCharsetFileType(@NotNull VirtualFile virtualFile) {
  FileType fileType = virtualFile.getFileType();
  if (fileType.isBinary()) return Pair.create(null, "binary file");
  // in lesser IDEs all special file types are plain text so check for that first
  if (fileType == FileTypes.PLAIN_TEXT) return Pair.create(null, null);
  if (fileType == StdFileTypes.GUI_DESIGNER_FORM) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA GUI Designer form");
  if (fileType == StdFileTypes.IDEA_MODULE) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA module file");
  if (fileType == StdFileTypes.IDEA_PROJECT) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA project file");
  if (fileType == StdFileTypes.IDEA_WORKSPACE) return Pair.create(CharsetToolkit.UTF8_CHARSET, "IDEA workspace file");

  if (fileType == StdFileTypes.PROPERTIES) return Pair.create(virtualFile.getCharset(), ".properties file");

  if (fileType == StdFileTypes.XML || fileType == StdFileTypes.JSPX) {
    return Pair.create(virtualFile.getCharset(), "XML file");
  }
  return Pair.create(null, null);
}
项目:tools-idea    文件:AssociateFileType.java   
public void update(AnActionEvent e) {
  Presentation presentation = e.getPresentation();
  DataContext dataContext = e.getDataContext();
  VirtualFile file = PlatformDataKeys.VIRTUAL_FILE.getData(dataContext);
  Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  boolean haveSmthToDo;
  if (project == null || file == null || file.isDirectory()) {
    haveSmthToDo = false;
  }
  else {
    // the action should also be available for files which have been auto-detected as text or as a particular language (IDEA-79574)
    haveSmthToDo = FileTypeManager.getInstance().getFileTypeByFileName(file.getName()) == FileTypes.UNKNOWN;
  }
  presentation.setVisible(haveSmthToDo || ActionPlaces.MAIN_MENU.equals(e.getPlace()));
  presentation.setEnabled(haveSmthToDo);
}
项目:tools-idea    文件:SelectionQuotingTypedHandlerTest.java   
private void doTest(@NotNull final String cs, @NotNull String before, @NotNull String expected) {
  final boolean smarterSelection = Registry.is("editor.smarterSelectionQuoting");
  Registry.get("editor.smarterSelectionQuoting").setValue(true);
  try {
    myFixture.configureByText(FileTypes.PLAIN_TEXT, before);
    final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();

    performAction(myFixture.getProject(), new Runnable() {
      @Override
      public void run() {
        for (int i = 0, max = cs.length(); i < max; i++) {
          final char c = cs.charAt(i);
          typedAction.actionPerformed(myFixture.getEditor(), c, ((EditorEx)myFixture.getEditor()).getDataContext());
        }
      }
    });
    myFixture.checkResult(expected);
  } finally {
    Registry.get("editor.smarterSelectionQuoting").setValue(smarterSelection);
  }
}
项目:tools-idea    文件:SelectionQuotingTypedHandlerTest.java   
public void testRuby7852ErrantEditor() {
  myFixture.configureByText(FileTypes.PLAIN_TEXT, "\"aaa\"\nbbb\n\n");
  myFixture.getEditor().getCaretModel().moveToOffset(0);
  myFixture.getEditor().getSelectionModel().setSelection(0, 5);
  final TypedAction typedAction = EditorActionManager.getInstance().getTypedAction();
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), '\'', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.getEditor().getSelectionModel().removeSelection();
  myFixture.checkResult("'aaa'\nbbb\n\n");

  myFixture.getEditor().getCaretModel().moveToOffset(myFixture.getEditor().getDocument().getLineStartOffset(3));
  performAction(myFixture.getProject(), new Runnable() {
    @Override
    public void run() {
      typedAction.actionPerformed(myFixture.getEditor(), 'A', ((EditorEx)myFixture.getEditor()).getDataContext());
      typedAction.actionPerformed(myFixture.getEditor(), 'B', ((EditorEx)myFixture.getEditor()).getDataContext());
    }
  });
  myFixture.checkResult("'aaa'\nbbb\n\nAB");
}
项目:tools-idea    文件:PathEditor.java   
private static boolean isJarFile(final VirtualFile file) {
  return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      VirtualFile tempFile = file;
      if ((file.getFileSystem() instanceof JarFileSystem) && file.getParent() == null) {
        //[myakovlev] It was bug - directories with *.jar extensions was saved as files of JarFileSystem.
        //    so we can not just return true, we should filter such directories.
        String path = file.getPath().substring(0, file.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
        tempFile = LocalFileSystem.getInstance().findFileByPath(path);
      }
      if (tempFile != null && !tempFile.isDirectory()) {
        return Boolean.valueOf(tempFile.getFileType().equals(FileTypes.ARCHIVE));
      }
      return Boolean.FALSE;
    }
  }).booleanValue();
}
项目:tools-idea    文件:CodeStyleSettings.java   
private void copyOldIndentOptions(@NonNls final String extension, final IndentOptions options) {
  final FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(extension);
  if (fileType != FileTypes.UNKNOWN && fileType != FileTypes.PLAIN_TEXT && !myAdditionalIndentOptions.containsKey(fileType) &&
      !fileType.getDefaultExtension().isEmpty()) {
    registerAdditionalIndentOptions(fileType, options);
    //
    // Upgrade to version 11
    //
    if (fileType instanceof LanguageFileType) {
      Language lang = ((LanguageFileType)fileType).getLanguage();
      CommonCodeStyleSettings langSettings = myCommonSettingsManager.getCommonSettings(lang);
      if (langSettings != this && langSettings.getIndentOptions() != null) {
        langSettings.importOldIndentOptions(this);
      }
    }
  }
}
项目:tools-idea    文件:CommitMessage.java   
/**
 * Creates a text editor appropriate for creating commit messages.
 *
 * @param project project this commit message editor is intended for
 * @param forceSpellCheckOn if false, {@link com.intellij.openapi.vcs.VcsConfiguration#CHECK_COMMIT_MESSAGE_SPELLING} will control
 *                          whether or not the editor has spell check enabled
 * @return a commit message editor
 */
public static EditorTextField createCommitTextEditor(final Project project, boolean forceSpellCheckOn) {
  Set<EditorCustomization> features = new HashSet<EditorCustomization>();

  VcsConfiguration configuration = VcsConfiguration.getInstance(project);
  if (configuration != null) {
    boolean enableSpellChecking = forceSpellCheckOn || configuration.CHECK_COMMIT_MESSAGE_SPELLING;
    features.add(SpellCheckingEditorCustomization.getInstance(enableSpellChecking));
    features.add(new RightMarginEditorCustomization(configuration.USE_COMMIT_MESSAGE_MARGIN, configuration.COMMIT_MESSAGE_MARGIN_SIZE));
    features.add(WrapWhenTypingReachesRightMarginCustomization.getInstance(configuration.WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN));
  } else {
    features.add(SpellCheckingEditorCustomization.ENABLED);
    features.add(new RightMarginEditorCustomization(false, -1));
  }

  features.add(SoftWrapsEditorCustomization.ENABLED);
  features.add(AdditionalPageAtBottomEditorCustomization.DISABLED);

  EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  return service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, features);
}
项目:tools-idea    文件:NewEditChangelistPanel.java   
private static EditorTextField createEditorField(final Project project, final int defaultLines) {
  final EditorTextFieldProvider service = ServiceManager.getService(project, EditorTextFieldProvider.class);
  final EditorTextField editorField;

  final Set<EditorCustomization> editorFeatures = ContainerUtil.newHashSet();
  editorFeatures.add(SpellCheckingEditorCustomization.ENABLED);

  if (defaultLines == 1) {
    editorFeatures.add(HorizontalScrollBarEditorCustomization.DISABLED);
    editorFeatures.add(OneLineEditorCustomization.ENABLED);
  } else {
    editorFeatures.add(SoftWrapsEditorCustomization.ENABLED);
  }
  editorField = service.getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, editorFeatures);
  final int height = editorField.getFontMetrics(editorField.getFont()).getHeight();
  editorField.getComponent().setMinimumSize(new Dimension(100, (int)(height * 1.3)));
  return editorField;
}
项目:tools-idea    文件:PatchApplier.java   
private boolean fileTypesAreOk(final List<Pair<VirtualFile, ApplyTextFilePatch>> textPatches) {
  for (Pair<VirtualFile, ApplyTextFilePatch> textPatch : textPatches) {
    final VirtualFile file = textPatch.getFirst();
    if (! file.isDirectory()) {
      FileType fileType = file.getFileType();
      if (fileType == FileTypes.UNKNOWN) {
        fileType = FileTypeChooser.associateFileType(file.getPresentableName());
        if (fileType == null) {
          showError(myProject, "Cannot apply patch. File " + file.getPresentableName() + " type not defined.", true);
          return false;
        }
      }
    }
  }
  return true;
}
项目:tools-idea    文件:FileTypeBasedRootFilter.java   
@Override
public boolean isAccepted(@NotNull VirtualFile rootCandidate, @NotNull final ProgressIndicator progressIndicator) {
  if (isJarDirectory()) {
    if (!rootCandidate.isDirectory() || !rootCandidate.isInLocalFileSystem()) {
      return false;
    }
    for (VirtualFile child : rootCandidate.getChildren()) {
      if (!child.isDirectory() && child.getFileType().equals(FileTypes.ARCHIVE)) {
        final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(child);
        if (jarRoot != null && containsFileOfType(jarRoot, progressIndicator)) {
          return true;
        }
      }
    }
    return false;
  }
  else {
    return containsFileOfType(rootCandidate, progressIndicator);
  }
}
项目:tools-idea    文件:FindDialog.java   
private void updateFileTypeForEditorComponent(@NotNull ComboBox inputComboBox) {
  final Component editorComponent = inputComboBox.getEditor().getEditorComponent();

  if (editorComponent instanceof EditorTextField) {
    boolean selected = myCbRegularExpressions.isSelectedWhenSelectable();
    @NonNls final String s = selected ? "*.regexp" : "*.txt";
    FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(s);

    if (selected && fileType == FileTypes.UNKNOWN) {
      fileType = FileTypeManager.getInstance().getFileTypeByFileName("*.txt"); // RegExp plugin is not installed
    }

    final PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText(s, fileType, ((EditorTextField)editorComponent).getText(), -1, true);

    ((EditorTextField)editorComponent).setNewDocumentAndFileType(fileType, PsiDocumentManager.getInstance(myProject).getDocument(file));
  }
}