private OutputFileObject getFileForOutput(Location location, JavaFileObject.Kind kind, String fileName, @Nullable String className, FileObject sibling) throws IOException {
    checkCanceled();

    Iterable<URI> originatingSources = null;
    if (sibling instanceof JavaFileObject) {
      final JavaFileObject javaFileObject = (JavaFileObject)sibling;
      if (javaFileObject.getKind() == JavaFileObject.Kind.SOURCE) {
        originatingSources = Iterators.asIterable(javaFileObject.toUri());
      }
    }
    if (originatingSources == null) {
      final Collection<String> originating = lookupOriginatingNames(className, fileName);
      if (originating != null) {
        for (String origQName : originating) {
          JavaFileObject found = lookupInputSource(origQName);
          if (found != null) {
            originatingSources = Iterators.flat(originatingSources, Iterators.asIterable(found.toUri()));
          }
        }
      }
    }

    File dir = findOutputDir(location, originatingSources);

    if (location == StandardLocation.CLASS_OUTPUT) {
      if (dir == null) {
        throw new IOException("Output directory is not specified");
      }
    }
    else if (location == StandardLocation.SOURCE_OUTPUT) {
      if (dir == null) {
        if (originatingSources != null) {
          dir = findOutputDir(StandardLocation.CLASS_OUTPUT, originatingSources);
        }
        if (dir == null) {
          throw new IOException("Neither class output directory nor source output are specified");
        }
      }
    }
    final File file = (dir == null? new File(fileName).getAbsoluteFile() : new File(dir, fileName));
    final boolean isGenerated = (sibling instanceof OutputFileObject && ((OutputFileObject)sibling).getKind() == JavaFileObject.Kind.SOURCE) /*created from generated source*/ || hasOriginatingNames(className, fileName);
    return new OutputFileObject(
      myContext, dir, fileName, file, kind, className, originatingSources == null? Collections.<URI>emptyList() : originatingSources, myEncodingName, null, location, isGenerated
    );
  }
private OutputFileObject getFileForOutput(Location location, JavaFileObject.Kind kind, String fileName, @Nullable String className, FileObject sibling)