private String computeRuleName( ObservableInjectingParser parser, Object singleForeachResult, PredicateSemantic activePredicateSemantic, String mode, IRuleName ruleNameFinder) throws SyntaxElementException { String ruleName = null; if (activePredicateSemantic == null) { // no matching when/as combination; perform default handling: if (singleForeachResult instanceof EObject) { EClass foreachElementType = ((EObject) singleForeachResult).eClass(); // get the template Template tmpl = TcsUtil.findTemplate( foreachElementType, mode, Collections.singletonList(URI.createURI(parser.getSyntaxUUID()))); // get the rule name from the template ruleName = ruleNameFinder.getRuleName(tmpl, mode); } else { // handle the base types if (!(singleForeachResult instanceof String) || !(singleForeachResult instanceof Number)) { throw new IllegalArgumentException( "The OCL element " + singleForeachResult + " cannot be used, as it is neither of type String nor a Number"); } } } else { ruleName = activePredicateSemantic.getAs(); } return ruleName; }