当前位置: 首页>>代码示例>>Java>>正文


Java NamespaceAwareXmlAttributeDescriptor类代码示例

本文整理汇总了Java中com.intellij.xml.NamespaceAwareXmlAttributeDescriptor的典型用法代码示例。如果您正苦于以下问题:Java NamespaceAwareXmlAttributeDescriptor类的具体用法?Java NamespaceAwareXmlAttributeDescriptor怎么用?Java NamespaceAwareXmlAttributeDescriptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


NamespaceAwareXmlAttributeDescriptor类属于com.intellij.xml包,在下文中一共展示了NamespaceAwareXmlAttributeDescriptor类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addVariants

import com.intellij.xml.NamespaceAwareXmlAttributeDescriptor; //导入依赖的package包/类
private static void addVariants(final CompletionResultSet result,
                                final XmlAttribute[] attributes,
                                final XmlAttributeDescriptor[] descriptors,
                                XmlAttribute attribute,
                                @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
  final XmlTag tag = attribute.getParent();
  final PsiFile file = tag.getContainingFile();
  final XmlExtension extension = XmlExtension.getExtension(file);
  final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0
                        ? attribute.getNamespacePrefix() + ":"
                        : null;

  CompletionData
    completionData = CompletionUtil.getCompletionDataByElement(attribute, attribute.getContainingFile().getOriginalFile());
  boolean caseSensitive = !(completionData instanceof HtmlCompletionData) || ((HtmlCompletionData)completionData).isCaseSensitive();

  for (XmlAttributeDescriptor descriptor : descriptors) {
    if (isValidVariant(attribute, descriptor, attributes, extension)) {
      String name = descriptor.getName(tag);

      InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

      if (tag instanceof HtmlTag &&
          HtmlUtil.isShortNotationOfBooleanAttributePreferred() &&
          HtmlUtil.isBooleanAttribute(descriptor, tag)) {
        insertHandler = null;
      }

      if (replacementInsertHandler != null) {
        insertHandler = replacementInsertHandler;
      }
      else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
        final String namespace = ((NamespaceAwareXmlAttributeDescriptor)descriptor).getNamespace(tag);

        if (file instanceof XmlFile &&
            namespace != null &&
            namespace.length() > 0 &&
            !name.contains(":") &&
            tag.getPrefixByNamespace(namespace) == null) {
          insertHandler = new XmlAttributeInsertHandler(namespace);
        }
      }
      if (prefix == null || name.startsWith(prefix)) {
        if (prefix != null && name.length() > prefix.length()) {
          name = descriptor.getName(tag).substring(prefix.length());
        }
        LookupElementBuilder element = LookupElementBuilder.create(name);
        if (descriptor instanceof PsiPresentableMetaData) {
          element = element.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
        }
        final int separator = name.indexOf(':');
        if (separator > 0) {
          element = element.withLookupString(name.substring(separator + 1));
        }
        element = element
          .withCaseSensitivity(caseSensitive)
          .withInsertHandler(insertHandler);
        result.addElement(
          descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) :
          HtmlUtil.isOwnHtmlAttribute(descriptor) ? PrioritizedLookupElement.withPriority(element, 50) : element);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:XmlAttributeReferenceCompletionProvider.java

示例2: addVariants

import com.intellij.xml.NamespaceAwareXmlAttributeDescriptor; //导入依赖的package包/类
private static void addVariants(final CompletionResultSet result,
                                final XmlAttribute[] attributes,
                                final XmlAttributeDescriptor[] descriptors,
                                XmlAttribute attribute,
                                @Nullable InsertHandler<LookupElement> replacementInsertHandler) {
  final XmlTag tag = attribute.getParent();
  final PsiFile file = tag.getContainingFile();
  final XmlExtension extension = XmlExtension.getExtension(file);
  final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0
                        ? attribute.getNamespacePrefix() + ":"
                        : null;

  CompletionData
    completionData = CompletionUtil.getCompletionDataByElement(attribute, attribute.getContainingFile().getOriginalFile());
  boolean caseSensitive = !(completionData instanceof HtmlCompletionData) || ((HtmlCompletionData)completionData).isCaseSensitive();

  for (XmlAttributeDescriptor descriptor : descriptors) {
    if (isValidVariant(attribute, descriptor, attributes, extension)) {
      String name = descriptor.getName(tag);

      InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

      if (replacementInsertHandler != null) {
        insertHandler = replacementInsertHandler;
      }
      else if (descriptor instanceof NamespaceAwareXmlAttributeDescriptor) {
        final String namespace = ((NamespaceAwareXmlAttributeDescriptor)descriptor).getNamespace(tag);

        if (file instanceof XmlFile &&
            namespace != null &&
            namespace.length() > 0 &&
            !name.contains(":") &&
            tag.getPrefixByNamespace(namespace) == null) {
          insertHandler = new XmlAttributeInsertHandler(namespace);
        }
      }
      if (prefix == null || name.startsWith(prefix)) {
        if (prefix != null && name.length() > prefix.length()) {
          name = descriptor.getName(tag).substring(prefix.length());
        }
        LookupElementBuilder element = LookupElementBuilder.create(name);
        if (descriptor instanceof PsiPresentableMetaData) {
          element = element.withIcon(((PsiPresentableMetaData)descriptor).getIcon());
        }
        final int separator = name.indexOf(':');
        if (separator > 0) {
          element = element.withLookupString(name.substring(separator + 1));
        }
        element = element
          .withCaseSensitivity(caseSensitive)
          .withInsertHandler(insertHandler);
        result.addElement(
          descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : element);
      }
    }
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:58,代码来源:XmlAttributeReferenceCompletionProvider.java

示例3: addVariants

import com.intellij.xml.NamespaceAwareXmlAttributeDescriptor; //导入依赖的package包/类
private static void addVariants(final CompletionResultSet result,
		final XmlAttribute[] attributes,
		final XmlAttributeDescriptor[] descriptors,
		XmlAttribute attribute,
		@Nullable InsertHandler<LookupElement> replacementInsertHandler)
{
	final XmlTag tag = attribute.getParent();
	final PsiFile file = tag.getContainingFile();
	final XmlExtension extension = XmlExtension.getExtension(file);
	final String prefix = attribute.getName().contains(":") && ((XmlAttributeImpl) attribute).getRealLocalName().length() > 0 ? attribute.getNamespacePrefix() + ":" : null;

	for(XmlAttributeDescriptor descriptor : descriptors)
	{
		if(isValidVariant(attribute, descriptor, attributes, extension))
		{
			String name = descriptor.getName(tag);

			InsertHandler<LookupElement> insertHandler = XmlAttributeInsertHandler.INSTANCE;

			if(tag instanceof HtmlTag && HtmlUtil.isShortNotationOfBooleanAttributePreferred() && HtmlUtil.isBooleanAttribute(descriptor, tag))
			{
				insertHandler = null;
			}

			if(replacementInsertHandler != null)
			{
				insertHandler = replacementInsertHandler;
			}
			else if(descriptor instanceof NamespaceAwareXmlAttributeDescriptor)
			{
				final String namespace = ((NamespaceAwareXmlAttributeDescriptor) descriptor).getNamespace(tag);

				if(file instanceof XmlFile && namespace != null && namespace.length() > 0 && !name.contains(":") && tag.getPrefixByNamespace(namespace) == null)
				{
					insertHandler = new XmlAttributeInsertHandler(namespace);
				}
			}
			if(prefix == null || name.startsWith(prefix))
			{
				if(prefix != null && name.length() > prefix.length())
				{
					name = descriptor.getName(tag).substring(prefix.length());
				}
				LookupElementBuilder element = LookupElementBuilder.create(name);
				if(descriptor instanceof PsiPresentableMetaData)
				{
					element = element.withIcon(((PsiPresentableMetaData) descriptor).getIcon());
				}
				final int separator = name.indexOf(':');
				if(separator > 0)
				{
					element = element.withLookupString(name.substring(separator + 1));
				}
				element = element.withCaseSensitivity(!(descriptor instanceof HtmlAttributeDescriptorImpl)).withInsertHandler(insertHandler);
				result.addElement(descriptor.isRequired() ? PrioritizedLookupElement.withPriority(element.appendTailText("(required)", true), 100) : HtmlUtil.isOwnHtmlAttribute(descriptor) ?
						PrioritizedLookupElement.withPriority(element, 50) : element);
			}
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-xml,代码行数:61,代码来源:XmlAttributeReferenceCompletionProvider.java


注:本文中的com.intellij.xml.NamespaceAwareXmlAttributeDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。