001/*-----------------------------------------------------------------------+ 002 | com.teamscale.checks 003 | | 004 $Id$ 005 | | 006 | Copyright (c) 2009-2015 CQSE GmbH | 007 +-----------------------------------------------------------------------*/ 008package eu.cqse.check.framework.core.xpath; 009 010import java.util.List; 011 012import org.conqat.lib.commons.collections.CollectionUtils; 013import org.conqat.lib.commons.string.StringUtils; 014 015import eu.cqse.check.framework.scanner.IToken; 016import eu.cqse.check.framework.shallowparser.framework.EShallowEntityType; 017import eu.cqse.check.framework.shallowparser.framework.ShallowEntity; 018 019/** 020 * A shallow entity that contains all shallow entities of one file, that is used 021 * to represent the document root of xPath selections. 022 */ 023public class DocumentRootShallowEntity extends ShallowEntity { 024 025 /** Version for serialization. */ 026 private static final long serialVersionUID = 1L; 027 028 /** Subtype name for the document root entity. */ 029 public static final String DOCUMENT_ROOT_SUBTYPE_NAME = "document-root"; 030 031 /** Constructor. */ 032 public DocumentRootShallowEntity(String name) { 033 super(EShallowEntityType.MODULE, DOCUMENT_ROOT_SUBTYPE_NAME, name, CollectionUtils.<IToken> emptyList(), 0); 034 } 035 036 /** Sets the children for this document root. */ 037 public void setChildren(List<ShallowEntity> children) { 038 for (ShallowEntity child : children) { 039 addChild(child); 040 } 041 } 042 043 /** Returns the toString() results of the root entity's children. */ 044 @Override 045 public String toString() { 046 return StringUtils.concat(getChildren(), "\n"); 047 } 048 049 @Override 050 public boolean hasValidStartToken() { 051 // DocumentRootShallowEntities are never backed by a token list, but this is by 052 // design. Therefore, the start index (0) is always >= list.size(). 053 return true; 054 } 055}