com.intellij.openapi.fileTypes.FileTypes Java Examples

The following examples show how to use com.intellij.openapi.fileTypes.FileTypes. 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: ExtensionFileGenerationUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
/**
 * @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);
}
 
Example #2
Source File: ExtensionFileGenerationUtil.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
/**
 * @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);
}
 
Example #3
Source File: FlowRenameDialog.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void createNewNameComponent() {
    String flowName = this.myTag.getAttribute("name").getValue();
    this.myNameSuggestionsField = new NameSuggestionsField(new String[]{ flowName }, this.myProject, FileTypes.PLAIN_TEXT, this.myEditor);
    this.myNameChangedListener = new NameSuggestionsField.DataChanged() {
        public void dataChanged() {
            FlowRenameDialog.this.validateButtons();
        }
    };
    this.myNameSuggestionsField.addDataChangedListener(this.myNameChangedListener);
    this.myNameSuggestionsField.getComponent().registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            FlowRenameDialog.this.completeVariable(FlowRenameDialog.this.myNameSuggestionsField.getEditor());
        }
    }, KeyStroke.getKeyStroke(32, 2), 2);
}
 
Example #4
Source File: MultiValueAutoComplete.java    From review-board-idea-plugin with Apache License 2.0 5 votes vote down vote up
public static EditorTextField create(Project project, DataProvider dataProvider) {
    List<EditorCustomization> customizations =
            Arrays.<EditorCustomization>asList(SoftWrapsEditorCustomization.ENABLED, SpellCheckingEditorCustomization.DISABLED);
    EditorTextField editorField = ServiceManager.getService(project, EditorTextFieldProvider.class)
            .getEditorField(FileTypes.PLAIN_TEXT.getLanguage(), project, customizations);
    new CommaSeparatedTextFieldCompletion(dataProvider).apply(editorField);
    return editorField;

}
 
Example #5
Source File: HaxeFindUsagesTest.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public void compareExpectedUsages(Collection<UsageInfo> foundUsages) {

    assertNotNull(foundUsages);

    // Need to keep the ordering constant, so sort the output.
    String[] formattedUsages = new String[foundUsages.size()];
    int i = 0;
    for (UsageInfo usage : foundUsages) {
      formattedUsages[i++] = prettyUsageMessage(usage);
    }
    Arrays.sort(formattedUsages, new Comparator<String>() {
      @Override
      public int compare(String o1, String o2) {
        return o1.compareTo(o2);
      }
    });

    StringBuilder builder = new StringBuilder();
    for (String s : formattedUsages) {
      builder.append(s);
      builder.append('\n');
    }

    // Convert the output to a file.  MUST use an API that sets eventSystemEnabled==true, or the file won't open.
    PsiFile foundFile = PsiFileFactory.getInstance(myFixture.getProject())
      .createFileFromText("testResult", FileTypes.PLAIN_TEXT, builder.toString(),
                          LocalTimeCounter.currentTime(), true);
    VirtualFile vFile = foundFile.getViewProvider().getVirtualFile();

    myFixture.openFileInEditor(vFile); // Can't use foundFile.getVirtualFile(); it returns null.
    myFixture.checkResultByFile(getResultsPath(), false);
  }
 
Example #6
Source File: PlainTextEditor.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public EmptyTextEditor(final Project project) {
  super("", project, FileTypes.PLAIN_TEXT);
  setOneLineMode(false);
  setAutoscrolls(true);
}
 
Example #7
Source File: BashTemplatesFactoryTest.java    From BashSupport with Apache License 2.0 4 votes vote down vote up
private PsiDirectory findSrcDir() {
    return myFixture.configureByText(FileTypes.PLAIN_TEXT, "dummy content").getContainingDirectory();
}
 
Example #8
Source File: ExtractPartialViewDialog.java    From idea-php-laravel-plugin with MIT License 3 votes vote down vote up
public ExtractPartialViewDialog(@NotNull Project project, VirtualFile targetDirectory) {
    super(project);

    panel = new JPanel(new BorderLayout());

    panel.add(new JLabel("View name (example: partials.header)"), BorderLayout.NORTH);

    viewNameEditor = new EditorTextField("", project, FileTypes.PLAIN_TEXT);
    new NewViewNameCompletionProvider(targetDirectory).apply(viewNameEditor);
    panel.add(viewNameEditor.getComponent(), BorderLayout.CENTER);

    setTitle("Extract Partial View");

    init();
}