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


Java JCTree.JCStatement方法代码示例

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


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

示例1: isFirstStatementThisOrSuperCall

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的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: buildReturnCheck

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@NotNull
private static Optional<List<JCTree.JCStatement>> buildReturnCheck(@NotNull ReturnToInstrumentInfo info) {
    CompilationUnitProcessingContext context = info.getContext();
    ExpressionTree returnExpression = info.getReturnExpression().getExpression();
    if (!(returnExpression instanceof JCTree.JCExpression)) {
        context.getLogger().reportDetails(String.format(
                "find a 'return' expression of type %s but got %s",
                JCTree.JCExpression.class.getName(), returnExpression.getClass().getName()
        ));
        return Optional.empty();
    }
    JCTree.JCExpression returnJcExpression = (JCTree.JCExpression) returnExpression;

    TreeMaker factory = context.getAstFactory();
    Names symbolsTable = context.getSymbolsTable();
    ExceptionTextGenerator<ReturnToInstrumentInfo> generator =
            context.getExceptionTextGeneratorManager().getGenerator(METHOD_RETURN, context.getPluginSettings());
    String errorMessage = generator.generate(info);

    List<JCTree.JCStatement> result = List.of(
            factory.VarDef(
                    factory.Modifiers(0),
                    symbolsTable.fromString(info.getTmpVariableName()),
                    info.getReturnType(),
                    returnJcExpression
            )
    );
    String exceptionToThrow = info.getContext().getPluginSettings().getExceptionToThrow(METHOD_RETURN);
    result = result.append(InstrumentationUtil.buildVarCheck(factory,
                                                             symbolsTable,
                                                             info.getTmpVariableName(),
                                                             errorMessage,
                                                             exceptionToThrow));
    result = result.append(
            factory.Return(
                    factory.Ident(symbolsTable.fromString(info.getTmpVariableName()))));
    return Optional.of(result);
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:39,代码来源:MethodReturnInstrumentator.java

示例3: visitClassDef

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void visitClassDef( JCTree.JCClassDecl tree )
{
  super.visitClassDef( tree );
  if( tree.sym != null && !tree.sym.isInner() )
  {
    if( !hasNoBootstrap( tree.getModifiers().getAnnotations() ) )
    {
      JCTree.JCStatement newNode = buildBootstrapStaticBlock();
      ArrayList<JCTree> newDefs = new ArrayList<>( tree.defs );
      newDefs.add( 0, newNode );
      tree.defs = List.from( newDefs );
    }
  }
  result = tree;
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:17,代码来源:BootstrapInserter.java

示例4: mayBeInstrument

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
protected boolean mayBeInstrument(@NotNull ParameterToInstrumentInfo info) {
    String parameterName = info.getMethodParameter().getName().toString();
    CompilationUnitProcessingContext context = info.getContext();
    ExceptionTextGenerator<ParameterToInstrumentInfo> generator =
            context.getExceptionTextGeneratorManager().getGenerator(METHOD_PARAMETER, context.getPluginSettings());
    String errorMessage = generator.generate(info);
    TreeMaker factory = context.getAstFactory();
    Names symbolsTable = context.getSymbolsTable();
    JCTree.JCBlock body = info.getBody();
    String exceptionToThrow = info.getContext().getPluginSettings().getExceptionToThrow(METHOD_PARAMETER);
    JCTree.JCIf varCheck = buildVarCheck(factory, symbolsTable, parameterName, errorMessage, exceptionToThrow);
    if (info.isConstructor() && isFirstStatementThisOrSuperCall(body)) {
        List<JCTree.JCStatement> newStatements = List.of(varCheck);
        List<JCTree.JCStatement> statements = body.getStatements();
        for (int i = 1; i < statements.size(); i++) {
            newStatements = newStatements.append(statements.get(i));
        }
        newStatements = newStatements.prepend(statements.get(0));
        body.stats = newStatements;
    } else {
        body.stats = body.stats.prepend(varCheck);
    }

    if (context.getPluginSettings().isVerboseMode()) {
        String methodName = info.getQualifiedMethodName();
        String methodNotice = methodName == null ? "" : " in the method " + methodName + "()";
        context.getLogger().info(String.format(
                "added a null-check for argument '%s'%s",
                parameterName, methodNotice
        ));
    }
    return true;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:35,代码来源:ParameterInstrumentator.java

示例5: mayBeInstrument

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
protected boolean mayBeInstrument(@NotNull ReturnToInstrumentInfo info) {
    ReturnInstrumentationAstParent parent
            = info.getParent().accept(new MethodInstrumentationParentFinder(info), null);
    if (parent == null) {
        return false;
    }
    Optional<List<JCTree.JCStatement>> returnCheckOptional = buildReturnCheck(info);
    if (!returnCheckOptional.isPresent()) {
        return false;
    }
    List<JCTree.JCStatement> statements = parent.getStatements();
    for (int i = 0; i < statements.size(); i++) {
        JCTree.JCStatement statement = statements.get(i);
        if (statement == info.getReturnExpression()) {
            List<JCTree.JCStatement> newStatements = returnCheckOptional.get();
            for (int j = i + 1; j < statements.size(); j++) {
                newStatements = newStatements.append(statements.get(j));
            }
            for (int j = i - 1; j >= 0; j--) {
                newStatements = newStatements.prepend(statements.get(j));
            }
            parent.setStatements(newStatements);
            mayBeLogInstrumentation(info);
            return true;
        }
    }
    // When control flow reaches this place, that means that the AST parent doesn't contain any statments, so,
    // we just populate it with new instructions.
    parent.setStatements(returnCheckOptional.get());
    mayBeLogInstrumentation(info);
    return true;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:34,代码来源:MethodReturnInstrumentator.java

示例6: buildBootstrapStaticBlock

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private JCTree.JCStatement buildBootstrapStaticBlock()
{
  TreeMaker make = _javacJacker.getTreeMaker();
  JavacElements javacElems = _javacJacker.getJavacElements();

  JCTree.JCMethodInvocation bootstrapInitCall = make.Apply( List.nil(), memberAccess( make, javacElems, Bootstrap.class.getName() + ".init" ), List.nil() );
  return make.Block( Modifier.STATIC, List.of( make.Exec( bootstrapInitCall ) ) );
}
 
开发者ID:manifold-systems,项目名称:manifold,代码行数:9,代码来源:BootstrapInserter.java

示例7: getStatements

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
@NotNull
public List<JCTree.JCStatement> getStatements() {
    return block.stats == null ? List.nil() : block.stats;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:6,代码来源:BlockReturnInstrumentationAstParent.java

示例8: setStatements

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void setStatements(@NotNull List<JCTree.JCStatement> statements) {
    block.stats = statements;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:5,代码来源:BlockReturnInstrumentationAstParent.java

示例9: getStatements

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
@NotNull
public List<JCTree.JCStatement> getStatements() {
    return jcCase.stats == null ? List.nil() : jcCase.stats;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:6,代码来源:CaseReturnInstrumentationAstParent.java

示例10: setStatements

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void setStatements(@NotNull List<JCTree.JCStatement> statements) {
    jcCase.stats = statements;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:5,代码来源:CaseReturnInstrumentationAstParent.java

示例11: setStatements

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * Replaces all {@link #getStatements() current statements} by the given statements.
 *
 * @param statements statements to use for the underlying {@code AST} element
 */
void setStatements(@NotNull List<JCTree.JCStatement> statements);
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:7,代码来源:ReturnInstrumentationAstParent.java

示例12: getStatements

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * @return  statements in the current {@code AST} parent
 */
@NotNull
List<JCTree.JCStatement> getStatements();
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:6,代码来源:ReturnInstrumentationAstParent.java


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