Skip to content

Commit

Permalink
Fixes #481 improving stack trace context description for methods and …
Browse files Browse the repository at this point in the history
…constructors
  • Loading branch information
javierfernandes committed Dec 14, 2015
1 parent 54b1ae0 commit 392979f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
1 change: 1 addition & 0 deletions org.uqbar.project.wollok.product.ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xtend-gen/
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.uqbar.project.wollok.interpreter.stack

import java.io.Serializable
import org.eclipse.emf.common.util.URI
import org.eclipse.xtend.lib.annotations.Accessors

/**
* Represents a source code segment.
Expand All @@ -11,13 +12,14 @@ import org.eclipse.emf.common.util.URI
*
* @author jfernandes
*/
@Accessors
class SourceCodeLocation implements Serializable {
@Property String fileURI
@Property int startLine
@Property int endLine
@Property int offset
@Property int length
@Property String contextDescription
var String fileURI
var int startLine
var int endLine
var int offset
var int length
var String contextDescription

new(URI fileURI, int startLine, int endLine, int offset, int length) {
this.fileURI = fileURI.toString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,10 @@ class WollokModelExtensions {
def static dispatch declaredVariables(WNamedObject obj) { obj.members.filter(WVariableDeclaration).map[variable] }
def static dispatch declaredVariables(WClass clazz) { clazz.members.filter(WVariableDeclaration).map[variable] }

def static WMethodDeclaration method(WExpression param) {
val container = param.eContainer
if (container instanceof WMethodDeclaration)
container
else if(container instanceof WExpression) container.method
// this is just a hack for expressions that are not within a method! Specifically
// for expressions in the root level of a file, like an interpreted program
// we are actually thinking on disallowing to do that, you won't be able to write
// any expression alone in a file. They must be within a class, object or other construction
// if we perform that change, then this null won't be necessary.
else null
}
def static dispatch WMethodDeclaration method(Void it) { null }
def static dispatch WMethodDeclaration method(EObject it) { null }
def static dispatch WMethodDeclaration method(WMethodDeclaration it) { it }
def static dispatch WMethodDeclaration method(WExpression it) { eContainer.method }

// ****************************
// ** transparent containers (in terms of debugging -maybe also could be used for visualizing, like outline?-)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import org.uqbar.project.wollok.wollokDsl.WExpression

import static extension org.uqbar.project.wollok.model.WMethodContainerExtensions.*
import static extension org.uqbar.project.wollok.model.WollokModelExtensions.*
import org.uqbar.project.wollok.wollokDsl.WMethodDeclaration
import org.uqbar.project.wollok.wollokDsl.WConstructor

/**
* Extension methods and utilities for xtext
Expand All @@ -25,13 +27,15 @@ class XTextExtensions {
def static toSourceCodeLocation(EObject o) {
o.astNode.textRegionWithLineInformation.toSourceCodeLocation(o.fileURI) => [ contextDescription = o.contextDescription ]
}
def static dispatch String contextDescription(EObject o) { null }
def static dispatch String contextDescription(WExpression e) {
val m = e.method
if (m != null)
m.declaringContext.contextName + "." + m.name + "(" + m.parameters.map[name].join(",") + ")"
else
null

def static dispatch String contextDescription(Void o) { null }
def static dispatch String contextDescription(EObject o) { /*println("No context for " + o) ;*/ null }
def static dispatch String contextDescription(WExpression e) { e.method.contextDescription }
def static dispatch String contextDescription(WMethodDeclaration m) {
m.declaringContext.contextName + "." + m.name + "(" + m.parameters.map[name].join(",") + ")"
}
def static dispatch String contextDescription(WConstructor m) {
m.declaringContext.contextName + "." + "(" + m.parameters.map[name].join(",") + ")"
}

def static toSourceCodeLocation(ITextRegionWithLineInformation t, URI file) {
Expand Down

0 comments on commit 392979f

Please sign in to comment.