Reputation: 4763
I am creating a compiler program using java, I have it compiling java files, and i have it finding out what error happened and on which line it happened on. My question is that when it is printing out this information i am getting a load of ///////////
in the middle of the output and I dont understand why this is!
My output is
Error on line 4 in ////////////////////////////////////////////////////////////////////////////////////////////.java:4: error: class ToCompileTwo is public, should be declared in a file named ToCompileTwo.java
public class ToCompileTwo {
this is the code i am using to get this display
for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
System.out.format("Error on line %d in %s", diagnostic.getLineNumber(), diagnostic);
}
EDIT
I managed to fix this, the following method is what was creating the ////////
protected DynamicJavaSourceCodeObject(String name, String code) {
super(URI.create("string:///" + name.replaceAll(".", "/") + Kind.SOURCE.extension), Kind.SOURCE);
this.qualifiedName = name;
this.sourceCode = code;
}
I changed the second line to
super(URI.create("string:///" + name.replaceAll("\\\\", "/") ), Kind.SOURCE);
This fixed the problem
Upvotes: 2
Views: 368
Reputation: 20065
When you do name.replaceAll(".", "/")
you replace all by /
. ReplaceAll take a regex as first parameter so you match ALL characters with .
and replace them with /
.
Replace your statement with :
name.replaceAll("\\.", "/")
\\.
: stand for the character dot.
Upvotes: 1