KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > comment > SingleCommentLine


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
12 package org.eclipse.jdt.internal.ui.text.comment;
13
14 import org.eclipse.jdt.internal.corext.refactoring.nls.NLSElement;
15
16 /**
17  * Single-line comment line in a comment region.
18  *
19  * @since 3.0
20  */

21 public class SingleCommentLine extends CommentLine {
22
23     /** Line prefix for single line comments */
24     public static final String JavaDoc SINGLE_COMMENT_PREFIX= "// "; //$NON-NLS-1$
25

26     /** Is the comment a NLS locale tag sequence? */
27     private boolean fLocaleSequence= false;
28
29     /**
30      * Creates a new single-line comment line.
31      *
32      * @param region
33      * Comment region to create the line for
34      */

35     protected SingleCommentLine(final CommentRegion region) {
36         super(region);
37     }
38
39     /**
40      * @inheritDoc
41      */

42     protected void adapt(final CommentLine previous) {
43         // Do nothing
44
}
45
46     /**
47      * @inheritDoc
48      */

49     protected void formatLowerBorder(final CommentRange range, final String JavaDoc indentation, final int length) {
50
51         final int offset= range.getOffset() + range.getLength();
52         final CommentRegion parent= getParent();
53
54         parent.logEdit(parent.getDelimiter(), offset, parent.getLength() - offset);
55     }
56
57     /**
58      * @inheritDoc
59      */

60     protected void formatUpperBorder(final CommentRange range, final String JavaDoc indentation, final int length) {
61
62         final CommentRegion parent= getParent();
63
64         parent.logEdit(getContentPrefix(), 0, range.getOffset() - parent.getOffset());
65     }
66
67     /**
68      * @inheritDoc
69      */

70     protected String JavaDoc getContentPrefix() {
71         return SINGLE_COMMENT_PREFIX;
72     }
73
74     /**
75      * @inheritDoc
76      */

77     protected String JavaDoc getEndingPrefix() {
78         return SINGLE_COMMENT_PREFIX;
79     }
80
81     /**
82      * @inheritDoc
83      */

84     protected String JavaDoc getStartingPrefix() {
85         return SINGLE_COMMENT_PREFIX;
86     }
87
88     /**
89      * @inheritDoc
90      */

91     protected void scanLine(final int line) {
92
93         final CommentRange range= getFirst();
94         final String JavaDoc content= getParent().getText(range.getOffset(), range.getLength());
95         final String JavaDoc prefix= getContentPrefix().trim();
96
97         final int offset= content.indexOf(prefix);
98         if (offset >= 0) {
99
100             if (content.startsWith(NLSElement.TAG_PREFIX))
101                 fLocaleSequence= true;
102
103             range.trimBegin(offset + prefix.length());
104         }
105     }
106
107     /**
108      * @inheritDoc
109      */

110     protected void tokenizeLine(final int line) {
111
112         if (!fLocaleSequence)
113             super.tokenizeLine(line);
114     }
115 }
116
Popular Tags