Refactor: Remove context parameter from BindingContextUtils.descriptorToDeclaration utilities family
This commit is contained in:
@@ -37,7 +37,6 @@ import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassBody;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
@@ -57,31 +56,21 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
private final List<FunctionDescriptor> functionsToAdd;
|
||||
private final Project project;
|
||||
private final Editor editor;
|
||||
private final BindingContext bindingContext;
|
||||
|
||||
/**
|
||||
* @param project Project where action takes place.
|
||||
* @param editor Editor where modification should be done.
|
||||
* @param bindingContext BindingContext to be used for finding type declarations.
|
||||
* @param functionsToAdd List of possible functions to add.
|
||||
*/
|
||||
public JetAddFunctionToClassifierAction(
|
||||
@NotNull Project project,
|
||||
@NotNull Editor editor,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull List<FunctionDescriptor> functionsToAdd
|
||||
) {
|
||||
this.project = project;
|
||||
this.editor = editor;
|
||||
this.bindingContext = bindingContext;
|
||||
this.functionsToAdd = new ArrayList<FunctionDescriptor>(functionsToAdd);
|
||||
}
|
||||
|
||||
private static void addFunction(
|
||||
@NotNull final Project project,
|
||||
@NotNull final ClassDescriptor typeDescriptor,
|
||||
@NotNull final FunctionDescriptor functionDescriptor,
|
||||
@NotNull BindingContext bindingContext
|
||||
@NotNull final FunctionDescriptor functionDescriptor
|
||||
) {
|
||||
final String signatureString = CodeInsightUtils.createFunctionSignatureStringFromDescriptor(
|
||||
functionDescriptor,
|
||||
@@ -89,7 +78,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.getDeclaration(project, typeDescriptor, bindingContext);
|
||||
final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.getDeclaration(project, typeDescriptor);
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -177,7 +166,6 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
}
|
||||
|
||||
private void addFunction(FunctionDescriptor functionToAdd) {
|
||||
addFunction(project, (ClassDescriptor) functionToAdd.getContainingDeclaration(),
|
||||
functionToAdd, bindingContext);
|
||||
addFunction(project, (ClassDescriptor) functionToAdd.getContainingDeclaration(), functionToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.plugin.libraries.DecompiledNavigationUtils;
|
||||
import org.jetbrains.jet.plugin.references.BuiltInsReferenceResolver;
|
||||
@@ -36,23 +35,15 @@ public final class DescriptorToDeclarationUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getDeclaration(
|
||||
@NotNull JetFile file,
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
return getDeclaration(file.getProject(), descriptor, bindingContext);
|
||||
public static PsiElement getDeclaration(@NotNull JetFile file, @NotNull DeclarationDescriptor descriptor) {
|
||||
return getDeclaration(file.getProject(), descriptor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getDeclaration(
|
||||
@NotNull Project project,
|
||||
@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
Collection<PsiElement> elements = BindingContextUtils.descriptorToDeclarations(bindingContext, descriptor);
|
||||
public static PsiElement getDeclaration(@NotNull Project project, @NotNull DeclarationDescriptor descriptor) {
|
||||
Collection<PsiElement> elements = BindingContextUtils.descriptorToDeclarations(descriptor);
|
||||
if (elements.isEmpty()) {
|
||||
elements = findDeclarationsForDescriptorWithoutTrace(project, descriptor);
|
||||
elements = findDecompiledAndBuiltInDeclarations(project, descriptor);
|
||||
}
|
||||
if (!elements.isEmpty()) {
|
||||
return elements.iterator().next();
|
||||
@@ -61,7 +52,7 @@ public final class DescriptorToDeclarationUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Collection<PsiElement> findDeclarationsForDescriptorWithoutTrace(
|
||||
public static Collection<PsiElement> findDecompiledAndBuiltInDeclarations(
|
||||
@NotNull Project project,
|
||||
@NotNull DeclarationDescriptor descriptor
|
||||
) {
|
||||
|
||||
@@ -60,7 +60,7 @@ public class GotoSuperActionHandler implements CodeInsightActionHandler {
|
||||
JetObjectDeclaration.class);
|
||||
if (declaration == null) return;
|
||||
|
||||
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
|
||||
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class GotoSuperActionHandler implements CodeInsightActionHandler {
|
||||
if (KotlinBuiltIns.getInstance().getAny() == descriptor) {
|
||||
return null;
|
||||
}
|
||||
return BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||
return BindingContextUtils.descriptorToDeclaration(descriptor);
|
||||
}
|
||||
});
|
||||
if (superDeclarations.isEmpty()) return;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class JetTypeDeclarationProvider implements TypeDeclarationProvider {
|
||||
if (type != null) {
|
||||
ClassifierDescriptor classifierDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
if (classifierDescriptor != null) {
|
||||
PsiElement typeElement = BindingContextUtils.descriptorToDeclaration(bindingContext, classifierDescriptor);
|
||||
PsiElement typeElement = BindingContextUtils.descriptorToDeclaration(classifierDescriptor);
|
||||
if (typeElement != null) {
|
||||
return new PsiElement[] {typeElement};
|
||||
}
|
||||
|
||||
@@ -57,16 +57,15 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
private static final Logger LOG = Logger.getInstance(OverrideImplementMethodsHandler.class.getCanonicalName());
|
||||
|
||||
public static List<DescriptorClassMember> membersFromDescriptors(
|
||||
JetFile file, Iterable<CallableMemberDescriptor> missingImplementations,
|
||||
BindingContext bindingContext
|
||||
JetFile file, Iterable<CallableMemberDescriptor> missingImplementations
|
||||
) {
|
||||
List<DescriptorClassMember> members = new ArrayList<DescriptorClassMember>();
|
||||
for (CallableMemberDescriptor memberDescriptor : missingImplementations) {
|
||||
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(file, memberDescriptor, bindingContext);
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(file, memberDescriptor);
|
||||
if (declaration == null) {
|
||||
LOG.error("Can not find declaration for descriptor " + memberDescriptor);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
DescriptorClassMember member = new DescriptorClassMember(declaration, memberDescriptor);
|
||||
members.add(member);
|
||||
}
|
||||
@@ -254,7 +253,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
HintManager.getInstance().showErrorHint(editor, getNoMethodsFoundHint());
|
||||
return;
|
||||
}
|
||||
List<DescriptorClassMember> members = membersFromDescriptors((JetFile) file, missingImplementations, bindingContext);
|
||||
List<DescriptorClassMember> members = membersFromDescriptors((JetFile) file, missingImplementations);
|
||||
|
||||
final List<DescriptorClassMember> selectedElements;
|
||||
if (implementAll) {
|
||||
|
||||
@@ -122,24 +122,21 @@ public final class DescriptorLookupConverter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LookupElement createLookupElement(
|
||||
@NotNull KotlinCodeAnalyzer analyzer,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull DeclarationDescriptor descriptor) {
|
||||
public static LookupElement createLookupElement(@NotNull KotlinCodeAnalyzer analyzer, @NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof CallableMemberDescriptor) {
|
||||
descriptor = DescriptorUtils.unwrapFakeOverride((CallableMemberDescriptor) descriptor);
|
||||
}
|
||||
return createLookupElement(analyzer, descriptor, BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor));
|
||||
return createLookupElement(analyzer, descriptor, BindingContextUtils.descriptorToDeclaration(descriptor));
|
||||
}
|
||||
|
||||
public static LookupElement[] collectLookupElements(
|
||||
@NotNull KotlinCodeAnalyzer analyzer,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull Iterable<DeclarationDescriptor> descriptors) {
|
||||
@NotNull Iterable<DeclarationDescriptor> descriptors
|
||||
) {
|
||||
List<LookupElement> result = Lists.newArrayList();
|
||||
|
||||
for (DeclarationDescriptor descriptor : descriptors) {
|
||||
result.add(createLookupElement(analyzer, bindingContext, descriptor));
|
||||
result.add(createLookupElement(analyzer, descriptor));
|
||||
}
|
||||
|
||||
return result.toArray(new LookupElement[result.size()]);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class JetCompletionResultSet {
|
||||
return;
|
||||
}
|
||||
|
||||
addElement(DescriptorLookupConverter.createLookupElement(resolveSession, bindingContext, descriptor));
|
||||
addElement(DescriptorLookupConverter.createLookupElement(resolveSession, descriptor));
|
||||
|
||||
// add special item for function with one argument of function type with more than one parameter
|
||||
if (descriptor instanceof FunctionDescriptor) {
|
||||
@@ -89,7 +89,7 @@ public class JetCompletionResultSet {
|
||||
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(parameterType)) {
|
||||
int parameterCount = KotlinBuiltIns.getInstance().getParameterTypeProjectionsFromFunctionType(parameterType).size();
|
||||
if (parameterCount > 1) {
|
||||
LookupElement lookupElement = DescriptorLookupConverter.createLookupElement(resolveSession, bindingContext, descriptor);
|
||||
LookupElement lookupElement = DescriptorLookupConverter.createLookupElement(resolveSession, descriptor);
|
||||
addElement(new LookupElementDecorator<LookupElement>(lookupElement) {
|
||||
@Override
|
||||
public void renderElement(@NotNull LookupElementPresentation presentation) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPackageDirective;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
@@ -33,6 +34,8 @@ import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Performs completion in package directive. Should suggest only packages and avoid showing fake package produced by
|
||||
* DUMMY_IDENTIFIER.
|
||||
@@ -75,8 +78,9 @@ public class JetPackagesContributor extends CompletionContributor {
|
||||
ResolvePackage.getLazyResolveSession(simpleNameReference.getExpression());
|
||||
BindingContext bindingContext = resolveSession.resolveToElement(simpleNameReference.getExpression());
|
||||
|
||||
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(
|
||||
resolveSession, bindingContext, TipsManager.getPackageReferenceVariants(simpleNameReference.getExpression(), bindingContext))) {
|
||||
Collection<DeclarationDescriptor> variants =
|
||||
TipsManager.getPackageReferenceVariants(simpleNameReference.getExpression(), bindingContext);
|
||||
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(resolveSession, variants)) {
|
||||
if (!variant.getLookupString().contains(DUMMY_IDENTIFIER)) {
|
||||
result.addElement(variant);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
else -> ExpectedInfoClassification.NOT_MATCHES
|
||||
}
|
||||
}
|
||||
result.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, resolveSession, bindingContext) })
|
||||
result.addLookupElements(expectedInfos, classifier, { createLookupElement(descriptor, resolveSession) })
|
||||
|
||||
if (receiver == null) {
|
||||
toFunctionReferenceLookupElement(descriptor, functionExpectedInfos)?.let { result.add(it) }
|
||||
@@ -104,7 +104,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
}
|
||||
|
||||
if (receiver == null) {
|
||||
TypeInstantiationItems(bindingContext, resolveSession, visibilityFilter).addToCollection(result, expectedInfos)
|
||||
TypeInstantiationItems(resolveSession, visibilityFilter).addToCollection(result, expectedInfos)
|
||||
|
||||
StaticMembers(bindingContext, resolveSession).addToCollection(result, expectedInfos, expression, itemsToSkip)
|
||||
|
||||
@@ -177,7 +177,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
val matchedExpectedInfos = functionExpectedInfos.filter { functionType.isSubtypeOf(it.`type`) }
|
||||
if (matchedExpectedInfos.isEmpty()) return null
|
||||
|
||||
var lookupElement = createLookupElement(descriptor, resolveSession, bindingContext)
|
||||
var lookupElement = createLookupElement(descriptor, resolveSession)
|
||||
val text = "::" + (if (descriptor is ConstructorDescriptor) descriptor.getContainingDeclaration().getName() else descriptor.getName())
|
||||
lookupElement = object: LookupElementDecorator<LookupElement>(lookupElement) {
|
||||
override fun getLookupString() = text
|
||||
|
||||
@@ -107,7 +107,7 @@ class StaticMembers(val bindingContext: BindingContext, val resolveSession: Reso
|
||||
}
|
||||
|
||||
private fun createLookupElement(memberDescriptor: DeclarationDescriptor, classDescriptor: ClassDescriptor): LookupElement {
|
||||
val lookupElement = createLookupElement(memberDescriptor, resolveSession, bindingContext)
|
||||
val lookupElement = createLookupElement(memberDescriptor, resolveSession)
|
||||
val qualifierPresentation = classDescriptor.getName().asString()
|
||||
val lookupString = qualifierPresentation + "." + lookupElement.getLookupString()
|
||||
val qualifierText = DescriptorUtils.getFqName(classDescriptor).asString() //TODO: escape keywords
|
||||
|
||||
@@ -68,7 +68,7 @@ class ThisItems(val bindingContext: BindingContext) {
|
||||
val name: Name = descriptor.getName()
|
||||
if (!name.isSpecial()) return name.asString()
|
||||
|
||||
val psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor)
|
||||
val psiElement = BindingContextUtils.descriptorToDeclaration(descriptor)
|
||||
val expression: JetExpression? = when (psiElement) {
|
||||
is JetFunctionLiteral -> psiElement.getParent() as? JetFunctionLiteralExpression
|
||||
is JetObjectDeclaration -> psiElement.getParent() as? JetObjectLiteralExpression
|
||||
|
||||
@@ -38,9 +38,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
|
||||
class TypeInstantiationItems(val bindingContext: BindingContext,
|
||||
val resolveSession: ResolveSessionForBodies,
|
||||
val visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
class TypeInstantiationItems(val resolveSession: ResolveSessionForBodies, val visibilityFilter: (DeclarationDescriptor) -> Boolean) {
|
||||
public fun addToCollection(collection: MutableCollection<LookupElement>, expectedInfos: Collection<ExpectedInfo>) {
|
||||
val expectedInfosGrouped: Map<JetType, List<ExpectedInfo>> = expectedInfos.groupBy { it.`type`.makeNotNullable() }
|
||||
for ((jetType, types) in expectedInfosGrouped) {
|
||||
@@ -65,7 +63,7 @@ class TypeInstantiationItems(val bindingContext: BindingContext,
|
||||
}
|
||||
if (allConstructors.isNotEmpty() && visibleConstructors.isEmpty()) return
|
||||
|
||||
var lookupElement = createLookupElement(classifier, resolveSession, bindingContext)
|
||||
var lookupElement = createLookupElement(classifier, resolveSession)
|
||||
|
||||
var lookupString = lookupElement.getLookupString()
|
||||
|
||||
|
||||
@@ -167,8 +167,8 @@ fun functionType(function: FunctionDescriptor): JetType? {
|
||||
function.getReturnType() ?: return null)
|
||||
}
|
||||
|
||||
fun createLookupElement(descriptor: DeclarationDescriptor, resolveSession: ResolveSessionForBodies, bindingContext: BindingContext): LookupElement {
|
||||
val element = DescriptorLookupConverter.createLookupElement(resolveSession, bindingContext, descriptor)
|
||||
fun createLookupElement(descriptor: DeclarationDescriptor, resolveSession: ResolveSessionForBodies): LookupElement {
|
||||
val element = DescriptorLookupConverter.createLookupElement(resolveSession, descriptor)
|
||||
return if (descriptor is FunctionDescriptor && descriptor.getValueParameters().isNotEmpty()) element.keepOldArgumentListOnTab() else element
|
||||
}
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
||||
if (getterDescriptor != null && !getterDescriptor.isDefault()) {
|
||||
val delegatedResolvedCall = bindingContext[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor]
|
||||
if (delegatedResolvedCall == null) {
|
||||
val getter = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, getterDescriptor)
|
||||
val getter = BindingContextUtils.callableDescriptorToDeclaration(getterDescriptor)
|
||||
if (getter is JetPropertyAccessor && (getter.getBodyExpression() != null || getter.getEqualsToken() != null)) {
|
||||
val psiMethod = LightClassUtil.getLightClassAccessorMethod(getter)
|
||||
if (psiMethod != null) {
|
||||
@@ -142,7 +142,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
||||
else {
|
||||
val delegatedPropertyGetterDescriptor = delegatedResolvedCall.getResultingDescriptor()
|
||||
if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) {
|
||||
val function = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, delegatedPropertyGetterDescriptor)
|
||||
val function = BindingContextUtils.callableDescriptorToDeclaration(delegatedPropertyGetterDescriptor)
|
||||
if (function is JetNamedFunction) {
|
||||
val psiMethod = LightClassUtil.getLightClassMethod(function)
|
||||
if (psiMethod != null) {
|
||||
@@ -163,7 +163,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
||||
|
||||
val descriptor = resolvedCall.getResultingDescriptor()
|
||||
if (descriptor is CallableMemberDescriptor) {
|
||||
val function = BindingContextUtils.callableDescriptorToDeclaration(bindingContext, descriptor)
|
||||
val function = BindingContextUtils.callableDescriptorToDeclaration(descriptor)
|
||||
if (function is JetNamedFunction) {
|
||||
val psiMethod = LightClassUtil.getLightClassMethod(function)
|
||||
if (psiMethod != null) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public abstract class CalleeReferenceVisitorBase extends JetTreeVisitorVoid {
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
if (descriptor == null) return;
|
||||
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
|
||||
if (declaration == null) return;
|
||||
|
||||
if (isProperty(descriptor, declaration) || isCallable(descriptor, declaration, expression)) {
|
||||
|
||||
@@ -299,7 +299,7 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
if (overriddenMembers.isEmpty()) return;
|
||||
List<PsiElement> list = Lists.newArrayList();
|
||||
for (CallableMemberDescriptor overriddenMember : overriddenMembers) {
|
||||
PsiElement declarationPsiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, overriddenMember);
|
||||
PsiElement declarationPsiElement = BindingContextUtils.descriptorToDeclaration(overriddenMember);
|
||||
list.add(declarationPsiElement);
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
|
||||
+1
-2
@@ -78,8 +78,7 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa
|
||||
if (variableDescriptor != null) {
|
||||
val containingDescriptor = variableDescriptor.getContainingDeclaration()
|
||||
if (containingDescriptor is AnonymousFunctionDescriptor) {
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
|
||||
return BindingContextUtils.descriptorToDeclaration(context, containingDescriptor) as? JetFunctionLiteral
|
||||
return BindingContextUtils.descriptorToDeclaration(containingDescriptor) as? JetFunctionLiteral
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -41,8 +41,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBa
|
||||
val simpleNameReference = simpleNameExpression.getReference() as JetReference?
|
||||
val target = simpleNameReference?.resolveToDescriptors()?.first()!!
|
||||
|
||||
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(simpleNameExpression)
|
||||
val funcExpr = BindingContextUtils.descriptorToDeclaration(bindingContext, target.getContainingDeclaration()!!) as JetFunctionLiteral
|
||||
val funcExpr = BindingContextUtils.descriptorToDeclaration(target.getContainingDeclaration()!!) as JetFunctionLiteral
|
||||
|
||||
val newExpr = JetPsiFactory.createExpression(project, "{ it -> 42 }") as JetFunctionLiteralExpression
|
||||
funcExpr.addRangeAfter(newExpr.getFunctionLiteral().getValueParameterList(),
|
||||
|
||||
@@ -83,7 +83,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
|
||||
List<JetNamedDeclaration> declarations = new ArrayList<JetNamedDeclaration>();
|
||||
for (DeclarationDescriptor declarationDescriptor : TipsManager.excludeNotCallableExtensions(filteredDescriptors, scope)) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bc, declarationDescriptor);
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(declarationDescriptor);
|
||||
assert declaration == null || declaration instanceof PsiNamedElement;
|
||||
|
||||
if (declaration instanceof JetProperty || declaration instanceof JetParameter) {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class JetAnonymousSuperMacro extends Macro {
|
||||
if (!classDescriptor.getModality().isOverridable()) continue;
|
||||
ClassKind kind = classDescriptor.getKind();
|
||||
if (kind == ClassKind.TRAIT || kind == ClassKind.CLASS) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bc, descriptor);
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
|
||||
if (declaration != null) {
|
||||
result.add((PsiNamedElement) declaration);
|
||||
}
|
||||
|
||||
+6
-6
@@ -151,7 +151,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
return true;
|
||||
}
|
||||
|
||||
private static String renderParameter(ValueParameterDescriptor parameter, boolean named, BindingContext bindingContext) {
|
||||
private static String renderParameter(ValueParameterDescriptor parameter, boolean named) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (named) builder.append("[");
|
||||
if (parameter.getVarargElementType() != null) {
|
||||
@@ -161,7 +161,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
.append(": ")
|
||||
.append(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(getActualParameterType(parameter)));
|
||||
if (parameter.hasDefaultValue()) {
|
||||
PsiElement parameterDeclaration = BindingContextUtils.descriptorToDeclaration(bindingContext, parameter);
|
||||
PsiElement parameterDeclaration = BindingContextUtils.descriptorToDeclaration(parameter);
|
||||
builder.append(" = ").append(getDefaultExpressionString(parameterDeclaration));
|
||||
}
|
||||
if (named) builder.append("]");
|
||||
@@ -258,7 +258,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
}
|
||||
else {
|
||||
ValueParameterDescriptor param = valueParameters.get(i);
|
||||
builder.append(renderParameter(param, false, bindingContext));
|
||||
builder.append(renderParameter(param, false));
|
||||
if (i <= currentParameterIndex && !isArgumentTypeValid(bindingContext, argument, param)) {
|
||||
isGrey = true;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
}
|
||||
else {
|
||||
ValueParameterDescriptor param = valueParameters.get(i);
|
||||
builder.append(renderParameter(param, false, bindingContext));
|
||||
builder.append(renderParameter(param, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
if (referenceExpression != null && !usedIndexes[j] && param.getName().equals(referenceExpression.getReferencedNameAsName())) {
|
||||
takeAnyArgument = false;
|
||||
usedIndexes[j] = true;
|
||||
builder.append(renderParameter(param, true, bindingContext));
|
||||
builder.append(renderParameter(param, true));
|
||||
if (i < currentParameterIndex && !isArgumentTypeValid(bindingContext, argument, param)) {
|
||||
isGrey = true;
|
||||
}
|
||||
@@ -301,7 +301,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
ValueParameterDescriptor param = valueParameters.get(j);
|
||||
if (!usedIndexes[j]) {
|
||||
usedIndexes[j] = true;
|
||||
builder.append(renderParameter(param, true, bindingContext));
|
||||
builder.append(renderParameter(param, true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -152,8 +151,7 @@ public class AddFunctionToSupertypeFix extends JetHintAction<JetNamedFunction> {
|
||||
|
||||
@NotNull
|
||||
private JetAddFunctionToClassifierAction createAction(Project project, Editor editor, JetFile file) {
|
||||
BindingContext bindingContext = ResolvePackage.getBindingContext(element);
|
||||
return new JetAddFunctionToClassifierAction(project, editor, bindingContext, functionsToAdd);
|
||||
return new JetAddFunctionToClassifierAction(project, editor, functionsToAdd);
|
||||
}
|
||||
|
||||
public static JetIntentionActionsFactory createFactory() {
|
||||
|
||||
@@ -145,7 +145,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
BindingContext context = ResolvePackage.getBindingContext((JetFile) entry.getContainingFile().getContainingFile());
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
if (resolvedCall == null) return null;
|
||||
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
|
||||
JetType expectedType = context.get(BindingContext.TYPE, entry.getTypeRef());
|
||||
if (componentFunction != null && expectedType != null) {
|
||||
return new ChangeFunctionReturnTypeFix(componentFunction, expectedType);
|
||||
@@ -166,7 +166,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
BindingContext context = ResolvePackage.getBindingContext(expression.getContainingJetFile());
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression);
|
||||
if (resolvedCall == null) return null;
|
||||
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
|
||||
if (hasNextFunction != null) {
|
||||
return new ChangeFunctionReturnTypeFix(hasNextFunction, KotlinBuiltIns.getInstance().getBooleanType());
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
BindingContext context = ResolvePackage.getBindingContext(expression.getContainingJetFile());
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
|
||||
if (resolvedCall == null) return null;
|
||||
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
|
||||
if (!(compareTo instanceof JetFunction)) return null;
|
||||
return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
|
||||
}
|
||||
@@ -224,7 +224,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
||||
}
|
||||
|
||||
if (overriddenMismatchingFunctions.size() == 1) {
|
||||
PsiElement overriddenFunction = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingFunctions.get(0));
|
||||
PsiElement overriddenFunction = BindingContextUtils.descriptorToDeclaration(overriddenMismatchingFunctions.get(0));
|
||||
if (overriddenFunction instanceof JetFunction) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) overriddenFunction, functionType));
|
||||
}
|
||||
|
||||
@@ -79,8 +79,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
return false;
|
||||
}
|
||||
|
||||
BindingContext bindingContext = ResolvePackage.getBindingContext((JetFile) file);
|
||||
List<PsiElement> declarations = BindingContextUtils.callableDescriptorToDeclarations(bindingContext, functionDescriptor);
|
||||
List<PsiElement> declarations = BindingContextUtils.callableDescriptorToDeclarations(functionDescriptor);
|
||||
if (declarations.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ChangeVariableMutabilityFix implements IntentionAction {
|
||||
BindingContext bindingContext = ResolvePackage.getBindingContext(file);
|
||||
VariableDescriptor descriptor = BindingContextUtils.extractVariableDescriptorIfAny(bindingContext, simpleNameExpression, true);
|
||||
if (descriptor != null) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(descriptor);
|
||||
if (declaration instanceof JetProperty) {
|
||||
return (JetProperty) declaration;
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
BindingContext context = ResolvePackage.getBindingContext(entry.getContainingJetFile());
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
if (resolvedCall == null) return null;
|
||||
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(resolvedCall.getCandidateDescriptor());
|
||||
if (componentFunction == null) return null;
|
||||
JetType expectedType = resolvedCall.getCandidateDescriptor().getReturnType();
|
||||
return expectedType == null ? null : new ChangeVariableTypeFix(entry, expectedType);
|
||||
@@ -168,7 +168,7 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
}
|
||||
|
||||
if (overriddenMismatchingProperties.size() == 1 && canChangeOverriddenPropertyType) {
|
||||
PsiElement overriddenProperty = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingProperties.get(0));
|
||||
PsiElement overriddenProperty = BindingContextUtils.descriptorToDeclaration(overriddenMismatchingProperties.get(0));
|
||||
if (overriddenProperty instanceof JetProperty) {
|
||||
actions.add(new ChangeVariableTypeFix((JetProperty) overriddenProperty, propertyType));
|
||||
}
|
||||
|
||||
@@ -110,11 +110,9 @@ private class TypeCandidate(public val theType: JetType, scope: JetScope? = null
|
||||
/**
|
||||
* Represents an element in the class selection list.
|
||||
*/
|
||||
private class ClassCandidate(public val typeCandidate: TypeCandidate, file: JetFile, context: BindingContext) {
|
||||
private class ClassCandidate(public val typeCandidate: TypeCandidate, file: JetFile) {
|
||||
public val jetClass: JetClass = DescriptorToDeclarationUtil.getDeclaration(
|
||||
file,
|
||||
DescriptorUtils.getClassDescriptorForType(typeCandidate.theType),
|
||||
context
|
||||
file, DescriptorUtils.getClassDescriptorForType(typeCandidate.theType)
|
||||
) as JetClass
|
||||
}
|
||||
|
||||
@@ -550,7 +548,7 @@ public class CreateFunctionFromUsageFix internal (
|
||||
}
|
||||
else {
|
||||
// class selection
|
||||
val list = JBList(ownerTypeCandidates.map { ClassCandidate(it, currentFile, currentFileContext) })
|
||||
val list = JBList(ownerTypeCandidates.map { ClassCandidate(it, currentFile) })
|
||||
val renderer = QuickFixUtil.ClassCandidateListCellRenderer()
|
||||
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION)
|
||||
list.setCellRenderer(renderer)
|
||||
@@ -574,7 +572,7 @@ public class CreateFunctionFromUsageFix internal (
|
||||
// gather relevant information
|
||||
ownerClassDescriptor = DescriptorUtils.getClassDescriptorForType(selectedReceiverType.theType)
|
||||
val receiverType = ownerClassDescriptor.getDefaultType()
|
||||
val classDeclaration = BindingContextUtils.classDescriptorToDeclaration(currentFileContext, ownerClassDescriptor)
|
||||
val classDeclaration = BindingContextUtils.classDescriptorToDeclaration(ownerClassDescriptor)
|
||||
if (classDeclaration is JetClass) {
|
||||
ownerClass = classDeclaration
|
||||
isExtension = !ownerClass.isWritable()
|
||||
|
||||
@@ -67,7 +67,7 @@ public class MakeOverriddenMemberOpenFix extends JetIntentionAction<JetDeclarati
|
||||
for (CallableMemberDescriptor overriddenDescriptor : getAllDeclaredNonOverridableOverriddenDescriptors(
|
||||
(CallableMemberDescriptor) descriptor)) {
|
||||
assert overriddenDescriptor.getKind() == DECLARATION : "Can only be applied to declarations.";
|
||||
PsiElement overriddenMember = descriptorToDeclaration(resolveSession.getBindingContext(), overriddenDescriptor);
|
||||
PsiElement overriddenMember = descriptorToDeclaration(overriddenDescriptor);
|
||||
if (overriddenMember == null || !QuickFixUtil.canModifyElement(overriddenMember)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
||||
if (expression instanceof JetOperationExpression) {
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
|
||||
if (resolvedCall != null) {
|
||||
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
|
||||
JetFunction declaration = getFunctionDeclaration(resolvedCall);
|
||||
if (declaration != null) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix(declaration, expectedType));
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
||||
if (parentBinary.getRight() == expression) {
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(parentBinary, context);
|
||||
if (resolvedCall != null) {
|
||||
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
|
||||
JetFunction declaration = getFunctionDeclaration(resolvedCall);
|
||||
if (declaration != null) {
|
||||
JetParameter binaryOperatorParameter = declaration.getValueParameterList().getParameters().get(0);
|
||||
actions.add(new ChangeParameterTypeFix(binaryOperatorParameter, expressionType));
|
||||
@@ -97,7 +97,7 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
||||
if (expression instanceof JetCallExpression) {
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(expression, context);
|
||||
if (resolvedCall != null) {
|
||||
JetFunction declaration = getFunctionDeclaration(context, resolvedCall);
|
||||
JetFunction declaration = getFunctionDeclaration(resolvedCall);
|
||||
if (declaration != null) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix(declaration, expectedType));
|
||||
}
|
||||
@@ -131,8 +131,8 @@ public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsF
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JetFunction getFunctionDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
|
||||
PsiElement result = QuickFixUtil.safeGetDeclaration(context, resolvedCall);
|
||||
private static JetFunction getFunctionDeclaration(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
PsiElement result = QuickFixUtil.safeGetDeclaration(resolvedCall);
|
||||
if (result instanceof JetFunction) {
|
||||
return (JetFunction) result;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ public class QuickFixUtil {
|
||||
BindingContext context = ResolvePackage.getBindingContext(callExpression.getContainingJetFile());
|
||||
ResolvedCall<?> resolvedCall = BindingContextUtilPackage.getResolvedCall(callExpression, context);
|
||||
if (resolvedCall == null) return null;
|
||||
PsiElement declaration = safeGetDeclaration(context, resolvedCall);
|
||||
PsiElement declaration = safeGetDeclaration(resolvedCall);
|
||||
if (declaration instanceof JetFunction) {
|
||||
return ((JetFunction) declaration).getValueParameterList();
|
||||
}
|
||||
@@ -121,8 +121,8 @@ public class QuickFixUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement safeGetDeclaration(@NotNull BindingContext context, @NotNull ResolvedCall<?> resolvedCall) {
|
||||
List<PsiElement> declarations = BindingContextUtils.descriptorToDeclarations(context, resolvedCall.getResultingDescriptor());
|
||||
public static PsiElement safeGetDeclaration(@NotNull ResolvedCall<?> resolvedCall) {
|
||||
List<PsiElement> declarations = BindingContextUtils.descriptorToDeclarations(resolvedCall.getResultingDescriptor());
|
||||
//do not create fix if descriptor has more than one overridden declaration
|
||||
if (declarations.size() == 1) {
|
||||
return declarations.iterator().next();
|
||||
|
||||
@@ -141,7 +141,7 @@ public class JetRefactoringUtil {
|
||||
@Override
|
||||
public Pair<PsiElement, CallableDescriptor> fun(CallableDescriptor descriptor) {
|
||||
return new Pair<PsiElement, CallableDescriptor>(
|
||||
DescriptorToDeclarationUtil.getDeclaration(project, descriptor, bindingContext),
|
||||
DescriptorToDeclarationUtil.getDeclaration(project, descriptor),
|
||||
descriptor
|
||||
);
|
||||
}
|
||||
@@ -220,12 +220,8 @@ public class JetRefactoringUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String formatClass(
|
||||
@NotNull DeclarationDescriptor classDescriptor,
|
||||
@NotNull BindingContext bindingContext,
|
||||
boolean inCode
|
||||
) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, classDescriptor);
|
||||
public static String formatClass(@NotNull DeclarationDescriptor classDescriptor, boolean inCode) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(classDescriptor);
|
||||
if (element instanceof PsiClass) {
|
||||
return formatPsiClass((PsiClass) element, false, inCode);
|
||||
}
|
||||
@@ -234,12 +230,8 @@ public class JetRefactoringUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String formatFunction(
|
||||
@NotNull DeclarationDescriptor functionDescriptor,
|
||||
@NotNull BindingContext bindingContext,
|
||||
boolean inCode
|
||||
) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(bindingContext, functionDescriptor);
|
||||
public static String formatFunction(@NotNull DeclarationDescriptor functionDescriptor, boolean inCode) {
|
||||
PsiElement element = BindingContextUtils.descriptorToDeclaration(functionDescriptor);
|
||||
if (element instanceof PsiMethod) {
|
||||
return formatPsiMethod((PsiMethod) element, false, inCode);
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ public class JetChangeSignature(val project: Project,
|
||||
|
||||
fun createChangeSignatureDialog(descriptorsForSignatureChange: Collection<FunctionDescriptor>): JetChangeSignatureDialog? {
|
||||
val baseDescriptor = preferContainedInClass(descriptorsForSignatureChange)
|
||||
val functionDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, baseDescriptor, bindingContext)
|
||||
val functionDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, baseDescriptor)
|
||||
if (functionDeclaration == null) {
|
||||
LOG.error("Could not find declaration for $baseDescriptor")
|
||||
return null
|
||||
@@ -145,7 +145,7 @@ public class JetChangeSignature(val project: Project,
|
||||
return null
|
||||
}
|
||||
|
||||
val changeSignatureData = JetChangeSignatureData(baseDescriptor, functionDeclaration, bindingContext, descriptorsForSignatureChange)
|
||||
val changeSignatureData = JetChangeSignatureData(baseDescriptor, functionDeclaration, descriptorsForSignatureChange)
|
||||
configuration.configure(changeSignatureData, bindingContext)
|
||||
return JetChangeSignatureDialog(project, changeSignatureData, defaultValueContext, commandName)
|
||||
}
|
||||
|
||||
+1
-5
@@ -49,20 +49,16 @@ public final class JetChangeSignatureData implements JetMethodDescriptor {
|
||||
@NotNull
|
||||
private final List<JetParameterInfo> parameters;
|
||||
@NotNull
|
||||
private final BindingContext bindingContext;
|
||||
@NotNull
|
||||
private final Collection<FunctionDescriptor> descriptorsForSignatureChange;
|
||||
private Collection<PsiElement> affectedFunctions = null;
|
||||
|
||||
public JetChangeSignatureData(
|
||||
@NotNull FunctionDescriptor baseDescriptor,
|
||||
@NotNull PsiElement baseDeclaration,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull Collection<FunctionDescriptor> descriptorsForSignatureChange
|
||||
) {
|
||||
this.baseDescriptor = baseDescriptor;
|
||||
this.baseDeclaration = baseDeclaration;
|
||||
this.bindingContext = bindingContext;
|
||||
this.descriptorsForSignatureChange = descriptorsForSignatureChange;
|
||||
final List<JetParameter> valueParameters = this.baseDeclaration instanceof JetFunction
|
||||
? ((JetFunction) this.baseDeclaration).getValueParameters()
|
||||
@@ -110,7 +106,7 @@ public final class JetChangeSignatureData implements JetMethodDescriptor {
|
||||
|
||||
@NotNull
|
||||
private Collection<PsiElement> computeHierarchyFrom(@NotNull FunctionDescriptor baseDescriptor) {
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(baseDeclaration.getProject(), baseDescriptor, bindingContext);
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.getDeclaration(baseDeclaration.getProject(), baseDescriptor);
|
||||
Set<PsiElement> result = Sets.newHashSet();
|
||||
result.add(declaration);
|
||||
if (!(declaration instanceof JetNamedFunction)) {
|
||||
|
||||
+4
-4
@@ -146,7 +146,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
if (!changeInfo.isConstructor() && functionScope != null && !info.getNewName().isEmpty()) {
|
||||
for (FunctionDescriptor conflict : functionScope.getFunctions(Name.identifier(info.getNewName()))) {
|
||||
if (conflict != oldDescriptor && getFunctionParameterTypes(conflict).equals(getFunctionParameterTypes(oldDescriptor))) {
|
||||
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(bindingContext, conflict);
|
||||
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(conflict);
|
||||
result.putValue(conflictElement, "Function already exists: '" + DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(conflict) + "'");
|
||||
break;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
if (parametersScope != null) {
|
||||
if (changeInfo.isConstructor() && valOrVar != JetValVar.None) {
|
||||
for (VariableDescriptor property : parametersScope.getProperties(Name.identifier(parameterName))) {
|
||||
PsiElement propertyDeclaration = BindingContextUtils.descriptorToDeclaration(bindingContext, property);
|
||||
PsiElement propertyDeclaration = BindingContextUtils.descriptorToDeclaration(property);
|
||||
|
||||
if (propertyDeclaration != null && !(propertyDeclaration.getParent() instanceof JetParameterList)) {
|
||||
result.putValue(propertyDeclaration, "Duplicating property '" + parameterName + "'");
|
||||
@@ -175,7 +175,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
VariableDescriptor variable = parametersScope.getLocalVariable(Name.identifier(parameterName));
|
||||
|
||||
if (variable != null && !(variable instanceof ValueParameterDescriptor)) {
|
||||
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(bindingContext, variable);
|
||||
PsiElement conflictElement = BindingContextUtils.descriptorToDeclaration(variable);
|
||||
result.putValue(conflictElement, "Duplicating local variable '" + parameterName + "'");
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
if (containingDeclaration instanceof ClassDescriptor)
|
||||
return ((ClassDescriptor) containingDeclaration).getMemberScope(ContainerUtil.<TypeProjection>emptyList());
|
||||
else if (containingDeclaration instanceof FunctionDescriptorImpl) {
|
||||
PsiElement container = BindingContextUtils.descriptorToDeclaration(bindingContext, containingDeclaration);
|
||||
PsiElement container = BindingContextUtils.descriptorToDeclaration(containingDeclaration);
|
||||
|
||||
if (container instanceof JetFunction)
|
||||
return getFunctionBodyScope((JetFunction) container, bindingContext);
|
||||
|
||||
@@ -105,7 +105,7 @@ class ExtractionData(
|
||||
val refOffsetToDeclaration by Delegates.lazy {
|
||||
fun isExtractableIt(descriptor: DeclarationDescriptor, context: BindingContext): Boolean {
|
||||
if (!(descriptor is ValueParameterDescriptor && (context[BindingContext.AUTO_CREATED_IT, descriptor] ?: false))) return false
|
||||
val function = BindingContextUtils.descriptorToDeclaration(context, descriptor.getContainingDeclaration()) as? JetFunctionLiteral
|
||||
val function = BindingContextUtils.descriptorToDeclaration(descriptor.getContainingDeclaration()) as? JetFunctionLiteral
|
||||
return function == null || !function.isInsideOf(originalElements)
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ class ExtractionData(
|
||||
val descriptor = context[BindingContext.REFERENCE_TARGET, ref]
|
||||
if (descriptor == null) continue
|
||||
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor, context) as? PsiNamedElement
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor) as? PsiNamedElement
|
||||
?: if (isExtractableIt(descriptor, context)) itFakeDeclaration else continue
|
||||
|
||||
val offset = ref.getTextRange()!!.getStartOffset() - originalStartOffset
|
||||
|
||||
+8
-12
@@ -284,7 +284,6 @@ fun TypeParameter.collectReferencedTypes(bindingContext: BindingContext): List<J
|
||||
}
|
||||
|
||||
private fun JetType.processTypeIfExtractable(
|
||||
bindingContext: BindingContext,
|
||||
typeParameters: MutableSet<TypeParameter>,
|
||||
nonDenotableTypes: MutableSet<JetType>,
|
||||
processTypeArguments: Boolean = true
|
||||
@@ -292,7 +291,7 @@ private fun JetType.processTypeIfExtractable(
|
||||
return collectReferencedTypes(processTypeArguments).fold(true) { (extractable, typeToCheck) ->
|
||||
val parameterTypeDescriptor = typeToCheck.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
|
||||
val typeParameter = parameterTypeDescriptor?.let {
|
||||
BindingContextUtils.descriptorToDeclaration(bindingContext, it)
|
||||
BindingContextUtils.descriptorToDeclaration(it)
|
||||
} as? JetTypeParameter
|
||||
|
||||
when {
|
||||
@@ -411,9 +410,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
}
|
||||
|
||||
if (referencedClassDescriptor != null) {
|
||||
if (!referencedClassDescriptor.getDefaultType().processTypeIfExtractable(
|
||||
bindingContext, typeParameters, nonDenotableTypes, false
|
||||
)) continue
|
||||
if (!referencedClassDescriptor.getDefaultType().processTypeIfExtractable(typeParameters, nonDenotableTypes, false)) continue
|
||||
|
||||
val replacingDescriptor = (originalDescriptor as? ConstructorDescriptor)?.getContainingDeclaration() ?: originalDescriptor
|
||||
replacementMap[refInfo.offsetInBody] = FqNameReplacement(DescriptorUtils.getFqNameSafe(replacingDescriptor))
|
||||
@@ -436,7 +433,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
?: DEFAULT_PARAMETER_TYPE
|
||||
}
|
||||
|
||||
if (!parameterType.processTypeIfExtractable(bindingContext, typeParameters, nonDenotableTypes)) continue
|
||||
if (!parameterType.processTypeIfExtractable(typeParameters, nonDenotableTypes)) continue
|
||||
|
||||
val parameterTypePredicate =
|
||||
pseudocode.getElementValue(originalRef)?.let { getExpectedTypePredicate(it, valueUsageMap, bindingContext) } ?: AllTypes
|
||||
@@ -470,7 +467,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
}
|
||||
|
||||
for (typeToCheck in typeParameters.flatMapTo(HashSet<JetType>()) { it.collectReferencedTypes(bindingContext) }) {
|
||||
typeToCheck.processTypeIfExtractable(bindingContext, typeParameters, nonDenotableTypes)
|
||||
typeToCheck.processTypeIfExtractable(typeParameters, nonDenotableTypes)
|
||||
}
|
||||
|
||||
parameters.addAll(extractedDescriptorToParameter.values())
|
||||
@@ -489,7 +486,7 @@ private fun ExtractionData.checkLocalDeclarationsWithNonLocalUsages(
|
||||
pseudocode.traverse(TraversalOrder.FORWARD) { instruction ->
|
||||
if (instruction !in localInstructions) {
|
||||
PseudocodeUtil.extractVariableDescriptorIfAny(instruction, true, bindingContext)?.let { descriptor ->
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor, bindingContext)
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor)
|
||||
if (declaration is JetNamedDeclaration && declaration.isInsideOf(originalElements)) {
|
||||
declarations.add(declaration)
|
||||
}
|
||||
@@ -572,7 +569,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
val (controlFlow, controlFlowMessage) = localInstructions.analyzeControlFlow(pseudocode, bindingContext, options, parameters)
|
||||
controlFlowMessage?.let { messages.add(it) }
|
||||
|
||||
controlFlow.returnType.processTypeIfExtractable(bindingContext, typeParameters, nonDenotableTypes)
|
||||
controlFlow.returnType.processTypeIfExtractable(typeParameters, nonDenotableTypes)
|
||||
|
||||
if (nonDenotableTypes.isNotEmpty()) {
|
||||
val typeStr = nonDenotableTypes.map {DescriptorRenderer.HTML.renderType(it)}.sort()
|
||||
@@ -633,9 +630,8 @@ fun ExtractionDescriptor.validate(): ExtractionDescriptorWithConflicts {
|
||||
val diagnostics = bindingContext.getDiagnostics().forElement(currentRefExpr)
|
||||
|
||||
val currentDescriptor = bindingContext[BindingContext.REFERENCE_TARGET, currentRefExpr]
|
||||
val currentTarget = currentDescriptor?.let {
|
||||
DescriptorToDeclarationUtil.getDeclaration(extractionData.project, it, bindingContext)
|
||||
} as? PsiNamedElement
|
||||
val currentTarget =
|
||||
currentDescriptor?.let { DescriptorToDeclarationUtil.getDeclaration(extractionData.project, it) } as? PsiNamedElement
|
||||
if (currentTarget is JetParameter && currentTarget.getParent() == function.getValueParameterList()) continue
|
||||
if (currentDescriptor is LocalVariableDescriptor
|
||||
&& parameters.any { it.mirrorVarName == currentDescriptor.getName().asString() }) continue
|
||||
|
||||
+1
-1
@@ -179,7 +179,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(project: Project, val optio
|
||||
val referenceToContext = JetFileReferencesResolver.resolve(element = declaration, visitReceivers = false)
|
||||
for ((refExpr, bindingContext) in referenceToContext) {
|
||||
val refTarget = bindingContext[BindingContext.REFERENCE_TARGET, refExpr]?.let { descriptor ->
|
||||
DescriptorToDeclarationUtil.getDeclaration(declaration.getProject(), descriptor, bindingContext)
|
||||
DescriptorToDeclarationUtil.getDeclaration(declaration.getProject(), descriptor)
|
||||
}
|
||||
if (refTarget == null || refTarget.isInsideOf(elementsToMove)) continue
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public fun JetElement.updateInternalReferencesOnPackageNameChange(
|
||||
}
|
||||
if (descriptor == null || !descriptor.canBeReferencedViaImport()) continue
|
||||
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(file, descriptor, bindingContext)
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(file, descriptor)
|
||||
if (declaration == null || isAncestor(declaration, true)) continue
|
||||
|
||||
val fqName = DescriptorUtils.getFqName(descriptor)
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ public class RenameKotlinPropertyProcessor : RenamePsiElementProcessor() {
|
||||
// Take one of supers for now - API doesn't support substitute to several elements (IDEA-48796)
|
||||
val deepest = supers.first()
|
||||
if (deepest != descriptor) {
|
||||
val superPsiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, deepest)
|
||||
val superPsiElement = BindingContextUtils.descriptorToDeclaration(deepest)
|
||||
return superPsiElement as? JetProperty
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
|
||||
val originalDeclaration = method.unwrapped
|
||||
if (originalDeclaration !is PsiMethod && originalDeclaration !is JetDeclaration) return
|
||||
|
||||
if (originalDeclaration != BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor)) return
|
||||
if (originalDeclaration != BindingContextUtils.descriptorToDeclaration(descriptor)) return
|
||||
|
||||
val args = callExpression.getValueArguments()
|
||||
|
||||
|
||||
+4
-4
@@ -219,10 +219,10 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
.mapTo(ArrayList<String>()) { overridenDescriptor ->
|
||||
JetBundle.message(
|
||||
"x.implements.y",
|
||||
JetRefactoringUtil.formatFunction(declarationDescriptor, bindingContext, true),
|
||||
JetRefactoringUtil.formatClass(declarationDescriptor.getContainingDeclaration(), bindingContext, true),
|
||||
JetRefactoringUtil.formatFunction(overridenDescriptor, bindingContext, true),
|
||||
JetRefactoringUtil.formatClass(overridenDescriptor.getContainingDeclaration(), bindingContext, true)
|
||||
JetRefactoringUtil.formatFunction(declarationDescriptor, true),
|
||||
JetRefactoringUtil.formatClass(declarationDescriptor.getContainingDeclaration(), true),
|
||||
JetRefactoringUtil.formatFunction(overridenDescriptor, true),
|
||||
JetRefactoringUtil.formatClass(overridenDescriptor.getContainingDeclaration(), true)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,13 +231,9 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
||||
|
||||
@NotNull
|
||||
public Collection<PsiElement> resolveBuiltInSymbol(@NotNull DeclarationDescriptor declarationDescriptor) {
|
||||
if (bindingContext == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
DeclarationDescriptor descriptor = findCurrentDescriptor(declarationDescriptor.getOriginal());
|
||||
if (descriptor != null) {
|
||||
return BindingContextUtils.descriptorToDeclarations(bindingContext, descriptor);
|
||||
return BindingContextUtils.descriptorToDeclarations(descriptor);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -95,12 +95,12 @@ abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
|
||||
override fun resolveMap(): Map<DeclarationDescriptor, Collection<PsiElement>> {
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(expression)
|
||||
return getTargetDescriptors(context) keysToMap { resolveToPsiElements(context, it) }
|
||||
return getTargetDescriptors(context) keysToMap { resolveToPsiElements(it) }
|
||||
}
|
||||
|
||||
private fun resolveToPsiElements(context: BindingContext, targetDescriptors: Collection<DeclarationDescriptor>): Collection<PsiElement> {
|
||||
if (targetDescriptors.isNotEmpty()) {
|
||||
return targetDescriptors flatMap { target -> resolveToPsiElements(context, target) }
|
||||
return targetDescriptors flatMap { target -> resolveToPsiElements(target) }
|
||||
}
|
||||
|
||||
val labelTargets = getLabelTargets(context)
|
||||
@@ -111,11 +111,11 @@ abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
return Collections.emptySet()
|
||||
}
|
||||
|
||||
private fun resolveToPsiElements(context: BindingContext, targetDescriptor: DeclarationDescriptor): Collection<PsiElement> {
|
||||
private fun resolveToPsiElements(targetDescriptor: DeclarationDescriptor): Collection<PsiElement> {
|
||||
val result = HashSet<PsiElement>()
|
||||
val project = expression.getProject()
|
||||
result.addAll(BindingContextUtils.descriptorToDeclarations(context, targetDescriptor))
|
||||
result.addAll(DescriptorToDeclarationUtil.findDeclarationsForDescriptorWithoutTrace(project, targetDescriptor))
|
||||
result.addAll(BindingContextUtils.descriptorToDeclarations(targetDescriptor))
|
||||
result.addAll(DescriptorToDeclarationUtil.findDecompiledAndBuiltInDeclarations(project, targetDescriptor))
|
||||
|
||||
if (targetDescriptor is PackageViewDescriptor) {
|
||||
val psiFacade = JavaPsiFacade.getInstance(project)
|
||||
|
||||
@@ -103,7 +103,7 @@ fun PsiReference.isConstructorUsage(jetClassOrObject: JetClassOrObject): Boolean
|
||||
val descriptor = getCallDescriptor(bindingContext)
|
||||
if (descriptor !is ConstructorDescriptor) return false
|
||||
|
||||
return BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor.getContainingDeclaration()) == jetClassOrObject
|
||||
return BindingContextUtils.descriptorToDeclaration(descriptor.getContainingDeclaration()) == jetClassOrObject
|
||||
}
|
||||
|
||||
checkJavaUsage() || checkKotlinUsage()
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<Tr
|
||||
when (memberDescriptor.getKind()) {
|
||||
CallableMemberDescriptor.Kind.FAKE_OVERRIDE,
|
||||
CallableMemberDescriptor.Kind.DELEGATION -> {
|
||||
val superTypeMember = DescriptorToDeclarationUtil.getDeclaration(project, memberDescriptor, context)
|
||||
val superTypeMember = DescriptorToDeclarationUtil.getDeclaration(project, memberDescriptor)
|
||||
if (superTypeMember is NavigatablePsiElement) {
|
||||
children.add(JetStructureViewElement(superTypeMember, memberDescriptor, true))
|
||||
}
|
||||
|
||||
@@ -165,10 +165,9 @@ public abstract class AbstractOverrideImplementTest extends JetLightCodeInsightF
|
||||
new WriteCommandAction(myFixture.getProject(), myFixture.getFile()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
OverrideImplementMethodsHandler.generateMethods(
|
||||
myFixture.getEditor(), classOrObject,
|
||||
OverrideImplementMethodsHandler
|
||||
.membersFromDescriptors(jetFile, Collections.singletonList(singleToOverride), resolveSession.getBindingContext()));
|
||||
OverrideImplementMethodsHandler.generateMethods(myFixture.getEditor(), classOrObject,
|
||||
OverrideImplementMethodsHandler.membersFromDescriptors(jetFile, Collections.singletonList(singleToOverride))
|
||||
);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
@@ -179,7 +178,7 @@ public abstract class AbstractOverrideImplementTest extends JetLightCodeInsightF
|
||||
assertNotNull("Caret should be inside class or object", classOrObject);
|
||||
|
||||
final JetFile jetFile = classOrObject.getContainingJetFile();
|
||||
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
|
||||
Set<CallableMemberDescriptor> descriptors = handler.collectMethodsToGenerate(classOrObject, bindingContext);
|
||||
|
||||
final ArrayList<CallableMemberDescriptor> descriptorsList = new ArrayList<CallableMemberDescriptor>(descriptors);
|
||||
@@ -195,7 +194,7 @@ public abstract class AbstractOverrideImplementTest extends JetLightCodeInsightF
|
||||
protected void run(Result result) throws Throwable {
|
||||
OverrideImplementMethodsHandler.generateMethods(
|
||||
myFixture.getEditor(), classOrObject,
|
||||
OverrideImplementMethodsHandler.membersFromDescriptors(jetFile, descriptorsList, bindingContext));
|
||||
OverrideImplementMethodsHandler.membersFromDescriptors(jetFile, descriptorsList));
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ public abstract class AbstractRenameTest : MultiFileTestCase() {
|
||||
val bindingContext = jetFile.getBindingContext()
|
||||
val classDescriptor = bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, classFqName)!!
|
||||
|
||||
val psiElement = BindingContextUtils.descriptorToDeclaration(bindingContext, findDescriptorToRename(classDescriptor))!!
|
||||
val psiElement = BindingContextUtils.descriptorToDeclaration(findDescriptorToRename(classDescriptor))!!
|
||||
|
||||
val substitution = RenamePsiElementProcessor.forElement(psiElement).substituteElementToRename(psiElement, null)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user