Explorar el Código

Applied auto-formatting to the frontend-utils.

Timur Sağlam hace 5 años
padre
commit
0dd7ebe7ae

+ 29 - 30
jplag.frontend-utils/src/main/java/jplag/InputState.java

@@ -6,36 +6,35 @@ import java.io.Reader;
 import antlr.InputBuffer;
 import antlr.LexerSharedInputState;
 
-/** 
- * This object contains the data associated with an input stream of characters. 
- * Multiple lexers share a single LexerSharedInputState to lex the same input stream.
+/**
+ * This object contains the data associated with an input stream of characters. Multiple lexers share a single
+ * LexerSharedInputState to lex the same input stream.
  */
 public class InputState extends LexerSharedInputState {
-  public int column = 0;
-  public int tokColumn = 0;
-  // public int guessing = 0;
-  public InputState(InputBuffer inbuf) {
-    super(inbuf);
-    column = 1;
-    line = 1;
-  }
-  public InputState(InputStream in) {
-    super(in);
-    column = 1;
-    line = 1;
-  }
-  public InputState(Reader in) {
-    super(in);
-    column = 1;
-    line = 1;
-  }
-  
-  @Override
-public int getLine() { return line; }
+    public int column = 0;
+    public int tokColumn = 0;
+
+    // public int guessing = 0;
+    public InputState(InputBuffer inbuf) {
+        super(inbuf);
+        column = 1;
+        line = 1;
+    }
+
+    public InputState(InputStream in) {
+        super(in);
+        column = 1;
+        line = 1;
+    }
+
+    public InputState(Reader in) {
+        super(in);
+        column = 1;
+        line = 1;
+    }
+
+    @Override
+    public int getLine() {
+        return line;
+    }
 }
-
-
-
-
-
-

+ 26 - 27
jplag.frontend-utils/src/main/java/jplag/NewlineStream.java

@@ -1,6 +1,5 @@
 package jplag;
 
