com.sun.tools.javac.code.Types.isCastable()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中com.sun.tools.javac.code.Types.isCastable()方法的一些代码示例,展示了Types.isCastable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.isCastable()方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:isCastable

Types.isCastable介绍

[英]Is t is castable to s?
s is assumed to be an erased type.
(not defined for Method and ForAll types).
[中]t是可浇铸的吗?
s被假定为已擦除类型。
(未为方法和所有类型定义)。

代码示例

代码示例来源:origin: google/error-prone

/** Returns true if {@code erasure(s)} is castable to {@code erasure(t)}. */
public static boolean isCastable(Type s, Type t, VisitorState state) {
 if (s == null || t == null) {
  return false;
 }
 Types types = state.getTypes();
 return types.isCastable(types.erasure(s), types.erasure(t));
}

代码示例来源:origin: google/error-prone

@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;
 }
}

代码示例来源:origin: google/error-prone

@Override
 public Description matchMethodInvocation(
   MethodInvocationTree methodInvocationTree, VisitorState visitorState) {
  if (!TO_ARRAY_MATCHER.matches(methodInvocationTree, visitorState)) {
   return NO_MATCH;
  }
  Types types = visitorState.getTypes();
  Type variableType =
    types.elemtype(getType(getOnlyElement(methodInvocationTree.getArguments())));
  if (variableType == null) {
   return NO_MATCH;
  }

  Type collectionType =
    types.asSuper(
      ASTHelpers.getReceiverType(methodInvocationTree),
      visitorState.getSymbolFromString("java.util.Collection"));
  List<Type> typeArguments = collectionType.getTypeArguments();

  if (!typeArguments.isEmpty()
    && !types.isCastable(
      types.erasure(variableType), types.erasure(getOnlyElement(typeArguments)))) {
   return describeMatch(methodInvocationTree);
  }
  return NO_MATCH;
 }
}

代码示例来源:origin: google/error-prone

types.isCastable(
  types.erasure(ASTHelpers.getType(instanceOfTree.getType())),
  types.erasure(ASTHelpers.getType(tree)));

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public boolean isCastable(Type t, Type s) {
  return isCastable(t, s, noWarnings);
}

代码示例来源:origin: sc.fiji/javac

public boolean isCastable(Type t, Type s) {
  return isCastable(t, s, Warner.noWarnings);
}

代码示例来源:origin: konsoletyper/teavm-javac

public boolean isCastable(Type t, Type s) {
  return isCastable(t, s, noWarnings);
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

private boolean isCastableRecursive(Type t, Type s) {
  TypePair pair = new TypePair(t, s);
  if (cache.add(pair)) {
    try {
      return Types.this.isCastable(t, s);
    } finally {
      cache.remove(pair);
    }
  } else {
    return true;
  }
}

代码示例来源:origin: sc.fiji/javac

private boolean isCastableRecursive(Type t, Type s) {
  TypePair pair = new TypePair(t, s);
  if (cache.add(pair)) {
    try {
      return Types.this.isCastable(t, s);
    } finally {
      cache.remove(pair);
    }
  } else {
    return true;
  }
}

代码示例来源:origin: konsoletyper/teavm-javac

private boolean isCastableRecursive(Type t, Type s) {
  TypePair pair = new TypePair(t, s);
  if (cache.add(pair)) {
    try {
      return Types.this.isCastable(t, s);
    } finally {
      cache.remove(pair);
    }
  } else {
    return true;
  }
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

private boolean isCastableRecursive(Type t, Type s) {
  TypePair pair = new TypePair(t, s);
  if (cache.add(pair)) {
    try {
      return Types.this.isCastable(t, s);
    } finally {
      cache.remove(pair);
    }
  } else {
    return true;
  }
}

代码示例来源:origin: sc.fiji/javac

@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
  return isCastable(upperBound(t), s, warnStack.head);
}

代码示例来源:origin: konsoletyper/teavm-javac

@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
  return isCastable(wildUpperBound(t), s, warnStack.head);
}

代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac

@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
  return isCastable(upperBound(t), s, warnStack.head);
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

@Override
public Boolean visitWildcardType(WildcardType t, Type s) {
  return isCastable(upperBound(t), s, warnStack.head);
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

boolean visitIntersectionType(IntersectionClassType ict, Type s, boolean reverse) {
  Warner warn = noWarnings;
  for (Type c : ict.getComponents()) {
    warn.clear();
    if (reverse ? !isCastable(s, c, warn) : !isCastable(c, s, warn))
      return false;
  }
  if (warn.hasLint(LintCategory.UNCHECKED))
    warnStack.head.warn(LintCategory.UNCHECKED);
  return true;
}

代码示例来源:origin: konsoletyper/teavm-javac

boolean visitIntersectionType(IntersectionClassType ict, Type s, boolean reverse) {
  Warner warn = noWarnings;
  for (Type c : ict.getComponents()) {
    warn.clear();
    if (reverse ? !isCastable(s, c, warn) : !isCastable(c, s, warn))
      return false;
  }
  if (warn.hasLint(LintCategory.UNCHECKED))
    warnStack.head.warn(LintCategory.UNCHECKED);
  return true;
}

代码示例来源:origin: com.google.errorprone/error_prone_check_api

/** Returns true if {@code erasure(s)} is castable to {@code erasure(t)}. */
public static boolean isCastable(Type s, Type t, VisitorState state) {
 if (s == null || t == null) {
  return false;
 }
 Types types = state.getTypes();
 return types.isCastable(types.erasure(s), types.erasure(t));
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

Type checkCastable(DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) {
  if (types.isCastable(found, req, castWarner(pos, found, req))) {
    return req;
  } else {
    checkContext.report(pos, diags.fragment("inconvertible.types", found, req));
    return types.createErrorType(found);
  }
}

代码示例来源:origin: konsoletyper/teavm-javac

Type checkCastable(DiagnosticPosition pos, Type found, Type req, CheckContext checkContext) {
  if (types.isCastable(found, req, castWarner(pos, found, req))) {
    return req;
  } else {
    checkContext.report(pos, diags.fragment("inconvertible.types", found, req));
    return types.createErrorType(found);
  }
}

相关文章

Types类方法