KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > folding > JspFoldUtils


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.core.syntax.folding;
21
22 import java.io.PrintStream JavaDoc;
23 import org.netbeans.api.editor.fold.Fold;
24 import org.netbeans.api.editor.fold.FoldHierarchy;
25 import org.netbeans.modules.web.core.syntax.JspSyntaxSupport;
26 import org.netbeans.spi.editor.fold.FoldOperation;
27
28 /**
29  * Utility class. Contains mostly debug messages suport.
30  *
31  * @author Marek.Fukala@Sun.COM
32  */

33
34 public class JspFoldUtils {
35
36
37     public static void printFolds(FoldOperation foldOperation) {
38         printFolds(foldOperation.getHierarchy(), System.out);
39     }
40
41     /** Prints folds recursivelly into standard output*/
42     public static void printFolds(FoldHierarchy foldHierarchy, PrintStream JavaDoc out) {
43         foldHierarchy.lock();
44         try {
45             Fold rootFold = foldHierarchy.getRootFold();
46             printChildren(rootFold, 0, out);
47         } finally {
48             foldHierarchy.unlock();
49         }
50     }
51     
52     private static void printChildren(Fold fold, int level, PrintStream JavaDoc out) {
53         int foldCount = fold.getFoldCount();
54         //indent
55
for( int i = 0; i < level; i ++) System.out.print(" ");
56         //print this fold info
57
out.println(fold.getDescription() + "[" + fold.getType().toString() + "; " + fold.getStartOffset() + " - " + fold.getEndOffset() + "]");
58         System.out.println(fold.getDescription() + "[" + fold.getType().toString() + "; " + fold.getStartOffset() + " - " + fold.getEndOffset() + "]");
59         //print children
60
for (int i = 0; i < foldCount; i++) {
61             Fold childFold = fold.getFold(i);
62             printChildren(childFold, level + 4, out);
63         }
64     }
65   
66     public static String JavaDoc getContextName(int typeId) {
67         switch(typeId) {
68             case JspSyntaxSupport.COMMENT_COMPLETION_CONTEXT:
69                 return "comment";
70             case JspSyntaxSupport.CONTENTL_COMPLETION_CONTEXT:
71                 return "content language";
72             case JspSyntaxSupport.DIRECTIVE_COMPLETION_CONTEXT:
73                 return "directive";
74             case JspSyntaxSupport.ENDTAG_COMPLETION_CONTEXT:
75                 return "end tag";
76             case JspSyntaxSupport.SCRIPTINGL_COMPLETION_CONTEXT:
77                 return "scripting";
78             case JspSyntaxSupport.TAG_COMPLETION_CONTEXT:
79                 return "tag";
80             case JspSyntaxSupport.TEXT_COMPLETION_CONTEXT:
81                 return "text";
82             default:
83                 return "?";
84         }
85     }
86     
87 }
88
Popular Tags