-
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -8,33 +7,33 @@ import java.io.InputStream;
  * This stream adds a newline to the end of a file. This is a proxy.
  */
 public class NewlineStream extends InputStream {
-  private int endOfFile = 0;
-  private InputStream stream;
+    private int endOfFile = 0;
+    private InputStream stream;
 
-  public NewlineStream(InputStream stream) {
-    super();
-    this.stream = stream;
-  }
+    public NewlineStream(InputStream stream) {
+        super();
+        this.stream = stream;
+    }
 
-  @Override
-public int read() throws IOException {
-    int result;
-    switch (endOfFile) {
-    case 0:
-      result = stream.read();
-      if (result == -1) {
-	result = 13;
-	endOfFile = 1;
-      }
-      break;
-    case 1:
-      result = 10;
-      endOfFile = 2;
-      break;
-    default:
-      result = -1;
-      break;
+    @Override
+    public int read() throws IOException {
+        int result;
+        switch (endOfFile) {
+        case 0:
+            result = stream.read();
+            if (result == -1) {
+                result = 13;
+                endOfFile = 1;
+            }
+            break;
+        case 1:
+            result = 10;
+            endOfFile = 2;
+            break;
+        default:
+            result = -1;
+            break;
+        }
+        return result;
     }
-    return result;
-  }
 }

+ 22 - 22
jplag.frontend-utils/src/main/java/jplag/Parser.java

@@ -5,27 +5,27 @@ package jplag;
  * @date 22.01.2005
  */
 public abstract class Parser { // TODO TS: We should rename this class, as all concrete parsers shadow its name.
-  protected ProgramI program;
-  protected int errors    = 0;
-  private   int errorsSum = 0;
-  
-  public boolean getErrors() {
-	  return (errors!=0);
-  }
-  
-  public int errorsCount() {
-	  return errorsSum;	
-  }
-  
-  protected void parseEnd() {
-	  errorsSum+=errors;	
-  }
+    protected ProgramI program;
+    protected int errors = 0;
+    private int errorsSum = 0;
 
-  public ProgramI getProgram() {
-	  return program;
-  }
-  
-  public void setProgram(ProgramI prog) {
-	  this.program=prog;
-  }
+    public boolean getErrors() {
+        return (errors != 0);
+    }
+
+    public int errorsCount() {
+        return errorsSum;
+    }
+
+    protected void parseEnd() {
+        errorsSum += errors;
+    }
+
+    public ProgramI getProgram() {
+        return program;
+    }
+
+    public void setProgram(ProgramI prog) {
+        this.program = prog;
+    }
 }

+ 80 - 54
jplag.frontend-utils/src/main/java/jplag/ParserToken.java

@@ -1,58 +1,84 @@
 package jplag;
 
-
 public class ParserToken extends antlr.Token {
-  /**
-   * This variable holds the line number of the current token.
-   */
-  protected int _line = -1;
-
-  /**
-   * This variable holds the column of the current token in its line.
-   */
-  protected int _column = -1;
-
-  /**
-   * This variable holds the label of the current token.
-   */
-  protected String _text = null;
-
-  /**
-   * This variable holds the identifier of the current token.
-   */
-
-  protected int _id = -1;
-
-  public ParserToken() { super(); }
-  public ParserToken(int type) { super(type); }
-  public ParserToken(int type, String text) {
-    super(type, text); setText(text);
-  }
-
-  @Override
-public void setLine(int line) { _line = line;}
-  @Override
-public void setColumn(int column) { _column = column; }
-  public void setID(int id) { _id = id; }
-  @Override
-public void setText(String text) {
-    _text = (text!=null ? text.intern() : null);
-  }
-
-  @Override
-public int getColumn() { return _column; }
-  @Override
-public int getLine() { return _line; }
-  @Override
-public String getText() { return _text; }
-  public int getID() { return _id; }
-
-  public int getLength() { return _text.length(); }
-
-  @Override
-public String toString()
-  {
-    return "{\"" + getText() + "\", <" + getType() + ">, " +
-      getLine() + " " + getColumn() + "}";
-  }
+    /**
+     * This variable holds the line number of the current token.
+     */
+    protected int _line = -1;
+
+    /**
+     * This variable holds the column of the current token in its line.
+     */
+    protected int _column = -1;
+
+    /**
+     * This variable holds the label of the current token.
+     */
+    protected String _text = null;
+
+    /**
+     * This variable holds the identifier of the current token.
+     */
+
+    protected int _id = -1;
+
+    public ParserToken() {
+        super();
+    }
+
+    public ParserToken(int type) {
+        super(type);
+    }
+
+    public ParserToken(int type, String text) {
+        super(type, text);
+        setText(text);
+    }
+
+    @Override
+    public void setLine(int line) {
+        _line = line;
+    }
+
+    @Override
+    public void setColumn(int column) {
+        _column = column;
+    }
+
+    public void setID(int id) {
+        _id = id;
+    }
+
+    @Override
+    public void setText(String text) {
+        _text = (text != null ? text.intern() : null);
+    }
+
+    @Override
+    public int getColumn() {
+        return _column;
+    }
+
+    @Override
+    public int getLine() {
+        return _line;
+    }
+
+    @Override
+    public String getText() {
+        return _text;
+    }
+
+    public int getID() {
+        return _id;
+    }
+
+    public int getLength() {
+        return _text.length();
+    }
+
+    @Override
+    public String toString() {
+        return "{\"" + getText() + "\", <" + getType() + ">, " + getLine() + " " + getColumn() + "}";
+    }
 }

+ 1 - 1
jplag.frontend-utils/src/main/java/jplag/ProgramI.java

@@ -1,7 +1,7 @@
 package jplag;
 
 public interface ProgramI {
-    
+
     /**
      * Print and store an error.
      * @param errorMessage is the error message.

+ 13 - 14
jplag.frontend-utils/src/main/java/jplag/StrippedProgram.java

@@ -1,23 +1,22 @@
 package jplag;
 
 /**
- * This is a stripped version of the JPlag main class Program to be used during
- * front end development only.
+ * This is a stripped version of the JPlag main class Program to be used during front end development only.
  */
 public class StrippedProgram implements ProgramI {
-	@Override
+    @Override
     public void addError(String errorMsg) {
-		System.err.println(errorMsg);
-	}
+        System.err.println(errorMsg);
+    }
 
-	@Override
+    @Override
     public void print(String normalMsg, String longMsg) {
-		if (longMsg != null) {
-			System.out.println(longMsg);
-		} else if (normalMsg != null) {
-			System.out.println(normalMsg);
-		} else {
-			System.out.println("Someboy messed up - no message given");
-		}
-	}
+        if (longMsg != null) {
+            System.out.println(longMsg);
+        } else if (normalMsg != null) {
+            System.out.println(normalMsg);
+        } else {
+            System.out.println("Someboy messed up - no message given");
+        }
+    }
 }

