use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class JavaFxLocationReferenceProvider method collectRefs.
private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
final int atSignIndex = value.indexOf('@');
if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
value = value.substring(atSignIndex + 1);
startInElement += atSignIndex + 1;
}
final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return item -> {
if (item instanceof PsiDirectory)
return true;
final VirtualFile virtualFile = item.getVirtualFile();
if (virtualFile == null)
return false;
final FileType fileType = virtualFile.getFileType();
return myAcceptedFileTypes.contains(fileType);
};
}
};
if (value.startsWith("/")) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return set.getAllReferences();
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class ResourceBundleEditorProvider method accept.
@Override
public boolean accept(@NotNull final Project project, @NotNull final VirtualFile file) {
if (file instanceof ResourceBundleAsVirtualFile)
return true;
if (!file.isValid())
return false;
final FileType type = file.getFileType();
if (type != StdFileTypes.PROPERTIES && type != StdFileTypes.XML)
return false;
return ReadAction.compute(() -> {
if (project.isDisposed())
return Boolean.FALSE;
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
PropertiesFile propertiesFile = PropertiesImplUtil.getPropertiesFile(psiFile);
return propertiesFile != null && propertiesFile.getResourceBundle().getPropertiesFiles().size() > 1;
});
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class SelectorBasedResponseHandler method getConfigurationComponent.
@NotNull
@Override
public JComponent getConfigurationComponent(@NotNull Project project) {
FileType fileType = getResponseType().getSelectorFileType();
HighlightedSelectorsTable table = new HighlightedSelectorsTable(fileType, project, getSelectors());
return new JBScrollPane(table);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class CustomRegexpFilter method createOpenFileHyperlink.
protected HyperlinkInfo createOpenFileHyperlink(String fileName, final int line, int column) {
if ((fileName == null || fileName.length() == 0)) {
if (myBase != null) {
fileName = myBase.getPresentableUrl();
} else {
return null;
}
}
fileName = fileName.replace(File.separatorChar, '/');
VirtualFile file;
// try to interpret the filename as URL
if (URLUtil.containsScheme(fileName)) {
try {
file = VfsUtil.findFileByURL(new URL(fileName));
} catch (MalformedURLException e) {
file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(fileName));
}
} else {
file = VfsUtil.findRelativeFile(fileName, myBase);
}
if (file == null) {
//noinspection ConstantConditions
return null;
}
final FileType fileType = file.getFileType();
if (fileType != null && column > 0) {
final Document document = FileDocumentManager.getInstance().getDocument(file);
final int start = document.getLineStartOffset(line);
final int max = document.getLineEndOffset(line);
final int tabSize = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getTabSize(fileType);
column = EditorUtil.calcColumnNumber(null, document.getCharsSequence(), start, Math.min(start + column, max), tabSize);
}
return new OpenFileHyperlinkInfo(myProject, file, line, column);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class ConfigFilesTreeBuilder method buildModuleNodes.
public Set<PsiFile> buildModuleNodes(final MultiMap<Module, PsiFile> files, final MultiMap<VirtualFile, PsiFile> jars, DefaultMutableTreeNode root) {
final HashSet<PsiFile> psiFiles = new HashSet<>();
final List<Module> modules = new ArrayList<>(files.keySet());
Collections.sort(modules, ModulesAlphaComparator.INSTANCE);
for (Module module : modules) {
DefaultMutableTreeNode moduleNode = createFileNode(module);
root.add(moduleNode);
if (files.containsKey(module)) {
List<PsiFile> moduleFiles = new ArrayList<>(files.get(module));
MultiMap<FileType, PsiFile> filesByType = new MultiMap<>();
for (PsiFile file : moduleFiles) {
filesByType.putValue(file.getFileType(), file);
}
if (hasNonEmptyGroups(filesByType)) {
for (Map.Entry<FileType, Collection<PsiFile>> entry : filesByType.entrySet()) {
DefaultMutableTreeNode fileTypeNode = createFileNode(entry.getKey());
moduleNode.add(fileTypeNode);
addChildrenFiles(psiFiles, fileTypeNode, new ArrayList<>(entry.getValue()));
}
} else {
addChildrenFiles(psiFiles, moduleNode, moduleFiles);
}
}
}
List<VirtualFile> sortedJars = new ArrayList<>(jars.keySet());
Collections.sort(sortedJars, (o1, o2) -> StringUtil.naturalCompare(o1.getName(), o2.getName()));
for (VirtualFile file : sortedJars) {
if (!file.isValid())
continue;
final List<PsiFile> list = new ArrayList<>(jars.get(file));
final PsiFile jar = list.get(0).getManager().findFile(file);
if (jar != null) {
final DefaultMutableTreeNode jarNode = createFileNode(jar);
root.add(jarNode);
Collections.sort(list, FILE_COMPARATOR);
for (PsiFile psiFile : list) {
jarNode.add(createFileNode(psiFile));
psiFiles.add(psiFile);
}
}
}
return psiFiles;
}
Aggregations