本文整理汇总了Java中com.intellij.psi.xml.XmlFile.getVirtualFile方法的典型用法代码示例。如果您正苦于以下问题:Java XmlFile.getVirtualFile方法的具体用法?Java XmlFile.getVirtualFile怎么用?Java XmlFile.getVirtualFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.xml.XmlFile
的用法示例。
在下文中一共展示了XmlFile.getVirtualFile方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDomFileEditor
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
public static DomFileEditor createDomFileEditor(final String name,
@Nullable final Icon icon,
final DomElement element,
final Factory<? extends CommittablePanel> committablePanel) {
final XmlFile file = DomUtil.getFile(element);
final Factory<BasicDomElementComponent> factory = new Factory<BasicDomElementComponent>() {
@Override
public BasicDomElementComponent create() {
CaptionComponent captionComponent = new CaptionComponent(name, icon);
captionComponent.initErrorPanel(element);
BasicDomElementComponent component = createComponentWithCaption(committablePanel.create(), captionComponent, element);
Disposer.register(component, captionComponent);
return component;
}
};
return new DomFileEditor<BasicDomElementComponent>(file.getProject(), file.getVirtualFile(), name, factory) {
@Override
public JComponent getPreferredFocusedComponent() {
return null;
}
};
}
示例2: parseXmlFileInTemplate
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@NotNull
private static XmlFile parseXmlFileInTemplate(@NotNull TemplateImpl template, @NotNull CustomTemplateCallback callback,
@NotNull Map<String, String> attributes) {
XmlTag dummyRootTag = null;
String templateString = template.getString();
final PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(callback.getProject());
if (!containsAttrsVar(template)) {
XmlFile dummyFile = (XmlFile)psiFileFactory.createFileFromText("dummy.html", HTMLLanguage.INSTANCE, templateString, false, true);
dummyRootTag = dummyFile.getRootTag();
if (dummyRootTag != null) {
addMissingAttributes(dummyRootTag, attributes);
}
}
templateString = dummyRootTag != null ? dummyRootTag.getContainingFile().getText() : templateString;
XmlFile xmlFile =
(XmlFile)psiFileFactory.createFileFromText("dummy.xml", StdFileTypes.XML, templateString, LocalTimeCounter.currentTime(), true);
VirtualFile vFile = xmlFile.getVirtualFile();
if (vFile != null) {
vFile.putUserData(UndoConstants.DONT_RECORD_UNDO, Boolean.TRUE);
}
return xmlFile;
}
示例3: findXmlFileInRoot
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@Nullable
private static XmlFile findXmlFileInRoot(@Nullable List<XmlFile> xmlFiles, @NotNull VirtualFile root) {
if (xmlFiles != null) {
for (XmlFile xmlFile : xmlFiles) {
VirtualFile vf = xmlFile.getVirtualFile();
if (vf != null) {
if (VfsUtilCore.isAncestor(root, vf, false)) {
return xmlFile;
}
}
}
}
return null;
}
示例4: getFileElement
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@Override
@Nullable
public final <T extends DomElement> DomFileElementImpl<T> getFileElement(XmlFile file) {
if (file == null) return null;
if (!(file.getFileType() instanceof DomSupportEnabled)) return null;
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null && virtualFile.isDirectory()) return null;
return this.<T>getOrCreateCachedValueProvider(file).getFileElement();
}
示例5: actionPerformedImpl
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
private boolean actionPerformedImpl(AnActionEvent e) {
final PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
if (file == null) {
return false;
}
final Project project = e.getData(CommonDataKeys.PROJECT);
if (project == null) {
return false;
}
final RngElementDescriptor descriptor = getRootDescriptor(file);
if (descriptor == null) return false;
final PsiElement element = descriptor.getDeclaration();
final XmlFile xmlFile = PsiTreeUtil.getParentOfType(element, XmlFile.class);
if (xmlFile == null) return false;
final VirtualFile instanceFile = file.getVirtualFile();
final VirtualFile schemaFile = xmlFile.getVirtualFile();
if (instanceFile == null || schemaFile == null) {
return true;
}
doRun(project, instanceFile, schemaFile);
return true;
}
示例6: processForwardDependencies
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
public static boolean processForwardDependencies(XmlFile file, final PsiElementProcessor<XmlFile> processor) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return processor.execute(file);
}
final Project project = file.getProject();
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludedFiles(virtualFile, true);
return processRelatedFiles(file, files, processor);
}
示例7: processBackwardDependencies
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
public static boolean processBackwardDependencies(@NotNull XmlFile file, PsiElementProcessor<XmlFile> processor) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return processor.execute(file);
}
final Project project = file.getProject();
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludingFiles(virtualFile, true);
return processRelatedFiles(file, files, processor);
}
示例8: inEnglish
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
/**
* Returns true if the given element is in an XML file that is in an English resource.
* Manifest files are considered to be in English, as are resources in base folders
* (unless a locale is explicitly defined on the root element)
*/
private static boolean inEnglish(PsiElement element) {
XmlFile file = PsiTreeUtil.getParentOfType(element, XmlFile.class);
if (file != null) {
String name = file.getName();
if (name.equals(ANDROID_MANIFEST_XML)) {
return true;
} else if (name.equals("generated.xml")) {
// Android Studio Workaround for issue https://code.google.com/p/android/issues/detail?id=76715
// If this a generated file like this:
// ${project}/${module}/build/generated/res/generated/{test?}/${flavors}/${build-type}/values/generated.xml
// ? If so, skip it.
AndroidFacet facet = AndroidFacet.getInstance(file);
VirtualFile virtualFile = file.getVirtualFile();
if (facet != null && facet.isGradleProject() && virtualFile != null) {
IdeaAndroidProject project = facet.getIdeaAndroidProject();
if (project != null) {
VirtualFile buildFolder = VfsUtil.findFileByIoFile(project.getDelegate().getBuildFolder(), false);
if (buildFolder != null && VfsUtilCore.isAncestor(buildFolder, virtualFile, false)) {
return false;
}
}
}
}
PsiDirectory dir = file.getParent();
if (dir != null) {
String locale = LintUtils.getLocaleAndRegion(dir.getName());
if (locale == null) {
locale = getToolsLocale(file);
}
return locale == null || locale.startsWith("en") || locale.equals("b+en") || locale.startsWith("b+en+");
}
}
return false;
}
示例9: doNavigate
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
protected void doNavigate(XmlFile file) {
if (file.isValid() && LayoutPullParserFactory.isSupported(file)) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null && virtualFile.isValid()) {
if (AndroidEditorSettings.getInstance().getGlobalState().isPreferXmlEditor()) {
new OpenFileDescriptor(file.getProject(), virtualFile, 0).navigate(true);
} else {
new OpenFileDescriptor(file.getProject(), virtualFile).navigate(true);
}
}
} else {
PsiNavigateUtil.navigate(file);
}
}
示例10: get
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
/** Returns an {link IncludeReference} specified for the given file, or {@link #NONE} if no include should be performed from the
* given file */
@NotNull
public static IncludeReference get(@NotNull final Module module, @NotNull final XmlFile file, @NotNull final RenderResources resolver) {
if (!ApplicationManager.getApplication().isReadAccessAllowed()) {
return ApplicationManager.getApplication().runReadAction(new Computable<IncludeReference>() {
@NotNull
@Override
public IncludeReference compute() {
return get(module, file, resolver);
}
});
}
ApplicationManager.getApplication().assertReadAccessAllowed();
XmlTag rootTag = file.getRootTag();
if (rootTag != null) {
String layout = rootTag.getAttributeValue(ATTR_RENDER_IN, TOOLS_URI);
if (layout != null) {
ResourceValue resValue = resolver.findResValue(layout, false);
if (resValue != null) {
// TODO: Do some sort of picking based on best configuration!!
// I should make sure I also get a configuration that is compatible with
// my target include! I could stash it in the include reference!
File path = ResourceHelper.resolveLayout(resolver, resValue);
if (path != null) {
VirtualFile source = LocalFileSystem.getInstance().findFileByIoFile(path);
if (source != null) {
VirtualFile target = file.getVirtualFile();
return create(module, source, target);
}
}
}
}
}
return NONE;
}
示例11: forkResourceFile
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
/**
* Create a variation (copy) of a given resource file (of a given type).
*
* @param xmlFile the XML resource file to fork
* @param myNewFolder the resource folder to create, or null to ask the user
* @param open if true, open the file after creating it
*/
public static void forkResourceFile(@NotNull final XmlFile xmlFile, @Nullable String myNewFolder, boolean open) {
VirtualFile file = xmlFile.getVirtualFile();
if (file == null) {
return;
}
Module module = AndroidPsiUtils.getModuleSafely(xmlFile);
if (module == null) {
return;
}
ResourceFolderType folderType = ResourceHelper.getFolderType(xmlFile);
if (folderType == null || folderType == ResourceFolderType.VALUES) {
return;
}
Configuration configuration = null;
if (folderType == ResourceFolderType.LAYOUT) {
AndroidFacet facet = AndroidFacet.getInstance(module);
if (facet != null) {
configuration = facet.getConfigurationManager().getConfiguration(file);
}
}
// Suppress: IntelliJ claims folderType can be null here, but it can't (and inserting assert folderType != null is correctly
// identified as redundant)
//noinspection ConstantConditions
forkResourceFile(module, folderType, file, xmlFile, myNewFolder, configuration, open);
}
示例12: processForwardDependencies
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
public static boolean processForwardDependencies(@NotNull XmlFile file, Processor<XmlFile> processor) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return true;
}
final Project project = file.getProject();
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludedFiles(virtualFile, true);
return _process(files, project, processor);
}
示例13: processBackwardDependencies
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
public static boolean processBackwardDependencies(@NotNull XmlFile file, Processor<XmlFile> processor) {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) {
return true;
}
final Project project = file.getProject();
final VirtualFile[] files = FileIncludeManager.getManager(project).getIncludingFiles(virtualFile, true);
return _process(files, project, processor);
}
示例14: execute
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
@Override
public boolean execute(@NotNull final PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
if (queryParameters instanceof XmlTagImpl) {
final XmlTagImpl xml = (XmlTagImpl) queryParameters;
if (isTypeElement(xml)) {
final Collection<SchemaTypeInfo> infos = ApplicationManager.getApplication().runReadAction(new Computable<Collection<SchemaTypeInfo>>() {
@Override
public Collection<SchemaTypeInfo> compute() {
return gatherInheritors(xml);
}
});
if (infos != null && ! infos.isEmpty()) {
final XmlFile file = XmlUtil.getContainingFile(xml);
final Project project = file.getProject();
final Module module = ModuleUtilCore.findModuleForPsiElement(queryParameters);
//if (module == null) return false;
final VirtualFile vf = file.getVirtualFile();
String thisNs = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
return XmlNamespaceIndex.getNamespace(vf, project, file);
}
});
thisNs = thisNs == null ? getDefaultNs(file) : thisNs;
// so thisNs can be null
if (thisNs == null) return false;
final ArrayList<SchemaTypeInfo> infosLst = new ArrayList<SchemaTypeInfo>(infos);
Collections.sort(infosLst);
final Map<String, Set<XmlFile>> nsMap = new HashMap<String, Set<XmlFile>>();
for (final SchemaTypeInfo info : infosLst) {
Set<XmlFile> targetFiles = nsMap.get(info.getNamespaceUri());
if (targetFiles == null) {
targetFiles = new HashSet<XmlFile>();
if (Comparing.equal(info.getNamespaceUri(), thisNs)) {
targetFiles.add(file);
}
final Collection<XmlFile> files = ApplicationManager.getApplication().runReadAction(new Computable<Collection<XmlFile>>() {
@Override
public Collection<XmlFile> compute() {
return XmlUtil.findNSFilesByURI(info.getNamespaceUri(), project, module);
}
});
if (files != null) {
targetFiles.addAll(files);
}
nsMap.put(info.getNamespaceUri(), targetFiles);
}
if (! targetFiles.isEmpty()) {
for (final XmlFile targetFile : targetFiles) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
public void run() {
final String prefixByURI = XmlUtil.findNamespacePrefixByURI(targetFile, info.getNamespaceUri());
if (prefixByURI == null) return;
final PsiElementProcessor processor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull PsiElement element) {
if (element instanceof XmlTagImpl) {
if (isCertainTypeElement((XmlTagImpl)element, info.getTagName(), prefixByURI) ||
isElementWithEmbeddedType((XmlTagImpl)element, info.getTagName(), prefixByURI)) {
consumer.process(element);
return false;
}
}
return true;
}
};
XmlUtil.processXmlElements(targetFile, processor, true);
}
});
}
}
}
}
}
}
return true;
}