Package com.sun.tools.javac.code

Examples of com.sun.tools.javac.code.Types$SingletonType


    super(typeToCompare);
  }

  @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)));
  }
View Full Code Here


    super(typeToCompare);
  }

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

    Fix fix = null;

    ExpressionTree leftOperand = tree.getLeftOperand();
    ExpressionTree rightOperand = tree.getRightOperand();
    Type leftType = ((JCTree) leftOperand).type;
    Types types = state.getTypes();
    Symtab symtab = state.getSymtab();

    /**
     * Try to figure out what they were trying to do.
     * Cases:
     * 1) (foo == foo) ==> (foo == other.foo)
     * 2) (foo == this.foo) ==> (other.foo == this.foo)
     * 3) (this.foo == foo) ==> (this.foo == other.foo)
     * 4) (this.foo == this.foo) ==> (this.foo == other.foo)
     */

    // Choose argument to replace.
    ExpressionTree toReplace;
    if (rightOperand.getKind() == Kind.IDENTIFIER) {
      toReplace = rightOperand;
    } else if (leftOperand.getKind() == Kind.IDENTIFIER) {
      toReplace = leftOperand;
    } else {
      // If we don't have a good reason to replace one or the other, replace the second.
      toReplace = rightOperand;
    }

    // Find containing block
    TreePath path = state.getPath();
    while (path.getLeaf() != null && path.getLeaf().getKind() != Kind.CLASS
        && path.getLeaf().getKind() != Kind.BLOCK) {
      path = path.getParentPath();
    }
    if (path.getLeaf() != null) {
      List<? extends JCTree> members;
      // Must be block or class
      if (path.getLeaf().getKind() == Kind.CLASS) {
        members = ((JCClassDecl) path.getLeaf()).getMembers();
      } else {
        members = ((JCBlock) path.getLeaf()).getStatements();
      }
      for (JCTree jcTree : members) {
        if (jcTree.getKind() == Kind.VARIABLE) {
          JCVariableDecl declaration = (JCVariableDecl) jcTree;
          TypeSymbol variableTypeSymbol = declaration.getType().type.tsym;

          if (ASTHelpers.getSymbol(toReplace).isMemberOf(variableTypeSymbol, state.getTypes())) {
            if (toReplace.getKind() == Kind.IDENTIFIER) {
              fix = SuggestedFix.prefixWith(toReplace, declaration.getName() + ".");
            } else {
              fix = SuggestedFix.replace(
                  ((JCFieldAccess) toReplace).getExpression(), declaration.getName().toString());
            }
          }
        }
      }
    }

    if (fix == null) {
      // No good replacement, let's try something else!

      // For floats or doubles, y!=y -> isNaN(y)
      if (tree.getKind() == Tree.Kind.EQUAL_TO) {
        fixedExpression.append("!");
      }
      if (types.isSameType(leftType, symtab.floatType)) {
        fixedExpression.append("Float.isNaN(" + leftOperand + ")");
        fix = SuggestedFix.replace(tree, fixedExpression.toString());
      } else if (types.isSameType(leftType, symtab.doubleType)) {
        fixedExpression.append("Double.isNaN(" + leftOperand + ")");
        fix = SuggestedFix.replace(tree, fixedExpression.toString());
      } else {

        // last resort, just replace with true or false
View Full Code Here

    super(typeToCompare);
  }

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

                    List.<Pair<Symbol.MethodSymbol, Attribute>>of(
                    new Pair<Symbol.MethodSymbol, Attribute>(profileValue, new Attribute.Constant(syms.intType, i))));
        }

        Type.moreInfo = true;
        Types types = Types.instance(task.getContext());
        Pool pool = new Pool(types);
        for (JavaFileObject file : fm.list(jarLocation, "", EnumSet.of(CLASS), true)) {
            String className = fm.inferBinaryName(jarLocation, file);
            int index = className.lastIndexOf('.');
            String pckName = index == -1 ? "" : className.substring(0, index);
View Full Code Here

   */
  public static TypeMirror leastUpperBound(ProcessingEnvironment processingEnv, TypeMirror tm1, TypeMirror tm2) {
    Type t1 = (Type) tm1;
    Type t2 = (Type) tm2;
    JavacProcessingEnvironment javacEnv = (JavacProcessingEnvironment) processingEnv;
    Types types = Types.instance(javacEnv.getContext());
    if (types.isSameType(t1, t2)) {
      // Special case if the two types are equal.
      return t1;
    }
    // Handle the 'null' type manually (not done by types.lub).
    if (t1.getKind() == TypeKind.NULL) {
      return t2;
    }
    if (t2.getKind() == TypeKind.NULL) {
      return t1;
    }
    // Special case for primitives.
    if (TypesUtils.isPrimitive(t1) || TypesUtils.isPrimitive(t2)) {
      if (types.isAssignable(t1, t2)) {
        return t2;
      } else if (types.isAssignable(t2, t1)) {
        return t1;
      } else {
        return processingEnv.getTypeUtils().getNoType(TypeKind.NONE);
      }
    }
    if (t1.getKind() == TypeKind.WILDCARD) {
      WildcardType wc1 = (WildcardType) t1;
      Type bound = (Type) wc1.getExtendsBound();
      if (bound == null) {
        // Implicit upper bound of java.lang.Object
        Elements elements = processingEnv.getElementUtils();
        return elements.getTypeElement("java.lang.Object").asType();
      }
      t1 = bound;
    }
    if (t2.getKind() == TypeKind.WILDCARD) {
      WildcardType wc2 = (WildcardType) t2;
      Type bound = (Type) wc2.getExtendsBound();
      if (bound == null) {
        // Implicit upper bound of java.lang.Object
        Elements elements = processingEnv.getElementUtils();
        return elements.getTypeElement("java.lang.Object").asType();
      }
      t2 = bound;
    }
    return types.lub(t1, t2);
  }
View Full Code Here

   */
  public static TypeMirror greatestLowerBound(ProcessingEnvironment processingEnv, TypeMirror tm1, TypeMirror tm2) {
    Type t1 = (Type) tm1;
    Type t2 = (Type) tm2;
    JavacProcessingEnvironment javacEnv = (JavacProcessingEnvironment) processingEnv;
    Types types = Types.instance(javacEnv.getContext());
    if (types.isSameType(t1, t2)) {
      // Special case if the two types are equal.
      return t1;
    }
    // Handle the 'null' type manually.
    if (t1.getKind() == TypeKind.NULL) {
      return t1;
    }
    if (t2.getKind() == TypeKind.NULL) {
      return t2;
    }
    // Special case for primitives.
    if (TypesUtils.isPrimitive(t1) || TypesUtils.isPrimitive(t2)) {
      if (types.isAssignable(t1, t2)) {
        return t1;
      } else if (types.isAssignable(t2, t1)) {
        return t2;
      } else {
        // Javac types.glb returns TypeKind.Error when the GLB does
        // not exist, but we can't create one. Use TypeKind.NONE
        // instead.
        return processingEnv.getTypeUtils().getNoType(TypeKind.NONE);
      }
    }
    if (t1.getKind() == TypeKind.WILDCARD) {
      return t2;
    }
    if (t2.getKind() == TypeKind.WILDCARD) {
      return t1;
    }
    return types.glb(t1, t2);
  }
View Full Code Here

TOP

Related Classes of com.sun.tools.javac.code.Types$SingletonType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.