01: /*
02: * Sun Public License Notice
03: *
04: * The contents of this file are subject to the Sun Public License
05: * Version 1.0 (the "License"). You may not use this file except in
06: * compliance with the License. A copy of the License is available at
07: * http://www.sun.com/
08: *
09: * The Original Code is NetBeans. The Initial Developer of the Original
10: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11: * Microsystems, Inc. All Rights Reserved.
12: */
13:
14: package org.netbeans.modules.web.core.syntax.folding;
15:
16: import java.io.PrintStream;
17: import org.netbeans.api.editor.fold.Fold;
18: import org.netbeans.api.editor.fold.FoldHierarchy;
19: import org.netbeans.modules.web.core.syntax.JspSyntaxSupport;
20: import org.netbeans.spi.editor.fold.FoldOperation;
21:
22: /**
23: * Utility class. Contains mostly debug messages suport.
24: *
25: * @author Marek Fukala
26: */
27:
28: public class JspFoldUtils {
29:
30: public static void printFolds(FoldOperation fo) {
31: printFolds(fo.getHierarchy(), System.out);
32: }
33:
34: /** Prints folds recursivelly into standard output*/
35: public static void printFolds(FoldHierarchy fh, PrintStream out) {
36: fh.lock();
37: try {
38: Fold rootFold = fh.getRootFold();
39: printChildren(rootFold, 0, out);
40: } finally {
41: fh.unlock();
42: }
43: }
44:
45: private static void printChildren(Fold f, int level, PrintStream out) {
46: int foldCount = f.getFoldCount();
47: //indent
48: for (int i = 0; i < level; i++)
49: System.out.print(" ");
50: //print this fold info
51: out.println(f.getDescription() + "[" + f.getType().toString()
52: + "; " + f.getStartOffset() + " - " + f.getEndOffset()
53: + "]");
54: System.out.println(f.getDescription() + "["
55: + f.getType().toString() + "; " + f.getStartOffset()
56: + " - " + f.getEndOffset() + "]");
57: //print children
58: for (int i = 0; i < foldCount; i++) {
59: Fold childFold = f.getFold(i);
60: printChildren(childFold, level + 4, out);
61: }
62: }
63:
64: public static String getContextName(int typeId) {
65: switch (typeId) {
66: case JspSyntaxSupport.COMMENT_COMPLETION_CONTEXT:
67: return "comment";
68: case JspSyntaxSupport.CONTENTL_COMPLETION_CONTEXT:
69: return "content language";
70: case JspSyntaxSupport.DIRECTIVE_COMPLETION_CONTEXT:
71: return "directive";
72: case JspSyntaxSupport.ENDTAG_COMPLETION_CONTEXT:
73: return "end tag";
74: case JspSyntaxSupport.SCRIPTINGL_COMPLETION_CONTEXT:
75: return "scripting";
76: case JspSyntaxSupport.TAG_COMPLETION_CONTEXT:
77: return "tag";
78: case JspSyntaxSupport.TEXT_COMPLETION_CONTEXT:
79: return "text";
80: default:
81: return "?";
82: }
83: }
84:
85: }
|