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

Java VisitorState类代码示例

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

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



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

示例1: handleChainFromFilter

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private void handleChainFromFilter(
    StreamTypeRecord streamType,
    MethodInvocationTree observableDotFilter,
    Tree filterMethodOrLambda,
    VisitorState state) {
  // Traverse the observable call chain out through any pass-through methods
  MethodInvocationTree outerCallInChain = observableOuterCallInChain.get(observableDotFilter);
  while (outerCallInChain != null
      && streamType.matchesType(ASTHelpers.getReceiverType(outerCallInChain), state)
      && streamType.isPassthroughMethod(ASTHelpers.getSymbol(outerCallInChain))) {
    outerCallInChain = observableOuterCallInChain.get(outerCallInChain);
  }
  // Check for a map method
  MethodInvocationTree mapCallsite = observableOuterCallInChain.get(observableDotFilter);
  if (outerCallInChain != null
      && observableCallToInnerMethodOrLambda.containsKey(outerCallInChain)) {
    // Update mapToFilterMap
    Symbol.MethodSymbol mapMethod = ASTHelpers.getSymbol(outerCallInChain);
    if (streamType.isMapMethod(mapMethod)) {
      MaplikeToFilterInstanceRecord record =
          new MaplikeToFilterInstanceRecord(
              streamType.getMaplikeMethodRecord(mapMethod), filterMethodOrLambda);
      mapToFilterMap.put(observableCallToInnerMethodOrLambda.get(outerCallInChain), record);
    }
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:27,代码来源:RxNullabilityPropagator.java


示例2: onMatchLambdaExpression

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public void onMatchLambdaExpression(
    NullAway analysis,
    LambdaExpressionTree tree,
    VisitorState state,
    Symbol.MethodSymbol methodSymbol) {
  if (filterMethodOrLambdaSet.contains(tree)
      && tree.getBodyKind().equals(LambdaExpressionTree.BodyKind.EXPRESSION)) {
    expressionBodyToFilterLambda.put((ExpressionTree) tree.getBody(), tree);
    // Single expression lambda, onMatchReturn will not be triggered, force the dataflow analysis
    // here
    AccessPathNullnessAnalysis nullnessAnalysis = analysis.getNullnessAnalysis(state);
    nullnessAnalysis.forceRunOnMethod(state.getPath(), state.context);
  }
  if (mapToFilterMap.containsKey(tree)) {
    bodyToMethodOrLambda.put(tree.getBody(), tree);
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:19,代码来源:RxNullabilityPropagator.java


示例3: onMatchReturn

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public void onMatchReturn(NullAway analysis, ReturnTree tree, VisitorState state) {
  // Figure out the enclosing method node
  TreePath enclosingMethodOrLambda =
      NullabilityUtil.findEnclosingMethodOrLambdaOrInitializer(state.getPath());
  if (enclosingMethodOrLambda == null) {
    throw new RuntimeException("no enclosing method, lambda or initializer!");
  }
  if (!(enclosingMethodOrLambda.getLeaf() instanceof MethodTree
      || enclosingMethodOrLambda.getLeaf() instanceof LambdaExpressionTree)) {
    throw new RuntimeException(
        "return statement outside of a method or lambda! (e.g. in an initializer block)");
  }
  Tree leaf = enclosingMethodOrLambda.getLeaf();
  if (filterMethodOrLambdaSet.contains(leaf)) {
    returnToEnclosingMethodOrLambda.put(tree, leaf);
    // We need to manually trigger the dataflow analysis to run on the filter method,
    // this ensures onDataflowVisitReturn(...) gets called for all return statements in this
    // method before
    // onDataflowInitialStore(...) is called for all successor methods in the observable chain.
    // Caching should prevent us from re-analyzing any given method.
    AccessPathNullnessAnalysis nullnessAnalysis = analysis.getNullnessAnalysis(state);
    nullnessAnalysis.forceRunOnMethod(new TreePath(state.getPath(), leaf), state.context);
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:26,代码来源:RxNullabilityPropagator.java


示例4: matchNewClass

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public Description matchNewClass(NewClassTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Symbol.MethodSymbol methodSymbol = ASTHelpers.getSymbol(tree);
  if (methodSymbol == null) {
    throw new RuntimeException("not expecting unresolved method here");
  }
  List<? extends ExpressionTree> actualParams = tree.getArguments();
  if (tree.getClassBody() != null && actualParams.size() > 0) {
    // passing parameters to constructor of anonymous class
    // this constructor just invokes the constructor of the superclass, and
    // in the AST does not have the parameter nullability annotations from the superclass.
    // so, treat as if the superclass constructor is being invoked directly
    // see https://github.com/uber/NullAway/issues/102
    Type supertype = state.getTypes().supertype(methodSymbol.owner.type);
    Symbol.MethodSymbol superConstructor =
        findSuperConstructorInType(methodSymbol, supertype, state.getTypes());
    if (superConstructor == null) {
      throw new RuntimeException("must find constructor in supertype");
    }
    methodSymbol = superConstructor;
  }
  return handleInvocation(state, methodSymbol, actualParams);
}
 
开发者ID:uber,项目名称:NullAway,代码行数:27,代码来源:NullAway.java


示例5: matchMemberSelect

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public Description matchMemberSelect(MemberSelectTree tree, VisitorState state) {
  if (!matchWithinClass) {
    return Description.NO_MATCH;
  }
  Symbol symbol = ASTHelpers.getSymbol(tree);
  // some checks for cases where we know it is not
  // a null dereference
  if (symbol == null || symbol.getSimpleName().toString().equals("class") || symbol.isEnum()) {
    return Description.NO_MATCH;
  }

  Description badDeref = matchDereference(tree.getExpression(), tree, state);
  if (!badDeref.equals(Description.NO_MATCH)) {
    return badDeref;
  }
  // if we're accessing a field of this, make sure we're not reading the field before init
  if (tree.getExpression() instanceof IdentifierTree
      && ((IdentifierTree) tree.getExpression()).getName().toString().equals("this")) {
    return checkForReadBeforeInit(tree, state);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:24,代码来源:NullAway.java


示例6: checkReturnExpression

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private Description checkReturnExpression(
    Tree tree, ExpressionTree retExpr, Symbol.MethodSymbol methodSymbol, VisitorState state) {
  Type returnType = methodSymbol.getReturnType();
  if (returnType.isPrimitive()) {
    // check for unboxing
    return doUnboxingCheck(state, retExpr);
  }
  if (returnType.toString().equals("java.lang.Void")) {
    return Description.NO_MATCH;
  }
  if (NullabilityUtil.fromUnannotatedPackage(methodSymbol, config)
      || Nullness.hasNullableAnnotation(methodSymbol)) {
    return Description.NO_MATCH;
  }
  if (mayBeNullExpr(state, retExpr)) {
    String message = "returning @Nullable expression from method with @NonNull return type";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.RETURN_NULLABLE, tree, message, retExpr, state.getPath());
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:22,代码来源:NullAway.java


示例7: matchLambdaExpression

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState state) {
  Symbol.MethodSymbol methodSymbol =
      NullabilityUtil.getFunctionalInterfaceMethod(tree, state.getTypes());
  handler.onMatchLambdaExpression(this, tree, state, methodSymbol);
  Description description = checkParamOverriding(tree, tree.getParameters(), methodSymbol, true);
  if (description != Description.NO_MATCH) {
    return description;
  }
  if (tree.getBodyKind() == LambdaExpressionTree.BodyKind.EXPRESSION
      && methodSymbol.getReturnType().getKind() != TypeKind.VOID) {
    ExpressionTree resExpr = (ExpressionTree) tree.getBody();
    return checkReturnExpression(tree, resExpr, methodSymbol, state);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:17,代码来源:NullAway.java


示例8: relevantInitializerMethodOrBlock

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private boolean relevantInitializerMethodOrBlock(
    TreePath enclosingBlockPath, VisitorState state) {
  Tree methodLambdaOrBlock = enclosingBlockPath.getLeaf();
  if (methodLambdaOrBlock instanceof LambdaExpressionTree) {
    return false;
  } else if (methodLambdaOrBlock instanceof MethodTree) {
    MethodTree methodTree = (MethodTree) methodLambdaOrBlock;
    if (isConstructor(methodTree) && !constructorInvokesAnother(methodTree, state)) return true;
    if (ASTHelpers.getSymbol(methodTree).isStatic()) {
      Set<MethodTree> staticInitializerMethods =
          class2Entities.get(enclosingClassSymbol(enclosingBlockPath)).staticInitializerMethods();
      return staticInitializerMethods.size() == 1
          && staticInitializerMethods.contains(methodTree);
    } else {
      Set<MethodTree> instanceInitializerMethods =
          class2Entities
              .get(enclosingClassSymbol(enclosingBlockPath))
              .instanceInitializerMethods();
      return instanceInitializerMethods.size() == 1
          && instanceInitializerMethods.contains(methodTree);
    }
  } else {
    // initializer or field declaration
    return true;
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:27,代码来源:NullAway.java


示例9: checkPossibleUninitFieldRead

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private Description checkPossibleUninitFieldRead(
    ExpressionTree tree,
    VisitorState state,
    Symbol symbol,
    TreePath path,
    TreePath enclosingBlockPath) {
  if (!fieldInitializedByPreviousInitializer(symbol, enclosingBlockPath, state)
      && !fieldAlwaysInitializedBeforeRead(symbol, path, state, enclosingBlockPath)) {
    return createErrorDescription(
        MessageTypes.NONNULL_FIELD_READ_BEFORE_INIT,
        tree,
        "read of @NonNull field " + symbol + " before initialization",
        path);
  } else {
    return Description.NO_MATCH;
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java


示例10: matchBinary

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
  ExpressionTree leftOperand = tree.getLeftOperand();
  ExpressionTree rightOperand = tree.getRightOperand();
  Type leftType = ASTHelpers.getType(leftOperand);
  Type rightType = ASTHelpers.getType(rightOperand);
  if (leftType == null || rightType == null) {
    throw new RuntimeException();
  }
  if (leftType.isPrimitive() && !rightType.isPrimitive()) {
    return doUnboxingCheck(state, rightOperand);
  }
  if (rightType.isPrimitive() && !leftType.isPrimitive()) {
    return doUnboxingCheck(state, leftOperand);
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:18,代码来源:NullAway.java


示例11: doUnboxingCheck

import com.google.errorprone.VisitorState; //导入依赖的package包/类
/**
 * if any expression has non-primitive type, we should check that it can't be null as it is
 * getting unboxed
 *
 * @param expressions expressions to check
 * @return error Description if an error is found, otherwise NO_MATCH
 */
private Description doUnboxingCheck(VisitorState state, ExpressionTree... expressions) {
  for (ExpressionTree tree : expressions) {
    Type type = ASTHelpers.getType(tree);
    if (type == null) {
      throw new RuntimeException("was not expecting null type");
    }
    if (!type.isPrimitive()) {
      if (mayBeNullExpr(state, tree)) {
        return createErrorDescription(
            MessageTypes.UNBOX_NULLABLE, tree, "unboxing of a @Nullable value", state.getPath());
      }
    }
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:23,代码来源:NullAway.java


示例12: checkConstructorInitialization

import com.google.errorprone.VisitorState; //导入依赖的package包/类
/**
 * @param entities field init info
 * @param state visitor state
 * @return a map from each constructor C to the nonnull fields that C does *not* initialize
 */
private SetMultimap<MethodTree, Symbol> checkConstructorInitialization(
    FieldInitEntities entities, VisitorState state) {
  SetMultimap<MethodTree, Symbol> result = LinkedHashMultimap.create();
  Set<Symbol> nonnullInstanceFields = entities.nonnullInstanceFields();
  Trees trees = Trees.instance(JavacProcessingEnvironment.instance(state.context));
  for (MethodTree constructor : entities.constructors()) {
    if (constructorInvokesAnother(constructor, state)) {
      continue;
    }
    Set<Element> guaranteedNonNull =
        guaranteedNonNullForConstructor(entities, state, trees, constructor);
    for (Symbol fieldSymbol : nonnullInstanceFields) {
      if (!guaranteedNonNull.contains(fieldSymbol)) {
        result.put(constructor, fieldSymbol);
      }
    }
  }
  return result;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:25,代码来源:NullAway.java


示例13: addGuaranteedNonNullFromInvokes

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private void addGuaranteedNonNullFromInvokes(
    VisitorState state,
    Trees trees,
    Set<Element> safeInitMethods,
    AccessPathNullnessAnalysis nullnessAnalysis,
    Set<Element> guaranteedNonNull) {
  for (Element invoked : safeInitMethods) {
    Tree invokedTree = trees.getTree(invoked);
    guaranteedNonNull.addAll(
        nullnessAnalysis.getNonnullFieldsOfReceiverAtExit(
            new TreePath(state.getPath(), invokedTree), state.context));
  }
}
 
开发者ID:uber,项目名称:NullAway,代码行数:14,代码来源:NullAway.java


示例14: isInitializerMethod

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private boolean isInitializerMethod(VisitorState state, Symbol.MethodSymbol symbol) {
  if (ASTHelpers.hasDirectAnnotationWithSimpleName(symbol, "Initializer")
      || config.isKnownInitializerMethod(symbol)) {
    return true;
  }
  for (AnnotationMirror anno : symbol.getAnnotationMirrors()) {
    String annoTypeStr = anno.getAnnotationType().toString();
    if (config.isInitializerMethodAnnotation(annoTypeStr)) {
      return true;
    }
  }
  Symbol.MethodSymbol closestOverriddenMethod =
      getClosestOverriddenMethod(symbol, state.getTypes());
  if (closestOverriddenMethod == null) {
    return false;
  }
  return isInitializerMethod(state, closestOverriddenMethod);
}
 
开发者ID:uber,项目名称:NullAway,代码行数:19,代码来源:NullAway.java


示例15: isExcludedClass

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private boolean isExcludedClass(Symbol.ClassSymbol classSymbol, VisitorState state) {
  String className = classSymbol.getQualifiedName().toString();
  if (config.isExcludedClass(className)) {
    return true;
  }
  if (!config.fromAnnotatedPackage(className)) {
    return true;
  }
  // check annotations
  for (AnnotationMirror anno : classSymbol.getAnnotationMirrors()) {
    if (config.isExcludedClassAnnotation(anno.getAnnotationType().toString())) {
      return true;
    }
  }
  return false;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:17,代码来源:NullAway.java


示例16: matchDereference

import com.google.errorprone.VisitorState; //导入依赖的package包/类
private Description matchDereference(
    ExpressionTree baseExpression, ExpressionTree derefExpression, VisitorState state) {
  Symbol dereferenced = ASTHelpers.getSymbol(baseExpression);
  if (dereferenced == null
      || dereferenced.type.isPrimitive()
      || !kindMayDeferenceNull(dereferenced.getKind())) {
    // we know we don't have a null dereference here
    return Description.NO_MATCH;
  }
  if (mayBeNullExpr(state, baseExpression)) {
    String message = "dereferenced expression " + baseExpression.toString() + " is @Nullable";
    return createErrorDescriptionForNullAssignment(
        MessageTypes.DEREFERENCE_NULLABLE,
        derefExpression,
        message,
        baseExpression,
        state.getPath());
  }
  return Description.NO_MATCH;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:21,代码来源:NullAway.java


示例17: matches

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
  if (!(tree instanceof MethodInvocationTree)) {
    return false;
  }
  MethodInvocationTree invTree = (MethodInvocationTree) tree;

  final MemberSelectTree memberTree = (MemberSelectTree) invTree.getMethodSelect();
  if (!memberTree.getIdentifier().contentEquals(TO)) {
    return false;
  }

  for (MethodMatchers.MethodNameMatcher nameMatcher : METHOD_NAME_MATCHERS) {
    if (nameMatcher.matches(invTree, state)) {
      ExpressionTree arg = invTree.getArguments().get(0);
      final Type scoper = state.getTypeFromString("com.uber.autodispose.Scoper");
      return ASTHelpers.isSubtype(ASTHelpers.getType(arg), scoper, state);
    }
  }
  return false;
}
 
开发者ID:uber,项目名称:RIBs,代码行数:22,代码来源:RxJavaMissingAutodisposeErrorChecker.java


示例18: matchReturn

import com.google.errorprone.VisitorState; //导入依赖的package包/类
@Override
public Description matchReturn(ReturnTree tree, VisitorState state) {
  if (tree.getExpression() == null) {
    return NO_MATCH;
  }
  Type type = null;
  outer:
  for (Tree parent : state.getPath()) {
    switch (parent.getKind()) {
      case METHOD:
        type = ASTHelpers.getType(((MethodTree) parent).getReturnType());
        break outer;
      case LAMBDA_EXPRESSION:
        type = state.getTypes().findDescriptorType(ASTHelpers.getType(parent)).getReturnType();
        break outer;
      default: // fall out
    }
  }
  if (type == null) {
    return NO_MATCH;
  }
  return check(type, tree.getExpression());
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:IntLongMath.java


示例19: removeFromList

import com.google.errorprone.VisitorState; //导入依赖的package包/类
/** Deletes an entry and its delimiter from a list. */
private static void removeFromList(
    SuggestedFix.Builder fix, VisitorState state, List<? extends Tree> arguments, Tree tree) {
  int idx = arguments.indexOf(tree);
  if (idx == arguments.size() - 1) {
    fix.replace(
        state.getEndPosition(arguments.get(arguments.size() - 1)),
        state.getEndPosition(tree),
        "");
  } else {
    fix.replace(
        ((JCTree) tree).getStartPosition(),
        ((JCTree) arguments.get(idx + 1)).getStartPosition(),
        "");
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:17,代码来源:AbstractTestExceptionChecker.java


示例20: isImmutable

import com.google.errorprone.VisitorState; //导入依赖的package包/类
/**
 * Recognize a small set of known-immutable types that are safe for DCL even without a volatile
 * field.
 */
private static boolean isImmutable(Type type, VisitorState state) {
  switch (type.getKind()) {
    case BOOLEAN:
    case BYTE:
    case SHORT:
    case INT:
    case CHAR:
    case FLOAT:
      return true;
    case LONG:
    case DOUBLE:
      // double-width primitives aren't written atomically
      return true;
    default:
      break;
  }
  return IMMUTABLE_WHITELIST.contains(
      state.getTypes().erasure(type).tsym.getQualifiedName().toString());
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:DoubleCheckedLocking.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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