code: public static Type resolve(Type type, Type declaringType, EntityType context) {
          Type resolved = unwrap(type);
  
          String varName = getVarName(resolved);
          if (varName != null) {
              resolved = resolveVar(resolved, varName, declaringType, context);
          } else if (!resolved.getParameters().isEmpty()) {
              resolved = resolveWithParameters(resolved, declaringType, context);
          }
  
          // rewrap entity type
          if (type instanceof EntityType) {
              if (!unwrap(type).equals(resolved)) {
                  resolved = new EntityType(resolved, ((EntityType) type).getSuperTypes());
              } else {
                  // reset to original type
                  resolved = type;
              }
          }
  
          return resolved;
      }
docs: Resolve type declared in declaringType for context
  
  @param type type to be resolved
  @param declaringType declaration context of type
  @param context target context of type
  @return resolved type