use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convertAnnotationTypeDeclaration.
private TreeNode convertAnnotationTypeDeclaration(JCTree.JCClassDecl node) {
AnnotationTypeDeclaration newNode = new AnnotationTypeDeclaration();
convertBodyDeclaration(node, node.getModifiers(), newNode, node.sym);
for (JCTree bodyDecl : node.getMembers()) {
if (bodyDecl.getKind() == Kind.METHOD) {
JCTree.JCMethodDecl methodDecl = (JCTree.JCMethodDecl) bodyDecl;
AnnotationTypeMemberDeclaration newMember = new AnnotationTypeMemberDeclaration().setDefault((Expression) convert(methodDecl.defaultValue)).setExecutableElement(methodDecl.sym);
newMember.setModifiers((int) methodDecl.getModifiers().flags).setAnnotations(convertAnnotations(methodDecl.mods)).setJavadoc((Javadoc) getAssociatedJavaDoc(methodDecl, methodDecl.sym));
newNode.addBodyDeclaration(newMember);
} else {
newNode.addBodyDeclaration((BodyDeclaration) convert(bodyDecl));
}
}
return newNode.setName(convertSimpleName(node.sym, node.type, getNamePosition(node))).setTypeElement(node.sym);
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class TreeConverter method convert.
private TreeNode convert(Object obj) {
if (obj == null) {
return null;
}
JCTree node = (JCTree) obj;
TreeNode newNode = convertInner(node).setPosition(getPosition(node));
if (newNode instanceof Expression) {
copyConstantValue(node, (Expression) newNode);
}
return newNode;
}
use of com.google.devtools.j2objc.ast.Expression 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.Expression 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());
}
use of com.google.devtools.j2objc.ast.Expression in project j2objc by google.
the class ClassFileConverter method convertAnnotationTypeMemberDeclaration.
private AnnotationTypeMemberDeclaration convertAnnotationTypeMemberDeclaration(ExecutableElement element) {
AnnotationValue annotValue = element.getDefaultValue();
Expression expr = annotValue != null ? convertAnnotationValue(element.getReturnType(), annotValue) : null;
AnnotationTypeMemberDeclaration memberDeclaration = new AnnotationTypeMemberDeclaration(element).setDefault(expr);
convertBodyDeclaration(memberDeclaration, element);
return memberDeclaration;
}
Aggregations