1 11 package org.eclipse.core.internal.watson; 12 13 import org.eclipse.core.internal.dtree.NodeComparison; 14 import org.eclipse.core.runtime.IPath; 15 16 20 public class ElementDelta { 21 protected ElementTreeDelta treeDelta; 22 protected IPath pathInDelta; 23 protected IPath pathInTrees; 24 protected NodeComparison comparison; 25 26 28 ElementDelta(ElementTreeDelta treeDelta, IPath pathInTrees, IPath pathInDelta, NodeComparison comparison) { 29 this.treeDelta = treeDelta; 30 this.pathInDelta = pathInDelta; 31 this.pathInTrees = pathInTrees; 32 this.comparison = comparison; 33 } 34 35 38 public void destroy() { 39 treeDelta.destroy(); 40 treeDelta = null; 41 pathInDelta = null; 42 pathInTrees = null; 43 comparison = null; 44 } 45 46 49 protected ElementDelta[] getAddedChildren(IDeltaFilter filter) { 50 IPath[] children = treeDelta.getElementTree().getChildren(pathInTrees); 51 ElementDelta[] deltas = new ElementDelta[children.length]; 52 for (int i = children.length; --i >= 0;) { 53 deltas[i] = new ElementDelta(treeDelta, children[i], pathInDelta.append(children[i].lastSegment()), comparison); 54 } 55 return deltas; 56 } 57 58 61 public ElementDelta[] getAffectedChildren(IDeltaFilter filter) { 62 switch (comparison.getComparison()) { 63 case NodeComparison.K_CHANGED : 64 return treeDelta.getAffectedElements(pathInDelta, filter); 65 case NodeComparison.K_ADDED : 66 70 if (filter.includeElement(comparison.getUserComparison())) { 71 return getAddedChildren(filter); 72 } 73 break; 74 case NodeComparison.K_REMOVED : 75 if (filter.includeElement(comparison.getUserComparison())) { 76 return getRemovedChildren(filter); 77 } 78 break; 79 } 80 return new ElementDelta[0]; 81 } 82 83 90 public int getComparison() { 91 return comparison.getUserComparison(); 92 } 93 94 97 public IPath getPath() { 98 return pathInTrees; 99 } 100 101 104 protected ElementDelta[] getRemovedChildren(IDeltaFilter filter) { 105 IPath[] children = treeDelta.getParent().getChildren(pathInTrees); 106 ElementDelta[] deltas = new ElementDelta[children.length]; 107 for (int i = children.length; --i >= 0;) { 108 deltas[i] = new ElementDelta(treeDelta, children[i], pathInDelta.append(children[i].lastSegment()), comparison); 109 } 110 return deltas; 111 } 112 113 116 public ElementTreeDelta getTreeDelta() { 117 return treeDelta; 118 } 119 120 124 public boolean hasAffectedChildren(IDeltaFilter filter) { 125 int compare = comparison.getComparison(); 126 127 128 if (compare == NodeComparison.K_CHANGED) { 129 return treeDelta.hasAffectedElements(pathInDelta, filter); 130 } 131 132 136 if (filter.includeElement(comparison.getUserComparison())) { 137 if (compare == NodeComparison.K_ADDED) { 138 139 return treeDelta.getElementTree().getChildCount(pathInTrees) > 0; 140 } else { 141 return treeDelta.getParent().getChildCount(pathInTrees) > 0; 142 } 143 } 144 return false; 145 } 146 147 151 public String toString() { 152 return "ElementDelta(" + pathInTrees + ")"; } 154 } | Popular Tags |