+ 105 - 105
jplag.frontend-utils/src/main/java/jplag/Structure.java

@@ -10,110 +10,110 @@ import java.io.ObjectOutputStream;
 
 /** The tokenlist */ // TODO PB: The name 'Structure' is very generic and should be changed to something more descriptive.
 public class Structure implements TokenConstants {
-	public Token[] tokens = new Token[0];
-	Table table = null;
-	int hash_length = -1;
-
-	int files; // number of END_FILE tokens
-	private int numberOfTokens;
-
-	public Structure() {
-		tokens = new Token[400];
-		files = numberOfTokens = 0;
-	}
-
-	public final int size() {
-		return numberOfTokens;
-	}
-
-	public final void ensureCapacity(int minCapacity) {
-		int oldCapacity = tokens.length;
-		if (minCapacity > oldCapacity) {
-			Token[] oldTokens = tokens;
-			int newCapacity = (2 * oldCapacity);
-			if (newCapacity < minCapacity) {
-				newCapacity = minCapacity;
-			}
-			tokens = new Token[newCapacity];
-			System.arraycopy(oldTokens, 0, tokens, 0, numberOfTokens);
-		}
-	}
-
-	public final void addToken(Token token) {
-		ensureCapacity(numberOfTokens + 1);
-		if (numberOfTokens > 0 && tokens[numberOfTokens - 1].file.equals(token.file))
-			token.file = tokens[numberOfTokens - 1].file; // To save memory ...
-		if ((numberOfTokens > 0) && (token.getLine() < tokens[numberOfTokens - 1].getLine()) && (token.file.equals(tokens[numberOfTokens - 1].file)))
-			token.setLine(tokens[numberOfTokens - 1].getLine());
-		// just to make sure
-
-		tokens[numberOfTokens++] = token;
-		if (token.type == FILE_END)
-			files++;
-	}
-
-	@Override
+    public Token[] tokens = new Token[0];
+    Table table = null;
+    int hash_length = -1;
+
+    int files; // number of END_FILE tokens
+    private int numberOfTokens;
+
+    public Structure() {
+        tokens = new Token[400];
+        files = numberOfTokens = 0;
+    }
+
+    public final int size() {
+        return numberOfTokens;
+    }
+
+    public final void ensureCapacity(int minCapacity) {
+        int oldCapacity = tokens.length;
+        if (minCapacity > oldCapacity) {
+            Token[] oldTokens = tokens;
+            int newCapacity = (2 * oldCapacity);
+            if (newCapacity < minCapacity) {
+                newCapacity = minCapacity;
+            }
+            tokens = new Token[newCapacity];
+            System.arraycopy(oldTokens, 0, tokens, 0, numberOfTokens);
+        }
+    }
+
+    public final void addToken(Token token) {
+        ensureCapacity(numberOfTokens + 1);
+        if (numberOfTokens > 0 && tokens[numberOfTokens - 1].file.equals(token.file))
+            token.file = tokens[numberOfTokens - 1].file; // To save memory ...
+        if ((numberOfTokens > 0) && (token.getLine() < tokens[numberOfTokens - 1].getLine()) && (token.file.equals(tokens[numberOfTokens - 1].file)))
+            token.setLine(tokens[numberOfTokens - 1].getLine());
+        // just to make sure
+
+        tokens[numberOfTokens++] = token;
+        if (token.type == FILE_END)
+            files++;
+    }
+
+    @Override
     public final String toString() {
-		StringBuffer buffer = new StringBuffer();
-
-		try {
-			for (int i = 0; i < numberOfTokens; i++) {
-				buffer.append(i);
-				buffer.append("\t");
-				buffer.append(tokens[i].toString());
-				if (i < numberOfTokens - 1) {
-					buffer.append("\n");
-				}
-			}
-		} catch (OutOfMemoryError e) {
-			return "Tokenlist to large for output: " + (numberOfTokens) + " Tokens";
-		}
-		return buffer.toString();
-	}
-
-	public void save(File file) {
-
-		try {
-			ObjectOutputStream input = new ObjectOutputStream((new FileOutputStream(file)));
-
-			input.writeInt(numberOfTokens);
-			input.writeInt(hash_length);
-			input.writeInt(files);
-
-			for (int i = 0; i < numberOfTokens; i++)
-				input.writeObject(tokens[i]);
-			input.flush();
-			input.close();
-		} catch (IOException e) {
-			System.out.println("Error writing file: " + file.toString());
-		}
-	}
-
-	/* returns "true" when successful */
-	public boolean load(File file) {
-		try {
-			ObjectInputStream input = new ObjectInputStream((new FileInputStream(file)));
-
-			int newNumberOfTokens = input.readInt();
-			hash_length = input.readInt();
-			files = input.readInt();
-			ensureCapacity(newNumberOfTokens);
-			numberOfTokens = newNumberOfTokens;
-			for (int i = 0; i < numberOfTokens; i++) {
-				tokens[i] = (Token) input.readObject();
-			}
-			input.close();
-			table = null;
-		} catch (FileNotFoundException e) {
-			System.out.println("File not found: " + file.toString());
-			return false;
-		} catch (IOException e) {
-			System.out.println("Error reading file: " + file.toString() + " (" + e + ")");
-			return false;
-		} catch (ClassNotFoundException e) {
-			System.out.println("Class not found in file: " + file.toString());
-			return false;
-		}
-		return true;
-	}
+        StringBuffer buffer = new StringBuffer();
+
+        try {
+            for (int i = 0; i < numberOfTokens; i++) {
+                buffer.append(i);
+                buffer.append("\t");
+                buffer.append(tokens[i].toString());
+                if (i < numberOfTokens - 1) {
+                    buffer.append("\n");
+                }
+            }
+        } catch (OutOfMemoryError e) {
+            return "Tokenlist to large for output: " + (numberOfTokens) + " Tokens";
+        }
+        return buffer.toString();
+    }
+
+    public void save(File file) {
+
+        try {
+            ObjectOutputStream input = new ObjectOutputStream((new FileOutputStream(file)));
+
+            input.writeInt(numberOfTokens);
+            input.writeInt(hash_length);
+            input.writeInt(files);
+
+            for (int i = 0; i < numberOfTokens; i++)
+                input.writeObject(tokens[i]);
+            input.flush();
+            input.close();
+        } catch (IOException e) {
+            System.out.println("Error writing file: " + file.toString());
+        }
+    }
+
+    /* returns "true" when successful */
+    public boolean load(File file) {
+        try {
+            ObjectInputStream input = new ObjectInputStream((new FileInputStream(file)));
+
+            int newNumberOfTokens = input.readInt();
+            hash_length = input.readInt();
+            files = input.readInt();
+            ensureCapacity(newNumberOfTokens);
+            numberOfTokens = newNumberOfTokens;
+            for (int i = 0; i < numberOfTokens; i++) {
+                tokens[i] = (Token) input.readObject();
+            }
+            input.close();
+            table = null;
+        } catch (FileNotFoundException e) {
+            System.out.println("File not found: " + file.toString());
+            return false;
+        } catch (IOException e) {
+            System.out.println("Error reading file: " + file.toString() + " (" + e + ")");
+            return false;
+        } catch (ClassNotFoundException e) {
+            System.out.println("Class not found in file: " + file.toString());
+            return false;
+        }
+        return true;
+    }
 }

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 1
jplag.frontend-utils/src/main/java/jplag/Table.java


