Files
cappuccino/Foundation/CPPredicate/CPExpression_keypath.j
T
cacaodev ca289e081e CPPredicate parsing support:
"($)path.($)variable"
 "SUBQUERY(collection, $x,$x = 2)"
 "sum:(arg1, ...)"
 "FUNCTION(target, selector, arg1, ...)
 "object[expression]"
 "set UNION|INTERSECT|MINUS otherset"
Fixed a bug where CPExpression_set was evaluating to an expression instead of a set.
Replaced parsing exceptions with a generic function indicating where it failed.
2010-11-07 17:56:22 +01:00

63 lines
1.4 KiB
Plaintext

@import "CPExpression.j"
@import "CPExpression_function.j"
@import "CPString.j"
@import "CPKeyValueCoding.j"
@implementation CPExpression_keypath : CPExpression_function
{
}
- (id)initWithKeyPath:(CPString)keyPath
{
return [self initWithOperand:[CPExpression expressionForEvaluatedObject] andKeyPath:keyPath];
}
- (id)initWithOperand:(CPExpression)operand andKeyPath:(CPString)keyPath
{
var arg = [CPExpression expressionForConstantValue:keyPath];
// Cocoa: if it's a direct path selector is valueForKey:
self = [super initWithTarget:operand selector:@selector(valueForKeyPath:) arguments:[arg] type:CPKeyPathExpressionType];
return self;
}
- (BOOL)isEqual:(id)object
{
if (object === self)
return YES;
return ([object keyPath] == [self keyPath]); //If it appears that parsing generates nested keypaths with different targets and same keyPath, comparing -keyPath won't work.
}
- (CPExpression)pathExpression
{
return [[self arguments] objectAtIndex:0];
}
- (CPString)keyPath
{
return [[self pathExpression] keyPath];
}
- (CPString)description
{
var result = "";
if ([_operand expressionType] != CPEvaluatedObjectExpressionType)
result += [_operand description] + ".";
result += [self keyPath];
return result;
}
@end
@implementation CPExpression_constant (KeyPath)
- (CPString)keyPath
{
return [self constantValue];
}
@end