forked from atg/Ingredients
-
Notifications
You must be signed in to change notification settings - Fork 2
/
IGKPredicateEditor.m
137 lines (113 loc) · 3.11 KB
/
IGKPredicateEditor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// IGKPredicateEditor.m
// Ingredients
//
// Created by Alex Gordon on 23/03/2010.
// Written in 2010 by Fileability.
//
#import "IGKPredicateEditor.h"
@implementation IGKPredicateEditor
- (NSPredicate *)predicate
{
//We want to remove any null comparison predicates from our predicate
NSCompoundPredicate *predicate = (NSCompoundPredicate *)[super predicate];
if (!predicate)
return nil;
if ([predicate isKindOfClass:[NSComparisonPredicate class]])
{
predicate = [[NSCompoundPredicate alloc] initWithType:NSAndPredicateType subpredicates:[NSArray arrayWithObject:predicate]];
}
else if (![predicate isKindOfClass:[NSCompoundPredicate class]])
{
return predicate;
}
requestedEntityName = @"Any";
NSArray *subpredicates = [predicate subpredicates];
NSMutableArray *newSubpredicates = [[NSMutableArray alloc] initWithCapacity:[subpredicates count]];
for (NSComparisonPredicate *cmpP in subpredicates)
{
NSExpression *right = [cmpP rightExpression];
NSExpression *left = [cmpP leftExpression];
if([[left keyPath] isEqual:@"xkind"])
{
requestedEntityName = [right constantValue];
continue;
}
if ([right expressionType] != NSConstantValueExpressionType)
{
[newSubpredicates addObject:cmpP];
continue;
}
id cv = [right constantValue];
if (cv && (![cv respondsToSelector:@selector(length)] || [cv length] > 0))
{
[newSubpredicates addObject:cmpP];
}
}
return [[NSCompoundPredicate alloc] initWithType:[predicate compoundPredicateType] subpredicates:newSubpredicates];
}
- (NSPredicate *)predicateWithEntityNamed:(NSString **)outEntityName
{
NSPredicate *newPredicate = [self predicate];
if (outEntityName != NULL)
{
if([requestedEntityName isEqual:@"Class"])
{
requestedEntityName = @"ObjCClass";
}
else if([requestedEntityName isEqual:@"Function Group"])
{
requestedEntityName = @"FunctionContainer";
}
else if([requestedEntityName isEqual:@"Category"])
{
requestedEntityName = @"ObjCCategory";
}
else if([requestedEntityName isEqual:@"Protocol"])
{
requestedEntityName = @"ObjCProtocol";
}
else if([requestedEntityName isEqual:@"Bindings"])
{
requestedEntityName = @"ObjCBindingsListing";
}
else if([requestedEntityName isEqual:@"Method"])
{
requestedEntityName = @"ObjCMethod";
}
else if([requestedEntityName isEqual:@"Property"])
{
requestedEntityName = @"ObjCProperty";
}
else if([requestedEntityName isEqual:@"Function"])
{
requestedEntityName = @"CFunction";
}
else if([requestedEntityName isEqual:@"Notification"])
{
requestedEntityName = @"ObjCNotification";
}
else if([requestedEntityName isEqual:@"Global"])
{
requestedEntityName = @"CGlobal";
}
else if([requestedEntityName isEqual:@"Constant"])
{
requestedEntityName = @"CConstant";
}
else if([requestedEntityName isEqual:@"Enum"])
{
requestedEntityName = @"CEnum";
}
else if([requestedEntityName isEqual:@"Miscellaneous Type"])
{
requestedEntityName = @"CTypedef";
}
else {
requestedEntityName = @"DocRecord";
}
*outEntityName = requestedEntityName;
}
return newPredicate;
}
@end