本文整理汇总了Java中com.intellij.psi.xml.XmlFile.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java XmlFile.getParent方法的具体用法?Java XmlFile.getParent怎么用?Java XmlFile.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.xml.XmlFile
的用法示例。
在下文中一共展示了XmlFile.getParent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isXmlResourceFile
import com.intellij.psi.xml.XmlFile; //导入方法依赖的package包/类
private static boolean isXmlResourceFile(XmlFile file) {
if (!AndroidResourceUtil.isInResourceSubdirectory(file, null)) {
return false;
}
final PsiDirectory parent = file.getParent();
if (parent == null) {
return false;
}
final String resType = AndroidCommonUtils.getResourceTypeByDirName(parent.getName());
if (resType == null) {
return false;
}
if (resType.equals(ResourceType.XML.getName())) {
return XmlResourceDomFileDescription.isXmlResourceFile(file);
}
return !resType.equals("raw");
}
示例2: 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;
}