本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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 ) ) );
}
示例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;
}
示例8: setStatements
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void setStatements(@NotNull List<JCTree.JCStatement> statements) {
block.stats = statements;
}
示例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;
}
示例10: setStatements
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
@Override
public void setStatements(@NotNull List<JCTree.JCStatement> statements) {
jcCase.stats = statements;
}
示例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);
示例12: getStatements
import com.sun.tools.javac.tree.JCTree; //导入方法依赖的package包/类
/**
* @return statements in the current {@code AST} parent
*/
@NotNull
List<JCTree.JCStatement> getStatements();