Java 类com.sun.source.tree.InstanceOfTree 实例源码

项目:incubator-netbeans    文件:SemanticHighlighterBase.java   
@Override
public Void visitInstanceOf(InstanceOfTree tree, EnumSet<UseTypes> d) {
    Tree expr = tree.getExpression();

    if (expr instanceof IdentifierTree) {
        handlePossibleIdentifier(new TreePath(getCurrentPath(), expr), EnumSet.of(UseTypes.READ));
    }

    TreePath tp = new TreePath(getCurrentPath(), tree.getType());
    handlePossibleIdentifier(tp, EnumSet.of(UseTypes.CLASS_USE));

    super.visitInstanceOf(tree, null);

    //TODO: should be considered
    return null;
}
项目:incubator-netbeans    文件:EvaluatorVisitor.java   
@Override
public Mirror visitInstanceOf(InstanceOfTree arg0, EvaluationContext evaluationContext) {
    Mirror expr = arg0.getExpression().accept(this, evaluationContext);
    VirtualMachine vm = evaluationContext.getDebugger().getVirtualMachine();
    if (vm == null) {
        return null;
    }
    if (expr == null) {
        return mirrorOf(vm, false);
    }
    Assert.assertAssignable(expr, ObjectReference.class, arg0, "instanceOfLeftOperandNotAReference", expr);

    ReferenceType expressionType = ((ObjectReference) expr).referenceType();
    Type type = (Type) arg0.getType().accept(this, evaluationContext);

    return mirrorOf(vm, instanceOf(expressionType, type));
}
项目:error-prone    文件:NestedInstanceOfConditions.java   
@Override
public boolean matches(Tree tree, VisitorState state) {
  if (tree instanceof IfTree) {
    ExpressionTree conditionTree = ASTHelpers.stripParentheses(((IfTree) tree).getCondition());

    if (conditionTree instanceof InstanceOfTree) {
      InstanceOfTree instanceOfTree = (InstanceOfTree) conditionTree;

      Types types = state.getTypes();

      boolean isCastable =
          types.isCastable(
              types.erasure(ASTHelpers.getType(instanceOfTree.getType())),
              types.erasure(ASTHelpers.getType(typeTree)));

      boolean isSameExpression =
          instanceOfTree.getExpression().toString().equals(expressionTree.toString());

      return isSameExpression && !isCastable;
    }
  }
  return false;
}
项目:incubator-netbeans    文件:TreeDuplicator.java   
@Override
public Tree visitInstanceOf(InstanceOfTree tree, Void p) {
    InstanceOfTree n = make.InstanceOf(tree.getExpression(), tree.getType());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
项目:incubator-netbeans    文件:CopyFinder.java   
public Boolean visitInstanceOf(InstanceOfTree node, TreePath p) {
    if (p == null)
        return super.visitInstanceOf(node, p);

    InstanceOfTree t = (InstanceOfTree) p.getLeaf();

    if (!scan(node.getExpression(), t.getExpression(), p))
        return false;

    return scan(node.getType(), t.getType(), p);
}
项目:incubator-netbeans    文件:TreeNode.java   
@Override
public Void visitInstanceOf(InstanceOfTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();

    addCorrespondingType(below);
    addCorrespondingComments(below);
    super.visitInstanceOf(tree, below);

    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}
项目:incubator-netbeans    文件:EqualsMethodHint.java   
@Override
public Void visitInstanceOf(InstanceOfTree node, Void p) {
    Element e = info.getTrees().getElement(new TreePath(getCurrentPath(), node.getExpression()));

    if (parameter.equals(e)) {
        throw new Found();
    }

    return super.visitInstanceOf(node, p);
}
项目:incubator-netbeans    文件:ExpectedTypeResolver.java   
/**
 * Anything object-typed could be in the instance-of
 * 
 * @param node
 * @param p
 * @return 
 */
@Override
public List<? extends TypeMirror> visitInstanceOf(InstanceOfTree node, Object p) {
    if (theExpression == null) {
        initExpression(new TreePath(getCurrentPath(), node.getExpression()));
    }
    TypeElement tel = info.getElements().getTypeElement("java.lang.Object");
    if (tel == null) {
        return null;
    }
    return Collections.singletonList(tel.asType()); // NOI18N
}
项目:javaide    文件:JavaInputAstVisitor.java   
@Override
public Void visitInstanceOf(InstanceOfTree node, Void unused) {
    sync(node);
    builder.open(plusFour);
    scan(node.getExpression(), null);
    builder.breakOp(" ");
    builder.open(ZERO);
    token("instanceof");
    builder.breakOp(" ");
    scan(node.getType(), null);
    builder.close();
    builder.close();
    return null;
}
项目:annotation-tools    文件:InstanceOfScanner.java   
@Override
public Void visitInstanceOf(InstanceOfTree node, Void p) {
  if (!done) {
    index++;
  }
  if (tree == node) {
    done = true;
  }
  return super.visitInstanceOf(node, p);
}
项目:error-prone    文件:ErrorProneScanner.java   
@Override
public Void visitInstanceOf(InstanceOfTree tree, VisitorState visitorState) {
  VisitorState state = visitorState.withPath(getCurrentPath());
  for (InstanceOfTreeMatcher matcher : instanceOfMatchers) {
    if (!isSuppressed(matcher, state)) {
      try {
        reportMatch(matcher.matchInstanceOf(tree, state), tree, state);
      } catch (Throwable t) {
        handleError(matcher, t);
      }
    }
  }
  return super.visitInstanceOf(tree, state);
}
项目:error-prone    文件:UInstanceOf.java   
@Override
@Nullable
public Choice<Unifier> visitInstanceOf(InstanceOfTree instanceOf, @Nullable Unifier unifier) {
  return getExpression()
      .unify(instanceOf.getExpression(), unifier)
      .thenChoose(unifications(getType(), instanceOf.getType()));
}
项目:error-prone    文件:PlaceholderUnificationVisitor.java   
@Override
public Choice<State<JCInstanceOf>> visitInstanceOf(final InstanceOfTree node, State<?> state) {
  return chooseSubtrees(
      state,
      s -> unifyExpression(node.getExpression(), s),
      expr -> maker().TypeTest(expr, (JCTree) node.getType()));
}
项目:error-prone    文件:NestedInstanceOfConditions.java   
@Override
public Description matchIf(IfTree ifTree, VisitorState visitorState) {

  ExpressionTree expressionTree = stripParentheses(ifTree.getCondition());

  if (expressionTree instanceof InstanceOfTree) {
    InstanceOfTree instanceOfTree = (InstanceOfTree) expressionTree;

    if (!(instanceOfTree.getExpression() instanceof IdentifierTree)) {
      return Description.NO_MATCH;
    }

    Matcher<Tree> assignmentTreeMatcher =
        new AssignmentTreeMatcher(instanceOfTree.getExpression());
    Matcher<Tree> containsAssignmentTreeMatcher = contains(assignmentTreeMatcher);

    if (containsAssignmentTreeMatcher.matches(ifTree, visitorState)) {
      return Description.NO_MATCH;
    }

    // set expression and type to look for in matcher
    Matcher<Tree> nestedInstanceOfMatcher =
        new NestedInstanceOfMatcher(instanceOfTree.getExpression(), instanceOfTree.getType());

    Matcher<Tree> containsNestedInstanceOfMatcher = contains(nestedInstanceOfMatcher);

    if (containsNestedInstanceOfMatcher.matches(ifTree.getThenStatement(), visitorState)) {
      return describeMatch(ifTree);
    }
  }

  return Description.NO_MATCH;
}
项目:error-prone    文件:InstanceOfAndCastMatchWrongType.java   
@Nullable
InstanceOfTree getRelevantTree() {
  if (notApplicable) {
    return null;
  }
  return relevantTree;
}
项目:error-prone    文件:InstanceOfAndCastMatchWrongType.java   
@Override
public Void visitInstanceOf(InstanceOfTree tree, ExpressionTree expr) {
  if (expressionsEqual(tree.getExpression(), expr)) {
    relevantTree = tree;
  }
  return super.visitInstanceOf(tree, expr);
}
项目:checker-framework    文件:CFGBuilder.java   
@Override
public Node visitInstanceOf(InstanceOfTree tree, Void p) {
    Node operand = scan(tree.getExpression(), p);
    TypeMirror refType = InternalUtils.typeOf(tree.getType());
    InstanceOfNode node = new InstanceOfNode(tree, operand, refType,
            types);
    extendWithNode(node);
    return node;
}
项目:bazel    文件:CFGBuilder.java   
@Override
public Node visitInstanceOf(InstanceOfTree tree, Void p) {
    Node operand = scan(tree.getExpression(), p);
    TypeMirror refType = InternalUtils.typeOf(tree.getType());
    InstanceOfNode node = new InstanceOfNode(tree, operand, refType, types);
    extendWithNode(node);
    return node;
}
项目:compile-testing    文件:TreeDiffer.java   
@Override
public Void visitInstanceOf(InstanceOfTree expected, Tree actual) {
  Optional<InstanceOfTree> other = checkTypeAndCast(expected, actual);
  if (!other.isPresent()) {
    addTypeMismatch(expected, actual);
    return null;
  }

  scan(expected.getExpression(), other.get().getExpression());
  scan(expected.getType(), other.get().getType());
  return null;
}
项目:incubator-netbeans    文件:DependencyCollector.java   
/**
 * instanceof adds dependency on the literal type
 */
@Override
public Object visitInstanceOf(InstanceOfTree node, Object p) {
    addDependency(node.getType());
    return super.visitInstanceOf(node, p);
}
项目:incubator-netbeans    文件:RemoveUnnecessary.java   
@Override
public Object visitInstanceOf(InstanceOfTree node, Object p) {
    return null;
}
项目:incubator-netbeans    文件:Flow.java   
public Boolean visitInstanceOf(InstanceOfTree node, ConstructorData p) {
    super.visitInstanceOf(node, p);
    return null;
}
项目:incubator-netbeans    文件:IllegalInstanceOf.java   
public List<ErrorDescription> run(CompilationInfo info, TreePath treePath) {
    if (treePath.getLeaf().getKind() != Kind.INSTANCE_OF) {
        return null;
    }

    InstanceOfTree iot = (InstanceOfTree) treePath.getLeaf();
    TypeMirror     leftTypeMirror = info.getTrees().getTypeMirror(new TreePath(treePath, iot.getExpression()));
    Element        rightType = info.getTrees().getElement(new TreePath(treePath, iot.getType()));

    if (leftTypeMirror == null || leftTypeMirror.getKind() != TypeKind.DECLARED) {
        return null;
    }

    Element leftType = ((DeclaredType) leftTypeMirror).asElement();

    if (leftType == null || rightType == null || !leftType.getKind().isInterface() || !rightType.getKind().isInterface()) {
        //no problem:
        return null;
    }

    TypeElement left = (TypeElement) leftType;
    TypeElement right = (TypeElement) rightType;

    if (   left.getEnclosingElement().getKind() != ElementKind.PACKAGE
        || right.getEnclosingElement().getKind() != ElementKind.PACKAGE) {
        return null;
    }

    PackageElement leftPackage = (PackageElement) left.getEnclosingElement();
    PackageElement rightPackage = (PackageElement) right.getEnclosingElement();

    String leftPackageFQN = leftPackage.getQualifiedName().toString();
    String rightPackageFQN = rightPackage.getQualifiedName().toString();

    if (packagesToCheck.containsKey(leftPackageFQN) && leftPackageFQN.equals(rightPackageFQN)) {
        String verifyClass = packagesToCheck.get(leftPackageFQN);
        TypeElement loadedVerify = info.getElements().getTypeElement(verifyClass);

        if (loadedVerify == null || !info.getTypes().isSubtype(left.asType(), loadedVerify.asType()))
            return null;

        if (!info.getTypes().isSubtype(right.asType(), loadedVerify.asType()))
            return null;

        int start = (int) info.getTrees().getSourcePositions().getStartPosition(info.getCompilationUnit(), iot);
        int end   = (int) info.getTrees().getSourcePositions().getEndPosition(info.getCompilationUnit(), iot);
        return Collections.<ErrorDescription>singletonList(
                   ErrorDescriptionFactory.createErrorDescription(getSeverity().toEditorSeverity(),
                                                                  NbBundle.getMessage(IllegalInstanceOf.class, "MSG_IllegalInstanceOf"),
                                                                  info.getFileObject(),
                                                                  start,
                                                                  end
                                                                 )
               );
    }

    return null;
}
项目:incubator-netbeans    文件:DeclarationForInstanceOf.java   
List<ErrorDescription> run(CompilationInfo info, TreePath treePath, int offset) {
    TreePath ifPath = treePath;

    while (ifPath != null) {
        Kind lk = ifPath.getLeaf().getKind();

        if (lk == Kind.IF) {
            break;
        }

        if (lk == Kind.METHOD || TreeUtilities.CLASS_TREE_KINDS.contains(lk)) {
            return null;
        }

        ifPath = ifPath.getParentPath();
    }

    if (ifPath == null) {
        return null;
    }

    InstanceOfTree leaf = (InstanceOfTree) treePath.getLeaf();

    if (leaf.getType() == null || leaf.getType().getKind() == Kind.ERRONEOUS) {
        return null;
    }

    TypeMirror castTo = info.getTrees().getTypeMirror(new TreePath(treePath, leaf.getType()));
    TreePath expression = new TreePath(treePath, leaf.getExpression());
    TypeMirror expressionType = info.getTrees().getTypeMirror(expression);

    if (!(Utilities.isValidType(castTo) && Utilities.isValidType(expressionType)) || !info.getTypeUtilities().isCastable(expressionType, castTo)) {
        return null;
    }

    List<Fix> fix = Collections.<Fix>singletonList(new FixImpl(info.getJavaSource(), TreePathHandle.create(ifPath, info), TreePathHandle.create(expression, info), TypeMirrorHandle.create(castTo), Utilities.getName(castTo)));
    String displayName = NbBundle.getMessage(DeclarationForInstanceOf.class, "ERR_DeclarationForInstanceof");
    ErrorDescription err = ErrorDescriptionFactory.createErrorDescription(Severity.HINT, displayName, fix, info.getFileObject(), offset, offset);

    return Collections.singletonList(err);
}
项目:incubator-netbeans    文件:ExpressionScanner.java   
@Override
public List<Tree> visitInstanceOf(InstanceOfTree node, ExpressionScanner.ExpressionsInfo p) {
    return scan(node.getExpression(), node.getType(), p);
}
项目:oblivion-netbeans-plugin    文件:ApexTreeVisitorAdapter.java   
@Override
public R visitInstanceOf(InstanceOfTree iot, P p) {
    return null;
}
项目:oblivion-netbeans-plugin    文件:TreeFinder.java   
@Override
public List<T> visitInstanceOf(InstanceOfTree node, T p) {
    return checkForCriteria(node);
}
项目:oblivion-netbeans-plugin    文件:ApexTreeFactory.java   
@Override
public InstanceOfTree createInstanceOf(ExpressionTree expression, Tree type) {
    return new InstanceOfTreeImp(expression, type);
}
项目:adalid    文件:CodeAnalyzerTreeVisitor.java   
@Override
public Object visitInstanceOf(InstanceOfTree t, Trees p) {
    info("InstanceOfTree" + CL + t.getKind() + SP + t);
    return super.visitInstanceOf(t, p);
}
项目:refactor-faster    文件:UTemplater.java   
@Override
public UInstanceOf visitInstanceOf(InstanceOfTree tree, Void v) {
  return UInstanceOf.create(template(tree.getExpression()), template(tree.getType()));
}
项目:refactor-faster    文件:UInstanceOf.java   
@Override
@Nullable
public Unifier visitInstanceOf(InstanceOfTree instanceOf, @Nullable Unifier unifier) {
  unifier = getExpression().unify(instanceOf.getExpression(), unifier);
  return getType().unify(instanceOf.getType(), unifier);
}
项目:error-prone    文件:UTemplater.java   
@Override
public UInstanceOf visitInstanceOf(InstanceOfTree tree, Void v) {
  return UInstanceOf.create(template(tree.getExpression()), templateType(tree.getType()));
}
项目:checker-framework    文件:InstanceOfNode.java   
@Override
public InstanceOfTree getTree() {
    return tree;
}
项目:checker-framework    文件:PurityChecker.java   
@Override
public PurityResult visitInstanceOf(InstanceOfTree node, PurityResult p) {
    PurityResult r = scan(node.getExpression(), p);
    return r;
}
项目:checker-framework    文件:BaseTypeVisitor.java   
@Override
public Void visitInstanceOf(InstanceOfTree node, Void p) {
    validateTypeOf(node.getType());
    return super.visitInstanceOf(node, p);
}
项目:checker-framework    文件:Locations.java   
@Override
public Void visitInstanceOf(InstanceOfTree tree, Void p) {
    if (locations)
        System.out.println("instanceof");
    return super.visitInstanceOf(tree, p);
}
项目:checker-framework    文件:ReportVisitor.java   
@Override
public Void visitInstanceOf(InstanceOfTree node, Void p) {
    // TODO Is it worth adding a separate annotation for this?
    return super.visitInstanceOf(node, p);
}
项目:checker-framework    文件:TypeFromTree.java   
@Override
public AnnotatedTypeMirror visitInstanceOf(InstanceOfTree node,
        AnnotatedTypeFactory f) {
    return f.type(node);
}
项目:Refaster    文件:UTemplater.java   
@Override
public UInstanceOf visitInstanceOf(InstanceOfTree tree, Void v) {
  return UInstanceOf.create(template(tree.getExpression()), template(tree.getType()));
}
项目:Refaster    文件:UInstanceOf.java   
@Override
@Nullable
public Unifier visitInstanceOf(InstanceOfTree instanceOf, @Nullable Unifier unifier) {
  unifier = getExpression().unify(instanceOf.getExpression(), unifier);
  return getType().unify(instanceOf.getType(), unifier);
}