浏览代码

Instrument each constraint with a source location.

Akiva Leffert 10 年之前
父节点
当前提交
bbe5b2e49d
共有 4 个文件被更改,包括 74 次插入16 次删除
  1. 6 0
      SnapKit.xcodeproj/project.pbxproj
  2. 4 1
      Source/Constraint.swift
  3. 28 15
      Source/ConstraintDescription.swift
  4. 36 0
      Source/SourceLocation.swift

+ 6 - 0
SnapKit.xcodeproj/project.pbxproj

@@ -7,6 +7,8 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
+		779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; settings = {ASSET_TAGS = (); }; };
+		779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 779230431BCB6FC30027CF5F /* SourceLocation.swift */; settings = {ASSET_TAGS = (); }; };
 		EE4910981B19A26000A54F1F /* ViewController+SnapKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */; };
 		EE4910991B19A40200A54F1F /* SnapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EEBCC9D819CC627D0083B827 /* SnapKit.framework */; };
 		EE94F6091AC0F10A008767FF /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EE94F6081AC0F10A008767FF /* UIKit.framework */; };
@@ -51,6 +53,7 @@
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
+		779230431BCB6FC30027CF5F /* SourceLocation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SourceLocation.swift; sourceTree = "<group>"; };
 		EE4910971B19A26000A54F1F /* ViewController+SnapKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "ViewController+SnapKit.swift"; sourceTree = "<group>"; };
 		EE94F6081AC0F10A008767FF /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
 		EE94F60A1AC0F10F008767FF /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; };
@@ -156,6 +159,7 @@
 				EEFCF32B1AD910B900A425FA /* Debugging.swift */,
 				EECDB3621AC0C95C006BBC11 /* ConstraintRelation.swift */,
 				EECDB35F1AC0C95C006BBC11 /* ConstraintAttributes.swift */,
+				779230431BCB6FC30027CF5F /* SourceLocation.swift */,
 				EECDB36B1AC0C967006BBC11 /* Supporting Files */,
 				EECDB3681AC0C95C006BBC11 /* Tests */,
 			);
@@ -363,6 +367,7 @@
 				EECDB3711AC0C9A6006BBC11 /* EdgeInsets.swift in Sources */,
 				EE4910981B19A26000A54F1F /* ViewController+SnapKit.swift in Sources */,
 				EECDB36F1AC0C9A6006BBC11 /* ConstraintMaker.swift in Sources */,
+				779230441BCB6FC30027CF5F /* SourceLocation.swift in Sources */,
 				EECDB36D1AC0C9A6006BBC11 /* ConstraintAttributes.swift in Sources */,
 				EECDB3721AC0C9A6006BBC11 /* LayoutConstraint.swift in Sources */,
 				EECDB36E1AC0C9A6006BBC11 /* ConstraintItem.swift in Sources */,
@@ -390,6 +395,7 @@
 				EECDB39A1AC0CBFF006BBC11 /* EdgeInsets.swift in Sources */,
 				EECDB3981AC0CBFF006BBC11 /* ConstraintMaker.swift in Sources */,
 				EECDB3961AC0CBFF006BBC11 /* ConstraintAttributes.swift in Sources */,
+				779230451BCB6FC30027CF5F /* SourceLocation.swift in Sources */,
 				EECDB39B1AC0CBFF006BBC11 /* LayoutConstraint.swift in Sources */,
 				EECDB3971AC0CBFF006BBC11 /* ConstraintItem.swift in Sources */,
 			);

+ 4 - 1
Source/Constraint.swift

