KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > patch > HunkDiffNode


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /* isResult */, 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 /* before state */, fullContext);
34     }
35
36     private static ITypedElement getAncestorElement(HunkResult result, boolean fullContext) {
37         if (!fullContext) {
38             // Don't provide an ancestor if the hunk didn't match or we're not doing fullContext
39
return null;
40         }
41         // Make the ancestor the same as the left so we have an incoming change
42
return new HunkTypedElement(result, false /* before state */, 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 JavaDoc 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