package net.ssehub.kernel_haven.code_model;

import java.io.File;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

import net.ssehub.kernel_haven.util.null_checks.NonNull;

/**
 * Represents a single file from the source tree.
 * 
 * @author Johannes
 * @author Adam
 */
public class SourceFile implements Iterable<@NonNull CodeElement> {

    /**
     * This path is relative to the source tree.
     */
    private @NonNull File path;

    /**
     * This are the toplevel elements which are not nested in other elements.
     */
    private @NonNull List<@NonNull CodeElement> elements;

    /**
     * Constructs a Sourcefile.
     * 
     * @param path
     *            The relative path to the source file in the source tree. Must
     *            not be <code>null</code>.
     */
    public SourceFile(@NonNull File path) {
        this.path = path;
        elements = new LinkedList<>();
    }

    /**
     * Retrieves the path of this file which is relative to the source tree.
     * 
     * @return The path.
     */
    public @NonNull File getPath() {
        return path;
    }

    /**
     * Adds a element to the end of the list.
     * 
     * @param element
     *            The element to add. Must not be <code>null</code>.
     */
    public void addElement(@NonNull CodeElement element) {
        this.elements.add(element);
    }

    /**
     * Iterates over the top elements not nested in other elements.
     * @return an iterator over top elements.
     */
    @Override
    public Iterator<@NonNull CodeElement> iterator() {
        return elements.iterator();
    }
    
    /**
     * Returns the number of top elements (not nested in other elements).
     *  
     * @return the number of elements.
     */
    public int getTopElementCount() {
        return elements.size();
    }

}

@@ -38,16 +38,93 @@
 model;%0A%0A
+import static net.ssehub.kernel_haven.util.null_checks.NullHelpers.notNull;%0A%0A
 import j
@@ -1707,32 +1707,436 @@
  %7D%0A    %0A    /**%0A
+     * Returns the top element at the given index.%0A     * %0A     * @param index The index to get the top element for.%0A     * @return The top element at the given index.%0A     * %0A     * @throws IndexOutOfBoundsException If index is out of range.%0A     */%0A    public @NonNull CodeElement getElement(int index) throws IndexOutOfBoundsException %7B%0A        return notNull(elements.get(index));%0A    %7D%0A    %0A    /**%0A
      * Returns t

Add SourceFile.getElement(int)