Commit 979b9413 authored by Joachim Müssig's avatar Joachim Müssig

clear up code, javadoc

parent da14fc5e
......@@ -132,24 +132,15 @@ public class IfThenElseListener extends Java8BaseListener{
public void rewriteFileWithAssertions() throws IOException {
insertAssertions();
List<String> lines = readLinesOfFile(pathToJavaFile);
File javaFile = new File(pathToJavaFile);
PrintWriter pw = new PrintWriter(new FileWriter(javaFile, false));
for(int i = 0; i < lines.size(); i++) {
if(insertions.containsKey(i)) {
pw.println(insertions.get(i));
}
pw.println(lines.get(i));
}
pw.close();
}
......@@ -166,7 +157,6 @@ public class IfThenElseListener extends Java8BaseListener{
@Override
public void enterIfThenElseStatement(Java8Parser.IfThenElseStatementContext ctx) {
if(ctx.statementNoShortIf()!=null && ctx.statement() != null) {
int line = ctx.start.getLine();
if(analysis.containsKey(line)) {
......
......@@ -6,14 +6,20 @@ import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import org.antlr.runtime.BufferedTokenStream;
import org.antlr.runtime.TokenSource;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Token;
import antlr.TokenStreamBasicFilter;
import joanakey.antlr.java8.Java8BaseListener;
import joanakey.antlr.java8.Java8Lexer;
public class PreProcessor extends Java8BaseListener {
//TODO: dont remove comments
public static void main(String[] args) throws IOException {
String testFilePath = "testdata/plusMinusFalsePositive";
......@@ -23,10 +29,10 @@ public class PreProcessor extends Java8BaseListener {
private static CommonTokenStream getTokenStream(String path) throws FileNotFoundException, IOException {
FileInputStream in = new FileInputStream(path);
Java8Lexer java8Lexer = new Java8Lexer(new ANTLRInputStream(in));
Java8Lexer java8Lexer = new Java8Lexer(new ANTLRInputStream(in));
CommonTokenStream tokens = new CommonTokenStream(java8Lexer);
// org.antlr.v4.runtime.BufferedTokenStream tokens = new org.antlr.v4.runtime.BufferedTokenStream(java8Lexer);
// t.getTokens();
tokens.getText();
return tokens;
}
......@@ -38,7 +44,6 @@ public class PreProcessor extends Java8BaseListener {
//System.out.println("tokens: "+);
for(Token t : tokens.getTokens()){
if(t.getText().equals("{")){
buffer.append("\n"+generateTab(depth)+t.getText()+"\n");
depth++;
br =true;
......@@ -46,9 +51,7 @@ public class PreProcessor extends Java8BaseListener {
else if(t.getText().equals("}")){
depth--;
buffer.append(generateTab(depth)+t.getText()+"\n");
br =true;
}
else if(t.getText().equals(";")){
buffer.append(t.getText()+"\n");
......@@ -67,9 +70,7 @@ public class PreProcessor extends Java8BaseListener {
}
public void formatJavaSourceFolder(String path) throws FileNotFoundException, IOException {
File file = new File(path);
if(file.isDirectory()) {
for(File sub : file.listFiles()) {
formatJavaSourceFolder(sub.getAbsolutePath());
......@@ -84,13 +85,9 @@ public class PreProcessor extends Java8BaseListener {
}
public void formatJavaFile(String path) throws FileNotFoundException, IOException {
CommonTokenStream tokens = getTokenStream(path);
String formatted = formatJavaSource(tokens);
writeContentsToFile(path, formatted);
}
private void writeContentsToFile(String path, String formatted) throws IOException {
......@@ -105,7 +102,7 @@ public class PreProcessor extends Java8BaseListener {
private static String generateTab(int len){
String result = "";
for (int i = 0; i < len; i++) {
result += " ";
result += " ";
}
return result;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment