DeclaredType implements InferredType { @Override public Optional<Symbol> resolveDeclaredMember(String memberName) { if (hasUnresolvedHierarchy()) { return Optional.empty(); } Set<Optional<Symbol>> resolvedMembers = alternativeTypeSymbols().stream() .filter(s -> s.is(CLASS)) .map(ClassSymbol.class::cast) .map(t -> t.resolveMember(memberName)) .filter(Optional::isPresent) .collect(Collectors.toSet()); return resolvedMembers.size() == 1 ? resolvedMembers.iterator().next() : Optional.empty(); } 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_resolveDeclaredMember() { ClassSymbolImpl typeClassX = new ClassSymbolImpl("x", "x"); SymbolImpl fooX = new SymbolImpl("foo", "x.foo"); typeClassX.addMembers(Collections.singletonList(fooX)); DeclaredType declaredTypeX = new DeclaredType(typeClassX); assertThat(declaredTypeX.resolveDeclaredMember("foo")).contains(fooX); assertThat(declaredTypeX.resolveDeclaredMember("bar")).isEmpty(); ClassSymbolImpl typeClassY = new ClassSymbolImpl("y", "y"); SymbolImpl fooY = new SymbolImpl("foo", "y.foo"); typeClassY.addMembers(Collections.singletonList(fooY)); DeclaredType declaredTypeY = new DeclaredType(typeClassY); DeclaredType union = new DeclaredType(new SymbolImpl("Union", "typing.Union"), Arrays.asList(declaredTypeX, declaredTypeY)); assertThat(union.resolveDeclaredMember("foo")).isEmpty(); assertThat(union.resolveDeclaredMember("bar")).isEmpty(); DeclaredType unresolved = new DeclaredType(new SymbolImpl("unresolved", "unresolved")); union = new DeclaredType(new SymbolImpl("Union", "typing.Union"), Arrays.asList(declaredTypeX, unresolved)); assertThat(union.resolveDeclaredMember("foo")).isEmpty(); }