use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class FileReferenceCompletionImpl method getFileReferenceCompletionVariants.
@NotNull
@Override
public Object[] getFileReferenceCompletionVariants(final FileReference reference) {
final String s = reference.getText();
if (s != null && s.equals("/")) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final CommonProcessors.CollectUniquesProcessor<PsiFileSystemItem> collector = new CommonProcessors.CollectUniquesProcessor<>();
final PsiElementProcessor<PsiFileSystemItem> processor = new PsiElementProcessor<PsiFileSystemItem>() {
@Override
public boolean execute(@NotNull PsiFileSystemItem fileSystemItem) {
return new FilteringProcessor<>(reference.getFileReferenceSet().getReferenceCompletionFilter(), collector).process(FileReference.getOriginalFile(fileSystemItem));
}
};
List<Object> additionalItems = ContainerUtil.newArrayList();
for (PsiFileSystemItem context : reference.getContexts()) {
for (final PsiElement child : context.getChildren()) {
if (child instanceof PsiFileSystemItem) {
processor.execute((PsiFileSystemItem) child);
}
}
if (context instanceof FileReferenceResolver) {
additionalItems.addAll(((FileReferenceResolver) context).getVariants(reference));
}
}
final FileType[] types = reference.getFileReferenceSet().getSuitableFileTypes();
final THashSet<PsiElement> set = new THashSet<>(collector.getResults(), VARIANTS_HASHING_STRATEGY);
final PsiElement[] candidates = PsiUtilCore.toPsiElementArray(set);
final Object[] variants = new Object[candidates.length + additionalItems.size()];
for (int i = 0; i < candidates.length; i++) {
PsiElement candidate = candidates[i];
Object item = reference.createLookupItem(candidate);
if (item == null) {
item = FileInfoManager.getFileLookupItem(candidate);
}
if (candidate instanceof PsiFile && item instanceof LookupElement && types.length > 0 && ArrayUtil.contains(((PsiFile) candidate).getFileType(), types)) {
item = PrioritizedLookupElement.withPriority((LookupElement) item, Double.MAX_VALUE);
}
variants[i] = item;
}
for (int i = 0; i < additionalItems.size(); i++) {
variants[i + candidates.length] = additionalItems.get(i);
}
if (!reference.getFileReferenceSet().isUrlEncoded()) {
return variants;
}
List<Object> encodedVariants = new ArrayList<>(variants.length + additionalItems.size());
for (int i = 0; i < candidates.length; i++) {
final PsiElement element = candidates[i];
if (element instanceof PsiNamedElement) {
final PsiNamedElement psiElement = (PsiNamedElement) element;
String name = psiElement.getName();
final String encoded = reference.encode(name, psiElement);
if (encoded == null)
continue;
if (!encoded.equals(name)) {
final Icon icon = psiElement.getIcon(Iconable.ICON_FLAG_READ_STATUS | Iconable.ICON_FLAG_VISIBILITY);
LookupElementBuilder item = FileInfoManager.getFileLookupItem(candidates[i], encoded, icon);
encodedVariants.add(item.withTailText(" (" + name + ")"));
} else {
encodedVariants.add(variants[i]);
}
}
}
encodedVariants.addAll(additionalItems);
return ArrayUtil.toObjectArray(encodedVariants);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class PsiCommentManipulator method handleContentChange.
@Override
public PsiComment handleContentChange(@NotNull PsiComment psiComment, @NotNull TextRange range, String newContent) throws IncorrectOperationException {
String oldText = psiComment.getText();
String newText = oldText.substring(0, range.getStartOffset()) + newContent + oldText.substring(range.getEndOffset());
FileType type = psiComment.getContainingFile().getFileType();
PsiFile fromText = PsiFileFactory.getInstance(psiComment.getProject()).createFileFromText("__." + type.getDefaultExtension(), type, newText);
PsiComment newElement = PsiTreeUtil.getParentOfType(fromText.findElementAt(0), psiComment.getClass(), false);
assert newElement != null : type + " " + type.getDefaultExtension() + " " + newText;
return (PsiComment) psiComment.replace(newElement);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class StubVersionMap method registerStamp.
private void registerStamp(FileType fileTypeByName, long stamp) {
fileTypeToVersion.put(fileTypeByName, stamp);
FileType previousType = versionToFileType.put(stamp, fileTypeByName);
if (previousType != null) {
assert false;
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class IndexConfiguration method registerIndex.
<K, V> void registerIndex(ID<K, V> name, @NotNull UpdatableIndex<K, V, FileContent> index, FileBasedIndex.InputFilter inputFilter, int version, @Nullable Collection<FileType> associatedFileTypes) {
assert !myFreezed;
synchronized (myIndices) {
myIndexIdToVersionMap.put(name, version);
if (associatedFileTypes != null && !associatedFileTypes.isEmpty()) {
for (FileType fileType : associatedFileTypes) {
List<ID<?, ?>> ids = myFileType2IndicesWithFileTypeInfoMap.get(fileType);
if (ids == null)
myFileType2IndicesWithFileTypeInfoMap.put(fileType, ids = new ArrayList<>(5));
ids.add(name);
}
} else {
myIndicesWithoutFileTypeInfo.add(name);
}
Pair<UpdatableIndex<?, ?, FileContent>, FileBasedIndex.InputFilter> old = myIndices.put(name, new Pair<>(index, inputFilter));
if (old != null) {
throw new IllegalStateException("Index " + old.first + " already registered for the name '" + name + "'");
}
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class LanguageTextField method createDocument.
public static Document createDocument(String value, @Nullable Language language, Project project, @NotNull SimpleDocumentCreator documentCreator) {
if (language != null) {
final PsiFileFactory factory = PsiFileFactory.getInstance(project);
final FileType fileType = language.getAssociatedFileType();
assert fileType != null;
final long stamp = LocalTimeCounter.currentTime();
final PsiFile psiFile = factory.createFileFromText("Dummy." + fileType.getDefaultExtension(), fileType, value, stamp, true, false);
documentCreator.customizePsiFile(psiFile);
final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
assert document != null;
return document;
} else {
return EditorFactory.getInstance().createDocument(value);
}
}
Aggregations