DeclaredType implements InferredType { @Override public boolean mustBeOrExtend(String typeName) { return alternativeTypeSymbols().stream().flatMap(a -> { if (a.is(Symbol.Kind.AMBIGUOUS)) { return ((AmbiguousSymbol) a).alternatives().stream().filter(alternative -> alternative.is(CLASS)); } return Stream.of(a); }).filter(a -> a.is(CLASS)).allMatch(a -> ((ClassSymbol) a).isOrExtends(typeName)); } DeclaredType(Symbol typeClass, List<DeclaredType> typeArgs);   DeclaredType(Symbol typeClass); @Override boolean canHaveMember(String memberName); @Override boolean declaresMember(String memberName); @Override boolean isIdentityComparableWith(InferredType other); @Override Optional<Symbol> resolveMember(String memberName); @Override Optional<Symbol> resolveDeclaredMember(String memberName); @Override boolean canBeOrExtend(String typeName); @Override boolean canOnlyBe(String typeName); @Override boolean isCompatibleWith(InferredType other); @Override boolean mustBeOrExtend(String typeName); @Override String toString(); String typeName(); Set<Symbol> alternativeTypeSymbols(); @Override boolean equals(Object o); @Override int hashCode(); static InferredType fromInferredType(InferredType inferredType);  }
@Test public void test_mustBeOrExtend() { ClassSymbolImpl x1 = new ClassSymbolImpl("x1", "x1"); ClassSymbolImpl x2 = new ClassSymbolImpl("x2", "x2"); x2.addSuperClass(x1); DeclaredType typeX1 = new DeclaredType(x1); DeclaredType typeX2 = new DeclaredType(x2); assertThat(typeX1.mustBeOrExtend("x1")).isTrue(); assertThat(typeX1.mustBeOrExtend("x2")).isFalse(); assertThat(typeX2.mustBeOrExtend("x1")).isTrue(); assertThat(typeX2.mustBeOrExtend("x2")).isTrue(); ClassSymbolImpl otherX1 = new ClassSymbolImpl("x1", "x1"); Set<Symbol> symbols = new HashSet<>(Arrays.asList(x1, otherX1)); AmbiguousSymbol ambiguousSymbol = new AmbiguousSymbolImpl("x1", "x1", symbols); DeclaredType typeAmbiguousX1 = new DeclaredType(ambiguousSymbol); assertThat(typeAmbiguousX1.mustBeOrExtend("x1")).isTrue(); assertThat(typeAmbiguousX1.mustBeOrExtend("other")).isFalse(); DeclaredType declaredType = new DeclaredType(new SymbolImpl("C", "foo.C")); assertThat(declaredType.mustBeOrExtend("other")).isTrue(); assertThat(declaredType.mustBeOrExtend("foo.C")).isTrue(); assertThat(declaredType.mustBeOrExtend("C")).isTrue(); }