-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix uqbar-project/wollok-language#27 - mirror methods moved to object
- Loading branch information
Showing
13 changed files
with
126 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
org.uqbar.project.wollok.lib/src/wollok/mirror/WObjectMirror.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
org.uqbar.project.wollok.tests/src/org/uqbar/project/wollok/tests/sdk/MirrorTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.uqbar.project.wollok.tests.sdk | ||
|
||
import org.junit.Test | ||
import org.uqbar.project.wollok.tests.interpreter.AbstractWollokInterpreterTestCase | ||
|
||
class MirrorTest extends AbstractWollokInterpreterTestCase { | ||
|
||
@Test | ||
def void instanceVariableFor() { | ||
''' | ||
import wollok.mirror.ObjectMirror | ||
class Perro { | ||
var nombre = "Colita" | ||
var edad = 7 | ||
} | ||
program p { | ||
const perro = new Perro() | ||
const mirror = new ObjectMirror(target = perro) | ||
const instVar = mirror.instanceVariableFor("nombre") | ||
assert.that(instVar != null) | ||
assert.equals("nombre", instVar.name()) | ||
assert.equals("Colita", instVar.value()) | ||
} | ||
'''.interpretPropagatingErrors | ||
} | ||
|
||
@Test | ||
def void instanceVariables() { | ||
''' | ||
import wollok.mirror.ObjectMirror | ||
class Perro { | ||
var nombre = "Colita" | ||
var edad = 7 | ||
} | ||
program p { | ||
const perro = new Perro() | ||
const mirror = new ObjectMirror(target = perro) | ||
const instVars = mirror.instanceVariables() | ||
assert.equals(2, instVars.size()) | ||
const nombreInstVar = instVars.find{e=> e.name() == "nombre"} | ||
assert.equals("Colita", nombreInstVar.value()) | ||
const edadInstVar = instVars.find{e=> e.name() == "edad"} | ||
assert.equals(7, edadInstVar.value()) | ||
««« assert.equals("#[edad=7, nombre=Colita]",instVars.toString()) | ||
} | ||
'''.interpretPropagatingErrors | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule wollok-language
updated
3 files
+0 −18 | src/wollok/lang.wlk | |
+26 −1 | src/wollok/mirror.wlk | |
+32 −0 | test/sanity/mirror/instanceVariableMirror.wtest |