public CompositeTemplate(final ListOfTemplates templates) { this.templates = templates; for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { templates.getTemplateByIndex(i).setFullNameParent(this); } }
/** * Calculates the number of list members which are not the any or none symbol. * * @return the number calculated. */ public int getNofTemplatesNotAnyornone(CompilationTimeStamp timestamp) { int result = 0; for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { ITTCN3Template template = templates.getTemplateByIndex(i); Template_type ttype = template.getTemplatetype(); switch (ttype) { case ANY_OR_OMIT: break; case PERMUTATION_MATCH: if (template instanceof TemplateBody) { template = ((TemplateBody) template).getTemplate(); } result += ((PermutationMatch_Template) template).getNofTemplatesNotAnyornone(timestamp); break; case ALLELEMENTSFROM: result += ((AllElementsFrom) template).getNofTemplatesNotAnyornone(timestamp); break; default: result++; break; } } return result; }
@Override public void checkRecursions( final CompilationTimeStamp timestamp, final IReferenceChain referenceChain) { if (referenceChain.add(this)) { for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { ITTCN3Template template = templates.getTemplateByIndex(i); if (template != null) { referenceChain.markState(); template.checkRecursions(timestamp, referenceChain); referenceChain.previousState(); } } } }
/** * Checks if the list of templates has at least one any or none or permutation symbol * * <p>It is prohibited after "all from" * * @return true if an any or none symbol was found, false otherwise. */ public boolean containsAnyornoneOrPermutation() { for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { ITTCN3Template template = templates.getTemplateByIndex(i); switch (template.getTemplatetype()) { case ANY_OR_OMIT: case PERMUTATION_MATCH: return true; default: break; } } return false; }
@Override public StringBuilder getFullName(final INamedNode child) { StringBuilder builder = super.getFullName(child); for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { if (templates.getTemplateByIndex(i) == child) { return builder .append(FULLNAMEPART) .append(String.valueOf(i)) .append(INamedNode.RIGHTPARENTHESES); } } return builder; }
/** * Checks if the list of templates has at least one any or none symbol. * * @return true if an any or none symbol was found, false otherwise. */ public boolean templateContainsAnyornone() { for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { ITTCN3Template template = templates.getTemplateByIndex(i); switch (template.getTemplatetype()) { case ANY_OR_OMIT: return true; case PERMUTATION_MATCH: if (template instanceof TemplateBody) { template = ((TemplateBody) template).getTemplate(); } if (((PermutationMatch_Template) template).templateContainsAnyornone()) { return true; } break; default: break; } } return false; }
@Override public String createStringRepresentation() { StringBuilder builder = new StringBuilder(); builder.append(getNameForStringRep() + "( "); for (int i = 0, size = templates.getNofTemplates(); i < size; i++) { if (i > 0) { builder.append(", "); } ITTCN3Template template = templates.getTemplateByIndex(i); builder.append(template.createStringRepresentation()); } builder.append(" )"); if (lengthRestriction != null) { builder.append(lengthRestriction.createStringRepresentation()); } if (isIfpresent) { builder.append("ifpresent"); } return builder.toString(); }
/** @return the number of templates in the list */ public int getNofTemplates() { return templates.getNofTemplates(); }