Java Code Examples for com.sun.source.tree.MemberReferenceTree.ReferenceMode#INVOKE

The following examples show how to use com.sun.source.tree.MemberReferenceTree.ReferenceMode#INVOKE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LambdaToMethod.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 2
Source File: JavacParser.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 3
Source File: JavacParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 4
Source File: LambdaToMethod.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 5
Source File: JavacParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 6
Source File: LambdaToMethod.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 7
Source File: JavacParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 8
Source File: LambdaToMethod.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 9
Source File: JavacParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 10
Source File: LambdaToMethod.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 11
Source File: JavacParser.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 12
Source File: LambdaToMethod.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 13
Source File: JavacParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 14
Source File: LambdaToMethod.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
JCLambda lambda() {
    int prevPos = make.pos;
    try {
        make.at(tree);

        //body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        VarSymbol rcvr = addParametersReturnReceiver();
        JCExpression expr = (tree.getMode() == ReferenceMode.INVOKE)
                ? expressionInvoke(rcvr)
                : expressionNew();

        JCLambda slam = make.Lambda(params.toList(), expr);
        slam.targets = tree.targets;
        slam.type = tree.type;
        slam.pos = tree.pos;
        return slam;
    } finally {
        make.at(prevPos);
    }
}
 
Example 15
Source File: JavacParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 16
Source File: JavacParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
JCExpression memberReferenceSuffix(int pos1, JCExpression t) {
    checkMethodReferences();
    mode = EXPR;
    List<JCExpression> typeArgs = null;
    if (token.kind == LT) {
        typeArgs = typeArguments(false);
    }
    Name refName;
    ReferenceMode refMode;
    if (token.kind == NEW) {
        refMode = ReferenceMode.NEW;
        refName = names.init;
        nextToken();
    } else {
        refMode = ReferenceMode.INVOKE;
        refName = ident();
    }
    return toP(F.at(t.getStartPosition()).Reference(refMode, refName, t, typeArgs));
}
 
Example 17
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void visitReference(JCMemberReference tree) {
    printExpr(tree.expr);
    print(cs.spaceAroundMethodReferenceDoubleColon() ? " :: " : "::");
    if (tree.typeargs != null && !tree.typeargs.isEmpty()) {
        print("<");
        printExprs(tree.typeargs);
        print(">");
    }
    if (tree.getMode() == ReferenceMode.INVOKE) print(tree.name);
    else print("new");
}
 
Example 18
Source File: LambdaToMethod.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the bridge
 */
JCMethodDecl bridge() {
    int prevPos = make.pos;
    try {
        make.at(tree);
        Type samDesc = localContext.bridgedRefSig();
        List<Type> samPTypes = samDesc.getParameterTypes();

        //an extra argument is prepended to the signature of the bridge in case
        //the member reference is an instance method reference (in which case
        //the receiver expression is passed to the bridge itself).
        Type recType = null;
        switch (tree.kind) {
            case IMPLICIT_INNER:
                recType = tree.sym.owner.type.getEnclosingType();
                break;
            case BOUND:
                recType = tree.getQualifierExpression().type;
                break;
            case UNBOUND:
                recType = samPTypes.head;
                samPTypes = samPTypes.tail;
                break;
        }

        //generate the parameter list for the bridged member reference - the
        //bridge signature will match the signature of the target sam descriptor

        VarSymbol rcvr = (recType == null)
                ? null
                : addParameter("rec$", recType, false);

        List<Type> refPTypes = tree.sym.type.getParameterTypes();
        int refSize = refPTypes.size();
        int samSize = samPTypes.size();
        // Last parameter to copy from referenced method
        int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize;

        List<Type> l = refPTypes;
        // Use parameter types of the referenced method, excluding final var args
        for (int i = 0; l.nonEmpty() && i < last; ++i) {
            addParameter("x$" + i, l.head, true);
            l = l.tail;
        }
        // Flatten out the var args
        for (int i = last; i < samSize; ++i) {
            addParameter("xva$" + i, tree.varargsElement, true);
        }

        //generate the bridge method declaration
        JCMethodDecl bridgeDecl = make.MethodDef(make.Modifiers(localContext.bridgeSym.flags()),
                localContext.bridgeSym.name,
                make.QualIdent(samDesc.getReturnType().tsym),
                List.<JCTypeParameter>nil(),
                params.toList(),
                tree.sym.type.getThrownTypes() == null
                ? List.<JCExpression>nil()
                : make.Types(tree.sym.type.getThrownTypes()),
                null,
                null);
        bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym;
        bridgeDecl.type = localContext.bridgeSym.type =
                types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList()));

        //bridge method body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        JCExpression bridgeExpr = (tree.getMode() == ReferenceMode.INVOKE)
                ? bridgeExpressionInvoke(makeReceiver(rcvr))
                : bridgeExpressionNew();

        //the body is either a return expression containing a method call,
        //or the method call itself, depending on whether the return type of
        //the bridge is non-void/void.
        bridgeDecl.body = makeLambdaExpressionBody(bridgeExpr, bridgeDecl);

        return bridgeDecl;
    } finally {
        make.at(prevPos);
    }
}
 
