1 19 20 package org.netbeans.modules.retouche.editor; 21 22 import javax.swing.text.Document ; 23 import org.netbeans.editor.BaseImageTokenID; 24 import org.netbeans.editor.TokenContext; 25 import org.netbeans.editor.TokenID; 26 import org.netbeans.editor.TokenItem; 27 import org.netbeans.editor.TokenContextPath; 28 import org.netbeans.editor.TokenItem; 29 import org.netbeans.editor.ext.FormatTokenPosition; 30 import org.netbeans.editor.ext.ExtFormatSupport; 31 import org.netbeans.editor.ext.FormatWriter; 32 import org.netbeans.modules.gsf.Language; 33 34 45 46 public class GsfFormatSupport extends ExtFormatSupport { 47 48 private TokenContextPath tokenContextPath; 49 private Language language; 50 private Document doc; 51 52 public GsfFormatSupport(FormatWriter formatWriter, Language language, Document doc) { 53 this(formatWriter, null, language, doc); 54 assert doc != null; 55 } 56 57 public GsfFormatSupport(FormatWriter formatWriter, TokenContextPath tokenContextPath, Language language, Document doc) { 58 super(formatWriter); 59 assert doc != null; 60 if (tokenContextPath == null) { 61 TokenContext context = new TokenContext("gsf"); 62 tokenContextPath = context.getContextPath(); 63 } 64 this.tokenContextPath = tokenContextPath; 65 this.language = language; 66 this.doc = doc; 67 } 68 69 public TokenContextPath getTokenContextPath() { 70 return tokenContextPath; 71 } 72 73 public boolean isComment(TokenItem token, int offset) { 74 TokenID tokenID = token.getTokenID(); 75 return false; 79 } 80 81 public boolean isMultiLineComment(TokenItem token) { 82 return false; 84 } 85 86 public boolean isMultiLineComment(FormatTokenPosition pos) { 87 TokenItem token = pos.getToken(); 88 return (token == null) ? false : isMultiLineComment(token); 89 } 90 91 94 public boolean isJavaDocComment(TokenItem token) { 95 return isMultiLineComment(token) 96 && token.getImage().startsWith("/**"); 97 } 98 99 public TokenID getWhitespaceTokenID() { 100 return new BaseImageTokenID(" "); 103 } 104 105 public TokenContextPath getWhitespaceTokenContextPath() { 106 return tokenContextPath; 107 } 108 109 public boolean canModifyWhitespace(TokenItem inToken) { 110 return false; 119 } 120 121 122 132 public int getTokenIndent(TokenItem token, boolean forceFirstNonWhitespace) { 133 FormatTokenPosition tp = getPosition(token, 0); 134 FormatTokenPosition fnw; 138 if (forceFirstNonWhitespace) 139 fnw = findLineFirstNonWhitespace(tp); 140 else 141 fnw = findLineFirstNonWhitespaceAndNonLeftBrace(tp); 142 143 if (fnw != null) { tp = fnw; 145 } 146 return getVisualColumnOffset(tp); 147 } 148 149 public int getTokenIndent(TokenItem token) { 150 return getTokenIndent(token, false); 151 } 152 153 public int findIndent(TokenItem token) { 154 int indent = -1; 156 if (token != null) { 158 } 159 160 if (indent < 0) { TokenItem t = findImportantToken(token, null, true); 163 if (t != null) { if (indent < 0) { indent = getTokenIndent(t); 166 } 167 } 168 } 169 170 if (indent < 0) { indent = 0; 172 } 173 174 return indent; 175 } 176 177 178 public FormatTokenPosition indentLine(FormatTokenPosition pos) { 179 if (language.getFormatter() != null) { 180 int offset = getFormatWriter().getOffset(); 182 return changeLineIndent(pos, language.getFormatter().getLineIndent(doc, offset, 183 new GsfFormatter.GenericFormattingPreferences(language.getFormatter().indentSize()))); 184 } 185 186 int indent = 0; 188 FormatTokenPosition firstNWS = findLineFirstNonWhitespace(pos); 190 if (firstNWS != null) { if (isComment(firstNWS)) { } else { indent = findIndent(firstNWS.getToken()); 194 } 195 } else { TokenItem token = pos.getToken(); 198 if (token == null) { 199 token = findLineStart(pos).getToken(); 200 if (token == null) { token = getLastToken(); 202 } 203 } 204 indent = findIndent(pos.getToken()); 205 } 206 207 return changeLineIndent(pos, indent); 209 } 210 211 217 public FormatTokenPosition findLineFirstNonWhitespaceAndNonLeftBrace(FormatTokenPosition pos) { 218 FormatTokenPosition ftp = super.findLineFirstNonWhitespace(pos); 220 if (ftp == null) { return null; 222 } 223 224 System.err.println("Bogus findLineFirstNonWhitespaceAndNonLeftBrace implementation"); 225 226 return ftp; 227 } 228 } 229 | Popular Tags |