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


Java ExpressionStatementTree.getExpression方法代码示例

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


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

示例1: isFirstStatementThisOrSuperCall

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
private static boolean isFirstStatementThisOrSuperCall(@NotNull JCTree.JCBlock body) {
    List<JCTree.JCStatement> statements = body.getStatements();
    if (statements.isEmpty()) {
        return false;
    }
    JCTree.JCStatement expressionCandidate = statements.get(0);
    if (expressionCandidate instanceof ExpressionStatementTree) {
        ExpressionStatementTree expression = (ExpressionStatementTree) expressionCandidate;
        ExpressionTree methodInvocationCandidate = expression.getExpression();
        if (methodInvocationCandidate instanceof MethodInvocationTree) {
            MethodInvocationTree methodInvocation = (MethodInvocationTree) methodInvocationCandidate;
            ExpressionTree methodSelect = methodInvocation.getMethodSelect();
            if (methodSelect != null) {
                String select = methodSelect.toString();
                return "this".equals(select) || "super".equals(select);
            }
        }
    }
    return false;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:21,代码来源:ParameterInstrumentator.java

示例2: visitExpressionStatement

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
@Override
public Wrapper visitExpressionStatement(ExpressionStatementTree arg0,
        Void arg1) {
    ExpressionTree t = arg0.getExpression();
    Wrapper w = null;
    MethodInvocationTree mi = getMethodInvocation(arg0);
    if (mi != null) {
        if (isYieldBreak(mi)) {
            w = new YieldBreakWrapper(arg0, visit(t,
                    CallMethodWrapper.class));
        } else if (isYieldReturn(mi)) {
            w = new YieldReturnWrapper(arg0, visit(t,
                    CallMethodWrapper.class));
        }
    }
    if (w == null) {
        // This is something else, don't care what!
        w = new ExpressionStatementWrapper(arg0, visit(
                arg0.getExpression(), ExpressionWrapper.class));
    } else {
        // Found a yield, set the flag!
        foundYieldStatement = true;
    }
    return w;
}
 
开发者ID:provegard,项目名称:yield4j,代码行数:26,代码来源:JavaTreeBuilderNew.java

示例3: isSynthetic

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
private static boolean isSynthetic(CompilationUnitTree cut, Tree leaf) throws NullPointerException {
    JCTree tree = (JCTree) leaf;

    if (tree.pos == (-1))
        return true;

    if (leaf.getKind() == Kind.METHOD) {
        //check for synthetic constructor:
        return (((JCMethodDecl)leaf).mods.flags & Flags.GENERATEDCONSTR) != 0L;
    }

    //check for synthetic superconstructor call:
    if (cut != null && leaf.getKind() == Kind.EXPRESSION_STATEMENT) {
        ExpressionStatementTree est = (ExpressionStatementTree) leaf;

        if (est.getExpression().getKind() == Kind.METHOD_INVOCATION) {
            MethodInvocationTree mit = (MethodInvocationTree) est.getExpression();

            if (mit.getMethodSelect().getKind() == Kind.IDENTIFIER) {
                IdentifierTree it = (IdentifierTree) mit.getMethodSelect();

                if ("super".equals(it.getName().toString())) {
                    return ((JCCompilationUnit) cut).endPositions.getEndPos(tree) == (-1);
                }
            }
        }
    }

    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:Utilities.java

示例4: visitExpressionStatement

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
@Override
public UStatement visitExpressionStatement(ExpressionStatementTree tree, Void v) {
  PlaceholderMethod placeholderMethod = placeholder(tree.getExpression());
  if (placeholderMethod != null && placeholderMethod.returnType().equals(UPrimitiveType.VOID)) {
    MethodInvocationTree invocation = (MethodInvocationTree) tree.getExpression();
    return UPlaceholderStatement.create(
        placeholderMethod,
        templateExpressions(invocation.getArguments()),
        ControlFlowVisitor.Result.NEVER_EXITS);
  }
  return UExpressionStatement.create(template(tree.getExpression()));
}
 
开发者ID:google,项目名称:error-prone,代码行数:13,代码来源:UTemplater.java

示例5: visitExpressionStatement

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
@Override
public Void visitExpressionStatement(ExpressionStatementTree node, VisitorState state) {
  ExpressionTree expression = node.getExpression();
  Match match = matches.get(expression.toString());
  if (match != null) {
    assertMatch(expression, match.expected);
    match.found = true;
  }
  return super.visitExpressionStatement(node, state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:11,代码来源:PreconditionsCheckNotNullPrimitiveTest.java

示例6: expressionStatementMatches

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
private Scanner expressionStatementMatches(
    final String expectedExpression, final Matcher<ExpressionTree> matcher) {
  return new TestScanner() {
    @Override
    public Void visitExpressionStatement(ExpressionStatementTree node, VisitorState state) {
      ExpressionTree expression = node.getExpression();
      if (expression.toString().equals(expectedExpression)) {
        assertMatch(node.getExpression(), state, matcher);
        setAssertionsComplete();
      }
      return super.visitExpressionStatement(node, state);
    }
  };
}
 
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:ASTHelpersTest.java

示例7: expressionStatementMatches

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
private Scanner expressionStatementMatches(final String expectedExpression,
    final Matcher<ExpressionTree> matcher) {
  return new TestScanner() {
    @Override
    public Void visitExpressionStatement(ExpressionStatementTree node, VisitorState state) {
      ExpressionTree expression = node.getExpression();
      if (expression.toString().equals(expectedExpression)) {
        assertMatch(node.getExpression(), state, matcher);
      }
      return super.visitExpressionStatement(node, state);
    }
  };
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:14,代码来源:ASTHelpersTest.java

示例8: getMethodInvocation

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
public static MethodInvocationTree getMethodInvocation(StatementTree s) {
    if (s instanceof ExpressionStatementTree == false)
        return null;
    ExpressionStatementTree es = (ExpressionStatementTree) s;
    ExpressionTree ex = es.getExpression();
    if (ex instanceof MethodInvocationTree == false)
        return null;
    return (MethodInvocationTree) ex;
}
 
开发者ID:provegard,项目名称:yield4j,代码行数:10,代码来源:Statements.java

示例9: testNullLiteral43625

import com.sun.source.tree.ExpressionStatementTree; //导入方法依赖的package包/类
/**
 * Rewrite null literal to itself.
 */ 
public void testNullLiteral43625() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile, 
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    public void taragui(Object o) {\n" +
        "        taragui(null);\n" +
        "    }\n" +
        "}\n"
        );
    String golden = 
        "package hierbas.del.litoral;\n" +
        "\n" +
        "public class Test {\n" +
        "    public void taragui(Object o) {\n" +
        "        taragui(null);\n" +
        "    }\n" +
        "}\n";
    JavaSource testSource = JavaSource.forFileObject(FileUtil.toFileObject(testFile));
    Task<WorkingCopy> task = new Task<WorkingCopy>() {

        public void run(WorkingCopy workingCopy) throws java.io.IOException {
            workingCopy.toPhase(Phase.RESOLVED);
            TreeMaker make = workingCopy.getTreeMaker();
            
            ClassTree clazz = (ClassTree) workingCopy.getCompilationUnit().getTypeDecls().get(0);
            MethodTree method = (MethodTree) clazz.getMembers().get(1);
            ExpressionStatementTree statement = (ExpressionStatementTree) method.getBody().getStatements().get(0);
            MethodInvocationTree mit = (MethodInvocationTree) statement.getExpression();
            LiteralTree lt = (LiteralTree) mit.getArguments().get(0);
            workingCopy.rewrite(lt, make.Literal(null));
        }
        
    };
    testSource.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    System.err.println(res);
    assertEquals(golden, res);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:44,代码来源:LiteralTest.java


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