Reduced number of constant renderers in DescriptorRenderer
This commit is contained in:
+17
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.diagnostics.rendering;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,6 +30,8 @@ import org.jetbrains.kotlin.lexer.JetModifierKeywordToken;
|
||||
import org.jetbrains.kotlin.psi.JetExpression;
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.kotlin.psi.JetTypeConstraint;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
|
||||
import org.jetbrains.kotlin.renderer.MultiRenderer;
|
||||
import org.jetbrains.kotlin.renderer.Renderer;
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker.VarianceConflictDiagnosticData;
|
||||
@@ -94,6 +97,18 @@ public class DefaultErrorMessages {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final DescriptorRenderer DEPRECATION_RENDERER = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.withOptions(
|
||||
new Function1<DescriptorRendererOptions, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(DescriptorRendererOptions options) {
|
||||
options.setWithoutTypeParameters(false);
|
||||
options.setReceiverAfterName(false);
|
||||
options.setRenderAccessors(true);
|
||||
return Unit.INSTANCE$;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
static {
|
||||
MAP.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", ELEMENT_TEXT);
|
||||
|
||||
@@ -268,8 +283,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class");
|
||||
MAP.put(COMPANION_OBJECT_NOT_ALLOWED, "A companion object is not allowed here");
|
||||
|
||||
MAP.put(DEPRECATED_SYMBOL, "''{0}'' is deprecated.", DEPRECATION);
|
||||
MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION, STRING);
|
||||
MAP.put(DEPRECATED_SYMBOL, "''{0}'' is deprecated.", DEPRECATION_RENDERER);
|
||||
MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING);
|
||||
|
||||
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
||||
MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME);
|
||||
|
||||
+1
@@ -25,3 +25,4 @@ public fun <P> renderParameter(parameter: P, renderer: Renderer<P>?): Any = rend
|
||||
public fun ClassDescriptor.renderKindWithName(): String = DescriptorRenderer.getClassKindPrefix(this) + " '" + getName() + "'"
|
||||
|
||||
public fun ClassDescriptor.renderKind(): String = DescriptorRenderer.getClassKindPrefix(this)
|
||||
|
||||
|
||||
@@ -99,12 +99,6 @@ public interface DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
|
||||
}
|
||||
|
||||
public val STARTS_FROM_NAME: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
modifiers = emptySet()
|
||||
startFromName = true
|
||||
}
|
||||
|
||||
public val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
modifiers = emptySet()
|
||||
@@ -133,43 +127,10 @@ public interface DescriptorRenderer : Renderer<DeclarationDescriptor> {
|
||||
flexibleTypesForCode = true
|
||||
}
|
||||
|
||||
public val HTML_COMPACT_WITH_MODIFIERS: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
public val HTML_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
nameShortness = NameShortness.SHORT
|
||||
renderCompanionObjectName = true
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
public val HTML: DescriptorRenderer = withOptions {
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
public val HTML_FOR_UNINFERRED_TYPE_PARAMS: DescriptorRenderer = withOptions {
|
||||
uninferredTypeParameterAsName = true
|
||||
modifiers = emptySet()
|
||||
nameShortness = NameShortness.SHORT
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
public val DEPRECATION: DescriptorRenderer = withOptions {
|
||||
withDefinedIn = false
|
||||
modifiers = emptySet()
|
||||
nameShortness = NameShortness.SHORT
|
||||
withoutTypeParameters = false
|
||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
|
||||
receiverAfterName = false
|
||||
renderCompanionObjectName = true
|
||||
renderAccessors = true
|
||||
withoutSuperTypes = true
|
||||
renderDefaultValues = false
|
||||
startFromName = true
|
||||
}
|
||||
|
||||
public fun getClassKindPrefix(klass: ClassDescriptor): String {
|
||||
if (klass.isCompanionObject()) {
|
||||
return "companion object"
|
||||
|
||||
@@ -110,7 +110,7 @@ public class IdeErrorMessages {
|
||||
MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "<html>{0} must override {1}<br />because it inherits many implementations of it</html>",
|
||||
RENDER_CLASS_OR_OBJECT, DescriptorRenderer.HTML);
|
||||
MAP.put(CONFLICTING_OVERLOADS, "<html>''{0}''<br />is already defined in {1}</html>",
|
||||
DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS, STRING);
|
||||
IdeRenderers.HTML_COMPACT_WITH_MODIFIERS, STRING);
|
||||
|
||||
MAP.put(RESULT_TYPE_MISMATCH, "<html>Function return type mismatch." +
|
||||
"<table><tr><td>Expected:</td><td>{1}</td></tr>" +
|
||||
|
||||
@@ -70,14 +70,18 @@ public object IdeRenderers {
|
||||
DescriptorRenderer.HTML.renderType(returnType)
|
||||
}
|
||||
|
||||
public val HTML_CONFLICTING_JVM_DECLARATIONS_DATA: Renderer<ConflictingJvmDeclarationsData> = Renderer<ConflictingJvmDeclarationsData> {
|
||||
public val HTML_COMPACT_WITH_MODIFIERS: DescriptorRenderer = DescriptorRenderer.HTML.withOptions {
|
||||
withDefinedIn = false
|
||||
}
|
||||
|
||||
public val HTML_CONFLICTING_JVM_DECLARATIONS_DATA: Renderer<ConflictingJvmDeclarationsData> = Renderer {
|
||||
data: ConflictingJvmDeclarationsData ->
|
||||
|
||||
val conflicts = data.signatureOrigins
|
||||
.map { it.descriptor }
|
||||
.filterNotNull()
|
||||
.sortBy(MemberComparator.INSTANCE)
|
||||
.joinToString("") { "<li>" + DescriptorRenderer.HTML_COMPACT_WITH_MODIFIERS.render(it) + "</li>\n" }
|
||||
.joinToString("") { "<li>" + HTML_COMPACT_WITH_MODIFIERS.render(it) + "</li>\n" }
|
||||
|
||||
"The following declarations have the same JVM signature (<code>${data.signature.name}${data.signature.desc}</code>):<br/>\n<ul>\n$conflicts</ul>"
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
import org.jetbrains.kotlin.renderer.RenderingFormat
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.hasTypeMismatchErrorOnParameter
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.hasUnmappedArguments
|
||||
@@ -36,8 +38,15 @@ public fun renderError(o: Any): String = RED_TEMPLATE.format(o)
|
||||
|
||||
public fun renderStrong(o: Any, error: Boolean): String = (if (error) RED_TEMPLATE else STRONG_TEMPLATE).format(o)
|
||||
|
||||
private val HTML_FOR_UNINFERRED_TYPE_PARAMS: DescriptorRenderer = DescriptorRenderer.withOptions {
|
||||
uninferredTypeParameterAsName = true
|
||||
modifiers = emptySet()
|
||||
nameShortness = NameShortness.SHORT
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
fun <D : CallableDescriptor> renderResolvedCall(resolvedCall: ResolvedCall<D>): String {
|
||||
val htmlRenderer = DescriptorRenderer.HTML_FOR_UNINFERRED_TYPE_PARAMS
|
||||
val htmlRenderer = HTML_FOR_UNINFERRED_TYPE_PARAMS
|
||||
val stringBuilder = StringBuilder("")
|
||||
val indent = " "
|
||||
|
||||
|
||||
@@ -83,13 +83,12 @@ public class KotlinQuickDocumentationProvider : AbstractDocumentationProvider()
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(javaClass<KotlinQuickDocumentationProvider>())
|
||||
|
||||
val quickDocNameFormat = DescriptorRenderer.withOptions {
|
||||
withDefinedIn = true
|
||||
private val DESCRIPTOR_RENDERER = DescriptorRenderer.HTML.withOptions {
|
||||
nameShortness = NameShortness.SHORT
|
||||
renderCompanionObjectName = true
|
||||
textFormat = RenderingFormat.HTML
|
||||
}
|
||||
|
||||
private val MIX_KOTLIN_TO_JAVA_RENDERER = DESCRIPTOR_RENDERER.withOptions { withDefinedIn = false }
|
||||
|
||||
private fun getText(element: PsiElement, originalElement: PsiElement?, quickNavigation: Boolean): String? {
|
||||
if (element is JetDeclaration) {
|
||||
@@ -126,7 +125,7 @@ public class KotlinQuickDocumentationProvider : AbstractDocumentationProvider()
|
||||
return "No documentation available"
|
||||
}
|
||||
|
||||
var renderedDecl = quickDocNameFormat.render(declarationDescriptor)
|
||||
var renderedDecl = DESCRIPTOR_RENDERER.render(declarationDescriptor)
|
||||
if (!quickNavigation) {
|
||||
renderedDecl = "<pre>" + renderedDecl + "</pre>"
|
||||
}
|
||||
@@ -141,7 +140,7 @@ public class KotlinQuickDocumentationProvider : AbstractDocumentationProvider()
|
||||
private fun mixKotlinToJava(declarationDescriptor: DeclarationDescriptor, element: PsiElement, originalElement: PsiElement?): String? {
|
||||
val originalInfo = JavaDocumentationProvider().getQuickNavigateInfo(element, originalElement)
|
||||
if (originalInfo != null) {
|
||||
val renderedDecl = DescriptorRenderer.HTML_NAMES_WITH_SHORT_TYPES.render(declarationDescriptor)
|
||||
val renderedDecl = MIX_KOTLIN_TO_JAVA_RENDERER.render(declarationDescriptor)
|
||||
return renderedDecl + "<br/>Java declaration:<br/>" + originalInfo
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user