KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Map JavaDoc;
15
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.TypedPosition;
18
19 import org.eclipse.jdt.internal.ui.text.IJavaPartitions;
20
21 /**
22  * Factory for comment related objects.
23  * <p>
24  * Use this factory to create comment objects specific to a certain comment
25  * type.
26  * </p>
27  *
28  * @since 3.0
29  */

30 public class CommentObjectFactory {
31
32     /**
33      * Creates a comment line for a specific comment region.
34      *
35      * @param region
36      * Comment region to create the line for
37      * @return A new comment line for the comment region, or <code>null</code>
38      * iff there is no line available for this comment type
39      */

40     public static CommentLine createLine(final CommentRegion region) {
41
42         final String JavaDoc type= region.getType();
43
44         if (type.equals(IJavaPartitions.JAVA_DOC))
45             return new JavaDocLine(region);
46         else if (type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT))
47             return new MultiCommentLine(region);
48         else if (type.equals(IJavaPartitions.JAVA_SINGLE_LINE_COMMENT))
49             return new SingleCommentLine(region);
50
51         return null;
52     }
53
54     /**
55      * Creates a comment region for a specific document partition type.
56      *
57      * @param document
58      * The document which contains the comment region
59      * @param range
60      * Range of the comment region in the document
61      * @param delimiter
62      * Line delimiter to use in the comment region
63      * @param preferences
64      * The preferences to use
65      * @param textMeasurement
66      * The text measurement. Can be <code>null</code>.
67      * @return A new comment region for the comment region range in the
68      * document
69      */

70     public static CommentRegion createRegion(final IDocument document, final TypedPosition range, final String JavaDoc delimiter, final Map JavaDoc preferences, final ITextMeasurement textMeasurement) {
71
72         final String JavaDoc type= range.getType();
73
74         if (type.equals(IJavaPartitions.JAVA_DOC))
75             return new JavaDocRegion(document, range, delimiter, preferences, textMeasurement);
76         else if (type.equals(IJavaPartitions.JAVA_MULTI_LINE_COMMENT))
77             return new MultiCommentRegion(document, range, delimiter, preferences, textMeasurement);
78
79         return new CommentRegion(document, range, delimiter, preferences, textMeasurement);
80     }
81
82     /**
83      * This class is not intended for instantiation.
84      * <p>
85      * Use the factory methods to create comment object instances.
86      */

87     private CommentObjectFactory() {
88         // Not for instantiation
89
}
90 }
91
Popular Tags