use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class TypeOrElementOrAttributeReference method getVariants.
public static Object[] getVariants(XmlTag tag, ReferenceType type, String prefix) {
String[] tagNames = null;
switch(type) {
case GroupReference:
tagNames = new String[] { SchemaReferencesProvider.GROUP_TAG_NAME };
break;
case AttributeGroupReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_GROUP_TAG_NAME };
break;
case AttributeReference:
tagNames = new String[] { SchemaReferencesProvider.ATTRIBUTE_TAG_NAME };
break;
case ElementReference:
tagNames = new String[] { SchemaReferencesProvider.ELEMENT_TAG_NAME };
break;
case TypeReference:
tagNames = new String[] { SchemaReferencesProvider.SIMPLE_TYPE_TAG_NAME, SchemaReferencesProvider.COMPLEX_TYPE_TAG_NAME };
break;
}
final XmlDocument document = ((XmlFile) tag.getContainingFile()).getDocument();
if (document == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final XmlTag rootTag = document.getRootTag();
String ourNamespace = rootTag != null ? rootTag.getAttributeValue(TARGET_NAMESPACE) : "";
if (ourNamespace == null)
ourNamespace = "";
CompletionProcessor processor = new CompletionProcessor(tag, prefix);
for (String namespace : tag.knownNamespaces()) {
if (ourNamespace.equals(namespace))
continue;
final XmlNSDescriptor nsDescriptor = tag.getNSDescriptor(namespace, true);
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(namespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
}
XmlNSDescriptor nsDescriptor = (XmlNSDescriptor) document.getMetaData();
if (nsDescriptor instanceof XmlNSDescriptorImpl) {
processNamespace(ourNamespace, processor, (XmlNSDescriptorImpl) nsDescriptor, tagNames);
}
return ArrayUtil.toStringArray(processor.myElements);
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class ExternalAnnotationsManagerImpl method sortItems.
private static void sortItems(@NotNull XmlFile xmlFile) {
XmlDocument document = xmlFile.getDocument();
if (document == null) {
return;
}
XmlTag rootTag = document.getRootTag();
if (rootTag == null) {
return;
}
List<XmlTag> itemTags = new ArrayList<>();
for (XmlTag item : rootTag.getSubTags()) {
if (item.getAttributeValue("name") != null) {
itemTags.add(item);
} else {
item.delete();
}
}
List<XmlTag> sorted = new ArrayList<>(itemTags);
Collections.sort(sorted, (item1, item2) -> {
String externalName1 = item1.getAttributeValue("name");
String externalName2 = item2.getAttributeValue("name");
// null names were not added
assert externalName1 != null && externalName2 != null;
return externalName1.compareTo(externalName2);
});
if (!sorted.equals(itemTags)) {
for (XmlTag item : sorted) {
rootTag.addAfter(item, null);
item.delete();
}
}
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlStructuralSearchProfile method createPatternTree.
@NotNull
@Override
public PsiElement[] createPatternTree(@NotNull String text, @NotNull PatternTreeContext context, @NotNull FileType fileType, @Nullable Language language, String contextName, @Nullable String extension, @NotNull Project project, boolean physical) {
final String ext = extension != null ? extension : fileType.getDefaultExtension();
String text1 = context == PatternTreeContext.File ? text : "<QQQ>" + text + "</QQQ>";
final PsiFile fileFromText = PsiFileFactory.getInstance(project).createFileFromText("dummy." + ext, fileType, text1, LocalTimeCounter.currentTime(), physical, true);
final XmlDocument document = HtmlUtil.getRealXmlDocument(((XmlFile) fileFromText).getDocument());
if (context == PatternTreeContext.File) {
return new PsiElement[] { document };
}
return document.getRootTag().getValue().getChildren();
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class AddAntBuildFile method update.
public void update(@NotNull AnActionEvent e) {
final Presentation presentation = e.getPresentation();
final Project project = e.getProject();
if (project != null) {
final VirtualFile[] files = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
if (files != null && files.length > 0) {
for (VirtualFile file : files) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (!(psiFile instanceof XmlFile)) {
continue;
}
final XmlFile xmlFile = (XmlFile) psiFile;
final XmlDocument document = xmlFile.getDocument();
if (document == null) {
continue;
}
final XmlTag rootTag = document.getRootTag();
if (rootTag == null) {
continue;
}
if (!"project".equals(rootTag.getName())) {
continue;
}
if (AntConfigurationBase.getInstance(project).getAntBuildFile(psiFile) != null) {
continue;
}
// found at least one candidate file
enable(presentation);
return;
}
}
}
disable(presentation);
}
use of com.intellij.psi.xml.XmlDocument in project intellij-plugins by JetBrains.
the class FlexUtils method processMetaAttributesForClass.
public static void processMetaAttributesForClass(@NotNull PsiElement jsClass, @NotNull final ActionScriptResolveUtil.MetaDataProcessor processor) {
ActionScriptResolveUtil.processMetaAttributesForClass(jsClass, processor);
if (jsClass instanceof XmlBackedJSClassImpl) {
PsiElement parent = jsClass.getParent();
if (parent != null) {
PsiFile file = parent.getContainingFile();
if (file instanceof XmlFile) {
XmlDocument document = ((XmlFile) file).getDocument();
if (document != null) {
XmlTag rootTag = document.getRootTag();
if (rootTag != null) {
JSResolveUtil.JSInjectedFilesVisitor visitor = new JSResolveUtil.JSInjectedFilesVisitor() {
@Override
protected void process(JSFile file) {
if (file != null) {
ActionScriptResolveUtil.processMetaAttributesForClass(file, processor);
}
}
};
processMxmlTags(rootTag, true, visitor);
}
}
}
}
}
}
Aggregations