Rename: NameShortness -> ClassifierNamePolicy

This commit is contained in:
Pavel V. Talanov
2016-02-18 17:15:18 +03:00
parent ced5a6c917
commit c7cb596f74
15 changed files with 46 additions and 46 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -141,7 +141,7 @@ abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment() {
})
val renderer = DescriptorRenderer.withOptions {
nameShortness = NameShortness.FULLY_QUALIFIED
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
modifiers = DescriptorRendererModifier.ALL
}
val renderedDescriptors = descriptors.map { renderer.render(it) }.joinToString(separator = "\n")
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -54,7 +54,7 @@ abstract class AbstractFunctionDescriptorInExpressionRendererTest : KotlinTestWi
})
val renderer = DescriptorRenderer.withOptions {
nameShortness = NameShortness.FULLY_QUALIFIED
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
modifiers = DescriptorRendererModifier.ALL
verbose = true
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier;
import org.jetbrains.kotlin.renderer.DescriptorRendererOptions;
import org.jetbrains.kotlin.renderer.NameShortness;
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
@@ -61,7 +61,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinLite
@Override
public Unit invoke(DescriptorRendererOptions options) {
options.setVerbose(true);
options.setNameShortness(NameShortness.SHORT.INSTANCE);
options.setClassifierNamePolicy(ClassifierNamePolicy.SHORT.INSTANCE);
options.setModifiers(DescriptorRendererModifier.ALL);
return Unit.INSTANCE;
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -54,7 +54,7 @@ public class RecursiveDescriptorComparator {
options.setExcludedAnnotationClasses(Collections.singleton(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)));
options.setOverrideRenderingPolicy(OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE);
options.setIncludePropertyConstant(true);
options.setNameShortness(NameShortness.FULLY_QUALIFIED.INSTANCE);
options.setClassifierNamePolicy(ClassifierNamePolicy.FULLY_QUALIFIED.INSTANCE);
options.setVerbose(true);
options.setModifiers(DescriptorRendererModifier.ALL);
return Unit.INSTANCE;
@@ -21,8 +21,8 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import java.util.*
interface NameShortness {
object SHORT : NameShortness {
interface ClassifierNamePolicy {
object SHORT : ClassifierNamePolicy {
override fun renderClassifier(classifier: ClassifierDescriptor, renderer: DescriptorRenderer): String {
if (classifier is TypeParameterDescriptor) return renderer.renderName(classifier.name)
@@ -40,7 +40,7 @@ interface NameShortness {
}
}
object FULLY_QUALIFIED : NameShortness {
object FULLY_QUALIFIED : ClassifierNamePolicy {
override fun renderClassifier(classifier: ClassifierDescriptor, renderer: DescriptorRenderer): String {
if (classifier is TypeParameterDescriptor) return renderer.renderName(classifier.name)
@@ -49,7 +49,7 @@ interface NameShortness {
}
// for local declarations qualified up to function scope
object SOURCE_CODE_QUALIFIED : NameShortness {
object SOURCE_CODE_QUALIFIED : ClassifierNamePolicy {
override fun renderClassifier(classifier: ClassifierDescriptor, renderer: DescriptorRenderer): String {
return qualifiedNameForSourceCode(classifier)
}
@@ -105,14 +105,14 @@ abstract class DescriptorRenderer {
@JvmField val COMPACT_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
modifiers = emptySet()
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
}
@JvmField val ONLY_NAMES_WITH_SHORT_TYPES: DescriptorRenderer = withOptions {
withDefinedIn = false
modifiers = emptySet()
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
withoutTypeParameters = true
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
receiverAfterName = true
@@ -126,13 +126,13 @@ abstract class DescriptorRenderer {
}
@JvmField val SHORT_NAMES_IN_TYPES: DescriptorRenderer = withOptions {
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ONLY_NON_SYNTHESIZED
}
@JvmField val DEBUG_TEXT: DescriptorRenderer = withOptions {
debugMode = true
nameShortness = NameShortness.FULLY_QUALIFIED
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
modifiers = DescriptorRendererModifier.ALL
}
@@ -162,7 +162,7 @@ abstract class DescriptorRenderer {
}
interface DescriptorRendererOptions {
var nameShortness: NameShortness
var classifierNamePolicy: ClassifierNamePolicy
var withDefinedIn: Boolean
var modifiers: Set<DescriptorRendererModifier>
var startFromName: Boolean
@@ -123,7 +123,7 @@ internal class DescriptorRendererImpl(
if (ErrorUtils.isError(klass)) {
return klass.typeConstructor.toString()
}
return nameShortness.renderClassifier(klass, this)
return classifierNamePolicy.renderClassifier(klass, this)
}
/* TYPES RENDERING */
@@ -143,7 +143,7 @@ internal class DescriptorRendererImpl(
return renderFlexibleTypeWithBothBounds(type.flexibility().lowerBound, type.flexibility().upperBound)
}
else if (flexibleTypesForCode) {
val prefix = if (nameShortness == NameShortness.SHORT) "" else Flexibility.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString() + "."
val prefix = if (classifierNamePolicy == ClassifierNamePolicy.SHORT) "" else Flexibility.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString() + "."
return prefix + Flexibility.FLEXIBLE_TYPE_CLASSIFIER.relativeClassName + lt() + renderNormalizedType(type.flexibility().lowerBound) + ", " + renderNormalizedType(type.flexibility().upperBound) + gt()
}
else {
@@ -203,7 +203,7 @@ internal class DescriptorRendererImpl(
}
val kotlinCollectionsPrefix = nameShortness.renderClassifier(type.builtIns.collection, this).substringBefore("Collection")
val kotlinCollectionsPrefix = classifierNamePolicy.renderClassifier(type.builtIns.collection, this).substringBefore("Collection")
val mutablePrefix = "Mutable"
// java.util.List<Foo> -> (Mutable)List<Foo!>!
val simpleCollection = replacePrefixes(lowerRendered, kotlinCollectionsPrefix + mutablePrefix, upperRendered, kotlinCollectionsPrefix, kotlinCollectionsPrefix + "(" + mutablePrefix + ")")
@@ -212,7 +212,7 @@ internal class DescriptorRendererImpl(
val mutableEntry = replacePrefixes(lowerRendered, kotlinCollectionsPrefix + "MutableMap.MutableEntry", upperRendered, kotlinCollectionsPrefix + "Map.Entry", kotlinCollectionsPrefix + "(Mutable)Map.(Mutable)Entry")
if (mutableEntry != null) return mutableEntry
val kotlinPrefix = nameShortness.renderClassifier(type.builtIns.array, this).substringBefore("Array")
val kotlinPrefix = classifierNamePolicy.renderClassifier(type.builtIns.array, this).substringBefore("Array")
// Foo[] -> Array<(out) Foo!>!
val array = replacePrefixes(lowerRendered, kotlinPrefix + escape("Array<"), upperRendered, kotlinPrefix + escape("Array<out "), kotlinPrefix + escape("Array<(out) "))
if (array != null) return array
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -63,7 +63,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
}
}
override var nameShortness: NameShortness by property(NameShortness.SOURCE_CODE_QUALIFIED)
override var classifierNamePolicy: ClassifierNamePolicy by property(ClassifierNamePolicy.SOURCE_CODE_QUALIFIED)
override var withDefinedIn by property(true)
override var modifiers: Set<DescriptorRendererModifier> by property(DescriptorRendererModifier.DEFAULTS)
override var startFromName by property(false)
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.util
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.isDynamic
@@ -54,17 +54,17 @@ object IdeDescriptorRenderers {
}
@JvmField val SOURCE_CODE: DescriptorRenderer = BASE.withOptions {
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
}
@JvmField val SOURCE_CODE_FOR_TYPE_ARGUMENTS: DescriptorRenderer = BASE.withOptions {
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS(unwrapAnonymousType(it)) }
}
@JvmField val SOURCE_CODE_SHORT_NAMES_IN_TYPES: DescriptorRenderer = BASE.withOptions {
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.RenderingFormat
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.hasTypeMismatchErrorOnParameter
@@ -42,7 +42,7 @@ fun renderStrong(o: Any, error: Boolean): String = (if (error) RED_TEMPLATE else
private val HTML_FOR_UNINFERRED_TYPE_PARAMS: DescriptorRenderer = DescriptorRenderer.withOptions {
uninferredTypeParameterAsName = true
modifiers = emptySet()
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
textFormat = RenderingFormat.HTML
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -100,7 +100,7 @@ private val OVERRIDE_RENDERER = DescriptorRenderer.withOptions {
renderDefaultValues = false
modifiers = setOf(DescriptorRendererModifier.OVERRIDE)
withDefinedIn = false
nameShortness = NameShortness.SOURCE_CODE_QUALIFIED
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
unitReturnType = false
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.render
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import javax.swing.Icon
@@ -70,7 +70,7 @@ open class DescriptorMemberChooserObject(
withDefinedIn = false
modifiers = emptySet()
startFromName = true
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
}
fun getText(descriptor: DeclarationDescriptor): String {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.psi.KtReferenceExpression
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
@@ -84,7 +84,7 @@ class KotlinQuickDocumentationProvider : AbstractDocumentationProvider() {
private val LOG = Logger.getInstance(KotlinQuickDocumentationProvider::class.java)
private val DESCRIPTOR_RENDERER = DescriptorRenderer.HTML.withOptions {
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
renderCompanionObjectName = true
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.psi.KtParameterList
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.descriptorUtil.setSingleOverridden
import org.jetbrains.kotlin.resolve.findMemberWithMaxVisibility
@@ -72,7 +72,7 @@ class ChangeMemberFunctionSignatureFix private constructor(
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
withDefinedIn = false
modifiers = emptySet()
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
unitReturnType = false
renderDefaultValues = false
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
* Copyright 2010-2016 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.
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.idea.util.application.runReadAction
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.renderer.DescriptorRenderer
import org.jetbrains.kotlin.renderer.NameShortness
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
class DeprecatedSymbolUsageInWholeProjectFix(
@@ -122,7 +122,7 @@ class DeprecatedSymbolUsageInWholeProjectFix(
//TODO: better rendering needed
private val RENDERER = DescriptorRenderer.withOptions {
modifiers = emptySet()
nameShortness = NameShortness.SHORT
classifierNamePolicy = ClassifierNamePolicy.SHORT
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
receiverAfterName = true
renderCompanionObjectName = true