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


Java JCTree.JCBlock方法代码示例

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


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

示例1: ParameterToInstrumentInfo

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public ParameterToInstrumentInfo(@NotNull CompilationUnitProcessingContext compilationUnitProcessingContext,
                                 @Nullable String notNullAnnotation,
                                 @Nullable String notNullByDefaultAnnotationDescription,
                                 @NotNull VariableTree methodParameter,
                                 @NotNull JCTree.JCBlock body,
                                 @Nullable String qualifiedMethodName,
                                 int methodParameterIndex,
                                 int methodParametersNumber,
                                 boolean constructor)
{
    if (notNullAnnotation == null && notNullByDefaultAnnotationDescription == null) {
        throw new IllegalArgumentException(String.format(
                "Detected an invalid attempt to instrument a method parameter - either NotNull annotation or "
                + "NotNullByDefault annotations are undefined. Method: %s(), parameter: %s",
                qualifiedMethodName, methodParameter.getName()));
    }
    this.compilationUnitProcessingContext = compilationUnitProcessingContext;
    this.notNullAnnotation = notNullAnnotation;
    this.notNullByDefaultAnnotationDescription = notNullByDefaultAnnotationDescription;
    this.methodParameter = methodParameter;
    this.body = body;
    this.qualifiedMethodName = qualifiedMethodName;
    this.methodParameterIndex = methodParameterIndex;
    this.methodParametersNumber = methodParametersNumber;
    this.constructor = constructor;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:27,代码来源:ParameterToInstrumentInfo.java

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

示例3: getMethodBody

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Nullable
private JCTree.JCBlock getMethodBody(@NotNull MethodTree method) {
    if (hasFlag(method.getModifiers(), Modifier.ABSTRACT)) {
        return null;
    }
    BlockTree bodyBlock = method.getBody();
    if (bodyBlock == null) {
        return null;
    }
    if (bodyBlock instanceof JCTree.JCBlock) {
        return (JCTree.JCBlock) bodyBlock;
    }
    context.getLogger().reportDetails(String.format(
            "get a %s instance in the method AST but got %s",
            JCTree.JCBlock.class.getName(), bodyBlock.getClass().getName()
    ));
    return null;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:19,代码来源:InstrumentationApplianceFinder.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: visitBlock

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public ReturnInstrumentationAstParent visitBlock(BlockTree node, Void aVoid) {
    if (node instanceof JCTree.JCBlock) {
        return new BlockReturnInstrumentationAstParent((JCTree.JCBlock) node);
    } else {
        report(JCTree.JCBlock.class, node);
        return null;
    }
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:10,代码来源:MethodInstrumentationParentFinder.java

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

示例7: visitForLoop

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

示例8: visitEnhancedForLoop

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

示例9: visitWhileLoop

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

示例10: visitDoWhileLoop

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

示例11: getBody

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
 * @return body of the method which target parameter is marked by the {@code NotNull} annotation
 */
@NotNull
public JCTree.JCBlock getBody() {
    return body;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:8,代码来源:ParameterToInstrumentInfo.java

示例12: BlockReturnInstrumentationAstParent

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
public BlockReturnInstrumentationAstParent(@NotNull JCTree.JCBlock block) {
    this.block = block;
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:4,代码来源:BlockReturnInstrumentationAstParent.java

示例13: buildBlock

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@NotNull
private JCTree.JCBlock buildBlock() {
    return info.getContext().getAstFactory().Block(0, List.nil());
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:5,代码来源:MethodInstrumentationParentFinder.java

示例14: instrumentMethodParameters

import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
private void instrumentMethodParameters(@NotNull MethodTree method, @NotNull JCTree.JCBlock bodyBlock) {
    SortedSet<ParameterToInstrumentInfo> variablesToCheck = new TreeSet<>(
            // There is a possible case that more than one method parameter is marked by a NotNull annotation.
            // We want to add null-checks in reverse order then, i.e. for the last parameter marked
            // by a NotNull, then for the previous before the last etc
            (o1, o2) -> o2.getMethodParameterIndex() - o1.getMethodParameterIndex()
    );
    int parameterIndex = -1;
    int parametersNumber = method.getParameters().size();
    for (VariableTree variable : method.getParameters()) {
        parameterIndex++;
        if (variable == null) {
            continue;
        }
        Tree type = variable.getType();
        if (type != null && PRIMITIVE_TYPES.contains(type.toString())) {
            continue;
        }
        Annotations annotations = findAnnotation(variable.getModifiers());
        if (annotations.notNull.isPresent()
            || (!parametersNotNullByDefault.isEmpty()) && !annotations.nullable.isPresent())
        {

            String notNullByDefaultAnnotationDescription =
                    parametersNotNullByDefault.isEmpty() ? null : parametersNotNullByDefault.peek();
            variablesToCheck.add(new ParameterToInstrumentInfo(context,
                                                               annotations.notNull.orElse(null),
                                                               notNullByDefaultAnnotationDescription,
                                                               variable,
                                                               bodyBlock,
                                                               getQualifiedMethodName(),
                                                               parameterIndex,
                                                               parametersNumber,
                                                               method.getReturnType() == null));
        }
    }

    for (ParameterToInstrumentInfo info : variablesToCheck) {
        mayBeSetPosition(info.getMethodParameter(), context.getAstFactory());
        parameterInstrumenter.instrument(info);
    }
}
 
开发者ID:denis-zhdanov,项目名称:traute,代码行数:43,代码来源:InstrumentationApplianceFinder.java


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