Examples of Cardinality


Examples of org.intellij.grammar.generator.RuleGraphHelper.Cardinality

        else if (Rule.isPrivate(metaRule)) {
          result = psiMap();
          Map<PsiElement, Cardinality> metaResults = getPrivateRuleContent(metaRule, visited);
          List<String> params = null;
          for (PsiElement member : metaResults.keySet()) {
            Cardinality cardinality = metaResults.get(member);
            if (!(member instanceof BnfExternalExpression)) {
              result.put(member, cardinality);
            }
            else {
              if (params == null) {
                params = collectExtraArguments(metaRule, metaRule.getExpression());
              }
              int idx = params.indexOf(member.getText());
              if (idx > -1 && idx + 1 < expressionList.size()) {
                Map<PsiElement, Cardinality> argMap = collectMembers(rule, expressionList.get(idx + 1), visited);
                for (PsiElement element : argMap.keySet()) {
                  result.put(element, cardinality.and(argMap.get(element)));
                }
              }
            }
          }
        }
        else {
          result = psiMap(metaRule, REQUIRED);
        }
      }
      if (firstNonTrivial && willCollapse(rule, result) && !Rule.isPrivate(rule)) {
        result = Collections.emptyMap();
      }
    }
    else {
      List<BnfExpression> pinned = ContainerUtil.newArrayList();
      GrammarUtil.processPinnedExpressions(rule, new CommonProcessors.CollectProcessor<BnfExpression>(pinned));
      boolean pinApplied = false;

      IElementType type = getEffectiveType(tree);

      List<Map<PsiElement, Cardinality>> list = new ArrayList<Map<PsiElement, Cardinality>>();
      List<BnfExpression> childExpressions = getChildExpressions(tree);
      for (BnfExpression child : childExpressions) {
        Map<PsiElement, Cardinality> nextMap = collectMembers(rule, child, visited);
        if (pinApplied) {
          nextMap = joinMaps(rule, false, BnfTypes.BNF_OP_OPT, Collections.singletonList(nextMap));
        }
        list.add(nextMap);
        if (!pinApplied && pinned.contains(child)) {
          pinApplied = true;
        }
      }
      result = joinMaps(rule, firstNonTrivial, type, list);
      result = result.remove(rule.getExpression()) != null ? joinMaps(rule, false, type, Arrays.asList(result, result)) : result;
    }
    if (rule.getExpression() == tree && Rule.isLeft(rule) && !Rule.isPrivate(rule) && !Rule.isInner(rule)) {
      List<Map<PsiElement, Cardinality>> list = new ArrayList<Map<PsiElement, Cardinality>>();
      Map<BnfRule, Cardinality> rulesToTheLeft = getRulesToTheLeft(rule);
      for (BnfRule r : rulesToTheLeft.keySet()) {
        Cardinality cardinality = rulesToTheLeft.get(r);
        Map<PsiElement, Cardinality> leftMap = psiMap(r, REQUIRED);
        if (cardinality.many()) {
          list.add(joinMaps(rule, false, BnfTypes.BNF_CHOICE, Arrays.asList(leftMap, psiMap(rule, REQUIRED))));
        }
        else {
          list.add(leftMap);
        }
View Full Code Here

Examples of org.intellij.grammar.generator.RuleGraphHelper.Cardinality

    for (BnfExpression e : nextMap.keySet()) {
      if (!(e instanceof BnfReferenceOrToken)) continue;
      BnfRule r = containingFile.getRule(e.getText());
      if (r == null || ParserGeneratorUtil.Rule.isPrivate(r)) continue;
      BnfExpression context = nextMap.get(e);
      Cardinality cardinality = REQUIRED;
      for (PsiElement cur = context; !(cur instanceof BnfRule); cur = cur.getParent()) {
        if (PsiTreeUtil.isAncestor(cur, e, true)) break;
        IElementType curType = getEffectiveType(cur);
        if (curType == BnfTypes.BNF_OP_OPT || curType == BnfTypes.BNF_OP_ONEMORE || curType == BnfTypes.BNF_OP_ZEROMORE) {
          cardinality = cardinality.and(Cardinality.fromNodeType(curType));
        }
      }
      Cardinality prev = result.get(r);
      result.put(r, prev == null? cardinality : cardinality.or(prev));
    }
    return result;
  }
View Full Code Here

Examples of org.intellij.grammar.generator.RuleGraphHelper.Cardinality

        return Collections.emptyMap();
      }
      Map<PsiElement, Cardinality> map = psiMap();
      boolean leftMarker = m.containsKey(LEFT_MARKER);
      for (PsiElement t : m.keySet()) {
        Cardinality joinedCard = fromNodeType(type).and(m.get(t));
        if (leftMarker) {
          joinedCard = joinedCard.single();
        }
        map.put(t, joinedCard);
      }
      return map;
    }
    else if (type == BnfTypes.BNF_SEQUENCE || type == BnfTypes.BNF_EXPRESSION || type == BnfTypes.BNF_REFERENCE_OR_TOKEN) {
      list = ContainerUtil.newArrayList(compactInheritors(rule, list));
      for (Iterator<Map<PsiElement, Cardinality>> it = list.iterator(); it.hasNext(); ) {
        if (it.next().isEmpty()) it.remove();
      }
      Map<PsiElement, Cardinality> map = psiMap();
      for (Map<PsiElement, Cardinality> m : list) {
        Cardinality leftMarker = m.get(LEFT_MARKER);
        if (leftMarker == REQUIRED) {
          map.clear();
          leftMarker = null;
        }
        else if (leftMarker == OPTIONAL) {
          for (PsiElement t : map.keySet()) {
            if (!m.containsKey(t)) {
              map.put(t, map.get(t).and(Cardinality.OPTIONAL));
            }
          }
        }
        for (PsiElement t : m.keySet()) {
          if (t == LEFT_MARKER && m != list.get(0)) continue;
          Cardinality c1 = map.get(t);
          Cardinality c2 = m.get(t);
          Cardinality joinedCard;
          if (leftMarker == null) {
            joinedCard = c2.or(c1);

          }
          // handle left semantic in a choice-like way
View Full Code Here

Examples of org.intellij.grammar.generator.RuleGraphHelper.Cardinality

    List<Map<PsiElement, Cardinality>> result = ContainerUtil.newArrayListWithCapacity(mapList.size());
    for (Map<PsiElement, Cardinality> map : mapList) {
      Map<PsiElement, Cardinality> copy = psiMap(map);
      result.add(copy);
      for (Map.Entry<BnfRule, BnfRule> e : replacementMap.entrySet()) {
        Cardinality card = copy.remove(e.getKey());
        if (card == null) continue;
        Cardinality cur = copy.get(e.getValue());
        copy.put(e.getValue(), cur == null ? card : cur.or(card));
      }
    }
    return result;
  }
View Full Code Here

Examples of org.jboss.dependency.spi.Cardinality

      assertEquals(Cardinality.ZERO_TO_ONE, Cardinality.toCardinality("0..1"));
      assertEquals(Cardinality.ZERO_TO_MANY, Cardinality.toCardinality("0..n"));
      assertEquals(Cardinality.ONE_TO_ONE, Cardinality.toCardinality("1..1"));
      assertEquals(Cardinality.ONE_TO_MANY, Cardinality.toCardinality("1..n"));

      Cardinality c1 = Cardinality.toCardinality("2..20");
      assertEquals(2, c1.getLeft());
      assertEquals(20, c1.getRight());

      Cardinality c2 = Cardinality.createCardinality(2, 20);
      assertEquals(2, c2.getLeft());
      assertEquals(20, c2.getRight());

      Cardinality c3 = Cardinality.createUnlimitedCardinality(10);
      assertEquals(10, c3.getLeft());
      assertTrue(c3.isRightInfinity());

      Cardinality c4 = Cardinality.createLimitedCardinality(10);
      assertEquals(0, c4.getLeft());
      assertEquals(10, c4.getRight());

      Cardinality c5 = Cardinality.createCardinality(Cardinality.INFINITY, Cardinality.INFINITY);
      assertTrue(c5.isLeftInfinity());
      assertTrue(c5.isRightInfinity());
   }
View Full Code Here

Examples of org.jboss.dependency.spi.Cardinality

      assertTrue(c5.isRightInfinity());
   }

   public void testRangeCardinality() throws Throwable
   {
      Cardinality c1 = Cardinality.fromString("5..10");
      assertTrue(c1.isInRange(5));
      assertTrue(c1.isInRange(7));
      assertTrue(c1.isInRange(10));
      assertFalse(c1.isInRange(-1));
      assertFalse(c1.isInRange(3));
      assertFalse(c1.isInRange(20));
      assertFalse(c1.isInRange(Cardinality.INFINITY));

      Cardinality c2 = Cardinality.ZERO_TO_MANY;
      assertFalse(c2.isInRange(-1));
      assertTrue(c2.isInRange(0));
      assertTrue(c2.isInRange(Integer.MAX_VALUE));

      Cardinality c3 = Cardinality.ONE_TO_MANY;
      assertFalse(c3.isInRange(-1));
      assertFalse(c3.isInRange(0));
      assertTrue(c3.isInRange(1));
      assertTrue(c3.isInRange(Integer.MAX_VALUE));

      Cardinality c4 = Cardinality.createCardinality(Cardinality.INFINITY, Cardinality.INFINITY);
      assertFalse(c4.isInRange(-1));
      assertFalse(c4.isInRange(0));
      assertFalse(c4.isInRange(1));
      assertFalse(c4.isInRange(10));
      assertFalse(c4.isInRange(Integer.MAX_VALUE));
   }
