本文整理汇总了Java中lombok.ast.Node.accept方法的典型用法代码示例。如果您正苦于以下问题:Java Node.accept方法的具体用法?Java Node.accept怎么用?Java Node.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lombok.ast.Node
的用法示例。
在下文中一共展示了Node.accept方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isReachableFrom
import lombok.ast.Node; //导入方法依赖的package包/类
private static boolean isReachableFrom(
@NonNull Node method,
@NonNull MethodInvocation from,
@NonNull MethodInvocation to) {
ReachableVisitor visitor = new ReachableVisitor(from, to);
method.accept(visitor);
return visitor.isReachable();
}
示例2: hasImport
import lombok.ast.Node; //导入方法依赖的package包/类
public static boolean hasImport(JavaContext context, MethodDefinition aMethodCall) {
ImportFinder finder = new ImportFinder(aMethodCall);
Node surroundingClass = context.getCompilationUnit();
surroundingClass.accept(finder);
return finder.isImportFound();
}
示例3: isCommittedInChainedCalls
import lombok.ast.Node; //导入方法依赖的package包/类
/**
* @return true if exists a commit or a getIntent
*/
private static boolean isCommittedInChainedCalls(@NonNull JavaContext context, @NonNull MethodInvocation node) {
JavaParser.ResolvedVariable boundVariable = getVariable(context, node);
if (boundVariable == null) {
Node parent = node.getParent();
while (parent instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) parent;
if (isTransactionCommitMethodCall(methodInvocation)) {
return true;
}
parent = parent.getParent();
}
}
if (boundVariable != null) {
Node method = JavaContext.findSurroundingMethod(node);
if (method == null) {
return true;
}
FinishVisitor commitVisitor = new FinishVisitor(context, boundVariable) {
@Override
protected boolean isCleanupCall(@NonNull MethodInvocation call) {
if (isTransactionCommitMethodCall(call)) {
Expression operand = call.astOperand();
if (operand != null) {
JavaParser.ResolvedNode resolved = mContext.resolve(operand);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
return true;
} else if (resolved instanceof JavaParser.ResolvedMethod
&& operand instanceof MethodInvocation
&& isCommittedInChainedCalls(mContext, (MethodInvocation) operand)) {
// Check that the target of the committed chains is the
// right variable!
while (operand instanceof MethodInvocation) {
operand = ((MethodInvocation) operand).astOperand();
}
if (operand instanceof VariableReference) {
resolved = mContext.resolve(operand);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
return true;
}
}
}
}
}
return false;
}
};
method.accept(commitVisitor);
if (commitVisitor.isCleanedUp()) {
return true;
}
}
return false;
}
示例4: checkRecycled
import lombok.ast.Node; //导入方法依赖的package包/类
private static void checkRecycled(@NonNull final JavaContext context, @NonNull Node node,
@NonNull final String recycleType, @NonNull final String recycleName) {
ResolvedVariable boundVariable = getVariable(context, node);
if (boundVariable == null) {
return;
}
Node method = JavaContext.findSurroundingMethod(node);
if (method == null) {
return;
}
FinishVisitor visitor = new FinishVisitor(context, boundVariable) {
@Override
protected boolean isCleanupCall(@NonNull MethodInvocation call) {
String methodName = call.astName().astValue();
if (!recycleName.equals(methodName)) {
return false;
}
ResolvedNode resolved = mContext.resolve(call);
if (resolved instanceof ResolvedMethod) {
ResolvedClass containingClass = ((ResolvedMethod) resolved).getContainingClass();
if (containingClass.isSubclassOf(recycleType, false)) {
// Yes, called the right recycle() method; now make sure
// we're calling it on the right variable
Expression operand = call.astOperand();
if (operand != null) {
resolved = mContext.resolve(operand);
//noinspection SuspiciousMethodCalls
if (resolved != null && mVariables.contains(resolved)) {
return true;
}
}
}
}
return false;
}
};
method.accept(visitor);
if (visitor.isCleanedUp() || visitor.variableEscapes()) {
return;
}
String className = recycleType.substring(recycleType.lastIndexOf('.') + 1);
String message;
if (RECYCLE.equals(recycleName)) {
message = String.format(
"This `%1$s` should be recycled after use with `#recycle()`", className);
} else {
message = String.format(
"This `%1$s` should be freed up after use with `#%2$s()`", className,
recycleName);
}
Node locationNode = node instanceof MethodInvocation ?
((MethodInvocation) node).astName() : node;
Location location = context.getLocation(locationNode);
context.report(RECYCLE_RESOURCE, node, location, message);
}