Example 19
Source File: LambdaToMethod.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Generate the bridge
 */
JCMethodDecl bridge() {
    int prevPos = make.pos;
    try {
        make.at(tree);
        Type samDesc = localContext.bridgedRefSig();
        List<Type> samPTypes = samDesc.getParameterTypes();

        //an extra argument is prepended to the signature of the bridge in case
        //the member reference is an instance method reference (in which case
        //the receiver expression is passed to the bridge itself).
        Type recType = null;
        switch (tree.kind) {
            case IMPLICIT_INNER:
                recType = tree.sym.owner.type.getEnclosingType();
                break;
            case BOUND:
                recType = tree.getQualifierExpression().type;
                break;
            case UNBOUND:
                recType = samPTypes.head;
                samPTypes = samPTypes.tail;
                break;
        }

        //generate the parameter list for the bridged member reference - the
        //bridge signature will match the signature of the target sam descriptor

        VarSymbol rcvr = (recType == null)
                ? null
                : addParameter("rec$", recType, false);

        List<Type> refPTypes = tree.sym.type.getParameterTypes();
        int refSize = refPTypes.size();
        int samSize = samPTypes.size();
        // Last parameter to copy from referenced method
        int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize;

        List<Type> l = refPTypes;
        // Use parameter types of the referenced method, excluding final var args
        for (int i = 0; l.nonEmpty() && i < last; ++i) {
            addParameter("x$" + i, l.head, true);
            l = l.tail;
        }
        // Flatten out the var args
        for (int i = last; i < samSize; ++i) {
            addParameter("xva$" + i, tree.varargsElement, true);
        }

        //generate the bridge method declaration
        JCMethodDecl bridgeDecl = make.MethodDef(make.Modifiers(localContext.bridgeSym.flags()),
                localContext.bridgeSym.name,
                make.QualIdent(samDesc.getReturnType().tsym),
                List.<JCTypeParameter>nil(),
                params.toList(),
                tree.sym.type.getThrownTypes() == null
                ? List.<JCExpression>nil()
                : make.Types(tree.sym.type.getThrownTypes()),
                null,
                null);
        bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym;
        bridgeDecl.type = localContext.bridgeSym.type =
                types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList()));

        //bridge method body generation - this can be either a method call or a
        //new instance creation expression, depending on the member reference kind
        JCExpression bridgeExpr = (tree.getMode() == ReferenceMode.INVOKE)
                ? bridgeExpressionInvoke(makeReceiver(rcvr))
                : bridgeExpressionNew();

        //the body is either a return expression containing a method call,
        //or the method call itself, depending on whether the return type of
        //the bridge is non-void/void.
        bridgeDecl.body = makeLambdaExpressionBody(bridgeExpr, bridgeDecl);

        return bridgeDecl;
    } finally {
        make.at(prevPos);
    }
}