use of com.google.devtools.j2objc.ast.QualifiedName in project j2objc by google.
the class TreeConverter method convertQualifiedName.
private static TreeNode convertQualifiedName(org.eclipse.jdt.core.dom.QualifiedName node) {
QualifiedName newNode = new QualifiedName();
convertName(node, newNode);
return newNode.setQualifier((Name) TreeConverter.convert(node.getQualifier())).setName((SimpleName) TreeConverter.convert(node.getName()));
}
use of com.google.devtools.j2objc.ast.QualifiedName 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.QualifiedName 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));
}
use of com.google.devtools.j2objc.ast.QualifiedName in project j2objc by google.
the class StatementGenerator method visit.
@Override
public boolean visit(QualifiedName node) {
Element element = node.getElement();
if (ElementUtil.isVariable(element)) {
VariableElement var = (VariableElement) element;
if (ElementUtil.isGlobalVar(var)) {
buffer.append(nameTable.getVariableQualifiedName(var));
return false;
}
}
if (ElementUtil.isTypeElement(element)) {
buffer.append(nameTable.getFullName((TypeElement) element));
return false;
}
Name qualifier = node.getQualifier();
qualifier.accept(this);
buffer.append("->");
node.getName().accept(this);
return false;
}
use of com.google.devtools.j2objc.ast.QualifiedName in project j2objc by google.
the class OuterReferenceResolverTest method testOuterVarAccess.
public void testOuterVarAccess() {
resolveSource("Test", "class Test { int i; class Inner { void test() { i++; } } }");
TypeDeclaration innerNode = (TypeDeclaration) nodesByType.get(Kind.TYPE_DECLARATION).get(1);
assertTrue(captureInfo.needsOuterReference(innerNode.getTypeElement()));
PostfixExpression increment = (PostfixExpression) nodesByType.get(Kind.POSTFIX_EXPRESSION).get(0);
Expression iNode = increment.getOperand();
assertTrue(iNode instanceof QualifiedName);
VariableElement outerVar = TreeUtil.getVariableElement(((QualifiedName) iNode).getQualifier());
assertNotNull(outerVar);
assertEquals("Test", outerVar.asType().toString());
}
Aggregations