KT-6566 Generate Override/Implement method does not work for locally declared classes
#KT-6566 Fixed
This commit is contained in:
@@ -129,7 +129,8 @@ public abstract class AbstractDescriptorRendererTest : KotlinTestWithEnvironment
|
||||
}
|
||||
})
|
||||
|
||||
val renderedDescriptors = descriptors.map { DescriptorRenderer.FQ_NAMES_IN_TYPES.render(it) }.joinToString(separator = "\n")
|
||||
val renderer = DescriptorRendererBuilder().setNameShortness(NameShortness.FULLY_QUALIFIED).build()
|
||||
val renderedDescriptors = descriptors.map { renderer.render(it) }.joinToString(separator = "\n")
|
||||
|
||||
val document = DocumentImpl(psiFile.getText())
|
||||
UsefulTestCase.assertSameLines(JetTestUtils.getLastCommentedLines(document), renderedDescriptors.toString())
|
||||
|
||||
+4
-3
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.psi.JetAnnotationEntry;
|
||||
import org.jetbrains.kotlin.psi.JetFile;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.test.JetLiteFixture;
|
||||
@@ -46,9 +47,9 @@ import java.util.List;
|
||||
|
||||
public abstract class AbstractAnnotationDescriptorResolveTest extends JetLiteFixture {
|
||||
private static final DescriptorRenderer WITH_ANNOTATION_ARGUMENT_TYPES = new DescriptorRendererBuilder()
|
||||
.setVerbose(true)
|
||||
.setShortNames(true)
|
||||
.build();
|
||||
.setVerbose(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.build();
|
||||
|
||||
private static final String PATH = "compiler/testData/resolveAnnotations/testFile.kt";
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.jvm.compiler.ExpectedLoadErrorsUtil;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
@@ -51,6 +52,7 @@ public class RecursiveDescriptorComparator {
|
||||
.setExcludedAnnotationClasses(Arrays.asList(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)))
|
||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE)
|
||||
.setIncludePropertyConstant(true)
|
||||
.setNameShortness(NameShortness.FULLY_QUALIFIED)
|
||||
.setVerbose(true).build();
|
||||
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.renderer;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
@@ -37,7 +38,7 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
|
||||
DescriptorRenderer COMPACT_WITH_SHORT_TYPES = new DescriptorRendererBuilder()
|
||||
.setModifiers()
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setIncludeSynthesizedParameterNames(false).build();
|
||||
|
||||
DescriptorRenderer STARTS_FROM_NAME = new DescriptorRendererBuilder()
|
||||
@@ -48,7 +49,7 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
DescriptorRenderer ONLY_NAMES_WITH_SHORT_TYPES = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setModifiers()
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setWithoutTypeParameters(true)
|
||||
.setWithoutFunctionParameterNames(true)
|
||||
.setReceiverAfterName(true)
|
||||
@@ -58,9 +59,12 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
|
||||
DescriptorRenderer FQ_NAMES_IN_TYPES = new DescriptorRendererBuilder().build();
|
||||
|
||||
DescriptorRenderer SHORT_NAMES_IN_TYPES = new DescriptorRendererBuilder().setShortNames(true).setIncludeSynthesizedParameterNames(false).build();
|
||||
DescriptorRenderer SHORT_NAMES_IN_TYPES = new DescriptorRendererBuilder().setNameShortness(NameShortness.SHORT).setIncludeSynthesizedParameterNames(false).build();
|
||||
|
||||
DescriptorRenderer DEBUG_TEXT = new DescriptorRendererBuilder().setDebugMode(true).build();
|
||||
DescriptorRenderer DEBUG_TEXT = new DescriptorRendererBuilder()
|
||||
.setDebugMode(true)
|
||||
.setNameShortness(NameShortness.FULLY_QUALIFIED)
|
||||
.build();
|
||||
|
||||
DescriptorRenderer FLEXIBLE_TYPES_FOR_CODE = new DescriptorRendererBuilder()
|
||||
.setFlexibleTypesForCode(true)
|
||||
@@ -72,7 +76,7 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
|
||||
DescriptorRenderer HTML_NAMES_WITH_SHORT_TYPES = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setRenderClassObjectName(true)
|
||||
.setTextFormat(TextFormat.HTML).build();
|
||||
|
||||
@@ -81,7 +85,7 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
DescriptorRenderer HTML_FOR_UNINFERRED_TYPE_PARAMS = new DescriptorRendererBuilder()
|
||||
.setUninferredTypeParameterAsName(true)
|
||||
.setModifiers()
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setTextFormat(TextFormat.HTML).build();
|
||||
|
||||
@NotNull
|
||||
@@ -90,6 +94,9 @@ public interface DescriptorRenderer extends Renderer<DeclarationDescriptor> {
|
||||
@NotNull
|
||||
String renderTypeArguments(@NotNull List<TypeProjection> typeArguments);
|
||||
|
||||
@NotNull
|
||||
String renderClassifierName(@NotNull ClassifierDescriptor klass);
|
||||
|
||||
@NotNull
|
||||
String renderAnnotation(@NotNull AnnotationDescriptor annotation);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class DescriptorRendererBuilder {
|
||||
private boolean shortNames = false;
|
||||
private NameShortness nameShortness = NameShortness.SOURCE_CODE_QUALIFIED;
|
||||
private boolean withDefinedIn = true;
|
||||
private Set<DescriptorRenderer.Modifier> modifiers = EnumSet.allOf(DescriptorRenderer.Modifier.class);
|
||||
private boolean startFromName = false;
|
||||
@@ -69,8 +69,8 @@ public class DescriptorRendererBuilder {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DescriptorRendererBuilder setShortNames(boolean shortNames) {
|
||||
this.shortNames = shortNames;
|
||||
public DescriptorRendererBuilder setNameShortness(NameShortness shortness) {
|
||||
this.nameShortness = shortness;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ public class DescriptorRendererBuilder {
|
||||
@NotNull
|
||||
public DescriptorRenderer build() {
|
||||
return new DescriptorRendererImpl(
|
||||
shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, verbose, unitReturnType,
|
||||
nameShortness, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor, verbose, unitReturnType,
|
||||
normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName,
|
||||
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant,
|
||||
includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName,
|
||||
|
||||
@@ -47,7 +47,7 @@ import static org.jetbrains.kotlin.types.TypeUtils.CANT_INFER_LAMBDA_PARAM_TYPE;
|
||||
public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
|
||||
private final Function1<JetType, JetType> typeNormalizer;
|
||||
private final boolean shortNames;
|
||||
private final NameShortness nameShortness;
|
||||
private final boolean withDefinedIn;
|
||||
private final Set<DescriptorRenderer.Modifier> modifiers;
|
||||
private final boolean startFromName;
|
||||
@@ -79,7 +79,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
private final Set<FqName> excludedAnnotationClasses;
|
||||
|
||||
/* package */ DescriptorRendererImpl(
|
||||
boolean shortNames,
|
||||
NameShortness nameShortness,
|
||||
boolean withDefinedIn,
|
||||
Set<Modifier> modifiers,
|
||||
boolean startFromName,
|
||||
@@ -106,7 +106,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
boolean renderDefaultValues,
|
||||
boolean flexibleTypesForCode
|
||||
) {
|
||||
this.shortNames = shortNames;
|
||||
this.nameShortness = nameShortness;
|
||||
this.withDefinedIn = withDefinedIn;
|
||||
this.modifiers = modifiers;
|
||||
this.startFromName = startFromName;
|
||||
@@ -271,31 +271,42 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
private String renderClassName(@NotNull ClassDescriptor klass) {
|
||||
public String renderClassifierName(@NotNull ClassifierDescriptor klass) {
|
||||
if (klass instanceof MissingDependencyErrorClass) {
|
||||
return ((MissingDependencyErrorClass) klass).getFullFqName().asString();
|
||||
}
|
||||
if (ErrorUtils.isError(klass)) {
|
||||
return klass.getTypeConstructor().toString();
|
||||
}
|
||||
if (shortNames) {
|
||||
List<Name> qualifiedNameElements = new ArrayList<Name>();
|
||||
switch (nameShortness) {
|
||||
case SHORT: {
|
||||
List<Name> qualifiedNameElements = new ArrayList<Name>();
|
||||
|
||||
// for nested classes qualified name should be used
|
||||
DeclarationDescriptor current = klass;
|
||||
do {
|
||||
if (((ClassDescriptor) current).getKind() != ClassKind.CLASS_OBJECT) {
|
||||
qualifiedNameElements.add(current.getName());
|
||||
// for nested classes qualified name should be used
|
||||
DeclarationDescriptor current = klass;
|
||||
do {
|
||||
if (((ClassDescriptor) current).getKind() != ClassKind.CLASS_OBJECT) {
|
||||
qualifiedNameElements.add(current.getName());
|
||||
}
|
||||
current = current.getContainingDeclaration();
|
||||
}
|
||||
current = current.getContainingDeclaration();
|
||||
}
|
||||
while (current instanceof ClassDescriptor);
|
||||
while (current instanceof ClassDescriptor);
|
||||
|
||||
Collections.reverse(qualifiedNameElements);
|
||||
return renderFqName(qualifiedNameElements);
|
||||
Collections.reverse(qualifiedNameElements);
|
||||
return renderFqName(qualifiedNameElements);
|
||||
}
|
||||
|
||||
case FULLY_QUALIFIED:
|
||||
return renderFqName(DescriptorUtils.getFqName(klass));
|
||||
|
||||
case SOURCE_CODE_QUALIFIED:
|
||||
return RendererPackage.qualifiedNameForSourceCode(klass);
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return renderFqName(DescriptorUtils.getFqName(klass));
|
||||
}
|
||||
|
||||
/* TYPES RENDERING */
|
||||
@@ -319,7 +330,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
TypesPackage.flexibility(type).getUpperBound());
|
||||
}
|
||||
else if (flexibleTypesForCode) {
|
||||
String prefix = shortNames ? "" : Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString() + ".";
|
||||
String prefix = nameShortness == NameShortness.SHORT ? "" : Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getPackageFqName().asString() + ".";
|
||||
return prefix + Flexibility.FLEXIBLE_TYPE_CLASSIFIER.getRelativeClassName()
|
||||
+ lt()
|
||||
+ renderNormalizedType(TypesPackage.flexibility(type).getLowerBound()) + ", "
|
||||
@@ -378,7 +389,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
return lowerRendered + "!";
|
||||
}
|
||||
|
||||
String kotlinPrefix = !shortNames ? "kotlin." : "";
|
||||
String kotlinPrefix = nameShortness != NameShortness.SHORT ? "kotlin." : "";
|
||||
String mutablePrefix = "Mutable";
|
||||
// java.util.List<Foo> -> (Mutable)List<Foo!>!
|
||||
String simpleCollection = replacePrefixes(
|
||||
@@ -458,7 +469,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
return renderName(cd.getName());
|
||||
}
|
||||
else if (cd instanceof ClassDescriptor) {
|
||||
return renderClassName((ClassDescriptor) cd);
|
||||
return renderClassifierName((ClassDescriptor) cd);
|
||||
}
|
||||
else {
|
||||
assert cd == null: "Unexpected classifier: " + cd.getClass();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public enum NameShortness {
|
||||
SHORT,
|
||||
FULLY_QUALIFIED,
|
||||
SOURCE_CODE_QUALIFIED // for local declarations qualified up to function scope
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.descriptors.*
|
||||
|
||||
public fun qualifiedNameForSourceCode(descriptor: ClassifierDescriptor): String {
|
||||
val nameString = DescriptorRenderer.COMPACT.renderName(descriptor.getName())
|
||||
val qualifier = qualifierName(descriptor.getContainingDeclaration())
|
||||
return if (qualifier != null && qualifier != "") qualifier + "." + nameString else nameString
|
||||
}
|
||||
|
||||
private fun qualifierName(descriptor: DeclarationDescriptor): String? = when (descriptor) {
|
||||
is ClassDescriptor -> if (descriptor.getKind() != ClassKind.CLASS_OBJECT) qualifiedNameForSourceCode(descriptor) else qualifierName(descriptor.getContainingDeclaration())
|
||||
is PackageFragmentDescriptor -> DescriptorRenderer.COMPACT.renderFqName(descriptor.fqName)
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.util;
|
||||
import kotlin.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 {
|
||||
@@ -38,17 +39,17 @@ public class IdeDescriptorRenderers {
|
||||
};
|
||||
|
||||
public static final DescriptorRenderer SOURCE_CODE = commonBuilder()
|
||||
.setShortNames(false)
|
||||
.setNameShortness(NameShortness.SOURCE_CODE_QUALIFIED)
|
||||
.setTypeNormalizer(APPROXIMATE_FLEXIBLE_TYPES)
|
||||
.build();
|
||||
|
||||
public static final DescriptorRenderer SOURCE_CODE_FOR_TYPE_ARGUMENTS = commonBuilder()
|
||||
.setShortNames(false)
|
||||
.setNameShortness(NameShortness.SOURCE_CODE_QUALIFIED)
|
||||
.setTypeNormalizer(APPROXIMATE_FLEXIBLE_TYPES_IN_ARGUMENTS)
|
||||
.build();
|
||||
|
||||
public static final DescriptorRenderer SOURCE_CODE_SHORT_NAMES_IN_TYPES = commonBuilder()
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setTypeNormalizer(APPROXIMATE_FLEXIBLE_TYPES)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -54,7 +55,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
.setRenderDefaultValues(false)
|
||||
.setModifiers(DescriptorRenderer.Modifier.OVERRIDE)
|
||||
.setWithDefinedIn(false)
|
||||
.setShortNames(false)
|
||||
.setNameShortness(NameShortness.SOURCE_CODE_QUALIFIED)
|
||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OVERRIDE)
|
||||
.setUnitReturnType(false)
|
||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
||||
|
||||
@@ -22,10 +22,6 @@ import com.intellij.codeInsight.lookup.AutoCompletionPolicy
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.codeInsight.completion.CompletionService
|
||||
import com.intellij.codeInsight.completion.CompletionProgressIndicator
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher
|
||||
@@ -66,6 +62,8 @@ import org.jetbrains.kotlin.psi.JetDeclarationWithBody
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.completion.handlers.WithTailInsertHandler
|
||||
import org.jetbrains.kotlin.psi.JetLoopExpression
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder
|
||||
import org.jetbrains.kotlin.renderer.NameShortness
|
||||
|
||||
enum class ItemPriority {
|
||||
MULTIPLE_ARGUMENTS_ITEM
|
||||
@@ -109,21 +107,6 @@ fun rethrowWithCancelIndicator(exception: ProcessCanceledException): ProcessCanc
|
||||
return exception
|
||||
}
|
||||
|
||||
fun qualifiedNameForSourceCode(descriptor: ClassifierDescriptor): String? {
|
||||
val name = descriptor.getName()
|
||||
if (name.isSpecial()) return null
|
||||
val nameString = IdeDescriptorRenderers.SOURCE_CODE.renderName(name)
|
||||
val qualifier = qualifierName(descriptor.getContainingDeclaration())
|
||||
return if (qualifier != null && qualifier != "") qualifier + "." + nameString else nameString
|
||||
}
|
||||
|
||||
private fun qualifierName(descriptor: DeclarationDescriptor): String? = when (descriptor) {
|
||||
is ClassDescriptor -> if (descriptor.getKind() != ClassKind.CLASS_OBJECT) qualifiedNameForSourceCode(descriptor) else qualifierName(descriptor.getContainingDeclaration())
|
||||
is PackageViewDescriptor -> IdeDescriptorRenderers.SOURCE_CODE.renderFqName(descriptor.getFqName())
|
||||
is PackageFragmentDescriptor -> IdeDescriptorRenderers.SOURCE_CODE.renderFqName(descriptor.fqName)
|
||||
else -> null
|
||||
}
|
||||
|
||||
fun PrefixMatcher.asNameFilter() = { (name: Name) -> !name.isSpecial() && prefixMatches(name.getIdentifier()) }
|
||||
|
||||
fun LookupElementPresentation.prependTailText(text: String, grayed: Boolean) {
|
||||
|
||||
+2
-2
@@ -43,11 +43,11 @@ import org.jetbrains.kotlin.psi.JetBinaryExpressionWithTypeRHS
|
||||
import org.jetbrains.kotlin.idea.codeInsight.ShortenReferences
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.idea.completion.qualifiedNameForSourceCode
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.JetTypeArgumentList
|
||||
import com.intellij.codeInsight.lookup.Lookup
|
||||
import org.jetbrains.kotlin.idea.completion.isAfterDot
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
|
||||
public abstract class KotlinCallableInsertHandler : BaseDeclarationInsertHandler() {
|
||||
public override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||
@@ -257,7 +257,7 @@ object CastReceiverInsertHandler : KotlinCallableInsertHandler() {
|
||||
val project = context.getProject()
|
||||
|
||||
val thisObj = if (descriptor.getExtensionReceiverParameter() != null) descriptor.getExtensionReceiverParameter() else descriptor.getDispatchReceiverParameter()
|
||||
val fqName = qualifiedNameForSourceCode(thisObj.getType().getConstructor().getDeclarationDescriptor())
|
||||
val fqName = IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(thisObj.getType().getConstructor().getDeclarationDescriptor())
|
||||
|
||||
val parentCast = JetPsiFactory(project).createExpression("(expr as $fqName)") as JetParenthesizedExpression
|
||||
val cast = parentCast.getExpression() as JetBinaryExpressionWithTypeRHS
|
||||
|
||||
@@ -23,13 +23,13 @@ import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.idea.codeInsight.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.completion.DeclarationDescriptorLookupObject
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.idea.completion.qualifiedNameForSourceCode
|
||||
import com.intellij.psi.PsiClass
|
||||
import org.jetbrains.kotlin.psi.JetNameReferenceExpression
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.idea.completion.isAfterDot
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
|
||||
public object KotlinClassInsertHandler : BaseDeclarationInsertHandler() {
|
||||
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||
@@ -52,7 +52,7 @@ public object KotlinClassInsertHandler : BaseDeclarationInsertHandler() {
|
||||
if (nameRef != null) {
|
||||
val bindingContext = nameRef.getResolutionFacade().analyze(nameRef, BodyResolveMode.PARTIAL)
|
||||
val target = bindingContext[BindingContext.REFERENCE_TARGET, nameRef] as? ClassDescriptor
|
||||
if (target != null && qualifiedNameForSourceCode(target) == qualifiedName) return
|
||||
if (target != null && IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(target) == qualifiedName) return
|
||||
}
|
||||
|
||||
val tempPrefix = if (nameRef != null)
|
||||
@@ -83,7 +83,7 @@ public object KotlinClassInsertHandler : BaseDeclarationInsertHandler() {
|
||||
private fun qualifiedNameToInsert(item: LookupElement): String {
|
||||
val lookupObject = item.getObject()
|
||||
return when (lookupObject) {
|
||||
is DeclarationDescriptorLookupObject -> qualifiedNameForSourceCode(lookupObject.descriptor as ClassDescriptor)!!
|
||||
is DeclarationDescriptorLookupObject -> IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(lookupObject.descriptor as ClassDescriptor)
|
||||
is PsiClass -> lookupObject.getQualifiedName()!!
|
||||
else -> error("Unknown object in LookupElement with KotlinClassInsertHandler: $lookupObject")
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import com.intellij.codeInsight.completion.InsertionContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.idea.completion.ExpectedInfo
|
||||
import org.jetbrains.kotlin.idea.completion.qualifiedNameForSourceCode
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolutionFacade
|
||||
@@ -35,6 +33,7 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.idea.util.fuzzyReturnType
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.idea.completion.isVisible
|
||||
import org.jetbrains.kotlin.idea.completion.ExpectedInfo
|
||||
|
||||
// adds java static members, enum members and members from class object
|
||||
class StaticMembers(
|
||||
@@ -103,7 +102,7 @@ class StaticMembers(
|
||||
private fun createLookupElement(memberDescriptor: DeclarationDescriptor, classDescriptor: ClassDescriptor): LookupElement {
|
||||
val lookupElement = lookupElementFactory.createLookupElement(memberDescriptor, resolutionFacade, bindingContext, false)
|
||||
val qualifierPresentation = classDescriptor.getName().asString()
|
||||
val qualifierText = qualifiedNameForSourceCode(classDescriptor)
|
||||
val qualifierText = IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classDescriptor)
|
||||
|
||||
return object: LookupElementDecorator<LookupElement>(lookupElement) {
|
||||
override fun getAllLookupStrings(): Set<String> {
|
||||
|
||||
@@ -164,7 +164,7 @@ class TypeInstantiationItems(
|
||||
var signatureText: String? = null
|
||||
|
||||
val insertHandler: InsertHandler<LookupElement>
|
||||
val typeText = qualifiedNameForSourceCode(classifier) + IdeDescriptorRenderers.SOURCE_CODE.renderTypeArguments(typeArgsToUse)
|
||||
val typeText = IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(classifier) + IdeDescriptorRenderers.SOURCE_CODE.renderTypeArguments(typeArgsToUse)
|
||||
if (isAbstract) {
|
||||
val constructorParenthesis = if (classifier.getKind() != ClassKind.TRAIT) "()" else ""
|
||||
itemText += constructorParenthesis
|
||||
|
||||
+2
-1
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.load.java.structure.impl.JavaFieldImpl;
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaMethodImpl;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPackage;
|
||||
|
||||
@@ -55,7 +56,7 @@ import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KOTLIN_SIGNATURE
|
||||
public class KotlinSignatureAnnotationIntention extends BaseIntentionAction implements Iconable {
|
||||
private static final DescriptorRenderer RENDERER = new DescriptorRendererBuilder()
|
||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setModifiers()
|
||||
.setWithDefinedIn(false).build();
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRendererBuilder;
|
||||
import org.jetbrains.kotlin.renderer.NameShortness;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil;
|
||||
import org.jetbrains.kotlin.resolve.VisibilityUtil;
|
||||
@@ -65,7 +66,7 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
.setTypeNormalizer(IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES)
|
||||
.setWithDefinedIn(false)
|
||||
.setModifiers()
|
||||
.setShortNames(true)
|
||||
.setNameShortness(NameShortness.SHORT)
|
||||
.setUnitReturnType(false).build();
|
||||
|
||||
private final List<FunctionDescriptor> possibleSignatures;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
abstract class C<A> {
|
||||
abstract fun f(a: A)
|
||||
}
|
||||
|
||||
fun f() {
|
||||
class R
|
||||
|
||||
object : C<R> {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
abstract class C<A> {
|
||||
abstract fun f(a: A)
|
||||
}
|
||||
|
||||
fun f() {
|
||||
class R
|
||||
|
||||
object : C<R> {
|
||||
override fun f(a: R) {
|
||||
<selection><caret>throw UnsupportedOperationException()</selection>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
object {}
|
||||
|
||||
// RESULT: Cannot perform an action because following types are unavailable from debugger scope: errors.MyClass.baseFun.<no name provided>
|
||||
// RESULT: Cannot perform an action because following types are unavailable from debugger scope: <no name provided>
|
||||
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.A
|
||||
Cannot extract method since following types are not denotable in the target scope: A
|
||||
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.A
|
||||
Cannot extract method since following types are not denotable in the target scope: A
|
||||
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.A
|
||||
Cannot extract method since following types are not denotable in the target scope: A
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.<no name provided>
|
||||
Cannot extract method since following types are not denotable in the target scope: <no name provided>
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.<no name provided>
|
||||
Cannot extract method since following types are not denotable in the target scope: <no name provided>
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.T
|
||||
Cannot extract method since following types are not denotable in the target scope: T
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.X
|
||||
Cannot extract method since following types are not denotable in the target scope: X
|
||||
+1
-1
@@ -1 +1 @@
|
||||
Cannot extract method since following types are not denotable in the target scope: foo.X
|
||||
Cannot extract method since following types are not denotable in the target scope: X
|
||||
@@ -193,4 +193,8 @@ public final class OverrideImplementTest extends AbstractOverrideImplementTest {
|
||||
public void testMultipleSupers() {
|
||||
doMultiOverrideFileTest();
|
||||
}
|
||||
|
||||
public void testLocalClass() {
|
||||
doImplementFileTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user