当前位置: 首页>>代码示例>>Java>>正文


Java MemberReferenceTree类代码示例

本文整理汇总了Java中com.sun.source.tree.MemberReferenceTree的典型用法代码示例。如果您正苦于以下问题:Java MemberReferenceTree类的具体用法?Java MemberReferenceTree怎么用?Java MemberReferenceTree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemberReferenceTree类属于com.sun.source.tree包,在下文中一共展示了MemberReferenceTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visitMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public Boolean visitMemberReference(MemberReferenceTree node, TreePath p) {
    if (p == null)
        return super.visitMemberReference(node, p);

    MemberReferenceTree t = (MemberReferenceTree) p.getLeaf();
    
    if (!node.getMode().equals(t.getMode()))
        return false;

    if (!scan(node.getQualifierExpression(), t.getQualifierExpression(), p))
        return false;

    String ident = t.getName().toString();

    if (ident.startsWith("$")) { //XXX: there should be a utility method for this check
        if (bindState.variables2Names.containsKey(ident)) {
            return node.getName().contentEquals(bindState.variables2Names.get(ident));
        } else {
            bindState.variables2Names.put(ident, node.getName().toString());
        }
        return true;
    }

    return node.getName().contentEquals(t.getName());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CopyFinder.java

示例2: visitMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public Void visitMemberReference(MemberReferenceTree node, Void p) {
    Element el = info.getTrees().getElement(getCurrentPath());
    if (toFind.equals(el)) {
        try {
            int[] span = treeUtils.findNameSpan(node);
            if(span != null) {
                MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                usages.add(region);
            }
        } catch (BadLocationException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
    return super.visitMemberReference(node, p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:FindLocalUsagesQuery.java

示例3: getSymbol

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
/**
 * Gets the symbol for a tree. Returns null if this tree does not have a symbol because it is of
 * the wrong type, if {@code tree} is null, or if the symbol cannot be found due to a compilation
 * error.
 */
// TODO(eaftan): refactor other code that accesses symbols to use this method
public static Symbol getSymbol(Tree tree) {
  if (tree instanceof JCFieldAccess) {
    return ((JCFieldAccess) tree).sym;
  }
  if (tree instanceof JCIdent) {
    return ((JCIdent) tree).sym;
  }
  if (tree instanceof JCMethodInvocation) {
    return ASTHelpers.getSymbol((MethodInvocationTree) tree);
  }
  if (tree instanceof JCNewClass) {
    return ASTHelpers.getSymbol((NewClassTree) tree);
  }
  if (tree instanceof MemberReferenceTree) {
    return ((JCMemberReference) tree).sym;
  }
  if (tree instanceof JCAnnotatedType) {
    return getSymbol(((JCAnnotatedType) tree).underlyingType);
  }

  return getDeclaredSymbol(tree);
}
 
开发者ID:google,项目名称:error-prone,代码行数:29,代码来源:ASTHelpers.java

示例4: getReceiver

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
/**
 * Returns the receiver of an expression.
 *
 * <p>Examples:
 *
 * <pre>{@code
 * a.foo() ==> a
 * a.b.foo() ==> a.b
 * a.bar().foo() ==> a.bar()
 * a.b.c ==> a.b
 * a.b().c ==> a.b()
 * this.foo() ==> this
 * foo() ==> null
 * TheClass.aStaticMethod() ==> TheClass
 * aStaticMethod() ==> null
 * aStaticallyImportedMethod() ==> null
 * }</pre>
 */
@Nullable
public static ExpressionTree getReceiver(ExpressionTree expressionTree) {
  if (expressionTree instanceof MethodInvocationTree) {
    ExpressionTree methodSelect = ((MethodInvocationTree) expressionTree).getMethodSelect();
    if (methodSelect instanceof IdentifierTree) {
      return null;
    }
    return getReceiver(methodSelect);
  } else if (expressionTree instanceof MemberSelectTree) {
    return ((MemberSelectTree) expressionTree).getExpression();
  } else if (expressionTree instanceof MemberReferenceTree) {
    return ((MemberReferenceTree) expressionTree).getQualifierExpression();
  } else {
    throw new IllegalStateException(
        String.format(
            "Expected expression '%s' to be a method invocation or field access, but was %s",
            expressionTree, expressionTree.getKind()));
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:38,代码来源:ASTHelpers.java

示例5: visitMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public Choice<State<JCMemberReference>> visitMemberReference(
    final MemberReferenceTree node, State<?> state) {
  return chooseSubtrees(
      state,
      s -> unifyExpression(node.getQualifierExpression(), s),
      expr ->
          maker()
              .Reference(
                  node.getMode(),
                  (Name) node.getName(),
                  expr,
                  List.convert(
                      JCExpression.class,
                      (List<? extends ExpressionTree>) node.getTypeArguments())));
}
 
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:PlaceholderUnificationVisitor.java

示例6: matchMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
  if (!tree.getName().contentEquals("equals")) {
    return NO_MATCH;
  }
  Type predicateType = predicateType(ASTHelpers.getType(tree), state);
  Type receiverType = getReceiverType(tree);
  if (EqualsIncompatibleType.compatibilityOfTypes(receiverType, predicateType, state)
      .compatible()) {
    return NO_MATCH;
  }
  return buildDescription(tree)
      .setMessage(
          String.format(
              "Using %s::equals as Predicate<%s>; the predicate will always return false",
              prettyType(receiverType), prettyType(predicateType)))
      .build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:19,代码来源:PredicateIncompatibleType.java

示例7: matchMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public Description matchMemberReference(MemberReferenceTree tree, VisitorState state) {
  if (COMPILING_SUPPORT_LIBRARY_MATCHER.matches(tree, state)) {
    return Description.NO_MATCH;
  }

  Type refType = ASTHelpers.getUpperBound(ASTHelpers.getResultType(tree), state.getTypes());
  if (checkEnclosingTypes(refType, state)) {
    return describe(tree, refType.asElement().enclClass(), state);
  }

  Symbol symbol = ASTHelpers.getSymbol(tree);
  if (!(symbol instanceof MethodSymbol)) {
    return Description.NO_MATCH;
  }
  MethodSymbol method = (MethodSymbol) symbol;

  // Directly calling a method that's restricted, or is declared on a restricted class
  return matchInvokedMethod(tree, method, state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:RestrictToEnforcer.java

示例8: matchMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:FutureReturnValueIgnored.java

示例9: matchMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:18,代码来源:AbstractReturnValueIgnored.java

示例10: visitMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public CodeModel visitMemberReference(MemberReferenceTree node, VisitContext p) {
  if (node.getMode() == MemberReferenceTree.ReferenceMode.INVOKE) {
    JCTree.JCMemberReference refTree = (JCTree.JCMemberReference) node;
    ExecutableElement method = (ExecutableElement) refTree.sym;
    MethodSignature signature = createMethodSignature(method, false);
    ExpressionModel expression = scan(node.getQualifierExpression(), p);
    if (expression instanceof ThisModel) {
      p.getReferencedMethods().add(node.getName().toString());
    }
    ExpressionModel methodReferenceExpression = expression.onMethodReference(signature);
    return methodReferenceExpression;
  } else {
    throw new UnsupportedOperationException("New reference not implemented yet");
  }
}
 
开发者ID:vert-x3,项目名称:vertx-codetrans,代码行数:17,代码来源:ModelBuilder.java

示例11: visitMemberReference

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
@Override
public Tree visitMemberReference(MemberReferenceTree tree, Void p) {
    MemberReferenceTree n = make.MemberReference(tree.getMode(), tree.getName(), tree.getQualifierExpression(), (List<ExpressionTree>)tree.getTypeArguments());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:TreeDuplicator.java

示例12: testMethodReferenceDiff

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
public void testMethodReferenceDiff() 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 = hierbas.del.litoral.Test :: taragui;\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);
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitMemberReference(MemberReferenceTree node, Void p) {
                    workingCopy.rewrite(node, make.MemberReference(node.getMode(), make.Identifier("Test"), node.getName(), node.getTypeArguments()));
                    return super.visitMemberReference(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:LambdaTest.java

示例13: testMethodReferenceNameDiff

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
public void testMethodReferenceNameDiff() 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 = Test :: taragui;\n" + 
        "    }\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        Runnable r = Test :: taragui2;\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);
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitMemberReference(MemberReferenceTree node, Void p) {
                    workingCopy.rewrite(node, make.setLabel(node, "taragui2"));
                    return super.visitMemberReference(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:LambdaTest.java

示例14: testMethodReferenceFirstTypeParam

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
public void testMethodReferenceFirstTypeParam() 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 = Test::taragui;\n" + 
        "    }\n" +
        "}\n"
        );
    String golden =
        "package hierbas.del.litoral;\n\n" +
        "public class Test {\n" +
        "    public static void taragui() {\n" +
        "        Runnable r = Test::<String>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);
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitMemberReference(MemberReferenceTree node, Void p) {
                    workingCopy.rewrite(node, make.MemberReference(node.getMode(), node.getQualifierExpression(), node.getName(), Collections.singletonList(make.Identifier("String"))));
                    return super.visitMemberReference(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:LambdaTest.java

示例15: testMethodReferenceLastTypeParam

import com.sun.source.tree.MemberReferenceTree; //导入依赖的package包/类
public void testMethodReferenceLastTypeParam() 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 = Test::<String>taragui;\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);
            final TreeMaker make = workingCopy.getTreeMaker();
            new ErrorAwareTreeScanner<Void, Void>() {
                @Override public Void visitMemberReference(MemberReferenceTree node, Void p) {
                    workingCopy.rewrite(node, make.MemberReference(node.getMode(), node.getQualifierExpression(), node.getName(), null));
                    return super.visitMemberReference(node, p);
                }
            }.scan(workingCopy.getCompilationUnit(), null);
        }

    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:LambdaTest.java


注:本文中的com.sun.source.tree.MemberReferenceTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。