Search in sources :

Example 1 with ExpressionMethodReference

use of com.google.devtools.j2objc.ast.ExpressionMethodReference in project j2objc by google.

the class TreeConverter method convertExpressionMethodReference.

private static TreeNode convertExpressionMethodReference(org.eclipse.jdt.core.dom.ExpressionMethodReference node) {
    IMethodBinding methodBinding = node.resolveMethodBinding();
    ExpressionMethodReference newNode = new ExpressionMethodReference();
    Expression expression = (Expression) convert(node.getExpression());
    boolean consumesFirstParam = !BindingUtil.isStatic(methodBinding) && expression instanceof Name && !ElementUtil.isVariable(((Name) expression).getElement());
    convertMethodReference(node, newNode, methodBinding, consumesFirstParam);
    return newNode.setName((SimpleName) TreeConverter.convert(node.getName())).setExpression(expression);
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) ExpressionMethodReference(com.google.devtools.j2objc.ast.ExpressionMethodReference) PostfixExpression(com.google.devtools.j2objc.ast.PostfixExpression) InstanceofExpression(com.google.devtools.j2objc.ast.InstanceofExpression) Expression(com.google.devtools.j2objc.ast.Expression) ConditionalExpression(com.google.devtools.j2objc.ast.ConditionalExpression) InfixExpression(com.google.devtools.j2objc.ast.InfixExpression) ParenthesizedExpression(com.google.devtools.j2objc.ast.ParenthesizedExpression) LambdaExpression(com.google.devtools.j2objc.ast.LambdaExpression) PrefixExpression(com.google.devtools.j2objc.ast.PrefixExpression) ThisExpression(com.google.devtools.j2objc.ast.ThisExpression) FunctionalExpression(com.google.devtools.j2objc.ast.FunctionalExpression) CastExpression(com.google.devtools.j2objc.ast.CastExpression) VariableDeclarationExpression(com.google.devtools.j2objc.ast.VariableDeclarationExpression) SimpleName(com.google.devtools.j2objc.ast.SimpleName) SimpleName(com.google.devtools.j2objc.ast.SimpleName) Name(com.google.devtools.j2objc.ast.Name) QualifiedName(com.google.devtools.j2objc.ast.QualifiedName)

Example 2 with ExpressionMethodReference

use of com.google.devtools.j2objc.ast.ExpressionMethodReference in project j2objc by google.

the class TreeConverter method convertMemberReference.

private TreeNode convertMemberReference(JCTree.JCMemberReference node) {
    Element element = node.sym;
    SourcePosition pos = getPosition(node);
    if (ElementUtil.isConstructor(element)) {
        CreationReference newNode = new CreationReference();
        convertMethodReference(node, newNode);
        return newNode.setType(Type.newType(nameType(node.expr)));
    }
    if (node.hasKind(JCTree.JCMemberReference.ReferenceKind.SUPER)) {
        SuperMethodReference newNode = new SuperMethodReference();
        convertMethodReference(node, newNode);
        if (node.getQualifierExpression().getKind() == Kind.IDENTIFIER) {
            // super::foo
            return newNode;
        } else {
            // Qualifier expression is <name>."super", so it's always a JCFieldAccess.
            JCTree.JCFieldAccess expr = (JCTree.JCFieldAccess) node.getQualifierExpression();
            return newNode.setQualifier(convertSimpleName(nameSymbol(expr.selected), expr.type, getPosition(expr.selected)));
        }
    }
    if (node.hasKind(JCTree.JCMemberReference.ReferenceKind.UNBOUND) || node.hasKind(JCTree.JCMemberReference.ReferenceKind.STATIC)) {
        TypeMethodReference newNode = new TypeMethodReference();
        convertMethodReference(node, newNode);
        return newNode.setName(convertSimpleName(node.sym, node.type, pos)).setType(convertType(node.type, pos, false));
    }
    ExpressionMethodReference newNode = new ExpressionMethodReference();
    convertMethodReference(node, newNode);
    return newNode.setName(convertSimpleName(node.sym, node.type, pos)).setExpression((Expression) convert(node.getQualifierExpression()));
}
Also used : ExpressionMethodReference(com.google.devtools.j2objc.ast.ExpressionMethodReference) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) SourcePosition(com.google.devtools.j2objc.ast.SourcePosition) CreationReference(com.google.devtools.j2objc.ast.CreationReference) JCTree(com.sun.tools.javac.tree.JCTree) TypeMethodReference(com.google.devtools.j2objc.ast.TypeMethodReference) SuperMethodReference(com.google.devtools.j2objc.ast.SuperMethodReference)

Aggregations

ExpressionMethodReference (com.google.devtools.j2objc.ast.ExpressionMethodReference)2 CastExpression (com.google.devtools.j2objc.ast.CastExpression)1 ConditionalExpression (com.google.devtools.j2objc.ast.ConditionalExpression)1 CreationReference (com.google.devtools.j2objc.ast.CreationReference)1 Expression (com.google.devtools.j2objc.ast.Expression)1 FunctionalExpression (com.google.devtools.j2objc.ast.FunctionalExpression)1 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)1 InstanceofExpression (com.google.devtools.j2objc.ast.InstanceofExpression)1 LambdaExpression (com.google.devtools.j2objc.ast.LambdaExpression)1 Name (com.google.devtools.j2objc.ast.Name)1 ParenthesizedExpression (com.google.devtools.j2objc.ast.ParenthesizedExpression)1 PostfixExpression (com.google.devtools.j2objc.ast.PostfixExpression)1 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)1 QualifiedName (com.google.devtools.j2objc.ast.QualifiedName)1 SimpleName (com.google.devtools.j2objc.ast.SimpleName)1 SourcePosition (com.google.devtools.j2objc.ast.SourcePosition)1 SuperMethodReference (com.google.devtools.j2objc.ast.SuperMethodReference)1 ThisExpression (com.google.devtools.j2objc.ast.ThisExpression)1 TypeMethodReference (com.google.devtools.j2objc.ast.TypeMethodReference)1 VariableDeclarationExpression (com.google.devtools.j2objc.ast.VariableDeclarationExpression)1