Got rid of DescriptorRendererBuilder providing new scheme for creating DescriptorRenderer's
This commit is contained in:
Generated
+1
@@ -9,6 +9,7 @@
|
|||||||
<w>pparent</w>
|
<w>pparent</w>
|
||||||
<w>processings</w>
|
<w>processings</w>
|
||||||
<w>rbracket</w>
|
<w>rbracket</w>
|
||||||
|
<w>renderers</w>
|
||||||
<w>rparenth</w>
|
<w>rparenth</w>
|
||||||
<w>selectioner</w>
|
<w>selectioner</w>
|
||||||
<w>unpluralize</w>
|
<w>unpluralize</w>
|
||||||
|
|||||||
+15
-6
@@ -16,13 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.jvm.compiler;
|
package org.jetbrains.kotlin.jvm.compiler;
|
||||||
|
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
||||||
@@ -43,11 +45,18 @@ public abstract class AbstractCompileJavaAgainstKotlinTest extends TestCaseWithT
|
|||||||
// Do not render parameter names because there are test cases where classes inherit from JDK collections,
|
// Do not render parameter names because there are test cases where classes inherit from JDK collections,
|
||||||
// and some versions of JDK have debug information in the class files (including parameter names), and some don't
|
// and some versions of JDK have debug information in the class files (including parameter names), and some don't
|
||||||
public static final RecursiveDescriptorComparator.Configuration CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.withRenderer(
|
public static final RecursiveDescriptorComparator.Configuration CONFIGURATION = DONT_INCLUDE_METHODS_OF_OBJECT.withRenderer(
|
||||||
new DescriptorRendererBuilder()
|
DescriptorRenderer.Companion.withOptions(
|
||||||
.setWithDefinedIn(false)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setParameterNameRenderingPolicy(DescriptorRenderer.ParameterNameRenderingPolicy.NONE)
|
@Override
|
||||||
.setVerbose(true)
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.build());
|
options.setWithDefinedIn(false);
|
||||||
|
options.setParameterNameRenderingPolicy(DescriptorRenderer.ParameterNameRenderingPolicy.NONE);
|
||||||
|
options.setVerbose(true);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
protected void doTest(String ktFilePath) throws IOException {
|
protected void doTest(String ktFilePath) throws IOException {
|
||||||
Assert.assertTrue(ktFilePath.endsWith(".kt"));
|
Assert.assertTrue(ktFilePath.endsWith(".kt"));
|
||||||
|
|||||||
+15
-15
@@ -31,7 +31,6 @@ import org.jetbrains.kotlin.load.kotlin.reflect.ReflectKotlinClass
|
|||||||
import org.jetbrains.kotlin.load.kotlin.reflect.RuntimeModuleData
|
import org.jetbrains.kotlin.load.kotlin.reflect.RuntimeModuleData
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.scopes.*
|
import org.jetbrains.kotlin.resolve.scopes.*
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies
|
||||||
@@ -44,24 +43,25 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
|||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.net.URLClassLoader
|
import java.net.URLClassLoader
|
||||||
|
import java.util.*
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||||
companion object {
|
companion object {
|
||||||
private val renderer = DescriptorRendererBuilder()
|
private val renderer = DescriptorRenderer.withOptions {
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setExcludedAnnotationClasses(listOf(
|
excludedAnnotationClasses = (listOf(
|
||||||
ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME,
|
ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME,
|
||||||
// TODO: add these annotations when they are retained at runtime
|
// TODO: add these annotations when they are retained at runtime
|
||||||
"kotlin.deprecated",
|
"kotlin.deprecated",
|
||||||
"kotlin.data",
|
"kotlin.data",
|
||||||
"kotlin.inline"
|
"kotlin.inline"
|
||||||
).map { FqName(it) } + JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES)
|
).map { FqName(it) } + JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES).toSet()
|
||||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE)
|
overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE
|
||||||
.setParameterNameRenderingPolicy(DescriptorRenderer.ParameterNameRenderingPolicy.NONE)
|
parameterNameRenderingPolicy = DescriptorRenderer.ParameterNameRenderingPolicy.NONE
|
||||||
.setIncludePropertyConstant(false)
|
includePropertyConstant = false
|
||||||
.setVerbose(true)
|
verbose = true
|
||||||
.build()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: this test does a dirty hack of text substitution to make all annotations defined in source code retain at runtime.
|
// NOTE: this test does a dirty hack of text substitution to make all annotations defined in source code retain at runtime.
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val renderer = DescriptorRendererBuilder().setNameShortness(NameShortness.FULLY_QUALIFIED).build()
|
val renderer = DescriptorRenderer.withOptions { nameShortness = NameShortness.FULLY_QUALIFIED }
|
||||||
val renderedDescriptors = descriptors.map { renderer.render(it) }.joinToString(separator = "\n")
|
val renderedDescriptors = descriptors.map { renderer.render(it) }.joinToString(separator = "\n")
|
||||||
|
|
||||||
val document = DocumentImpl(psiFile.getText())
|
val document = DocumentImpl(psiFile.getText())
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ abstract public class AbstractFunctionDescriptorInExpressionRendererTest : Kotli
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
val renderer = DescriptorRendererBuilder().setNameShortness(NameShortness.FULLY_QUALIFIED).setVerbose(true).build()
|
val renderer = DescriptorRenderer.withOptions { nameShortness = NameShortness.FULLY_QUALIFIED; verbose = true }
|
||||||
val renderedDescriptors = descriptors.map { renderer.render(it) }.joinToString(separator = "\n")
|
val renderedDescriptors = descriptors.map { renderer.render(it) }.joinToString(separator = "\n")
|
||||||
|
|
||||||
val document = DocumentImpl(file.getText())
|
val document = DocumentImpl(file.getText())
|
||||||
|
|||||||
+13
-5
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.resolve.annotation;
|
|||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
@@ -31,7 +33,7 @@ import org.jetbrains.kotlin.name.Name;
|
|||||||
import org.jetbrains.kotlin.psi.JetAnnotationEntry;
|
import org.jetbrains.kotlin.psi.JetAnnotationEntry;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
@@ -48,10 +50,16 @@ import java.util.List;
|
|||||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isNonCompanionObject;
|
||||||
|
|
||||||
public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
||||||
private static final DescriptorRenderer WITH_ANNOTATION_ARGUMENT_TYPES = new DescriptorRendererBuilder()
|
private static final DescriptorRenderer WITH_ANNOTATION_ARGUMENT_TYPES = DescriptorRenderer.Companion.withOptions(
|
||||||
.setVerbose(true)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setNameShortness(NameShortness.SHORT)
|
@Override
|
||||||
.build();
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
|
options.setVerbose(true);
|
||||||
|
options.setNameShortness(NameShortness.SHORT);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
private static final String PATH = "compiler/testData/resolveAnnotations/testFile.kt";
|
private static final String PATH = "compiler/testData/resolveAnnotations/testFile.kt";
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ package org.jetbrains.kotlin.serialization.builtins;
|
|||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
@@ -25,7 +27,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
|||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
|
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||||
@@ -47,12 +49,18 @@ public class LoadBuiltinsTest extends KotlinTestWithEnvironment {
|
|||||||
public void testBuiltIns() throws Exception {
|
public void testBuiltIns() throws Exception {
|
||||||
RecursiveDescriptorComparator.Configuration configuration =
|
RecursiveDescriptorComparator.Configuration configuration =
|
||||||
RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(
|
RecursiveDescriptorComparator.RECURSIVE_ALL.includeMethodsOfKotlinAny(false).withRenderer(
|
||||||
new DescriptorRendererBuilder()
|
DescriptorRenderer.Companion.withOptions(
|
||||||
.setWithDefinedIn(false)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE)
|
@Override
|
||||||
.setVerbose(true)
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.setPrettyFunctionTypes(false)
|
options.setWithDefinedIn(false);
|
||||||
.build()
|
options.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||||
|
options.setVerbose(true);
|
||||||
|
options.setPrettyFunctionTypes(false);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
List<JetFile> files = JetTestUtils.loadToJetFiles(getEnvironment(), ContainerUtil.concat(
|
List<JetFile> files = JetTestUtils.loadToJetFiles(getEnvironment(), ContainerUtil.concat(
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import com.google.common.base.Predicate;
|
|||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||||
@@ -27,7 +29,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
|||||||
import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil;
|
import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.MemberComparator;
|
import org.jetbrains.kotlin.resolve.MemberComparator;
|
||||||
@@ -37,7 +39,6 @@ import org.jetbrains.kotlin.utils.Printer;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -46,13 +47,20 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
|||||||
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden;
|
import static org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden;
|
||||||
|
|
||||||
public class RecursiveDescriptorComparator {
|
public class RecursiveDescriptorComparator {
|
||||||
private static final DescriptorRenderer DEFAULT_RENDERER = new DescriptorRendererBuilder()
|
private static final DescriptorRenderer DEFAULT_RENDERER = DescriptorRenderer.Companion.withOptions(
|
||||||
.setWithDefinedIn(false)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setExcludedAnnotationClasses(Arrays.asList(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)))
|
@Override
|
||||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE)
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.setIncludePropertyConstant(true)
|
options.setWithDefinedIn(false);
|
||||||
.setNameShortness(NameShortness.FULLY_QUALIFIED)
|
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)));
|
||||||
.setVerbose(true).build();
|
options.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
|
||||||
|
options.setIncludePropertyConstant(true);
|
||||||
|
options.setNameShortness(NameShortness.FULLY_QUALIFIED);
|
||||||
|
options.setVerbose(true);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false,
|
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false,
|
||||||
Predicates.<DeclarationDescriptor>alwaysTrue(),
|
Predicates.<DeclarationDescriptor>alwaysTrue(),
|
||||||
|
|||||||
+1
-1
@@ -100,7 +100,7 @@ public final class JvmAnnotationNames {
|
|||||||
public static final FqName OLD_KOTLIN_TRAIT_IMPL = new FqName("jet.KotlinTraitImpl");
|
public static final FqName OLD_KOTLIN_TRAIT_IMPL = new FqName("jet.KotlinTraitImpl");
|
||||||
|
|
||||||
// When these annotations appear on a declaration, they are copied to the _type_ of the declaration, becoming type annotations
|
// When these annotations appear on a declaration, they are copied to the _type_ of the declaration, becoming type annotations
|
||||||
// See also DescriptorRendererBuilder#excludedTypeAnnotationClasses
|
// See also DescriptorRendererOptions#excludedTypeAnnotationClasses
|
||||||
public static final Set<FqName> ANNOTATIONS_COPIED_TO_TYPES = KotlinPackage.setOf(
|
public static final Set<FqName> ANNOTATIONS_COPIED_TO_TYPES = KotlinPackage.setOf(
|
||||||
JETBRAINS_READONLY_ANNOTATION,
|
JETBRAINS_READONLY_ANNOTATION,
|
||||||
JETBRAINS_MUTABLE_ANNOTATION,
|
JETBRAINS_MUTABLE_ANNOTATION,
|
||||||
|
|||||||
@@ -21,12 +21,19 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.FqNameBase
|
import org.jetbrains.kotlin.name.FqNameBase
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
import org.jetbrains.kotlin.types.TypeProjection
|
import org.jetbrains.kotlin.types.TypeProjection
|
||||||
|
|
||||||
public interface DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
public interface DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||||
|
public fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||||
|
val options = (this as DescriptorRendererImpl).options.copy()
|
||||||
|
options.changeOptions()
|
||||||
|
options.lock()
|
||||||
|
return DescriptorRendererImpl(options)
|
||||||
|
}
|
||||||
|
|
||||||
public fun renderType(type: JetType): String
|
public fun renderType(type: JetType): String
|
||||||
|
|
||||||
@@ -70,121 +77,157 @@ public interface DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
|||||||
MEMBER_KIND
|
MEMBER_KIND
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see DefaultValueParameterHandler
|
|
||||||
*/
|
|
||||||
public interface ValueParametersHandler {
|
public interface ValueParametersHandler {
|
||||||
public fun appendBeforeValueParameters(function: FunctionDescriptor, stringBuilder: StringBuilder)
|
public fun appendBeforeValueParameters(function: FunctionDescriptor, builder: StringBuilder)
|
||||||
public fun appendAfterValueParameters(function: FunctionDescriptor, stringBuilder: StringBuilder)
|
public fun appendAfterValueParameters(function: FunctionDescriptor, builder: StringBuilder)
|
||||||
|
|
||||||
public fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, stringBuilder: StringBuilder)
|
public fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, builder: StringBuilder)
|
||||||
public fun appendAfterValueParameter(parameter: ValueParameterDescriptor, stringBuilder: StringBuilder)
|
public fun appendAfterValueParameter(parameter: ValueParameterDescriptor, builder: StringBuilder)
|
||||||
}
|
|
||||||
|
|
||||||
public class DefaultValueParameterHandler : ValueParametersHandler {
|
public object DEFAULT : ValueParametersHandler {
|
||||||
override fun appendBeforeValueParameters(function: FunctionDescriptor, stringBuilder: StringBuilder) {
|
override fun appendBeforeValueParameters(function: FunctionDescriptor, builder: StringBuilder) {
|
||||||
stringBuilder.append("(")
|
builder.append("(")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun appendAfterValueParameters(function: FunctionDescriptor, stringBuilder: StringBuilder) {
|
override fun appendAfterValueParameters(function: FunctionDescriptor, builder: StringBuilder) {
|
||||||
stringBuilder.append(")")
|
builder.append(")")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, stringBuilder: StringBuilder) {
|
override fun appendBeforeValueParameter(parameter: ValueParameterDescriptor, builder: StringBuilder) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun appendAfterValueParameter(parameter: ValueParameterDescriptor, stringBuilder: StringBuilder) {
|
override fun appendAfterValueParameter(parameter: ValueParameterDescriptor, builder: StringBuilder) {
|
||||||
val function = parameter.getContainingDeclaration() as FunctionDescriptor
|
val function = parameter.getContainingDeclaration() as FunctionDescriptor
|
||||||
if (parameter.getIndex() != function.getValueParameters().size() - 1) {
|
if (parameter.getIndex() != function.getValueParameters().size() - 1) {
|
||||||
stringBuilder.append(", ")
|
builder.append(", ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
public val COMPACT_WITH_MODIFIERS: DescriptorRenderer = DescriptorRendererBuilder()
|
public fun withOptions(changeOptions: DescriptorRendererOptions.() -> Unit): DescriptorRenderer {
|
||||||
.setWithDefinedIn(false)
|
val options = DescriptorRendererOptionsImpl()
|
||||||
.build()
|
options.changeOptions()
|
||||||
|
options.lock()
|
||||||
|
return DescriptorRendererImpl(options)
|
||||||
|
}
|
||||||
|
|
||||||
public val COMPACT: DescriptorRenderer = DescriptorRendererBuilder()
|
public val COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setModifiers()
|
}
|
||||||
.build()
|
|
||||||
|
|
||||||
public val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = DescriptorRendererBuilder()
|
public val COMPACT: DescriptorRenderer = withOptions {
|
||||||
.setModifiers()
|
withDefinedIn = false
|
||||||
.setNameShortness(NameShortness.SHORT)
|
modifiers = emptySet()
|
||||||
.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED)
|
}
|
||||||
.build()
|
|
||||||
|
|
||||||
public val STARTS_FROM_NAME: DescriptorRenderer = DescriptorRendererBuilder()
|
public val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||||
.setWithDefinedIn(false)
|
modifiers = emptySet()
|
||||||
.setModifiers()
|
nameShortness = NameShortness.SHORT
|
||||||
.setStartFromName(true)
|
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||||
.build()
|
}
|
||||||
|
|
||||||
public val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = DescriptorRendererBuilder()
|
public val STARTS_FROM_NAME: DescriptorRenderer = withOptions {
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setModifiers()
|
modifiers = emptySet()
|
||||||
.setNameShortness(NameShortness.SHORT)
|
startFromName = true
|
||||||
.setWithoutTypeParameters(true)
|
}
|
||||||
.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE)
|
|
||||||
.setReceiverAfterName(true)
|
|
||||||
.setRenderCompanionObjectName(true)
|
|
||||||
.setWithoutSuperTypes(true)
|
|
||||||
.setStartFromName(true)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
public val FQ_NAMES_IN_TYPES: DescriptorRenderer = DescriptorRendererBuilder().build()
|
public val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||||
|
withDefinedIn = false
|
||||||
|
modifiers = emptySet()
|
||||||
|
nameShortness = NameShortness.SHORT
|
||||||
|
withoutTypeParameters = true
|
||||||
|
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
|
||||||
|
receiverAfterName = true
|
||||||
|
renderCompanionObjectName = true
|
||||||
|
withoutSuperTypes = true
|
||||||
|
startFromName = true
|
||||||
|
}
|
||||||
|
|
||||||
public val SHORT_NAMES_IN_TYPES: DescriptorRenderer = DescriptorRendererBuilder()
|
public val FQ_NAMES_IN_TYPES: DescriptorRenderer = withOptions { }
|
||||||
.setNameShortness(NameShortness.SHORT)
|
|
||||||
.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
public val DEBUG_TEXT: DescriptorRenderer = DescriptorRendererBuilder()
|
public val SHORT_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
|
||||||
.setDebugMode(true)
|
nameShortness = NameShortness.SHORT
|
||||||
.setNameShortness(NameShortness.FULLY_QUALIFIED)
|
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||||
.build()
|
}
|
||||||
|
|
||||||
public val FLEXIBLE_TYPES_FOR_CODE: DescriptorRenderer = DescriptorRendererBuilder()
|
public val DEBUG_TEXT: DescriptorRenderer = withOptions {
|
||||||
.setFlexibleTypesForCode(true)
|
debugMode = true
|
||||||
.build()
|
nameShortness = NameShortness.FULLY_QUALIFIED
|
||||||
|
}
|
||||||
|
|
||||||
public val HTML_COMPACT_WITH_MODIFIERS: DescriptorRenderer = DescriptorRendererBuilder()
|
public val FLEXIBLE_TYPES_FOR_CODE: DescriptorRenderer = withOptions {
|
||||||
.setWithDefinedIn(false)
|
flexibleTypesForCode = true
|
||||||
.setTextFormat(TextFormat.HTML)
|
}
|
||||||
.build()
|
|
||||||
|
|
||||||
public val HTML_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = DescriptorRendererBuilder()
|
public val HTML_COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setNameShortness(NameShortness.SHORT)
|
textFormat = TextFormat.HTML
|
||||||
.setRenderCompanionObjectName(true)
|
}
|
||||||
.setTextFormat(TextFormat.HTML)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
public val HTML: DescriptorRenderer = DescriptorRendererBuilder()
|
public val HTML_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||||
.setTextFormat(TextFormat.HTML)
|
withDefinedIn = false
|
||||||
.build()
|
nameShortness = NameShortness.SHORT
|
||||||
|
renderCompanionObjectName = true
|
||||||
|
textFormat = TextFormat.HTML
|
||||||
|
}
|
||||||
|
|
||||||
public val HTML_FOR_UNINFERRED_TYPE_PARAMS: DescriptorRenderer = DescriptorRendererBuilder()
|
public val HTML: DescriptorRenderer = withOptions {
|
||||||
.setUninferredTypeParameterAsName(true)
|
textFormat = TextFormat.HTML
|
||||||
.setModifiers()
|
}
|
||||||
.setNameShortness(NameShortness.SHORT)
|
|
||||||
.setTextFormat(TextFormat.HTML)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
public val DEPRECATION: DescriptorRenderer = DescriptorRendererBuilder()
|
public val HTML_FOR_UNINFERRED_TYPE_PARAMS: DescriptorRenderer = withOptions {
|
||||||
.setWithDefinedIn(false)
|
uninferredTypeParameterAsName = true
|
||||||
.setModifiers()
|
modifiers = emptySet()
|
||||||
.setNameShortness(NameShortness.SHORT)
|
nameShortness = NameShortness.SHORT
|
||||||
.setWithoutTypeParameters(false)
|
textFormat = TextFormat.HTML
|
||||||
.setParameterNameRenderingPolicy(ParameterNameRenderingPolicy.NONE)
|
}
|
||||||
.setReceiverAfterName(false)
|
|
||||||
.setRenderCompanionObjectName(true)
|
public val DEPRECATION: DescriptorRenderer = withOptions {
|
||||||
.setRenderAccessors(true)
|
withDefinedIn = false
|
||||||
.setWithoutSuperTypes(true)
|
modifiers = emptySet()
|
||||||
.setRenderDefaultValues(false)
|
nameShortness = NameShortness.SHORT
|
||||||
.setStartFromName(true)
|
withoutTypeParameters = false
|
||||||
.build()
|
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
|
||||||
|
receiverAfterName = false
|
||||||
|
renderCompanionObjectName = true
|
||||||
|
renderAccessors = true
|
||||||
|
withoutSuperTypes = true
|
||||||
|
renderDefaultValues = false
|
||||||
|
startFromName = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface DescriptorRendererOptions {
|
||||||
|
public var nameShortness: NameShortness
|
||||||
|
public var withDefinedIn: Boolean
|
||||||
|
public var modifiers: Set<DescriptorRenderer.Modifier>
|
||||||
|
public var startFromName: Boolean
|
||||||
|
public var debugMode: Boolean
|
||||||
|
public var classWithPrimaryConstructor: Boolean
|
||||||
|
public var verbose: Boolean
|
||||||
|
public var unitReturnType: Boolean
|
||||||
|
public var normalizedVisibilities: Boolean
|
||||||
|
public var showInternalKeyword: Boolean
|
||||||
|
public var prettyFunctionTypes: Boolean
|
||||||
|
public var uninferredTypeParameterAsName: Boolean
|
||||||
|
public var overrideRenderingPolicy: DescriptorRenderer.OverrideRenderingPolicy
|
||||||
|
public var valueParametersHandler: DescriptorRenderer.ValueParametersHandler
|
||||||
|
public var textFormat: DescriptorRenderer.TextFormat
|
||||||
|
public var excludedAnnotationClasses: Set<FqName>
|
||||||
|
public var excludedTypeAnnotationClasses: Set<FqName>
|
||||||
|
public var includePropertyConstant: Boolean
|
||||||
|
public var parameterNameRenderingPolicy: DescriptorRenderer.ParameterNameRenderingPolicy
|
||||||
|
public var withoutTypeParameters: Boolean
|
||||||
|
public var receiverAfterName: Boolean
|
||||||
|
public var renderCompanionObjectName: Boolean
|
||||||
|
public var withoutSuperTypes: Boolean
|
||||||
|
public var typeNormalizer: (JetType) -> JetType
|
||||||
|
public var renderDefaultValues: Boolean
|
||||||
|
public var flexibleTypesForCode: Boolean
|
||||||
|
public var secondaryConstructorsAsPrimary: Boolean
|
||||||
|
public var renderAccessors: Boolean
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,212 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.renderer
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.types.JetType
|
|
||||||
import java.util.Collections
|
|
||||||
import java.util.EnumSet
|
|
||||||
|
|
||||||
public class DescriptorRendererBuilder {
|
|
||||||
private var nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
|
|
||||||
private var withDefinedIn = true
|
|
||||||
private var modifiers: Set<DescriptorRenderer.Modifier> = EnumSet.allOf(javaClass<DescriptorRenderer.Modifier>())
|
|
||||||
private var startFromName = false
|
|
||||||
private var debugMode = false
|
|
||||||
private var classWithPrimaryConstructor = false
|
|
||||||
private var verbose = false
|
|
||||||
private var unitReturnType = true
|
|
||||||
private var normalizedVisibilities = false
|
|
||||||
private var showInternalKeyword = true
|
|
||||||
private var prettyFunctionTypes = true
|
|
||||||
private var uninferredTypeParameterAsName = false
|
|
||||||
private var includePropertyConstant = false
|
|
||||||
private var withoutTypeParameters = false
|
|
||||||
private var withoutSuperTypes = false
|
|
||||||
private var typeNormalizer: Function1<JetType, JetType> = object : Function1<JetType, JetType> {
|
|
||||||
override fun invoke(type: JetType): JetType {
|
|
||||||
return type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private var renderDefaultValues = true
|
|
||||||
private var flexibleTypesForCode = false
|
|
||||||
private var secondaryConstructorsAsPrimary = true
|
|
||||||
private var overrideRenderingPolicy: DescriptorRenderer.OverrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN
|
|
||||||
private var valueParametersHandler: DescriptorRenderer.ValueParametersHandler = DescriptorRenderer.DefaultValueParameterHandler()
|
|
||||||
private var textFormat: DescriptorRenderer.TextFormat = DescriptorRenderer.TextFormat.PLAIN
|
|
||||||
private var parameterNameRenderingPolicy: DescriptorRenderer.ParameterNameRenderingPolicy = DescriptorRenderer.ParameterNameRenderingPolicy.ALL
|
|
||||||
private var excludedAnnotationClasses: Collection<FqName> = emptyList()
|
|
||||||
private var receiverAfterName = false
|
|
||||||
private var renderCompanionObjectName = false
|
|
||||||
private var renderAccessors = false
|
|
||||||
|
|
||||||
// See JvmAnnotationNames#ANNOTATIONS_COPIED_TO_TYPES
|
|
||||||
private var excludedTypeAnnotationClasses: Collection<FqName> = setOf(
|
|
||||||
FqName("org.jetbrains.annotations.ReadOnly"),
|
|
||||||
FqName("org.jetbrains.annotations.Mutable"),
|
|
||||||
FqName("org.jetbrains.annotations.NotNull"),
|
|
||||||
FqName("org.jetbrains.annotations.Nullable"))
|
|
||||||
|
|
||||||
public fun setNameShortness(shortness: NameShortness): DescriptorRendererBuilder {
|
|
||||||
this.nameShortness = shortness
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setWithDefinedIn(withDefinedIn: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.withDefinedIn = withDefinedIn
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setModifiers(modifiers: Set<DescriptorRenderer.Modifier>): DescriptorRendererBuilder {
|
|
||||||
this.modifiers = modifiers
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setModifiers(vararg modifiers: DescriptorRenderer.Modifier): DescriptorRendererBuilder {
|
|
||||||
return setModifiers(setOf(*modifiers))
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setStartFromName(startFromName: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.startFromName = startFromName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setDebugMode(debugMode: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.debugMode = debugMode
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setClassWithPrimaryConstructor(classWithPrimaryConstructor: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.classWithPrimaryConstructor = classWithPrimaryConstructor
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setVerbose(verbose: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.verbose = verbose
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setUnitReturnType(unitReturnType: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.unitReturnType = unitReturnType
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setNormalizedVisibilities(normalizedVisibilities: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.normalizedVisibilities = normalizedVisibilities
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setShowInternalKeyword(showInternalKeyword: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.showInternalKeyword = showInternalKeyword
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setOverrideRenderingPolicy(overrideRenderingPolicy: DescriptorRenderer.OverrideRenderingPolicy): DescriptorRendererBuilder {
|
|
||||||
this.overrideRenderingPolicy = overrideRenderingPolicy
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setValueParametersHandler(valueParametersHandler: DescriptorRenderer.ValueParametersHandler): DescriptorRendererBuilder {
|
|
||||||
this.valueParametersHandler = valueParametersHandler
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setTextFormat(textFormat: DescriptorRenderer.TextFormat): DescriptorRendererBuilder {
|
|
||||||
this.textFormat = textFormat
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setExcludedAnnotationClasses(excludedAnnotationClasses: Collection<FqName>): DescriptorRendererBuilder {
|
|
||||||
this.excludedAnnotationClasses = excludedAnnotationClasses
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setExcludedTypeAnnotationClasses(excludedTypeAnnotationClasses: Collection<FqName>): DescriptorRendererBuilder {
|
|
||||||
this.excludedTypeAnnotationClasses = excludedTypeAnnotationClasses
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setPrettyFunctionTypes(prettyFunctionTypes: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.prettyFunctionTypes = prettyFunctionTypes
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setUninferredTypeParameterAsName(uninferredTypeParameterAsName: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.uninferredTypeParameterAsName = uninferredTypeParameterAsName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setIncludePropertyConstant(includePropertyConstant: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.includePropertyConstant = includePropertyConstant
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setParameterNameRenderingPolicy(parameterNameRenderingPolicy: DescriptorRenderer.ParameterNameRenderingPolicy): DescriptorRendererBuilder {
|
|
||||||
this.parameterNameRenderingPolicy = parameterNameRenderingPolicy
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setWithoutTypeParameters(withoutTypeParameters: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.withoutTypeParameters = withoutTypeParameters
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setReceiverAfterName(receiverAfterName: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.receiverAfterName = receiverAfterName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setRenderCompanionObjectName(renderCompanionObjectName: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.renderCompanionObjectName = renderCompanionObjectName
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setWithoutSuperTypes(withoutSuperTypes: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.withoutSuperTypes = withoutSuperTypes
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setRenderDefaultValues(renderDefaultValues: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.renderDefaultValues = renderDefaultValues
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setTypeNormalizer(typeNormalizer: Function1<JetType, JetType>): DescriptorRendererBuilder {
|
|
||||||
this.typeNormalizer = typeNormalizer
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setFlexibleTypesForCode(flexibleTypesForCode: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.flexibleTypesForCode = flexibleTypesForCode
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setSecondaryConstructorsAsPrimary(secondaryConstructorsAsPrimary: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.secondaryConstructorsAsPrimary = secondaryConstructorsAsPrimary
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun setRenderAccessors(renderAccessors: Boolean): DescriptorRendererBuilder {
|
|
||||||
this.renderAccessors = renderAccessors
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun build(): DescriptorRenderer {
|
|
||||||
return DescriptorRendererImpl(nameShortness, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName, overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, excludedTypeAnnotationClasses, includePropertyConstant, parameterNameRenderingPolicy, withoutTypeParameters, receiverAfterName, renderCompanionObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode, secondaryConstructorsAsPrimary, renderAccessors)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -38,42 +38,12 @@ import java.util.*
|
|||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject
|
import org.jetbrains.kotlin.resolve.DescriptorUtils.isCompanionObject
|
||||||
import org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE
|
import org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_FUNCTION_PARAM_TYPE
|
||||||
|
|
||||||
public class DescriptorRendererImpl internal constructor(
|
public/*TODO*/ class DescriptorRendererImpl internal constructor(
|
||||||
private val nameShortness: NameShortness,
|
public val options: DescriptorRendererOptionsImpl
|
||||||
private val withDefinedIn: Boolean,
|
) : DescriptorRenderer, DescriptorRendererOptions by options/* this gives access to options without qualifier */ {
|
||||||
private val modifiers: Set<DescriptorRenderer.Modifier>,
|
|
||||||
private val startFromName: Boolean,
|
|
||||||
private val debugMode: Boolean,
|
|
||||||
private val classWithPrimaryConstructor: Boolean,
|
|
||||||
private val verbose: Boolean,
|
|
||||||
private val unitReturnType: Boolean,
|
|
||||||
private val normalizedVisibilities: Boolean,
|
|
||||||
private val showInternalKeyword: Boolean,
|
|
||||||
private val prettyFunctionTypes: Boolean,
|
|
||||||
private val uninferredTypeParameterAsName: Boolean,
|
|
||||||
private val overrideRenderingPolicy: DescriptorRenderer.OverrideRenderingPolicy,
|
|
||||||
private val handler: DescriptorRenderer.ValueParametersHandler,
|
|
||||||
private val textFormat: DescriptorRenderer.TextFormat,
|
|
||||||
excludedAnnotationClasses: Collection<FqName>,
|
|
||||||
excludedTypeAnnotationClasses: Collection<FqName>,
|
|
||||||
private val includePropertyConstant: Boolean,
|
|
||||||
private val parameterNameRenderingPolicy: DescriptorRenderer.ParameterNameRenderingPolicy,
|
|
||||||
private val withoutTypeParameters: Boolean,
|
|
||||||
private val receiverAfterName: Boolean,
|
|
||||||
private val renderCompanionObjectName: Boolean,
|
|
||||||
private val withoutSuperTypes: Boolean,
|
|
||||||
private val typeNormalizer: Function1<JetType, JetType>,
|
|
||||||
private val renderDefaultValues: Boolean,
|
|
||||||
private val flexibleTypesForCode: Boolean,
|
|
||||||
private val secondaryConstructorsAsPrimary: Boolean,
|
|
||||||
private val renderAccessors: Boolean
|
|
||||||
) : DescriptorRenderer {
|
|
||||||
private val excludedAnnotationClasses: Set<FqName>
|
|
||||||
private val excludedTypeAnnotationClasses: Set<FqName>
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.excludedAnnotationClasses = HashSet(excludedAnnotationClasses)
|
assert(options.isLocked)
|
||||||
this.excludedTypeAnnotationClasses = HashSet(excludedTypeAnnotationClasses)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FORMATTING */
|
/* FORMATTING */
|
||||||
@@ -682,13 +652,13 @@ public class DescriptorRendererImpl internal constructor(
|
|||||||
|
|
||||||
private fun renderValueParameters(function: FunctionDescriptor, builder: StringBuilder) {
|
private fun renderValueParameters(function: FunctionDescriptor, builder: StringBuilder) {
|
||||||
val includeNames = shouldRenderParameterNames(function)
|
val includeNames = shouldRenderParameterNames(function)
|
||||||
handler.appendBeforeValueParameters(function, builder)
|
valueParametersHandler.appendBeforeValueParameters(function, builder)
|
||||||
for (parameter in function.getValueParameters()) {
|
for (parameter in function.getValueParameters()) {
|
||||||
handler.appendBeforeValueParameter(parameter, builder)
|
valueParametersHandler.appendBeforeValueParameter(parameter, builder)
|
||||||
renderValueParameter(parameter, includeNames, builder, false)
|
renderValueParameter(parameter, includeNames, builder, false)
|
||||||
handler.appendAfterValueParameter(parameter, builder)
|
valueParametersHandler.appendAfterValueParameter(parameter, builder)
|
||||||
}
|
}
|
||||||
handler.appendAfterValueParameters(function, builder)
|
valueParametersHandler.appendAfterValueParameters(function, builder)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun shouldRenderParameterNames(function: FunctionDescriptor): Boolean {
|
private fun shouldRenderParameterNames(function: FunctionDescriptor): Boolean {
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 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.kotlin.renderer
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.types.JetType
|
||||||
|
import java.lang.reflect.Modifier
|
||||||
|
import java.util.EnumSet
|
||||||
|
import kotlin.properties.Delegates
|
||||||
|
import kotlin.properties.ObservableProperty
|
||||||
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
|
||||||
|
internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||||
|
public var isLocked: Boolean = false
|
||||||
|
private set
|
||||||
|
|
||||||
|
public fun lock() {
|
||||||
|
assert(!isLocked)
|
||||||
|
isLocked = true
|
||||||
|
}
|
||||||
|
|
||||||
|
public fun copy(): DescriptorRendererOptionsImpl {
|
||||||
|
val copy = DescriptorRendererOptionsImpl()
|
||||||
|
|
||||||
|
//TODO: use Kotlin reflection when it's ready
|
||||||
|
for (field in this.javaClass.getDeclaredFields()) {
|
||||||
|
if (field.getModifiers().and(Modifier.STATIC) != 0) continue
|
||||||
|
field.setAccessible(true)
|
||||||
|
val property = field.get(this) as? ObservableProperty<*> ?: continue
|
||||||
|
val value = property.get(this, PropertyMetadataImpl("")/* not used*/)
|
||||||
|
field.set(copy, copy.property(value as Any))
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun <T> property(initialValue: T): ReadWriteProperty<DescriptorRendererOptionsImpl, T> {
|
||||||
|
return Delegates.vetoable(initialValue) { property, oldValue, newValue ->
|
||||||
|
if (isLocked) {
|
||||||
|
throw IllegalStateException("Cannot modify readonly DescriptorRendererOptions")
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override var nameShortness by property(NameShortness.SOURCE_CODE_QUALIFIED)
|
||||||
|
override var withDefinedIn by property(true)
|
||||||
|
override var modifiers: Set<DescriptorRenderer.Modifier> by property(EnumSet.allOf(javaClass<DescriptorRenderer.Modifier>()))
|
||||||
|
override var startFromName by property(false)
|
||||||
|
override var debugMode by property(false)
|
||||||
|
override var classWithPrimaryConstructor by property(false)
|
||||||
|
override var verbose by property(false)
|
||||||
|
override var unitReturnType by property(true)
|
||||||
|
override var normalizedVisibilities by property(false)
|
||||||
|
override var showInternalKeyword by property(true)
|
||||||
|
override var prettyFunctionTypes by property(true)
|
||||||
|
override var uninferredTypeParameterAsName by property(false)
|
||||||
|
override var includePropertyConstant by property(false)
|
||||||
|
override var withoutTypeParameters by property(false)
|
||||||
|
override var withoutSuperTypes by property(false)
|
||||||
|
override var typeNormalizer by property<(JetType) -> JetType>({ it })
|
||||||
|
override var renderDefaultValues by property(true)
|
||||||
|
override var flexibleTypesForCode by property(false)
|
||||||
|
override var secondaryConstructorsAsPrimary by property(true)
|
||||||
|
override var overrideRenderingPolicy by property(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN)
|
||||||
|
override var valueParametersHandler: DescriptorRenderer.ValueParametersHandler by property(DescriptorRenderer.ValueParametersHandler.DEFAULT)
|
||||||
|
override var textFormat by property(DescriptorRenderer.TextFormat.PLAIN)
|
||||||
|
override var parameterNameRenderingPolicy by property(DescriptorRenderer.ParameterNameRenderingPolicy.ALL)
|
||||||
|
override var receiverAfterName by property(false)
|
||||||
|
override var renderCompanionObjectName by property(false)
|
||||||
|
override var renderAccessors by property(false)
|
||||||
|
|
||||||
|
override var excludedAnnotationClasses by property(emptySet<FqName>())
|
||||||
|
|
||||||
|
override var excludedTypeAnnotationClasses by property(setOf(
|
||||||
|
FqName("org.jetbrains.annotations.ReadOnly"),
|
||||||
|
FqName("org.jetbrains.annotations.Mutable"),
|
||||||
|
FqName("org.jetbrains.annotations.NotNull"),
|
||||||
|
FqName("org.jetbrains.annotations.Nullable")
|
||||||
|
))
|
||||||
|
}
|
||||||
@@ -16,10 +16,12 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve;
|
package org.jetbrains.kotlin.resolve;
|
||||||
|
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -29,7 +31,15 @@ import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
|||||||
public class MemberComparator implements Comparator<DeclarationDescriptor> {
|
public class MemberComparator implements Comparator<DeclarationDescriptor> {
|
||||||
public static final MemberComparator INSTANCE = new MemberComparator();
|
public static final MemberComparator INSTANCE = new MemberComparator();
|
||||||
|
|
||||||
private static final DescriptorRenderer RENDERER = new DescriptorRendererBuilder().setWithDefinedIn(false).setVerbose(true).build();
|
private static final DescriptorRenderer RENDERER = DescriptorRenderer.Companion.withOptions(
|
||||||
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
|
@Override
|
||||||
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
|
options.setWithDefinedIn(false);
|
||||||
|
options.setVerbose(true);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
private MemberComparator() {
|
private MemberComparator() {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.idea.util;
|
|
||||||
|
|
||||||
import kotlin.jvm.functions.Function1;
|
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
|
||||||
|
|
||||||
public class IdeDescriptorRenderers {
|
|
||||||
|
|
||||||
public static final Function1<JetType, JetType> APPROXIMATE_FLEXIBLE_TYPES = new Function1<JetType, JetType>() {
|
|
||||||
@Override
|
|
||||||
public JetType invoke(JetType type) {
|
|
||||||
return UtilPackage.approximateFlexibleTypes(type, true);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final Function1<JetType, JetType> APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS = new Function1<JetType, JetType>() {
|
|
||||||
@Override
|
|
||||||
public JetType invoke(JetType type) {
|
|
||||||
return UtilPackage.approximateFlexibleTypes(type, false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public static final DescriptorRenderer SOURCE_CODE = commonBuilder()
|
|
||||||
.setNameShortness(NameShortness.SOURCE_CODE_QUALIFIED)
|
|
||||||
.setTypeNormalizer(APPROXIMATE_FLEXIBLE_TYPES)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public static final DescriptorRenderer SOURCE_CODE_FOR_TYPE_ARGUMENTS = commonBuilder()
|
|
||||||
.setNameShortness(NameShortness.SOURCE_CODE_QUALIFIED)
|
|
||||||
.setTypeNormalizer(APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
public static final DescriptorRenderer SOURCE_CODE_SHORT_NAMES_IN_TYPES = commonBuilder()
|
|
||||||
.setNameShortness(NameShortness.SHORT)
|
|
||||||
.setTypeNormalizer(APPROXIMATE_FLEXIBLE_TYPES)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private static DescriptorRendererBuilder commonBuilder() {
|
|
||||||
return new DescriptorRendererBuilder()
|
|
||||||
.setNormalizedVisibilities(true)
|
|
||||||
.setWithDefinedIn(false)
|
|
||||||
.setShowInternalKeyword(false)
|
|
||||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OVERRIDE)
|
|
||||||
.setUnitReturnType(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 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.kotlin.idea.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
|
import org.jetbrains.kotlin.renderer.NameShortness
|
||||||
|
import org.jetbrains.kotlin.types.JetType
|
||||||
|
|
||||||
|
public object IdeDescriptorRenderers {
|
||||||
|
public val APPROXIMATE_FLEXIBLE_TYPES: (JetType) -> JetType = { approximateFlexibleTypes(it, true) }
|
||||||
|
|
||||||
|
public val APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS: (JetType) -> JetType = { approximateFlexibleTypes(it, false) }
|
||||||
|
|
||||||
|
private val BASE: DescriptorRenderer = DescriptorRenderer.withOptions {
|
||||||
|
normalizedVisibilities = true
|
||||||
|
withDefinedIn = false
|
||||||
|
showInternalKeyword = false
|
||||||
|
overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OVERRIDE
|
||||||
|
unitReturnType = false
|
||||||
|
}
|
||||||
|
|
||||||
|
public val SOURCE_CODE: DescriptorRenderer = BASE.withOptions {
|
||||||
|
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
|
||||||
|
typeNormalizer = APPROXIMATE_FLEXIBLE_TYPES
|
||||||
|
}
|
||||||
|
|
||||||
|
public val SOURCE_CODE_FOR_TYPE_ARGUMENTS: DescriptorRenderer = BASE.withOptions {
|
||||||
|
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
|
||||||
|
typeNormalizer = APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS
|
||||||
|
}
|
||||||
|
|
||||||
|
public val SOURCE_CODE_SHORT_NAMES_IN_TYPES: DescriptorRenderer = BASE.withOptions {
|
||||||
|
nameShortness = NameShortness.SHORT
|
||||||
|
typeNormalizer = APPROXIMATE_FLEXIBLE_TYPES
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-20
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.load.kotlin.header.isCompatibleClassKind
|
|||||||
import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind
|
import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry
|
import org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry
|
||||||
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.secondaryConstructors
|
import org.jetbrains.kotlin.resolve.descriptorUtil.secondaryConstructors
|
||||||
@@ -93,26 +92,18 @@ private val DECOMPILED_CODE_COMMENT = "/* compiled code */"
|
|||||||
private val DECOMPILED_COMMENT_FOR_PARAMETER = "/* = compiled code */"
|
private val DECOMPILED_COMMENT_FOR_PARAMETER = "/* = compiled code */"
|
||||||
private val FLEXIBLE_TYPE_COMMENT = "/* platform type */"
|
private val FLEXIBLE_TYPE_COMMENT = "/* platform type */"
|
||||||
|
|
||||||
private val descriptorRendererForDecompiler = DescriptorRendererBuilder()
|
private val descriptorRendererForDecompiler = DescriptorRenderer.withOptions {
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setClassWithPrimaryConstructor(true)
|
classWithPrimaryConstructor = true
|
||||||
.setTypeNormalizer {
|
typeNormalizer = { type -> if (type.isFlexible()) type.flexibility().lowerBound else type }
|
||||||
type ->
|
secondaryConstructorsAsPrimary = false
|
||||||
if (type.isFlexible()) {
|
}
|
||||||
type.flexibility().lowerBound
|
|
||||||
}
|
|
||||||
else type
|
|
||||||
|
|
||||||
}
|
|
||||||
.setSecondaryConstructorsAsPrimary(false)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
private val descriptorRendererForKotlinJavascriptDecompiler = DescriptorRendererBuilder()
|
|
||||||
.setWithDefinedIn(false)
|
|
||||||
.setClassWithPrimaryConstructor(true)
|
|
||||||
.setSecondaryConstructorsAsPrimary(false)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
|
private val descriptorRendererForKotlinJavascriptDecompiler = DescriptorRenderer.withOptions {
|
||||||
|
withDefinedIn = false
|
||||||
|
classWithPrimaryConstructor = true
|
||||||
|
secondaryConstructorsAsPrimary = false
|
||||||
|
}
|
||||||
|
|
||||||
private val descriptorRendererForKeys = DescriptorRenderer.COMPACT_WITH_MODIFIERS
|
private val descriptorRendererForKeys = DescriptorRenderer.COMPACT_WITH_MODIFIERS
|
||||||
|
|
||||||
|
|||||||
+27
-18
@@ -17,6 +17,8 @@
|
|||||||
package org.jetbrains.kotlin.idea.highlighter;
|
package org.jetbrains.kotlin.idea.highlighter;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||||
@@ -26,11 +28,12 @@ import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.Table
|
|||||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.FunctionArgumentsRow;
|
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.FunctionArgumentsRow;
|
||||||
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.TableRow;
|
import org.jetbrains.kotlin.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.TableRow;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.renderer.Renderer;
|
import org.jetbrains.kotlin.renderer.Renderer;
|
||||||
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition;
|
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPosition;
|
||||||
import org.jetbrains.kotlin.types.JetType;
|
import org.jetbrains.kotlin.types.JetType;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -166,44 +169,50 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
|||||||
|
|
||||||
private static final DescriptorRenderer.ValueParametersHandler VALUE_PARAMETERS_HANDLER = new DescriptorRenderer.ValueParametersHandler() {
|
private static final DescriptorRenderer.ValueParametersHandler VALUE_PARAMETERS_HANDLER = new DescriptorRenderer.ValueParametersHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void appendBeforeValueParameter(@NotNull ValueParameterDescriptor parameter, @NotNull StringBuilder stringBuilder) {
|
public void appendBeforeValueParameter(@NotNull ValueParameterDescriptor parameter, @NotNull StringBuilder builder) {
|
||||||
stringBuilder.append("<td align=\"right\" style=\"white-space:nowrap;font-weight:bold;\">");
|
builder.append("<td align=\"right\" style=\"white-space:nowrap;font-weight:bold;\">");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendAfterValueParameter(@NotNull ValueParameterDescriptor parameter, @NotNull StringBuilder stringBuilder) {
|
public void appendAfterValueParameter(@NotNull ValueParameterDescriptor parameter, @NotNull StringBuilder builder) {
|
||||||
boolean last = ((FunctionDescriptor) parameter.getContainingDeclaration()).getValueParameters().size() - 1 == parameter.getIndex();
|
boolean last = ((FunctionDescriptor) parameter.getContainingDeclaration()).getValueParameters().size() - 1 == parameter.getIndex();
|
||||||
if (!last) {
|
if (!last) {
|
||||||
stringBuilder.append(",");
|
builder.append(",");
|
||||||
}
|
}
|
||||||
stringBuilder.append("</td>");
|
builder.append("</td>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendBeforeValueParameters(@NotNull FunctionDescriptor function, @NotNull StringBuilder stringBuilder) {
|
public void appendBeforeValueParameters(@NotNull FunctionDescriptor function, @NotNull StringBuilder builder) {
|
||||||
stringBuilder.append("</td>");
|
builder.append("</td>");
|
||||||
if (function.getValueParameters().isEmpty()) {
|
if (function.getValueParameters().isEmpty()) {
|
||||||
tdBold(stringBuilder, "( )");
|
tdBold(builder, "( )");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tdBold(stringBuilder, "(");
|
tdBold(builder, "(");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void appendAfterValueParameters(@NotNull FunctionDescriptor function, @NotNull StringBuilder stringBuilder) {
|
public void appendAfterValueParameters(@NotNull FunctionDescriptor function, @NotNull StringBuilder builder) {
|
||||||
if (!function.getValueParameters().isEmpty()) {
|
if (!function.getValueParameters().isEmpty()) {
|
||||||
tdBold(stringBuilder, ")");
|
tdBold(builder, ")");
|
||||||
}
|
}
|
||||||
stringBuilder.append("<td style=\"white-space:nowrap;font-weight:bold;\">");
|
builder.append("<td style=\"white-space:nowrap;font-weight:bold;\">");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final DescriptorRenderer DESCRIPTOR_IN_TABLE = new DescriptorRendererBuilder()
|
public static final DescriptorRenderer DESCRIPTOR_IN_TABLE = DescriptorRenderer.Companion.withOptions(
|
||||||
.setWithDefinedIn(false)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setModifiers()
|
@Override
|
||||||
.setValueParametersHandler(VALUE_PARAMETERS_HANDLER)
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.setTextFormat(DescriptorRenderer.TextFormat.HTML).build();
|
options.setWithDefinedIn(false);
|
||||||
|
options.setModifiers(Collections.<DescriptorRenderer.Modifier>emptySet());
|
||||||
|
options.setValueParametersHandler(VALUE_PARAMETERS_HANDLER);
|
||||||
|
options.setTextFormat(DescriptorRenderer.TextFormat.HTML);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
private static void td(StringBuilder builder, String text) {
|
private static void td(StringBuilder builder, String text) {
|
||||||
builder.append("<td style=\"white-space:nowrap;\">").append(text).append("</td>");
|
builder.append("<td style=\"white-space:nowrap;\">").append(text).append("</td>");
|
||||||
|
|||||||
+16
-7
@@ -24,6 +24,8 @@ import com.intellij.psi.PsiClass;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiMember;
|
import com.intellij.psi.PsiMember;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||||
@@ -32,12 +34,13 @@ import org.jetbrains.kotlin.psi.JetClass;
|
|||||||
import org.jetbrains.kotlin.psi.JetDeclaration;
|
import org.jetbrains.kotlin.psi.JetDeclaration;
|
||||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
|
import org.jetbrains.kotlin.psi.JetNamedDeclaration;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||||
import org.jetbrains.kotlin.renderer.RendererPackage;
|
import org.jetbrains.kotlin.renderer.RendererPackage;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class DescriptorClassMember extends MemberChooserObjectBase implements ClassMemberWithElement {
|
public class DescriptorClassMember extends MemberChooserObjectBase implements ClassMemberWithElement {
|
||||||
|
|
||||||
@@ -47,12 +50,18 @@ public class DescriptorClassMember extends MemberChooserObjectBase implements Cl
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final PsiElement myPsiElement;
|
private final PsiElement myPsiElement;
|
||||||
|
|
||||||
private static final DescriptorRenderer MEMBER_RENDERER = new DescriptorRendererBuilder()
|
private static final DescriptorRenderer MEMBER_RENDERER = DescriptorRenderer.Companion.withOptions(
|
||||||
.setWithDefinedIn(false)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setModifiers()
|
@Override
|
||||||
.setStartFromName(true)
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.setNameShortness(NameShortness.SHORT)
|
options.setWithDefinedIn(false);
|
||||||
.build();
|
options.setModifiers(Collections.<DescriptorRenderer.Modifier>emptySet());
|
||||||
|
options.setStartFromName(true);
|
||||||
|
options.setNameShortness(NameShortness.SHORT);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
public DescriptorClassMember(@NotNull PsiElement element, @NotNull DeclarationDescriptor descriptor) {
|
public DescriptorClassMember(@NotNull PsiElement element, @NotNull DeclarationDescriptor descriptor) {
|
||||||
super(getText(descriptor), getIcon(element, descriptor));
|
super(getText(descriptor), getIcon(element, descriptor));
|
||||||
|
|||||||
+9
-10
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences
|
|||||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness
|
import org.jetbrains.kotlin.renderer.NameShortness
|
||||||
import org.jetbrains.kotlin.types.JetType
|
import org.jetbrains.kotlin.types.JetType
|
||||||
|
|
||||||
@@ -118,15 +117,15 @@ public abstract class OverrideImplementMethodsHandler : LanguageCodeInsightActio
|
|||||||
override fun startInWriteAction(): Boolean = false
|
override fun startInWriteAction(): Boolean = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val OVERRIDE_RENDERER = DescriptorRendererBuilder()
|
private val OVERRIDE_RENDERER = DescriptorRenderer.withOptions {
|
||||||
.setRenderDefaultValues(false)
|
renderDefaultValues = false
|
||||||
.setModifiers(DescriptorRenderer.Modifier.OVERRIDE)
|
modifiers = setOf(DescriptorRenderer.Modifier.OVERRIDE)
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setNameShortness(NameShortness.SOURCE_CODE_QUALIFIED)
|
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
|
||||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OVERRIDE)
|
overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OVERRIDE
|
||||||
.setUnitReturnType(false)
|
unitReturnType = false
|
||||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
|
||||||
.build()
|
}
|
||||||
|
|
||||||
private val LOG = Logger.getInstance(javaClass<OverrideImplementMethodsHandler>().getCanonicalName())
|
private val LOG = Logger.getInstance(javaClass<OverrideImplementMethodsHandler>().getCanonicalName())
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.psi.JetReferenceExpression
|
|||||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness
|
import org.jetbrains.kotlin.renderer.NameShortness
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||||
@@ -83,12 +82,12 @@ public class KotlinQuickDocumentationProvider : AbstractDocumentationProvider()
|
|||||||
companion object {
|
companion object {
|
||||||
private val LOG = Logger.getInstance(javaClass<KotlinQuickDocumentationProvider>())
|
private val LOG = Logger.getInstance(javaClass<KotlinQuickDocumentationProvider>())
|
||||||
|
|
||||||
val quickDocNameFormat = DescriptorRendererBuilder()
|
val quickDocNameFormat = DescriptorRenderer.withOptions {
|
||||||
.setWithDefinedIn(true)
|
withDefinedIn = true
|
||||||
.setNameShortness(NameShortness.SHORT)
|
nameShortness = NameShortness.SHORT
|
||||||
.setRenderCompanionObjectName(true)
|
renderCompanionObjectName = true
|
||||||
.setTextFormat(DescriptorRenderer.TextFormat.HTML)
|
textFormat = DescriptorRenderer.TextFormat.HTML
|
||||||
.build()
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun getText(element: PsiElement, originalElement: PsiElement?, quickNavigation: Boolean): String? {
|
private fun getText(element: PsiElement, originalElement: PsiElement?, quickNavigation: Boolean): String? {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
|||||||
import org.jetbrains.kotlin.resolve.OverrideResolver
|
import org.jetbrains.kotlin.resolve.OverrideResolver
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import com.intellij.psi.NavigatablePsiElement
|
import com.intellij.psi.NavigatablePsiElement
|
||||||
@@ -45,12 +44,12 @@ object SuperDeclarationMarkerTooltip: Function<JetDeclaration, String> {
|
|||||||
|
|
||||||
val isAbstract = elementDescriptor!!.getModality() == Modality.ABSTRACT
|
val isAbstract = elementDescriptor!!.getModality() == Modality.ABSTRACT
|
||||||
|
|
||||||
val renderer = DescriptorRendererBuilder()
|
val renderer = DescriptorRenderer.withOptions {
|
||||||
.setTextFormat(DescriptorRenderer.TextFormat.HTML)
|
textFormat = DescriptorRenderer.TextFormat.HTML
|
||||||
.setWithDefinedIn(false)
|
withDefinedIn = false
|
||||||
.setStartFromName(true)
|
startFromName = true
|
||||||
.setWithoutSuperTypes(true)
|
withoutSuperTypes = true
|
||||||
.build()
|
}
|
||||||
|
|
||||||
val containingStrings = overriddenDescriptors.map {
|
val containingStrings = overriddenDescriptors.map {
|
||||||
val declaration = it.getContainingDeclaration()
|
val declaration = it.getContainingDeclaration()
|
||||||
|
|||||||
+16
-6
@@ -31,6 +31,8 @@ import com.intellij.psi.util.PsiTreeUtil;
|
|||||||
import com.intellij.psi.util.PsiUtil;
|
import com.intellij.psi.util.PsiUtil;
|
||||||
import com.intellij.util.IncorrectOperationException;
|
import com.intellij.util.IncorrectOperationException;
|
||||||
import com.intellij.util.messages.MessageBusConnection;
|
import com.intellij.util.messages.MessageBusConnection;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor;
|
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor;
|
||||||
@@ -45,20 +47,28 @@ import org.jetbrains.kotlin.load.java.structure.impl.JavaConstructorImpl;
|
|||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaFieldImpl;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaFieldImpl;
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaMethodImpl;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaMethodImpl;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver;
|
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KOTLIN_SIGNATURE;
|
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KOTLIN_SIGNATURE;
|
||||||
|
|
||||||
public class KotlinSignatureAnnotationIntention extends BaseIntentionAction implements Iconable {
|
public class KotlinSignatureAnnotationIntention extends BaseIntentionAction implements Iconable {
|
||||||
private static final DescriptorRenderer RENDERER = new DescriptorRendererBuilder()
|
private static final DescriptorRenderer RENDERER = DescriptorRenderer.Companion.withOptions(
|
||||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setNameShortness(NameShortness.SHORT)
|
@Override
|
||||||
.setModifiers()
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.setWithDefinedIn(false).build();
|
options.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES);
|
||||||
|
options.setNameShortness(NameShortness.SHORT);
|
||||||
|
options.setModifiers(Collections.<DescriptorRenderer.Modifier>emptySet());
|
||||||
|
options.setWithDefinedIn(false);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ import com.intellij.psi.PsiDocumentManager;
|
|||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.util.IncorrectOperationException;
|
import com.intellij.util.IncorrectOperationException;
|
||||||
import com.intellij.util.PlatformIcons;
|
import com.intellij.util.PlatformIcons;
|
||||||
|
import kotlin.Unit;
|
||||||
|
import kotlin.jvm.functions.Function1;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.descriptors.*;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
@@ -46,7 +48,7 @@ import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
|||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil;
|
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil;
|
||||||
import org.jetbrains.kotlin.resolve.VisibilityUtil;
|
import org.jetbrains.kotlin.resolve.VisibilityUtil;
|
||||||
@@ -62,12 +64,19 @@ import java.util.*;
|
|||||||
* Fix that changes member function's signature to match one of super functions' signatures.
|
* Fix that changes member function's signature to match one of super functions' signatures.
|
||||||
*/
|
*/
|
||||||
public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunction> {
|
public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunction> {
|
||||||
private static final DescriptorRenderer SIGNATURE_RENDERER = new DescriptorRendererBuilder()
|
private static final DescriptorRenderer SIGNATURE_RENDERER = DescriptorRenderer.Companion.withOptions(
|
||||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
new Function1<DescriptorRendererOptions, Unit>() {
|
||||||
.setWithDefinedIn(false)
|
@Override
|
||||||
.setModifiers()
|
public Unit invoke(DescriptorRendererOptions options) {
|
||||||
.setNameShortness(NameShortness.SHORT)
|
options.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES);
|
||||||
.setUnitReturnType(false).build();
|
options.setWithDefinedIn(false);
|
||||||
|
options.setModifiers(Collections.<DescriptorRenderer.Modifier>emptySet());
|
||||||
|
options.setNameShortness(NameShortness.SHORT);
|
||||||
|
options.setUnitReturnType(false);
|
||||||
|
return Unit.INSTANCE$;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
private final List<FunctionDescriptor> possibleSignatures;
|
private final List<FunctionDescriptor> possibleSignatures;
|
||||||
|
|
||||||
|
|||||||
+10
-12
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.psi.JetNamedFunction
|
|||||||
import org.jetbrains.kotlin.psi.JetProperty
|
import org.jetbrains.kotlin.psi.JetProperty
|
||||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
|
||||||
import org.jetbrains.kotlin.renderer.NameShortness
|
import org.jetbrains.kotlin.renderer.NameShortness
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||||
@@ -149,17 +148,16 @@ public class DeprecatedSymbolUsageInWholeProjectFix(
|
|||||||
|
|
||||||
companion object : JetSingleIntentionActionFactory() {
|
companion object : JetSingleIntentionActionFactory() {
|
||||||
//TODO: better rendering needed
|
//TODO: better rendering needed
|
||||||
private val RENDERER = DescriptorRendererBuilder()
|
private val RENDERER = DescriptorRenderer.withOptions {
|
||||||
.setModifiers()
|
modifiers = emptySet()
|
||||||
.setNameShortness(NameShortness.SHORT)
|
nameShortness = NameShortness.SHORT
|
||||||
// .setWithoutTypeParameters(true)
|
parameterNameRenderingPolicy = DescriptorRenderer.ParameterNameRenderingPolicy.NONE
|
||||||
.setParameterNameRenderingPolicy(DescriptorRenderer.ParameterNameRenderingPolicy.NONE)
|
receiverAfterName = true
|
||||||
.setReceiverAfterName(true)
|
renderCompanionObjectName = true
|
||||||
.setRenderCompanionObjectName(true)
|
withoutSuperTypes = true
|
||||||
.setWithoutSuperTypes(true)
|
startFromName = true
|
||||||
.setStartFromName(true)
|
withDefinedIn = false
|
||||||
.setWithDefinedIn(false)
|
}
|
||||||
.build()
|
|
||||||
|
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val nameExpression = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return null
|
val nameExpression = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return null
|
||||||
|
|||||||
Reference in New Issue
Block a user