1 package com.github.javaparser; 2 3 import com.github.javaparser.ast.comments.BlockComment; 4 import com.github.javaparser.ast.comments.Comment; 5 import com.github.javaparser.ast.comments.JavadocComment; 6 import com.github.javaparser.ast.comments.LineComment; 7 8 import static com.github.javaparser.GeneratedJavaParserConstants.*; 9 10 /** 11 * Base class for {@link com.github.javaparser.GeneratedJavaParserTokenManager} 12 */ 13 abstract class GeneratedJavaParserTokenManagerBase { 14 /** 15 * Create a TokenRange that spans exactly one token 16 */ tokenRange(Token token)17 private static TokenRange tokenRange(Token token) { 18 JavaToken javaToken = token.javaToken; 19 return new TokenRange(javaToken, javaToken); 20 } 21 22 /** 23 * Since comments are completely captured in a single token, including their delimiters, deconstruct them here so we 24 * can turn them into nodes later on. 25 */ createCommentFromToken(Token token)26 static Comment createCommentFromToken(Token token) { 27 String commentText = token.image; 28 if (token.kind == JAVADOC_COMMENT) { 29 return new JavadocComment(tokenRange(token), commentText.substring(3, commentText.length() - 2)); 30 } else if (token.kind == MULTI_LINE_COMMENT) { 31 return new BlockComment(tokenRange(token), commentText.substring(2, commentText.length() - 2)); 32 } else if (token.kind == SINGLE_LINE_COMMENT) { 33 return new LineComment(tokenRange(token), commentText.substring(2)); 34 } 35 throw new AssertionError("Unexpectedly got passed a non-comment token."); 36 } 37 } 38