use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class JavadocConverter method visitParam.
@Override
public Void visitParam(ParamTree node, TagElement tag) {
DCTree.DCIdentifier identifier = (DCTree.DCIdentifier) node.getName();
if (identifier == null || node.isTypeParameter()) {
return null;
}
List<? extends VariableElement> params = element instanceof ExecutableElement ? ((ExecutableElement) element).getParameters() : Collections.emptyList();
tag.setTagName(TagElement.TAG_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.SimpleName in project j2objc by google.
the class TreeConverter method convertFieldAccess.
private TreeNode convertFieldAccess(JCTree.JCFieldAccess node) {
String fieldName = node.name.toString();
SourcePosition pos = getPosition(node);
JCTree.JCExpression selected = node.getExpression();
if (fieldName.equals("this")) {
return new ThisExpression().setQualifier((Name) convert(selected)).setTypeMirror(node.sym.asType());
}
if ("super".equals(getMemberName(selected))) {
SuperFieldAccess newNode = new SuperFieldAccess().setVariableElement((VariableElement) node.sym).setName(convertSimpleName(node.sym, node.type, pos));
if (selected.getKind() == Kind.MEMBER_SELECT) {
newNode.setQualifier((Name) convert(((JCTree.JCFieldAccess) selected).getExpression()));
}
return newNode;
}
if (node.getIdentifier().toString().equals("class")) {
return new TypeLiteral(node.type).setType((Type) convertType(selected.type, pos, false).setPosition(getPosition(node)));
}
if (selected.getKind() == Kind.IDENTIFIER && (!node.sym.getKind().isField() || ElementUtil.isConstant((VariableElement) node.sym))) {
if (selected.toString().equals("this")) {
// Just return the constant.
return new SimpleName(node.sym);
}
JCIdent ident = (JCTree.JCIdent) selected;
return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier(convertSimpleName(ident.sym, ident.type, pos)).setElement(node.sym);
}
if (selected.getKind() == Kind.MEMBER_SELECT) {
TreeNode newSelected = convertFieldAccess((JCTree.JCFieldAccess) selected).setPosition(pos);
if (newSelected.getKind() == TreeNode.Kind.QUALIFIED_NAME) {
return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier((QualifiedName) newSelected).setElement(node.sym);
}
}
if (ElementUtil.isConstant((VariableElement) node.sym) && ElementUtil.isStatic(node.sym) && !(selected.getKind() == Kind.METHOD_INVOCATION)) {
return new QualifiedName().setName(convertSimpleName(node.sym, node.type, pos)).setQualifier((Name) convert(selected)).setElement(node.sym);
}
return new FieldAccess().setVariableElement((VariableElement) node.sym).setExpression((Expression) convert(selected)).setName(convertSimpleName(node.sym, node.type, pos).setTypeMirror(node.type));
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class TreeConverter method convertBreakStatement.
private TreeNode convertBreakStatement(JCTree.JCBreak node) {
BreakStatement newNode = new BreakStatement();
Object label = node.getLabel();
if (label != null) {
newNode.setLabel((SimpleName) new SimpleName(label.toString()).setPosition(getPosition(node)));
}
return newNode;
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class TreeConverter method convertContinueStatement.
private TreeNode convertContinueStatement(JCTree.JCContinue node) {
ContinueStatement newNode = new ContinueStatement();
Object label = node.getLabel();
if (label != null) {
newNode.setLabel((SimpleName) new SimpleName(label.toString()).setPosition(getPosition(node)));
}
return newNode;
}
use of com.google.devtools.j2objc.ast.SimpleName in project j2objc by google.
the class JavadocGenerator method printTagFragments.
private String printTagFragments(List<TreeNode> fragments) {
if (fragments.isEmpty()) {
return "";
}
StringBuilder sb = new StringBuilder();
int lineNo = fragments.get(0).getLineNumber();
for (TreeNode fragment : fragments) {
if (fragment.getLineNumber() > lineNo) {
sb.append("\n ");
lineNo = fragment.getLineNumber();
}
if (fragment instanceof TextElement) {
if (spanningPreTag) {
sb.append(getSourceIndent(fragment));
}
String text = escapeDocText(((TextElement) fragment).getText());
sb.append(text);
} else if (fragment instanceof TagElement) {
sb.append(printTag((TagElement) fragment));
} else if (fragment instanceof SimpleName) {
Element element = ((Name) fragment).getElement();
if (element != null && ElementUtil.isVariable(element)) {
sb.append(NameTable.getDocCommentVariableName(((VariableElement) element)));
} else {
sb.append(fragment.toString());
}
} else {
sb.append(fragment.toString().trim());
}
}
return sb.toString();
}
Aggregations