use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method addDependency.
private static void addDependency(final XmlFile file, final Set<PsiFile> visited) {
if (file != null) {
final XmlDocument document = file.getDocument();
collectDependencies(document != null ? document.getRootTag() : null, file, visited);
}
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlNSDescriptorImpl method findSpecialTagIn.
private static XmlTag findSpecialTagIn(final XmlTag[] tags, final String specialName, final String name, final XmlTag rootTag, final XmlNSDescriptorImpl descriptor, final HashSet<XmlTag> visited) {
for (XmlTag tag : tags) {
if (equalsToSchemaName(tag, specialName)) {
String attribute = tag.getAttributeValue("name");
if (name.equals(attribute) || name.contains(":") && name.substring(name.indexOf(":") + 1).equals(attribute)) {
return tag;
}
} else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME) || (equalsToSchemaName(tag, IMPORT_TAG_NAME) && rootTag.getNamespaceByPrefix(XmlUtil.findPrefixByQualifiedName(name)).equals(tag.getAttributeValue("namespace")))) {
final String schemaLocation = tag.getAttributeValue("schemaLocation");
if (schemaLocation != null) {
final XmlFile xmlFile = XmlUtil.findNamespace(rootTag.getContainingFile(), schemaLocation);
if (xmlFile != null) {
final XmlDocument document = xmlFile.getDocument();
if (document != null) {
final XmlTag rTag = findSpecialTag(name, specialName, document.getRootTag(), descriptor, visited);
if (rTag != null)
return rTag;
}
}
}
} else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
XmlTag rTag = findSpecialTagIn(tag.getSubTags(), specialName, name, rootTag, descriptor, visited);
if (rTag != null)
return rTag;
final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
if (nsDescriptor != null) {
final XmlTag redefinedRootTag = ((XmlDocument) nsDescriptor.getDeclaration()).getRootTag();
rTag = findSpecialTagIn(redefinedRootTag.getSubTags(), specialName, name, redefinedRootTag, nsDescriptor, visited);
if (rTag != null)
return rTag;
}
}
}
return null;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class GenerateDTDAction method getHandler.
@Override
@NotNull
protected CodeInsightActionHandler getHandler() {
return new CodeInsightActionHandler() {
@Override
public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
final XmlDocument document = findSuitableXmlDocument(file);
if (document != null) {
@NonNls final StringBuilder buffer = new StringBuilder();
buffer.append("<!DOCTYPE " + document.getRootTag().getName() + " [\n");
buffer.append(XmlUtil.generateDocumentDTD(document, true));
buffer.append("]>\n");
XmlFile tempFile;
try {
final XmlProlog prolog = document.getProlog();
final PsiElement childOfType = PsiTreeUtil.getChildOfType(prolog, XmlProcessingInstruction.class);
if (childOfType != null) {
final String text = childOfType.getText();
buffer.insert(0, text);
final PsiElement nextSibling = childOfType.getNextSibling();
if (nextSibling instanceof PsiWhiteSpace) {
buffer.insert(text.length(), nextSibling.getText());
}
}
tempFile = (XmlFile) PsiFileFactory.getInstance(file.getProject()).createFileFromText("dummy.xml", buffer.toString());
prolog.replace(tempFile.getDocument().getProlog());
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
}
};
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlTextContextType method isInContext.
@Override
public boolean isInContext(@NotNull PsiFile file, int offset) {
if (!XmlContextType.isInXml(file, offset))
return false;
PsiElement element = file.findElementAt(offset);
if (element == null)
return false;
if (PsiTreeUtil.getParentOfType(element, XmlText.class, false) != null) {
return true;
}
PsiElement parent = element.getParent();
if (parent instanceof PsiErrorElement) {
parent = parent.getParent();
}
return parent instanceof XmlDocument;
}
use of com.intellij.psi.xml.XmlDocument in project intellij-community by JetBrains.
the class XmlElementSignatureProvider method restoreBySignatureTokens.
@Override
protected PsiElement restoreBySignatureTokens(@NotNull PsiFile file, @NotNull PsiElement parent, @NotNull String type, @NotNull StringTokenizer tokenizer, @Nullable StringBuilder processingInfoStorage) {
if (type.equals("tag")) {
String name = tokenizer.nextToken();
if (parent instanceof XmlFile) {
parent = ((XmlFile) parent).getDocument();
if (parent == null) {
return null;
}
}
try {
int index = Integer.parseInt(tokenizer.nextToken());
String unescapedName = unescape(name);
PsiElement result = restoreElementInternal(parent, unescapedName, index, XmlTag.class);
if (result == null && file.getFileType() == StdFileTypes.JSP) {
//TODO: FoldingBuilder API, psi roots, etc?
if (parent instanceof XmlDocument) {
// html tag, not found in jsp tree
result = restoreElementInternal(HtmlUtil.getRealXmlDocument((XmlDocument) parent), unescapedName, index, XmlTag.class);
} else if (name.equals("<unnamed>") && parent != null) {
// scriplet/declaration missed because null name
result = restoreElementInternal(parent, "", index, XmlTag.class);
}
}
return result;
} catch (NumberFormatException e) {
LOG.error(e);
return null;
}
}
return null;
}
Aggregations