View Full Code Here

Examples of org.openehr.am.archetype.constraintmodel.Cardinality

            }
           
            switch(parentClassName){
                case "CMultipleAttribute":
                    CMultipleAttribute multipleAttribute = (CMultipleAttribute)parent;
                    Cardinality cardinality = multipleAttribute.getCardinality();
                    debugText("cardinality interval: "+cardinality.getInterval());
                    debugText("cardinality isBag: "+cardinality.isBag());
                    debugText("cardinality isList: "+cardinality.isList());
                    debugText("cardinality isOrdered: "+cardinality.isOrdered());
                    debugText("cardinality isSet: "+cardinality.isSet());
                    debugText("cardinality isUnique: "+cardinality.isUnique());
                   
                    debugText("multipleAttribute rmAttributeName: "+multipleAttribute.getRmAttributeName());
                    debugText("multipleAttribute isValid: "+multipleAttribute.isValid());
                    debugText("multipleAttribute existence: "+multipleAttribute.getExistence());
                    debugText("multipleAttribute isAnyAllowed: "+multipleAttribute.isAnyAllowed());
View Full Code Here

Examples of org.sonar.check.Cardinality

    }
  }

  private void processRule(RulesDefinition.NewRepository repo, SMInputCursor ruleC) throws XMLStreamException {
    String key = null, name = null, description = null, internalKey = null, severity = Severity.defaultSeverity(), status = null;
    Cardinality cardinality = Cardinality.SINGLE;
    List<ParamStruct> params = new ArrayList<ParamStruct>();
    List<String> tags = new ArrayList<String>();

    /* BACKWARD COMPATIBILITY WITH VERY OLD FORMAT */
    String keyAttribute = ruleC.getAttrValue("key");
View Full Code Here

Examples of peg.GraphHelper.Cardinality

        }

        public Distance update(Tree iNode, Distance d1, Distance d2, Tree kNode) {
            if (d1 == NO_WAY || d2 == NO_WAY) return this;
            // calc d1 + d2
            Cardinality c = d1.card.and(fromNodeType(kNode.getType())).and(d2.card);
            return or(iNode, c);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.