Skip to content

Commit

Permalink
Merge branch 'dev' into fix-#1083
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Oct 2, 2017
2 parents d76c36a + 656e878 commit 59662d5
Show file tree
Hide file tree
Showing 21 changed files with 243 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ class WollokREPLInterpreter extends WollokInterpreter {
new XStackFrame(root, nativeLobby, WollokSourcecodeLocator.INSTANCE)
}

override isRootFile() { true }
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ class WollokLauncherInterpreterEvaluator extends WollokInterpreterEvaluator {
if (main !== null)
main.eval
else {
val isASuite = tests.empty && suite !== null
val _isASuite = isASuite
var testsToRun = tests
var String suiteName = null
if (isASuite) {
if (_isASuite) {
suiteName = suite.name
testsToRun = suite.tests
}
wollokTestsReporter.testsToRun(suiteName, it, testsToRun)
try {
testsToRun.fold(null) [ a, _test |
resetGlobalState
if (isASuite) {
if (_isASuite) {
_test.evalInSuite(suite)
} else {
_test.eval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class WollokRepl {
printReturnValue(returnValue)
} catch (Exception e) {
resetIndent
handleException(e)
e.handleException
}
}

Expand Down Expand Up @@ -134,7 +134,7 @@ class WollokRepl {

resourceSet.resources.add(resource)

resource.load(in, #{});
resource.load(in, #{})
launcher.validate(injector, resource, [], [throw new ReplParserException(it)])
resource.contents.get(0) as WFile
}
Expand All @@ -144,7 +144,7 @@ class WollokRepl {
for (var i = 0; i < Integer.MAX_VALUE; i++) {
var syntheticUri = parsedMainFile.eResource.URI.trimFileExtension.trimSegments(1).appendSegment(name + i).
appendFileExtension(WollokConstants.PROGRAM_EXTENSION)
if (resourceSet.getResource(syntheticUri, false) == null) {
if (resourceSet.getResource(syntheticUri, false) === null) {
return syntheticUri
}
}
Expand All @@ -164,16 +164,6 @@ class WollokRepl {
whiteSpaces = ""
}

def dispatch void handleException(ReplParserException e) {
e.issues.forEach [
printlnIdent(errorStyle('''«severity.name»: «message» («LINE»: «lineNumber - numberOfLinesBefore»)'''))
]
}

def dispatch void handleException(Throwable e) {
println(e.stackTraceAsString.errorStyle)
}

def stackTraceAsString(Throwable e) {
val s = new ByteArrayOutputStream
e.printStackTrace(new PrintStream(s))
Expand All @@ -184,46 +174,38 @@ class WollokRepl {
2 + parsedMainFile.imports.size
}

def toLinkForConsole(StackTraceElementDTO st) {
st.contextForStackTrace.errorStyle + st.linkForStackTrace.linkStyle
}

def dispatch void handleException(ReplParserException e) {
e.issues.forEach [
printlnIdent(errorStyle('''«severity.name»: «message» («LINE»: «lineNumber - numberOfLinesBefore»)'''))
]
}

def dispatch void handleException(Throwable e) {
println(e.stackTraceAsString.errorStyle)
}

def dispatch void handleException(WollokProgramExceptionWrapper e) {
// Wollok-level user exception
//printlnIdent(filterREPLLines(e.wollokStackTrace).errorStyle)
println((e.exceptionClassName + ": " + e.wollokMessage).errorStyle)
val errorLine = e.wollokException
.convertStackTrace
.filter [ !it.shouldBeFiltered ]
.toList
.reverse
.map [ stackDTO | stackDTO.toLinkForConsole ]
.join(System.lineSeparator)

printlnIdent(errorLine.errorStyle)
}

def toLinkForConsole(StackTraceElementDTO st) {
val result = new StringBuffer => [
append(" ")
append("at")
append(" ")
if (st.contextDescription !== null) {
append(st.contextDescription)
append(" ")
}
]

var link = new StringBuffer
if (st.hasFileName) {
link.append("(" + st.fileName + ":" + st.lineNumber + ")")
}

result.toString.errorStyle + link.toString.linkStyle
}

def dispatch void handleException(WollokInterpreterException e) {
if (e.lineNumber > numberOfLinesBefore) {
printlnIdent('''«WVM_ERROR» («e.lineNumber - numberOfLinesBefore»): «e.nodeText»:'''.errorStyle)
}

if (e.cause != null) {
if (e.cause !== null) {
indent
handleException(e.cause)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import static org.uqbar.project.wollok.sdk.WollokDSK.*

import static extension org.uqbar.project.wollok.interpreter.nativeobj.WollokJavaConversions.*

import static extension org.uqbar.project.wollok.errorHandling.WollokExceptionExtensions.*

class WollokExceptionUtils {


Expand All @@ -31,30 +33,14 @@ class WollokExceptionUtils {
wollokException.internalStackTraceToDTO
}

private static def internalStackTraceToDTO(WollokObject fullStackTrace) {
val stackTrace = fullStackTrace.call("getFullStackTrace").wollokToJava(List) as List<WollokObject>
stackTrace.map [ wo |
val contextDescription = wo.call("contextDescription").wollokToJava(String) as String
val location = wo.call("location").wollokToJava(String) as String
val data = location.split(",")
val fileName = data.get(0)
var Integer lineNumber = 0
try {
lineNumber = new Integer(data.get(1))
} catch (NumberFormatException e) {
}
new StackTraceElementDTO(contextDescription, fileName, lineNumber)
]
}

/**
* Converts an exception to a String
*/
def static dispatch String convertToString(WollokProgramExceptionWrapper exception) {
val wollokException = exception.wollokException
val className = wollokException.call("className").wollokToJava(String) as String
val message = exception.wollokMessage
val concatMessage = if (message != null) ": " + message else ""
val concatMessage = if (message !== null) ": " + message else ""
return className + concatMessage
}

Expand All @@ -72,20 +58,20 @@ class WollokExceptionUtils {
* Prepares an exception for a RMI call
*/
def static dispatch void prepareExceptionForTrip(Throwable e) {
if (e.cause != null)
if (e.cause !== null)
e.cause.prepareExceptionForTrip
}

def static dispatch void prepareExceptionForTrip(WollokInterpreterException e) {
e.sourceElement = null

if (e.cause != null)
if (e.cause !== null)
e.cause.prepareExceptionForTrip
}

def static dispatch void prepareExceptionForTrip(WollokProgramExceptionWrapper e) {
e.URI = null
if (e.cause != null)
if (e.cause !== null)
e.cause.prepareExceptionForTrip
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,6 @@ class WollokReplConsoleViewer extends TextConsoleViewer {
styledText.setLeftMargin(Math.max(styledText.getLeftMargin(), 2))
return styledText
}


}
Loading

0 comments on commit 59662d5

Please sign in to comment.