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

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

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

Types.isAssignable介绍

[英]Is t assignable to s?
Equivalent to subtype except for constant values and raw types.
(not defined for Method and ForAll types)
[中]t可分配给s吗?
除了常量值和原始类型之外,与子类型等效。
(未为方法和所有类型定义)

代码示例

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

private boolean isCheckedException(Type type) {
  return !state.getTypes().isAssignable(type, state.getSymtab().errorType)
    && !state.getTypes().isAssignable(type, state.getSymtab().runtimeExceptionType);
 }
}

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

private static boolean isAssignableTo(Type type, Supplier<Type> supplier, VisitorState state) {
 Type to = supplier.get(state);
 if (to == null) {
  // the type couldn't be loaded
  return false;
 }
 to = state.getTypes().erasure(to);
 return state.getTypes().isAssignable(type, to);
}

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

&& state.getTypes().isAssignable(exception.type, getLast(proposedTypes))) {
return Optional.of(
  appendArgument(constructor, exception.getSimpleName().toString(), state, types));

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

&& methodSymbol.isVarArgs()
 && p.type instanceof ArrayType
 && !state.getTypes().isAssignable(a.type, p.type)) {
return true;

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

private static Optional<Fix> linkedListFix(Tree tree, VisitorState state) {
 Type type = getTargetType(state);
 if (type == null) {
  return Optional.empty();
 }
 Types types = state.getTypes();
 for (String replacement : ImmutableList.of("java.util.ArrayList", "java.util.ArrayDeque")) {
  Symbol sym = state.getSymbolFromString(replacement);
  if (sym == null) {
   continue;
  }
  if (types.isAssignable(types.erasure(sym.asType()), types.erasure(type))) {
   SuggestedFix.Builder fix = SuggestedFix.builder();
   while (tree instanceof ParameterizedTypeTree) {
    tree = ((ParameterizedTypeTree) tree).getType();
   }
   fix.replace(tree, SuggestedFixes.qualifyType(state, fix, sym));
   return Optional.of(fix.build());
  }
 }
 return Optional.empty();
}

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

if (state.getTypes().isAssignable(availableParamType, formalParamType)) {
 reportMatch(invocation, state, actualParam, formalParamName);

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

? ImmutableList.copyOf(((UnionClassType) t).getAlternativeTypes()).stream()
          : Stream.of(t))
    .filter(t -> thrownTypes.stream().noneMatch(x -> types.isAssignable(t, x)))
    .collect(toImmutableList());
if (!toThrow.isEmpty()) {

代码示例来源:origin: uber/AutoDispose

&& !"this".equals(identifierStr)
&& returnType != null
&& state.getTypes().isAssignable(returnType, identifierType)) {

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

Type value = ASTHelpers.getUpperBound(tyargs.get(1), types);
Type arg = ASTHelpers.getType(Iterables.getOnlyElement(tree.getArguments()));
boolean valueShaped = types.isAssignable(arg, value);
boolean keyShaped = types.isAssignable(arg, key);

代码示例来源:origin: cincheo/jsweet

/**
 * Tells if the given list contains an type which is assignable from type.
 */
public static boolean containsAssignableType(Types types, List<Type> list, Type type) {
  for (Type t : list) {
    if (types.isAssignable(t, type)) {
      return true;
    }
  }
  return false;
}

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

&& !symbol.name.contentEquals("this")
&& returnType != null
&& state.getTypes().isAssignable(returnType, identifierType)) {

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

/**
 * Return true if this parameter is assignable to the target parameter. This will consider
 * subclassing, autoboxing and null.
 */
boolean isAssignableTo(Parameter target, VisitorState state) {
 if (state.getTypes().isSameType(type(), Type.noType)
   || state.getTypes().isSameType(target.type(), Type.noType)) {
  return false;
 }
 try {
  return state.getTypes().isAssignable(type(), target.type());
 } catch (CompletionFailure e) {
  // Report completion errors to avoid e.g. https://github.com/bazelbuild/bazel/issues/4105
  Check.instance(state.context)
    .completionError((DiagnosticPosition) state.getPath().getLeaf(), e);
  return false;
 }
}

代码示例来源:origin: cincheo/jsweet

/**
 * Tells if two type symbols are assignable.
 */
public static boolean isAssignable(Types types, TypeSymbol to, TypeSymbol from) {
  if (to.equals(from)) {
    return true;
  } else {
    return types.isAssignable(from.asType(), to.asType());
  }
}

代码示例来源:origin: cincheo/jsweet

overriden = true;
  for (int i = 0; i < subm.getParameters().size(); i++) {
    if (!types.isAssignable(m.getParameters().get(i).type,
        subm.getParameters().get(i).type)) {
      overriden = false;
overrides = true;
for (int i = 0; i < subm.getParameters().size(); i++) {
  if (!types.isAssignable(m.getParameters().get(i).type, subm.getParameters().get(i).type)) {
    overrides = false;

代码示例来源:origin: cincheo/jsweet

isValid = false;
for (int j = 0; j < m1.getParameters().size(); j++) {
  if (types.isAssignable(types.erasure(m1.getParameters().get(j).type),
      types.erasure(m2.getParameters().get(j).type))) {
    i--;
  if (types.isAssignable(types.erasure(m2.getParameters().get(j).type),
      types.erasure(m1.getParameters().get(j).type))) {
    i++;

代码示例来源:origin: cincheo/jsweet

/**
 * Tells if a method can be invoked with some given parameter types.
 * 
 * @param types
 *            a reference to the types in the compilation scope
 * @param from
 *            the caller method signature to test (contains the parameter types)
 * @param target
 *            the callee method signature
 * @return true if the callee can be invoked by the caller
 */
public static boolean isInvocable(Types types, MethodType from, MethodType target) {
  if (from.getParameterTypes().length() != target.getParameterTypes().length()) {
    return false;
  }
  for (int i = 0; i < from.getParameterTypes().length(); i++) {
    if (!types.isAssignable(types.erasure(from.getParameterTypes().get(i)),
        types.erasure(target.getParameterTypes().get(i)))) {
      return false;
    }
  }
  return true;
}

代码示例来源:origin: cincheo/jsweet

if (context.types.isAssignable(clazz.sym.type, context.symtab.throwableType)) {
  printIndent().print("(<any>Object).setPrototypeOf(this, " + getClassName(clazz.sym) + ".prototype);")
      .println();

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

private boolean isCheckedException(Type type) {
  return !state.getTypes().isAssignable(type, state.getSymtab().errorType)
    && !state.getTypes().isAssignable(type, state.getSymtab().runtimeExceptionType);
 }
}

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

public boolean isAssignable(TypeMirror t1, TypeMirror t2) {
validateTypeNotIn(t1, EXEC_OR_PKG);
validateTypeNotIn(t2, EXEC_OR_PKG);
return types.isAssignable((Type) t1, (Type) t2);
}

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

private static boolean isAssignableTo(Type type, Supplier<Type> supplier, VisitorState state) {
 Type to = supplier.get(state);
 if (to == null) {
  // the type couldn't be loaded
  return false;
 }
 return state.getTypes().isAssignable(type, to);
}

相关文章

Types类方法