File path: /jabref-2.10/src/java/net/sf/jabref/collab/ChangeScanner.java | File path: /jabref-2.10/src/java/net/sf/jabref/collab/ChangeScanner.java | |||
Method name: void scanStrings(BibtexDatabase, BibtexDatabase, BibtexDatabase)
|
Method name: BibtexString findString(BibtexDatabase, String, HashSet |
|||
Number of AST nodes: 6 | Number of AST nodes: 6 | |||
1 | private void scanStrings(BibtexDatabase inMem, BibtexDatabase onTmp, BibtexDatabase onDisk) { | 1 | private BibtexString findString(BibtexDatabase base, String name, HashSet<Object> used) { | |
2 | int nTmp = onTmp.getStringCount(), | 2 | if (!base.hasStringLabel(name)) | |
3 | nDisk = onDisk.getStringCount(); | 3 | return null; | |
4 | if ((nTmp == 0) && (nDisk == 0)) | 4 | for (Iterator<String> i=base.getStringKeySet().iterator(); i.hasNext();) { | |
5 | return; | 5 | String key = i.next(); | |
6 | 6 | BibtexString bs = base.getString(key); | ||
7 | HashSet<Object> used = new HashSet<Object>(); | 7 | if (bs.getName().equals(name) && !used.contains(key)) { | |
8 | HashSet<Object> usedInMem = new HashSet<Object>(); | 8 | used.add(key); | |
9 | HashSet<String> notMatched = new HashSet<String>(onTmp.getStringCount()); | 9 | return bs; | |
10 | 10 | } | ||
11 | // First try to match by string names. | 11 | } | |
12 | //int piv2 = -1; | 12 | return null; | |
13 | mainLoop: for (String key : onTmp.getStringKeySet()){ | 13 | } | |
14 | BibtexString tmp = onTmp.getString(key); | |||
15 | ||||
16 | // for (int j=piv2+1; j<nDisk; j++) | |||
17 | for (String diskId : onDisk.getStringKeySet()){ | |||
18 | if (!used.contains(diskId)) { | |||
19 | BibtexString disk = onDisk.getString(diskId); | |||
20 | if (disk.getName().equals(tmp.getName())) { | |||
21 | // We have found a string with a matching name. | |||
22 | if ((tmp.getContent() != null) && !tmp.getContent().equals(disk.getContent())) { | |||
23 | // But they have nonmatching contents, so we've found a change. | |||
24 | BibtexString mem = findString(inMem, tmp.getName(), usedInMem); | |||
25 | if (mem != null) | |||
26 | changes.add(new StringChange(mem, tmp, tmp.getName(), | |||
27 | mem.getContent(), | |||
28 | tmp.getContent(), disk.getContent())); | |||
29 | else | |||
30 | changes.add(new StringChange(null, tmp, tmp.getName(), null, tmp.getContent(), disk.getContent())); | |||
31 | } | |||
32 | used.add(diskId); | |||
33 | //if (j==piv2) | |||
34 | // piv2++; | |||
35 | continue mainLoop; | |||
36 | } | |||
37 | ||||
38 | } | |||
39 | } | |||
40 | // If we get here, there was no match for this string. | |||
41 | notMatched.add(tmp.getId()); | |||
42 | } | |||
43 | ||||
44 | // See if we can detect a name change for those entries that we couldn't match. | |||
45 | if (notMatched.size() > 0) { | |||
46 | for (Iterator<String> i = notMatched.iterator(); i.hasNext();){ | |||
47 | BibtexString tmp = onTmp.getString(i.next()); | |||
48 | ||||
49 | // If we get to this point, we found no string with matching name. See if we | |||
50 | // can find one with matching content. | |||
51 | for (String diskId : onDisk.getStringKeySet()){ | |||
52 | ||||
53 | if (!used.contains(diskId)) { | |||
54 | BibtexString disk = onDisk.getString(diskId); | |||
55 | ||||
56 | if (disk.getContent().equals(tmp.getContent())) { | |||
57 | // We have found a string with the same content. It cannot have the same | |||
58 | // name, or we would have found it above. | |||
59 | ||||
60 | // Try to find the matching one in memory: | |||
61 | BibtexString bsMem = null; | |||
62 | ||||
63 | for (String memId : inMem.getStringKeySet()){ | |||
64 | BibtexString bsMem_cand = inMem.getString(memId); | |||
65 | if (bsMem_cand.getContent().equals(disk.getContent()) && | |||
66 | !usedInMem.contains(memId)) { | |||
67 | usedInMem.add(memId); | |||
68 | bsMem = bsMem_cand; | |||
69 | break; | |||
70 | } | |||
71 | } | |||
72 | ||||
73 | changes.add(new StringNameChange(bsMem, tmp, bsMem.getName(), | |||
74 | tmp.getName(), disk.getName(), | |||
75 | tmp.getContent())); | |||
76 | i.remove(); | |||
77 | used.add(diskId); | |||
78 | ||||
79 | } | |||
80 | } | |||
81 | } | |||
82 | } | |||
83 | } | |||
84 | ||||
85 | if (notMatched.size() > 0) { | |||
86 | // Still one or more non-matched strings. So they must have been removed. | |||
87 | for (Iterator<String> i = notMatched.iterator(); i.hasNext(); ) { | |||
88 | String nmId = i.next(); | |||
89 | BibtexString tmp = onTmp.getString(nmId); | |||
90 | BibtexString mem = findString(inMem, tmp.getName(), usedInMem); | |||
91 | if (mem != null) { // The removed string is not removed from the mem version. | |||
92 | changes.add(new StringRemoveChange(tmp, tmp, mem)); | |||
93 | } | |||
94 | } | |||
95 | } | |||
96 | ||||
97 | ||||
98 | // Finally, see if there are remaining strings in the disk database. They | |||
99 | // must have been added. | |||
100 | for (Iterator<String> i=onDisk.getStringKeySet().iterator(); i.hasNext();) { | |||
101 | String diskId = i.next(); | |||
102 | if (!used.contains(diskId)) { | |||
103 | BibtexString disk = onDisk.getString(diskId); | |||
104 | //System.out.println(disk.getName()); | |||
105 | used.add(diskId); | |||
106 | changes.add(new StringAddChange(disk)); | |||
107 | } | |||
108 | } | |||
109 | } | |||
See real code fragment | See real code fragment |
-
{Non-refactorable}
Mapping Summary
Number of mapped statements 5
Number of unmapped statements in the first code fragment 2
Number of unmapped statements in the second code fragment 1
Time elapsed for statement mapping (ms) 0.0
Similarity Score 0.727
Clone type Type 3
Mapped Statements
ID
Statement
ID
Statement
29 for (String memId : inMem.getStringKeySet())
29 for (String memId : inMem.getStringKeySet()) 3 for (Iterator<String> i = base.getStringKeySet().iterator(); i.hasNext(); )
Differences Expression1 Expression2 Difference memId key VARIABLE_NAME_MISMATCH inMem base VARIABLE_NAME_MISMATCH
3 for (Iterator<String> i = base.getStringKeySet().iterator(); i.hasNext(); )
4 String key = i.next();
Differences Expression1 Expression2 Difference memId key VARIABLE_NAME_MISMATCH
4 String key = i.next();
30 BibtexString bsMem_cand = inMem.getString(memId);
30 BibtexString bsMem_cand = inMem.getString(memId); 5 BibtexString bs = base.getString(key);
Differences Expression1 Expression2 Difference bsMem_cand bs VARIABLE_NAME_MISMATCH memId key VARIABLE_NAME_MISMATCH inMem base VARIABLE_NAME_MISMATCH
5 BibtexString bs = base.getString(key);
31 if (bsMem_cand.getContent().equals(disk.getContent()) && !usedInMem.contains(memId))
31 if (bsMem_cand.getContent().equals(disk.getContent()) && !usedInMem.contains(memId)) 6 if (bs.getName().equals(name) && !used.contains(key))
Differences Expression1 Expression2 Difference disk.getContent() name TYPE_COMPATIBLE_REPLACEMENT getContent getName METHOD_INVOCATION_NAME_MISMATCH bsMem_cand bs VARIABLE_NAME_MISMATCH memId key VARIABLE_NAME_MISMATCH usedInMem used VARIABLE_NAME_MISMATCH
Preondition Violations Expression bsMem_cand.getContent() cannot be parameterized, because it has dependencies to/from statements that will be extracted Expression bs.getName() cannot be parameterized, because it has dependencies to/from statements that will be extracted
6 if (bs.getName().equals(name) && !used.contains(key))
32 usedInMem.add(memId);
32 usedInMem.add(memId); 7 used.add(key);
Differences Expression1 Expression2 Difference memId key VARIABLE_NAME_MISMATCH usedInMem used VARIABLE_NAME_MISMATCH
7 used.add(key);
8 return bs;
Preondition Violations Unmatched statement return bs; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted Unmatched return bs;
8 return bs;
33 bsMem = bsMem_cand;
33 bsMem = bsMem_cand;
Preondition Violations Unmatched statement bsMem=bsMem_cand; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
34 break;
34 break;
Preondition Violations Unmatched break;
Precondition Violations (6)
Row
Violation
1 Expression bsMem_cand.getContent() cannot be parameterized, because it has dependencies to/from statements that will be extracted 2 Expression bs.getName() cannot be parameterized, because it has dependencies to/from statements that will be extracted 3 Unmatched statement return bs; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted 4 Unmatched return bs; 5 Unmatched statement bsMem=bsMem_cand; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted 6 Unmatched break;