Formatting, refactoring, use separate message for nil key

This commit is contained in:
Aparajita Fishman committed 2013-03-06 07:49:18 -05:00
1 parent af142a5ccc
commit 4b0b19aec7
2 files changed
+64 -34

No files matched your search

+4 -3
View File
@@ -1156,13 +1156,14 @@ The sum of the views and the sum of the dividers should be equal to the size of
{
_preCollapsePositions = [CPMutableDictionary new];
for (var i = 0, count = [preCollapseArray count]; i < count; i++) {
for (var i = 0, count = [preCollapseArray count]; i < count; i++)
{
var item = preCollapseArray[i];
if (item === nil)
[_preCollapsePositions removeObjectForKey:i + ""];
[_preCollapsePositions removeObjectForKey:String(i)];
else
[_preCollapsePositions setObject:item forKey:i + ""];
[_preCollapsePositions setObject:item forKey:String(i)];
}
}
}
+60 -31
View File
@@ -28,7 +28,7 @@
#import "Ref.h"
//FIXME: After release of 0.9.7 remove below variable
var deprecatedMessage = YES;
var CPDictionaryShowNilDeprecationMessage = YES;
/* @ignore */
@implementation _CPDictionaryValueEnumerator : CPEnumerator
@@ -257,24 +257,36 @@ var deprecatedMessage = YES;
self = [super init];
if ([objects count] != [keyArray count])
[CPException raise:CPInvalidArgumentException reason:"Counts are different.(" + [objects count] + "!=" + [keyArray count] + ")"];
[CPException raise:CPInvalidArgumentException reason:[CPString stringWithFormat:@"Counts are different.(%d != %d)", [objects count], [keyArray count]]];
if (self)
{
var i = [keyArray count];
while (i--) {
var aValue = objects[i],
aKey = keyArray[i];
while (i--)
{
var value = objects[i],
key = keyArray[i];
if (aValue === nil || aKey === nil) {
deprecatedMessage = NO;
CPLog.warn(@"[" + [self className] + @" " + _cmd + @"DEPRECATED: Attempt to insert nil object from objects[" + i + @"]");
if (value === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil object from objects[%d]", [self className], _cmd, i]);
objj_backtrace_print(CPLog.warn);
//FIXME: After release of 0.9.7 remove variable deprecatedMessage and change above line to this:
//[CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + i + @"]"];
// FIXME: After release of 0.9.7 change 3 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + i + @"]"];
}
[self setObject:aValue forKey:aKey];
if (key === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil key from keys[%d]", [self className], _cmd, i]);
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change 3 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil key from keys[" + i + @"]"];
}
[self setObject:value forKey:key];
}
}
@@ -312,17 +324,27 @@ var deprecatedMessage = YES;
for (; index < argCount; index += 2)
{
var value = arguments[index],
aKey = arguments[index + 1];
key = arguments[index + 1];
if (value === nil || aKey === nil) {
deprecatedMessage = NO;
CPLog.warn(@"[" + [self className] + @" " + _cmd + @"DEPRECATED: Attempt to insert nil object from objects[" + (index / 2 - 1) + @"]");
if (value === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil object from objects[%d]", [self className], _cmd, (index / 2) - 1]);
objj_backtrace_print(CPLog.warn);
//FIXME: After release of 0.9.7 remove variable deprecatedMessage and change above line to this:
//[CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + (index / 2 - 1) + @"]"];
// FIXME: After release of 0.9.7 change 3 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil object from objects[" + ((index / 2) - 1) + @"]"];
}
[self setObject:value forKey:aKey];
if (key === nil)
{
CPDictionaryShowNilDeprecationMessage = NO;
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: Attempt to insert nil key from keys[%d]", [self className], _cmd, (index / 2) - 1]);
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change 3 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"Attempt to insert nil key from keys[" + ((index / 2) - 1) + @"]"];
}
[self setObject:value forKey:key];
}
}
@@ -631,22 +653,29 @@ var deprecatedMessage = YES;
*/
- (void)setObject:(id)anObject forKey:(id)aKey
{
if (deprecatedMessage && aKey === nil) {
CPLog.warn(@"[" + [self className] + @" " + _cmd + @"] DEPRECATED: Key cannot be nil");
objj_backtrace_print(CPLog.warn);
//FIXME: After release of 0.9.7 change above line to this:
//[CPException raise:CPInvalidArgumentException reason:@"Key cannot be nil"];
}
// FIXME: After release of 0.9.7, remove this test and leave the contents of its block
if (CPDictionaryShowNilDeprecationMessage)
{
if (aKey === nil)
{
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: key cannot be nil", [self className], _cmd]);
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change 2 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"key cannot be nil"];
}
if (deprecatedMessage && anObject === nil) {
CPLog.warn(@"[" + [self className] + @" " + _cmd + @"] DEPRECATED: Object cannot be nil (key: " + aKey + @")");
objj_backtrace_print(CPLog.warn);
//FIXME: After release of 0.9.7 change above line to this:
//[CPException raise:CPInvalidArgumentException reason:@"Object cannot be nil (key: " + aKey + @")"];
if (anObject === nil)
{
CPLog.warn([CPString stringWithFormat:@"[%s %s] DEPRECATED: object cannot be nil (key: %s)", [self className], _cmd, aKey]);
objj_backtrace_print(CPLog.warn);
// FIXME: After release of 0.9.7 change 2 lines above to this:
// [CPException raise:CPInvalidArgumentException reason:@"object cannot be nil (key: " + aKey + @")"];
}
}
// FIXME: After release of 0.9.7 remove 2 lines below.
else
CPDictionaryShowNilDeprecationMessage = YES;
//FIXME: After release of 0.9.7 remove below line.
deprecatedMessage = YES;
self.setValueForKey(aKey, anObject);
}