+ 52 - 44
jplag.frontend-utils/src/main/java/jplag/Token.java

@@ -1,51 +1,59 @@
 package jplag;
 
-
 import java.io.Serializable;
 
 abstract public class Token implements TokenConstants, Serializable {
-	private static final long serialVersionUID = 862935679966383302L;
-	public int type;
-	public String file;
-	
-	protected boolean marked;
-	protected boolean basecode = false;
-	protected int hash = -1;// hash-value. set and used by main algorithm (GSTiling)
-	
-	public Token(int type, String file, int line) {
-		this(type, file, line, -1, -1);
-	}
-	
-	public Token(int type, String file, int line, int column, int length) {
-		this.type = type;
-		this.file = file;
-		setLine(line>0 ? line : 1);
-		setColumn(column);
-		setLength(length);
-	}
-	
-	// abstract members
-	abstract public int getLine();
-	abstract public int getColumn();
-	abstract public int getLength();
-	protected void setLine(int line) {}
-	protected void setColumn(int line) {}
-	protected void setLength(int line) {}
-	
-	// this is made to distinguish the character front end.
-	// maybe other front ends can use it too?
-  public int getIndex() { return -1; }
-	
-	public static String type2string(int type) {
-		return "<abstract>";
-	}
-	
-	@Override
+    private static final long serialVersionUID = 862935679966383302L;
+    public int type;
+    public String file;
+
+    protected boolean marked;
+    protected boolean basecode = false;
+    protected int hash = -1;// hash-value. set and used by main algorithm (GSTiling)
+
+    public Token(int type, String file, int line) {
+        this(type, file, line, -1, -1);
+    }
+
+    public Token(int type, String file, int line, int column, int length) {
+        this.type = type;
+        this.file = file;
+        setLine(line > 0 ? line : 1);
+        setColumn(column);
+        setLength(length);
+    }
+
+    // abstract members
+    abstract public int getLine();
+
+    abstract public int getColumn();
+
+    abstract public int getLength();
+
+    protected void setLine(int line) {
+    }
+
+    protected void setColumn(int line) {
+    }
+
+    protected void setLength(int line) {
+    }
+
+    // this is made to distinguish the character front end. Maybe other front ends can use it too?
+    public int getIndex() {
+        return -1;
+    }
+
+    public static String type2string(int type) {
+        return "<abstract>";
+    }
+
+    @Override
     public String toString() {
-		return type2string(type);
-	}
-	
-	public static int numberOfTokens() { 
-		return 1;
-	} 
+        return type2string(type);
+    }
+
+    public static int numberOfTokens() {
+        return 1;
+    }
 }

