Exemplo n.º 1
0
 public PomModelEvent runInner() throws IncorrectOperationException {
   final ASTNode anchor = expandTag();
   if (myChild.getElementType() == XmlElementType.XML_TAG) {
     // compute where to insert tag according to DTD or XSD
     final XmlElementDescriptor parentDescriptor = getDescriptor();
     final XmlTag[] subTags = getSubTags();
     final PsiElement declaration =
         parentDescriptor != null ? parentDescriptor.getDeclaration() : null;
     // filtring out generated dtds
     if (declaration != null
         && declaration.getContainingFile() != null
         && declaration.getContainingFile().isPhysical()
         && subTags.length > 0) {
       final XmlElementDescriptor[] childElementDescriptors =
           parentDescriptor.getElementsDescriptors(XmlTagImpl.this);
       int subTagNum = -1;
       for (final XmlElementDescriptor childElementDescriptor : childElementDescriptors) {
         final String childElementName = childElementDescriptor.getName();
         while (subTagNum < subTags.length - 1
             && subTags[subTagNum + 1].getName().equals(childElementName)) {
           subTagNum++;
         }
         if (childElementName.equals(
             XmlChildRole.START_TAG_NAME_FINDER.findChild(myChild).getText())) {
           // insert child just after anchor
           // insert into the position specified by index
           if (subTagNum >= 0) {
             final ASTNode subTag = (ASTNode) subTags[subTagNum];
             if (subTag.getTreeParent() != XmlTagImpl.this) {
               // in entity
               final XmlEntityRef entityRef =
                   PsiTreeUtil.getParentOfType(subTags[subTagNum], XmlEntityRef.class);
               throw new IncorrectOperationException(
                   "Can't insert subtag to the entity. Entity reference text: "
                       + (entityRef == null ? "" : entityRef.getText()));
             }
             myNewElement =
                 XmlTagImpl.super.addInternal(myChild, myChild, subTag, Boolean.FALSE);
           } else {
             final ASTNode child = XmlChildRole.START_TAG_END_FINDER.findChild(XmlTagImpl.this);
             myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, child, Boolean.FALSE);
           }
           return null;
         }
       }
     } else {
       final ASTNode child = XmlChildRole.CLOSING_TAG_START_FINDER.findChild(XmlTagImpl.this);
       myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, child, Boolean.TRUE);
       return null;
     }
   }
   myNewElement = XmlTagImpl.super.addInternal(myChild, myChild, anchor, Boolean.TRUE);
   return null;
 }
  public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
    final XmlAttributeDescriptor descriptor =
        myDelegate.getAttributeDescriptor(attributeName.toLowerCase(), context);
    if (descriptor != null) return descriptor;

    return RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(
        attributeName, context);
  }
Exemplo n.º 3
0
  @Nullable
  protected XmlElementDescriptor computeElementDescriptor() {
    for (XmlElementDescriptorProvider provider :
        Extensions.getExtensions(XmlElementDescriptorProvider.EP_NAME)) {
      XmlElementDescriptor elementDescriptor = provider.getDescriptor(this);
      if (elementDescriptor != null) {
        return elementDescriptor;
      }
    }

    final String namespace = getNamespace();
    if (XmlUtil.EMPTY_URI.equals(namespace)) { // nonqualified items
      final XmlTag parent = getParentTag();
      if (parent != null) {
        final XmlElementDescriptor descriptor = parent.getDescriptor();
        if (descriptor != null) {
          XmlElementDescriptor fromParent = descriptor.getElementDescriptor(this, parent);
          if (fromParent != null && !(fromParent instanceof AnyXmlElementDescriptor)) {
            return fromParent;
          }
        }
      }
    }

    XmlElementDescriptor elementDescriptor = null;
    final XmlNSDescriptor nsDescriptor = getNSDescriptor(namespace, false);

    LOG.debug(
        "Descriptor for namespace "
            + namespace
            + " is "
            + (nsDescriptor != null ? nsDescriptor.getClass().getCanonicalName() : "NULL"));

    if (nsDescriptor != null) {
      if (!DumbService.getInstance(getProject()).isDumb()
          || DumbService.isDumbAware(nsDescriptor)) {
        elementDescriptor = nsDescriptor.getElementDescriptor(this);
      }
    }
    if (elementDescriptor == null) {
      return XmlUtil.findXmlDescriptorByType(this);
    }

    return elementDescriptor;
  }
  public XmlElementDescriptor getElementDescriptor(XmlTag childTag, XmlTag contextTag) {
    XmlElementDescriptor elementDescriptor = myDelegate.getElementDescriptor(childTag, contextTag);

    if (elementDescriptor == null) {
      return RelaxedHtmlFromSchemaElementDescriptor.getRelaxedDescriptor(this, childTag);
    }

    return elementDescriptor;
  }
 private Map<String, XmlElementDescriptor> configure(String... files) {
   myFixture.configureByFiles(files);
   XmlTag tag = ((XmlFile) getFile()).getRootTag();
   assertNotNull(tag);
   XmlElementDescriptor descriptor = tag.getDescriptor();
   assertNotNull(descriptor);
   XmlElementDescriptor[] descriptors = descriptor.getElementsDescriptors(tag);
   Map<String, XmlElementDescriptor> map =
       ContainerUtil.assignKeys(
           Arrays.asList(descriptors).iterator(),
           new Convertor<XmlElementDescriptor, String>() {
             @Override
             public String convert(XmlElementDescriptor o) {
               return o.getName();
             }
           });
   map.put(tag.getName(), tag.getDescriptor());
   return map;
 }
 public XmlAttributeDescriptor[] getAttributesDescriptors(final XmlTag context) {
   return RelaxedHtmlFromSchemaElementDescriptor.addAttrDescriptorsForFacelets(
       context, myDelegate.getAttributesDescriptors(context));
 }
 @Override
 public String getName(PsiElement context) {
   return myDelegate.getName(context);
 }
 public void testXsdConstraints() throws Exception {
   Map<String, XmlElementDescriptor> map = configure("test.xml", "test.xsd");
   XmlElementDescriptor a = map.get("a");
   XmlElementsGroup topGroup = a.getTopGroup();
 }
 @Override
 public void init(PsiElement element) {
   myDelegate.init(element);
 }
 @Override
 public PsiElement getDeclaration() {
   return myDelegate.getDeclaration();
 }
 @Override
 public XmlElementsGroup getTopGroup() {
   return myDelegate.getTopGroup();
 }
 @Override
 public int getContentType() {
   return myDelegate.getContentType();
 }
 @Override
 public XmlNSDescriptor getNSDescriptor() {
   return myDelegate.getNSDescriptor();
 }
 @Override
 public Object[] getDependences() {
   return myDelegate.getDependences();
 }
 public XmlElementDescriptor[] getElementsDescriptors(final XmlTag context) {
   return ArrayUtil.mergeArrays(
       myDelegate.getElementsDescriptors(context), HtmlUtil.getCustomTagDescriptors(context));
 }
 @Override
 public String getDefaultName() {
   return myDelegate.getDefaultName();
 }
 @Override
 public String getQualifiedName() {
   return myDelegate.getQualifiedName();
 }