use of com.google.devtools.j2objc.ast.SuperFieldAccess 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.SuperFieldAccess in project j2objc by google.
the class TreeConverter method convertFieldAccess.
private TreeNode convertFieldAccess(MemberSelectTree node, TreePath parent) {
TreePath path = getTreePath(parent, node);
String fieldName = node.getIdentifier().toString();
SourcePosition pos = getPosition(node);
ExpressionTree selected = node.getExpression();
TreePath selectedPath = getTreePath(path, selected);
Element element = getElement(path);
TypeMirror typeMirror = getTypeMirror(path);
if (fieldName.equals("this")) {
return new ThisExpression().setQualifier((Name) convert(selected, path)).setTypeMirror(typeMirror);
}
if ("super".equals(getMemberName(selected))) {
SuperFieldAccess newNode = new SuperFieldAccess().setVariableElement((VariableElement) element).setTypeMirror(typeMirror);
if (selected.getKind() == Kind.MEMBER_SELECT) {
newNode.setQualifier((Name) convert(((MemberSelectTree) selected).getExpression(), selectedPath));
}
return newNode;
}
if (node.getIdentifier().toString().equals("class")) {
Type type = convertType(getTypeMirror(selectedPath), pos, false);
type.setPosition(getPosition(node));
return new TypeLiteral(typeMirror).setType(type);
}
if (selected.getKind() == Kind.IDENTIFIER && (!element.getKind().isField() || ElementUtil.isConstant((VariableElement) element))) {
if (selected.toString().equals("this")) {
// Just return the constant.
return new SimpleName(element);
}
return new QualifiedName().setName(convertSimpleName(element, typeMirror, pos)).setQualifier(convertSimpleName(getElement(selectedPath), getTypeMirror(selectedPath), pos)).setElement(element);
}
if (selected.getKind() == Kind.MEMBER_SELECT) {
TreeNode newSelected = convertFieldAccess((MemberSelectTree) selected, path).setPosition(pos);
if (newSelected.getKind() == TreeNode.Kind.QUALIFIED_NAME) {
return new QualifiedName().setName(convertSimpleName(element, typeMirror, pos)).setQualifier((QualifiedName) newSelected).setElement(element);
}
}
if (ElementUtil.isConstant((VariableElement) element) && ElementUtil.isStatic(element) && !(selected.getKind() == Kind.METHOD_INVOCATION) && !(selected.getKind() == Kind.MEMBER_SELECT) && !(selected.getKind() == Kind.PARENTHESIZED)) {
return new QualifiedName().setName(convertSimpleName(element, typeMirror, pos)).setQualifier((Name) convert(selected, path)).setElement(element);
}
return new FieldAccess().setVariableElement((VariableElement) element).setExpression((Expression) convert(selected, path)).setName(convertSimpleName(element, typeMirror, pos).setTypeMirror(typeMirror));
}
Aggregations