Java 类com.intellij.psi.impl.source.xml.TagNameVariantCollector 实例源码

项目:tools-idea    文件:DefaultXmlExtension.java   
@NotNull
public List<TagInfo> getAvailableTagNames(@NotNull final XmlFile file, @NotNull final XmlTag context) {

  final Set<String> namespaces = new HashSet<String>(Arrays.asList(context.knownNamespaces()));
  final List<XmlSchemaProvider> providers = XmlSchemaProvider.getAvailableProviders(file);
  for (XmlSchemaProvider provider : providers) {
    namespaces.addAll(provider.getAvailableNamespaces(file, null));
  }
  List<String> nsInfo = new ArrayList<String>();
  List<XmlElementDescriptor> descriptors = TagNameVariantCollector.getTagDescriptors(context, namespaces, nsInfo);
  final List<TagInfo> set = new ArrayList<TagInfo>();
  for (int i = 0; i < descriptors.size(); i++) {
    final XmlElementDescriptor descriptor = descriptors.get(i);
    String qualifiedName = descriptor.getName(context);
    final int pos = qualifiedName.indexOf(':');
    final String name = pos >= 0 ? qualifiedName.substring(pos + 1) : qualifiedName;
    set.add(new TagInfo(name, nsInfo.get(i)) {
      @Nullable
      @Override
      public PsiElement getDeclaration() {
        return descriptor.getDeclaration();
      }
    });
  }
  return set;
}
项目:intellij-ce-playground    文件:DefaultXmlExtension.java   
@Override
@NotNull
public List<TagInfo> getAvailableTagNames(@NotNull final XmlFile file, @NotNull final XmlTag context) {

  final Set<String> namespaces = new HashSet<String>(Arrays.asList(context.knownNamespaces()));
  final List<XmlSchemaProvider> providers = XmlSchemaProvider.getAvailableProviders(file);
  for (XmlSchemaProvider provider : providers) {
    namespaces.addAll(provider.getAvailableNamespaces(file, null));
  }
  List<String> nsInfo = new ArrayList<String>();
  List<XmlElementDescriptor> descriptors = TagNameVariantCollector.getTagDescriptors(context, namespaces, nsInfo);
  final List<TagInfo> set = new ArrayList<TagInfo>();
  for (int i = 0; i < descriptors.size(); i++) {
    final XmlElementDescriptor descriptor = descriptors.get(i);
    String qualifiedName = descriptor.getName(context);
    LOG.assertTrue(qualifiedName != null, descriptor + " returned null name");
    final int pos = qualifiedName.indexOf(':');
    final String name = pos >= 0 ? qualifiedName.substring(pos + 1) : qualifiedName;
    set.add(new TagInfo(name, nsInfo.get(i)) {
      @Nullable
      @Override
      public PsiElement getDeclaration() {
        return descriptor.getDeclaration();
      }
    });
  }
  return set;
}
项目:intellij-ce-playground    文件:XmlMover.java   
private static boolean moveTags(MoveInfo info, XmlTag moved, XmlTag target, boolean down) {
  if (target.getParent() == moved) {
    // we are going to jump into our own children
    // this can mean that target computed incorrectly
    XmlTag next = down ? PsiTreeUtil.getNextSiblingOfType(moved, XmlTag.class) :
                         PsiTreeUtil.getPrevSiblingOfType(moved, XmlTag.class);
    if (next == null) return info.prohibitMove();
    info.toMove = new LineRange(moved);
    info.toMove2 = new LineRange(next);
    return true;
  }
  else if (moved.getParent() == target) {
    return false;
  }

  LineRange targetRange = new LineRange(target);
  if (targetRange.contains(info.toMove2)) {
    // we are going to jump into sibling tag
    XmlElementDescriptor descriptor = moved.getDescriptor();
    if (descriptor == null) return false;
    XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
    if (nsDescriptor == null) return false;
    XmlFile descriptorFile = nsDescriptor.getDescriptorFile();
    if (descriptorFile == null || XmlDocumentImpl.isAutoGeneratedSchema(descriptorFile)) return false;
    if (!TagNameVariantCollector.couldContain(target, moved)) {
      info.toMove = new LineRange(moved);
      info.toMove2 = targetRange;
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:JavaFxCompletionContributor.java   
private static void addJavaFxTagVariants(JavaFxTagNameReference reference, CompletionResultSet result) {
  final XmlTag xmlTag = (XmlTag)reference.getElement();

  List<String> namespaces = Arrays.asList(xmlTag.knownNamespaces());
  final List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(xmlTag, namespaces, null);
  for (XmlElementDescriptor descriptor : variants) {
    final String descriptorName = descriptor.getName(reference.getElement());
    if (descriptorName != null) {
      LookupElementBuilder lookupElement = LookupElementBuilder.create(descriptor, descriptorName);
      result.addElement(lookupElement.withInsertHandler(JavaFxTagInsertHandler.INSTANCE));
    }
  }
}
项目:tools-idea    文件:XmlMover.java   
private static boolean moveTags(MoveInfo info, XmlTag moved, XmlTag target, boolean down) {
  if (target.getParent() == moved) {
    // we are going to jump into our own children
    // this can mean that target computed incorrectly
    XmlTag next = down ? PsiTreeUtil.getNextSiblingOfType(moved, XmlTag.class) :
                         PsiTreeUtil.getPrevSiblingOfType(moved, XmlTag.class);
    if (next == null) return info.prohibitMove();
    info.toMove = new LineRange(moved);
    info.toMove2 = new LineRange(next);
    return true;
  }
  else if (moved.getParent() == target) {
    return false;
  }

  LineRange targetRange = new LineRange(target);
  if (targetRange.contains(info.toMove2)) {
    // we are going to jump into sibling tag
    XmlElementDescriptor descriptor = moved.getDescriptor();
    if (descriptor == null) return false;
    XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
    if (nsDescriptor == null) return false;
    XmlFile descriptorFile = nsDescriptor.getDescriptorFile();
    if (descriptorFile == null || XmlDocumentImpl.isAutoGeneratedSchema(descriptorFile)) return false;
    if (!TagNameVariantCollector.couldContain(target, moved)) {
      info.toMove = new LineRange(moved);
      info.toMove2 = targetRange;
      return true;
    }
  }

  return false;
}
项目:tools-idea    文件:JavaFxCompletionContributor.java   
private static void addJavaFxTagVariants(JavaFxTagNameReference reference, CompletionResultSet result) {
  final XmlTag xmlTag = (XmlTag)reference.getElement();

  List<String> namespaces = Arrays.asList(xmlTag.knownNamespaces());
  final List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(xmlTag, namespaces, null);
  for (XmlElementDescriptor descriptor : variants) {
    final String descriptorName = descriptor.getName(reference.getElement());
    if (descriptorName != null) {
      LookupElementBuilder lookupElement = LookupElementBuilder.create(descriptor, descriptorName);
      result.addElement(lookupElement.withInsertHandler(JavaFxTagInsertHandler.INSTANCE));
    }
  }
}
项目:consulo-javafx    文件:JavaFxCompletionContributor.java   
private static void addJavaFxTagVariants(JavaFxTagNameReference reference, CompletionResultSet result) {
  final XmlTag xmlTag = (XmlTag)reference.getElement();

  List<String> namespaces = Arrays.asList(xmlTag.knownNamespaces());
  final List<XmlElementDescriptor> variants = TagNameVariantCollector.getTagDescriptors(xmlTag, namespaces, null);
  for (XmlElementDescriptor descriptor : variants) {
    final String descriptorName = descriptor.getName(reference.getElement());
    if (descriptorName != null) {
      LookupElementBuilder lookupElement = LookupElementBuilder.create(descriptor, descriptorName);
      result.addElement(lookupElement.withInsertHandler(JavaFxTagInsertHandler.INSTANCE));
    }
  }
}
项目:consulo-xml    文件:DefaultXmlExtension.java   
@Override
@NotNull
public List<TagInfo> getAvailableTagNames(@NotNull final XmlFile file, @NotNull final XmlTag context)
{

    final Set<String> namespaces = new HashSet<>(Arrays.asList(context.knownNamespaces()));
    final List<XmlSchemaProvider> providers = XmlSchemaProvider.getAvailableProviders(file);
    for(XmlSchemaProvider provider : providers)
    {
        namespaces.addAll(provider.getAvailableNamespaces(file, null));
    }
    List<String> nsInfo = new ArrayList<>();
    List<XmlElementDescriptor> descriptors = TagNameVariantCollector.getTagDescriptors(context, namespaces, nsInfo);
    final List<TagInfo> set = new ArrayList<>();
    for(int i = 0; i < descriptors.size(); i++)
    {
        final XmlElementDescriptor descriptor = descriptors.get(i);
        String qualifiedName = descriptor.getName(context);
        LOG.assertTrue(qualifiedName != null, descriptor + " returned null name");
        final int pos = qualifiedName.indexOf(':');
        final String name = pos >= 0 ? qualifiedName.substring(pos + 1) : qualifiedName;
        set.add(new TagInfo(name, nsInfo.get(i))
        {
            @Nullable
            @Override
            public PsiElement getDeclaration()
            {
                return descriptor.getDeclaration();
            }
        });
    }
    return set;
}
项目:consulo-xml    文件:XmlMover.java   
private static boolean moveTags(MoveInfo info, XmlTag moved, XmlTag target, boolean down) {
  if (target.getParent() == moved) {
    // we are going to jump into our own children
    // this can mean that target computed incorrectly
    XmlTag next = down ? PsiTreeUtil.getNextSiblingOfType(moved, XmlTag.class) :
                  PsiTreeUtil.getPrevSiblingOfType(moved, XmlTag.class);
    if (next == null) return info.prohibitMove();
    info.toMove = new LineRange(moved);
    info.toMove2 = new LineRange(next);
    return true;
  }
  else if (moved.getParent() == target) {
    return false;
  }

  LineRange targetRange = new LineRange(target);
  if (targetRange.contains(info.toMove2)) {
    // we are going to jump into sibling tag
    XmlElementDescriptor descriptor = moved.getDescriptor();
    if (descriptor == null) return false;
    XmlNSDescriptor nsDescriptor = descriptor.getNSDescriptor();
    if (nsDescriptor == null) return false;
    XmlFile descriptorFile = nsDescriptor.getDescriptorFile();
    if (descriptorFile == null || XmlDocumentImpl.isAutoGeneratedSchema(descriptorFile)) return false;
    if (!TagNameVariantCollector.couldContain(target, moved)) {
      info.toMove = new LineRange(moved);
      info.toMove2 = targetRange;
      return true;
    }
  }

  return false;
}