本文整理汇总了Java中com.intellij.xml.util.XmlUtil类的典型用法代码示例。如果您正苦于以下问题:Java XmlUtil类的具体用法?Java XmlUtil怎么用?Java XmlUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlUtil类属于com.intellij.xml.util包,在下文中一共展示了XmlUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertSchemaLocationLookup
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static void insertSchemaLocationLookup(XmlFile xmlFile, String namespace, String locationLookup) {
final XmlTag rootTag = xmlFile.getRootTag();
if (rootTag == null)
return;
final XmlAttribute attribute = rootTag.getAttribute("xsi:schemaLocation", HTTP_WWW_W3_ORG_2001_XMLSCHEMA);
if (attribute != null) {
final String value = attribute.getValue();
attribute.setValue(value + "\n\t\t\t" + namespace + " " + locationLookup);
} else {
final XmlElementFactory elementFactory = XmlElementFactory.getInstance(xmlFile.getProject());
final XmlAttribute schemaLocation = elementFactory.createXmlAttribute("xsi:schemaLocation", XmlUtil.XML_SCHEMA_INSTANCE_URI);
schemaLocation.setValue(namespace + " " + locationLookup);
rootTag.add(schemaLocation);
}
}
示例2: getChildrenByName
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public List<DomStub> getChildrenByName(final CharSequence name, @Nullable final String nsKey) {
final List<DomStub> stubs = getChildrenStubs();
if (stubs.isEmpty()) {
return Collections.emptyList();
}
final String s = nsKey == null ? "" : nsKey;
final List<DomStub> result = new SmartList<DomStub>();
//noinspection ForLoopReplaceableByForEach
for (int i = 0, size = stubs.size(); i < size; i++) {
final DomStub stub = stubs.get(i);
if (XmlUtil.getLocalName(stub.getName()).equals(name) &&
Comparing.equal(s, stub.getNamespaceKey())) {
result.add(stub);
}
}
return result;
}
示例3: getElementsToSurround
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
@NotNull public PsiElement[] getElementsToSurround(PsiFile file, int startOffset, int endOffset) {
final Pair<XmlTagChild, XmlTagChild> childrenInRange = XmlUtil.findTagChildrenInRange(file, startOffset, endOffset);
if (childrenInRange == null) {
final PsiElement elementAt = file.findElementAt(startOffset);
if (elementAt instanceof XmlToken &&
((XmlToken)elementAt).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
return new PsiElement[] {elementAt};
}
return PsiElement.EMPTY_ARRAY;
}
List<PsiElement> result = new ArrayList<PsiElement>();
PsiElement first = childrenInRange.getFirst();
PsiElement last = childrenInRange.getSecond();
while(true) {
result.add(first);
if (first == last) break;
first = first.getNextSibling();
}
return PsiUtilCore.toPsiElementArray(result);
}
示例4: calcXmlFileHeader
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@NotNull
private static XmlFileHeader calcXmlFileHeader(final XmlFile file) {
if (file instanceof PsiFileEx && ((PsiFileEx)file).isContentsLoaded() && file.getNode().isParsed()) {
return computeHeaderByPsi(file);
}
if (!XmlUtil.isStubBuilding() && file.getFileType() == XmlFileType.INSTANCE) {
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile instanceof VirtualFileWithId) {
ObjectStubTree tree = StubTreeLoader.getInstance().readFromVFile(file.getProject(), virtualFile);
if (tree != null) {
Stub root = tree.getRoot();
if (root instanceof FileStub) {
return ((FileStub)root).getHeader();
}
}
}
}
if (!file.isValid()) return XmlFileHeader.EMPTY;
return NanoXmlUtil.parseHeader(file);
}
示例5: isSchemaEnumerated
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static boolean isSchemaEnumerated(final PsiElement element) {
if (element instanceof XmlTag) {
final XmlTag simpleContent = XmlUtil.getSchemaSimpleContent((XmlTag)element);
if (simpleContent != null && XmlUtil.collectEnumerationValues(simpleContent, new HashSet<String>())) {
return true;
}
}
if (element instanceof XmlAttributeValue) {
final PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute) {
final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
if (descriptor != null && descriptor.isEnumerated()) {
return true;
}
String[] enumeratedValues = XmlAttributeValueGetter.getEnumeratedValues((XmlAttribute)parent);
if (enumeratedValues != null && enumeratedValues.length > 0) {
String value = descriptor == null ? null : descriptor.getDefaultValue();
if (value == null || enumeratedValues.length != 1 || !value.equals(enumeratedValues[0])) {
return true;
}
}
}
}
return false;
}
示例6: getElementDescriptor
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
public XmlElementDescriptor getElementDescriptor(@NotNull XmlTag tag) {
XmlElementDescriptor elementDescriptor = super.getElementDescriptor(tag);
if (LOG.isDebugEnabled()) {
LOG.debug("Descriptor from rng for tag " +
tag.getName() +
" is " +
(elementDescriptor != null ? elementDescriptor.getClass().getCanonicalName() : "NULL"));
}
String namespace;
if (elementDescriptor == null &&
!((namespace = tag.getNamespace()).equals(XmlUtil.XHTML_URI))) {
return new AnyXmlElementDescriptor(
null,
XmlUtil.HTML_URI.equals(namespace) ? this : tag.getNSDescriptor(tag.getNamespace(), true)
);
}
return elementDescriptor;
}
示例7: get
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
public Object[] get(final PsiElement context, CompletionContext completionContext) {
final List<String> results = new LinkedList<String>();
final PsiElementProcessor processor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull final PsiElement element) {
if (element instanceof XmlEntityDecl) {
final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl)element;
if (xmlEntityDecl.isInternalReference()) {
results.add(xmlEntityDecl.getName());
}
}
return true;
}
};
XmlUtil.processXmlElements((XmlFile)context.getContainingFile().getOriginalFile(), processor, true);
return ArrayUtil.toObjectArray(results);
}
示例8: getCommentBeforeEatComment
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Nullable
private static String getCommentBeforeEatComment(XmlTag tag) {
PsiElement comment = XmlDocumentationProvider.findPreviousComment(tag);
for (int i = 0; i < 5; ++i) {
if (comment == null) {
break;
}
String value = StringUtil.trim(XmlUtil.getCommentText((XmlComment)comment));
// This check is there to ignore "formatting" comments like the first and third lines in
// <!-- ============== -->
// <!-- Generic styles -->
// <!-- ============== -->
if (!StringUtil.isEmpty(value) && value.charAt(0) != '*' && value.charAt(0) != '=') {
return value;
}
comment = XmlDocumentationProvider.findPreviousComment(comment.getPrevSibling());
}
return null;
}
示例9: getType
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Nullable
public TypeDescriptor getType(XmlElement context) {
final XmlNSDescriptor nsDescriptor = getNSDescriptor(context);
if (!(nsDescriptor instanceof XmlNSTypeDescriptorProvider)) return null;
TypeDescriptor type = ((XmlNSTypeDescriptorProvider) nsDescriptor).getTypeDescriptor(myDescriptorTag);
if (type == null) {
String substAttr = myDescriptorTag.getAttributeValue("substitutionGroup");
if (substAttr != null) {
final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(substAttr);
final String namespace = namespacePrefix.isEmpty() ?
getDefaultNamespace() :
myDescriptorTag.getNamespaceByPrefix(namespacePrefix);
final String local = XmlUtil.findLocalNameByQualifiedName(substAttr);
final XmlElementDescriptorImpl originalElement = (XmlElementDescriptorImpl)((XmlNSDescriptorImpl)getNSDescriptor()).getElementDescriptor(local, namespace);
if (originalElement != null && originalElement != this) {
type = originalElement.getType(context);
}
}
}
return type;
}
示例10: getElementDescriptor
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
@Override
public XmlElementDescriptor getElementDescriptor(XmlTag element, XmlTag contextTag){
final XmlElement context = (XmlElement)element.getParent();
XmlElementDescriptor elementDescriptor = getElementDescriptor(
element.getLocalName(),
element.getNamespace(), context,
element.getName()
);
if(elementDescriptor == null || element.getAttributeValue("xsi:type") != null){
final XmlElementDescriptor xmlDescriptorByType = XmlUtil.findXmlDescriptorByType(element);
if (xmlDescriptorByType != null) elementDescriptor = xmlDescriptorByType;
else if (context instanceof XmlTag && ((XmlTag)context).getAttributeValue("xsi:type") != null && askParentDescriptorViaXsi()) {
final XmlElementDescriptor parentXmlDescriptorByType = XmlUtil.findXmlDescriptorByType(((XmlTag)context));
if (parentXmlDescriptorByType != null) {
elementDescriptor = parentXmlDescriptorByType.getElementDescriptor(element, contextTag);
}
}
}
return elementDescriptor;
}
示例11: findSpecialTag
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private static @Nullable XmlTag findSpecialTag(@NonNls String name, @NonNls String specialName, XmlTag rootTag, XmlNSDescriptorImpl descriptor,
HashSet<XmlTag> visited) {
XmlNSDescriptorImpl nsDescriptor = getNSDescriptorToSearchIn(rootTag, name, descriptor);
if (nsDescriptor != descriptor) {
final XmlDocument document = nsDescriptor.getDescriptorFile() != null ? nsDescriptor.getDescriptorFile().getDocument():null;
if (document == null) return null;
return findSpecialTag(
XmlUtil.findLocalNameByQualifiedName(name),
specialName,
document.getRootTag(),
nsDescriptor,
visited
);
}
if (visited == null) visited = new HashSet<XmlTag>(1);
else if (visited.contains(rootTag)) return null;
visited.add(rootTag);
XmlTag[] tags = rootTag.getSubTags();
return findSpecialTagIn(tags, specialName, name, rootTag, descriptor, visited);
}
示例12: getRedefinedElementDescriptorFile
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
public static XmlFile getRedefinedElementDescriptorFile(final XmlTag parentTag) {
final String schemaL = parentTag.getAttributeValue(XmlUtil.SCHEMA_LOCATION_ATT);
if (schemaL != null) {
final PsiReference[] references = parentTag.getAttribute(XmlUtil.SCHEMA_LOCATION_ATT, null).getValueElement().getReferences();
if (references.length > 0) {
final PsiElement psiElement = references[references.length - 1].resolve();
if (psiElement instanceof XmlFile) {
return ((XmlFile)psiElement);
}
}
}
return null;
}
示例13: isLanguageRelevant
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private static boolean isLanguageRelevant(final PsiElement element,
final PsiFile file,
final Ref<Boolean> isRelevantLanguage,
final Ref<Boolean> isAnt) {
Boolean isAntFile = isAnt.get();
if (isAntFile == null) {
isAntFile = XmlUtil.isAntFile(file);
isAnt.set(isAntFile);
}
Boolean result = isRelevantLanguage.get();
if (result == null) {
Language language = element.getLanguage();
PsiElement parent = element.getParent();
if (element instanceof PsiWhiteSpace && parent != null) {
language = parent.getLanguage();
}
result = language instanceof XMLLanguage || HtmlUtil.supportsXmlTypedHandlers(file) || isAntFile.booleanValue();
isRelevantLanguage.set(result);
}
return result.booleanValue();
}
示例14: createAndPutTypesCachedValue
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private CachedValue<TypeDescriptor> createAndPutTypesCachedValue(final XmlTag tag, final Pair<QNameKey, XmlTag> pair) {
final CachedValue<TypeDescriptor> value = CachedValuesManager.getManager(tag.getProject()).createCachedValue(
new CachedValueProvider<TypeDescriptor>() {
@Override
public CachedValueProvider.Result<TypeDescriptor> compute() {
final String name = tag.getAttributeValue("name");
if (name != null &&
pair.first != null &&
pair.first.first != null &&
!name.equals(XmlUtil.findLocalNameByQualifiedName(pair.first.first))
) {
myTypesMap.remove(pair);
return new Result<TypeDescriptor>(null, PsiModificationTracker.MODIFICATION_COUNT);
}
final ComplexTypeDescriptor complexTypeDescriptor = new ComplexTypeDescriptor(XmlNSDescriptorImpl.this, tag);
return new Result<TypeDescriptor>(complexTypeDescriptor, tag);
}
}, false);
myTypesMap.put(pair, value);
return value;
}
示例15: processEnumeration
import com.intellij.xml.util.XmlUtil; //导入依赖的package包/类
private boolean processEnumeration(XmlElement context, PairProcessor<PsiElement, String> processor, boolean forCompletion) {
XmlTag contextTag = context != null ? PsiTreeUtil.getContextOfType(context, XmlTag.class, false) : null;
final XmlElementDescriptorImpl elementDescriptor = (XmlElementDescriptorImpl)XmlUtil.findXmlDescriptorByType(getDeclaration(), contextTag);
if (elementDescriptor!=null && elementDescriptor.getType() instanceof ComplexTypeDescriptor) {
return processEnumerationImpl(((ComplexTypeDescriptor)elementDescriptor.getType()).getDeclaration(), processor, forCompletion);
}
final String namespacePrefix = getDeclaration().getNamespacePrefix();
XmlTag type = getDeclaration().findFirstSubTag(
((namespacePrefix.length() > 0) ? namespacePrefix + ":" : "") + "simpleType"
);
if (type != null) {
return processEnumerationImpl(type, processor, forCompletion);
}
return false;
}