Skip to content
Browse files

Add license and little progress on test

  • Loading branch information...
1 parent 374c766 commit 624e0df9fa06db6b83a4a8db6a314af3c7f4c06f @chiquitinxx committed Sep 19, 2012
View
14 LICENSE.txt
@@ -0,0 +1,14 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
View
8 NOTICE.txt
@@ -0,0 +1,8 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the GScript Framework for Groovy. ==
+ =========================================================================
+
+ GScript Framework for Groovy
+ Copyright 2012 Developers and Contributors
View
68 src/main/groovy/org/yila/gscript/GsConverter.groovy
@@ -34,7 +34,8 @@ class GsConverter {
def printlnFunction
//When true, we dont add this no variables
- def dontAddMoreThis
+ //TODO remove this variable properly
+ //def dontAddMoreThis
def GsConverter() {
initFunctionNames()
@@ -170,6 +171,16 @@ class GsConverter {
addLine()
}
+ def translateClassName(String name) {
+ def result = name
+ def i
+ while ((i = result.indexOf('.'))>=0) {
+ result = result.substring(i+1)
+ }
+
+ result
+ }
+
def processClassNode(ClassNode node) {
//Starting class conversion
@@ -187,7 +198,7 @@ class GsConverter {
classNameStack.push(node.name)
variableScoping.push([])
- addScript("function gsCreate$node.name() {")
+ addScript("function gsCreate${translateClassName(node.name)}() {")
indent ++
addLine()
@@ -197,7 +208,7 @@ class GsConverter {
//Allowed inheritance
if (node.superClass.name != 'java.lang.Object') {
//println 'Allowed!'+ node.superClass.class.name
- addScript("var gSobject = gsCreate${node.superClass.name}();")
+ addScript("var gSobject = gsCreate${translateClassName(node.superClass.name)}();")
//We add to this class scope variables of fathers
variableScoping.peek().addAll(inheritedVariables[node.superClass.name])
@@ -234,6 +245,9 @@ class GsConverter {
//Methods
node?.methods?.each { //println 'method->'+it;
+ //Add too method names to variable scoping
+ variableScoping.peek().add(it.name)
+
processMethodNode(it,false)
}
@@ -255,9 +269,9 @@ class GsConverter {
}
if (!has1parameterConstructor) {
- addScript("gSobject.${node.name}1 = function(map) { gSpassMapToObject(map,this); return this;};")
+ addScript("gSobject.${translateClassName(node.name)}1 = function(map) { gSpassMapToObject(map,this); return this;};")
addLine()
- addScript("if (arguments.length==1) {gSobject.${node.name}1(arguments[0]); }")
+ addScript("if (arguments.length==1) {gSobject.${translateClassName(node.name)}1(arguments[0]); }")
addLine()
}
//if (!has0parameterConstructor) {
@@ -676,7 +690,8 @@ class GsConverter {
} else {
//Constructor have name with number of params on it
//addScript("gsCreate${expression.type.name}().${expression.type.name}${expression.arguments.expressions.size()}")
- addScript("gsCreate${expression.type.name}")
+ def name = translateClassName(expression.type.name)
+ addScript("gsCreate${name}")
}
"process${expression.arguments.class.simpleName}"(expression.arguments)
}
@@ -712,7 +727,7 @@ class GsConverter {
if (expression.objectExpression instanceof VariableExpression) {
if (expression.objectExpression.name == 'this') {
- dontAddMoreThis = true
+ //dontAddMoreThis = true
}
}
@@ -727,15 +742,15 @@ class GsConverter {
}
}
- dontAddMoreThis = false
+ //dontAddMoreThis = false
}
def processMethodCallExpression(MethodCallExpression expression) {
//println "MCE ${expression.objectExpression} - ${expression.methodAsString}"
if (expression.objectExpression instanceof VariableExpression) {
if (expression.objectExpression.name == 'this') {
- dontAddMoreThis = true
+ //dontAddMoreThis = true
}
}
@@ -749,19 +764,28 @@ class GsConverter {
} else if (expression.objectExpression instanceof VariableExpression &&
expression.objectExpression.name=='super') {
addScript("${superMethodBegin}${expression.methodAsString}")
- //Function times, with a number, have to put (number)
+ //Function times, with a number, have to put (number) in javascript
} else if (expression.methodAsString == 'times' && expression.objectExpression instanceof ConstantExpression) {
addScript('(')
"process${expression.objectExpression.class.simpleName}"(expression.objectExpression)
addScript(')')
addScript(".${expression.methodAsString}")
} else {
- "process${expression.objectExpression.class.simpleName}"(expression.objectExpression)
- addScript(".${expression.methodAsString}")
+ //A lot of times come with this
+ //println 'Maybe this->'+expression.objectExpression
+ if (expression.objectExpression instanceof VariableExpression &&
+ expression.objectExpression.name == 'this' &&
+ variableScoping.peek()?.contains(expression.methodAsString)) {
+ //Remove this and put gSobject for variable scoping
+ addScript("gSobject.${expression.methodAsString}")
+ } else {
+ "process${expression.objectExpression.class.simpleName}"(expression.objectExpression)
+ addScript(".${expression.methodAsString}")
+ }
}
"process${expression.arguments.class.simpleName}"(expression.arguments)
- dontAddMoreThis = false
+ //dontAddMoreThis = false
}
def processPostfixExpression(PostfixExpression expression) {
@@ -781,13 +805,19 @@ class GsConverter {
boolean first = true
actualScope = []
- expression.parameters?.each { param ->
- if (!first) {
- addScript(', ')
+ //If no parameters, we add it by defaul
+ if (!expression.parameters || expression.parameters.size()==0) {
+ addScript('it')
+ actualScope.add('it')
+ } else {
+ expression.parameters?.each { param ->
+ if (!first) {
+ addScript(', ')
+ }
+ actualScope.add(param.name)
+ addScript(param.name)
+ first = false
}
- actualScope.add(param.name)
- addScript(param.name)
- first = false
}
addScript(') {')
indent++
View
2 src/test/groovy/org/yila/gscript/TestAdvanced.groovy
@@ -45,7 +45,7 @@ class TestAdvanced extends Specification {
def 'super table' () {
when:
- //TODO packages in class names!
+ //TODO More stuff!
def result = readAndConvert('advanced/SuperTable',true)
then:
View
9 src/test/resources/advanced/SuperTable.groovy
@@ -13,12 +13,11 @@ class SuperTab {
items << object
}
- def addMultiple(head,number) {
+ def addMultiple(head,property,number) {
number.times {
def object = new Expando()
- object.name = head + it
- object.date = new Date()
- items << object
+ object."$property" = head + it
+ add object
}
}
@@ -28,7 +27,7 @@ class SuperTab {
}
def superTable = new SuperTab()
-superTable.addMultiple('Groovy ',10)
+superTable.addMultiple('Groovy ','name',10)
assert superTable.getItems()[0].name == 'Groovy 0'
assert superTable.getItems().size() == 10

0 comments on commit 624e0df

Please sign in to comment.
Something went wrong with that request. Please try again.