Skip to content

Commit

Permalink
Feature removing constructors (#1978)
Browse files Browse the repository at this point in the history
* Fix #1916 Class initialization including mixins

* First step: removing WConstructor from class & removing compiler errors

* WIP: fixing tests

* Fix all xpect tests

* Fixing tests wollok-language - pointing to new branch

* Removing WConstructor, WSelf & WSuperDelegatingConstructorCall from xtext definition

* Removing fixture - build

* Removing fixture - fixing tests

* Fixing initialize method bug

* Removing validation for override and super in initialize method

* WIP - specification pending

* Adding lazy definition of variables & initializers

* Removing println

* New wollok-language version

* Updating wollok language commit with last changes

* Changes requested by @nscarcella

* Fixing unit tests

* Fix Mixin validation for uninitialized references

* Fix mixed method container instantiation for named parameters

* Fixing named object passing parameters to parent class

* Fix named object test

* Refactored & added object literal validation

* Adding more tests

* Solving lazy problems

* Moving tests to wollok-language

* Removing duplicated tests

* Enhancing initialization attributes for Named Object & Object literals

* Merging last changes from wollok-language/master

* Moving sanity tests to Wollok Xtext until we discuss lazy feature = uqbar-project/wollok-language#90

* Upgrading wollok-language

* Pointing to wollok-language merged version => release 3.0.0
  • Loading branch information
fdodino committed Feb 14, 2021
1 parent 1183b94 commit 0ac87bb
Show file tree
Hide file tree
Showing 90 changed files with 698 additions and 3,622 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ class WollokLauncherInterpreterEvaluator extends WollokInterpreterEvaluator {
// If in a suite, we should create a suite wko so this will be our current context to eval the tests
try {
val suiteObject = new SuiteBuilder(suite, interpreter).forTest(test).build
interpreter.performOnStack(test, suiteObject, [ | test.eval])
interpreter.performOnStack(test, suiteObject, [ |
test.eval
])
} catch (Exception e) {
handleExceptionInTest(e, test)
}
Expand Down Expand Up @@ -146,18 +148,17 @@ class SuiteBuilder {
// Suite -> suite wko
val suiteObject = new WollokObject(interpreter, suite)
// Declaring suite variables as suite wko instance variables
suite.members.forEach [ member |
suiteObject.addMember(member)
suite.variableDeclarations.forEach [ attribute |
suiteObject.addMember(attribute)
suiteObject.initializeAttribute(attribute)
]
if (suite.fixture !== null) {
suite.fixture.elements.forEach [ element |
interpreter.performOnStack(test, suiteObject, [| interpreter.eval(element) ])
]
}
if (suite.initializeMethod !== null) {
interpreter.performOnStack(test, suiteObject, [| interpreter.eval(suite.initializeMethod.expression) ])
}
if (test !== null) {
// Now, declaring test local variables as suite wko instance variables
test.variableDeclarations.forEach[ variable |
suiteObject.addMember(variable, false)
test.variableDeclarations.forEach[ attribute |
suiteObject.addMember(attribute)
]
}
suiteObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import org.eclipse.xtext.documentation.impl.MultiLineCommentDocumentationProvide
import org.uqbar.project.wollok.WollokConstants
import org.uqbar.project.wollok.launch.WollokChecker
import org.uqbar.project.wollok.launch.WollokLauncherParameters
import org.uqbar.project.wollok.wollokDsl.WClass
import org.uqbar.project.wollok.wollokDsl.WConstructor
import org.uqbar.project.wollok.wollokDsl.WFile
import org.uqbar.project.wollok.wollokDsl.WMethodContainer
import org.uqbar.project.wollok.wollokDsl.WMethodDeclaration
Expand Down Expand Up @@ -186,11 +184,6 @@ class WollokDocParser extends WollokChecker {
def dispatch void generateWollokDoc(EObject o) {
}

def dispatch void generateWollokDoc(WConstructor c) {
writeFile(BOLD_ON + WollokConstants.CONSTRUCTOR + BOLD_OFF + "(" + c.parameters.map[name].join(", ") + ")")
c.showComment
}

def dispatch void generateWollokDoc(WMethodDeclaration m) {
val comment = m.comment
if (m.originalComment.contains(PRIVATE)) {
Expand All @@ -215,21 +208,10 @@ class WollokDocParser extends WollokChecker {
writeFile(TABLE_ROW_OFF)
}

def dispatch getDefinedConstructors(WMethodContainer mc) { newArrayList }
def dispatch getDefinedConstructors(WClass c) { c.constructors }

def dispatch void generateWollokDoc(WMethodContainer mc) {
header(mc.imageName + SPACE + mc.name, mc.name)
writeFile(showHierarchy(mc))
mc.showComment
val constructors = mc.definedConstructors
if (!constructors.isEmpty) {
header2("Constructors")
writeFile(TABLE_ON)
constructors.forEach [ generateWollokDoc ]
writeFile(TABLE_OFF)
writeFile(HORIZONTAL_LINE)
}
val attributes = mc.variableDeclarations
if (!attributes.isEmpty) {
header2("Attributes")
Expand All @@ -251,7 +233,7 @@ class WollokDocParser extends WollokChecker {
writeInheritedMethods(mc)
writeFile(HORIZONTAL_LINE)
}
if (constructors.isEmpty && mc.methods.isEmpty) {
if (mc.methods.isEmpty) {
writeFile(HORIZONTAL_LINE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,6 @@ var nombre = ""
var bloqueNumeroPositivo = { num => num > 0 }
constructor(canciones) {
nombre = "MASHUP" + self.concatenarNombres(canciones)
duracion = self.cancionMasLarga(canciones)
letra = self.concatenarCanciones(canciones).trim()
}
Expand All @@ -415,12 +410,6 @@ var nombre = ""
var letra = ""
var bloqueNumeroPositivo = { num => num > 0 }
constructor(canciones) {
nombre = "MASHUP" + self.concatenarNombres(canciones)
duracion = self.cancionMasLarga(canciones)
letra = self.concatenarCanciones(canciones).trim()
}
method concatenarNombres(canciones) {
return canciones.fold("", { acum , cancion => acum + cancion.nombre() })
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.uqbar.project.wollok.tests.formatter

import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.Test
import org.junit.runner.RunWith
import org.uqbar.project.wollok.tests.injectors.WollokTestInjectorProvider

@RunWith(XtextRunner)
@InjectWith(WollokTestInjectorProvider)
class ConstructorCallsFormatterTestCase extends AbstractWollokFormatterTestCase {

@Test
def void constructorCallFormatting() throws Exception {
assertFormatting('''
class A { var a
var b = 2 var c var d
}
class B {
method buildA() {
new A( a
=
200
,
b = "Hello"
,
c = new Date()
, d=#{1 , 8} )
}
''',
'''
class A {
var a
var b = 2
var c
var d
}
class B {
method buildA() {
new A(a = 200, b = "Hello", c = new Date(), d = #{ 1, 8 })
}
}
''')
}
}
Loading

0 comments on commit 0ac87bb

Please sign in to comment.