• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Node类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中lombok.ast.Node的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: visitMethod

import lombok.ast.Node; //导入依赖的package包/类
@Override
public void visitMethod(JavaContext context, AstVisitor visitor, MethodInvocation node) {
    if (!isNode(context, node, MethodDefinitions.ALL_OF)) {
        return;
    }
    // is parent onView or withView?
    Node parentNode = node.getParent();
    if (isInvalidParent(context, parentNode)) {
        return;
    }

    MethodInvocation matcher = extractMatcher(context, node);
    // has withXXX()
    if (!isWithNode(context, matcher)) {
        return;
    }
    String message = argumentsAsString(matcher, MESSAGE_FORMAT);
    context.report(ISSUE, node, context.getLocation(parentNode), message);
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:20,代码来源:AllOfIsDisplayedDetector.java


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


示例3: visitResourceReference

import lombok.ast.Node; //导入依赖的package包/类
@Override
public void visitResourceReference(
        @NonNull JavaContext context,
        @Nullable AstVisitor visitor,
        @NonNull Node node,
        @NonNull String type,
        @NonNull String name,
        boolean isFramework) {
    if (context.getProject().isGradleProject() && !isFramework) {
        Project project = context.getProject();
        if (project.getGradleProjectModel() != null && project.getCurrentVariant() != null) {
            ResourceType resourceType = ResourceType.getEnum(type);
            if (resourceType != null && isPrivate(context, resourceType, name)) {
                String message = createUsageErrorMessage(context, resourceType, name);
                context.report(ISSUE, node, context.getLocation(node), message);
            }
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PrivateResourceDetector.java


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


示例5: findNodeByLiterals

import lombok.ast.Node; //导入依赖的package包/类
public static Node findNodeByLiterals(Node root, Class<?> targetNodeClass, String literals) {
    if (null == root || null == targetNodeClass) {
        return null;
    }

    if (root.getClass().equals(targetNodeClass) &&
            root.toString().equals(literals)) {
        return root;
    }

    Node ret = null;
    for (Node child : root.getChildren()) {
        ret = findNodeByLiterals(child, targetNodeClass, literals);
        if (null != ret) {
            break;
        }
    }
    return ret;
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:20,代码来源:NodeUtils.java


示例6: searchSetPriorityNodes

import lombok.ast.Node; //导入依赖的package包/类
/**
 * 给定thread变量名,获取其所有的setPriority()节点列表
 *
 * @param operand
 * @param node
 * @param setPriorityNodes
 */
private void searchSetPriorityNodes(Node operand, Node node, ArrayList<MethodInvocation> setPriorityNodes) {
    JavaParser.ResolvedMethod resolvedMethod = NodeUtils.parseResolvedMethod(mContext, node);
    if (null != resolvedMethod &&
            "setPriority".equals(resolvedMethod.getName()) &&
            resolvedMethod.getContainingClass().isSubclassOf("java.lang.Thread", false) &&
            node instanceof MethodInvocation) {
        MethodInvocation methodInvocation = (MethodInvocation)node;
        // 这里比较的是Node.toString()而非Node本身,原因在于,赋值节点的operand是Identifier,
        // 而此处Thread.setPriority()节点的operand确实VariableReference。虽然它们的字符串值
        // 相同,但是在AST里却是不同类型的节点。
        if (methodInvocation.rawOperand().toString().equals(operand.toString())) {
            setPriorityNodes.add(methodInvocation);
        }
    }

    List<Node> children = node.getChildren();
    if (null != children && !children.isEmpty()) {
        for (Node child : node.getChildren()) {
            searchSetPriorityNodes(operand, child, setPriorityNodes);
        }
    }
}
 
开发者ID:squirrel-explorer,项目名称:eagleeye-android,代码行数:30,代码来源:ThreadPriorityAstVisitor.java


示例7: resolve

import lombok.ast.Node; //导入依赖的package包/类
@Nullable
@Override
public ResolvedNode resolve(@NonNull JavaContext context, @NonNull Node node) {
  final PsiElement element = getPsiElement(node);
  if (element == null) {
    return null;
  }

  Application application = ApplicationManager.getApplication();
  if (application.isReadAccessAllowed()) {
    return resolve(element);
  }
  return application.runReadAction(new Computable<ResolvedNode>() {
    @Nullable
    @Override
    public ResolvedNode compute() {
      return resolve(element);
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:LombokPsiParser.java


示例8: isThisInstanceOfActivity_ForActivity

import lombok.ast.Node; //导入依赖的package包/类
/**
 * If setContentView is called by 'this' instance,
 * this method will check if 'this' is an instance of a Class inherit from android.app.Activity, for eaxmple AppCompatActivity or FragmentActivity, and so on.
 */
private boolean isThisInstanceOfActivity_ForActivity(@NonNull JavaContext context, @NonNull MethodInvocation node) {
    Node currentNode = node.getParent();

    JavaParser.ResolvedNode resolved = context.resolve(JavaContext.findSurroundingClass(node));
    JavaParser.ResolvedClass sorroundingClass = (JavaParser.ResolvedClass) resolved;
    while (sorroundingClass != null) {
        //System.out.println("sorroundingClass = " + sorroundingClass);
        if ("android.app.Activity".equals(sorroundingClass.getName())) {
            return true;
        } else {
            sorroundingClass = sorroundingClass.getSuperClass();
        }
    }


    return false;


}
 
开发者ID:ljfxyj2008,项目名称:CustomLintDemo,代码行数:24,代码来源:ActivityFragmentLayoutNameDetector.java


示例9: checkClass

import lombok.ast.Node; //导入依赖的package包/类
@Override
public void checkClass(@NonNull JavaContext context, @Nullable ClassDeclaration declaration,
        @NonNull Node node, @NonNull ResolvedClass cls) {
    if (!isInnerClass(declaration)) {
        return;
    }

    if (isStaticClass(declaration)) {
        return;
    }

    // Only flag handlers using the default looper
    if (hasLooperConstructorParameter(cls)) {
        return;
    }

    Node locationNode = node instanceof ClassDeclaration
            ? ((ClassDeclaration) node).astName() : node;
    Location location = context.getLocation(locationNode);
    context.report(ISSUE, location, String.format(
            "This Handler class should be static or leaks might occur (%1$s)",
            cls.getName()));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:HandlerDetector.java


示例10: checkWithinConditional

import lombok.ast.Node; //导入依赖的package包/类
private static boolean checkWithinConditional(
        @NonNull JavaContext context,
        @Nullable Node curr,
        @NonNull MethodInvocation logCall) {
    while (curr != null) {
        if (curr instanceof If) {
            If ifNode = (If) curr;
            if (ifNode.astCondition() instanceof MethodInvocation) {
                MethodInvocation call = (MethodInvocation) ifNode.astCondition();
                if (IS_LOGGABLE.equals(call.astName().astValue())) {
                    checkTagConsistent(context, logCall, call);
                }
            }

            return true;
        } else if (curr instanceof MethodInvocation
                || curr instanceof ClassDeclaration) { // static block
            break;
        }
        curr = curr.getParent();
    }
    return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:LogDetector.java


示例11: parse

import lombok.ast.Node; //导入依赖的package包/类
@Nullable
private static Node parse(String code) {
  CompilerOptions options = new CompilerOptions();
  options.complianceLevel = options.sourceLevel = options.targetJDK = ClassFileConstants.JDK1_7;
  options.parseLiteralExpressionsAsConstants = true;
  ProblemReporter problemReporter = new ProblemReporter(
    DefaultErrorHandlingPolicies.exitOnFirstError(), options, new DefaultProblemFactory());
  Parser parser = new Parser(problemReporter, options.parseLiteralExpressionsAsConstants);
  parser.javadocParser.checkDocComment = false;
  EcjTreeConverter converter = new EcjTreeConverter();
  org.eclipse.jdt.internal.compiler.batch.CompilationUnit sourceUnit =
    new org.eclipse.jdt.internal.compiler.batch.CompilationUnit(code.toCharArray(), "unitTest", "UTF-8");
  CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
  CompilationUnitDeclaration unit = parser.parse(sourceUnit, compilationResult);
  if (unit == null) {
    return null;
  }
  converter.visit(code, unit);
  List<? extends Node> nodes = converter.getAll();
  for (lombok.ast.Node node : nodes) {
    if (node instanceof lombok.ast.CompilationUnit) {
      return node;
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:LombokPsiConverterTest.java


示例12: getParentOfType

import lombok.ast.Node; //导入依赖的package包/类
/**
 * Returns the first ancestor node of 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 <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) {
    if (element == null) {
        return null;
    }

    if (strict) {
        element = element.getParent();
    }

    while (element != null) {
        if (clz.isInstance(element)) {
            //noinspection unchecked
            return (T) element;
        }
        element = element.getParent();
    }

    return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:JavaContext.java


示例13: visitMethod

import lombok.ast.Node; //导入依赖的package包/类
@Override
public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor,
        @NonNull MethodInvocation node) {

    // Call is only allowed if it is both only called on the super class (invoke special)
    // as well as within the same overriding method (e.g. you can't call super.onLayout
    // from the onMeasure method)
    Expression operand = node.astOperand();
    if (!(operand instanceof Super)) {
        report(context, node);
        return;
    }

    Node method = StringFormatDetector.getParentMethod(node);
    if (!(method instanceof MethodDeclaration) ||
            !((MethodDeclaration)method).astMethodName().astValue().equals(
                    node.astName().astValue())) {
        report(context, node);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:WrongCallDetector.java


示例14: checkColor

import lombok.ast.Node; //导入依赖的package包/类
private static void checkColor(@NonNull JavaContext context, @NonNull Node argument) {
    if (argument instanceof InlineIfExpression) {
        InlineIfExpression expression = (InlineIfExpression) argument;
        checkColor(context, expression.astIfTrue());
        checkColor(context, expression.astIfFalse());
        return;
    }

    List<ResourceType> types = getResourceTypes(context, argument);

    if (types != null && types.contains(ResourceType.COLOR)) {
        String message = String.format(
                "Should pass resolved color instead of resource id here: " +
                        "`getResources().getColor(%1$s)`", argument.toString());
        context.report(COLOR_USAGE, argument, context.getLocation(argument), message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SupportAnnotationDetector.java


示例15: getLhs

import lombok.ast.Node; //导入依赖的package包/类
@Nullable
private static VariableDefinition getLhs(@NonNull Node node) {
    while (node != null) {
        Class<? extends Node> type = node.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 null;
        }
        if (type == VariableDefinition.class) {
            return (VariableDefinition) node;
        }

        node = node.getParent();
    }

    return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SharedPrefsDetector.java


示例16: checkIntRange

import lombok.ast.Node; //导入依赖的package包/类
private static void checkIntRange(
        @NonNull JavaContext context,
        @NonNull ResolvedAnnotation annotation,
        @NonNull Node argument) {
    Object object = ConstantEvaluator.evaluate(context, argument);
    if (!(object instanceof Number)) {
        return;
    }
    long value = ((Number)object).longValue();
    long from = getLongAttribute(annotation, ATTR_FROM, Long.MIN_VALUE);
    long to = getLongAttribute(annotation, ATTR_TO, Long.MAX_VALUE);

    String message = getIntRangeError(value, from, to);
    if (message != null) {
        context.report(RANGE, argument, context.getLocation(argument), message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:SupportAnnotationDetector.java


示例17: checkFloatRange

import lombok.ast.Node; //导入依赖的package包/类
private static void checkFloatRange(
        @NonNull JavaContext context,
        @NonNull ResolvedAnnotation annotation,
        @NonNull Node argument) {
    Object object = ConstantEvaluator.evaluate(context, argument);
    if (!(object instanceof Number)) {
        return;
    }
    double value = ((Number)object).doubleValue();
    double from = getDoubleAttribute(annotation, ATTR_FROM, Double.NEGATIVE_INFINITY);
    double to = getDoubleAttribute(annotation, ATTR_TO, Double.POSITIVE_INFINITY);
    boolean fromInclusive = getBoolean(annotation, ATTR_FROM_INCLUSIVE, true);
    boolean toInclusive = getBoolean(annotation, ATTR_TO_INCLUSIVE, true);

    String message = getFloatRangeError(value, from, to, fromInclusive, toInclusive, argument);
    if (message != null) {
        context.report(RANGE, argument, context.getLocation(argument), message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:SupportAnnotationDetector.java


示例18: checkClass

import lombok.ast.Node; //导入依赖的package包/类
@Override
public void checkClass(@NonNull JavaContext context, @Nullable ClassDeclaration node,
        @NonNull Node declarationOrAnonymous, @NonNull ResolvedClass resolvedClass) {
    if (!context.getProject().getReportIssues()) {
        return;
    }
    String className = resolvedClass.getName();
    if (resolvedClass.isSubclassOf(PREFERENCE_ACTIVITY, false)
            && mExportedActivities.containsKey(className)) {

        // Ignore the issue if we target an API greater than 19 and the class in
        // question specifically overrides isValidFragment() and thus knowingly white-lists
        // valid fragments.
        if (context.getMainProject().getTargetSdk() >= 19
                && overridesIsValidFragment(resolvedClass)) {
            return;
        }

        String message = String.format(
                "`PreferenceActivity` subclass `%1$s` should not be exported",
                className);
        context.report(ISSUE, mExportedActivities.get(className).resolve(), message);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:PreferenceActivityDetector.java


示例19: isInvalidParent

import lombok.ast.Node; //导入依赖的package包/类
private boolean isInvalidParent(JavaContext context, Node parentNode) {
    if (!(parentNode instanceof MethodInvocation)) {
        return true;
    }
    MethodInvocation parent = (MethodInvocation) parentNode;
    return !isNode(context, parent, MethodDefinitions.RISTRETTO_WITH_VIEW)
            && !isNode(context, parent, MethodDefinitions.ON_VIEW);
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:9,代码来源:AllOfIsDisplayedDetector.java


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LinkProperties类代码示例发布时间:2022-05-21
下一篇:
Java NoopTracerFactory类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap