下面列出了怎么用com.intellij.psi.impl.source.xml.XmlFileImpl的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
protected boolean runEnable(AnActionEvent anActionEvent) {
Object o = anActionEvent.getDataContext().getData(DataConstants.PSI_FILE);
if (o instanceof XmlFileImpl) {
parentFileName = ((XmlFileImpl) o).getVirtualFile().getParent().getName();
if (isPreference(parentFileName)) {
return true;
}
} else if (o instanceof PsiFile) {
parentFileName = ((PsiFile) o).getVirtualFile().getParent().getName();
if (isDataBase(parentFileName)) {
return true;
}
}
return false;
}
public static List<PsiElement> findXmlPsiElement(Project project, Collection<VirtualFile> virtualFiles, String key) {
List<PsiElement> result = new ArrayList<>();
for (VirtualFile virtualFile : virtualFiles) {
PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
if (psiFile instanceof XmlFileImpl) {
XmlFileImpl xmlFile = (XmlFileImpl) psiFile;
PsiElement navigationElement = xmlFile.getNavigationElement();
if (Objects.nonNull(navigationElement)) {
if (Objects.nonNull(navigationElement.getChildren())) {
PsiElement child = navigationElement.getChildren()[0];
if (Objects.nonNull(child)) {
if (Objects.nonNull(child.getChildren()) && child.getChildren().length > 0) {
PsiElement child1 = child.getChildren()[1];
if (Objects.nonNull(child1)) {
PsiElement[] psiElements = child1.getChildren();
if (Objects.nonNull(psiElements) && psiElements.length > 0) {
List<XmlTag> xmlTags = PsiTreeUtil.getChildrenOfAnyType(child1, XmlTag.class);
for (XmlTag xmlTag : xmlTags) {
if ("sql".equals(xmlTag.getName())) {
XmlAttribute xmlAttribute = xmlTag.getAttribute("id");
String id = xmlAttribute.getValue();
if (key.equals(id)) {
result.add(xmlAttribute.getValueElement());
}
}
}
}
}
}
}
}
}
}
}
return result;
}
@Override
protected String getAndroidFacetName(AnActionEvent anActionEvent) {
Object o = anActionEvent.getDataContext().getData(DataConstants.PSI_FILE);
if (o instanceof XmlFileImpl) {
return ((XmlFileImpl) o).getVirtualFile().getParent().getParent().getName();
} else if (o instanceof PsiFile) {
return parentFileName = ((PsiFile) o).getVirtualFile().getParent().getParent().getName();
}
return super.getAndroidFacetName(anActionEvent);
}
public boolean parseRequirejsConfig() {
VirtualFile mainJsVirtualFile = findPathInWebDir(settings.configFilePath);
if (null == mainJsVirtualFile) {
this.showErrorConfigNotification("Config file not found. File " + settings.publicPath + '/' + settings.configFilePath + " not found in project");
LOG.debug("Config not found");
return false;
} else {
PsiFile mainJs = PsiManager.getInstance(project).findFile(mainJsVirtualFile);
if (mainJs instanceof JSFileImpl || mainJs instanceof XmlFileImpl) {
Map<String, VirtualFile> allConfigPaths;
packageConfig.clear();
requireMap.clear();
requirePaths.clear();
if (((PsiFileImpl) mainJs).getTreeElement() == null) {
parseMainJsFile(((PsiFileImpl) mainJs).calcTreeElement());
} else {
parseMainJsFile(((PsiFileImpl) mainJs).getTreeElement());
}
} else {
this.showErrorConfigNotification("Config file wrong format");
LOG.debug("Config file wrong format");
return false;
}
}
return true;
}