Create an extension point to DescriptorSerializer
Extract the existing predicate logic into it
This commit is contained in:
+8
-10
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.descriptors.serialization;
|
package org.jetbrains.jet.descriptors.serialization;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.base.Predicates;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||||
@@ -47,24 +45,24 @@ public class DescriptorSerializer {
|
|||||||
};
|
};
|
||||||
private final NameTable nameTable;
|
private final NameTable nameTable;
|
||||||
private final Interner<TypeParameterDescriptor> typeParameters;
|
private final Interner<TypeParameterDescriptor> typeParameters;
|
||||||
private final Predicate<ClassDescriptor> isSpecial;
|
private final SerializerExtension extension;
|
||||||
|
|
||||||
public DescriptorSerializer() {
|
public DescriptorSerializer() {
|
||||||
this(Predicates.<ClassDescriptor>alwaysFalse());
|
this(SerializerExtension.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DescriptorSerializer(@NotNull Predicate<ClassDescriptor> isSpecial) {
|
public DescriptorSerializer(@NotNull SerializerExtension extension) {
|
||||||
this(new NameTable(), new Interner<TypeParameterDescriptor>(), isSpecial);
|
this(new NameTable(), new Interner<TypeParameterDescriptor>(), extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DescriptorSerializer(NameTable nameTable, Interner<TypeParameterDescriptor> typeParameters, Predicate<ClassDescriptor> isSpecial) {
|
private DescriptorSerializer(NameTable nameTable, Interner<TypeParameterDescriptor> typeParameters, SerializerExtension extension) {
|
||||||
this.nameTable = nameTable;
|
this.nameTable = nameTable;
|
||||||
this.typeParameters = typeParameters;
|
this.typeParameters = typeParameters;
|
||||||
this.isSpecial = isSpecial;
|
this.extension = extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
private DescriptorSerializer createChildSerializer() {
|
private DescriptorSerializer createChildSerializer() {
|
||||||
return new DescriptorSerializer(nameTable, new Interner<TypeParameterDescriptor>(typeParameters), Predicates.<ClassDescriptor>alwaysFalse());
|
return new DescriptorSerializer(nameTable, new Interner<TypeParameterDescriptor>(typeParameters), extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -90,7 +88,7 @@ public class DescriptorSerializer {
|
|||||||
builder.addTypeParameter(local.typeParameter(typeParameterDescriptor));
|
builder.addTypeParameter(local.typeParameter(typeParameterDescriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isSpecial.apply(classDescriptor)) {
|
if (extension.hasSupertypes(classDescriptor)) {
|
||||||
// Special classes (Any, Nothing) have no supertypes
|
// Special classes (Any, Nothing) have no supertypes
|
||||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||||
builder.addSupertype(local.type(supertype));
|
builder.addSupertype(local.type(supertype));
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.descriptors.serialization;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
|
|
||||||
|
public abstract class SerializerExtension {
|
||||||
|
public static final SerializerExtension DEFAULT = new SerializerExtension() {};
|
||||||
|
|
||||||
|
public boolean hasSupertypes(@NotNull ClassDescriptor descriptor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.jetbrains.jet.generators.builtins;
|
package org.jetbrains.jet.generators.builtins;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
@@ -59,12 +58,12 @@ public class BuiltInsSerializer {
|
|||||||
System.err.println("Could not make directories: " + destDir);
|
System.err.println("Could not make directories: " + destDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
final DescriptorSerializer serializer = new DescriptorSerializer(new Predicate<ClassDescriptor>() {
|
final DescriptorSerializer serializer = new DescriptorSerializer(new SerializerExtension() {
|
||||||
private final ImmutableSet<String> set = ImmutableSet.of("Any", "Nothing");
|
private final ImmutableSet<String> set = ImmutableSet.of("Any", "Nothing");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(ClassDescriptor classDescriptor) {
|
public boolean hasSupertypes(@NotNull ClassDescriptor classDescriptor) {
|
||||||
return set.contains(classDescriptor.getName().asString());
|
return !set.contains(classDescriptor.getName().asString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ByteArrayOutputStream classNames = new ByteArrayOutputStream();
|
ByteArrayOutputStream classNames = new ByteArrayOutputStream();
|
||||||
|
|||||||
Reference in New Issue
Block a user