KT-4043 "Find usages ignores class names usages as class objects"
This commit is contained in:
@@ -377,18 +377,29 @@ public class BodyResolver {
|
|||||||
annotationResolver.resolveAnnotationsArguments(classDescriptor.getScopeForSupertypeResolution(), klass.getPrimaryConstructorModifierList(), trace);
|
annotationResolver.resolveAnnotationsArguments(classDescriptor.getScopeForSupertypeResolution(), klass.getPrimaryConstructorModifierList(), trace);
|
||||||
|
|
||||||
if (unsubstitutedPrimaryConstructor != null) {
|
if (unsubstitutedPrimaryConstructor != null) {
|
||||||
WritableScope parameterScope = new WritableScopeImpl(classDescriptor.getScopeForSupertypeResolution(), unsubstitutedPrimaryConstructor,
|
WritableScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForSupertypeResolution(), unsubstitutedPrimaryConstructor);
|
||||||
RedeclarationHandler.DO_NOTHING, "Scope with value parameters of a constructor");
|
|
||||||
for (ValueParameterDescriptor valueParameterDescriptor : unsubstitutedPrimaryConstructor.getValueParameters()) {
|
|
||||||
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
|
||||||
}
|
|
||||||
parameterScope.changeLockLevel(WritableScope.LockLevel.READING);
|
|
||||||
expressionTypingServices.resolveValueParameters(klass.getPrimaryConstructorParameters(), unsubstitutedPrimaryConstructor.getValueParameters(),
|
expressionTypingServices.resolveValueParameters(klass.getPrimaryConstructorParameters(), unsubstitutedPrimaryConstructor.getValueParameters(),
|
||||||
parameterScope, context.getOuterDataFlowInfo(), trace);
|
parameterScope, context.getOuterDataFlowInfo(), trace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static WritableScope getPrimaryConstructorParametersScope(
|
||||||
|
JetScope originalScope,
|
||||||
|
ConstructorDescriptor unsubstitutedPrimaryConstructor
|
||||||
|
) {
|
||||||
|
WritableScope parameterScope = new WritableScopeImpl(
|
||||||
|
originalScope,
|
||||||
|
unsubstitutedPrimaryConstructor,
|
||||||
|
RedeclarationHandler.DO_NOTHING, "Scope with value parameters of a constructor"
|
||||||
|
);
|
||||||
|
for (ValueParameterDescriptor valueParameterDescriptor : unsubstitutedPrimaryConstructor.getValueParameters()) {
|
||||||
|
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
||||||
|
}
|
||||||
|
parameterScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
return parameterScope;
|
||||||
|
}
|
||||||
|
|
||||||
private void resolvePropertyDeclarationBodies() {
|
private void resolvePropertyDeclarationBodies() {
|
||||||
|
|
||||||
// Member properties
|
// Member properties
|
||||||
@@ -595,6 +606,22 @@ public class BodyResolver {
|
|||||||
assert functionDescriptor.getReturnType() != null;
|
assert functionDescriptor.getReturnType() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resolveConstructorParameterDefaultValuesAndAnnotations(
|
||||||
|
@NotNull BindingTrace trace,
|
||||||
|
@NotNull JetClass klass,
|
||||||
|
@NotNull ConstructorDescriptor constructorDescriptor,
|
||||||
|
@NotNull JetScope declaringScope
|
||||||
|
) {
|
||||||
|
if (!context.completeAnalysisNeeded(klass)) return;
|
||||||
|
|
||||||
|
List<JetParameter> valueParameters = klass.getPrimaryConstructorParameters();
|
||||||
|
List<ValueParameterDescriptor> valueParameterDescriptors = constructorDescriptor.getValueParameters();
|
||||||
|
|
||||||
|
JetScope scope = getPrimaryConstructorParametersScope(declaringScope, constructorDescriptor);
|
||||||
|
|
||||||
|
expressionTypingServices.resolveValueParameters(valueParameters, valueParameterDescriptors, scope, context.getOuterDataFlowInfo(), trace);
|
||||||
|
}
|
||||||
|
|
||||||
private void resolveAnnotationArguments(@NotNull JetScope scope, @NotNull JetModifierListOwner owner) {
|
private void resolveAnnotationArguments(@NotNull JetScope scope, @NotNull JetModifierListOwner owner) {
|
||||||
annotationResolver.resolveAnnotationsArguments(scope, owner.getModifierList(), trace);
|
annotationResolver.resolveAnnotationsArguments(scope, owner.getModifierList(), trace);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,11 @@ public class ResolveElementCache {
|
|||||||
|
|
||||||
JetParameter parameter = PsiTreeUtil.getTopmostParentOfType(jetElement, JetParameter.class);
|
JetParameter parameter = PsiTreeUtil.getTopmostParentOfType(jetElement, JetParameter.class);
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
|
JetClass klass = PsiTreeUtil.getParentOfType(parameter, JetClass.class);
|
||||||
|
if (klass != null && parameter.getParent() == klass.getPrimaryConstructorParameterList()) {
|
||||||
|
return additionalResolveCache.getValue().invoke(klass);
|
||||||
|
}
|
||||||
|
|
||||||
// Parameters for function literal could be met inside other parameters. We can't make resolveToDescriptors for internal elements.
|
// Parameters for function literal could be met inside other parameters. We can't make resolveToDescriptors for internal elements.
|
||||||
jetElement = parameter;
|
jetElement = parameter;
|
||||||
}
|
}
|
||||||
@@ -148,6 +153,9 @@ public class ResolveElementCache {
|
|||||||
else if (resolveElement instanceof JetAnnotationEntry) {
|
else if (resolveElement instanceof JetAnnotationEntry) {
|
||||||
annotationAdditionalResolve(resolveSession, (JetAnnotationEntry) resolveElement);
|
annotationAdditionalResolve(resolveSession, (JetAnnotationEntry) resolveElement);
|
||||||
}
|
}
|
||||||
|
else if (resolveElement instanceof JetClass) {
|
||||||
|
constructorAdditionalResolve(resolveSession, (JetClass) resolveElement, trace, file);
|
||||||
|
}
|
||||||
else if (resolveElement instanceof JetTypeParameter) {
|
else if (resolveElement instanceof JetTypeParameter) {
|
||||||
typeParameterAdditionalResolve(resolveSession, (JetTypeParameter) resolveElement);
|
typeParameterAdditionalResolve(resolveSession, (JetTypeParameter) resolveElement);
|
||||||
}
|
}
|
||||||
@@ -276,6 +284,22 @@ public class ResolveElementCache {
|
|||||||
bodyResolver.resolveFunctionBody(trace, namedFunction, functionDescriptor, scope);
|
bodyResolver.resolveFunctionBody(trace, namedFunction, functionDescriptor, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void constructorAdditionalResolve(
|
||||||
|
ResolveSession resolveSession,
|
||||||
|
JetClass klass,
|
||||||
|
BindingTrace trace,
|
||||||
|
JetFile file
|
||||||
|
) {
|
||||||
|
BodyResolver bodyResolver = createBodyResolverWithEmptyContext(trace, file, resolveSession.getRootModuleDescriptor());
|
||||||
|
JetScope scope = resolveSession.getInjector().getScopeProvider().getResolutionScopeForDeclaration(klass);
|
||||||
|
|
||||||
|
ClassDescriptor classDescriptor = (ClassDescriptor) resolveSession.resolveToDescriptor(klass);
|
||||||
|
ConstructorDescriptor constructorDescriptor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
|
assert constructorDescriptor != null;
|
||||||
|
|
||||||
|
bodyResolver.resolveConstructorParameterDefaultValuesAndAnnotations(trace, klass, constructorDescriptor, scope);
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean initializerAdditionalResolve(
|
private static boolean initializerAdditionalResolve(
|
||||||
KotlinCodeAnalyzer analyzer,
|
KotlinCodeAnalyzer analyzer,
|
||||||
JetClassInitializer classInitializer,
|
JetClassInitializer classInitializer,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package client
|
|||||||
|
|
||||||
import server.Server
|
import server.Server
|
||||||
|
|
||||||
class Client: Server() {
|
class Client(name: String = Server.NAME): Server() {
|
||||||
var nextServer: Server? = new Server()
|
var nextServer: Server? = new Server()
|
||||||
val name = Server.NAME
|
val name = Server.NAME
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ object ClientObject: Server() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Client.bar(s: Server) {
|
fun Client.bar(s: Server = Server.NAME) {
|
||||||
foo(s)
|
foo(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ Function return types (14: 26) fun getNextServer(): Server? {
|
|||||||
Function return types (36: 21) fun Any.asServer(): Server? {
|
Function return types (36: 21) fun Any.asServer(): Server? {
|
||||||
Import directive (3: 15) import server.Server
|
Import directive (3: 15) import server.Server
|
||||||
Local variable type (10: 21) val server: Server = s
|
Local variable type (10: 21) val server: Server = s
|
||||||
|
Nested class/object (28: 28) fun Client.bar(s: Server = Server.NAME) {
|
||||||
|
Nested class/object (5: 29) class Client(name: String = Server.NAME): Server() {
|
||||||
Nested class/object (7: 16) val name = Server.NAME
|
Nested class/object (7: 16) val name = Server.NAME
|
||||||
Parameter type (28: 19) fun Client.bar(s: Server) {
|
Parameter type (28: 19) fun Client.bar(s: Server = Server.NAME) {
|
||||||
Parameter type (9: 16) fun foo(s: Server) {
|
Parameter type (9: 16) fun foo(s: Server) {
|
||||||
Super type qualifier (19: 15) super<Server>.work()
|
Super type qualifier (19: 15) super<Server>.work()
|
||||||
Target type of 'as' operation (37: 40) return if (this is Server) this as Server else null
|
Target type of 'as' operation (37: 40) return if (this is Server) this as Server else null
|
||||||
Target type of 'is' operation (37: 24) return if (this is Server) this as Server else null
|
Target type of 'is' operation (37: 24) return if (this is Server) this as Server else null
|
||||||
Unclassified usage (24: 22) object ClientObject: Server() {
|
Unclassified usage (24: 22) object ClientObject: Server() {
|
||||||
Unclassified usage (5: 15) class Client: Server() {
|
Unclassified usage (5: 43) class Client(name: String = Server.NAME): Server() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package client
|
|||||||
|
|
||||||
import server.Server
|
import server.Server
|
||||||
|
|
||||||
class Client: Server() {
|
class Client(name: String = Server.NAME): Server() {
|
||||||
var nextServer: Server? = new Server()
|
var nextServer: Server? = new Server()
|
||||||
val name = Server.NAME
|
val name = Server.NAME
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ object ClientObject: Server() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Client.bar(s: Server) {
|
fun Client.bar(s: Server = Server.NAME) {
|
||||||
foo(s)
|
foo(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -3,9 +3,11 @@ Function return types (14: 26) fun getNextServer(): Server? {
|
|||||||
Function return types (36: 21) fun Any.asServer(): Server? {
|
Function return types (36: 21) fun Any.asServer(): Server? {
|
||||||
Import directive (3: 15) import server.Server
|
Import directive (3: 15) import server.Server
|
||||||
Local variable type (10: 21) val server: Server = s
|
Local variable type (10: 21) val server: Server = s
|
||||||
|
Nested class/object (28: 28) fun Client.bar(s: Server = Server.NAME) {
|
||||||
|
Nested class/object (5: 29) class Client(name: String = Server.NAME): Server() {
|
||||||
Nested class/object (7: 16) val name = Server.NAME
|
Nested class/object (7: 16) val name = Server.NAME
|
||||||
Parameter type (28: 19) fun Client.bar(s: Server) {
|
Parameter type (28: 19) fun Client.bar(s: Server = Server.NAME) {
|
||||||
Parameter type (9: 16) fun foo(s: Server) {
|
Parameter type (9: 16) fun foo(s: Server) {
|
||||||
Super type qualifier (19: 15) super<Server>.work()
|
Super type qualifier (19: 15) super<Server>.work()
|
||||||
Target type of 'as' operation (37: 40) return if (this is Server) this as Server else null
|
Target type of 'as' operation (37: 40) return if (this is Server) this as Server else null
|
||||||
Target type of 'is' operation (37: 24) return if (this is Server) this as Server else null
|
Target type of 'is' operation (37: 24) return if (this is Server) this as Server else null
|
||||||
|
|||||||
Reference in New Issue
Block a user