@@ -61,6 +61,7 @@ public class Constraint {
     internal var makerFile: String = "Unknown"
     internal var makerLine: UInt = 0
     
+    internal(set) public var location : SourceLocation?
 }
 
 /**
@@ -195,13 +196,15 @@ internal class ConcreteConstraint: Constraint {
     
     private var installInfo: ConcreteConstraintInstallInfo? = nil
     
-    internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float) {
+    internal init(fromItem: ConstraintItem, toItem: ConstraintItem, relation: ConstraintRelation, constant: Any, multiplier: Float, priority: Float, location : SourceLocation?) {
         self.fromItem = fromItem
         self.toItem = toItem
         self.relation = relation
         self.constant = constant
         self.multiplier = multiplier
         self.priority = priority
+        super.init()
+        self.location = location
     }
     
     internal func installOnView(updateExisting updateExisting: Bool = false, file: String? = nil, line: UInt? = nil) -> [LayoutConstraint] {

+ 28 - 15
Source/ConstraintDescription.swift

@@ -197,25 +197,31 @@ public class ConstraintDescriptionRelatable {
     }
     
 
-    public func equalTo(other: RelationTarget) -> ConstraintDescriptionEditable {
-        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .Equal))
+    public func equalTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
+        let location = SourceLocation(file: file, line: line)
+        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .Equal, location: location))
     }
-    public func equalTo(other: LayoutSupport) -> ConstraintDescriptionEditable {
-        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .Equal))
+    public func equalTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
+        let location = SourceLocation(file: file, line: line)
+        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .Equal, location: location))
     }
     
-    public func lessThanOrEqualTo(other: RelationTarget) -> ConstraintDescriptionEditable {
-        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .LessThanOrEqualTo))
+    public func lessThanOrEqualTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
+        let location = SourceLocation(file: file, line: line)
+        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .LessThanOrEqualTo, location: location))
     }
-    public func lessThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable {
-        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .LessThanOrEqualTo))
+    public func lessThanOrEqualTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
+        let location = SourceLocation(file: file, line: line)
+        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .LessThanOrEqualTo, location: location))
     }
     
-    public func greaterThanOrEqualTo(other: RelationTarget) -> ConstraintDescriptionEditable {
-        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .GreaterThanOrEqualTo))
+    public func greaterThanOrEqualTo(other: RelationTarget, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
+        let location = SourceLocation(file: file, line: line)
+        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .GreaterThanOrEqualTo, location: location))
     }
-    public func greaterThanOrEqualTo(other: LayoutSupport) -> ConstraintDescriptionEditable {
-        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .GreaterThanOrEqualTo))
+    public func greaterThanOrEqualTo(other: LayoutSupport, file : String = __FILE__, line : UInt = __LINE__) -> ConstraintDescriptionEditable {
+        let location = SourceLocation(file: file, line: line)
+        return ConstraintDescriptionEditable(self.backing.constrainTo(other, relation : .GreaterThanOrEqualTo, location: location))
     }
 }
 
@@ -301,6 +307,8 @@ public class ConstraintDescriptionExtendable: ConstraintDescriptionRelatable {
  */
 internal class ConstraintDescription {
     
+    private var location : SourceLocation?
+    
     private var left: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Left) }
     private var top: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Top) }
     private var right: ConstraintDescription { return self.addConstraint(ConstraintAttributes.Right) }
@@ -418,7 +426,9 @@ internal class ConstraintDescription {
                 relation: self.relation!,
                 constant: self.constant,
                 multiplier: self.multiplier,
-                priority: self.priority)
+                priority: self.priority,
+                location: self.location
+            )
         }
         return self.concreteConstraint!
     }
@@ -470,7 +480,10 @@ internal class ConstraintDescription {
         return self
     }
     
-    private func constrainTo(other: RelationTarget, relation: ConstraintRelation) -> ConstraintDescription {
+    private func constrainTo(other: RelationTarget, relation: ConstraintRelation, location : SourceLocation) -> ConstraintDescription {
+        
+        self.location = location
+        
         if let constant = other as? FloatConvertible {
             self.constant = constant.floatValue
         }
@@ -494,7 +507,7 @@ internal class ConstraintDescription {
     }
     
     @available(iOS 7.0, *)
-    private func constrainTo(other: LayoutSupport, relation: ConstraintRelation) -> ConstraintDescription {
+    private func constrainTo(other: LayoutSupport, relation: ConstraintRelation, location : SourceLocation) -> ConstraintDescription {
         return constrainTo(ConstraintItem(object: other, attributes: ConstraintAttributes.None), relation: relation, location: location)
     }
     

+ 36 - 0
Source/SourceLocation.swift

@@ -0,0 +1,36 @@
+//
+//  SnapKit
+//
+//  Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit
+//
+//  Permission is hereby granted, free of charge, to any person obtaining a copy
+//  of this software and associated documentation files (the "Software"), to deal
+//  in the Software without restriction, including without limitation the rights
+//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+//  copies of the Software, and to permit persons to whom the Software is
+//  furnished to do so, subject to the following conditions:
+//
+//  The above copyright notice and this permission notice shall be included in
+//  all copies or substantial portions of the Software.
+//
+//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+//  THE SOFTWARE.
+
+public struct SourceLocation {
+    
+    public let file : String
+    public let line : UInt
+    
+    init(file : String, line : UInt) {
+        self.file = file
+        self.line = line
+    }
+    
+}
+
+