1 11 package org.eclipse.compare.internal.patch; 12 13 import org.eclipse.compare.ITypedElement; 14 import org.eclipse.compare.patch.PatchConfiguration; 15 import org.eclipse.compare.structuremergeviewer.Differencer; 16 17 public class HunkDiffNode extends PatchDiffNode { 18 19 private final HunkResult result; 20 21 public static HunkDiffNode createDiffNode(PatchFileDiffNode parent, HunkResult result, boolean fullContext) { 22 return new HunkDiffNode(result, parent, Differencer.CHANGE, getAncestorElement(result, fullContext), getLeftElement(result, fullContext), getRightElement(result, fullContext)); 23 } 24 25 private static ITypedElement getRightElement(HunkResult result, boolean fullContext) { 26 return new HunkTypedElement(result, true , fullContext); 27 } 28 29 private static ITypedElement getLeftElement(HunkResult result, 30 boolean fullContext) { 31 if (fullContext && !result.isOK()) 32 return new UnmatchedHunkTypedElement(result); 33 return new HunkTypedElement(result, false , fullContext); 34 } 35 36 private static ITypedElement getAncestorElement(HunkResult result, boolean fullContext) { 37 if (!fullContext) { 38 return null; 40 } 41 return new HunkTypedElement(result, false , result.isOK()); 43 } 44 45 private HunkDiffNode(HunkResult result, PatchFileDiffNode parent, int kind, ITypedElement ancestor, ITypedElement left, ITypedElement right) { 46 super(result.getHunk(), parent, kind, ancestor, left, right); 47 this.result = result; 48 } 49 50 public HunkResult getHunkResult() { 51 return result; 52 } 53 54 protected PatchConfiguration getConfiguration() { 55 return result.getDiffResult().getConfiguration(); 56 } 57 58 public boolean isManuallyMerged() { 59 Object left = getLeft(); 60 if (left instanceof UnmatchedHunkTypedElement) { 61 UnmatchedHunkTypedElement element = (UnmatchedHunkTypedElement) left; 62 return element.isManuallyMerged(); 63 } 64 return false; 65 } 66 67 } 68 | Popular Tags |