/*
 * Copyright 2013 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.errorprone.matchers;

import com.google.errorprone.VisitorState;
import com.google.errorprone.suppliers.Supplier;
import com.sun.source.tree.Tree;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.tree.JCTree;

/**
 * @author eaftan@google.com (Eddie Aftandilian)
 */
public class IsSubtypeOf<T extends Tree> extends AbstractTypeMatcher<T> {

  public IsSubtypeOf(Supplier<Type> typeToCompareSupplier) {
    super(typeToCompareSupplier);
  }

  public IsSubtypeOf(String typeString) {
    super(typeString);
  }

  @Override
  public boolean matches(T tree, VisitorState state) {
    Types types = state.getTypes();
    Type typeToCompare = typeToCompareSupplier.get(state);
    return (typeToCompare != null &&
        types.isSubtype(((JCTree) tree).type, types.erasure(typeToCompare)));
  }
}

@@ -650,32 +650,39 @@
 tchers;%0A%0Aimport 
+static 
 com.google.error
@@ -687,27 +687,38 @@
 orprone.
-VisitorStat
+util.ASTHelpers.getTyp
 e;%0Aimpor
@@ -715,24 +715,31 @@
 ype;%0Aimport 
+static 
 com.google.e
@@ -752,136 +752,159 @@
 one.
-suppliers.Supplier;%0Aimport com.sun.source.tree.Tree;%0Aimport com.sun.tools.javac.code.Type;%0Aimport com.sun.tools.javac.code.Types
+util.ASTHelpers.isSubtype;%0A%0Aimport com.google.errorprone.VisitorState;%0Aimport com.google.errorprone.suppliers.Supplier;%0Aimport com.sun.source.tree.Tree
 ;%0Aim
@@ -932,28 +932,23 @@
 vac.
-tree.JCTre
+code.Typ
 e;%0A%0A/**
-%0A *
  @au
@@ -989,17 +989,16 @@
 ndilian)
-%0A
  */%0Apubl
@@ -1313,211 +1313,79 @@
     
-Types types = state.getTypes();%0A    Type typeToCompare = typeToCompareSupplier.get(state);%0A    return (typeToCompare != null &&%0A        types.isSubtype(((JCTree) tree).type, types.erasure(typeToCompare))
+return isSubtype(getType(tree), typeToCompareSupplier.get(state), state
 );%0A 

Handle nulls in IsSubtypeOf