RC2 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / corext / refactoring / nls / NLSElement.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.corext.refactoring.nls;
12
13 import org.eclipse.jface.text.Region;
14 import org.eclipse.jface.util.Assert;
15
16 public class NLSElement {
17
18         public static final String TAG_PREFIX= "//$NON-NLS-"; //$NON-NLS-1$
19         public static final int TAG_PREFIX_LENGTH= TAG_PREFIX.length();
20         public static final String TAG_POSTFIX= "$"; //$NON-NLS-1$
21         public static final int TAG_POSTFIX_LENGTH= TAG_POSTFIX.length();
22
23         /** The original string denoted by the position */
24         private String fValue;
25         /** The position of the original string */
26         private Region fPosition;
27
28         /** Position of the // $NON_NLS_*$ tag */
29         private Region fTagPosition;
30
31         /** Index of the Element in an NLSLine */
32         private int fIndex;
33
34         /**
35          * Creates a new NLS element for the given string and position.
36          */
37         public NLSElement(String value, int start, int length, int index) {
38                 fValue= value;
39                 fIndex= index;
40                 Assert.isNotNull(fValue);
41                 fPosition= new Region(start, length);
42         }
43
44         /**
45          * Returns the position of the string to be NLSed.
46          * @return Returns the position of the string to be NLSed
47          */
48         public Region getPosition() {
49                 return fPosition;
50         }
51
52         /**
53          * Returns the actual string value.
54          * @return the actual string value
55          */
56         public String getValue() {
57                 return fValue;
58         }
59
60         /**
61          * Sets the actual string value.
62          */
63         public void setValue(String value) {
64                 fValue= value;
65         }
66
67         /**
68          * Sets the tag position if one is associated with the NLS element.
69          */
70         public void setTagPosition(int start, int length) {
71                 fTagPosition= new Region(start, length);
72         }
73
74         /**
75          * Returns the tag position for this element. The method can return <code>null</code>.
76          * In this case no tag has been found for this NLS element.
77          */
78         public Region getTagPosition() {
79                 return fTagPosition;
80         }
81
82         /**
83          * Returns <code>true</code> if the NLS element has an assicated $NON-NLS-*$ tag. 
84          * Otherwise <code>false</code> is returned.
85          */
86         public boolean hasTag() {
87                 return fTagPosition != null && fTagPosition.getLength() > 0;
88         }
89
90         public static String createTagText(int index) {
91                 return TAG_PREFIX + index + TAG_POSTFIX;
92         }
93
94         public String getTagText() {
95                 return TAG_PREFIX + (fIndex + 1) + TAG_POSTFIX;
96         }
97
98         /* (Non-Javadoc)
99          * Method declared in Object.
100          * only for debugging
101          */
102         public String toString() {
103                 return fPosition + ": " + fValue + "    Tag position: " + //$NON-NLS-2$ //$NON-NLS-1$
104                                 (hasTag() ? fTagPosition.toString() : "no tag found"); //$NON-NLS-1$
105         }
106 }
107