本文整理汇总了Java中lombok.ast.Node.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getParent方法的具体用法?Java Node.getParent怎么用?Java Node.getParent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lombok.ast.Node
的用法示例。
在下文中一共展示了Node.getParent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitAnnotation
import lombok.ast.Node; //导入方法依赖的package包/类
@Override
public boolean visitAnnotation(Annotation node) {
String type = node.astAnnotationTypeReference().getTypeName();
if (DAGGER_MODULE.equals(type)) {
Node parent = node.getParent();
if (parent instanceof Modifiers) {
parent = parent.getParent();
if (parent instanceof ClassDeclaration) {
int flags = ((ClassDeclaration) parent).astModifiers().getEffectiveModifierFlags();
if ((flags & Modifier.ABSTRACT) == 0) {
context.report(ISSUE, Location.create(context.file), ISSUE.getBriefDescription(TextFormat.TEXT));
}
}
}
}
return super.visitAnnotation(node);
}
示例2: isCommittedInChainedCalls
import lombok.ast.Node; //导入方法依赖的package包/类
private static boolean isCommittedInChainedCalls(@NonNull JavaContext context,
@NonNull MethodInvocation node) {
// Look for chained calls since the FragmentManager methods all return "this"
// to allow constructor chaining, e.g.
// getFragmentManager().beginTransaction().addToBackStack("test")
// .disallowAddToBackStack().hide(mFragment2).setBreadCrumbShortTitle("test")
// .show(mFragment2).setCustomAnimations(0, 0).commit();
Node parent = node.getParent();
while (parent instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) parent;
if (isTransactionCommitMethodCall(context, methodInvocation)
|| isShowFragmentMethodCall(context, methodInvocation)) {
return true;
}
parent = parent.getParent();
}
return false;
}
示例3: getParentOfType
import lombok.ast.Node; //导入方法依赖的package包/类
/**
* Returns the first ancestor node of the given type, stopping at the given type
*
* @param element the element to search from
* @param clz the target node type
* @param strict if true, do not consider the element itself, only its parents
* @param terminators optional node types to terminate the search at
* @param <T> the target node type
* @return the nearest ancestor node in the parent chain, or null if not found
*/
@Nullable
public static <T extends Node> T getParentOfType(@Nullable Node element,
@NonNull Class<T> clz,
boolean strict,
@NonNull Class<? extends Node>... terminators) {
if (element == null) {
return null;
}
if (strict) {
element = element.getParent();
}
while (element != null && !clz.isInstance(element)) {
for (Class<?> terminator : terminators) {
if (terminator.isInstance(element)) {
return null;
}
}
element = element.getParent();
}
//noinspection unchecked
return (T) element;
}
示例4: getLhs
import lombok.ast.Node; //导入方法依赖的package包/类
@Nullable
private static String getLhs(@NonNull MethodInvocation call) {
Node parent = call.getParent();
if (parent instanceof Cast) {
parent = parent.getParent();
}
if (parent instanceof VariableDefinitionEntry) {
VariableDefinitionEntry vde = (VariableDefinitionEntry) parent;
return vde.astName().astValue();
} else if (parent instanceof BinaryExpression) {
BinaryExpression be = (BinaryExpression) parent;
Expression left = be.astLeft();
if (left instanceof VariableReference || left instanceof Select) {
return be.astLeft().toString();
} else if (left instanceof ArrayAccess) {
ArrayAccess aa = (ArrayAccess) left;
return aa.astOperand().toString();
}
}
return null;
}
示例5: isInsideDialogFragment
import lombok.ast.Node; //导入方法依赖的package包/类
private boolean isInsideDialogFragment(JavaContext context, MethodInvocation node) {
Node parent = node.getParent();
while (parent != null) {
Object resolvedNode = context.resolve(parent);
if (resolvedNode instanceof JavaParser.ResolvedMethod) {
JavaParser.ResolvedMethod method = (JavaParser.ResolvedMethod) resolvedNode;
if (isDialogFragment(method.getContainingClass())) {
return true;
}
}
parent = parent.getParent();
}
return false;
}
示例6: detectR2
import lombok.ast.Node; //导入方法依赖的package包/类
private static boolean detectR2(JavaContext context, Node node, Identifier identifier) {
boolean isR2 = node.getParent() != null
&& (identifier.toString().equals(R2) || identifier.toString().contains(".R2."))
&& node.getParent() instanceof Select
&& SUPPORTED_TYPES.contains(((Select) node.getParent()).astIdentifier().toString());
if (isR2 && !context.isSuppressedWithComment(node, ISSUE)) {
context.report(ISSUE, node, context.getLocation(identifier), LINT_ERROR_BODY);
}
return isR2;
}
示例7: findSurroundingMethod
import lombok.ast.Node; //导入方法依赖的package包/类
public static Node findSurroundingMethod(Node scope) {
while(true) {
if(scope != null) {
Class type = scope.getClass();
if(type != MethodDeclaration.class && type != ConstructorDeclaration.class && !isLambdaExpression(type)) {
scope = scope.getParent();
continue;
}
return scope;
}
return null;
}
}
示例8: visitMethodInvocation
import lombok.ast.Node; //导入方法依赖的package包/类
@Override
public boolean visitMethodInvocation(MethodInvocation node) {
JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
if (null == resolvedMethod) {
return super.visitMethodInvocation(node);
}
//判断是不是zipEntry.getName()函数
if ("java.util.zip.ZipEntry".equals(resolvedMethod.getContainingClass().getName()) && "public java.lang.String getName() ".equals(resolvedMethod.getSignature())) {
//找到当前调用所在的方法定义边界
boolean isSafe = false;
Node surroundingNode = JavaContext.findSurroundingMethod(node);
Node parent = node.getParent();
while (surroundingNode != parent) {
//判断有没有做保护
String judgeState = ".contains(\"../\")";
if (parent.toString().contains(judgeState)) {
isSafe = true;
break;
}
parent = parent.getParent();
}
if (!isSafe) {
mContext.report(
ZipEntryDetector.ISSUE,
mContext.getLocation(node),
"请检查zipEntry.getName()的返回值中是否含有字符串../,如果有,则是有危险的Zip包(可抛异常等操作"
);
}
}
return super.visitMethodInvocation(node);
}
示例9: findAssignOperand
import lombok.ast.Node; //导入方法依赖的package包/类
/**
* 获取new Thread()的赋值对象节点
*
* @param node new Thread()构造函数节点
* @return Thread t = new Thread()的赋值对象节点t,对于new Thread().xxx()形式,
* 赋值对象节点为new Thread()本身
*/
private Node findAssignOperand(Node node) {
Node parentNode = node.getParent();
if (null == parentNode) {
return node;
}
return parentNode.getChildren().get(0);
}
示例10: checkSingleThreadIterating
import lombok.ast.Node; //导入方法依赖的package包/类
private boolean checkSingleThreadIterating(MethodInvocation node) {
boolean ret = false;
if (!modCountChangeable(node)) {
return ret;
}
// 获取Method的operand,此处应为一个Collection实例
String operand = node.astOperand().toString();
// 获取当前调用所在的方法定义,作为检查的边界
Node surroundingMethod = JavaContext.findSurroundingMethod(node);
Node parent = node.getParent();
// 试图寻找,可能改变operand modCount的方法,是否运行在operand的iterating中
while (surroundingMethod != parent) {
if (parent instanceof ForEach &&
operand.equals(((ForEach)parent).astIterable().toString())) {
ret = true;
mContext.report(
ConcurrentModificationDetector.ISSUE,
mContext.getLocation(node),
"Please DO NOT modify elements DIRECTLY when iterating \"" + operand + "\".");
break;
}
parent = parent.getParent();
}
return ret;
}
示例11: getCurrentTryDepth
import lombok.ast.Node; //导入方法依赖的package包/类
/**
* Get depth of current Try node.
* By default, the init depth of Try node is 1.
* @param node current Try node.
*/
private int getCurrentTryDepth(Try node) {
Node currentCheckNode = node;
int depth = 0;
while (currentCheckNode != null){
if (currentCheckNode instanceof Try){
depth++;
}
currentCheckNode = currentCheckNode.getParent();
}
return depth;
}
示例12: getCurrentIfDepth
import lombok.ast.Node; //导入方法依赖的package包/类
/**
* Get depth of current If node.
* By default, the init depth of If node is 1.
* @param node current If node.
*/
private int getCurrentIfDepth(If node) {
Node currentCheckNode = node;
int depth = 0;
while (currentCheckNode != null){
if (currentCheckNode instanceof If){
depth++;
}
currentCheckNode = currentCheckNode.getParent();
}
return depth;
}
示例13: getCurrentForDepth
import lombok.ast.Node; //导入方法依赖的package包/类
private int getCurrentForDepth(For node) {
Node currentCheckNode = node;
int depth = 0;
while (currentCheckNode != null){
if (currentCheckNode instanceof For){
depth++;
}
currentCheckNode = currentCheckNode.getParent();
}
return depth;
}
示例14: isInterface
import lombok.ast.Node; //导入方法依赖的package包/类
private static boolean isInterface(Node node) {
while (!(node instanceof TypeDeclaration)) {
if (node == null)
return false;
node = node.getParent();
}
return ((TypeDeclaration) node).isInterface();
}
示例15: findSurroundingMethod
import lombok.ast.Node; //导入方法依赖的package包/类
@Nullable
public static Node findSurroundingMethod(Node scope) {
while (scope != null) {
Class<? extends Node> type = scope.getClass();
// The Lombok AST uses a flat hierarchy of node type implementation classes
// so no need to do instanceof stuff here.
if (type == MethodDeclaration.class || type == ConstructorDeclaration.class) {
return scope;
}
scope = scope.getParent();
}
return null;
}