Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mihai.herda
keyjoana
Commits
979b9413
Commit
979b9413
authored
Nov 21, 2019
by
Joachim Müssig
Browse files
clear up code, javadoc
parent
da14fc5e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/joanakey/customlistener/IfThenElseListener.java
View file @
979b9413
...
...
@@ -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
))
{
...
...
src/joanakey/customlistener/PreProcessor.java
View file @
979b9413
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment