1 package edu.uci.eecs.codeGenerator;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.Comparator;
8 import edu.uci.eecs.specExtraction.Code;
12 * This class represents all the code additions that should be added to a
19 public class CodeAdditions {
23 * This class represents the addition of code for a specific file. It
24 * records a list of lines to be inserted for a specific file, and the line
25 * after which the code should be inserted to the file.
31 public static class CodeAddition {
32 // The line after which the code should be inserted to the file
33 // E.g. insertingLine == 0 => insert the lines ine very beginning.
34 public final int insertingLine;
36 // The code to be added to the specified place
37 public final Code code;
39 public CodeAddition(int insertingLine, Code code) {
40 this.insertingLine = insertingLine;
44 public static Comparator<CodeAddition> lineNumComparator = new Comparator<CodeAddition>() {
45 public int compare(CodeAddition addition1, CodeAddition addition2) {
46 return addition1.insertingLine - addition2.insertingLine;
51 // A list of code addition for the same file
52 public final ArrayList<CodeAddition> codeAdditions;
54 // The file that the list of additions belong to
55 public final File file;
57 public CodeAdditions(File file) {
59 codeAdditions = new ArrayList<CodeAddition>();
62 public void addCodeAddition(CodeAddition a) {
63 this.codeAdditions.add(a);
68 * Whether the addition list is empty
73 public boolean isEmpty() {
74 return this.codeAdditions.size() == 0;
79 * Sort the list of code additions to the same file in an increasing order
80 * by the inserting line number of the code additions. We will call this
81 * function so that we can process code addition more conveniently.
85 Collections.sort(codeAdditions, CodeAddition.lineNumComparator);