Tabnine Logo
Types.asSuper
Code IndexAdd Tabnine to your IDE (free)

How to use
asSuper
method
in
com.sun.tools.javac.code.Types

Best Java code snippets using com.sun.tools.javac.code.Types.asSuper (Showing top 20 results out of 315)

origin: google/error-prone

private static List<Type> typeArgsAsSuper(Type baseType, Type superType, VisitorState state) {
 Type projectedType = state.getTypes().asSuper(baseType, superType.tsym);
 if (projectedType != null) {
  return projectedType.getTypeArguments();
 }
 return new ArrayList<>();
}
origin: google/error-prone

private static Type predicateType(Type type, VisitorState state) {
 Symbol predicate = state.getSymbolFromString(java.util.function.Predicate.class.getName());
 if (predicate == null) {
  return null;
 }
 Type asPredicate = state.getTypes().asSuper(type, predicate);
 if (asPredicate == null) {
  return null;
 }
 return getOnlyElement(asPredicate.getTypeArguments(), null);
}
origin: google/error-prone

 /**
  * Extracts the appropriate type argument from a specific supertype of the given {@code type}.
  * This handles the case when a subtype has different type arguments than the expected type. For
  * example, {@code ClassToInstanceMap<T>} implements {@code Map<Class<? extends T>, T>}.
  *
  * @param type the (sub)type from which to extract the type argument
  * @param superTypeSym the symbol of the supertype on which the type parameter is defined
  * @param typeArgIndex the index of the type argument to extract from the supertype
  * @param types the {@link Types} utility class from the {@link VisitorState}
  * @return the type argument, if defined, or null otherwise
  */
 @Nullable
 protected static final Type extractTypeArgAsMemberOfSupertype(
   Type type, Symbol superTypeSym, int typeArgIndex, Types types) {
  Type collectionType = types.asSuper(type, superTypeSym);
  if (collectionType == null) {
   return null;
  }
  com.sun.tools.javac.util.List<Type> tyargs = collectionType.getTypeArguments();
  if (tyargs.size() <= typeArgIndex) {
   // Collection is raw, nothing we can do.
   return null;
  }

  return tyargs.get(typeArgIndex);
 }
}
origin: google/error-prone

 private static boolean isVariableClassCreator(
   VariableTree variableTree,
   VisitorState state,
   ClassType classType,
   Symbol parcelableCreatorSymbol) {
  Tree typeTree = variableTree.getType();
  Type type = ASTHelpers.getType(typeTree);
  Types types = state.getTypes();
  Type superType = types.asSuper(type, parcelableCreatorSymbol);
  if (superType == null) {
   return false;
  }
  List<Type> typeArguments = superType.getTypeArguments();
  if (typeArguments.isEmpty()) {
   // raw creator
   return true;
  }
  return ASTHelpers.isSubtype(classType, Iterables.getOnlyElement(typeArguments), state);
 }
}
origin: google/error-prone

 private static Type getComparableTypeArgument(ClassTree tree, VisitorState state) {
  final Type comparable =
    state
      .getTypes()
      .asSuper(ASTHelpers.getType(tree), state.getSymtab().comparableType.asElement());

  if (comparable != null && !comparable.getTypeArguments().isEmpty()) {
   return Iterables.getOnlyElement(comparable.getTypeArguments());
  }

  return null;
 }
}
origin: google/error-prone

 @Override
 public boolean matches(Tree tree, VisitorState state) {
  Symbol sym = state.getSymbolFromString(clazz);
  if (sym == null) {
   return false;
  }
  Type type = ASTHelpers.getType(tree);
  if (!ASTHelpers.isSubtype(type, sym.type, state)) {
   return false;
  }
  Types types = state.getTypes();
  Type superType = types.asSuper(type, sym);
  if (superType == null) {
   return false;
  }
  List<Type> typeArguments = superType.getTypeArguments();
  if (typeArguments.isEmpty()) {
   return false;
  }
  return ASTHelpers.isSameType(
    typeArguments.get(typeArgumentIndex), state.getTypeFromString(URL_CLASS), state);
 }
}
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

 /** Ignore some common ThreadLocal type arguments that are fine to have per-instance copies of. */
 private boolean wellKnownTypeArgument(NewClassTree tree, VisitorState state) {
  Type type = getType(tree);
  if (type == null) {
   return false;
  }
  type = state.getTypes().asSuper(type, state.getSymbolFromString("java.lang.ThreadLocal"));
  if (type == null) {
   return false;
  }
  if (type.getTypeArguments().isEmpty()) {
   return false;
  }
  Type argType = getOnlyElement(type.getTypeArguments());
  if (WELL_KNOWN_TYPES.contains(argType.asElement().getQualifiedName().toString())) {
   return true;
  }
  if (isSubtype(argType, state.getTypeFromString("java.text.DateFormat"), state)) {
   return true;
  }
  return false;
 }
}
origin: google/error-prone

} else if (isSubtype(type, state.getTypeFromString("org.hamcrest.Matcher"), state)) {
 Type matcherType =
   state.getTypes().asSuper(type, state.getSymbolFromString("org.hamcrest.Matcher"));
 if (!matcherType.getTypeArguments().isEmpty()) {
  Type matchType = getOnlyElement(matcherType.getTypeArguments());
origin: google/error-prone

Type returnedFutureType = state.getTypes().asSuper(returnType, futureType.tsym);
if (returnedFutureType != null
origin: google/error-prone

 return NO_MATCH;
Type classType = state.getTypes().asSuper(type, state.getSymtab().classType.asElement());
if (classType == null || classType.getTypeArguments().isEmpty()) {
 return NO_MATCH;
origin: google/error-prone

  ASTHelpers.getType(Iterables.getOnlyElement(methodInvocation.getArguments()));
Symbol extension = state.getSymbolFromString("com.google.protobuf.ExtensionLite");
Type genericsArgument = state.getTypes().asSuper(argumentType, extension);
origin: org.kohsuke.sorcerer/sorcerer-javac

@Override
public Type visitTypeVar(TypeVar t, Symbol sym) {
  if (t.tsym == sym)
    return t;
  else
    return asSuper(t.bound, sym);
}
origin: org.kohsuke.sorcerer/sorcerer-javac

/** does this functional expression require serialization support? */
boolean isSerializable() {
  for (Type target : tree.targets) {
    if (types.asSuper(target, syms.serializableType.tsym) != null) {
      return true;
    }
  }
  return false;
}
origin: com.google.errorprone/error_prone_core

private static List<Type> typeArgsAsSuper(Type baseType, Type superType, VisitorState state) {
 Type projectedType = state.getTypes().asSuper(baseType, superType.tsym);
 if (projectedType != null) {
  return projectedType.getTypeArguments();
 }
 return new ArrayList<>();
}
origin: com.google.errorprone/error_prone_core

private static Type predicateType(Type type, VisitorState state) {
 Symbol predicate = state.getSymbolFromString(java.util.function.Predicate.class.getName());
 if (predicate == null) {
  return null;
 }
 Type asPredicate = state.getTypes().asSuper(type, predicate);
 if (asPredicate == null) {
  return null;
 }
 return getOnlyElement(asPredicate.getTypeArguments(), null);
}
origin: org.kohsuke.sorcerer/sorcerer-javac

private JCStatement makeResourceCloseInvocation(JCExpression resource) {
  // convert to AutoCloseable if needed
  if (types.asSuper(resource.type, syms.autoCloseableType.tsym) == null) {
    resource = (JCExpression) convert(resource, syms.autoCloseableType);
  }
  // create resource.close() method invocation
  JCExpression resourceClose = makeCall(resource,
                     names.close,
                     List.<JCExpression>nil());
  return make.Exec(resourceClose);
}
origin: com.google.errorprone/error_prone_core

 private static Type getComparableTypeArgument(ClassTree tree, VisitorState state) {
  final Type comparable =
    state
      .getTypes()
      .asSuper(ASTHelpers.getType(tree), state.getSymtab().comparableType.asElement());

  if (comparable != null && !comparable.getTypeArguments().isEmpty()) {
   return Iterables.getOnlyElement(comparable.getTypeArguments());
  }

  return null;
 }
}
origin: org.jvnet.sorcerer/sorcerer-javac

public void visitTypeCast(JCTypeCast tree) {
result = genExpr(tree.expr, tree.clazz.type).load();
// Additional code is only needed if we cast to a reference type
// which is not statically a supertype of the expression's type.
// For basic types, the coerce(...) in genExpr(...) will do
// the conversion.
if (tree.clazz.type.tag > lastBaseTag &&
  types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) {
  code.emitop2(checkcast, makeRef(tree.pos(), tree.clazz.type));
}
}
origin: org.kohsuke.sorcerer/sorcerer-javac

public void visitTypeCast(JCTypeCast tree) {
  setTypeAnnotationPositions(tree.pos);
  result = genExpr(tree.expr, tree.clazz.type).load();
  // Additional code is only needed if we cast to a reference type
  // which is not statically a supertype of the expression's type.
  // For basic types, the coerce(...) in genExpr(...) will do
  // the conversion.
  if (!tree.clazz.type.isPrimitive() &&
    types.asSuper(tree.expr.type, tree.clazz.type.tsym) == null) {
    code.emitop2(checkcast, makeRef(tree.pos(), tree.clazz.type));
  }
}
com.sun.tools.javac.codeTypesasSuper

Javadoc

Return the (most specific) base type of t that starts with the given symbol. If none exists, return null.

Popular methods of Types

  • instance
  • erasure
  • isAssignable
    Is t assignable to s? Equivalent to subtype except for constant values and raw types. (not defined f
  • isSameType
  • isSubtype
  • closure
    Returns the closure of a class or interface type.
  • isArray
  • isCastable
    Is t is castable to s? s is assumed to be an erased type. (not defined for Method and ForAll types).
  • supertype
  • elemtype
    The element type of an array.
  • findDescriptorSymbol
    Find the method descriptor associated to this class symbol - if the symbol 'origin' is not a functio
  • findDescriptorType
    Find the type of the method descriptor associated to this class symbol - if the symbol 'origin' is n
  • findDescriptorSymbol,
  • findDescriptorType,
  • interfaces,
  • lub,
  • subst,
  • boxedClass,
  • containsTypeEquivalent,
  • getBounds,
  • isConvertible

Popular in Java

  • Running tasks concurrently on multiple threads
  • setContentView (Activity)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • scheduleAtFixedRate (Timer)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • BufferedReader (java.io)
    Wraps an existing Reader and buffers the input. Expensive interaction with the underlying reader is
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • JButton (javax.swing)
  • JTable (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now