ExternalDependency (final IonReader reader, final ReadContext context) { if (reader.next() == null) return null; reader.stepIn(); ExternalDependency dependency = context.getDependenciesMap().computeIfAbsent(readInt(reader, OBJECT_ID_FIELD), new ObjectFactory<AbstractExternalDependency>() { @Override public AbstractExternalDependency newInstance() { String type = readString(reader, "_type"); if (ExternalLibraryDependency.class.getSimpleName().equals(type)) { return new DefaultExternalLibraryDependency(); } else if (ExternalMultiLibraryDependency.class.getSimpleName().equals(type)) { return new DefaultExternalMultiLibraryDependency(); } else if (ExternalProjectDependency.class.getSimpleName().equals(type)) { return new DefaultExternalProjectDependency(); } else if (FileCollectionDependency.class.getSimpleName().equals(type)) { return new DefaultFileCollectionDependency(); } else if (UnresolvedExternalDependency.class.getSimpleName().equals(type)) { return new DefaultUnresolvedExternalDependency(); } else { throw new RuntimeException("Unsupported dependency"); } } @Override public void fill(AbstractExternalDependency externalDependency) { readDependencyCommonFields(reader, context, externalDependency); if (externalDependency instanceof DefaultExternalLibraryDependency) { DefaultExternalLibraryDependency libraryDependency = (DefaultExternalLibraryDependency)externalDependency; libraryDependency.setFile(readFile(reader, "file")); libraryDependency.setSource(readFile(reader, "source")); libraryDependency.setJavadoc(readFile(reader, "javadoc")); } else if (externalDependency instanceof DefaultExternalMultiLibraryDependency) { DefaultExternalMultiLibraryDependency multiLibraryDependency = (DefaultExternalMultiLibraryDependency)externalDependency; multiLibraryDependency.getFiles().addAll(readFiles(reader)); multiLibraryDependency.getSources().addAll(readFiles(reader)); multiLibraryDependency.getJavadoc().addAll(readFiles(reader)); } else if (externalDependency instanceof DefaultExternalProjectDependency) { DefaultExternalProjectDependency projectDependency = (DefaultExternalProjectDependency)externalDependency; projectDependency.setProjectPath(readString(reader, "projectPath")); projectDependency.setConfigurationName(readString(reader, "configurationName")); projectDependency.setProjectDependencyArtifacts(readFiles(reader)); projectDependency.setProjectDependencyArtifactsSources(readFiles(reader)); } else if (externalDependency instanceof DefaultFileCollectionDependency) { DefaultFileCollectionDependency fileCollectionDependency = (DefaultFileCollectionDependency)externalDependency; fileCollectionDependency.setFiles(readFiles(reader)); fileCollectionDependency.setExcludedFromIndexing(readBoolean(reader, "excludedFromIndexing")); } else if (externalDependency instanceof DefaultUnresolvedExternalDependency) { DefaultUnresolvedExternalDependency unresolvedExternalDependency = (DefaultUnresolvedExternalDependency)externalDependency; unresolvedExternalDependency.setFailureMessage(readString(reader, "failureMessage")); } else { throw new RuntimeException("Unsupported dependency type: " + externalDependency.getClass().getName()); } } }); reader.stepOut(); return dependency; }