use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class LongLineInspection method checkFile.
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
final Project project = manager.getProject();
final int codeStyleRightMargin = CodeStyleSettingsManager.getSettings(project).getRightMargin(file.getLanguage());
final VirtualFile vFile = file.getVirtualFile();
if (vFile instanceof VirtualFileWindow) {
return null;
}
final Document document = FileDocumentManager.getInstance().getDocument(vFile);
if (document == null) {
return null;
}
final List<ProblemDescriptor> descriptors = new SmartList<>();
for (int idx = 0; idx < document.getLineCount(); idx++) {
final int startOffset = document.getLineStartOffset(idx);
final int endOffset = document.getLineEndOffset(idx);
if (endOffset - startOffset > codeStyleRightMargin) {
final int maxOffset = startOffset + codeStyleRightMargin;
descriptors.add(manager.createProblemDescriptor(file, new TextRange(maxOffset, endOffset), String.format("Line is longer than allowed by code style (> %s columns)", codeStyleRightMargin), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly));
}
}
return descriptors.isEmpty() ? null : descriptors.toArray(new ProblemDescriptor[descriptors.size()]);
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class InjectedFileViewProvider method clone.
@Override
public FileViewProvider clone() {
final DocumentWindow oldDocumentWindow = ((VirtualFileWindow) getVirtualFile()).getDocumentWindow();
Document hostDocument = oldDocumentWindow.getDelegate();
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(getManager().getProject());
PsiFile hostFile = documentManager.getPsiFile(hostDocument);
Language language = getBaseLanguage();
PsiFile file = getPsi(language);
final Language hostFileLanguage = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file).getLanguage();
PsiFile hostPsiFileCopy = (PsiFile) hostFile.copy();
Segment firstTextRange = oldDocumentWindow.getHostRanges()[0];
PsiElement hostElementCopy = hostPsiFileCopy.getViewProvider().findElementAt(firstTextRange.getStartOffset(), hostFileLanguage);
assert hostElementCopy != null;
final Ref<FileViewProvider> provider = new Ref<>();
PsiLanguageInjectionHost.InjectedPsiVisitor visitor = new PsiLanguageInjectionHost.InjectedPsiVisitor() {
@Override
public void visit(@NotNull PsiFile injectedPsi, @NotNull List<PsiLanguageInjectionHost.Shred> places) {
Document document = documentManager.getCachedDocument(injectedPsi);
if (document instanceof DocumentWindowImpl && oldDocumentWindow.areRangesEqual((DocumentWindowImpl) document)) {
provider.set(injectedPsi.getViewProvider());
}
}
};
for (PsiElement current = hostElementCopy; current != null && current != hostPsiFileCopy; current = current.getParent()) {
current.putUserData(LANGUAGE_FOR_INJECTED_COPY_KEY, language);
try {
InjectedLanguageUtil.enumerate(current, hostPsiFileCopy, false, visitor);
} finally {
current.putUserData(LANGUAGE_FOR_INJECTED_COPY_KEY, null);
}
if (provider.get() != null)
break;
}
return provider.get();
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class InjectedLanguageManagerImpl method getInjectionHost.
@Override
public PsiLanguageInjectionHost getInjectionHost(@NotNull PsiElement element) {
final PsiFile file = element.getContainingFile();
final VirtualFile virtualFile = file == null ? null : file.getVirtualFile();
if (virtualFile instanceof VirtualFileWindow) {
// use utility method in case the file's overridden getContext()
PsiElement host = FileContextUtil.getFileContext(file);
if (host instanceof PsiLanguageInjectionHost) {
return (PsiLanguageInjectionHost) host;
}
}
return null;
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-community by JetBrains.
the class PerFileConfigurableBase method selectFile.
public void selectFile(@NotNull VirtualFile virtualFile, boolean addIfMissing) {
VirtualFile file = virtualFile instanceof VirtualFileWindow ? ((VirtualFileWindow) virtualFile).getDelegate() : virtualFile;
int[] rows = findRow(file, addIfMissing, false);
if (rows.length == 0 && addIfMissing) {
doAddFiles(Collections.singletonList(virtualFile));
} else {
selectRows(rows, true);
}
myFileToSelect = file;
}
use of com.intellij.injected.editor.VirtualFileWindow in project intellij-plugins by JetBrains.
the class IncrementalDocumentSynchronizer method styleChanged.
private void styleChanged() {
// BE AWARE!!! INJECTION BEHAVIOR IS NOT PREDICTABLE, file may be injected.
//noinspection ConstantConditions
VirtualFile file = event.getFile().getViewProvider().getVirtualFile();
if (file instanceof VirtualFileWindow) {
file = ((VirtualFileWindow) file).getDelegate();
}
DesignerApplicationManager.getInstance().renderDocumentsAndCheckLocalStyleModification(new Document[] { FileDocumentManager.getInstance().getCachedDocument(file) }, true, false);
}
Aggregations