-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed compiling of constructor and type reference. Fixed unary plus/minus. Added node.getRaw(). #14
Changes from all commits
2028a30
c7227e6
ae9228c
8f0569b
a3efad8
05fee8b
b47bc89
f5b05db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -15,6 +15,7 @@ | |||
*/ | ||||
|
||||
import {SpelNode} from './SpelNode'; | ||||
import {Stack} from '../lib/Stack'; | ||||
|
||||
/** | ||||
* Represents the invocation of a constructor. Either a constructor on a regular type or | ||||
|
@@ -29,13 +30,51 @@ import {SpelNode} from './SpelNode'; | |||
* @author Juergen Hoeller | ||||
* @since 3.0 | ||||
*/ | ||||
function createNode(position, left, right) { | ||||
var node = SpelNode.create('constructorref', position, left, right); | ||||
function createNode(position, dimensions, nodes) { | ||||
var isArray = nodes !== undefined; | ||||
var dimension; | ||||
if (isArray) { | ||||
dimension = dimensions.length && dimensions[0] && dimensions[0].getType() === 'number' ? dimensions[0].getValue() : null; | ||||
} else { | ||||
nodes = dimensions; | ||||
dimensions = undefined; | ||||
} | ||||
const [_qualifiedIdentifier, ...args] = nodes; | ||||
|
||||
var node = SpelNode.create('constructorref', position, ...nodes); | ||||
|
||||
node.getRaw = function () { | ||||
return dimension; | ||||
}; | ||||
|
||||
node.getValue = function (state) { | ||||
if (isArray && args.length <= 1) { | ||||
var compiledArgs = []; | ||||
|
||||
//populate arguments | ||||
args.forEach(function (arg) { | ||||
// reset the active context to root context for evaluating argument | ||||
const currentActiveContext = state.activeContext | ||||
state.activeContext = new Stack(); | ||||
state.activeContext.push(state.rootContext); | ||||
|
||||
// evaluate argument | ||||
compiledArgs.push(arg.getValue(state)); | ||||
|
||||
// reset the active context | ||||
state.activeContext = currentActiveContext; | ||||
}); | ||||
|
||||
if (args.length === 1) { | ||||
return compiledArgs[0]; | ||||
} else { | ||||
return dimension ? new Array(dimension) : []; | ||||
} | ||||
} | ||||
|
||||
throw { | ||||
name: 'MethodNotImplementedException', | ||||
message: 'BeanReference: Not implemented' | ||||
message: 'ConstructorReference: Not implemented' | ||||
} | ||||
Comment on lines
75
to
78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this throw be removed now since it's implemented? It looks like it's unreachable anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's implemented only for array construction: spel2js/src/ast/ConstructorReference.js Line 51 in f5b05db
For other classes it will throw ConstructorReference: Not implemented (just renamed typo here BeanReference -> ConstructorReference )
|
||||
}; | ||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line would create an empty array with dimension, not an array with 1 element.
Example in console:
See test for evaluating
new int[3]
:spel2js/test/spec/SpelExpressionEvaluator.spec.js
Lines 906 to 918 in f5b05db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, thanks