use of com.intellij.psi.xml.XmlDocument in project intellij-plugins by JetBrains.
the class FxDefinitionBackedDescriptor method getDeclarationByFxDefinitionTag.
@Nullable
private static XmlAttributeValue getDeclarationByFxDefinitionTag(@NotNull final XmlTag xmlTag) {
if (!xmlTag.isValid() || xmlTag.getParent() instanceof XmlDocument) {
return null;
}
XmlTag rootTag = xmlTag;
XmlTag parent;
while ((parent = rootTag.getParentTag()) != null) {
rootTag = parent;
}
final XmlTag[] subTags = rootTag.getSubTags();
final XmlTag libraryTag = subTags.length > 0 && FlexPredefinedTagNames.LIBRARY.equals(subTags[0].getLocalName()) && JavaScriptSupportLoader.MXML_URI3.equals(subTags[0].getNamespace()) ? subTags[0] : null;
final XmlTag[] definitionTags = libraryTag == null ? XmlTag.EMPTY : libraryTag.findSubTags(CodeContext.DEFINITION_TAG_NAME, JavaScriptSupportLoader.MXML_URI3);
final String localName = xmlTag.getLocalName();
for (final XmlTag definitionTag : definitionTags) {
final XmlAttribute nameAttribute = definitionTag.getAttribute(MxmlLanguageTagsUtil.NAME_ATTRIBUTE);
final XmlAttributeValue attributeValue = nameAttribute == null ? null : nameAttribute.getValueElement();
if (attributeValue != null && localName.equals(attributeValue.getValue())) {
return attributeValue;
}
}
return null;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class AntDomFileDescription method isAntFile.
public static boolean isAntFile(final XmlFile xmlFile) {
final XmlDocument document = xmlFile.getDocument();
if (document != null) {
final XmlTag tag = document.getRootTag();
final VirtualFile vFile = xmlFile.getOriginalFile().getVirtualFile();
if (tag != null && ROOT_TAG_NAME.equals(tag.getName()) && tag.getContext() instanceof XmlDocument) {
if (tag.getAttributeValue("name") != null && tag.getAttributeValue("default") != null && vFile != null && ForcedAntFileAttribute.mayBeAntFile(vFile)) {
return true;
}
}
if (vFile != null && ForcedAntFileAttribute.isAntFile(vFile)) {
return true;
}
}
return false;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class DomGenPanel method createUIComponents.
private void createUIComponents() {
mySchemaLocation = new TextFieldWithBrowseButton();
final String title = "Choose XSD or DTD schema";
mySchemaLocation.addBrowseFolderListener(title, "Make sure there are only necessary schemes in directory where your XSD or DTD schema is located", myProject, new FileTypeDescriptor(title, "xsd", "dtd"));
mySchemaLocation.getTextField().setEditable(false);
mySchemaLocation.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final File file = new File(mySchemaLocation.getText());
if (file.exists() && file.getName().toLowerCase().endsWith(".xsd")) {
final VirtualFile vf = LocalFileSystem.getInstance().findFileByIoFile(file);
if (vf != null) {
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vf);
if (psiFile instanceof XmlFile) {
final XmlDocument xml = ((XmlFile) psiFile).getDocument();
if (xml != null) {
final XmlTag rootTag = xml.getRootTag();
if (rootTag != null) {
String target = null;
ArrayList<String> ns = new ArrayList<>();
for (XmlAttribute attr : rootTag.getAttributes()) {
if ("targetNamespace".equals(attr.getName())) {
target = attr.getValue();
} else if (attr.getName().startsWith("xmlns")) {
ns.add(attr.getValue());
}
}
ns.remove(target);
if (target != null) {
myNamespace.setText(target);
}
mySkipSchemas.setText(StringUtil.join(ArrayUtil.toStringArray(ns), "\n"));
}
}
}
}
}
}
});
myOutputDir = new TextFieldWithBrowseButton();
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
myOutputDir.addBrowseFolderListener("Select Output Directory For Generated Files", "", myProject, descriptor);
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class RegistrationCheckerUtil method processPluginXml.
private static void processPluginXml(XmlFile xmlFile, RegistrationTypeFinder finder, boolean includeActions) {
final XmlDocument document = xmlFile.getDocument();
if (document == null)
return;
final XmlTag rootTag = document.getRootTag();
if (rootTag == null)
return;
DescriptorUtil.processComponents(rootTag, finder);
if (includeActions) {
DescriptorUtil.processActions(rootTag, finder);
}
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class ExternalAnnotationsManagerImpl method annotateExternally.
private void annotateExternally(@NotNull final PsiModifierListOwner listOwner, @NotNull final String annotationFQName, @Nullable final XmlFile xmlFile, @NotNull final PsiFile codeUsageFile, @Nullable final PsiNameValuePair[] values) {
if (xmlFile == null) {
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
return;
}
try {
final XmlDocument document = xmlFile.getDocument();
if (document != null) {
final XmlTag rootTag = document.getRootTag();
final String externalName = getExternalName(listOwner, false);
if (externalName == null) {
LOG.info("member without external name: " + listOwner);
}
if (rootTag != null && externalName != null) {
XmlTag anchor = null;
for (XmlTag item : rootTag.getSubTags()) {
int compare = Comparing.compare(externalName, StringUtil.unescapeXml(item.getAttributeValue("name")));
if (compare == 0) {
anchor = null;
for (XmlTag annotation : item.getSubTags()) {
compare = Comparing.compare(annotationFQName, annotation.getAttributeValue("name"));
if (compare == 0) {
annotation.delete();
break;
}
anchor = annotation;
}
XmlTag newTag = XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText(createAnnotationTag(annotationFQName, values));
item.addAfter(newTag, anchor);
commitChanges(xmlFile);
notifyAfterAnnotationChanging(listOwner, annotationFQName, true);
return;
}
if (compare < 0)
break;
anchor = item;
}
@NonNls String text = "<item name=\'" + StringUtil.escapeXml(externalName) + "\'>\n";
text += createAnnotationTag(annotationFQName, values);
text += "</item>";
rootTag.addAfter(XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText(text), anchor);
commitChanges(xmlFile);
notifyAfterAnnotationChanging(listOwner, annotationFQName, true);
return;
}
}
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
} catch (IncorrectOperationException e) {
LOG.error(e);
notifyAfterAnnotationChanging(listOwner, annotationFQName, false);
} finally {
dropCache();
if (codeUsageFile.getVirtualFile().isInLocalFileSystem()) {
UndoUtil.markPsiFileForUndo(codeUsageFile);
}
}
}
Aggregations