static Type wildBound(Type type) { return type.hasTag(TypeTag.WILDCARD) ? ((WildcardType) type).type : type; } }
/** * Returns the upper bound of a type if it has one, or the type itself if not. Correctly handles * wildcards and capture variables. */ public static Type getUpperBound(Type type, Types types) { if (type.hasTag(TypeTag.WILDCARD)) { return types.wildUpperBound(type); } if (type.hasTag(TypeTag.TYPEVAR) && ((TypeVar) type).isCaptured()) { return types.cvarUpperBound(type); } if (type.getUpperBound() != null) { return type.getUpperBound(); } // concrete type, e.g. java.lang.String, or a case we haven't considered return type; }
/** Returns the compile-time constant value of a tree if it has one, or {@code null}. */ @Nullable public static Object constValue(Tree tree) { if (tree == null) { return null; } tree = stripParentheses(tree); Type type = ASTHelpers.getType(tree); Object value; if (tree instanceof JCLiteral) { value = ((JCLiteral) tree).value; } else if (type != null) { value = type.constValue(); } else { return null; } if (type.hasTag(TypeTag.BOOLEAN) && value instanceof Integer) { return ((Integer) value) == 1; } return value; }
private boolean containerOfSubtyping( Set<String> containerTypeParameters, AnnotationInfo annotation, TypeVariableSymbol typaram, Type tyargument) { // (1) if (!tyargument.hasTag(TypeTag.TYPEVAR)) { return false; } // (2) if (!containerTypeParameters.contains(tyargument.asElement().getSimpleName().toString()) || isTypeParameterThreadSafe( (TypeVariableSymbol) tyargument.asElement(), containerTypeParameters)) { return false; } // (3) if (annotation.containerOf().contains(typaram.getSimpleName().toString())) { return false; } return true; }
Type arg = superClass.getTypeArguments().get(i); TypeVariableSymbol formal = superClass.asElement().getTypeParameters().get(i); if (!arg.hasTag(TypeTag.TYPEVAR)) { continue;
Type returnedFutureType = state.getTypes().asSuper(returnType, futureType.tsym); if (returnedFutureType != null && !returnedFutureType.hasTag(TypeTag.ERROR) // work around error-prone#996 && !returnedFutureType.isRaw()) { if (ASTHelpers.isSubtype(
/** A class is an inner class if it it has an enclosing instance class. */ public boolean isInner() { return type.getEnclosingType().hasTag(CLASS); }
/** Construct a method symbol, given its flags, name, type and owner. */ public MethodSymbol(long flags, Name name, Type type, Symbol owner) { super(MTH, flags, name, type, owner); if (owner.type.hasTag(TYPEVAR)) Assert.error(owner + "." + name); }
@Override public boolean accepts(Type t) { return !t.isErroneous() && !inferenceContext.free(t) && !t.hasTag(BOT); } };
UnboundMethodReferenceLookupHelper(JCMemberReference referenceTree, Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, MethodResolutionPhase maxPhase) { super(referenceTree, name, site, argtypes.tail, typeargtypes, maxPhase); if (site.isRaw() && !argtypes.head.hasTag(NONE)) { Type asSuperSite = types.asSuper(argtypes.head, site.tsym); this.site = asSuperSite; } }
private Type L(Type t) { while (t.hasTag(WILDCARD)) { WildcardType w = (WildcardType)t.unannotatedType(); if (w.isExtendsBound()) return syms.botType; else t = w.type; } return t; }
@Override public boolean compatible(Type found, Type req, Warner warn) { //a void return is compatible with an expression statement lambda return TreeInfo.isExpressionStatement(expr) && req.hasTag(VOID) || super.compatible(found, req, warn); } }
/** An inner class has an outer instance if it is not an interface * it has an enclosing instance class which might be referenced from the class. * Nested classes can see instance members of their enclosing class. * Their constructors carry an additional this$n parameter, inserted * implicitly by the compiler. * * @see #isInner */ public boolean hasOuterInstance() { return type.getEnclosingType().hasTag(CLASS) && (flags() & (INTERFACE | NOOUTERTHIS)) == 0; }
/** Compute all the supertypes of t, indexed by type symbol (except thise in typesSkip). */ private void closure(Type t, Map<TypeSymbol,Type> typesSkip, Map<TypeSymbol,Type> typeMap) { if (!t.hasTag(CLASS)) return; if (typesSkip.get(t.tsym) != null) return; if (typeMap.put(t.tsym, t) == null) { closure(types.supertype(t), typesSkip, typeMap); for (Type i : types.interfaces(t)) closure(i, typesSkip, typeMap); } }
@Override public Boolean visitArrayType(ArrayType t, Type s) { if (t == s) return true; if (s.isPartial()) return visit(s, t); return s.hasTag(ARRAY) && containsTypeEquivalent(t.elemtype, elemtype(s)); }
@Override public Boolean visitType(Type t, Type s) { if (s.hasTag(WILDCARD)) return visit(s, t); else return notSoftSubtypeRecursive(t, s) || notSoftSubtypeRecursive(s, t); }
@Override public Void visitArrayType(ArrayType source, Type target) throws AdaptFailure { if (target.hasTag(ARRAY)) adaptRecursive(elemtype(source), elemtype(target)); return null; }
@Override public Boolean visitForAll(ForAll t, Type s) { if (!s.hasTag(FORALL)) return strict ? false : visitMethodType(t.asMethodType(), s); ForAll forAll = (ForAll)s; return hasSameBounds(t, forAll) && visit(t.qtype, subst(forAll.qtype, forAll.tvars, t.tvars)); }
@Override protected Type check(DiagnosticPosition pos, Type found) { if (found.hasTag(DEFERRED)) { DeferredType dt = (DeferredType)found; return dt.check(this); } else { return super.check(pos, chk.checkNonVoid(pos, types.capture(U(found.baseType())))); } }
List<Type> erasedSupertypes(Type t) { ListBuffer<Type> buf = new ListBuffer<>(); for (Type sup : closure(t)) { if (sup.hasTag(TYPEVAR)) { buf.append(sup); } else { buf.append(erasure(sup)); } } return buf.toList(); }