mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[Gradle|Sync] cleanup: unified Gradle serialisation util's signatures
GitOrigin-RevId: 1011f0a0d67bbcc0b943d71939455e009876ddfb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d5f82c6433
commit
b5882a4383
@@ -135,9 +135,9 @@ public final class GradleBuildScriptClasspathSerializationService implements Ser
|
||||
if (reader.next() == null) return null;
|
||||
reader.stepIn();
|
||||
ClasspathEntryModel entryModel = new ClasspathEntryModelImpl(
|
||||
readFilesSet(reader),
|
||||
readFilesSet(reader),
|
||||
readFilesSet(reader)
|
||||
readFileSet(reader, null),
|
||||
readFileSet(reader, null),
|
||||
readFileSet(reader, null)
|
||||
);
|
||||
reader.stepOut();
|
||||
return entryModel;
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.plugins.gradle.model.AnnotationProcessingConfig;
|
||||
import org.jetbrains.plugins.gradle.model.AnnotationProcessingModel;
|
||||
import org.jetbrains.plugins.gradle.tooling.internal.AnnotationProcessingConfigImpl;
|
||||
import org.jetbrains.plugins.gradle.tooling.internal.AnnotationProcessingModelImpl;
|
||||
import org.jetbrains.plugins.gradle.tooling.serialization.internal.adapter.Supplier;
|
||||
import org.jetbrains.plugins.gradle.tooling.util.IntObjectMap;
|
||||
import org.jetbrains.plugins.gradle.tooling.util.ObjectCollector;
|
||||
|
||||
@@ -101,17 +100,7 @@ public final class AnnotationProcessingModelSerializationService implements Seri
|
||||
}
|
||||
|
||||
private static Map<String, AnnotationProcessingConfig> readConfigs(final IonReader reader, final ReadContext context) {
|
||||
return readMap(reader, new Supplier<String>() {
|
||||
@Override
|
||||
public String get() {
|
||||
return readString(reader, null);
|
||||
}
|
||||
}, new Supplier<AnnotationProcessingConfig>() {
|
||||
@Override
|
||||
public AnnotationProcessingConfig get() {
|
||||
return readConfig(reader, context);
|
||||
}
|
||||
});
|
||||
return readMap(reader, null, () -> readString(reader, null), () -> readConfig(reader, context));
|
||||
}
|
||||
|
||||
private static AnnotationProcessingConfig readConfig(final IonReader reader, final ReadContext context) {
|
||||
@@ -122,8 +111,8 @@ public final class AnnotationProcessingModelSerializationService implements Seri
|
||||
.computeIfAbsent(readInt(reader, OBJECT_ID_FIELD), new IntObjectMap.SimpleObjectFactory<AnnotationProcessingConfigImpl>() {
|
||||
@Override
|
||||
public AnnotationProcessingConfigImpl create() {
|
||||
List<String> args = readStringList(reader);
|
||||
List<File> files = readFiles(reader);
|
||||
List<String> args = readStringList(reader, null);
|
||||
List<File> files = readFileList(reader, null);
|
||||
String output = readString(reader, "output");
|
||||
boolean isTest = readBoolean(reader,"isTestSources");
|
||||
return new AnnotationProcessingConfigImpl(files, args, output, isTest);
|
||||
|
||||
@@ -469,16 +469,16 @@ public final class ExternalProjectSerializationService implements SerializationS
|
||||
DefaultGradleSourceSetModel sourceSetModel = new DefaultGradleSourceSetModel();
|
||||
sourceSetModel.setSourceCompatibility(readString(reader, "sourceCompatibility"));
|
||||
sourceSetModel.setTargetCompatibility(readString(reader, "targetCompatibility"));
|
||||
sourceSetModel.setTaskArtifacts(readFiles(reader, "taskArtifacts"));
|
||||
sourceSetModel.setTaskArtifacts(readFileList(reader, "taskArtifacts"));
|
||||
sourceSetModel.setConfigurationArtifacts(readConfigurationArtifacts(reader));
|
||||
sourceSetModel.setSourceSets(readSourceSets(reader, context));
|
||||
sourceSetModel.setAdditionalArtifacts(readFiles(reader));
|
||||
sourceSetModel.setAdditionalArtifacts(readFileList(reader, null));
|
||||
reader.stepOut();
|
||||
return sourceSetModel;
|
||||
}
|
||||
|
||||
private static @NotNull Map<String, Set<File>> readConfigurationArtifacts(IonReader reader) {
|
||||
return readMap(reader, "configurationArtifacts", () -> readString(reader, null), () -> readFilesSet(reader));
|
||||
return readMap(reader, "configurationArtifacts", () -> readString(reader, null), () -> readFileSet(reader, null));
|
||||
}
|
||||
|
||||
private static @NotNull Map<String, DefaultExternalSourceSet> readSourceSets(IonReader reader, ReadContext context) {
|
||||
@@ -504,7 +504,7 @@ public final class ExternalProjectSerializationService implements SerializationS
|
||||
sourceSet.setSourceCompatibility(readString(reader, "sourceCompatibility"));
|
||||
sourceSet.setTargetCompatibility(readString(reader, "targetCompatibility"));
|
||||
sourceSet.setPreview(readBoolean(reader, "isPreview"));
|
||||
sourceSet.setArtifacts(readFiles(reader));
|
||||
sourceSet.setArtifacts(readFileList(reader, null));
|
||||
sourceSet.setDependencies(readDependencies(reader, context));
|
||||
sourceSet.setSources(readSourceDirectorySets(reader));
|
||||
sourceSet.setJavaToolchainHome(readFile(reader, "javaToolchainHome"));
|
||||
@@ -532,8 +532,8 @@ public final class ExternalProjectSerializationService implements SerializationS
|
||||
ExternalSystemSourceType sourceType = ExternalSystemSourceType.valueOf(assertNotNull(readString(reader, "sourceType")));
|
||||
DefaultExternalSourceDirectorySet directorySet = new DefaultExternalSourceDirectorySet();
|
||||
directorySet.setName(assertNotNull(readString(reader, "name")));
|
||||
directorySet.setSrcDirs(readFilesSet(reader));
|
||||
directorySet.setGradleOutputDirs(readFiles(reader));
|
||||
directorySet.setSrcDirs(readFileSet(reader, null));
|
||||
directorySet.setGradleOutputDirs(readFileList(reader, null));
|
||||
File outputDir = readFile(reader, "outputDir");
|
||||
if (outputDir != null) {
|
||||
directorySet.setOutputDir(outputDir);
|
||||
@@ -574,8 +574,8 @@ public final class ExternalProjectSerializationService implements SerializationS
|
||||
reader.next();
|
||||
reader.stepIn();
|
||||
FilePatternSetImpl patternSet = new FilePatternSetImpl();
|
||||
patternSet.setIncludes(readStringSet(reader));
|
||||
patternSet.setExcludes(readStringSet(reader));
|
||||
patternSet.setIncludes(readStringSet(reader, null));
|
||||
patternSet.setExcludes(readStringSet(reader, null));
|
||||
reader.stepOut();
|
||||
return patternSet;
|
||||
}
|
||||
@@ -633,20 +633,20 @@ public final class ExternalProjectSerializationService implements SerializationS
|
||||
}
|
||||
else if (externalDependency instanceof DefaultExternalMultiLibraryDependency) {
|
||||
DefaultExternalMultiLibraryDependency multiLibraryDependency = (DefaultExternalMultiLibraryDependency)externalDependency;
|
||||
multiLibraryDependency.getFiles().addAll(readFiles(reader));
|
||||
multiLibraryDependency.getSources().addAll(readFiles(reader));
|
||||
multiLibraryDependency.getJavadoc().addAll(readFiles(reader));
|
||||
multiLibraryDependency.getFiles().addAll(readFileList(reader, null));
|
||||
multiLibraryDependency.getSources().addAll(readFileList(reader, null));
|
||||
multiLibraryDependency.getJavadoc().addAll(readFileList(reader, null));
|
||||
}
|
||||
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));
|
||||
projectDependency.setProjectDependencyArtifacts(readFileList(reader, null));
|
||||
projectDependency.setProjectDependencyArtifactsSources(readFileList(reader, null));
|
||||
}
|
||||
else if (externalDependency instanceof DefaultFileCollectionDependency) {
|
||||
DefaultFileCollectionDependency fileCollectionDependency = (DefaultFileCollectionDependency)externalDependency;
|
||||
fileCollectionDependency.setFiles(readFiles(reader));
|
||||
fileCollectionDependency.setFiles(readFileList(reader, null));
|
||||
fileCollectionDependency.setExcludedFromIndexing(readBoolean(reader, "excludedFromIndexing"));
|
||||
}
|
||||
else if (externalDependency instanceof DefaultUnresolvedExternalDependency) {
|
||||
|
||||
@@ -32,7 +32,7 @@ public final class ExternalTestsSerializationService implements SerializationSer
|
||||
@Override
|
||||
public byte[] write(ExternalTestsModel testsModel, Class<? extends ExternalTestsModel> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out)) {
|
||||
try (IonWriter writer = createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, testsModel);
|
||||
}
|
||||
return out.toByteArray();
|
||||
@@ -136,7 +136,7 @@ public final class ExternalTestsSerializationService implements SerializationSer
|
||||
DefaultExternalTestSourceMapping mapping = new DefaultExternalTestSourceMapping();
|
||||
mapping.setTestName(readString(reader, "testName"));
|
||||
mapping.setTestTaskPath(assertNotNull(readString(reader, "testTaskPath")));
|
||||
mapping.setSourceFolders(readStringSet(reader));
|
||||
mapping.setSourceFolders(readStringSet(reader, null));
|
||||
return mapping;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class GradleExtensionsSerializationService implements Serialization
|
||||
@Override
|
||||
public byte[] write(GradleExtensions gradleExtensions, Class<? extends GradleExtensions> modelClazz) throws IOException {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
try (IonWriter writer = ToolingStreamApiUtils.createIonWriter().build(out)) {
|
||||
try (IonWriter writer = createIonWriter().build(out)) {
|
||||
write(writer, myWriteContext, gradleExtensions);
|
||||
}
|
||||
return out.toByteArray();
|
||||
@@ -198,7 +198,7 @@ public final class GradleExtensionsSerializationService implements Serialization
|
||||
readString(reader, "description"),
|
||||
readBoolean(reader, "visible"),
|
||||
readBoolean(reader, "scriptClasspathConfiguration"),
|
||||
readStringList(reader));
|
||||
readStringList(reader, null));
|
||||
}
|
||||
});
|
||||
reader.stepOut();
|
||||
|
||||
@@ -25,51 +25,63 @@ public final class ToolingStreamApiUtils {
|
||||
.withStreamCopyOptimized(true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String readString(@NotNull IonReader reader, @Nullable String fieldName) {
|
||||
public static @Nullable String readString(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
IonType type = reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
if (type == null) return null;
|
||||
return reader.stringValue();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String readString(@NotNull IonReader reader, @Nullable String fieldName, @NotNull ConcurrentMap<String, String> stringCache) {
|
||||
public static @Nullable String readString(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName,
|
||||
@NotNull ConcurrentMap<String, String> stringCache
|
||||
) {
|
||||
String str = readString(reader, fieldName);
|
||||
if (str == null) {
|
||||
return null;
|
||||
}
|
||||
String old = stringCache.putIfAbsent(str, str);
|
||||
if (old == null) {
|
||||
return str;
|
||||
} else {
|
||||
if (old != null) {
|
||||
return old;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static int readInt(@NotNull IonReader reader, @NotNull String fieldName) {
|
||||
public static int readInt(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
return reader.intValue();
|
||||
}
|
||||
|
||||
public static long readLong(@NotNull IonReader reader, @NotNull String fieldName) {
|
||||
public static long readLong(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
return reader.longValue();
|
||||
}
|
||||
|
||||
public static boolean readBoolean(@NotNull IonReader reader, @NotNull String fieldName) {
|
||||
public static boolean readBoolean(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
return reader.booleanValue();
|
||||
}
|
||||
|
||||
public static List<File> readFiles(@NotNull IonReader reader) {
|
||||
return readFiles(reader, null);
|
||||
}
|
||||
|
||||
public static List<File> readFiles(@NotNull IonReader reader, @Nullable String fieldName) {
|
||||
public static @NotNull List<File> readFileList(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
List<File> list = new ArrayList<>();
|
||||
@@ -82,11 +94,10 @@ public final class ToolingStreamApiUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Set<File> readFilesSet(@NotNull IonReader reader) {
|
||||
return readFilesSet(reader, null);
|
||||
}
|
||||
|
||||
public static @NotNull Set<File> readFilesSet(@NotNull IonReader reader, @Nullable String fieldName) {
|
||||
public static @NotNull Set<File> readFileSet(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
Set<File> set = new HashSet<>();
|
||||
@@ -99,23 +110,21 @@ public final class ToolingStreamApiUtils {
|
||||
return set;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File readFile(@NotNull IonReader reader, @Nullable String fieldName) {
|
||||
public static @Nullable File readFile(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
String filePath = readString(reader, fieldName);
|
||||
return filePath == null ? null : new File(filePath);
|
||||
}
|
||||
|
||||
|
||||
public static <K, V> Map<K, V> readMap(@NotNull IonReader reader,
|
||||
@NotNull Supplier<? extends K> keyReader,
|
||||
@NotNull Supplier<? extends V> valueReader) {
|
||||
return readMap(reader, null, keyReader, valueReader);
|
||||
}
|
||||
|
||||
public static <K, V> Map<K, V> readMap(@NotNull IonReader reader,
|
||||
@Nullable String fieldName,
|
||||
@NotNull Supplier<? extends K> keyReader,
|
||||
@NotNull Supplier<? extends V> valueReader) {
|
||||
public static <K, V> @NotNull Map<K, V> readMap(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName,
|
||||
@NotNull Supplier<? extends K> keyReader,
|
||||
@NotNull Supplier<? extends V> valueReader
|
||||
) {
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
reader.stepIn();
|
||||
@@ -129,31 +138,48 @@ public final class ToolingStreamApiUtils {
|
||||
return map;
|
||||
}
|
||||
|
||||
public static void writeString(@NotNull IonWriter writer, @NotNull String fieldName, @Nullable String value) throws IOException {
|
||||
public static void writeString(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
@Nullable String value
|
||||
) throws IOException {
|
||||
writer.setFieldName(fieldName);
|
||||
writer.writeString(value);
|
||||
}
|
||||
|
||||
public static void writeLong(@NotNull IonWriter writer, @NotNull String fieldName, long value) throws IOException {
|
||||
public static void writeLong(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
long value
|
||||
) throws IOException {
|
||||
writer.setFieldName(fieldName);
|
||||
writer.writeInt(value);
|
||||
}
|
||||
|
||||
public static void writeBoolean(@NotNull IonWriter writer, @NotNull String fieldName, boolean value) throws IOException {
|
||||
public static void writeBoolean(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
boolean value
|
||||
) throws IOException {
|
||||
writer.setFieldName(fieldName);
|
||||
writer.writeBool(value);
|
||||
}
|
||||
|
||||
public static void writeFile(@NotNull IonWriter writer, @NotNull String fieldName, @Nullable File file) throws IOException {
|
||||
public static void writeFile(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
@Nullable File file
|
||||
) throws IOException {
|
||||
writeString(writer, fieldName, file == null ? null : file.getPath());
|
||||
}
|
||||
|
||||
public static <K, V> void writeMap(@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
@NotNull Map<K, V> map,
|
||||
@NotNull ThrowableConsumer<? super K, ? extends IOException> keyWriter,
|
||||
@NotNull ThrowableConsumer<? super V, ? extends IOException> valueWriter)
|
||||
throws IOException {
|
||||
public static <K, V> void writeMap(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
@NotNull Map<K, V> map,
|
||||
@NotNull ThrowableConsumer<? super K, ? extends IOException> keyWriter,
|
||||
@NotNull ThrowableConsumer<? super V, ? extends IOException> valueWriter
|
||||
) throws IOException {
|
||||
writer.setFieldName(fieldName);
|
||||
writer.stepIn(IonType.LIST);
|
||||
for (Map.Entry<K, V> entry : map.entrySet()) {
|
||||
@@ -167,7 +193,11 @@ public final class ToolingStreamApiUtils {
|
||||
writer.stepOut();
|
||||
}
|
||||
|
||||
public static void writeFiles(@NotNull IonWriter writer, @NotNull String fieldName, @NotNull Collection<File> files) throws IOException {
|
||||
public static void writeFiles(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
@NotNull Collection<File> files
|
||||
) throws IOException {
|
||||
writer.setFieldName(fieldName);
|
||||
writer.stepIn(IonType.LIST);
|
||||
for (File file : files) {
|
||||
@@ -176,8 +206,11 @@ public final class ToolingStreamApiUtils {
|
||||
writer.stepOut();
|
||||
}
|
||||
|
||||
public static void writeStrings(@NotNull IonWriter writer, @NotNull String fieldName, @NotNull Collection<String> strings)
|
||||
throws IOException {
|
||||
public static void writeStrings(
|
||||
@NotNull IonWriter writer,
|
||||
@NotNull String fieldName,
|
||||
@NotNull Collection<String> strings
|
||||
) throws IOException {
|
||||
writer.setFieldName(fieldName);
|
||||
writer.stepIn(IonType.LIST);
|
||||
for (String str : strings) {
|
||||
@@ -186,9 +219,13 @@ public final class ToolingStreamApiUtils {
|
||||
writer.stepOut();
|
||||
}
|
||||
|
||||
public static Set<String> readStringSet(@NotNull IonReader reader) {
|
||||
public static @NotNull Set<String> readStringSet(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
Set<String> set = new HashSet<>();
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
reader.stepIn();
|
||||
String nextString;
|
||||
while ((nextString = readString(reader, null)) != null) {
|
||||
@@ -198,9 +235,13 @@ public final class ToolingStreamApiUtils {
|
||||
return set;
|
||||
}
|
||||
|
||||
public static List<String> readStringList(@NotNull IonReader reader) {
|
||||
public static @NotNull List<String> readStringList(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
List<String> list = new ArrayList<>();
|
||||
reader.next();
|
||||
assertFieldName(reader, fieldName);
|
||||
reader.stepIn();
|
||||
String nextString;
|
||||
while ((nextString = readString(reader, null)) != null) {
|
||||
@@ -210,14 +251,16 @@ public final class ToolingStreamApiUtils {
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void assertFieldName(@NotNull IonReader reader, @Nullable String fieldName) {
|
||||
public static void assertFieldName(
|
||||
@NotNull IonReader reader,
|
||||
@Nullable String fieldName
|
||||
) {
|
||||
String readerFieldName = reader.getFieldName();
|
||||
assert fieldName == null || fieldName.equals(readerFieldName) :
|
||||
"Expected field name '" + fieldName + "', got `" + readerFieldName + "' ";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> T assertNotNull(@Nullable T t) {
|
||||
public static <T> @NotNull T assertNotNull(@Nullable T t) {
|
||||
assert t != null;
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -569,7 +569,7 @@ public final class IdeaProjectSerializationService implements SerializationServi
|
||||
contentRoot.setTestDirectories(readSourceDirectories(reader, "testDirectories"));
|
||||
contentRoot.setResourceDirectories(readSourceDirectories(reader, "resourceDirectories"));
|
||||
contentRoot.setTestResourceDirectories(readSourceDirectories(reader, "testResourceDirectories"));
|
||||
contentRoot.setExcludeDirectories(readFilesSet(reader, "excludeDirectories"));
|
||||
contentRoot.setExcludeDirectories(readFileSet(reader, "excludeDirectories"));
|
||||
reader.stepOut();
|
||||
return contentRoot;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user