use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.
the class JavadocConverter method visitEntity.
@Override
public Void visitEntity(EntityTree node, TagElement tag) {
String text = String.format("&%s;", node.getName().toString());
tag.addFragment(setPos(node, new TextElement().setText(text)));
return null;
}
use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.
the class JavadocConverter method visitErroneous.
@Override
public Void visitErroneous(ErroneousTree node, TagElement tag) {
if (reportWarnings) {
// Update node's position to be relative to the whole source file, instead of just
// the doc-comment's start. That way, the diagnostic printer will fetch the correct
// text for the line the error is on.
((DCTree.DCErroneous) node).pos = ((DCTree) node).pos((DCTree.DCDocComment) docComment).getStartPosition();
ErrorUtil.warning(node.getDiagnostic().toString());
} else {
// Include erroneous text in doc-comment as is.
TreeNode newNode = setPos(node, new TextElement().setText(node.getBody()));
tag.addFragment(newNode);
}
return null;
}
use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.
the class JavadocConverter method visitParam.
@Override
public Void visitParam(ParamTree node, TagElement tag) {
IdentifierTree identifier = node.getName();
if (identifier == null || node.isTypeParameter()) {
return null;
}
List<? extends VariableElement> params = element instanceof ExecutableElement ? ((ExecutableElement) element).getParameters() : Collections.emptyList();
tag.setTagKind(TagElement.TagKind.PARAM);
String name = identifier.toString();
VariableElement param = null;
for (VariableElement p : params) {
if (name.equals(p.getSimpleName().toString())) {
param = p;
break;
}
}
// param will be null if the @param tag refers to a nonexistent parameter.
TreeNode nameNode = param != null ? new SimpleName(param) : new SimpleName(name);
setPos(identifier, nameNode);
tag.addFragment(nameNode);
scan(node.getDescription(), tag);
int lastEnd = nameNode.getStartPosition();
for (TreeNode fragment : tag.getFragments()) {
// TODO(tball): remove and fix JavadocGenerator after javac switch.
if (fragment.getKind() == TreeNode.Kind.TEXT_ELEMENT) {
TextElement text = (TextElement) fragment;
text.setText(" " + text.getText());
text.setSourceRange(text.getStartPosition(), text.getLength() + 1);
}
int thisEnd = lastEnd + fragment.getLength();
setPos(fragment, lastEnd, thisEnd);
lastEnd = thisEnd;
}
setPos(tag, pos(node), endPos(node));
tag.setLineNumber(nameNode.getLineNumber());
return null;
}
use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.
the class JavadocConverter method visitText.
@Override
public Void visitText(TextTree node, TagElement tag) {
String[] lines = node.getBody().split("\n");
int linePos = pos(node);
for (String line : lines) {
if (line.length() > 0) {
linePos = source.indexOf(line, linePos);
int endPos = linePos + line.length();
TreeNode newNode = setPos(new TextElement().setText(line), linePos, endPos);
tag.addFragment(newNode);
}
}
return null;
}
use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.
the class JavadocConverter method visitEndElement.
@Override
public Void visitEndElement(EndElementTree node, TagElement tag) {
String text = String.format("</%s>", node.getName().toString());
int pos = pos(node);
tag.addFragment(setPos(new TextElement().setText(text), pos, pos + text.length()));
return null;
}
Aggregations