Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/uqbar-project/wollok into po…
Browse files Browse the repository at this point in the history
…lymorphic-method-type
  • Loading branch information
PalumboN committed Jun 7, 2020
2 parents 82426ee + 05a1100 commit e34b5f3
Show file tree
Hide file tree
Showing 40 changed files with 223 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ class XDebugStackFrame implements Serializable {

def static toVariable(WVariable variable, EvaluationContext<WollokObject> context) {
if (allVariables.contains(variable)) {
return new XDebugStackFrameVariable(variable, null) // Evita que el listener entre en loop infinito por referencias circulares. Luego el diagrama de objetos enlaza los objetos por id interno.
// Evita que el listener entre en loop infinito por referencias circulares. (parte 1)
// Luego el diagrama de objetos enlaza los objetos por id interno.
return new XDebugStackFrameVariable(variable, null)
}
val value = allValues.get(variable)
if (value !== null) {
return new XDebugStackFrameVariable(variable, value)
}
allVariables.add(variable)
val newValue = context.resolve(variable.name)
allValues.put(variable, newValue)
new XDebugStackFrameVariable(variable, newValue)
val result = new XDebugStackFrameVariable(variable, newValue)
result
}

def static initAllVariables() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.interpreter.context.WVariable
import org.uqbar.project.wollok.interpreter.core.WollokObject

import static org.uqbar.project.wollok.debugger.server.rmi.XDebugStackFrame.*
import static org.uqbar.project.wollok.sdk.WollokSDK.*

/**
Expand All @@ -20,7 +21,22 @@ class XDebugStackFrameVariable implements Serializable {

new(WVariable variable, WollokObject value) {
this.variable = variable
this.value = if (value === null) null else value.asRemoteValue
if (value === null) {
this.value = null
return
}
this.value = variable.getRemoteValue(value)
}

def getRemoteValue(WVariable variable, WollokObject value) {
val valueIdentifier = value.call("identity").toString
val allVariableIds = XDebugStackFrame.allVariables.map [ id.toString ]
if (allVariableIds.contains(valueIdentifier)) {
return null
}
allVariables.add(variable)
allValues.put(variable, value)
value.asRemoteValue
}

def asRemoteValue(WollokObject object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ abstract class XWollokCollectionDebugValue extends XDebugValue {
new(WollokObject collection, String concreteNativeType, String collectionType) {
super(collectionType, System.identityHashCode(collection))
this.concreteNativeType = concreteNativeType
var i = 0
val result = newArrayList
val elements = collection.getElements(concreteNativeType)
for (e : elements) {
result.add(new XDebugStackFrameVariable(new WVariable(i.getVariableName(collection, concreteNativeType), System.identityHashCode(e), false), e))
i++
}
elements.forEach [ element, i |
result.add(new XDebugStackFrameVariable(new WVariable(i.getVariableName(collection, concreteNativeType), System.identityHashCode(element), false), element))
]
variables = newArrayList(result)
}

Expand Down Expand Up @@ -74,7 +72,8 @@ class XWollokDictionaryDebugValue extends XWollokCollectionDebugValue {

override getVariableName(int i, WollokObject collection, String concreteNativeType) {
val wrapped = collection.getNativeObject(concreteNativeType) as WDictionary
wrapped.keys.get(i).asString
val key = wrapped.keys.get(i)
if (key !== null) key.asString else "null"
}

override getElements(WollokObject collection, String concreteNativeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import static extension org.uqbar.project.wollok.interpreter.core.ToStringBuilde
import static extension org.uqbar.project.wollok.model.WollokModelExtensions.*
import static extension org.uqbar.project.wollok.utils.WollokObjectUtils.*
import static extension org.uqbar.project.wollok.sdk.WollokSDK.*
import static org.uqbar.project.wollok.WollokConstants.*

/**
* A stack frame variable's value that holds a wollok object.
Expand All @@ -29,11 +30,11 @@ class XWollokObjectDebugValue extends XDebugValue {

def static description(WollokObject obj) {
if (obj.isBasicType) {
obj.asString("toSmartString",obj)
obj.asString(TO_STRING_PRINTABLE)
}
else {
if (obj.hasShortDescription)
obj.asString("shortDescription")
obj.asString(TO_STRING_SHORT)
else obj.shortLabel
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import org.uqbar.project.wollok.launch.WollokLauncher
import org.uqbar.project.wollok.wollokDsl.WFile

import static org.uqbar.project.wollok.launch.Messages.*
import static org.uqbar.project.wollok.sdk.WollokSDK.*

import static extension org.uqbar.project.wollok.errorHandling.WollokExceptionExtensions.*
import static extension org.uqbar.project.wollok.model.WollokModelExtensions.*
import static org.uqbar.project.wollok.WollokConstants.*

/**
*
Expand Down Expand Up @@ -144,12 +146,8 @@ class WollokRepl {
}

def dispatch doPrintReturnValue(WollokObject wo) {
println(wo?.call("printString").toString.returnStyle)
}

// Unused
def dispatch doPrintReturnValue(String obj) {
println(('"' + obj + '"').returnStyle)
val toStringMethod = if (wo.kind.fqn.equals(STRING)) TO_STRING_PRINTABLE else TO_STRING
println(wo?.call(toStringMethod).toString.returnStyle)
}

def parseRepl(CharSequence content, File mainFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class WBoolean extends AbstractJavaWrapper<Boolean> {

@NativeMessage("toString")
def wollokToString() { wrapped.toString }
def toSmartString(Object alreadyShown) { wollokToString }

@NativeMessage("==")
def wollokEquals(WollokObject other) {
Expand Down
2 changes: 1 addition & 1 deletion org.uqbar.project.wollok.lib/src/wollok/lang/WObject.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class WObject {
instVarName.checkNotNull("resolve")
obj.resolve(instVarName)
}

def newInstance(String className, Object... arguments) {
val wArgs = arguments.map[javaToWollok]
(interpreter.evaluator as WollokInterpreterEvaluator).newInstance(className, wArgs)
Expand Down
25 changes: 12 additions & 13 deletions org.uqbar.project.wollok.lib/src/wollok/lang/WString.xtend
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ class WString extends AbstractJavaWrapper<String> {
def dispatch WollokObject doConcatWith(WString o) { newInstanceWithWrapped(this.wrapped + o.wrapped) }
def dispatch WollokObject doConcatWith(WollokObject it) { convertToWString.asWString.doConcatWith }

def startsWith(String other) {
other.checkNotNull("startsWith")
wrapped.startsWith(other)
def startsWith(String prefix) {
prefix.checkNotNull("startsWith")
wrapped.startsWith(prefix)
}

def endsWith(String other) {
other.checkNotNull("endsWith")
wrapped.endsWith(other)
def endsWith(String suffix) {
suffix.checkNotNull("endsWith")
wrapped.endsWith(suffix)
}

def indexOf(String other) {
Expand All @@ -54,9 +54,9 @@ class WString extends AbstractJavaWrapper<String> {
result
}

def contains(String other) {
other.checkNotNull("contains")
wrapped.contains(other)
def contains(String element) {
element.checkNotNull("contains")
wrapped.contains(element)
}

def toLowerCase() { wrapped.toLowerCase }
Expand All @@ -69,15 +69,14 @@ class WString extends AbstractJavaWrapper<String> {
wrapped.substring(index.coerceToPositiveInteger)
}

def substring(BigDecimal startIndex, BigDecimal length) {
def substring(BigDecimal startIndex, BigDecimal endIndex) {
startIndex.checkNotNull("substring")
length.checkNotNull("substring")
wrapped.substring(startIndex.coerceToPositiveInteger, length.coerceToPositiveInteger)
endIndex.checkNotNull("substring")
wrapped.substring(startIndex.coerceToPositiveInteger, endIndex.coerceToPositiveInteger)
}

@NativeMessage("toString")
def wollokToString() { wrapped.toString }
def toSmartString(Object alreadyShown) { '"' + wollokToString + '"' }

@NativeMessage("<")
def lessThan(WollokObject other) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class WollokObjectComparator implements Comparator<WollokObject> {
}

static def defaultOrderingKey(WollokObject object) {
object.kind.fqn + object.toString + object.hashCode
}
object.kind.fqn + object.hashCode
}
}

/**
Expand Down
38 changes: 38 additions & 0 deletions org.uqbar.project.wollok.lib/src/wollok/mirror/WObjectMirror.xtend
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package wollok.mirror

import org.eclipse.xtend.lib.annotations.Accessors
import org.uqbar.project.wollok.interpreter.WollokInterpreter
import org.uqbar.project.wollok.interpreter.core.WollokObject
import wollok.lang.WObject

@Accessors(PUBLIC_GETTER)
class WObjectMirror {

WollokObject obj
WollokInterpreter interpreter

new(WollokObject obj, WollokInterpreter interpreter) {
this.obj = obj
this.interpreter = interpreter
}

def WollokObject resolve(String attributeName) {
internalTarget.resolve(attributeName)
}

def instanceVariables() {
internalTarget.instanceVariables
}

def instanceVariableFor(String name) {
internalTarget.instanceVariableFor(name)
}

def target() {
obj.resolve("target") as WollokObject
}

def internalTarget() {
new WObject(target, interpreter)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
<repository location="http://dl.bintray.com/wollok/sgit-update-site/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://ci.eclipse.org/xpect/job/Xpect/job/master/lastSuccessfulBuild/artifact/org.eclipse.xpect.releng/p2-repository/target/repository/"/>
<unit id="org.eclipse.xpect.sdk.feature.group" version="0.2.0.201907311039"/>
<unit id="org.eclipse.xpect.xtext.lib.feature.feature.group" version="0.2.0.201907311039"/>
<unit id="org.eclipse.xpect.xtext.xbase.lib.feature.feature.group" version="0.2.0.201907311039"/>
<repository location="https://ci.eclipse.org/xpect/job/Xpect/job/release_0.2.0/lastBuild/artifact/org.eclipse.xpect.releng/p2-repository/target/repository/"/>
<unit id="org.eclipse.xpect.sdk.feature.group" version="0.2.0.v20190619"/>
<unit id="org.eclipse.xpect.xtext.lib.feature.feature.group" version="0.2.0.v20190619"/>
<unit id="org.eclipse.xpect.xtext.xbase.lib.feature.feature.group" version="0.2.0.v20190619"/>
</location>
</locations>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class RecursiveToStringTestCase extends AbstractWollokInterpreterTestCase {
obj2.setY(obj1)
obj1.addX(new Prb())
assert.equals('obj2[y=obj1[x=[obj2, a Prb[]]]]', obj2.toString())
assert.equals('obj2', obj2.toString())
}
'''.interpretPropagatingErrors
}
Expand Down Expand Up @@ -70,7 +70,7 @@ class RecursiveToStringTestCase extends AbstractWollokInterpreterTestCase {
cuenta.duenios().add(duenio)
cuenta.metodoInexistente()
} catch e {
assert.equals("a Cuenta[duenios=[a Duenio[cuentas=[a Cuenta]]]] does not understand metodoInexistente()", e.message())
assert.equals("a Cuenta does not understand metodoInexistente()", e.message())
}
}
'''.interpretPropagatingErrors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ class MixinsTestCase extends AbstractWollokInterpreterTestCase {
}

@Test
def void toString1() {
def void toStringMixedMethodContainer1Mixin() {
'''
«toStringFixture»
test "toString de un mixed method container con 1 mixin" {
const pm = new Persona() with EnvejeceDoble
assert.equals(pm.toString(), "Persona with EnvejeceDoble[edad=10]")
assert.equals(pm.toString(), "Persona with EnvejeceDoble")
}
'''.interpretPropagatingErrors
}

@Test
def void toString2() {
def void toStringMixedContainerWith2Mixins() {
'''
«toStringFixture»
test "toString de un mixed method container con 2 mixins" {
const pm = new Persona() with EnvejeceDoble with EnvejeceTriple
assert.equals(pm.toString(), "Persona with EnvejeceDoble with EnvejeceTriple[edad=10]")
assert.equals(pm.toString(), "Persona with EnvejeceDoble with EnvejeceTriple")
}
'''.interpretPropagatingErrors
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ class WollokLibraryHealthyTest extends AbstractWollokInterpreterTestCase {
.filter[severity == Severity.ERROR && code != 'OBJECT_NAME_MUST_START_LOWERCASE']
.forEach[ sb.append(severity).append(":").append(message).append(" ").append(uri).append(":").append(lineNumber).append(System.lineSeparator) ]
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ program natives {
assert.equals(1, true)
} catch e {
assert.equals(e.getStackTraceAsString(),
"wollok.lib.AssertionException: Expected [1] but found [true]
"wollok.lib.AssertionException: Expected <1> but found <true>
at wollok.lib.assert.equals(expected,actual) [/lib.wlk:72]
at [/assertTest.wpgm:3]
"
Expand Down
Loading

0 comments on commit e34b5f3

Please sign in to comment.