use of com.google.devtools.j2objc.ast.BlockComment in project j2objc by google.
the class TreeConverter method addNativeComments.
private static void addNativeComments(CompilationUnit unit, String delim, String endDelim) {
// Can't use a regex because it will greedily include everything between
// the first and last closing pattern, resulting in a single comment node.
String source = unit.getSource();
int startPos = 0;
int endPos = 0;
while ((startPos = source.indexOf(delim, endPos)) > -1) {
endPos = source.indexOf(endDelim, startPos);
if (endPos > startPos) {
// Include closing delimiter.
endPos += 4;
BlockComment ocniComment = new BlockComment();
ocniComment.setSourceRange(startPos, endPos - startPos);
unit.getCommentList().add(ocniComment);
}
}
}
use of com.google.devtools.j2objc.ast.BlockComment in project j2objc by google.
the class TreeConverter method convertAssociatedComment.
private Comment convertAssociatedComment(JCTree node, Element element) {
boolean docCommentsEnabled = newUnit.getEnv().options().docCommentsEnabled();
DocCommentTable docComments = unit.docComments;
if (!docCommentsEnabled || docComments == null || !docComments.hasComment(node)) {
return null;
}
com.sun.tools.javac.parser.Tokens.Comment javacComment = docComments.getComment(node);
Comment comment;
switch(javacComment.getStyle()) {
case BLOCK:
comment = new BlockComment();
break;
case JAVADOC:
comment = docCommentsEnabled ? convertJavadocComment(element) : new Javadoc();
break;
case LINE:
comment = new LineComment();
break;
default:
throw new AssertionError("unknown comment type");
}
int startPos = javacComment.getSourcePos(0);
int endPos = startPos + javacComment.getText().length();
comment.setSourceRange(startPos, endPos);
comment.setLineNumber(unit.getLineMap().getLineNumber(startPos));
return comment;
}
Aggregations