use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class TestDataNavigationHandler method showNavigationPopup.
private static void showNavigationPopup(final Project project, final List<String> fileNames, final RelativePoint point) {
List<String> listPaths = new ArrayList<>(fileNames);
final String CREATE_MISSING_OPTION = "Create Missing Files";
if (fileNames.size() == 2) {
VirtualFile file1 = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileNames.get(0));
VirtualFile file2 = LocalFileSystem.getInstance().refreshAndFindFileByPath(fileNames.get(1));
if (file1 == null || file2 == null) {
listPaths.add(CREATE_MISSING_OPTION);
}
}
final JList list = new JBList(ArrayUtil.toStringArray(listPaths));
list.setCellRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
String path = (String) value;
String fileName = PathUtil.getFileName(path);
if (!fileName.equals(CREATE_MISSING_OPTION)) {
final FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(fileName);
setIcon(fileType.getIcon());
}
append(String.format("%s (%s)", fileName, PathUtil.getParentPath(path)));
}
});
PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setItemChoosenCallback(() -> {
final int[] indices = list.getSelectedIndices();
if (ArrayUtil.indexOf(indices, fileNames.size()) >= 0) {
createMissingFiles(project, fileNames);
} else {
for (int index : indices) {
openFileByIndex(project, fileNames, index);
}
}
}).createPopup().show(point);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class NewGroovyClassAction method buildDialog.
@Override
protected void buildDialog(Project project, PsiDirectory directory, CreateFileFromTemplateDialog.Builder builder) {
builder.setTitle(GroovyBundle.message("newclass.dlg.title")).addKind("Class", JetgroovyIcons.Groovy.Class, GroovyTemplates.GROOVY_CLASS).addKind("Interface", JetgroovyIcons.Groovy.Interface, GroovyTemplates.GROOVY_INTERFACE);
if (GroovyConfigUtils.getInstance().isVersionAtLeast(directory, GroovyConfigUtils.GROOVY2_3, true)) {
builder.addKind("Trait", JetgroovyIcons.Groovy.Trait, GroovyTemplates.GROOVY_TRAIT);
}
builder.addKind("Enum", JetgroovyIcons.Groovy.Enum, GroovyTemplates.GROOVY_ENUM).addKind("Annotation", JetgroovyIcons.Groovy.AnnotationType, GroovyTemplates.GROOVY_ANNOTATION);
for (FileTemplate template : FileTemplateManager.getInstance(project).getAllTemplates()) {
FileType fileType = FileTypeManagerEx.getInstanceEx().getFileTypeByExtension(template.getExtension());
if (fileType.equals(GroovyFileType.GROOVY_FILE_TYPE) && JavaDirectoryService.getInstance().getPackage(directory) != null) {
builder.addKind(template.getName(), JetgroovyIcons.Groovy.Class, template.getName());
}
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class BeforeAfterActionMetaData method retrieveURLs.
@NotNull
private static TextDescriptor[] retrieveURLs(@NotNull URL descriptionDirectory, @NotNull String prefix, @NotNull String suffix) throws MalformedURLException {
List<TextDescriptor> urls = new ArrayList<>();
final FileType[] fileTypes = FileTypeManager.getInstance().getRegisteredFileTypes();
for (FileType fileType : fileTypes) {
final String[] extensions = FileTypeManager.getInstance().getAssociatedExtensions(fileType);
for (String extension : extensions) {
for (int i = 0; ; i++) {
URL url = new URL(descriptionDirectory.toExternalForm() + "/" + prefix + "." + extension + (i == 0 ? "" : Integer.toString(i)) + suffix);
try {
InputStream inputStream = url.openStream();
inputStream.close();
urls.add(new ResourceTextDescriptor(url));
} catch (IOException ioe) {
break;
}
}
}
}
if (urls.isEmpty()) {
String[] children;
Exception cause = null;
try {
URI uri = descriptionDirectory.toURI();
children = uri.isOpaque() ? null : ObjectUtils.notNull(new File(uri).list(), ArrayUtil.EMPTY_STRING_ARRAY);
} catch (URISyntaxException | IllegalArgumentException e) {
cause = e;
children = null;
}
LOG.error("URLs not found for available file types and prefix: '" + prefix + "', suffix: '" + suffix + "';" + " in directory: '" + descriptionDirectory + "'" + (children == null ? "" : "; directory contents: " + Arrays.asList(children)), cause);
return EMPTY_EXAMPLE;
}
return urls.toArray(new TextDescriptor[urls.size()]);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class IntentionDescriptionPanel method showUsages.
private static void showUsages(final JPanel panel, final TitledSeparator separator, final List<IntentionUsagePanel> usagePanels, @Nullable final TextDescriptor[] exampleUsages) throws IOException {
GridBagConstraints gb = null;
boolean reuse = exampleUsages != null && panel.getComponents().length == exampleUsages.length;
if (!reuse) {
disposeUsagePanels(usagePanels);
panel.setLayout(new GridBagLayout());
panel.removeAll();
gb = new GridBagConstraints();
gb.anchor = GridBagConstraints.NORTHWEST;
gb.fill = GridBagConstraints.BOTH;
gb.gridheight = GridBagConstraints.REMAINDER;
gb.gridwidth = 1;
gb.gridx = 0;
gb.gridy = 0;
gb.insets = new Insets(0, 0, 0, 0);
gb.ipadx = 5;
gb.ipady = 5;
gb.weightx = 1;
gb.weighty = 1;
}
if (exampleUsages != null) {
for (int i = 0; i < exampleUsages.length; i++) {
final TextDescriptor exampleUsage = exampleUsages[i];
final String name = exampleUsage.getFileName();
final FileTypeManagerEx fileTypeManager = FileTypeManagerEx.getInstanceEx();
final String extension = fileTypeManager.getExtension(name);
final FileType fileType = fileTypeManager.getFileTypeByExtension(extension);
IntentionUsagePanel usagePanel;
if (reuse) {
usagePanel = (IntentionUsagePanel) panel.getComponent(i);
} else {
usagePanel = new IntentionUsagePanel();
usagePanels.add(usagePanel);
}
usagePanel.reset(exampleUsage.getText(), fileType);
if (!reuse) {
if (i == exampleUsages.length) {
gb.gridwidth = GridBagConstraints.REMAINDER;
}
panel.add(usagePanel, gb);
gb.gridx++;
}
}
}
panel.revalidate();
panel.repaint();
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class FrameworkDetectionIndex method getIndexer.
@NotNull
@Override
public DataIndexer<Integer, Void, FileContent> getIndexer() {
final MultiMap<FileType, Pair<ElementPattern<FileContent>, Integer>> detectors = new MultiMap<>();
FrameworkDetectorRegistry registry = FrameworkDetectorRegistry.getInstance();
for (FrameworkDetector detector : FrameworkDetector.EP_NAME.getExtensions()) {
detectors.putValue(detector.getFileType(), Pair.create(detector.createSuitableFilePattern(), registry.getDetectorId(detector)));
}
return new DataIndexer<Integer, Void, FileContent>() {
@NotNull
@Override
public Map<Integer, Void> map(@NotNull FileContent inputData) {
final FileType fileType = inputData.getFileType();
if (!detectors.containsKey(fileType)) {
return Collections.emptyMap();
}
Map<Integer, Void> result = null;
for (Pair<ElementPattern<FileContent>, Integer> pair : detectors.get(fileType)) {
if (pair.getFirst().accepts(inputData)) {
if (LOG.isDebugEnabled()) {
LOG.debug(inputData.getFile() + " accepted by detector " + pair.getSecond());
}
if (result == null) {
result = new HashMap<>();
}
myDispatcher.getMulticaster().fileUpdated(inputData.getFile(), pair.getSecond());
result.put(pair.getSecond(), null);
}
}
return result != null ? result : Collections.<Integer, Void>emptyMap();
}
};
}
Aggregations