From 36c417458df2f18554f8ead1e3b0ca045270089a Mon Sep 17 00:00:00 2001 From: cacaodev Date: Sun, 27 Dec 2015 22:08:30 +0100 Subject: [PATCH] STYLE: replaced expression methods with accessors Also added methods and documentation for the new methods: -trueExpression, -falseExpression and -expressionBlock. Completed documentation for -predicate and -arguments. --- .../CPPredicate/_CPAggregateExpression.j | 7 +--- Foundation/CPPredicate/_CPBlockExpression.j | 14 +------ .../CPPredicate/_CPConditionalExpression.j | 21 ++-------- .../CPPredicate/_CPConstantValueExpression.j | 7 +--- Foundation/CPPredicate/_CPExpression.j | 39 +++++++++++++++++-- .../CPPredicate/_CPFunctionExpression.j | 14 +------ Foundation/CPPredicate/_CPSetExpression.j | 14 +------ .../CPPredicate/_CPSubqueryExpression.j | 14 +------ .../CPPredicate/_CPVariableExpression.j | 7 +--- 9 files changed, 50 insertions(+), 87 deletions(-) diff --git a/Foundation/CPPredicate/_CPAggregateExpression.j b/Foundation/CPPredicate/_CPAggregateExpression.j index 688166398..2216c959c 100644 --- a/Foundation/CPPredicate/_CPAggregateExpression.j +++ b/Foundation/CPPredicate/_CPAggregateExpression.j @@ -25,7 +25,7 @@ @implementation _CPAggregateExpression : CPExpression { - CPArray _aggregate; + CPArray _aggregate @accessors(getter=collection); } - (id)initWithAggregate:(CPArray)collection @@ -48,11 +48,6 @@ return YES; } -- (id)collection -{ - return _aggregate; -} - - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { var eval_array = [CPArray array], diff --git a/Foundation/CPPredicate/_CPBlockExpression.j b/Foundation/CPPredicate/_CPBlockExpression.j index 10a007205..299f250ee 100644 --- a/Foundation/CPPredicate/_CPBlockExpression.j +++ b/Foundation/CPPredicate/_CPBlockExpression.j @@ -23,8 +23,8 @@ @implementation _CPBlockExpression : CPExpression { - Function _block; - CPArray _arguments; + Function _block @accessors(getter=expressionBlock); + CPArray _arguments @accessors(getter=arguments); } - (id)initWithBlock:(Function)aBlock arguments:(CPArray)arguments @@ -51,16 +51,6 @@ return YES; } -- (Function)expressionBlock -{ - return _block; -} - -- (CPArray)arguments -{ - return _arguments; -} - - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { var args = []; diff --git a/Foundation/CPPredicate/_CPConditionalExpression.j b/Foundation/CPPredicate/_CPConditionalExpression.j index 86926e392..8fc544580 100644 --- a/Foundation/CPPredicate/_CPConditionalExpression.j +++ b/Foundation/CPPredicate/_CPConditionalExpression.j @@ -23,9 +23,9 @@ @implementation _CPConditionalExpression : CPExpression { - CPPredicate _predicate; - CPExpression _trueExpression; - CPExpression _falseExpression; + CPPredicate _predicate @accessors(getter=predicate); + CPExpression _trueExpression @accessors(getter=trueExpression); + CPExpression _falseExpression @accessors(getter=falseExpression); } - (id)initWithPredicate:(CPPredicate)aPredicate trueExpression:(CPExpression)trueExpression falseExpression:(CPExpression)falseExpression @@ -53,21 +53,6 @@ return YES; } -- (CPPredicate)predicate -{ - return _predicate; -} - -- (CPExpression)trueExpression -{ - return _trueExpression; -} - -- (CPExpression)falseExpression -{ - return _falseExpression; -} - - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { var eval = [_predicate evaluateWithObject:object substitutionVariables:context], diff --git a/Foundation/CPPredicate/_CPConstantValueExpression.j b/Foundation/CPPredicate/_CPConstantValueExpression.j index 617c9b10a..81fd60b2e 100644 --- a/Foundation/CPPredicate/_CPConstantValueExpression.j +++ b/Foundation/CPPredicate/_CPConstantValueExpression.j @@ -27,7 +27,7 @@ @implementation _CPConstantValueExpression : CPExpression { - id _value; + id _value @accessors(getter=constantValue); } - (id)initWithValue:(id)value @@ -51,11 +51,6 @@ return YES; } -- (id)constantValue -{ - return _value; -} - - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { return _value; diff --git a/Foundation/CPPredicate/_CPExpression.j b/Foundation/CPPredicate/_CPExpression.j index b26707fc0..8a671c5b2 100644 --- a/Foundation/CPPredicate/_CPExpression.j +++ b/Foundation/CPPredicate/_CPExpression.j @@ -350,7 +350,7 @@ A dictionary that the expression can use to store temporary state for one predic /*! Returns the arguments for the receiver. - @return The arguments for the receiver—that is, the array of expressions that will be passed as parameters during invocation of the selector on the operand of a function expression. + @return The arguments for the receiver—that is, the array of expressions that will be passed as parameters during invocation of the selector on the operand of a function expression or as a parameter of the block of a block expression. This method raises an exception if it is not applicable to the receiver. */ - (CPArray)arguments @@ -371,8 +371,8 @@ A dictionary that the expression can use to store temporary state for one predic } /*! - Returns the predicate in a subquery expression. - @return The predicate in a subquery expression.. + Returns the predicate in a subquery expression or a conditional expression. + @return The predicate in a subquery expression or a conditional expression. This method raises an exception if it is not applicable to the receiver. */ - (CPPredicate)predicate @@ -414,6 +414,39 @@ A dictionary that the expression can use to store temporary state for one predic return nil; } +/*! + Returns the block of a block expression. + @return The block of a block expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (Function)expressionBlock +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the true expression of a conditional expression. + @return The true expression of a conditional expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPExpression)trueExpression +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + +/*! + Returns the false expression of a conditional expression. + @return The false expression of a conditional expression. + This method raises an exception if it is not applicable to the receiver. +*/ +- (CPExpression)falseExpression +{ + _CPRaiseInvalidAbstractInvocation(self, _cmd); + return nil; +} + - (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables { return self; diff --git a/Foundation/CPPredicate/_CPFunctionExpression.j b/Foundation/CPPredicate/_CPFunctionExpression.j index 394c93612..32790d4e4 100644 --- a/Foundation/CPPredicate/_CPFunctionExpression.j +++ b/Foundation/CPPredicate/_CPFunctionExpression.j @@ -28,9 +28,9 @@ @implementation _CPFunctionExpression : CPExpression { - CPExpression _operand; + CPExpression _operand @accessors(getter=operand); SEL _selector; - CPArray _arguments; + CPArray _arguments @accessors(getter=arguments); int _argc; int _maxargs; } @@ -88,16 +88,6 @@ return [self _function]; } -- (CPArray)arguments -{ - return _arguments; -} - -- (CPExpression)operand -{ - return _operand; -} - - (id)expressionValueWithObject:(id)object context:(CPDictionary)context { var target = [_operand expressionValueWithObject:object context:context], diff --git a/Foundation/CPPredicate/_CPSetExpression.j b/Foundation/CPPredicate/_CPSetExpression.j index a0e9df3bb..707486b32 100644 --- a/Foundation/CPPredicate/_CPSetExpression.j +++ b/Foundation/CPPredicate/_CPSetExpression.j @@ -25,8 +25,8 @@ @implementation _CPSetExpression : CPExpression { - CPExpression _left; - CPExpression _right; + CPExpression _left @accessors(getter=leftExpression); + CPExpression _right @accessors(getter=rightExpression); } - (id)initWithType:(int)type left:(CPExpression)left right:(CPExpression)right @@ -88,16 +88,6 @@ return self; } -- (CPExpression)leftExpression -{ - return _left; -} - -- (CPExpression)rightExpression -{ - return _right; -} - - (CPString)description { var desc; diff --git a/Foundation/CPPredicate/_CPSubqueryExpression.j b/Foundation/CPPredicate/_CPSubqueryExpression.j index e8f648403..d69483d2c 100644 --- a/Foundation/CPPredicate/_CPSubqueryExpression.j +++ b/Foundation/CPPredicate/_CPSubqueryExpression.j @@ -26,9 +26,9 @@ @implementation _CPSubqueryExpression : CPExpression { - CPExpression _collection; + CPExpression _collection @accessors(getter=collection); CPExpression _variableExpression; - CPPredicate _subpredicate; + CPPredicate _subpredicate @accessors(getter=predicate); } - (id)initWithExpression:(CPExpression)collection usingIteratorVariable:(CPString)variable predicate:(CPPredicate)subpredicate @@ -81,21 +81,11 @@ return YES; } -- (CPExpression)collection -{ - return _collection; -} - - (id)copy { return [[_CPSubqueryExpression alloc] initWithExpression:[_collection copy] usingIteratorExpression:[_variableExpression copy] predicate:[_subpredicate copy]]; } -- (CPPredicate)predicate -{ - return _subpredicate; -} - - (CPString)description { return [self predicateFormat]; diff --git a/Foundation/CPPredicate/_CPVariableExpression.j b/Foundation/CPPredicate/_CPVariableExpression.j index 910ef23d5..a33911222 100644 --- a/Foundation/CPPredicate/_CPVariableExpression.j +++ b/Foundation/CPPredicate/_CPVariableExpression.j @@ -29,7 +29,7 @@ @implementation _CPVariableExpression : CPExpression { - CPString _variable; + CPString _variable @accessors(getter=variable); } - (id)initWithVariable:(CPString)variable @@ -54,11 +54,6 @@ return YES; } -- (CPString)variable -{ - return _variable; -} - - (id)expressionValueWithObject:object context:(CPDictionary)context { var expression = [self _expressionWithSubstitutionVariables:context];