@Override
 public void visitXmlTag(XmlTag tag) {
   super.visitXmlTag(tag);
   final XmlElementDescriptor descriptor = tag.getDescriptor();
   if (descriptor instanceof JavaFxClassTagDescriptorBase) {
     appendClassName(descriptor.getDeclaration());
   } else if (descriptor instanceof JavaFxPropertyTagDescriptor
       && ((JavaFxPropertyTagDescriptor) descriptor).isStatic()) {
     final PsiElement declaration = descriptor.getDeclaration();
     if (declaration instanceof PsiMember) {
       appendClassName(((PsiMember) declaration).getContainingClass());
     }
   }
 }
 private static boolean isCollection(XmlElementDescriptor each) {
   XmlTag declaration = (XmlTag) each.getDeclaration();
   if (declaration != null) {
     XmlTag complexType = declaration.findFirstSubTag("xs:complexType");
     if (complexType != null) {
       if (complexType.findFirstSubTag("xs:sequence") != null) return true;
     }
   }
   return false;
 }
Пример #3
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 PsiElement getDeclaration() {
   return myDelegate.getDeclaration();
 }
  @Nullable
  public XmlElementDescriptor getElementDescriptor(
      String localName, String namespace, Set<XmlNSDescriptorImpl> visited, boolean reference) {
    if (visited.contains(this)) return null;

    final QNameKey pair = new QNameKey(namespace, localName);
    final CachedValue<XmlElementDescriptor> descriptor = myDescriptorsMap.get(pair);
    if (descriptor != null) {
      final XmlElementDescriptor value = descriptor.getValue();
      if (value == null || value.getDeclaration().isValid()) return value;
    }

    final XmlTag rootTag = myTag;
    if (rootTag == null) return null;
    XmlTag[] tags = rootTag.getSubTags();
    visited.add(this);

    for (final XmlTag tag : tags) {
      if (equalsToSchemaName(tag, ELEMENT_TAG_NAME)) {
        String name = tag.getAttributeValue("name");

        if (name != null) {
          if (checkElementNameEquivalence(localName, namespace, name, tag)) {
            final CachedValue<XmlElementDescriptor> cachedValue =
                CachedValuesManager.getManager(tag.getProject())
                    .createCachedValue(
                        new CachedValueProvider<XmlElementDescriptor>() {
                          public Result<XmlElementDescriptor> compute() {
                            final String name = tag.getAttributeValue("name");

                            if (name != null && !name.equals(pair.second)) {
                              myDescriptorsMap.remove(pair);
                              return new Result<XmlElementDescriptor>(null);
                            }
                            final XmlElementDescriptor xmlElementDescriptor =
                                createElementDescriptor(tag);
                            return new Result<XmlElementDescriptor>(
                                xmlElementDescriptor, xmlElementDescriptor.getDependences());
                          }
                        },
                        false);
            myDescriptorsMap.put(pair, cachedValue);
            return cachedValue.getValue();
          }
        }
      } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME)
          || (reference
              && equalsToSchemaName(tag, IMPORT_TAG_NAME)
              && (namespace.equals(tag.getAttributeValue("namespace"))
                  || namespace.length() == 0 && tag.getAttributeValue("namespace") == null))) {
        final XmlAttribute schemaLocation = tag.getAttribute("schemaLocation", null);
        if (schemaLocation != null) {
          final XmlFile xmlFile =
              XmlUtil.findNamespaceByLocation(
                  rootTag.getContainingFile(), schemaLocation.getValue());
          if (xmlFile != null) {
            final XmlDocument includedDocument = xmlFile.getDocument();
            if (includedDocument != null) {
              final PsiMetaData data = includedDocument.getMetaData();
              if (data instanceof XmlNSDescriptorImpl) {
                final XmlElementDescriptor elementDescriptor =
                    ((XmlNSDescriptorImpl) data)
                        .getElementDescriptor(localName, namespace, visited, reference);
                if (elementDescriptor != null) {
                  // final CachedValue<XmlElementDescriptor> value =
                  // includedDocument.getManager().getCachedValuesManager()
                  //  .createCachedValue(new CachedValueProvider<XmlElementDescriptor>() {
                  //    public Result<XmlElementDescriptor> compute() {
                  //      return new Result<XmlElementDescriptor>(elementDescriptor,
                  // elementDescriptor.getDependences());
                  //    }
                  //  }, false);
                  // return value.getValue();
                  return elementDescriptor;
                }
              }
            }
          }
        }
      } else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
        final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
        if (nsDescriptor != null) {
          final XmlElementDescriptor xmlElementDescriptor =
              nsDescriptor.getElementDescriptor(localName, namespace, visited, reference);
          if (xmlElementDescriptor != null) return xmlElementDescriptor;
        }
      }
    }

    return null;
  }