コード例 #1
0
  @Override
  public boolean visit(final CFGNode node, final Element element) {
    final LinkedList<Pair<XMLPattern, SimpleAutomatonID>> matchings =
        new LinkedList<Pair<XMLPattern, SimpleAutomatonID>>();
    for (XMLPattern pattern : getXMLAutomatonDefinition().getXMLpatterns()) {
      final Pair<Boolean, XMLPatternVariablesAssignment> matchResult =
          pattern.matchesNode(node, aliasResolver);
      if (matchResult.getFirst()) {
        final XMLPatternVariablesAssignment assign = matchResult.getSecond();
        final boolean isGlobal = isGlobalAssignement(assign);
        matchings.add(Pair.make(pattern, new SimpleAutomatonID(assign, isGlobal)));
      }
    }

    if (matchings.size() > 1) checkMatchingConflict(element, matchings);

    if (!matchings.isEmpty()) {
      final PatternLocation newLocation = createCommonPatternLocation(node, matchings);
      getNodeLocationDictionary().put(node, Pair.make(newLocation, newLocation));
      if (matchings.getFirst().getFirst().isConstructive())
        getAutomataIDs().add(matchings.getFirst().getSecond());
    } else if (getNavigator().isCallNode(node)) {
      final PatternLocation callLocation = createRuleLessPatternLocation(node);
      final PatternLocation returnLocation = createRuleLessPatternLocation(node);
      getNodeLocationDictionary().put(node, Pair.make(callLocation, returnLocation));
      callLocation.setLocationForCallNotPassedStates(returnLocation);
    }

    return true;
  }
コード例 #2
0
 private LinkedList<ErrorRule> createErrorRules(
     final LinkedList<Pair<XMLPattern, SimpleAutomatonID>> matchings) {
   final LinkedList<ErrorRule> errorRules = new LinkedList<ErrorRule>();
   for (Pair<XMLPattern, SimpleAutomatonID> item : matchings)
     for (final XMLErrorRule XMLerrorRule :
         getXMLAutomatonDefinition().getXMLerrorRulesForPattern(item.getFirst()))
       errorRules.add(new ErrorRule(XMLerrorRule, item.getSecond()));
   return errorRules;
 }
コード例 #3
0
 private LinkedList<TransitionRule> createTransitionRules(
     final LinkedList<Pair<XMLPattern, SimpleAutomatonID>> matchings) {
   final LinkedList<TransitionRule> transitionRules = new LinkedList<TransitionRule>();
   for (Pair<XMLPattern, SimpleAutomatonID> item : matchings)
     for (final XMLTransitionRule XMLtransitionRule :
         getXMLAutomatonDefinition().getXMLtransitionRulesForPattern(item.getFirst()))
       transitionRules.add(new TransitionRule(XMLtransitionRule, item.getSecond()));
   return transitionRules;
 }
コード例 #4
0
  private void checkMatchingConflict(
      final Element element, final LinkedList<Pair<XMLPattern, SimpleAutomatonID>> matchings) {
    if (!logger.isDebugEnabled()) return;

    boolean same = true;
    final Set<String> names = new HashSet<String>();
    names.add(matchings.getFirst().getFirst().getName());
    for (final Pair<XMLPattern, SimpleAutomatonID> match : matchings)
      if (names.add(match.getFirst().getName())) {
        same = false;
        break;
      }
    if (!same) {
      logger.debug("This code:");
      logger.debug(element.asXML());
      logger.debug("can be matched by more than one " + "distinct rule:");
      for (final Pair<XMLPattern, SimpleAutomatonID> match : matchings) {
        final XMLPattern pat = match.getFirst();
        logger.debug(pat.getName() + ": " + pat.getPatternXMLelement().asXML());
      }
    }
  }