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

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

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

Types.erasure介绍

[英]The erasure of t |t| -- the type that results when all type parameters in t are deleted.
[中]t | t |的擦除——删除t中的所有类型参数时产生的类型。

代码示例

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

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

代码示例来源: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

/** Returns true if {@code erasure(s) <: erasure(t)}. */
public static boolean isSubtype(Type s, Type t, VisitorState state) {
 if (s == null || t == null) {
  return false;
 }
 if (SUBTYPE_UNDEFINED.contains(s.getTag()) || SUBTYPE_UNDEFINED.contains(t.getTag())) {
  return false;
 }
 Types types = state.getTypes();
 return types.isSubtype(types.erasure(s), types.erasure(t));
}

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

/** Returns the binary names of the class. */
public static String classDescriptor(Type type, Types types) {
 SigGen sig = new SigGen(types);
 sig.assembleClassSig(types.erasure(type));
 return sig.toString();
}

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

/** Returns a JVMS 4.3.3 method descriptor. */
public static String descriptor(Type type, Types types) {
 SigGen sig = new SigGen(types);
 sig.assembleSig(types.erasure(type));
 return sig.toString();
}

代码示例来源: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

ImmutableList.Builder<Type> calleeFormatArgTypesBuilder = ImmutableList.builder();
for (ExpressionTree formatArgExpression : args) {
 calleeFormatArgTypesBuilder.add(types.erasure(((JCExpression) formatArgExpression).type));

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

@Override
public Choice<Unifier> visitForAll(ForAll target, Unifier unifier) {
 Types types = unifier.types();
 try {
  Type myType = inline(new Inliner(unifier.getContext(), Bindings.create()));
  return Choice.condition(
    types.overrideEquivalent(types.erasure(myType), types.erasure(target)), unifier);
 } catch (CouldNotResolveImportException e) {
  return Choice.none();
 }
}

代码示例来源: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

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

/**
 * Recognize a small set of known-immutable types that are safe for DCL even without a volatile
 * field.
 */
private static boolean isImmutable(Type type, VisitorState state) {
 switch (type.getKind()) {
  case BOOLEAN:
  case BYTE:
  case SHORT:
  case INT:
  case CHAR:
  case FLOAT:
   return true;
  case LONG:
  case DOUBLE:
   // double-width primitives aren't written atomically
   return true;
  default:
   break;
 }
 return IMMUTABLE_WHITELIST.contains(
   state.getTypes().erasure(type).tsym.getQualifiedName().toString());
}

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

Type unboxedType = types.unboxedTypeOrType(types.erasure(type));
if (unboxedType.isPrimitive()) {
 type = unboxedType;

代码示例来源: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

@Override
 public boolean matches(ExpressionTree expressionTree, VisitorState state) {
  Symbol sym = ASTHelpers.getSymbol(expressionTree);
  if (sym == null) {
   return false;
  }
  if (!(sym instanceof MethodSymbol)) {
   throw new IllegalArgumentException(
     "DescendantOf matcher expects a method call but found "
       + sym.getClass()
       + ". Expression: "
       + expressionTree);
  }
  if (sym.isStatic()) {
   return false;
  }

  if (methodName.equals(sym.toString())) {
   Type accessedReferenceType = sym.owner.type;
   Type collectionType = state.getTypeFromString(fullClassName);
   if (collectionType != null) {
    return state
      .getTypes()
      .isSubtype(accessedReferenceType, state.getTypes().erasure(collectionType));
   }
  }

  return false;
 }
}

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

boolean isKnownCheckedException(VisitorState state, Type type) {
  Types types = state.getTypes();
  Symtab symtab = state.getSymtab();
  // Check erasure for generics.
  type = types.erasure(type);
  return
  // Has to be some Exception: A variable of type Throwable might be an Error.
  types.isSubtype(type, symtab.exceptionType)
    // Has to be some subtype: A variable of type Exception might be a RuntimeException.
    && !types.isSameType(type, symtab.exceptionType)
    // Can't be of type RuntimeException.
    && !types.isSubtype(type, symtab.runtimeExceptionType);
 }
};

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

return Description.NO_MATCH;
Type instantiatedReturnType = types.erasure(call.meth.type.getReturnType());
if (instantiatedReturnType == null) {
 return Description.NO_MATCH;
 return Description.NO_MATCH;
Type uninstantiatedReturnType = types.erasure(methodSym.type.getReturnType());
if (uninstantiatedReturnType == null) {
 return Description.NO_MATCH;

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

Type canonicalType = types.erasure(importedType.asType());
if (canonicalType == null) {
 return null;
 Type owner = types.erasure(member.owner.type);
 if (canonicalOwner == null || types.isSubtype(owner, canonicalOwner)) {
  canonicalOwner = owner;

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

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

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

JCVariableDecl declaration = (JCVariableDecl) jcTree;
TypeSymbol variableTypeSymbol =
  state.getTypes().erasure(ASTHelpers.getType(declaration)).tsym;

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

Type erasedType = types.erasure(typeCastTreeType);
if (ASTHelpers.isSameType(erasedType, state.getSymtab().objectType, state)) {

相关文章

Types类方法