KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javacore > jmiimpl > javamodel > DiffElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.javacore.jmiimpl.javamodel;
21
22 /**
23  * Represents one diff record in the source. Provides data structure for
24  * creating diff list. Contains start offset of change, end offset and
25  * the new text for this range.
26  *
27  * @author Pavel Flaska
28  */

29 public final class DiffElement {
30
31     private final int startOffset;
32     private final int endOffset;
33     private final String JavaDoc text;
34
35     /**
36      * Instances represent one diff record. One instance defines range of
37      * change in original source text and new text. Value cannot be null.
38      *
39      * @param startOffset where to start replacement
40      * @param endOffset where to end replacement
41      * @param value new text to use
42      */

43     public DiffElement(int startOffset, int endOffset, String JavaDoc text) {
44         //assert startOffset > endOffset : "startOffset > endOffset";
45
//assert startOffset == endOffset && value.length() == 0 : "no operation";
46
this.startOffset = startOffset;
47         this.endOffset = endOffset;
48         this.text = text;
49     }
50
51     /**
52      * Getter for property startOffset.
53      *
54      * @return Value of property startOffset.
55      */

56     public int getStartOffset() {
57         return startOffset;
58     }
59
60     /**
61      * Getter for property endOffset.
62      *
63      * @return Value of property endOffset.
64      */

65     public int getEndOffset() {
66         return endOffset;
67     }
68
69     /**
70      * Getter for property text.
71      *
72      * @return Value of property text.
73      */

74     public String JavaDoc getText() {
75         return text;
76     }
77
78     /**
79      * Returns true, if the record is newly inserted (i.e. it doesn't
80      * replace anything in the original code).
81      *
82      * @return true, if the diff is inserted code
83      */

84     public boolean isInserted() {
85         return startOffset == endOffset;
86     }
87     
88     /**
89      *
90      * @return true, if the diff is deleted code
91      */

92     public boolean isDeleted() {
93         return startOffset < endOffset && text.length() == 0;
94     }
95 }
96
Popular Tags