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


Java JCTree.JCIf方法代码示例

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


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

示例1: visitIf

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public void visitIf(JCTree.JCIf tree) {
    JCDiagnostic.DiagnosticPosition nil = null;
    // generate dummy messages to exercise the log API
    log.error("not.stmt");
    log.error(tree.pos, "not.stmt");
    log.error(tree.pos(), "not.stmt");
    log.error(nil, "not.stmt");

    log.warning("div.zero");
    log.warning(tree.pos, "div.zero");
    log.warning(tree.pos(), "div.zero");
    log.warning(nil, "div.zero");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TestLog.java

示例2: 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

示例3: visitIf

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public ReturnInstrumentationAstParent visitIf(IfTree node, Void aVoid) {
    if (!(node instanceof JCTree.JCIf)) {
        report(JCTree.JCIf.class, node);
        return null;
    }
    JCTree.JCIf jcIf = (JCTree.JCIf) node;
    JCTree.JCBlock block = null;
    if (jcIf.thenpart == info.getReturnExpression()) {
        jcIf.thenpart = (block = buildBlock());
    } else if (jcIf.elsepart == info.getReturnExpression()) {
        jcIf.elsepart = (block = buildBlock());
    }
    return block == null ? null : new BlockReturnInstrumentationAstParent(block);
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:16,代码来源:MethodInstrumentationParentFinder.java

示例4: buildVarCheck

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * Builds an {@code AST 'if'} element which looks as below:
 * <pre>
 *     if ([given-variable-name] == null) {
 *         throw new [given-exception]([given-error-message]);
 *     }
 * </pre>
 *
 * @param factory           an {@code AST} factory to use
 * @param symbolsTable      a symbols table to use
 * @param variableName      a variable name to use
 * @param errorMessage      an error message to use
 * @param exceptionToThrow  an exception to throw in case of failed check
 * @return                  an {@code AST 'if'} for the parameters above
 */
@NotNull
public static JCTree.JCIf buildVarCheck(@NotNull TreeMaker factory,
                                        @NotNull Names symbolsTable,
                                        @NotNull String variableName,
                                        @NotNull String errorMessage,
                                        @NotNull String exceptionToThrow)
{
    return factory.If(
            factory.Parens(
                    factory.Binary(
                            JCTree.Tag.EQ,
                            factory.Ident(
                                    symbolsTable.fromString(variableName)
                            ),
                            factory.Literal(TypeTag.BOT, null))
            ),
            factory.Block(0, List.of(
                    factory.Throw(
                            factory.NewClass(
                                    null,
                                    nil(),
                                    buildExceptionClassExpression(exceptionToThrow, factory, symbolsTable),
                                    List.of(factory.Literal(TypeTag.CLASS, errorMessage)),
                                    null
                            )
                    )
            )),
            null
    );
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:46,代码来源:InstrumentationUtil.java


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