1 11 12 package org.eclipse.jdt.core.dom; 13 14 import org.eclipse.jdt.core.compiler.InvalidInputException; 15 import org.eclipse.jdt.internal.compiler.parser.Scanner; 16 import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; 17 18 76 public abstract class Statement extends ASTNode { 77 78 84 private String optionalLeadingComment = null; 85 86 94 Statement(AST ast) { 95 super(ast); 96 } 97 98 120 public String getLeadingComment() { 121 return optionalLeadingComment; 122 } 123 124 156 public void setLeadingComment(String comment) { 157 if (comment != null) { 158 char[] source = comment.toCharArray(); 159 Scanner scanner = this.ast.scanner; 160 scanner.resetTo(0, source.length); 161 scanner.setSource(source); 162 try { 163 int token; 164 boolean onlyOneComment = false; 165 while ((token = scanner.getNextToken()) != TerminalTokens.TokenNameEOF) { 166 switch(token) { 167 case TerminalTokens.TokenNameCOMMENT_BLOCK : 168 case TerminalTokens.TokenNameCOMMENT_JAVADOC : 169 case TerminalTokens.TokenNameCOMMENT_LINE : 170 if (onlyOneComment) { 171 throw new IllegalArgumentException (); 172 } 173 onlyOneComment = true; 174 break; 175 default: 176 onlyOneComment = false; 177 } 178 } 179 if (!onlyOneComment) { 180 throw new IllegalArgumentException (); 181 } 182 } catch (InvalidInputException e) { 183 throw new IllegalArgumentException (); 184 } 185 } 186 checkModifiable(); 189 this.optionalLeadingComment = comment; 190 } 191 192 198 void copyLeadingComment(Statement source) { 199 setLeadingComment(source.getLeadingComment()); 200 } 201 202 205 int memSize() { 206 int size = BASE_NODE_SIZE + 1 * 4 + stringSize(getLeadingComment()); 207 return size; 208 } 209 } 210 211 | Popular Tags |