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


Java VisitorState类代码示例

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


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


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