FLEXRuntimeKeyPath.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // FLEXRuntimeKeyPath.m
  3. // FLEX
  4. //
  5. // Created by Tanner on 3/22/17.
  6. // Copyright © 2017 Tanner Bennett. All rights reserved.
  7. //
  8. #import "FLEXRuntimeKeyPath.h"
  9. #import "FLEXRuntimeClient.h"
  10. @interface FLEXRuntimeKeyPath () {
  11. NSString *flex_description;
  12. }
  13. @end
  14. @implementation FLEXRuntimeKeyPath
  15. + (instancetype)empty {
  16. static FLEXRuntimeKeyPath *empty = nil;
  17. static dispatch_once_t onceToken;
  18. dispatch_once(&onceToken, ^{
  19. FLEXSearchToken *any = FLEXSearchToken.any;
  20. empty = [self new];
  21. empty->_bundleKey = any;
  22. empty->flex_description = @"";
  23. });
  24. return empty;
  25. }
  26. + (instancetype)bundle:(FLEXSearchToken *)bundle
  27. class:(FLEXSearchToken *)cls
  28. method:(FLEXSearchToken *)method
  29. isInstance:(NSNumber *)instance
  30. string:(NSString *)keyPathString {
  31. FLEXRuntimeKeyPath *keyPath = [self new];
  32. keyPath->_bundleKey = bundle;
  33. keyPath->_classKey = cls;
  34. keyPath->_methodKey = method;
  35. keyPath->_instanceMethods = instance;
  36. // Remove irrelevant trailing '*' for equality purposes
  37. if ([keyPathString hasSuffix:@"*"]) {
  38. keyPathString = [keyPathString substringToIndex:keyPathString.length];
  39. }
  40. keyPath->flex_description = keyPathString;
  41. if (bundle.isAny && cls.isAny && method.isAny) {
  42. [FLEXRuntimeClient initializeWebKitLegacy];
  43. }
  44. return keyPath;
  45. }
  46. - (NSString *)description {
  47. return flex_description;
  48. }
  49. - (NSUInteger)hash {
  50. return flex_description.hash;
  51. }
  52. - (BOOL)isEqual:(id)object {
  53. if ([object isKindOfClass:[FLEXRuntimeKeyPath class]]) {
  54. FLEXRuntimeKeyPath *kp = object;
  55. return [flex_description isEqualToString:kp->flex_description];
  56. }
  57. return NO;
  58. }
  59. @end