use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class BlockSupportImpl method makeFullParse.
@NotNull
private static DiffLog makeFullParse(@NotNull PsiFileImpl fileImpl, @NotNull FileASTNode oldFileNode, @NotNull CharSequence newFileText, @NotNull ProgressIndicator indicator, @NotNull CharSequence lastCommittedText) {
if (fileImpl instanceof PsiCodeFragment) {
FileElement parent = fileImpl.getTreeElement();
final FileElement holderElement = new DummyHolder(fileImpl.getManager(), fileImpl.getContext()).getTreeElement();
holderElement.rawAddChildren(fileImpl.createContentLeafElement(holderElement.getCharTable().intern(newFileText, 0, newFileText.length())));
DiffLog diffLog = new DiffLog();
diffLog.appendReplaceFileElement(parent, (FileElement) holderElement.getFirstChildNode());
return diffLog;
} else {
FileViewProvider viewProvider = fileImpl.getViewProvider();
viewProvider.getLanguages();
FileType fileType = viewProvider.getVirtualFile().getFileType();
String fileName = fileImpl.getName();
final LightVirtualFile lightFile = new LightVirtualFile(fileName, fileType, newFileText, viewProvider.getVirtualFile().getCharset(), fileImpl.getViewProvider().getModificationStamp());
lightFile.setOriginalFile(viewProvider.getVirtualFile());
FileViewProvider copy = viewProvider.createCopy(lightFile);
if (copy.isEventSystemEnabled()) {
throw new AssertionError("Copied view provider must be non-physical for reparse to deliver correct events: " + viewProvider);
}
copy.getLanguages();
// optimization: do not convert file contents to bytes to determine if we should codeinsight it
SingleRootFileViewProvider.doNotCheckFileSizeLimit(lightFile);
PsiFileImpl newFile = getFileCopy(fileImpl, copy);
newFile.setOriginalFile(fileImpl);
final FileElement newFileElement = (FileElement) newFile.getNode();
final FileElement oldFileElement = (FileElement) oldFileNode;
if (!lastCommittedText.toString().equals(oldFileElement.getText())) {
throw new IncorrectOperationException(viewProvider.toString());
}
DiffLog diffLog = mergeTrees(fileImpl, oldFileElement, newFileElement, indicator, lastCommittedText);
((PsiManagerEx) fileImpl.getManager()).getFileManager().setViewProvider(lightFile, null);
return diffLog;
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class JavaVfsSourceRootDetectionUtil method suggestRoots.
/**
* Scan directory and detect java source roots within it. The source root is detected as the following:
* <ol>
* <li>It contains at least one Java file.</li>
* <li>Java file is located in the sub-folder that matches package statement in the file.</li>
* </ol>
*
* @param dir a directory to scan
* @param progressIndicator
* @return a list of found source roots within directory. If no source roots are found, a empty list is returned.
*/
@NotNull
public static List<VirtualFile> suggestRoots(@NotNull VirtualFile dir, @NotNull final ProgressIndicator progressIndicator) {
if (!dir.isDirectory()) {
return ContainerUtil.emptyList();
}
final FileTypeManager typeManager = FileTypeManager.getInstance();
final ArrayList<VirtualFile> foundDirectories = new ArrayList<>();
try {
VfsUtilCore.visitChildrenRecursively(dir, new VirtualFileVisitor() {
@NotNull
@Override
public Result visitFileEx(@NotNull VirtualFile file) {
progressIndicator.checkCanceled();
if (file.isDirectory()) {
if (typeManager.isFileIgnored(file) || StringUtil.startsWithIgnoreCase(file.getName(), "testData")) {
return SKIP_CHILDREN;
}
} else {
FileType type = typeManager.getFileTypeByFileName(file.getName());
if (StdFileTypes.JAVA == type) {
VirtualFile root = suggestRootForJavaFile(file);
if (root != null) {
foundDirectories.add(root);
return skipTo(root);
}
}
}
return CONTINUE;
}
});
} catch (ProcessCanceledException ignore) {
}
return foundDirectories;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class FileDocumentManagerImpl method getDocument.
@Override
@Nullable
public Document getDocument(@NotNull final VirtualFile file) {
ApplicationManager.getApplication().assertReadAccessAllowed();
DocumentEx document = (DocumentEx) getCachedDocument(file);
if (document == null) {
if (!file.isValid() || file.isDirectory() || isBinaryWithoutDecompiler(file))
return null;
boolean tooLarge = FileUtilRt.isTooLarge(file.getLength());
if (file.getFileType().isBinary() && tooLarge)
return null;
final CharSequence text = tooLarge ? LoadTextUtil.loadText(file, getPreviewCharCount(file)) : LoadTextUtil.loadText(file);
synchronized (lock) {
document = (DocumentEx) getCachedDocument(file);
// Double checking
if (document != null)
return document;
document = (DocumentEx) createDocument(text, file);
document.setModificationStamp(file.getModificationStamp());
final FileType fileType = file.getFileType();
document.setReadOnly(tooLarge || !file.isWritable() || fileType.isBinary());
if (!(file instanceof LightVirtualFile || file.getFileSystem() instanceof NonPhysicalFileSystem)) {
document.addDocumentListener(myPhysicalDocumentChangeTracker);
}
if (file instanceof LightVirtualFile) {
registerDocument(document, file);
} else {
document.putUserData(FILE_KEY, file);
cacheDocument(file, document);
}
}
myMultiCaster.fileContentLoaded(file, document);
}
return document;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class HttpVirtualFileImpl method getFileType.
@Override
@NotNull
public FileType getFileType() {
if (myFileInfo == null) {
return super.getFileType();
}
VirtualFile localFile = myFileInfo.getLocalFile();
if (localFile != null) {
return localFile.getFileType();
}
FileType fileType = super.getFileType();
if (myInitialFileType == null) {
myInitialFileType = fileType;
}
return fileType;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class NextPrevWordTest method testRegexpCharsAreNotTreatedAsSeparateWords.
public void testRegexpCharsAreNotTreatedAsSeparateWords() {
FileType regExpFileType = FileTypeManagerEx.getInstanceEx().findFileTypeByName("RegExp");
assertNotNull(regExpFileType);
myFixture.configureByText(regExpFileType, "<caret>abc");
myFixture.performEditorAction(IdeActions.ACTION_EDITOR_NEXT_WORD);
myFixture.checkResult("abc<caret>");
}
Aggregations