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


Java Node.getParent方法代码示例

本文整理汇总了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);
}
 
开发者ID:ashdavies,项目名称:dagger-lint,代码行数:19,代码来源:ConcreteModuleDetector.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CleanupDetector.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:JavaContext.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CutPasteDetector.java

示例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;
}
 
开发者ID:Piasy,项目名称:SafelyAndroid,代码行数:15,代码来源:UnsafeAndroidDetector.java

示例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;
}
 
开发者ID:hoangkien0705,项目名称:Android-ButterKinfe,代码行数:13,代码来源:InvalidR2UsageDetector.java

示例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;
    }
}
 
开发者ID:GavinCT,项目名称:MeituanLintDemo,代码行数:16,代码来源:ToastDetector.java

示例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);
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:32,代码来源:ZipEntryAstVisitor.java

示例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);
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:15,代码来源:ThreadPriorityAstVisitor.java

示例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;
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:30,代码来源:ConcurrentModificationAstVisitor.java

示例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;
}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:19,代码来源:ForIfTryDepthDetector.java

示例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;
}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:19,代码来源:ForIfTryDepthDetector.java

示例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;
}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:14,代码来源:ForIfTryDepthDetector.java

示例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();
}
 
开发者ID:tynn,项目名称:simplDb,代码行数:9,代码来源:SimplLintVisitor.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:16,代码来源:JavaContext.java


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