KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > nls > NLSElement


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.corext.refactoring.nls;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.jface.text.Region;
16
17 public class NLSElement {
18
19     public static final String JavaDoc TAG_PREFIX= "//$NON-NLS-"; //$NON-NLS-1$
20
public static final int TAG_PREFIX_LENGTH= TAG_PREFIX.length();
21     public static final String JavaDoc TAG_POSTFIX= "$"; //$NON-NLS-1$
22
public static final int TAG_POSTFIX_LENGTH= TAG_POSTFIX.length();
23
24     /** The original string denoted by the position */
25     private String JavaDoc fValue;
26     /** The position of the original string */
27     private Region fPosition;
28
29     /** Position of the // $NON_NLS_*$ tag */
30     private Region fTagPosition;
31
32     /** Index of the Element in an NLSLine */
33     private int fIndex;
34     private boolean fIsEclipseNLS;
35     private AccessorClassReference fAccessorClassReference;
36
37     /**
38      * Creates a new NLS element for the given string and position.
39      */

40     public NLSElement(String JavaDoc value, int start, int length, int index, boolean isEclipseNLS) {
41         fValue= value;
42         fIndex= index;
43         Assert.isNotNull(fValue);
44         fPosition= new Region(start, length);
45         fIsEclipseNLS= isEclipseNLS;
46     }
47
48     /**
49      * Returns the position of the string to be NLSed.
50      * @return Returns the position of the string to be NLSed
51      */

52     public Region getPosition() {
53         return fPosition;
54     }
55
56     /**
57      * Returns the actual string value.
58      * @return the actual string value
59      */

60     public String JavaDoc getValue() {
61         return fValue;
62     }
63
64     /**
65      * Sets the actual string value.
66      */

67     public void setValue(String JavaDoc value) {
68         fValue= value;
69     }
70
71     /**
72      * Sets the tag position if one is associated with the NLS element.
73      */

74     public void setTagPosition(int start, int length) {
75         fTagPosition= new Region(start, length);
76     }
77
78     /**
79      * Returns the tag position for this element. The method can return <code>null</code>.
80      * In this case no tag has been found for this NLS element.
81      */

82     public Region getTagPosition() {
83         return fTagPosition;
84     }
85
86     /**
87      * Returns <code>true</code> if the NLS element has an asscociated $NON-NLS-*$ tag.
88      * Otherwise <code>false</code> is returned.
89      */

90     public boolean hasTag() {
91         return fTagPosition != null && fTagPosition.getLength() > 0;
92     }
93
94     public static String JavaDoc createTagText(int index) {
95         return TAG_PREFIX + index + TAG_POSTFIX;
96     }
97
98     public String JavaDoc getTagText() {
99         return TAG_PREFIX + (fIndex + 1) + TAG_POSTFIX;
100     }
101
102     /* (Non-Javadoc)
103      * Method declared in Object.
104      * only for debugging
105      */

106     public String JavaDoc toString() {
107         return fPosition + ": " + fValue + " Tag position: " + //$NON-NLS-2$ //$NON-NLS-1$
108
(hasTag() ? fTagPosition.toString() : "no tag found"); //$NON-NLS-1$
109
}
110
111     //--------------- Eclipse NLS mechanism support ---------------
112

113     /**
114      * Returns whether the standard resource bundle mechanism or
115      * the Eclipse NLSing mechanism is used.
116      *
117      * @return <code>true</code> if the standard resource bundle mechanism
118      * is used and <code>false</code> NLSing is done the Eclipse way
119      * @since 3.1
120      */

121     public boolean isEclipseNLS() {
122         return fIsEclipseNLS;
123     }
124     
125     /**
126      * Sets the accessor class reference for this element.
127      * <p>
128      * Note: this call is only valid when the element is
129      * using the Eclipse NLS mechanism.
130      * </p>
131      *
132      * @param accessorClassRef the accessor class reference
133      * @since 3.1
134      */

135     public void setAccessorClassReference(AccessorClassReference accessorClassRef) {
136         Assert.isTrue(fIsEclipseNLS);
137         fAccessorClassReference= accessorClassRef;
138     }
139
140     /**
141      * Returns the accessor class reference for this element.
142      * <p>
143      * Note: this call is only valid when the element is
144      * using the Eclipse NLS mechanism.
145      * </p>
146      *
147      * @return the accessor class reference
148      * @since 3.1
149      */

150     public AccessorClassReference getAccessorClassReference() {
151         Assert.isTrue(fIsEclipseNLS);
152         return fAccessorClassReference;
153     }
154 }
155
156
Popular Tags