Search in sources :

Example 1 with TypeMethodReference

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

the class TreeConverter method convertTypeMethodReference.

private static TreeNode convertTypeMethodReference(org.eclipse.jdt.core.dom.TypeMethodReference node) {
    TypeMethodReference newNode = new TypeMethodReference();
    IMethodBinding methodBinding = node.resolveMethodBinding();
    if (node.getType().resolveBinding().isArray()) {
        // JDT does not provide the correct method on array types, so we find it from
        // java.lang.Object.
        IMethodBinding functionalInterface = getFunctionalInterface(node.resolveTypeBinding());
        methodBinding = getObjectMethod(node.getAST(), node.getName().getIdentifier(), functionalInterface.getParameterTypes().length - 1);
    }
    convertMethodReference(node, newNode, methodBinding, !BindingUtil.isStatic(methodBinding));
    return newNode.setName((SimpleName) TreeConverter.convert(node.getName())).setType((Type) TreeConverter.convert(node.getType()));
}
Also used : IMethodBinding(org.eclipse.jdt.core.dom.IMethodBinding) SimpleName(com.google.devtools.j2objc.ast.SimpleName) TypeMethodReference(com.google.devtools.j2objc.ast.TypeMethodReference)

Example 2 with TypeMethodReference

use of com.google.devtools.j2objc.ast.TypeMethodReference 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

TypeMethodReference (com.google.devtools.j2objc.ast.TypeMethodReference)2 CreationReference (com.google.devtools.j2objc.ast.CreationReference)1 ExpressionMethodReference (com.google.devtools.j2objc.ast.ExpressionMethodReference)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 JCTree (com.sun.tools.javac.tree.JCTree)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 PackageElement (javax.lang.model.element.PackageElement)1 VariableElement (javax.lang.model.element.VariableElement)1 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)1