コード例 #1
0
 @Nonnull
 private CSSSupportsRule _createSupportsRule(@Nonnull final CSSNode aNode) {
   _expectNodeType(aNode, ECSSNodeType.SUPPORTSRULE);
   final CSSSupportsRule ret = new CSSSupportsRule();
   ret.setSourceLocation(aNode.getSourceLocation());
   for (final CSSNode aChildNode : aNode) {
     if (ECSSNodeType.SUPPORTSCONDITION.isNode(aChildNode, m_eVersion)) {
       for (final CSSNode aChildChildNode : aChildNode) {
         final ICSSSupportsConditionMember aMember =
             _createSupportsConditionMemberRecursive(aChildChildNode);
         if (aMember != null) ret.addSupportConditionMember(aMember);
       }
     } else if (ECSSNodeType.STYLERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createStyleRule(aChildNode));
     else if (ECSSNodeType.MEDIARULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createMediaRule(aChildNode));
     else if (ECSSNodeType.PAGERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createPageRule(aChildNode));
     else if (ECSSNodeType.FONTFACERULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createFontFaceRule(aChildNode));
     else if (ECSSNodeType.KEYFRAMESRULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createKeyframesRule(aChildNode));
     else if (ECSSNodeType.VIEWPORTRULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createViewportRule(aChildNode));
     else if (ECSSNodeType.SUPPORTSRULE.isNode(aChildNode, m_eVersion))
       ret.addRule(_createSupportsRule(aChildNode));
     else if (!ECSSNodeType.isErrorNode(aChildNode, m_eVersion))
       s_aLogger.error(
           "Unsupported supports-rule child: " + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
   }
   return ret;
 }
コード例 #2
0
  @Nullable
  private ICSSSupportsConditionMember _createSupportsConditionMemberRecursive(
      @Nonnull final CSSNode aNode) {
    final int nChildCount = aNode.jjtGetNumChildren();

    if (ECSSNodeType.SUPPORTSCONDITIONOPERATOR.isNode(aNode, m_eVersion)) {
      if (nChildCount != 0)
        _throwUnexpectedChildrenCount(aNode, "Expected no children but got " + nChildCount + "!");

      return ECSSSupportsConditionOperator.getFromNameCaseInsensitiveOrNull(aNode.getText());
    }

    if (ECSSNodeType.SUPPORTSNEGATION.isNode(aNode, m_eVersion)) {
      if (nChildCount != 1)
        _throwUnexpectedChildrenCount(
            aNode, "Expected at exactly 1 child but got " + nChildCount + "!");

      final ICSSSupportsConditionMember aNestedMember =
          _createSupportsConditionMemberRecursive(aNode.jjtGetChild(0));
      if (aNestedMember == null) return null;

      final CSSSupportsConditionNegation ret = new CSSSupportsConditionNegation(aNestedMember);
      ret.setSourceLocation(aNode.getSourceLocation());
      return ret;
    }

    if (ECSSNodeType.SUPPORTSCONDITIONINPARENS.isNode(aNode, m_eVersion)) {
      if (nChildCount != 1)
        _throwUnexpectedChildrenCount(
            aNode, "Expected at exactly 1 child but got " + nChildCount + "!");

      final CSSNode aChildNode = aNode.jjtGetChild(0);

      if (ECSSNodeType.STYLEDECLARATION.isNode(aChildNode, m_eVersion)) {
        final CSSDeclaration aDeclaration = _createDeclaration(aChildNode);
        if (aDeclaration == null)
          throw new CSSHandlingException(
              aChildNode, "The style declaration in the @supports rule is invalid!");
        final CSSSupportsConditionDeclaration ret =
            new CSSSupportsConditionDeclaration(aDeclaration);
        ret.setSourceLocation(aNode.getSourceLocation());
        return ret;
      }

      if (ECSSNodeType.SUPPORTSCONDITION.isNode(aChildNode, m_eVersion)) {
        final CSSSupportsConditionNested ret = new CSSSupportsConditionNested();
        for (final CSSNode aChildChildNode : aChildNode) {
          final ICSSSupportsConditionMember aMember =
              _createSupportsConditionMemberRecursive(aChildChildNode);
          if (aMember != null) ret.addMember(aMember);
        }
        return ret;
      }

      s_aLogger.error(
          "Unsupported supportsConditionInParents child: "
              + ECSSNodeType.getNodeName(aChildNode, m_eVersion));
      return null;
    }

    if (!ECSSNodeType.isErrorNode(aNode, m_eVersion))
      s_aLogger.error(
          "Unsupported supports-condition child: " + ECSSNodeType.getNodeName(aNode, m_eVersion));

    return null;
  }