KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > formatter > comment > SingleCommentLine


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
12 package org.eclipse.jdt.internal.formatter.comment;
13
14 /**
15  * Single-line comment line in a comment region.
16  *
17  * @since 3.0
18  */

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

24     /** NLS tag prefix */
25     private static final String JavaDoc NLS_TAG_PREFIX= "//$NON-NLS-"; //$NON-NLS-1$
26

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

35     protected SingleCommentLine(final CommentRegion region) {
36         super(region);
37     }
38
39     /*
40      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#adapt(org.eclipse.jdt.internal.corext.text.comment.CommentLine)
41      */

42     protected void adapt(final CommentLine previous) {
43         // Do nothing
44
}
45
46     /*
47      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#formatLowerBorder(org.eclipse.jdt.internal.corext.text.comment.CommentRange, java.lang.String, int)
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      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#formatUpperBorder(org.eclipse.jdt.internal.corext.text.comment.CommentRange, java.lang.String, int)
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());
65     }
66
67     /*
68      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#getContentPrefix()
69      */

70     protected String JavaDoc getContentPrefix() {
71         return SINGLE_COMMENT_PREFIX;
72     }
73
74     /*
75      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#getEndingPrefix()
76      */

77     protected String JavaDoc getEndingPrefix() {
78         return SINGLE_COMMENT_PREFIX;
79     }
80
81     /*
82      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#getStartingPrefix()
83      */

84     protected String JavaDoc getStartingPrefix() {
85         return SINGLE_COMMENT_PREFIX;
86     }
87
88     /*
89      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#scanLine(int)
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(NLS_TAG_PREFIX))
101                 fLocaleSequence= true;
102
103             range.trimBegin(offset + prefix.length());
104         }
105     }
106
107     /*
108      * @see org.eclipse.jdt.internal.corext.text.comment.CommentLine#tokenizeLine(int)
109      */

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