Permalink
Browse files

Partial fixes for issue 1176. Continue issue 882. Make compiler detect

the line of error in umple file.
  • Loading branch information...
YiranShu committed Oct 21, 2018
1 parent 41a59b8 commit 742b988f08ec3eb9b02d74909d0d047edcd86d5f
@@ -1,5 +1,6 @@
class UmpleToJava {
class_MethodDeclaration <<!<</*class_MethodDeclaration*/>><<#
if (uClass.hasMethods())
{
boolean hasQueued = false;
@@ -3,6 +3,7 @@ class UmpleToJava {
java.util.regex.Pattern lineNumberPattern = java.util.regex.Pattern.compile("// line ([0|1|2|3|4|5|6|7|8|9]*) \"(.*)\"");
private void addUncaughtExceptionVariables(int javaline, String code, String methodname)
{
String[] lines = code.split("\\n");
java.util.regex.Matcher matcher = lineNumberPattern.matcher(lines[0]);
if(matcher.matches())
@@ -75,7 +75,24 @@ class CodeCompiler {
StackTraceElement ust;
String javaFileName;
int javaLineNumber;
String lineParts[] = line.split(":",3);
String lineParts[] = null;
if(File.separator.equals("\\")) {
// Windows System
String tempLineParts[] = line.split(":", 4);
if(tempLineParts.length == 4) {
lineParts = new String[3];
lineParts[0] = tempLineParts[0] + ":" + tempLineParts[1];
lineParts[1] = tempLineParts[2];
lineParts[2] = tempLineParts[3];
} else {
lineParts = line.split(":",3);
}
}
else {
// Mac or Linux
lineParts = line.split(":",3);
}
// Case 1: No colons so nothing to translate
if(lineParts.length < 3) {
@@ -107,7 +124,9 @@ class CodeCompiler {
"",
javaFile,
Integer.parseInt(lineParts[1])), "");
// System.err.println("*"+lineParts[0]+"*"); // Debug
if(ust==null) {
return line;
}
@@ -83,12 +83,14 @@ class ExceptionDumper {
depend java.io.*;
depend java.nio.file.Path;
depend java.nio.file.Paths;
depend java.nio.file.InvalidPathException;
public static String dumpCompilerError(Throwable ex) {
String generatedMessage = "";
String exceptionMessage = "";
String generatedSourcePath = System.getenv("GeneratedSourcePath");
String sourcePathType="GeneratedSourcePath that has been set to ";
if (generatedSourcePath == null) {
String homedir = System.getenv("HOME");
if(homedir != null &&
@@ -132,22 +134,36 @@ class ExceptionDumper {
// Translate the java stack trace line information into the corresponding Umple line
public static StackTraceElement javaToUmpleStackTrace(StackTraceElement javaStack, String generatedSourcePath) {
int javaLineNumber = javaStack.getLineNumber();
Path pathToJavaFile = Paths.get(generatedSourcePath +
Path pathToJavaFile;
try {
pathToJavaFile = Paths.get(generatedSourcePath +
javaStack.getClassName().replace('.',File.separatorChar) + ".java");
} catch (InvalidPathException ipe) {
pathToJavaFile = null;
}
Scanner sc = null;
try {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
if(pathToJavaFile != null) {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
}
}
catch (FileNotFoundException fne) {
sc = null;
}
if(sc == null) {
// Try opening using just the natural hierarchy from package names
pathToJavaFile = Paths.get(javaStack.getClassName().replace('.',File.separatorChar) + ".java");
try {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
pathToJavaFile = Paths.get(javaStack.getClassName().replace('.',File.separatorChar) + ".java");
} catch (InvalidPathException ipe) {
pathToJavaFile = null;
}
try {
if(pathToJavaFile != null) {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
}
}
catch (FileNotFoundException fne) {
sc = null;
@@ -157,10 +173,17 @@ class ExceptionDumper {
if(sc == null) {
// Try opening using just the plain file name
int classNameStart = javaStack.getClassName().lastIndexOf('.')+1;
pathToJavaFile = Paths.get(generatedSourcePath +
try {
pathToJavaFile = Paths.get(generatedSourcePath +
javaStack.getClassName().substring(classNameStart)+".java");
} catch (InvalidPathException ipe) {
pathToJavaFile = null;
}
try {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
if(pathToJavaFile != null) {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
}
}
catch (FileNotFoundException fne) {
sc = null;
@@ -170,9 +193,15 @@ class ExceptionDumper {
if(sc == null) {
// The above doesn't work for relative paths in the className,
// so use the actual fileNmae attribute of javaStack
pathToJavaFile = Paths.get(generatedSourcePath + javaStack.getFileName());
try {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
pathToJavaFile = Paths.get(generatedSourcePath + javaStack.getFileName());
} catch (InvalidPathException ipe) {
pathToJavaFile = null;
}
try {
if(pathToJavaFile != null) {
sc = new Scanner(new BufferedReader(new FileReader(pathToJavaFile.toFile())));
}
}
catch (FileNotFoundException fne) {
return null;
@@ -43,7 +43,7 @@ public static void CompareCompiledOutputToExpected(BufferedReader actualReader,
int line = 0;
while (error != null && expected != null) {
line++;
Assert.assertEquals("Failed at: " + line, expected, error);
Assert.assertEquals("Failed at: " + line, expected.trim(), error.trim());
error = actualReader.readLine();
expected = expectedReader.readLine();
}

0 comments on commit 742b988

Please sign in to comment.