Tools__Diff2CodeView2.st
changeset 15278 1d449ea6c8e0
parent 14371 491ec9ff2c09
child 15566 184cea584be5
equal deleted inserted replaced
15277:f96605ba2467 15278:1d449ea6c8e0
    39  inclusion of the above copyright notice.   This software may not
    39  inclusion of the above copyright notice.   This software may not
    40  be provided or otherwise made available to, or used by, any
    40  be provided or otherwise made available to, or used by, any
    41  other person.  No title to or ownership of the software is
    41  other person.  No title to or ownership of the software is
    42  hereby transferred.
    42  hereby transferred.
    43 "
    43 "
    44 ! !
       
    45 
       
    46 !Diff2CodeView2 class methodsFor:'defaults'!
       
    47 
       
    48 numberOfViews
       
    49     "return the number of the synced subViews.
       
    50      Usually redefined in subclasses"
       
    51 
       
    52     ^ 2
       
    53 
       
    54     "Created: / 16-03-2012 / 12:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    55 ! !
       
    56 
       
    57 !Diff2CodeView2 methodsFor:'accessing'!
       
    58 
       
    59 text1:t1 text2:t2 
       
    60     |data|
       
    61 
       
    62     data := self computeDiffDataForText1:t1 text2:t2.
       
    63 
       
    64     (textViews at:1) 
       
    65         contents:(data text1);
       
    66         deletedLines:(data deleted);
       
    67         changedLines:(data changed);
       
    68         insertedLines:#();    
       
    69         originDiffText:t1;
       
    70         emptyLines:(data inserted).
       
    71 
       
    72     (textViews at:2) 
       
    73         contents:(data text2);
       
    74         deletedLines:#();
       
    75         changedLines:(data changed);
       
    76         insertedLines:(data inserted);
       
    77         originDiffText:t2;
       
    78         emptyLines:(data deleted).
       
    79 
       
    80     "Created: / 06-03-2010 / 10:45:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    81     "Modified: / 22-06-2010 / 21:36:35 / Jakub <zelenja7@fel.cvut.cz>"
       
    82     "Modified: / 15-07-2010 / 23:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    83 ! !
       
    84 
       
    85 !Diff2CodeView2 methodsFor:'private'!
       
    86 
       
    87 computeDiffDataForText1:t1 text2:t2 
       
    88     "created diffText object from two string"
       
    89 
       
    90     "/ cg: same code as in DiffCodeView2!!!!!!
       
    91     "/ please refactor and make this a utility method on the class side
       
    92 
       
    93     |array1 array2 diff change index1 index2 text1 text2 i 
       
    94      data deleted inserted helperText addConstant1 addConstant2 changed helper ins del pom
       
    95      array1Size array2Size|
       
    96 
       
    97     "Convert text into an array of individual lines"
       
    98     array1 := self createArray:t1.
       
    99     array2 := self createArray:t2.
       
   100     "Initialize inserted/deleted/changed "
       
   101     inserted := OrderedCollection new.
       
   102     deleted := OrderedCollection new.
       
   103     changed := OrderedCollection new.
       
   104 
       
   105      "indicates which row of origin text is added to ne text"
       
   106     index1 := 1.
       
   107     index2 := 1.
       
   108      "indicate how much rows were deleted or inserted "
       
   109     addConstant1 := 0.
       
   110     addConstant2 := 0.
       
   111     text1 := ''.
       
   112     text2 := ''.
       
   113     diff := Diff new.
       
   114     diff a:array1 b:array2.
       
   115     change := diff diff:false.
       
   116     data := Diff2Data new.
       
   117 
       
   118 
       
   119 
       
   120     [ change notNil ] whileTrue:[
       
   121         "check first lines which are same"
       
   122         (((change line0) > 0) and:[ ((change line1) > 0) ]) ifTrue:[
       
   123             [
       
   124                 index1 <= (change line0)
       
   125             ] whileTrue:[
       
   126                 helperText := (array1 at:index1) asText.
       
   127                 text1 := text1 asString , helperText asString.
       
   128                 index1 := index1 + 1.
       
   129             ].
       
   130             [
       
   131                 index2 <= (change line1)
       
   132             ] whileTrue:[
       
   133                 helperText := (array2 at:index2) asText.
       
   134                 text2 := text2 , helperText.
       
   135                 index2 := index2 + 1.
       
   136             ].
       
   137         ].
       
   138         ins := change inserted.
       
   139         del := change deleted.
       
   140         index1 := (change line0) + 1.
       
   141         index2 := (change line1) + 1.
       
   142          "find replace files "
       
   143         ((del > 0) and:[ ins > 0 ]) ifTrue:[
       
   144             helper := del - ins.
       
   145             (helper <= 0) ifTrue:[
       
   146                 pom := change deleted.
       
   147             ].
       
   148             (helper > 0) ifTrue:[
       
   149                 pom := change inserted.
       
   150             ].
       
   151              "its same count row"
       
   152             i := 1.
       
   153             [ i <= pom ] whileTrue:[
       
   154                 changed add:index1 + addConstant1.
       
   155                 text1 := text1 , (array1 at:index1) asString.
       
   156                 text2 := text2 , (array2 at:index2) asString.
       
   157                 index1 := index1 + 1.
       
   158                 index2 := index2 + 1.
       
   159                 del := del - 1.
       
   160                 ins := ins - 1.
       
   161                 i := i + 1.
       
   162             ].
       
   163         ].
       
   164          "find deleted files"
       
   165         (del > 0) ifTrue:[
       
   166             i := 1.
       
   167             [ i <= del ] whileTrue:[
       
   168                 deleted add:index1 + addConstant1.
       
   169                 text2 := text2 , Character cr.
       
   170                 addConstant2 := addConstant2 + 1.
       
   171                 text1 := text1 , (array1 at:index1) asString.
       
   172                 index1 := index1 + 1.
       
   173                 i := i + 1.
       
   174             ].
       
   175         ].
       
   176          "find inserted lines"
       
   177         (ins > 0) ifTrue:[
       
   178             i := 1.
       
   179             [ i <= ins ] whileTrue:[
       
   180                 inserted add:index2 + addConstant2.
       
   181                 text1 := text1 , Character cr.
       
   182                 addConstant1 := addConstant1 + 1.
       
   183                 text2 := text2 , (array2 at:index2) asString.
       
   184                 index2 := index2 + 1.
       
   185                 i := i + 1.
       
   186             ].
       
   187         ].
       
   188         change := change nextLink.
       
   189     ].
       
   190      "kontrola zda nam nechybi posledni znaky"
       
   191     array1Size := array1 size.
       
   192     (index1 <= array1Size) ifTrue:[
       
   193         [ index1 <= array1Size ] whileTrue:[
       
   194             helperText := (array1 at:index1) asText.
       
   195             text1 := text1 , helperText.
       
   196             index1 := index1 + 1.
       
   197         ].
       
   198     ].
       
   199     array2Size := array2 size.
       
   200     (index2 <= array2Size) ifTrue:[
       
   201         [ index2 <= (array2 size) ] whileTrue:[
       
   202             helperText := (array2 at:index2) asText.
       
   203             text2 := text2 , helperText.
       
   204             index2 := index2 + 1.
       
   205         ].
       
   206     ].
       
   207     data text1:text1.
       
   208     data text2:text2.
       
   209     data changed:changed.
       
   210     data inserted:inserted.
       
   211     data deleted:deleted.
       
   212     ^ data.
       
   213 
       
   214     "Modified: / 22-06-2010 / 21:02:50 / Jakub <zelenja7@fel.cvut.cz>"
       
   215     "Modified: / 16-03-2012 / 12:53:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   216     "Modified (format): / 16-03-2012 / 16:10:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   217 !
       
   218 
       
   219 createArray:text1 
       
   220 
       
   221     | array src line c |
       
   222     array := StringCollection new.
       
   223     src := text1 readStream.
       
   224     line := (String new: 80) writeStream.
       
   225     [ src atEnd ] whileFalse:[
       
   226         c := src next.
       
   227         line nextPut: c.
       
   228         c == Character cr ifTrue:[
       
   229             array add: line contents.
       
   230             line reset.
       
   231         ]        
       
   232     ].
       
   233     line position ~~ 0 ifTrue:[
       
   234         array add: line contents
       
   235     ].
       
   236     ^array
       
   237 
       
   238     "Created: / 22-03-2010 / 14:48:27 / Jakub <zelenja7@fel.cvut.cz>"
       
   239     "Modified (comment): / 19-07-2011 / 11:14:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   240 ! !
    44 ! !
   241 
    45 
   242 !Diff2CodeView2::Diff2Data methodsFor:'accessing'!
    46 !Diff2CodeView2::Diff2Data methodsFor:'accessing'!
   243 
    47 
   244 changed
    48 changed
   286 ! !
    90 ! !
   287 
    91 
   288 !Diff2CodeView2 class methodsFor:'documentation'!
    92 !Diff2CodeView2 class methodsFor:'documentation'!
   289 
    93 
   290 version
    94 version
   291     ^ '$Header: /cvs/stx/stx/libtool/Tools__Diff2CodeView2.st,v 1.2 2014-05-15 17:21:25 cg Exp $'
    95     ^ '$Header: /cvs/stx/stx/libtool/Tools__Diff2CodeView2.st,v 1.3 2015-02-13 19:27:24 cg Exp $'
   292 !
    96 !
   293 
    97 
   294 version_CVS
    98 version_CVS
   295     ^ '$Header: /cvs/stx/stx/libtool/Tools__Diff2CodeView2.st,v 1.2 2014-05-15 17:21:25 cg Exp $'
    99     ^ '$Header: /cvs/stx/stx/libtool/Tools__Diff2CodeView2.st,v 1.3 2015-02-13 19:27:24 cg Exp $'
   296 ! !
   100 ! !
   297 
   101