Java 类com.sun.source.tree.MemberReferenceTree.ReferenceMode 实例源码

项目:OpenJSharp    文件:JavacParser.java   
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));
}
项目:OpenJSharp    文件:LambdaToMethod.java   
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);
    }
}
项目:openjdk-jdk10    文件:JavacParser.java   
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));
}
项目:openjdk-jdk10    文件:LambdaToMethod.java   
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);
    }
}
项目:openjdk9    文件:JavacParser.java   
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));
}
项目:openjdk9    文件:LambdaToMethod.java   
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);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:JavacParser.java   
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));
}
项目:lookaside_java-1.8.0-openjdk    文件:LambdaToMethod.java   
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);
    }
}
项目:jsr308-langtools    文件:JavacParser.java   
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));
}
项目:jsr308-langtools    文件:LambdaToMethod.java   
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);
    }
}
项目:infobip-open-jdk-8    文件:JavacParser.java   
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));
}
项目:infobip-open-jdk-8    文件:LambdaToMethod.java   
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);
    }
}
项目:error-prone    文件:FutureReturnValueIgnored.java   
/**
 * Detect member references that implement an interface that return Object, but resolve to a
 * method that returns Future.
 */
@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
  Description description = super.matchMemberReference(tree, state);
  if (Description.NO_MATCH == description) {
    if (allOf(
            (t, s) -> t.getMode() == ReferenceMode.INVOKE,
            FutureReturnValueIgnored::isObjectReturningMethodReferenceExpression,
            not((t, s) -> isWhitelistedInterfaceType(((JCMemberReference) t).type, s)),
            not((t, s) -> isThrowingFunctionalInterface(s, ((JCMemberReference) t).type)),
            specializedMatcher())
        .matches(tree, state)) {
      return describeMatch(tree);
    }
  }
  return description;
}
项目:error-prone    文件:AbstractReturnValueIgnored.java   
@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
  if (allOf(
          (t, s) -> t.getMode() == ReferenceMode.INVOKE,
          AbstractReturnValueIgnored::isVoidReturningMethodReferenceExpression,
          // Skip cases where the method we're referencing really does return void. We're only
          // looking for cases where the referenced method does not return void, but it's being
          // used on a void-returning functional interface.
          not((t, s) -> ASTHelpers.isVoidType(ASTHelpers.getSymbol(tree).getReturnType(), s)),
          not((t, s) -> isThrowingFunctionalInterface(s, ((JCMemberReference) t).type)),
          specializedMatcher())
      .matches(tree, state)) {
    return describeMatch(tree);
  }

  return Description.NO_MATCH;
}
项目:OLD-OpenJDK8    文件:JavacParser.java   
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));
}
项目:incubator-netbeans    文件:VeryPretty.java   
@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");
}
项目:incubator-netbeans    文件:TreeFactory.java   
public MemberReferenceTree MemberReference(ReferenceMode refMode, CharSequence name, ExpressionTree expression, List<? extends ExpressionTree> typeArguments) {
    ListBuffer<JCExpression> targs;

    if (typeArguments != null) {
        targs = new ListBuffer<JCExpression>();
        for (ExpressionTree t : typeArguments)
            targs.append((JCExpression)t);
    } else {
        targs = null;
    }

    return make.at(NOPOS).Reference(refMode, names.fromString(name.toString()), (JCExpression) expression, targs != null ? targs.toList() : null);
}
项目:incubator-netbeans    文件:LambdaTest.java   
public void testPrintMemberReference() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        Runnable r = null;\n" + 
        "    }\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        Runnable r = Test::taragui;\n" + 
        "    }\n" +
        "}\n";
    JavaSource src = getJavaSource(testFile);

    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(final WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitLiteral(LiteralTree node, Void p) {
                    workingCopy.rewrite(node, make.MemberReference(ReferenceMode.INVOKE, make.Identifier("Test"), "taragui", Collections.<ExpressionTree>emptyList()));
                    return super.visitLiteral(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
项目:incubator-netbeans    文件:LambdaTest.java   
public void testPrintMemberReference() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        Runnable r = null;\n" + 
        "    }\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        Runnable r = Test::taragui;\n" + 
        "    }\n" +
        "}\n";
    JavaSource src = getJavaSource(testFile);

    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(final WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            CompilationUnitTree cut = workingCopy.getCompilationUnit();
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitLiteral(LiteralTree node, Void p) {
                    workingCopy.rewrite(node, make.MemberReference(ReferenceMode.INVOKE, make.Identifier("Test"), "taragui", Collections.<ExpressionTree>emptyList()));
                    return super.visitLiteral(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
项目:OpenJSharp    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:OpenJSharp    文件:LambdaToMethod.java   
/**
 * Does this reference need to be converted to a lambda
 * (i.e. var args need to be expanded or "super" is used)
 */
final boolean needsConversionToLambda() {
    return interfaceParameterIsIntersectionType() ||
            isSuper ||
            needsVarArgsConversion() ||
            isArrayOp() ||
            isPrivateInOtherClass() ||
            !receiverAccessible() ||
            (tree.getMode() == ReferenceMode.NEW &&
              tree.kind != ReferenceKind.ARRAY_CTOR &&
              (tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
}
项目:openjdk-jdk10    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:openjdk-jdk10    文件:LambdaToMethod.java   
/**
 * Does this reference need to be converted to a lambda
 * (i.e. var args need to be expanded or "super" is used)
 */
final boolean needsConversionToLambda() {
    return interfaceParameterIsIntersectionType() ||
            isSuper ||
            needsVarArgsConversion() ||
            isArrayOp() ||
            isPrivateInOtherClass() ||
            isProtectedInSuperClassOfEnclosingClassInOtherPackage() ||
            !receiverAccessible() ||
            (tree.getMode() == ReferenceMode.NEW &&
              tree.kind != ReferenceKind.ARRAY_CTOR &&
              (tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
}
项目:openjdk9    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:openjdk9    文件:LambdaToMethod.java   
/**
 * Does this reference need to be converted to a lambda
 * (i.e. var args need to be expanded or "super" is used)
 */
final boolean needsConversionToLambda() {
    return interfaceParameterIsIntersectionType() ||
            isSuper ||
            needsVarArgsConversion() ||
            isArrayOp() ||
            isPrivateInOtherClass() ||
            !receiverAccessible() ||
            (tree.getMode() == ReferenceMode.NEW &&
              tree.kind != ReferenceKind.ARRAY_CTOR &&
              (tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
}
项目:lookaside_java-1.8.0-openjdk    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:LambdaToMethod.java   
/**
 * Does this reference need to be converted to a lambda
 * (i.e. var args need to be expanded or "super" is used)
 */
final boolean needsConversionToLambda() {
    return interfaceParameterIsIntersectionType() ||
            isSuper ||
            needsVarArgsConversion() ||
            isArrayOp() ||
            isPrivateInOtherClass() ||
            !receiverAccessible() ||
            (tree.getMode() == ReferenceMode.NEW &&
              tree.kind != ReferenceKind.ARRAY_CTOR &&
              (tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
}
项目:jsr308-langtools    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:jsr308-langtools    文件:LambdaToMethod.java   
/**
 * Does this reference need to be converted to a lambda
 * (i.e. var args need to be expanded or "super" is used)
 */
final boolean needsConversionToLambda() {
    return interfaceParameterIsIntersectionType() ||
            isSuper ||
            needsVarArgsConversion() ||
            isArrayOp() ||
            isPrivateInOtherClass() ||
            !receiverAccessible() ||
            (tree.getMode() == ReferenceMode.NEW &&
              tree.kind != ReferenceKind.ARRAY_CTOR &&
              (tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
}
项目:infobip-open-jdk-8    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:infobip-open-jdk-8    文件:LambdaToMethod.java   
/**
 * Does this reference need to be converted to a lambda
 * (i.e. var args need to be expanded or "super" is used)
 */
final boolean needsConversionToLambda() {
    return interfaceParameterIsIntersectionType() ||
            isSuper ||
            needsVarArgsConversion() ||
            isArrayOp() ||
            isPrivateInOtherClass() ||
            !receiverAccessible() ||
            (tree.getMode() == ReferenceMode.NEW &&
              tree.kind != ReferenceKind.ARRAY_CTOR &&
              (tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
}
项目:error-prone    文件:CanBeStaticAnalyzer.java   
@Override
public void visitReference(JCMemberReference tree) {
  super.visitReference(tree);
  if (tree.getMode() != ReferenceMode.NEW) {
    return;
  }
  if (memberOfEnclosing(owner, state, tree.expr.type.tsym)) {
    referencesOuter = true;
  }
}
项目:OLD-OpenJDK8    文件:Pretty.java   
public void visitReference(JCMemberReference tree) {
    try {
        printExpr(tree.expr);
        print("::");
        if (tree.typeargs != null) {
            print("<");
            printExprs(tree.typeargs);
            print(">");
        }
        print(tree.getMode() == ReferenceMode.INVOKE ? tree.name : "new");
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
项目:OpenJSharp    文件:JCTree.java   
private ReferenceKind(ReferenceMode mode, boolean unbound) {
    this.mode = mode;
    this.unbound = unbound;
}
项目:OpenJSharp    文件:JCTree.java   
protected JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
    this.mode = mode;
    this.name = name;
    this.expr = expr;
    this.typeargs = typeargs;
}
项目:OpenJSharp    文件:JCTree.java   
@Override
public ReferenceMode getMode() { return mode; }
项目:OpenJSharp    文件:Attr.java   
ResultInfo memberReferenceQualifierResult(JCMemberReference tree) {
    //if this is a constructor reference, the expected kind must be a type
    return new ResultInfo(tree.getMode() == ReferenceMode.INVOKE ? VAL | TYP : TYP, Type.noType);
}
项目:openjdk-jdk10    文件:Attr.java   
ResultInfo memberReferenceQualifierResult(JCMemberReference tree) {
    //if this is a constructor reference, the expected kind must be a type
    return new ResultInfo(tree.getMode() == ReferenceMode.INVOKE ?
                          KindSelector.VAL_TYP : KindSelector.TYP,
                          Type.noType);
}
项目:openjdk9    文件:Attr.java   
ResultInfo memberReferenceQualifierResult(JCMemberReference tree) {
    //if this is a constructor reference, the expected kind must be a type
    return new ResultInfo(tree.getMode() == ReferenceMode.INVOKE ?
                          KindSelector.VAL_TYP : KindSelector.TYP,
                          Type.noType);
}
项目:lookaside_java-1.8.0-openjdk    文件:JCTree.java   
private ReferenceKind(ReferenceMode mode, boolean unbound) {
    this.mode = mode;
    this.unbound = unbound;
}