use of com.intellij.openapi.fileTypes.FileNameMatcher in project intellij-community by JetBrains.
the class Utils method buildPattern.
@NotNull
private static String buildPattern(FileType fileType) {
final StringBuilder result = new StringBuilder();
final List<FileNameMatcher> associations = FileTypeManager.getInstance().getAssociations(fileType);
for (FileNameMatcher matcher : associations) {
if (result.length() != 0)
result.append(",");
result.append(matcher.getPresentableString());
}
if (associations.size() > 1) {
result.insert(0, "{").append("}");
}
return result.toString();
}
use of com.intellij.openapi.fileTypes.FileNameMatcher in project intellij-community by JetBrains.
the class FileTypeAssocTable method findAssociatedFileType.
@Nullable
T findAssociatedFileType(@NotNull FileNameMatcher matcher) {
if (matcher instanceof ExtensionFileNameMatcher) {
return myExtensionMappings.get(((ExtensionFileNameMatcher) matcher).getExtension());
}
if (matcher instanceof ExactFileNameMatcher) {
final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher) matcher;
Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings;
return mapToUse.get(exactFileNameMatcher.getFileName());
}
for (Pair<FileNameMatcher, T> mapping : myMatchingMappings) {
if (matcher.equals(mapping.getFirst()))
return mapping.getSecond();
}
return null;
}
use of com.intellij.openapi.fileTypes.FileNameMatcher in project intellij-community by JetBrains.
the class FileTypeAssocTable method removeAssociation.
boolean removeAssociation(@NotNull FileNameMatcher matcher, @NotNull T type) {
if (matcher instanceof ExtensionFileNameMatcher) {
String extension = ((ExtensionFileNameMatcher) matcher).getExtension();
if (myExtensionMappings.get(extension) == type) {
myExtensionMappings.remove(extension);
return true;
}
return false;
}
if (matcher instanceof ExactFileNameMatcher) {
final ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher) matcher;
String fileName = exactFileNameMatcher.getFileName();
final Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings;
if (mapToUse.get(fileName) == type) {
mapToUse.remove(fileName);
return true;
}
return false;
}
List<Pair<FileNameMatcher, T>> copy = new ArrayList<>(myMatchingMappings);
for (Pair<FileNameMatcher, T> assoc : copy) {
if (matcher.equals(assoc.getFirst())) {
myMatchingMappings.remove(assoc);
return true;
}
}
return false;
}
use of com.intellij.openapi.fileTypes.FileNameMatcher in project intellij-community by JetBrains.
the class TemplateDataLanguagePatterns method getState.
@Override
public Element getState() {
Element state = new Element("x");
for (final Language language : TemplateDataLanguageMappings.getTemplateableLanguages()) {
final List<FileNameMatcher> matchers = myAssocTable.getAssociations(language);
if (!matchers.isEmpty()) {
final Element child = new Element("pattern");
state.addContent(child);
child.setAttribute("value", StringUtil.join(matchers, fileNameMatcher -> fileNameMatcher.getPresentableString(), SEPARATOR));
child.setAttribute("lang", language.getID());
}
}
return state;
}
use of com.intellij.openapi.fileTypes.FileNameMatcher in project intellij-community by JetBrains.
the class ApproveRemovedMappingsActivity method runActivity.
@Override
public void runActivity(@NotNull final Project project) {
final Map<FileNameMatcher, Pair<FileType, Boolean>> map = ((FileTypeManagerImpl) FileTypeManager.getInstance()).getRemovedMappings();
if (!map.isEmpty()) {
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override
public void run() {
for (Iterator<Map.Entry<FileNameMatcher, Pair<FileType, Boolean>>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<FileNameMatcher, Pair<FileType, Boolean>> entry = iterator.next();
if (entry.getValue().getSecond()) {
continue;
}
final FileNameMatcher matcher = entry.getKey();
final FileType fileType = entry.getValue().getFirst();
Notification notification = new Notification("File type recognized", "File type recognized", "File extension " + matcher.getPresentableString() + " was reassigned to " + fileType.getName() + " <a href='revert'>Revert</a>", NotificationType.WARNING, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
ApplicationManager.getApplication().runWriteAction(() -> {
FileTypeManager.getInstance().associate(PlainTextFileType.INSTANCE, matcher);
map.put(matcher, Pair.create(fileType, true));
});
notification.expire();
}
});
Notifications.Bus.notify(notification, project);
ApplicationManager.getApplication().runWriteAction(() -> FileTypeManager.getInstance().associate(fileType, matcher));
iterator.remove();
}
}
});
}
}
Aggregations