1 19 package org.netbeans.modules.java.source.builder; 20 21 import com.sun.tools.javadoc.DocCommentScanner; 22 import org.netbeans.api.java.source.query.CommentHandler; 23 import com.sun.tools.javac.util.Context; 24 import org.netbeans.modules.java.source.save.SourceBuffer; 25 26 30 public class Scanner extends DocCommentScanner { 31 32 static final boolean TRACE_TOKEN = false; 33 static final boolean TRACE_COMMENT = false; 34 static final boolean TRACE_WHITESPACE = false; 35 36 40 public static class Factory extends DocCommentScanner.Factory { 41 42 public static com.sun.tools.javac.parser.Scanner.Factory instance(Context context) { 43 com.sun.tools.javac.parser.Scanner.Factory instance = context.get(scannerFactoryKey); 44 if (instance == null) 45 instance = new Factory(context); 46 return instance; 47 } 48 49 Factory(Context context) { 50 super(context); 51 } 52 53 public com.sun.tools.javac.parser.Scanner newScanner(CharSequence source, 54 BufferRunQueue runs) { 55 return new Scanner(this, source, runs); 56 } 57 } 58 59 CharSequence source; 60 BufferRunQueue runs; 61 62 69 protected Scanner(Factory fac, CharSequence source, BufferRunQueue runs) { 70 super(fac, source.toString().toCharArray(), source.length()); 71 this.source = source; 72 this.runs = runs; 73 74 if (TRACE_TOKEN || TRACE_COMMENT) 75 System.err.println("\nScanner:\n--------"); 76 } 77 78 81 @Override 82 public void nextToken() { 83 super.nextToken(); 84 BufferRun br = new TokenRun(pos(), endPos(), token()); 85 runs.add(br); 86 if (TRACE_TOKEN) { 87 System.err.println("token:" + token() + " pos:" + pos() + 88 " endpos:" + endPos() + " \"" + br.getString(source) + "\""); 89 } 90 } 91 92 95 @Override 96 protected void processComment(CommentStyle style) { 97 super.processComment(style); 98 BufferRun br = new CommentRun(pos(), endPos(), style); 99 if (TRACE_COMMENT) { 100 String dc = docComment(); 101 System.err.println("comment:" + style + " pos:" + pos() + 102 " endpos:" + endPos() + 103 " \"" + br.getString(source) + "\""); 104 if (dc != null) 105 System.err.println("docComment:" + " \"" + dc + "\""); 106 } 107 runs.add(br); 108 } 109 110 113 @Override 114 protected void processWhiteSpace() { 115 super.processWhiteSpace(); 116 if (TRACE_WHITESPACE) { 117 System.err.println("whitespace pos:" + pos() + 118 " endpos:" + endPos()); 119 } 120 runs.add(new WhitespaceRun(pos(), endPos())); 121 } 122 123 126 @Override 127 protected void processLineTerminator() { 128 super.processLineTerminator(); 129 if (TRACE_WHITESPACE) { 130 System.err.println("lineterminator pos:" + pos() + 131 " endpos:" + endPos()); 132 } 133 runs.add(new LineEndingRun(pos(), endPos())); 134 } 135 } 136 | Popular Tags |