+ 5 - 6
jplag.frontend-utils/src/main/java/jplag/TokenConstants.java

@@ -1,10 +1,9 @@
 package jplag;
 
 public interface TokenConstants {
-  final static int FILE_END = 0;
-	/**
-	 * Used to optionally separate methods from each other with an always marked
-	 * token
-	 */
-  final static int SEPARATOR_TOKEN = 1;
+    final static int FILE_END = 0;
+    /**
+     * Used to optionally separate methods from each other with an always marked token
+     */
+    final static int SEPARATOR_TOKEN = 1;
 }

+ 27 - 29
jplag.frontend-utils/src/main/java/jplag/UnicodeReader.java

@@ -1,20 +1,21 @@
-/**
- Original pseudocode   : Thomas Weidenfeller
- Implementation tweaked: Aki Nieminen
-
- http://www.unicode.org/unicode/faq/utf_bom.html
- BOMs:
- 00 00 FE FF    = UTF-32, big-endian
- FF FE 00 00    = UTF-32, little-endian
- FE FF          = UTF-16, big-endian
- FF FE          = UTF-16, little-endian
- EF BB BF       = UTF-8
-
- Win2k Notepad:
- Unicode format = UTF-16LE
- ***/
+/*
+ * Original pseudocode   : Thomas Weidenfeller
+ * Implementation tweaked: Aki Nieminen
+ * 
+ * http://www.unicode.org/unicode/faq/utf_bom.html
+ * BOMs:
+ * 00 00 FE FF    = UTF-32, big-endian
+ * FF FE 00 00    = UTF-32, little-endian
+ * FE FF          = UTF-16, big-endian
+ * FF FE          = UTF-16, little-endian
+ * EF BB BF       = UTF-8
+ * 
+ * Win2k Notepad:
+ * Unicode format = UTF-16LE
+ */
 
 package jplag;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -22,14 +23,15 @@ import java.io.PushbackInputStream;
 import java.io.Reader;
 
 /**
- * Generic unicode text reader, which will use BOM mark to identify the encoding
- * to be used. If BOM is not found then use a given default encoding. System
- * default is used if: BOM mark is not found and defaultEnc is NULL.<br />
+ * Generic unicode text reader, which will use BOM mark to identify the encoding to be used. If BOM is not found then
+ * use a given default encoding. System default is used if: BOM mark is not found and defaultEnc is NULL.<br />
+ * Usage pattern:
  * 
- * Usage pattern:<pre>
+ * <pre>
  * String defaultEnc = "UTF-8"; // or NULL to use system default
  * FileInputStream fis = new FileInputStream(file);
- * Reader in = new UnicodeReader(fis, defaultEnc);</pre>
+ * Reader in = new UnicodeReader(fis, defaultEnc);
+ * </pre>
  */
 public class UnicodeReader extends Reader {
     PushbackInputStream internalIn;
@@ -56,8 +58,7 @@ public class UnicodeReader extends Reader {
     }
 
     /**
-     * Read-ahead four bytes and check for BOM marks. Extra bytes are
-     * unread back to the stream, only BOM bytes are skipped.
+     * Read-ahead four bytes and check for BOM marks. Extra bytes are unread back to the stream, only BOM bytes are skipped.
      */
     protected void init() throws IOException {
         if (internalIn2 != null)
@@ -68,8 +69,7 @@ public class UnicodeReader extends Reader {
         int n, unread;
         n = internalIn.read(bom, 0, bom.length);
 
-        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB)
-                && (bom[2] == (byte) 0xBF)) {
+        if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
             encoding = "UTF-8";
             unread = n - 3;
         } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
@@ -78,12 +78,10 @@ public class UnicodeReader extends Reader {
         } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
             encoding = "UTF-16LE";
             unread = n - 2;
-        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00)
-                && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
+        } else if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
             encoding = "UTF-32BE";
             unread = n - 4;
-        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)
-                && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
+        } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
             encoding = "UTF-32LE";
             unread = n - 4;
         } else {
@@ -91,7 +89,7 @@ public class UnicodeReader extends Reader {
             encoding = defaultEnc;
             unread = n;
         }
-        //      System.out.println("read=" + n + ", unread=" + unread);
+        // System.out.println("read=" + n + ", unread=" + unread);
 
         if (unread > 0)
             internalIn.unread(bom, (n - unread), unread);

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio