提交 a94b77ff 编写于 作者: A Andrey Breslav

Revert GUICE introduction

上级 e9a7a909
<component name="libraryTable">
<library name="guice-3.0">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/guice/aopalliance.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/guice/guice-3.0.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/guice/javax.inject.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<path id="classpath"> <path id="classpath">
<fileset dir="${idea.sdk}" includes="core/*.jar"/> <fileset dir="${idea.sdk}" includes="core/*.jar"/>
<fileset dir="${basedir}/lib" includes="**/*.jar"/> <fileset dir="${basedir}/lib" includes="*.jar"/>
<pathelement path="${output}/classes/runtime"/> <pathelement path="${output}/classes/runtime"/>
</path> </path>
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" /> <orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
<orderEntry type="library" name="guice-3.0" level="project" />
</component> </component>
</module> </module>
...@@ -18,6 +18,8 @@ package org.jetbrains.jet.lang; ...@@ -18,6 +18,8 @@ package org.jetbrains.jet.lang;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker; import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices; import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
...@@ -47,6 +49,16 @@ public class JetSemanticServices { ...@@ -47,6 +49,16 @@ public class JetSemanticServices {
return standardLibrary; return standardLibrary;
} }
@NotNull
public DescriptorResolver getClassDescriptorResolver(BindingTrace trace) {
return new DescriptorResolver(this, trace);
}
@NotNull
public ExpressionTypingServices getTypeInferrerServices(@NotNull BindingTrace trace) {
return new ExpressionTypingServices(this, trace);
}
@NotNull @NotNull
public JetTypeChecker getTypeChecker() { public JetTypeChecker getTypeChecker() {
return typeChecker; return typeChecker;
......
...@@ -36,7 +36,6 @@ import org.jetbrains.jet.lang.types.ErrorUtils; ...@@ -36,7 +36,6 @@ import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices; import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import javax.inject.Inject;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -48,49 +47,46 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; ...@@ -48,49 +47,46 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
*/ */
public class AnnotationResolver { public class AnnotationResolver {
private ExpressionTypingServices expressionTypingServices; private final BindingTrace trace;
private CallResolver callResolver; private final JetSemanticServices semanticServices;
private final CallResolver callResolver;
@Inject public AnnotationResolver(JetSemanticServices semanticServices, BindingTrace trace) {
public void setExpressionTypingServices(ExpressionTypingServices expressionTypingServices) { this.trace = trace;
this.expressionTypingServices = expressionTypingServices; this.callResolver = new CallResolver(semanticServices, DataFlowInfo.EMPTY);
} this.semanticServices = semanticServices;
@Inject
public void setCallResolver(CallResolver.Context callResolverContext) {
this.callResolver = new CallResolver(callResolverContext, DataFlowInfo.EMPTY);
} }
@NotNull @NotNull
public List<AnnotationDescriptor> resolveAnnotations(@NotNull JetScope scope, @Nullable JetModifierList modifierList, BindingTrace trace) { public List<AnnotationDescriptor> resolveAnnotations(@NotNull JetScope scope, @Nullable JetModifierList modifierList) {
if (modifierList == null) { if (modifierList == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return resolveAnnotations(scope, modifierList.getAnnotationEntries(), trace); return resolveAnnotations(scope, modifierList.getAnnotationEntries());
} }
@NotNull @NotNull
public List<AnnotationDescriptor> resolveAnnotations(@NotNull JetScope scope, @NotNull List<JetAnnotationEntry> annotationEntryElements, BindingTrace trace) { public List<AnnotationDescriptor> resolveAnnotations(@NotNull JetScope scope, @NotNull List<JetAnnotationEntry> annotationEntryElements) {
if (annotationEntryElements.isEmpty()) return Collections.emptyList(); if (annotationEntryElements.isEmpty()) return Collections.emptyList();
List<AnnotationDescriptor> result = Lists.newArrayList(); List<AnnotationDescriptor> result = Lists.newArrayList();
for (JetAnnotationEntry entryElement : annotationEntryElements) { for (JetAnnotationEntry entryElement : annotationEntryElements) {
AnnotationDescriptor descriptor = new AnnotationDescriptor(); AnnotationDescriptor descriptor = new AnnotationDescriptor();
resolveAnnotationStub(scope, entryElement, descriptor, trace); resolveAnnotationStub(scope, entryElement, descriptor);
result.add(descriptor); result.add(descriptor);
} }
return result; return result;
} }
public void resolveAnnotationStub(@NotNull JetScope scope, @NotNull JetAnnotationEntry entryElement, public void resolveAnnotationStub(@NotNull JetScope scope, @NotNull JetAnnotationEntry entryElement,
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) { @NotNull AnnotationDescriptor descriptor) {
OverloadResolutionResults<FunctionDescriptor> results = resolveType(scope, entryElement, descriptor, trace); OverloadResolutionResults<FunctionDescriptor> results = resolveType(scope, entryElement, descriptor);
resolveArguments(results, descriptor, trace); resolveArguments(results, descriptor);
} }
@NotNull @NotNull
private OverloadResolutionResults<FunctionDescriptor> resolveType(@NotNull JetScope scope, private OverloadResolutionResults<FunctionDescriptor> resolveType(@NotNull JetScope scope,
@NotNull JetAnnotationEntry entryElement, @NotNull JetAnnotationEntry entryElement,
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) { @NotNull AnnotationDescriptor descriptor) {
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(trace, scope, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, entryElement), NO_EXPECTED_TYPE); OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(trace, scope, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, entryElement), NO_EXPECTED_TYPE);
JetType annotationType = results.getResultingDescriptor().getReturnType(); JetType annotationType = results.getResultingDescriptor().getReturnType();
if (results.isSuccess()) { if (results.isSuccess()) {
...@@ -102,7 +98,7 @@ public class AnnotationResolver { ...@@ -102,7 +98,7 @@ public class AnnotationResolver {
} }
private void resolveArguments(@NotNull OverloadResolutionResults<FunctionDescriptor> results, private void resolveArguments(@NotNull OverloadResolutionResults<FunctionDescriptor> results,
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) { @NotNull AnnotationDescriptor descriptor) {
List<CompileTimeConstant<?>> arguments = Lists.newArrayList(); List<CompileTimeConstant<?>> arguments = Lists.newArrayList();
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument : for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument :
results.getResultingCall().getValueArguments().entrySet()) { results.getResultingCall().getValueArguments().entrySet()) {
...@@ -110,18 +106,19 @@ public class AnnotationResolver { ...@@ -110,18 +106,19 @@ public class AnnotationResolver {
List<JetExpression> argumentExpressions = descriptorToArgument.getValue().getArgumentExpressions(); List<JetExpression> argumentExpressions = descriptorToArgument.getValue().getArgumentExpressions();
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey(); ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
for (JetExpression argument : argumentExpressions) { for (JetExpression argument : argumentExpressions) {
arguments.add(resolveAnnotationArgument(argument, parameterDescriptor.getType(), trace)); arguments.add(resolveAnnotationArgument(argument, parameterDescriptor.getType()));
} }
} }
descriptor.setValueArguments(arguments); descriptor.setValueArguments(arguments);
} }
@Nullable @Nullable
public CompileTimeConstant<?> resolveAnnotationArgument(@NotNull JetExpression expression, @NotNull final JetType expectedType, final BindingTrace trace) { public CompileTimeConstant<?> resolveAnnotationArgument(@NotNull JetExpression expression, @NotNull final JetType expectedType) {
JetVisitor<CompileTimeConstant<?>, Void> visitor = new JetVisitor<CompileTimeConstant<?>, Void>() { JetVisitor<CompileTimeConstant<?>, Void> visitor = new JetVisitor<CompileTimeConstant<?>, Void>() {
@Override @Override
public CompileTimeConstant<?> visitConstantExpression(JetConstantExpression expression, Void nothing) { public CompileTimeConstant<?> visitConstantExpression(JetConstantExpression expression, Void nothing) {
JetType type = expressionTypingServices.getType(JetScope.EMPTY, expression, expectedType, DataFlowInfo.EMPTY, trace); ExpressionTypingServices typeInferrerServices = semanticServices.getTypeInferrerServices(trace);
JetType type = typeInferrerServices.getType(JetScope.EMPTY, expression, expectedType, DataFlowInfo.EMPTY);
if (type == null) { if (type == null) {
// TODO: // TODO:
// trace.report(ANNOTATION_PARAMETER_SHOULD_BE_CONSTANT.on(expression)); // trace.report(ANNOTATION_PARAMETER_SHOULD_BE_CONSTANT.on(expression));
...@@ -164,15 +161,15 @@ public class AnnotationResolver { ...@@ -164,15 +161,15 @@ public class AnnotationResolver {
} }
@NotNull @NotNull
public List<AnnotationDescriptor> createAnnotationStubs(@Nullable JetModifierList modifierList, BindingTrace trace) { public List<AnnotationDescriptor> createAnnotationStubs(@Nullable JetModifierList modifierList) {
if (modifierList == null) { if (modifierList == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
return createAnnotationStubs(modifierList.getAnnotationEntries(), trace); return createAnnotationStubs(modifierList.getAnnotationEntries());
} }
@NotNull @NotNull
public List<AnnotationDescriptor> createAnnotationStubs(List<JetAnnotationEntry> annotations, BindingTrace trace) { public List<AnnotationDescriptor> createAnnotationStubs(List<JetAnnotationEntry> annotations) {
List<AnnotationDescriptor> result = Lists.newArrayList(); List<AnnotationDescriptor> result = Lists.newArrayList();
for (JetAnnotationEntry annotation : annotations) { for (JetAnnotationEntry annotation : annotations) {
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor(); AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
......
...@@ -21,7 +21,6 @@ import com.google.common.collect.Sets; ...@@ -21,7 +21,6 @@ import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.util.containers.Queue; import com.intellij.util.containers.Queue;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.CallMaker; import org.jetbrains.jet.lang.resolve.calls.CallMaker;
...@@ -40,7 +39,6 @@ import org.jetbrains.jet.util.Box; ...@@ -40,7 +39,6 @@ import org.jetbrains.jet.util.Box;
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException; import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
import org.jetbrains.jet.util.slicedmap.WritableSlice; import org.jetbrains.jet.util.slicedmap.WritableSlice;
import javax.inject.Inject;
import java.util.*; import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
...@@ -51,25 +49,13 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; ...@@ -51,25 +49,13 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
* @author abreslav * @author abreslav
*/ */
public class BodyResolver { public class BodyResolver {
@NotNull
private final TopDownAnalysisContext context; private final TopDownAnalysisContext context;
@NotNull
private final JetSemanticServices semanticServices; private final ObservableBindingTrace trace;
@NotNull
private final DescriptorResolver descriptorResolver; public BodyResolver(TopDownAnalysisContext context) {
@NotNull
private final ExpressionTypingServices expressionTypingServices;
@NotNull
private final CallResolver.Context callResolverContext;
@Inject
public BodyResolver(@NotNull TopDownAnalysisContext context,
@NotNull JetSemanticServices semanticServices, @NotNull DescriptorResolver descriptorResolver, @NotNull ExpressionTypingServices expressionTypingServices, CallResolver.Context callResolverContext) {
this.context = context; this.context = context;
this.semanticServices = semanticServices; this.trace = context.getTrace();
this.descriptorResolver = descriptorResolver;
this.expressionTypingServices = expressionTypingServices;
this.callResolverContext = callResolverContext;
} }
public void resolveBehaviorDeclarationBodies() { public void resolveBehaviorDeclarationBodies() {
...@@ -88,7 +74,7 @@ public class BodyResolver { ...@@ -88,7 +74,7 @@ public class BodyResolver {
computeDeferredTypes(); computeDeferredTypes();
} }
} }
private void resolveDelegationSpecifierLists() { private void resolveDelegationSpecifierLists() {
// TODO : Make sure the same thing is not initialized twice // TODO : Make sure the same thing is not initialized twice
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
...@@ -104,8 +90,8 @@ public class BodyResolver { ...@@ -104,8 +90,8 @@ public class BodyResolver {
final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor(); final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor();
final JetScope scopeForConstructor = primaryConstructor == null final JetScope scopeForConstructor = primaryConstructor == null
? null ? null
: FunctionDescriptorUtil.getFunctionInnerScope(descriptor.getScopeForSupertypeResolution(), primaryConstructor, context.getTrace()); : FunctionDescriptorUtil.getFunctionInnerScope(descriptor.getScopeForSupertypeResolution(), primaryConstructor, trace);
final ExpressionTypingServices typeInferrer = expressionTypingServices; // TODO : flow final ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace); // TODO : flow
final Map<JetTypeReference, JetType> supertypes = Maps.newLinkedHashMap(); final Map<JetTypeReference, JetType> supertypes = Maps.newLinkedHashMap();
JetVisitorVoid visitor = new JetVisitorVoid() { JetVisitorVoid visitor = new JetVisitorVoid() {
...@@ -135,8 +121,8 @@ public class BodyResolver { ...@@ -135,8 +121,8 @@ public class BodyResolver {
JetScope scope = scopeForConstructor == null JetScope scope = scopeForConstructor == null
? descriptor.getScopeForMemberResolution() ? descriptor.getScopeForMemberResolution()
: scopeForConstructor; : scopeForConstructor;
JetType type = typeInferrer.getType(scope, delegateExpression, NO_EXPECTED_TYPE, context.getTrace()); JetType type = typeInferrer.getType(scope, delegateExpression, NO_EXPECTED_TYPE);
if (type != null && supertype != null && !semanticServices.getTypeChecker().isSubtypeOf(type, supertype)) { if (type != null && supertype != null && !context.getSemanticServices().getTypeChecker().isSubtypeOf(type, supertype)) {
context.getTrace().report(TYPE_MISMATCH.on(delegateExpression, supertype, type)); context.getTrace().report(TYPE_MISMATCH.on(delegateExpression, supertype, type));
} }
} }
...@@ -155,7 +141,7 @@ public class BodyResolver { ...@@ -155,7 +141,7 @@ public class BodyResolver {
assert descriptor.getKind() == ClassKind.TRAIT; assert descriptor.getKind() == ClassKind.TRAIT;
return; return;
} }
OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(callResolverContext, DataFlowInfo.EMPTY).resolveCall( OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall(
context.getTrace(), scopeForConstructor, context.getTrace(), scopeForConstructor,
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE); CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
if (results.isSuccess()) { if (results.isSuccess()) {
...@@ -275,8 +261,9 @@ public class BodyResolver { ...@@ -275,8 +261,9 @@ public class BodyResolver {
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor(); ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
assert primaryConstructor != null; assert primaryConstructor != null;
final JetScope scopeForInitializers = classDescriptor.getScopeForInitializers(); final JetScope scopeForInitializers = classDescriptor.getScopeForInitializers();
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
for (JetClassInitializer anonymousInitializer : anonymousInitializers) { for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
expressionTypingServices.getType(scopeForInitializers, anonymousInitializer.getBody(), NO_EXPECTED_TYPE, context.getTrace()); typeInferrer.getType(scopeForInitializers, anonymousInitializer.getBody(), NO_EXPECTED_TYPE);
} }
} }
else { else {
...@@ -311,12 +298,12 @@ public class BodyResolver { ...@@ -311,12 +298,12 @@ public class BodyResolver {
private void resolveSecondaryConstructorBody(JetSecondaryConstructor declaration, final ConstructorDescriptor descriptor) { private void resolveSecondaryConstructorBody(JetSecondaryConstructor declaration, final ConstructorDescriptor descriptor) {
if (!context.completeAnalysisNeeded(declaration)) return; if (!context.completeAnalysisNeeded(declaration)) return;
MutableClassDescriptor classDescriptor = (MutableClassDescriptor) descriptor.getContainingDeclaration(); MutableClassDescriptor classDescriptor = (MutableClassDescriptor) descriptor.getContainingDeclaration();
final JetScope scopeForSupertypeInitializers = FunctionDescriptorUtil.getFunctionInnerScope(classDescriptor.getScopeForSupertypeResolution(), descriptor, context.getTrace()); final JetScope scopeForSupertypeInitializers = FunctionDescriptorUtil.getFunctionInnerScope(classDescriptor.getScopeForSupertypeResolution(), descriptor, trace);
//contains only constructor parameters //contains only constructor parameters
final JetScope scopeForConstructorBody = FunctionDescriptorUtil.getFunctionInnerScope(classDescriptor.getScopeForInitializers(), descriptor, context.getTrace()); final JetScope scopeForConstructorBody = FunctionDescriptorUtil.getFunctionInnerScope(classDescriptor.getScopeForInitializers(), descriptor, trace);
//contains members & backing fields //contains members & backing fields
final CallResolver callResolver = new CallResolver(callResolverContext, DataFlowInfo.EMPTY); // TODO: dataFlowInfo final CallResolver callResolver = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY); // TODO: dataFlowInfo
PsiElement nameElement = declaration.getNameNode().getPsi(); PsiElement nameElement = declaration.getNameNode().getPsi();
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) { if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
...@@ -376,8 +363,9 @@ public class BodyResolver { ...@@ -376,8 +363,9 @@ public class BodyResolver {
} }
JetExpression bodyExpression = declaration.getBodyExpression(); JetExpression bodyExpression = declaration.getBodyExpression();
if (bodyExpression != null) { if (bodyExpression != null) {
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
expressionTypingServices.checkFunctionReturnType(scopeForConstructorBody, declaration, descriptor, JetStandardClasses.getUnitType(), context.getTrace()); typeInferrer.checkFunctionReturnType(scopeForConstructorBody, declaration, descriptor, JetStandardClasses.getUnitType());
} }
checkDefaultParameterValues(declaration.getValueParameters(), descriptor.getValueParameters(), scopeForConstructorBody); checkDefaultParameterValues(declaration.getValueParameters(), descriptor.getValueParameters(), scopeForConstructorBody);
...@@ -436,8 +424,8 @@ public class BodyResolver { ...@@ -436,8 +424,8 @@ public class BodyResolver {
private JetScope makeScopeForPropertyAccessor(@NotNull JetPropertyAccessor accessor, PropertyDescriptor propertyDescriptor) { private JetScope makeScopeForPropertyAccessor(@NotNull JetPropertyAccessor accessor, PropertyDescriptor propertyDescriptor) {
JetScope declaringScope = context.getDeclaringScopes().get(accessor); JetScope declaringScope = context.getDeclaringScopes().get(accessor);
JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScope( JetScope propertyDeclarationInnerScope = context.getDescriptorResolver().getPropertyDeclarationInnerScope(
declaringScope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter(), context.getTrace()); declaringScope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter());
WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope"); WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
accessorScope.changeLockLevel(WritableScope.LockLevel.READING); accessorScope.changeLockLevel(WritableScope.LockLevel.READING);
...@@ -463,7 +451,7 @@ public class BodyResolver { ...@@ -463,7 +451,7 @@ public class BodyResolver {
} }
private ObservableBindingTrace createFieldTrackingTrace(final PropertyDescriptor propertyDescriptor) { private ObservableBindingTrace createFieldTrackingTrace(final PropertyDescriptor propertyDescriptor) {
return new ObservableBindingTrace(context.getTrace()).addHandler(BindingContext.REFERENCE_TARGET, new ObservableBindingTrace.RecordHandler<JetReferenceExpression, DeclarationDescriptor>() { return new ObservableBindingTrace(trace).addHandler(BindingContext.REFERENCE_TARGET, new ObservableBindingTrace.RecordHandler<JetReferenceExpression, DeclarationDescriptor>() {
@Override @Override
public void handleRecord(WritableSlice<JetReferenceExpression, DeclarationDescriptor> slice, JetReferenceExpression expression, DeclarationDescriptor descriptor) { public void handleRecord(WritableSlice<JetReferenceExpression, DeclarationDescriptor> slice, JetReferenceExpression expression, DeclarationDescriptor descriptor) {
if (expression instanceof JetSimpleNameExpression) { if (expression instanceof JetSimpleNameExpression) {
...@@ -471,7 +459,7 @@ public class BodyResolver { ...@@ -471,7 +459,7 @@ public class BodyResolver {
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
// This check may be considered redundant as long as $x is only accessible from accessors to $x // This check may be considered redundant as long as $x is only accessible from accessors to $x
if (descriptor == propertyDescriptor) { // TODO : original? if (descriptor == propertyDescriptor) { // TODO : original?
context.getTrace().record(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor); // TODO: this context.getTrace()? trace.record(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor); // TODO: this context.getTrace()?
} }
} }
} }
...@@ -481,8 +469,9 @@ public class BodyResolver { ...@@ -481,8 +469,9 @@ public class BodyResolver {
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) { private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15 //JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE; JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
JetType type = expressionTypingServices.getType(descriptorResolver.getPropertyDeclarationInnerScope(scope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter(), context.getTrace()), initializer, expectedTypeForInitializer, context.getTrace()); JetType type = typeInferrer.getType(context.getDescriptorResolver().getPropertyDeclarationInnerScope(scope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter()), initializer, expectedTypeForInitializer);
// //
// JetType expectedType = propertyDescriptor.getInType(); // JetType expectedType = propertyDescriptor.getInType();
// if (expectedType == null) { // if (expectedType == null) {
...@@ -504,7 +493,7 @@ public class BodyResolver { ...@@ -504,7 +493,7 @@ public class BodyResolver {
JetScope declaringScope = this.context.getDeclaringScopes().get(declaration); JetScope declaringScope = this.context.getDeclaringScopes().get(declaration);
assert declaringScope != null; assert declaringScope != null;
resolveFunctionBody(context.getTrace(), declaration, descriptor, declaringScope); resolveFunctionBody(trace, declaration, descriptor, declaringScope);
assert descriptor.getReturnType() != null; assert descriptor.getReturnType() != null;
} }
...@@ -520,7 +509,9 @@ public class BodyResolver { ...@@ -520,7 +509,9 @@ public class BodyResolver {
JetExpression bodyExpression = function.getBodyExpression(); JetExpression bodyExpression = function.getBodyExpression();
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(declaringScope, functionDescriptor, trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(declaringScope, functionDescriptor, trace);
if (bodyExpression != null) { if (bodyExpression != null) {
expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, trace); ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
typeInferrer.checkFunctionReturnType(functionInnerScope, function, functionDescriptor);
} }
List<JetParameter> valueParameters = function.getValueParameters(); List<JetParameter> valueParameters = function.getValueParameters();
...@@ -532,13 +523,14 @@ public class BodyResolver { ...@@ -532,13 +523,14 @@ public class BodyResolver {
} }
private void checkDefaultParameterValues(List<JetParameter> valueParameters, List<ValueParameterDescriptor> valueParameterDescriptors, JetScope declaringScope) { private void checkDefaultParameterValues(List<JetParameter> valueParameters, List<ValueParameterDescriptor> valueParameterDescriptors, JetScope declaringScope) {
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
for (int i = 0; i < valueParameters.size(); i++) { for (int i = 0; i < valueParameters.size(); i++) {
ValueParameterDescriptor valueParameterDescriptor = valueParameterDescriptors.get(i); ValueParameterDescriptor valueParameterDescriptor = valueParameterDescriptors.get(i);
if (valueParameterDescriptor.hasDefaultValue()) { if (valueParameterDescriptor.hasDefaultValue()) {
JetParameter jetParameter = valueParameters.get(i); JetParameter jetParameter = valueParameters.get(i);
JetExpression defaultValue = jetParameter.getDefaultValue(); JetExpression defaultValue = jetParameter.getDefaultValue();
if (defaultValue != null) { if (defaultValue != null) {
expressionTypingServices.getType(declaringScope, defaultValue, valueParameterDescriptor.getType(), context.getTrace()); typeInferrer.getType(declaringScope, defaultValue, valueParameterDescriptor.getType());
} }
} }
} }
......
...@@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.psi.*; ...@@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import javax.inject.Inject;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -35,10 +34,9 @@ public class DeclarationResolver { ...@@ -35,10 +34,9 @@ public class DeclarationResolver {
private final AnnotationResolver annotationResolver; private final AnnotationResolver annotationResolver;
private final TopDownAnalysisContext context; private final TopDownAnalysisContext context;
@Inject public DeclarationResolver(TopDownAnalysisContext context) {
public DeclarationResolver(AnnotationResolver annotationResolver, TopDownAnalysisContext context) {
this.annotationResolver = annotationResolver;
this.context = context; this.context = context;
this.annotationResolver = new AnnotationResolver(context.getSemanticServices(), context.getTrace());
} }
public void process() { public void process() {
...@@ -61,6 +59,7 @@ public class DeclarationResolver { ...@@ -61,6 +59,7 @@ public class DeclarationResolver {
} }
private void resolveAnnotationStubsOnClassesAndConstructors() { private void resolveAnnotationStubsOnClassesAndConstructors() {
AnnotationResolver annotationResolver = new AnnotationResolver(context.getSemanticServices(), context.getTrace());
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey(); JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
...@@ -76,7 +75,7 @@ public class DeclarationResolver { ...@@ -76,7 +75,7 @@ public class DeclarationResolver {
private void resolveAnnotationsForClassOrObject(AnnotationResolver annotationResolver, JetClassOrObject jetClass, MutableClassDescriptor descriptor) { private void resolveAnnotationsForClassOrObject(AnnotationResolver annotationResolver, JetClassOrObject jetClass, MutableClassDescriptor descriptor) {
JetModifierList modifierList = jetClass.getModifierList(); JetModifierList modifierList = jetClass.getModifierList();
if (modifierList != null) { if (modifierList != null) {
descriptor.getAnnotations().addAll(annotationResolver.resolveAnnotations(descriptor.getScopeForSupertypeResolution(), modifierList.getAnnotationEntries(), context.getTrace())); descriptor.getAnnotations().addAll(annotationResolver.resolveAnnotations(descriptor.getScopeForSupertypeResolution(), modifierList.getAnnotationEntries()));
} }
} }
...@@ -121,7 +120,7 @@ public class DeclarationResolver { ...@@ -121,7 +120,7 @@ public class DeclarationResolver {
declaration.accept(new JetVisitorVoid() { declaration.accept(new JetVisitorVoid() {
@Override @Override
public void visitNamedFunction(JetNamedFunction function) { public void visitNamedFunction(JetNamedFunction function) {
SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function, context.getTrace()); SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
namespaceLike.addFunctionDescriptor(functionDescriptor); namespaceLike.addFunctionDescriptor(functionDescriptor);
context.getFunctions().put(function, functionDescriptor); context.getFunctions().put(function, functionDescriptor);
context.getDeclaringScopes().put(function, scopeForFunctions); context.getDeclaringScopes().put(function, scopeForFunctions);
...@@ -129,7 +128,7 @@ public class DeclarationResolver { ...@@ -129,7 +128,7 @@ public class DeclarationResolver {
@Override @Override
public void visitProperty(JetProperty property) { public void visitProperty(JetProperty property) {
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scopeForPropertyInitializers, property, context.getTrace()); PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scopeForPropertyInitializers, property);
namespaceLike.addPropertyDescriptor(propertyDescriptor); namespaceLike.addPropertyDescriptor(propertyDescriptor);
context.getProperties().put(property, propertyDescriptor); context.getProperties().put(property, propertyDescriptor);
context.getDeclaringScopes().put(property, scopeForPropertyInitializers); context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
...@@ -143,7 +142,7 @@ public class DeclarationResolver { ...@@ -143,7 +142,7 @@ public class DeclarationResolver {
@Override @Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) { public void visitObjectDeclaration(JetObjectDeclaration declaration) {
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration), context.getTrace()); PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration));
namespaceLike.addPropertyDescriptor(propertyDescriptor); namespaceLike.addPropertyDescriptor(propertyDescriptor);
} }
...@@ -152,7 +151,7 @@ public class DeclarationResolver { ...@@ -152,7 +151,7 @@ public class DeclarationResolver {
if (enumEntry.getPrimaryConstructorParameterList() == null) { if (enumEntry.getPrimaryConstructorParameterList() == null) {
MutableClassDescriptorLite classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor(); MutableClassDescriptorLite classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
assert classObjectDescriptor != null; assert classObjectDescriptor != null;
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), context.getTrace()); PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry));
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor); classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
} }
} }
...@@ -171,13 +170,13 @@ public class DeclarationResolver { ...@@ -171,13 +170,13 @@ public class DeclarationResolver {
// TODO : not all the parameters are real properties // TODO : not all the parameters are real properties
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution(); JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass, context.getTrace()); ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) { for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
if (parameter.getValOrVarNode() != null) { if (parameter.getValOrVarNode() != null) {
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty( PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
classDescriptor, classDescriptor,
memberScope, memberScope,
parameter, context.getTrace() parameter
); );
classDescriptor.addPropertyDescriptor(propertyDescriptor); classDescriptor.addPropertyDescriptor(propertyDescriptor);
context.getPrimaryConstructorParameterProperties().add(propertyDescriptor); context.getPrimaryConstructorParameterProperties().add(propertyDescriptor);
...@@ -195,7 +194,7 @@ public class DeclarationResolver { ...@@ -195,7 +194,7 @@ public class DeclarationResolver {
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolveSecondaryConstructorDescriptor( ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolveSecondaryConstructorDescriptor(
classDescriptor.getScopeForMemberResolution(), classDescriptor.getScopeForMemberResolution(),
classDescriptor, classDescriptor,
constructor, context.getTrace()); constructor);
classDescriptor.addConstructor(constructorDescriptor, context.getTrace()); classDescriptor.addConstructor(constructorDescriptor, context.getTrace());
context.getConstructors().put(constructor, constructorDescriptor); context.getConstructors().put(constructor, constructorDescriptor);
context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup()); context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
......
...@@ -34,14 +34,12 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; ...@@ -34,14 +34,12 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.util.lazy.LazyValue; import org.jetbrains.jet.util.lazy.LazyValue;
import org.jetbrains.jet.util.lazy.LazyValueWithDefault; import org.jetbrains.jet.util.lazy.LazyValueWithDefault;
import javax.inject.Inject;
import java.util.*; import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
...@@ -50,39 +48,28 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.*; ...@@ -50,39 +48,28 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.*;
* @author abreslav * @author abreslav
*/ */
public class DescriptorResolver { public class DescriptorResolver {
private JetSemanticServices semanticServices; private final JetSemanticServices semanticServices;
private TypeResolver typeResolver; private final TypeResolver typeResolver;
private AnnotationResolver annotationResolver; private final TypeResolver typeResolverNotCheckingBounds;
private ExpressionTypingServices expressionTypingServices; private final BindingTrace trace;
private final AnnotationResolver annotationResolver;
@Inject public DescriptorResolver(JetSemanticServices semanticServices, BindingTrace trace) {
public void setSemanticServices(JetSemanticServices semanticServices) {
this.semanticServices = semanticServices; this.semanticServices = semanticServices;
this.typeResolver = new TypeResolver(semanticServices, trace, true);
this.typeResolverNotCheckingBounds = new TypeResolver(semanticServices, trace, false);
this.trace = trace;
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
} }
@Inject public void resolveMutableClassDescriptor(@NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) {
public void setTypeResolver(TypeResolver typeResolver) {
this.typeResolver = typeResolver;
}
@Inject
public void setAnnotationResolver(AnnotationResolver annotationResolver) {
this.annotationResolver = annotationResolver;
}
@Inject
public void setExpressionTypingServices(ExpressionTypingServices expressionTypingServices) {
this.expressionTypingServices = expressionTypingServices;
}
public void resolveMutableClassDescriptor(@NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor, BindingTrace trace) {
// TODO : Where-clause // TODO : Where-clause
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList(); List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
int index = 0; int index = 0;
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) { for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
descriptor, descriptor,
annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace), annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
!typeParameter.hasModifier(JetTokens.ERASED_KEYWORD), !typeParameter.hasModifier(JetTokens.ERASED_KEYWORD),
typeParameter.getVariance(), typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()), JetPsiUtil.safeName(typeParameter.getName()),
...@@ -100,16 +87,16 @@ public class DescriptorResolver { ...@@ -100,16 +87,16 @@ public class DescriptorResolver {
trace.record(BindingContext.CLASS, classElement, descriptor); trace.record(BindingContext.CLASS, classElement, descriptor);
} }
public void resolveSupertypes(@NotNull JetClassOrObject jetClass, @NotNull MutableClassDescriptor descriptor, BindingTrace trace) { public void resolveSupertypes(@NotNull JetClassOrObject jetClass, @NotNull MutableClassDescriptor descriptor) {
List<JetDelegationSpecifier> delegationSpecifiers = jetClass.getDelegationSpecifiers(); List<JetDelegationSpecifier> delegationSpecifiers = jetClass.getDelegationSpecifiers();
if (delegationSpecifiers.isEmpty()) { if (delegationSpecifiers.isEmpty()) {
descriptor.addSupertype(getDefaultSupertype(jetClass, trace)); descriptor.addSupertype(getDefaultSupertype(jetClass));
} }
else { else {
Collection<JetType> supertypes = resolveDelegationSpecifiers( Collection<JetType> supertypes = resolveDelegationSpecifiers(
descriptor.getScopeForSupertypeResolution(), descriptor.getScopeForSupertypeResolution(),
delegationSpecifiers, delegationSpecifiers,
typeResolver, trace, false); typeResolverNotCheckingBounds);
for (JetType supertype : supertypes) { for (JetType supertype : supertypes) {
descriptor.addSupertype(supertype); descriptor.addSupertype(supertype);
} }
...@@ -117,7 +104,7 @@ public class DescriptorResolver { ...@@ -117,7 +104,7 @@ public class DescriptorResolver {
} }
private JetType getDefaultSupertype(JetClassOrObject jetClass, BindingTrace trace) { private JetType getDefaultSupertype(JetClassOrObject jetClass) {
// TODO : beautify // TODO : beautify
if (jetClass instanceof JetEnumEntry) { if (jetClass instanceof JetEnumEntry) {
JetClassOrObject parent = PsiTreeUtil.getParentOfType(jetClass, JetClassOrObject.class); JetClassOrObject parent = PsiTreeUtil.getParentOfType(jetClass, JetClassOrObject.class);
...@@ -133,7 +120,7 @@ public class DescriptorResolver { ...@@ -133,7 +120,7 @@ public class DescriptorResolver {
return JetStandardClasses.getAnyType(); return JetStandardClasses.getAnyType();
} }
public Collection<JetType> resolveDelegationSpecifiers(JetScope extensibleScope, List<JetDelegationSpecifier> delegationSpecifiers, @NotNull TypeResolver resolver, BindingTrace trace, boolean checkBounds) { public Collection<JetType> resolveDelegationSpecifiers(JetScope extensibleScope, List<JetDelegationSpecifier> delegationSpecifiers, @NotNull TypeResolver resolver) {
if (delegationSpecifiers.isEmpty()) { if (delegationSpecifiers.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
...@@ -141,7 +128,7 @@ public class DescriptorResolver { ...@@ -141,7 +128,7 @@ public class DescriptorResolver {
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) { for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
JetTypeReference typeReference = delegationSpecifier.getTypeReference(); JetTypeReference typeReference = delegationSpecifier.getTypeReference();
if (typeReference != null) { if (typeReference != null) {
result.add(resolver.resolveType(extensibleScope, typeReference, trace, checkBounds)); result.add(resolver.resolveType(extensibleScope, typeReference));
JetTypeElement typeElement = typeReference.getTypeElement(); JetTypeElement typeElement = typeReference.getTypeElement();
while (typeElement instanceof JetNullableType) { while (typeElement instanceof JetNullableType) {
JetNullableType nullableType = (JetNullableType) typeElement; JetNullableType nullableType = (JetNullableType) typeElement;
...@@ -166,19 +153,19 @@ public class DescriptorResolver { ...@@ -166,19 +153,19 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public SimpleFunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function, final BindingTrace trace) { public SimpleFunctionDescriptor resolveFunctionDescriptor(DeclarationDescriptor containingDescriptor, final JetScope scope, final JetNamedFunction function) {
final SimpleFunctionDescriptorImpl functionDescriptor = new SimpleFunctionDescriptorImpl( final SimpleFunctionDescriptorImpl functionDescriptor = new SimpleFunctionDescriptorImpl(
containingDescriptor, containingDescriptor,
annotationResolver.resolveAnnotations(scope, function.getModifierList(), trace), annotationResolver.resolveAnnotations(scope, function.getModifierList()),
JetPsiUtil.safeName(function.getName()), JetPsiUtil.safeName(function.getName()),
CallableMemberDescriptor.Kind.DECLARATION CallableMemberDescriptor.Kind.DECLARATION
); );
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope"); WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope");
innerScope.addLabeledDeclaration(functionDescriptor); innerScope.addLabeledDeclaration(functionDescriptor);
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace); List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters());
innerScope.changeLockLevel(WritableScope.LockLevel.BOTH); innerScope.changeLockLevel(WritableScope.LockLevel.BOTH);
resolveGenericBounds(function, innerScope, typeParameterDescriptors, trace); resolveGenericBounds(function, innerScope, typeParameterDescriptors);
JetType receiverType = null; JetType receiverType = null;
JetTypeReference receiverTypeRef = function.getReceiverTypeRef(); JetTypeReference receiverTypeRef = function.getReceiverTypeRef();
...@@ -187,17 +174,17 @@ public class DescriptorResolver { ...@@ -187,17 +174,17 @@ public class DescriptorResolver {
function.hasTypeParameterListBeforeFunctionName() function.hasTypeParameterListBeforeFunctionName()
? innerScope ? innerScope
: scope; : scope;
receiverType = typeResolver.resolveType(scopeForReceiver, receiverTypeRef, trace, true); receiverType = typeResolver.resolveType(scopeForReceiver, receiverTypeRef);
} }
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, innerScope, function.getValueParameters(), trace); List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, innerScope, function.getValueParameters());
innerScope.changeLockLevel(WritableScope.LockLevel.READING); innerScope.changeLockLevel(WritableScope.LockLevel.READING);
JetTypeReference returnTypeRef = function.getReturnTypeRef(); JetTypeReference returnTypeRef = function.getReturnTypeRef();
JetType returnType; JetType returnType;
if (returnTypeRef != null) { if (returnTypeRef != null) {
returnType = typeResolver.resolveType(innerScope, returnTypeRef, trace, true); returnType = typeResolver.resolveType(innerScope, returnTypeRef);
} }
else if (function.hasBlockBody()) { else if (function.hasBlockBody()) {
returnType = JetStandardClasses.getUnitType(); returnType = JetStandardClasses.getUnitType();
...@@ -209,7 +196,7 @@ public class DescriptorResolver { ...@@ -209,7 +196,7 @@ public class DescriptorResolver {
@Override @Override
protected JetType compute() { protected JetType compute() {
//JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression); //JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression);
return expressionTypingServices.inferFunctionReturnType(scope, function, functionDescriptor, trace); return semanticServices.getTypeInferrerServices(trace).inferFunctionReturnType(scope, function, functionDescriptor);
} }
}); });
} }
...@@ -249,7 +236,7 @@ public class DescriptorResolver { ...@@ -249,7 +236,7 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
private List<ValueParameterDescriptor> resolveValueParameters(FunctionDescriptor functionDescriptor, WritableScope parameterScope, List<JetParameter> valueParameters, BindingTrace trace) { private List<ValueParameterDescriptor> resolveValueParameters(FunctionDescriptor functionDescriptor, WritableScope parameterScope, List<JetParameter> valueParameters) {
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>(); List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) { for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
JetParameter valueParameter = valueParameters.get(i); JetParameter valueParameter = valueParameters.get(i);
...@@ -260,10 +247,10 @@ public class DescriptorResolver { ...@@ -260,10 +247,10 @@ public class DescriptorResolver {
trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter)); trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter));
type = ErrorUtils.createErrorType("Type annotation was missing"); type = ErrorUtils.createErrorType("Type annotation was missing");
} else { } else {
type = typeResolver.resolveType(parameterScope, typeReference, trace, true); type = typeResolver.resolveType(parameterScope, typeReference);
} }
ValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(functionDescriptor, valueParameter, i, type, trace); ValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(functionDescriptor, valueParameter, i, type);
parameterScope.addVariableDescriptor(valueParameterDescriptor); parameterScope.addVariableDescriptor(valueParameterDescriptor);
result.add(valueParameterDescriptor); result.add(valueParameterDescriptor);
} }
...@@ -271,7 +258,7 @@ public class DescriptorResolver { ...@@ -271,7 +258,7 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public MutableValueParameterDescriptor resolveValueParameterDescriptor(DeclarationDescriptor declarationDescriptor, JetParameter valueParameter, int index, JetType type, BindingTrace trace) { public MutableValueParameterDescriptor resolveValueParameterDescriptor(DeclarationDescriptor declarationDescriptor, JetParameter valueParameter, int index, JetType type) {
JetType varargElementType = null; JetType varargElementType = null;
JetType variableType = type; JetType variableType = type;
if (valueParameter.hasModifier(JetTokens.VARARG_KEYWORD)) { if (valueParameter.hasModifier(JetTokens.VARARG_KEYWORD)) {
...@@ -281,7 +268,7 @@ public class DescriptorResolver { ...@@ -281,7 +268,7 @@ public class DescriptorResolver {
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl( MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
declarationDescriptor, declarationDescriptor,
index, index,
annotationResolver.createAnnotationStubs(valueParameter.getModifierList(), trace), annotationResolver.createAnnotationStubs(valueParameter.getModifierList()),
JetPsiUtil.safeName(valueParameter.getName()), JetPsiUtil.safeName(valueParameter.getName()),
valueParameter.isMutable(), valueParameter.isMutable(),
variableType, variableType,
...@@ -303,23 +290,23 @@ public class DescriptorResolver { ...@@ -303,23 +290,23 @@ public class DescriptorResolver {
} }
} }
public List<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters, BindingTrace trace) { public List<TypeParameterDescriptor> resolveTypeParameters(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, List<JetTypeParameter> typeParameters) {
List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>(); List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>();
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) { for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
JetTypeParameter typeParameter = typeParameters.get(i); JetTypeParameter typeParameter = typeParameters.get(i);
result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter, i, trace)); result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter, i));
} }
return result; return result;
} }
private TypeParameterDescriptor resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter, int index, BindingTrace trace) { private TypeParameterDescriptor resolveTypeParameter(DeclarationDescriptor containingDescriptor, WritableScope extensibleScope, JetTypeParameter typeParameter, int index) {
// JetTypeReference extendsBound = typeParameter.getExtendsBound(); // JetTypeReference extendsBound = typeParameter.getExtendsBound();
// JetType bound = extendsBound == null // JetType bound = extendsBound == null
// ? JetStandardClasses.getDefaultBound() // ? JetStandardClasses.getDefaultBound()
// : typeResolver.resolveType(extensibleScope, extendsBound); // : typeResolver.resolveType(extensibleScope, extendsBound);
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification( TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
containingDescriptor, containingDescriptor,
annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace), annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
!typeParameter.hasModifier(JetTokens.ERASED_KEYWORD), !typeParameter.hasModifier(JetTokens.ERASED_KEYWORD),
typeParameter.getVariance(), typeParameter.getVariance(),
JetPsiUtil.safeName(typeParameter.getName()), JetPsiUtil.safeName(typeParameter.getName()),
...@@ -331,7 +318,7 @@ public class DescriptorResolver { ...@@ -331,7 +318,7 @@ public class DescriptorResolver {
return typeParameterDescriptor; return typeParameterDescriptor;
} }
public void resolveGenericBounds(@NotNull JetTypeParameterListOwner declaration, JetScope scope, List<TypeParameterDescriptor> parameters, BindingTrace trace) { public void resolveGenericBounds(@NotNull JetTypeParameterListOwner declaration, JetScope scope, List<TypeParameterDescriptor> parameters) {
List<JetTypeParameter> typeParameters = declaration.getTypeParameters(); List<JetTypeParameter> typeParameters = declaration.getTypeParameters();
Map<String, TypeParameterDescriptor> parameterByName = Maps.newHashMap(); Map<String, TypeParameterDescriptor> parameterByName = Maps.newHashMap();
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) { for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
...@@ -340,7 +327,7 @@ public class DescriptorResolver { ...@@ -340,7 +327,7 @@ public class DescriptorResolver {
parameterByName.put(typeParameterDescriptor.getName(), typeParameterDescriptor); parameterByName.put(typeParameterDescriptor.getName(), typeParameterDescriptor);
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound(); JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
if (extendsBound != null) { if (extendsBound != null) {
typeParameterDescriptor.addUpperBound(resolveAndCheckUpperBoundType(extendsBound, scope, false, trace)); typeParameterDescriptor.addUpperBound(resolveAndCheckUpperBoundType(extendsBound, scope, false));
} }
} }
for (JetTypeConstraint constraint : declaration.getTypeConstaints()) { for (JetTypeConstraint constraint : declaration.getTypeConstaints()) {
...@@ -354,7 +341,7 @@ public class DescriptorResolver { ...@@ -354,7 +341,7 @@ public class DescriptorResolver {
} }
TypeParameterDescriptor typeParameterDescriptor = parameterByName.get(referencedName); TypeParameterDescriptor typeParameterDescriptor = parameterByName.get(referencedName);
JetTypeReference boundTypeReference = constraint.getBoundTypeReference(); JetTypeReference boundTypeReference = constraint.getBoundTypeReference();
JetType bound = boundTypeReference != null ? resolveAndCheckUpperBoundType(boundTypeReference, scope, constraint.isClassObjectContraint(), trace) : null; JetType bound = boundTypeReference != null ? resolveAndCheckUpperBoundType(boundTypeReference, scope, constraint.isClassObjectContraint()) : null;
if (typeParameterDescriptor == null) { if (typeParameterDescriptor == null) {
// To tell the user that we look only for locally defined type parameters // To tell the user that we look only for locally defined type parameters
ClassifierDescriptor classifier = scope.getClassifier(referencedName); ClassifierDescriptor classifier = scope.getClassifier(referencedName);
...@@ -401,8 +388,8 @@ public class DescriptorResolver { ...@@ -401,8 +388,8 @@ public class DescriptorResolver {
} }
} }
private JetType resolveAndCheckUpperBoundType(@NotNull JetTypeReference upperBound, @NotNull JetScope scope, boolean classObjectConstaint, BindingTrace trace) { private JetType resolveAndCheckUpperBoundType(@NotNull JetTypeReference upperBound, @NotNull JetScope scope, boolean classObjectConstaint) {
JetType jetType = typeResolver.resolveType(scope, upperBound, trace, false); JetType jetType = typeResolverNotCheckingBounds.resolveType(scope, upperBound);
if (!TypeUtils.canHaveSubtypes(semanticServices.getTypeChecker(), jetType)) { if (!TypeUtils.canHaveSubtypes(semanticServices.getTypeChecker(), jetType)) {
if (classObjectConstaint) { if (classObjectConstaint) {
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, jetType)); trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, jetType));
...@@ -415,16 +402,16 @@ public class DescriptorResolver { ...@@ -415,16 +402,16 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter, BindingTrace trace) { public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter) {
JetType type = resolveParameterType(scope, parameter, trace); JetType type = resolveParameterType(scope, parameter);
return resolveLocalVariableDescriptor(containingDeclaration, parameter, type, trace); return resolveLocalVariableDescriptor(containingDeclaration, parameter, type);
} }
private JetType resolveParameterType(JetScope scope, JetParameter parameter, BindingTrace trace) { private JetType resolveParameterType(JetScope scope, JetParameter parameter) {
JetTypeReference typeReference = parameter.getTypeReference(); JetTypeReference typeReference = parameter.getTypeReference();
JetType type; JetType type;
if (typeReference != null) { if (typeReference != null) {
type = typeResolver.resolveType(scope, typeReference, trace, true); type = typeResolver.resolveType(scope, typeReference);
} }
else { else {
// Error is reported by the parser // Error is reported by the parser
...@@ -433,10 +420,10 @@ public class DescriptorResolver { ...@@ -433,10 +420,10 @@ public class DescriptorResolver {
return type; return type;
} }
public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetParameter parameter, @NotNull JetType type, BindingTrace trace) { public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetParameter parameter, @NotNull JetType type) {
VariableDescriptor variableDescriptor = new LocalVariableDescriptor( VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
containingDeclaration, containingDeclaration,
annotationResolver.createAnnotationStubs(parameter.getModifierList(), trace), annotationResolver.createAnnotationStubs(parameter.getModifierList()),
JetPsiUtil.safeName(parameter.getName()), JetPsiUtil.safeName(parameter.getName()),
type, type,
parameter.isMutable()); parameter.isMutable());
...@@ -445,19 +432,19 @@ public class DescriptorResolver { ...@@ -445,19 +432,19 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public VariableDescriptor resolveLocalVariableDescriptor(DeclarationDescriptor containingDeclaration, JetScope scope, JetProperty property, DataFlowInfo dataFlowInfo, BindingTrace trace) { public VariableDescriptor resolveLocalVariableDescriptor(DeclarationDescriptor containingDeclaration, JetScope scope, JetProperty property, DataFlowInfo dataFlowInfo) {
VariableDescriptorImpl variableDescriptor = resolveLocalVariableDescriptorWithType(containingDeclaration, property, null, trace); VariableDescriptorImpl variableDescriptor = resolveLocalVariableDescriptorWithType(containingDeclaration, property, null);
JetType type = getVariableType(scope, property, dataFlowInfo, false, trace); // For a local variable the type must not be deferred JetType type = getVariableType(scope, property, dataFlowInfo, false); // For a local variable the type must not be deferred
variableDescriptor.setOutType(type); variableDescriptor.setOutType(type);
return variableDescriptor; return variableDescriptor;
} }
@NotNull @NotNull
public VariableDescriptorImpl resolveLocalVariableDescriptorWithType(DeclarationDescriptor containingDeclaration, JetProperty property, JetType type, BindingTrace trace) { public VariableDescriptorImpl resolveLocalVariableDescriptorWithType(DeclarationDescriptor containingDeclaration, JetProperty property, JetType type) {
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor( VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
containingDeclaration, containingDeclaration,
annotationResolver.createAnnotationStubs(property.getModifierList(), trace), annotationResolver.createAnnotationStubs(property.getModifierList()),
JetPsiUtil.safeName(property.getName()), JetPsiUtil.safeName(property.getName()),
type, type,
property.isVar()); property.isVar());
...@@ -467,26 +454,26 @@ public class DescriptorResolver { ...@@ -467,26 +454,26 @@ public class DescriptorResolver {
@NotNull @NotNull
public VariableDescriptor resolveObjectDeclaration(@NotNull DeclarationDescriptor containingDeclaration, public VariableDescriptor resolveObjectDeclaration(@NotNull DeclarationDescriptor containingDeclaration,
@NotNull JetClassOrObject objectDeclaration, @NotNull JetClassOrObject objectDeclaration,
@NotNull ClassDescriptor classDescriptor, BindingTrace trace) { @NotNull ClassDescriptor classDescriptor) {
boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor) boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor)
|| (containingDeclaration instanceof ClassDescriptor); || (containingDeclaration instanceof ClassDescriptor);
if (isProperty) { if (isProperty) {
return resolveObjectDeclarationAsPropertyDescriptor(containingDeclaration, objectDeclaration, classDescriptor, trace); return resolveObjectDeclarationAsPropertyDescriptor(containingDeclaration, objectDeclaration, classDescriptor);
} else { } else {
return resolveObjectDeclarationAsLocalVariable(containingDeclaration, objectDeclaration, classDescriptor, trace); return resolveObjectDeclarationAsLocalVariable(containingDeclaration, objectDeclaration, classDescriptor);
} }
} }
@NotNull @NotNull
public PropertyDescriptor resolveObjectDeclarationAsPropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, public PropertyDescriptor resolveObjectDeclarationAsPropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
@NotNull JetClassOrObject objectDeclaration, @NotNull JetClassOrObject objectDeclaration,
@NotNull ClassDescriptor classDescriptor, BindingTrace trace) { @NotNull ClassDescriptor classDescriptor) {
JetModifierList modifierList = objectDeclaration.getModifierList(); JetModifierList modifierList = objectDeclaration.getModifierList();
Visibility visibility = resolveVisibilityFromModifiers(objectDeclaration.getModifierList()); Visibility visibility = resolveVisibilityFromModifiers(objectDeclaration.getModifierList());
PropertyDescriptor propertyDescriptor = new PropertyDescriptor( PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
containingDeclaration, containingDeclaration,
annotationResolver.createAnnotationStubs(modifierList, trace), annotationResolver.createAnnotationStubs(modifierList),
Modality.FINAL, Modality.FINAL,
visibility, visibility,
false, false,
...@@ -505,11 +492,11 @@ public class DescriptorResolver { ...@@ -505,11 +492,11 @@ public class DescriptorResolver {
@NotNull @NotNull
private VariableDescriptor resolveObjectDeclarationAsLocalVariable(@NotNull DeclarationDescriptor containingDeclaration, private VariableDescriptor resolveObjectDeclarationAsLocalVariable(@NotNull DeclarationDescriptor containingDeclaration,
@NotNull JetClassOrObject objectDeclaration, @NotNull JetClassOrObject objectDeclaration,
@NotNull ClassDescriptor classDescriptor, BindingTrace trace) { @NotNull ClassDescriptor classDescriptor) {
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor( VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
containingDeclaration, containingDeclaration,
annotationResolver.createAnnotationStubs(objectDeclaration.getModifierList(), trace), annotationResolver.createAnnotationStubs(objectDeclaration.getModifierList()),
JetPsiUtil.safeName(objectDeclaration.getName()), JetPsiUtil.safeName(objectDeclaration.getName()),
classDescriptor.getDefaultType(), classDescriptor.getDefaultType(),
/*isVar =*/ false); /*isVar =*/ false);
...@@ -521,8 +508,8 @@ public class DescriptorResolver { ...@@ -521,8 +508,8 @@ public class DescriptorResolver {
} }
public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope, public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope,
@NotNull PropertyDescriptor propertyDescriptor, List<TypeParameterDescriptor> typeParameters, @NotNull PropertyDescriptor propertyDescriptor, List<TypeParameterDescriptor> typeParameters,
ReceiverDescriptor receiver, BindingTrace trace) { ReceiverDescriptor receiver) {
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope"); WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope");
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) { for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
result.addTypeParameterDescriptor(typeParameterDescriptor); result.addTypeParameterDescriptor(typeParameterDescriptor);
...@@ -535,7 +522,7 @@ public class DescriptorResolver { ...@@ -535,7 +522,7 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public PropertyDescriptor resolvePropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, JetProperty property, BindingTrace trace) { public PropertyDescriptor resolvePropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, JetProperty property) {
JetModifierList modifierList = property.getModifierList(); JetModifierList modifierList = property.getModifierList();
boolean isVar = property.isVar(); boolean isVar = property.isVar();
...@@ -544,7 +531,7 @@ public class DescriptorResolver { ...@@ -544,7 +531,7 @@ public class DescriptorResolver {
Modality defaultModality = getDefaultModality(containingDeclaration, hasBody); Modality defaultModality = getDefaultModality(containingDeclaration, hasBody);
PropertyDescriptor propertyDescriptor = new PropertyDescriptor( PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
containingDeclaration, containingDeclaration,
annotationResolver.resolveAnnotations(scope, modifierList, trace), annotationResolver.resolveAnnotations(scope, modifierList),
resolveModalityFromModifiers(property.getModifierList(), defaultModality), resolveModalityFromModifiers(property.getModifierList(), defaultModality),
resolveVisibilityFromModifiers(property.getModifierList()), resolveVisibilityFromModifiers(property.getModifierList()),
isVar, isVar,
...@@ -565,15 +552,15 @@ public class DescriptorResolver { ...@@ -565,15 +552,15 @@ public class DescriptorResolver {
} }
else { else {
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property"); WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters, trace); typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters);
writableScope.changeLockLevel(WritableScope.LockLevel.READING); writableScope.changeLockLevel(WritableScope.LockLevel.READING);
resolveGenericBounds(property, writableScope, typeParameterDescriptors, trace); resolveGenericBounds(property, writableScope, typeParameterDescriptors);
scopeWithTypeParameters = writableScope; scopeWithTypeParameters = writableScope;
} }
JetTypeReference receiverTypeRef = property.getReceiverTypeRef(); JetTypeReference receiverTypeRef = property.getReceiverTypeRef();
if (receiverTypeRef != null) { if (receiverTypeRef != null) {
receiverType = typeResolver.resolveType(scopeWithTypeParameters, receiverTypeRef, trace, true); receiverType = typeResolver.resolveType(scopeWithTypeParameters, receiverTypeRef);
} }
} }
...@@ -581,14 +568,14 @@ public class DescriptorResolver { ...@@ -581,14 +568,14 @@ public class DescriptorResolver {
? ReceiverDescriptor.NO_RECEIVER ? ReceiverDescriptor.NO_RECEIVER
: new ExtensionReceiver(propertyDescriptor, receiverType); : new ExtensionReceiver(propertyDescriptor, receiverType);
JetScope propertyScope = getPropertyDeclarationInnerScope(scope, propertyDescriptor, typeParameterDescriptors, receiverDescriptor, trace); JetScope propertyScope = getPropertyDeclarationInnerScope(scope, propertyDescriptor, typeParameterDescriptors, receiverDescriptor);
JetType type = getVariableType(propertyScope, property, DataFlowInfo.EMPTY, true, trace); JetType type = getVariableType(propertyScope, property, DataFlowInfo.EMPTY, true);
propertyDescriptor.setType(type, typeParameterDescriptors, DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), receiverDescriptor); propertyDescriptor.setType(type, typeParameterDescriptors, DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), receiverDescriptor);
PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace); PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
propertyDescriptor.initialize(getter, setter); propertyDescriptor.initialize(getter, setter);
...@@ -612,7 +599,7 @@ public class DescriptorResolver { ...@@ -612,7 +599,7 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
private JetType getVariableType(@NotNull final JetScope scope, @NotNull final JetProperty property, @NotNull final DataFlowInfo dataFlowInfo, boolean allowDeferred, final BindingTrace trace) { private JetType getVariableType(@NotNull final JetScope scope, @NotNull final JetProperty property, @NotNull final DataFlowInfo dataFlowInfo, boolean allowDeferred) {
// TODO : receiver? // TODO : receiver?
JetTypeReference propertyTypeRef = property.getPropertyTypeRef(); JetTypeReference propertyTypeRef = property.getPropertyTypeRef();
...@@ -629,7 +616,7 @@ public class DescriptorResolver { ...@@ -629,7 +616,7 @@ public class DescriptorResolver {
LazyValue<JetType> lazyValue = new LazyValueWithDefault<JetType>(ErrorUtils.createErrorType("Recursive dependency")) { LazyValue<JetType> lazyValue = new LazyValueWithDefault<JetType>(ErrorUtils.createErrorType("Recursive dependency")) {
@Override @Override
protected JetType compute() { protected JetType compute() {
return expressionTypingServices.safeGetType(scope, initializer, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo, trace); return semanticServices.getTypeInferrerServices(trace).safeGetType(scope, initializer, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo);
} }
}; };
if (allowDeferred) { if (allowDeferred) {
...@@ -640,7 +627,7 @@ public class DescriptorResolver { ...@@ -640,7 +627,7 @@ public class DescriptorResolver {
} }
} }
} else { } else {
return typeResolver.resolveType(scope, propertyTypeRef, trace, true); return typeResolver.resolveType(scope, propertyTypeRef);
} }
} }
...@@ -689,11 +676,11 @@ public class DescriptorResolver { ...@@ -689,11 +676,11 @@ public class DescriptorResolver {
} }
@Nullable @Nullable
private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor, BindingTrace trace) { private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
JetPropertyAccessor setter = property.getSetter(); JetPropertyAccessor setter = property.getSetter();
PropertySetterDescriptor setterDescriptor = null; PropertySetterDescriptor setterDescriptor = null;
if (setter != null) { if (setter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList(), trace); List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList());
JetParameter parameter = setter.getParameter(); JetParameter parameter = setter.getParameter();
setterDescriptor = new PropertySetterDescriptor( setterDescriptor = new PropertySetterDescriptor(
...@@ -714,7 +701,7 @@ public class DescriptorResolver { ...@@ -714,7 +701,7 @@ public class DescriptorResolver {
type = propertyDescriptor.getType(); // TODO : this maybe unknown at this point type = propertyDescriptor.getType(); // TODO : this maybe unknown at this point
} }
else { else {
type = typeResolver.resolveType(scope, typeReference, trace, true); type = typeResolver.resolveType(scope, typeReference);
JetType inType = propertyDescriptor.getType(); JetType inType = propertyDescriptor.getType();
if (inType != null) { if (inType != null) {
if (!TypeUtils.equalTypes(type, inType)) { if (!TypeUtils.equalTypes(type, inType)) {
...@@ -726,7 +713,7 @@ public class DescriptorResolver { ...@@ -726,7 +713,7 @@ public class DescriptorResolver {
} }
} }
MutableValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(setterDescriptor, parameter, 0, type, trace); MutableValueParameterDescriptor valueParameterDescriptor = resolveValueParameterDescriptor(setterDescriptor, parameter, 0, type);
setterDescriptor.initialize(valueParameterDescriptor); setterDescriptor.initialize(valueParameterDescriptor);
} }
else { else {
...@@ -759,17 +746,17 @@ public class DescriptorResolver { ...@@ -759,17 +746,17 @@ public class DescriptorResolver {
} }
@Nullable @Nullable
private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor, BindingTrace trace) { private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
PropertyGetterDescriptor getterDescriptor; PropertyGetterDescriptor getterDescriptor;
JetPropertyAccessor getter = property.getGetter(); JetPropertyAccessor getter = property.getGetter();
if (getter != null) { if (getter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList(), trace); List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList());
JetType outType = propertyDescriptor.getType(); JetType outType = propertyDescriptor.getType();
JetType returnType = outType; JetType returnType = outType;
JetTypeReference returnTypeReference = getter.getReturnTypeReference(); JetTypeReference returnTypeReference = getter.getReturnTypeReference();
if (returnTypeReference != null) { if (returnTypeReference != null) {
returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true); returnType = typeResolver.resolveType(scope, returnTypeReference);
if (outType != null && !TypeUtils.equalTypes(returnType, outType)) { if (outType != null && !TypeUtils.equalTypes(returnType, outType)) {
trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType())); trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType()));
} }
...@@ -799,8 +786,8 @@ public class DescriptorResolver { ...@@ -799,8 +786,8 @@ public class DescriptorResolver {
} }
@NotNull @NotNull
public ConstructorDescriptorImpl resolveSecondaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetSecondaryConstructor constructor, BindingTrace trace) { public ConstructorDescriptorImpl resolveSecondaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetSecondaryConstructor constructor) {
return createConstructorDescriptor(scope, classDescriptor, false, constructor.getModifierList(), constructor, classDescriptor.getTypeConstructor().getParameters(), constructor.getValueParameters(), trace); return createConstructorDescriptor(scope, classDescriptor, false, constructor.getModifierList(), constructor, classDescriptor.getTypeConstructor().getParameters(), constructor.getValueParameters());
} }
@NotNull @NotNull
...@@ -810,10 +797,10 @@ public class DescriptorResolver { ...@@ -810,10 +797,10 @@ public class DescriptorResolver {
boolean isPrimary, boolean isPrimary,
@Nullable JetModifierList modifierList, @Nullable JetModifierList modifierList,
@NotNull JetDeclaration declarationToTrace, @NotNull JetDeclaration declarationToTrace,
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters, BindingTrace trace) { List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters) {
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl( ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
classDescriptor, classDescriptor,
annotationResolver.resolveAnnotations(scope, modifierList, trace), annotationResolver.resolveAnnotations(scope, modifierList),
isPrimary isPrimary
); );
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor); trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor);
...@@ -824,12 +811,12 @@ public class DescriptorResolver { ...@@ -824,12 +811,12 @@ public class DescriptorResolver {
resolveValueParameters( resolveValueParameters(
constructorDescriptor, constructorDescriptor,
parameterScope, parameterScope,
valueParameters, trace), valueParameters),
resolveVisibilityFromModifiers(modifierList)); resolveVisibilityFromModifiers(modifierList));
} }
@Nullable @Nullable
public ConstructorDescriptorImpl resolvePrimaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass classElement, BindingTrace trace) { public ConstructorDescriptorImpl resolvePrimaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetClass classElement) {
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY && !classElement.hasPrimaryConstructor()) return null; if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY && !classElement.hasPrimaryConstructor()) return null;
return createConstructorDescriptor( return createConstructorDescriptor(
scope, scope,
...@@ -837,15 +824,15 @@ public class DescriptorResolver { ...@@ -837,15 +824,15 @@ public class DescriptorResolver {
true, true,
classElement.getPrimaryConstructorModifierList(), classElement.getPrimaryConstructorModifierList(),
classElement, classElement,
classDescriptor.getTypeConstructor().getParameters(), classElement.getPrimaryConstructorParameters(), trace); classDescriptor.getTypeConstructor().getParameters(), classElement.getPrimaryConstructorParameters());
} }
@NotNull @NotNull
public PropertyDescriptor resolvePrimaryConstructorParameterToAProperty( public PropertyDescriptor resolvePrimaryConstructorParameterToAProperty(
@NotNull ClassDescriptor classDescriptor, @NotNull ClassDescriptor classDescriptor,
@NotNull JetScope scope, @NotNull JetScope scope,
@NotNull JetParameter parameter, BindingTrace trace) { @NotNull JetParameter parameter) {
JetType type = resolveParameterType(scope, parameter, trace); JetType type = resolveParameterType(scope, parameter);
String name = parameter.getName(); String name = parameter.getName();
boolean isMutable = parameter.isMutable(); boolean isMutable = parameter.isMutable();
JetModifierList modifierList = parameter.getModifierList(); JetModifierList modifierList = parameter.getModifierList();
...@@ -859,7 +846,7 @@ public class DescriptorResolver { ...@@ -859,7 +846,7 @@ public class DescriptorResolver {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor( PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
classDescriptor, classDescriptor,
annotationResolver.resolveAnnotations(scope, modifierList, trace), annotationResolver.resolveAnnotations(scope, modifierList),
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL), resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
resolveVisibilityFromModifiers(parameter.getModifierList()), resolveVisibilityFromModifiers(parameter.getModifierList()),
isMutable, isMutable,
...@@ -879,7 +866,7 @@ public class DescriptorResolver { ...@@ -879,7 +866,7 @@ public class DescriptorResolver {
return propertyDescriptor; return propertyDescriptor;
} }
public void checkBounds(@NotNull JetTypeReference typeReference, @NotNull JetType type, BindingTrace trace) { public void checkBounds(@NotNull JetTypeReference typeReference, @NotNull JetType type) {
if (ErrorUtils.isErrorType(type)) return; if (ErrorUtils.isErrorType(type)) return;
JetTypeElement typeElement = typeReference.getTypeElement(); JetTypeElement typeElement = typeReference.getTypeElement();
...@@ -899,10 +886,10 @@ public class DescriptorResolver { ...@@ -899,10 +886,10 @@ public class DescriptorResolver {
if (argumentTypeReference == null) continue; if (argumentTypeReference == null) continue;
JetType typeArgument = arguments.get(i).getType(); JetType typeArgument = arguments.get(i).getType();
checkBounds(argumentTypeReference, typeArgument, trace); checkBounds(argumentTypeReference, typeArgument);
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i); TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
checkBounds(argumentTypeReference, typeArgument, typeParameterDescriptor, substitutor, trace); checkBounds(argumentTypeReference, typeArgument, typeParameterDescriptor, substitutor);
} }
} }
...@@ -910,7 +897,7 @@ public class DescriptorResolver { ...@@ -910,7 +897,7 @@ public class DescriptorResolver {
@NotNull JetTypeReference argumentTypeReference, @NotNull JetTypeReference argumentTypeReference,
@NotNull JetType typeArgument, @NotNull JetType typeArgument,
@NotNull TypeParameterDescriptor typeParameterDescriptor, @NotNull TypeParameterDescriptor typeParameterDescriptor,
@NotNull TypeSubstitutor substitutor, BindingTrace trace) { @NotNull TypeSubstitutor substitutor) {
for (JetType bound : typeParameterDescriptor.getUpperBounds()) { for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT); JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT);
if (!semanticServices.getTypeChecker().isSubtypeOf(typeArgument, substitutedBound)) { if (!semanticServices.getTypeChecker().isSubtypeOf(typeArgument, substitutedBound)) {
......
...@@ -22,35 +22,17 @@ import com.google.common.collect.Lists; ...@@ -22,35 +22,17 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.ClassKind; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; import org.jetbrains.jet.lang.resolve.scopes.*;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetImportDirective;
import org.jetbrains.jet.lang.psi.JetQualifiedExpression;
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import javax.inject.Inject;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.jetbrains.jet.lang.diagnostics.Errors.CANNOT_BE_IMPORTED; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.CANNOT_IMPORT_FROM_ELEMENT;
import static org.jetbrains.jet.lang.diagnostics.Errors.NO_CLASS_OBJECT;
import static org.jetbrains.jet.lang.diagnostics.Errors.UNRESOLVED_REFERENCE;
import static org.jetbrains.jet.lang.diagnostics.Errors.UNSUPPORTED;
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_HIDDEN_IMPORT;
import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_SIMPLE_IMPORT;
/** /**
* @author abreslav * @author abreslav
...@@ -59,7 +41,6 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_SIMPLE_IMPORT; ...@@ -59,7 +41,6 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.USELESS_SIMPLE_IMPORT;
public class ImportsResolver { public class ImportsResolver {
private final TopDownAnalysisContext context; private final TopDownAnalysisContext context;
@Inject
public ImportsResolver(@NotNull TopDownAnalysisContext context) { public ImportsResolver(@NotNull TopDownAnalysisContext context) {
this.context = context; this.context = context;
} }
......
...@@ -19,9 +19,6 @@ package org.jetbrains.jet.lang.resolve; ...@@ -19,9 +19,6 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile; import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -29,15 +26,8 @@ import org.jetbrains.jet.lang.Configuration; ...@@ -29,15 +26,8 @@ import org.jetbrains.jet.lang.Configuration;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.OverloadingConflictResolver;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;
import org.picocontainer.defaults.SetterInjectionComponentAdapter;
import org.picocontainer.defaults.SetterInjectionComponentAdapterFactory;
import java.io.PrintStream; import java.io.PrintStream;
import java.util.Map; import java.util.Map;
...@@ -46,28 +36,14 @@ import java.util.Set; ...@@ -46,28 +36,14 @@ import java.util.Set;
/** /**
* @author abreslav * @author abreslav
*/ */
public class TopDownAnalysisContext { /*package*/ class TopDownAnalysisContext {
//private final MutablePicoContainer picoContainer;
private final ObservableBindingTrace trace; private final ObservableBindingTrace trace;
private final JetSemanticServices semanticServices;
private final Configuration configuration; private final Configuration configuration;
@NotNull
private final DescriptorResolver descriptorResolver; private final DescriptorResolver descriptorResolver;
@NotNull
private final ImportsResolver importsResolver; private final ImportsResolver importsResolver;
@NotNull
private final BodyResolver bodyResolver;
@NotNull
private final DeclarationResolver declarationResolver;
@NotNull
private final CallResolver.Context callResolverContext;
@NotNull
private final TypeResolver typeResolver;
@NotNull
private final ExpressionTypingServices expressionTypingServices;
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap(); private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap(); private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap(); protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap();
...@@ -85,26 +61,11 @@ public class TopDownAnalysisContext { ...@@ -85,26 +61,11 @@ public class TopDownAnalysisContext {
private boolean analyzingBootstrapLibrary = false; private boolean analyzingBootstrapLibrary = false;
private boolean declaredLocally; private boolean declaredLocally;
public TopDownAnalysisContext(final JetSemanticServices semanticServices, final BindingTrace trace, Predicate<PsiFile> analyzeCompletely, @NotNull Configuration configuration, boolean declaredLocally) { public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace, Predicate<PsiFile> analyzeCompletely, @NotNull Configuration configuration, boolean declaredLocally) {
class TdacModule extends AbstractModule {
@Override
protected void configure() {
bind(JetSemanticServices.class).toInstance(semanticServices);
bind(TopDownAnalysisContext.class).toInstance(TopDownAnalysisContext.this);
}
}
Injector injector = Guice.createInjector(new TdacModule());
this.importsResolver = injector.getInstance(ImportsResolver.class);
this.bodyResolver = injector.getInstance(BodyResolver.class);
this.declarationResolver = injector.getInstance(DeclarationResolver.class);
this.callResolverContext = injector.getInstance(CallResolver.Context.class);
this.typeResolver = injector.getInstance(TypeResolver.class);
this.expressionTypingServices = injector.getInstance(ExpressionTypingServices.class);
this.descriptorResolver = injector.getInstance(DescriptorResolver.class);
this.trace = new ObservableBindingTrace(trace); this.trace = new ObservableBindingTrace(trace);
this.semanticServices = semanticServices;
this.descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
this.importsResolver = new ImportsResolver(this);
this.analyzeCompletely = analyzeCompletely; this.analyzeCompletely = analyzeCompletely;
this.configuration = configuration; this.configuration = configuration;
this.declaredLocally = declaredLocally; this.declaredLocally = declaredLocally;
...@@ -145,11 +106,14 @@ public class TopDownAnalysisContext { ...@@ -145,11 +106,14 @@ public class TopDownAnalysisContext {
return result; return result;
} }
@NotNull
public ObservableBindingTrace getTrace() { public ObservableBindingTrace getTrace() {
return trace; return trace;
} }
public JetSemanticServices getSemanticServices() {
return semanticServices;
}
public DescriptorResolver getDescriptorResolver() { public DescriptorResolver getDescriptorResolver() {
return descriptorResolver; return descriptorResolver;
} }
...@@ -158,11 +122,6 @@ public class TopDownAnalysisContext { ...@@ -158,11 +122,6 @@ public class TopDownAnalysisContext {
return importsResolver; return importsResolver;
} }
@NotNull
public BodyResolver getBodyResolver() {
return bodyResolver;
}
public Map<JetClass, MutableClassDescriptor> getClasses() { public Map<JetClass, MutableClassDescriptor> getClasses() {
return classes; return classes;
} }
...@@ -207,24 +166,4 @@ public class TopDownAnalysisContext { ...@@ -207,24 +166,4 @@ public class TopDownAnalysisContext {
public boolean isDeclaredLocally() { public boolean isDeclaredLocally() {
return declaredLocally; return declaredLocally;
} }
@NotNull
public DeclarationResolver getDeclarationResolver() {
return declarationResolver;
}
@NotNull
public CallResolver.Context getCallResolverContext() {
return callResolverContext;
}
@NotNull
public TypeResolver getTypeResolver() {
return typeResolver;
}
@NotNull
public ExpressionTypingServices getExpressionTypingServices() {
return expressionTypingServices;
}
} }
...@@ -80,13 +80,13 @@ public class TopDownAnalyzer { ...@@ -80,13 +80,13 @@ public class TopDownAnalyzer {
context.debug("Enter"); context.debug("Enter");
new TypeHierarchyResolver(context).process(outerScope, owner, declarations); new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
context.getDeclarationResolver().process(); new DeclarationResolver(context).process();
new DelegationResolver(context).process(); new DelegationResolver(context).process();
new OverrideResolver(context).process(); new OverrideResolver(context).process();
lockScopes(context); lockScopes(context);
new OverloadResolver(context).process(); new OverloadResolver(context).process();
if (!context.analyzingBootstrapLibrary()) { if (!context.analyzingBootstrapLibrary()) {
context.getBodyResolver().resolveBehaviorDeclarationBodies(); new BodyResolver(context).resolveBehaviorDeclarationBodies();
new ControlFlowAnalyzer(context, flowDataTraceFactory).process(); new ControlFlowAnalyzer(context, flowDataTraceFactory).process();
new DeclarationsChecker(context).process(); new DeclarationsChecker(context).process();
} }
......
...@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve; ...@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiNameIdentifierOwner; import com.intellij.psi.PsiNameIdentifierOwner;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -259,7 +260,7 @@ public class TypeHierarchyResolver { ...@@ -259,7 +260,7 @@ public class TypeHierarchyResolver {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey(); JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
context.getDescriptorResolver().resolveMutableClassDescriptor(jetClass, descriptor, context.getTrace()); context.getDescriptorResolver().resolveMutableClassDescriptor(jetClass, descriptor);
descriptor.createTypeConstructor(); descriptor.createTypeConstructor();
} }
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) { for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
...@@ -276,13 +277,13 @@ public class TypeHierarchyResolver { ...@@ -276,13 +277,13 @@ public class TypeHierarchyResolver {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey(); JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
context.getDescriptorResolver().resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters(), context.getTrace()); context.getDescriptorResolver().resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters());
context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor, context.getTrace()); context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor);
} }
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) { for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
JetClassOrObject jetClass = entry.getKey(); JetClassOrObject jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor, context.getTrace()); context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor);
} }
} }
...@@ -477,7 +478,7 @@ public class TypeHierarchyResolver { ...@@ -477,7 +478,7 @@ public class TypeHierarchyResolver {
if (typeReference != null) { if (typeReference != null) {
JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference); JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference);
if (type != null) { if (type != null) {
context.getDescriptorResolver().checkBounds(typeReference, type, context.getTrace()); context.getDescriptorResolver().checkBounds(typeReference, type);
} }
} }
} }
...@@ -487,7 +488,7 @@ public class TypeHierarchyResolver { ...@@ -487,7 +488,7 @@ public class TypeHierarchyResolver {
if (extendsBound != null) { if (extendsBound != null) {
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound); JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
if (type != null) { if (type != null) {
context.getDescriptorResolver().checkBounds(extendsBound, type, context.getTrace()); context.getDescriptorResolver().checkBounds(extendsBound, type);
} }
} }
} }
...@@ -497,7 +498,7 @@ public class TypeHierarchyResolver { ...@@ -497,7 +498,7 @@ public class TypeHierarchyResolver {
if (extendsBound != null) { if (extendsBound != null) {
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound); JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
if (type != null) { if (type != null) {
context.getDescriptorResolver().checkBounds(extendsBound, type, context.getTrace()); context.getDescriptorResolver().checkBounds(extendsBound, type);
} }
} }
} }
......
...@@ -18,44 +18,24 @@ package org.jetbrains.jet.lang.resolve; ...@@ -18,44 +18,24 @@ package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor; import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetElement; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetFunctionType;
import org.jetbrains.jet.lang.psi.JetNullableType;
import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.psi.JetProjectionKind;
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
import org.jetbrains.jet.lang.psi.JetTupleType;
import org.jetbrains.jet.lang.psi.JetTypeElement;
import org.jetbrains.jet.lang.psi.JetTypeProjection;
import org.jetbrains.jet.lang.psi.JetTypeReference;
import org.jetbrains.jet.lang.psi.JetUserType;
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter; import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
import org.jetbrains.jet.lang.types.ErrorUtils; import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeImpl;
import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lang.types.TypeSubstitutor;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.Variance;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.util.lazy.LazyValue; import org.jetbrains.jet.util.lazy.LazyValue;
import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.jetbrains.jet.lang.diagnostics.Errors.UNRESOLVED_REFERENCE; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.UNSUPPORTED;
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET; import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
/** /**
...@@ -63,28 +43,27 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET; ...@@ -63,28 +43,27 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
*/ */
public class TypeResolver { public class TypeResolver {
private AnnotationResolver annotationResolver; private final JetSemanticServices semanticServices;
private DescriptorResolver descriptorResolver; private final BindingTrace trace;
private final boolean checkBounds;
private final AnnotationResolver annotationResolver;
@Inject public TypeResolver(JetSemanticServices semanticServices, BindingTrace trace, boolean checkBounds) {
public void setDescriptorResolver(DescriptorResolver descriptorResolver) { this.semanticServices = semanticServices;
this.descriptorResolver = descriptorResolver; this.trace = trace;
} this.checkBounds = checkBounds;
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
@Inject
public void setAnnotationResolver(AnnotationResolver annotationResolver) {
this.annotationResolver = annotationResolver;
} }
@NotNull @NotNull
public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference, BindingTrace trace, boolean checkBounds) { public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference) {
JetType cachedType = trace.getBindingContext().get(BindingContext.TYPE, typeReference); JetType cachedType = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
if (cachedType != null) return cachedType; if (cachedType != null) return cachedType;
final List<AnnotationDescriptor> annotations = annotationResolver.createAnnotationStubs(typeReference.getAnnotations(), trace); final List<AnnotationDescriptor> annotations = annotationResolver.createAnnotationStubs(typeReference.getAnnotations());
JetTypeElement typeElement = typeReference.getTypeElement(); JetTypeElement typeElement = typeReference.getTypeElement();
JetType type = resolveTypeElement(scope, annotations, typeElement, false, trace, checkBounds); JetType type = resolveTypeElement(scope, annotations, typeElement, false);
trace.record(BindingContext.TYPE, typeReference, type); trace.record(BindingContext.TYPE, typeReference, type);
return type; return type;
...@@ -92,7 +71,7 @@ public class TypeResolver { ...@@ -92,7 +71,7 @@ public class TypeResolver {
@NotNull @NotNull
private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations, private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations,
JetTypeElement typeElement, final boolean nullable, final BindingTrace trace, final boolean checkBounds) { JetTypeElement typeElement, final boolean nullable) {
final JetType[] result = new JetType[1]; final JetType[] result = new JetType[1];
if (typeElement != null) { if (typeElement != null) {
...@@ -105,9 +84,9 @@ public class TypeResolver { ...@@ -105,9 +84,9 @@ public class TypeResolver {
return; return;
} }
ClassifierDescriptor classifierDescriptor = resolveClass(scope, type, trace); ClassifierDescriptor classifierDescriptor = resolveClass(scope, type);
if (classifierDescriptor == null) { if (classifierDescriptor == null) {
resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments(), trace, checkBounds); resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments());
return; return;
} }
...@@ -116,7 +95,7 @@ public class TypeResolver { ...@@ -116,7 +95,7 @@ public class TypeResolver {
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, typeParameterDescriptor); trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, typeParameterDescriptor);
JetScope scopeForTypeParameter = getScopeForTypeParameter(typeParameterDescriptor, checkBounds); JetScope scopeForTypeParameter = getScopeForTypeParameter(typeParameterDescriptor);
if (scopeForTypeParameter instanceof ErrorUtils.ErrorScope) { if (scopeForTypeParameter instanceof ErrorUtils.ErrorScope) {
result[0] = ErrorUtils.createErrorType("?"); result[0] = ErrorUtils.createErrorType("?");
} else { } else {
...@@ -129,14 +108,14 @@ public class TypeResolver { ...@@ -129,14 +108,14 @@ public class TypeResolver {
); );
} }
resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments(), trace, checkBounds); resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments());
} }
else if (classifierDescriptor instanceof ClassDescriptor) { else if (classifierDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor; ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor); trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor);
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor(); TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments(), trace, checkBounds); List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments());
List<TypeParameterDescriptor> parameters = typeConstructor.getParameters(); List<TypeParameterDescriptor> parameters = typeConstructor.getParameters();
int expectedArgumentCount = parameters.size(); int expectedArgumentCount = parameters.size();
int actualArgumentCount = arguments.size(); int actualArgumentCount = arguments.size();
...@@ -166,7 +145,7 @@ public class TypeResolver { ...@@ -166,7 +145,7 @@ public class TypeResolver {
JetTypeReference typeReference = type.getTypeArguments().get(i).getTypeReference(); JetTypeReference typeReference = type.getTypeArguments().get(i).getTypeReference();
if (typeReference != null) { if (typeReference != null) {
descriptorResolver.checkBounds(typeReference, argument, parameter, substitutor, trace); semanticServices.getClassDescriptorResolver(trace).checkBounds(typeReference, argument, parameter, substitutor);
} }
} }
} }
...@@ -177,29 +156,29 @@ public class TypeResolver { ...@@ -177,29 +156,29 @@ public class TypeResolver {
@Override @Override
public void visitNullableType(JetNullableType nullableType) { public void visitNullableType(JetNullableType nullableType) {
result[0] = resolveTypeElement(scope, annotations, nullableType.getInnerType(), true, trace, checkBounds); result[0] = resolveTypeElement(scope, annotations, nullableType.getInnerType(), true);
} }
@Override @Override
public void visitTupleType(JetTupleType type) { public void visitTupleType(JetTupleType type) {
// TODO labels // TODO labels
result[0] = JetStandardClasses.getTupleType(resolveTypes(scope, type.getComponentTypeRefs(), trace, checkBounds)); result[0] = JetStandardClasses.getTupleType(resolveTypes(scope, type.getComponentTypeRefs()));
} }
@Override @Override
public void visitFunctionType(JetFunctionType type) { public void visitFunctionType(JetFunctionType type) {
JetTypeReference receiverTypeRef = type.getReceiverTypeRef(); JetTypeReference receiverTypeRef = type.getReceiverTypeRef();
JetType receiverType = receiverTypeRef == null ? null : resolveType(scope, receiverTypeRef, trace, checkBounds); JetType receiverType = receiverTypeRef == null ? null : resolveType(scope, receiverTypeRef);
List<JetType> parameterTypes = new ArrayList<JetType>(); List<JetType> parameterTypes = new ArrayList<JetType>();
for (JetParameter parameter : type.getParameters()) { for (JetParameter parameter : type.getParameters()) {
parameterTypes.add(resolveType(scope, parameter.getTypeReference(), trace, checkBounds)); parameterTypes.add(resolveType(scope, parameter.getTypeReference()));
} }
JetTypeReference returnTypeRef = type.getReturnTypeRef(); JetTypeReference returnTypeRef = type.getReturnTypeRef();
JetType returnType; JetType returnType;
if (returnTypeRef != null) { if (returnTypeRef != null) {
returnType = resolveType(scope, returnTypeRef, trace, checkBounds); returnType = resolveType(scope, returnTypeRef);
} }
else { else {
returnType = JetStandardClasses.getUnitType(); returnType = JetStandardClasses.getUnitType();
...@@ -223,7 +202,7 @@ public class TypeResolver { ...@@ -223,7 +202,7 @@ public class TypeResolver {
return result[0]; return result[0];
} }
private JetScope getScopeForTypeParameter(final TypeParameterDescriptor typeParameterDescriptor, boolean checkBounds) { private JetScope getScopeForTypeParameter(final TypeParameterDescriptor typeParameterDescriptor) {
if (checkBounds) { if (checkBounds) {
return typeParameterDescriptor.getUpperBoundsAsType().getMemberScope(); return typeParameterDescriptor.getUpperBoundsAsType().getMemberScope();
} }
...@@ -237,16 +216,16 @@ public class TypeResolver { ...@@ -237,16 +216,16 @@ public class TypeResolver {
} }
} }
private List<JetType> resolveTypes(JetScope scope, List<JetTypeReference> argumentElements, BindingTrace trace, boolean checkBounds) { private List<JetType> resolveTypes(JetScope scope, List<JetTypeReference> argumentElements) {
final List<JetType> arguments = new ArrayList<JetType>(); final List<JetType> arguments = new ArrayList<JetType>();
for (JetTypeReference argumentElement : argumentElements) { for (JetTypeReference argumentElement : argumentElements) {
arguments.add(resolveType(scope, argumentElement, trace, checkBounds)); arguments.add(resolveType(scope, argumentElement));
} }
return arguments; return arguments;
} }
@NotNull @NotNull
private List<TypeProjection> resolveTypeProjections(JetScope scope, TypeConstructor constructor, List<JetTypeProjection> argumentElements, BindingTrace trace, boolean checkBounds) { private List<TypeProjection> resolveTypeProjections(JetScope scope, TypeConstructor constructor, List<JetTypeProjection> argumentElements) {
final List<TypeProjection> arguments = new ArrayList<TypeProjection>(); final List<TypeProjection> arguments = new ArrayList<TypeProjection>();
for (int i = 0, argumentElementsSize = argumentElements.size(); i < argumentElementsSize; i++) { for (int i = 0, argumentElementsSize = argumentElements.size(); i < argumentElementsSize; i++) {
JetTypeProjection argumentElement = argumentElements.get(i); JetTypeProjection argumentElement = argumentElements.get(i);
...@@ -265,7 +244,7 @@ public class TypeResolver { ...@@ -265,7 +244,7 @@ public class TypeResolver {
} }
else { else {
// TODO : handle the Foo<in *> case // TODO : handle the Foo<in *> case
type = resolveType(scope, argumentElement.getTypeReference(), trace, checkBounds); type = resolveType(scope, argumentElement.getTypeReference());
Variance kind = null; Variance kind = null;
switch (projectionKind) { switch (projectionKind) {
case IN: case IN:
...@@ -286,8 +265,8 @@ public class TypeResolver { ...@@ -286,8 +265,8 @@ public class TypeResolver {
} }
@Nullable @Nullable
public ClassifierDescriptor resolveClass(JetScope scope, JetUserType userType, BindingTrace trace) { public ClassifierDescriptor resolveClass(JetScope scope, JetUserType userType) {
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType, trace); ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
if (classifierDescriptor == null) { if (classifierDescriptor == null) {
trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression())); trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression()));
...@@ -300,7 +279,7 @@ public class TypeResolver { ...@@ -300,7 +279,7 @@ public class TypeResolver {
} }
@Nullable @Nullable
private ClassifierDescriptor resolveClassWithoutErrorReporting(JetScope scope, JetUserType userType, BindingTrace trace) { private ClassifierDescriptor resolveClassWithoutErrorReporting(JetScope scope, JetUserType userType) {
JetSimpleNameExpression expression = userType.getReferenceExpression(); JetSimpleNameExpression expression = userType.getReferenceExpression();
if (expression == null) { if (expression == null) {
return null; return null;
...@@ -313,12 +292,12 @@ public class TypeResolver { ...@@ -313,12 +292,12 @@ public class TypeResolver {
if (userType.isAbsoluteInRootNamespace()) { if (userType.isAbsoluteInRootNamespace()) {
classifierDescriptor = JetModuleUtil.getRootNamespaceType(userType).getMemberScope().getClassifier(referencedName); classifierDescriptor = JetModuleUtil.getRootNamespaceType(userType).getMemberScope().getClassifier(referencedName);
trace.record(BindingContext.RESOLUTION_SCOPE, userType.getReferenceExpression(), trace.record(BindingContext.RESOLUTION_SCOPE, userType.getReferenceExpression(),
JetModuleUtil.getRootNamespaceType(userType).getMemberScope()); JetModuleUtil.getRootNamespaceType(userType).getMemberScope());
} }
else { else {
JetUserType qualifier = userType.getQualifier(); JetUserType qualifier = userType.getQualifier();
if (qualifier != null) { if (qualifier != null) {
scope = resolveClassLookupScope(scope, qualifier, trace); scope = resolveClassLookupScope(scope, qualifier);
} }
if (scope == null) { if (scope == null) {
return ErrorUtils.getErrorClass(); return ErrorUtils.getErrorClass();
...@@ -331,8 +310,8 @@ public class TypeResolver { ...@@ -331,8 +310,8 @@ public class TypeResolver {
} }
@Nullable @Nullable
private JetScope resolveClassLookupScope(JetScope scope, JetUserType userType, BindingTrace trace) { private JetScope resolveClassLookupScope(JetScope scope, JetUserType userType) {
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType, trace); ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
if (classifierDescriptor instanceof ClassDescriptor) { if (classifierDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor; ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
JetType classObjectType = classDescriptor.getClassObjectType(); JetType classObjectType = classDescriptor.getClassObjectType();
...@@ -341,7 +320,7 @@ public class TypeResolver { ...@@ -341,7 +320,7 @@ public class TypeResolver {
} }
} }
NamespaceDescriptor namespaceDescriptor = resolveNamespace(scope, userType, trace); NamespaceDescriptor namespaceDescriptor = resolveNamespace(scope, userType);
if (namespaceDescriptor == null) { if (namespaceDescriptor == null) {
trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression())); trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression()));
return null; return null;
...@@ -350,15 +329,15 @@ public class TypeResolver { ...@@ -350,15 +329,15 @@ public class TypeResolver {
} }
@Nullable @Nullable
private NamespaceDescriptor resolveNamespace(JetScope scope, JetUserType userType, BindingTrace trace) { private NamespaceDescriptor resolveNamespace(JetScope scope, JetUserType userType) {
if (userType.isAbsoluteInRootNamespace()) { if (userType.isAbsoluteInRootNamespace()) {
return resolveNamespace(JetModuleUtil.getRootNamespaceType(userType).getMemberScope(), userType, trace); return resolveNamespace(JetModuleUtil.getRootNamespaceType(userType).getMemberScope(), userType);
} }
JetUserType qualifier = userType.getQualifier(); JetUserType qualifier = userType.getQualifier();
NamespaceDescriptor namespace; NamespaceDescriptor namespace;
if (qualifier != null) { if (qualifier != null) {
NamespaceDescriptor domain = resolveNamespace(scope, qualifier, trace); NamespaceDescriptor domain = resolveNamespace(scope, qualifier);
if (domain == null) { if (domain == null) {
return null; return null;
} }
......
...@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.calls; ...@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.calls;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.Inject;
import com.intellij.lang.ASTNode; import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
...@@ -34,7 +33,6 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope; ...@@ -34,7 +33,6 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices; import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import org.jetbrains.jet.lang.types.expressions.OperatorConventions; import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses; import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
...@@ -58,46 +56,14 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; ...@@ -58,46 +56,14 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
public class CallResolver { public class CallResolver {
private static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE"); private static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
private final JetTypeChecker typeChecker = JetTypeChecker.INSTANCE; private final JetSemanticServices semanticServices;
private final OverloadingConflictResolver overloadingConflictResolver; private final OverloadingConflictResolver overloadingConflictResolver;
private final DataFlowInfo dataFlowInfo; private final DataFlowInfo dataFlowInfo;
private final TypeResolver typeResolver;
public static class Context { public CallResolver(JetSemanticServices semanticServices, DataFlowInfo dataFlowInfo) {
public OverloadingConflictResolver overloadingConflictResolver; this.semanticServices = semanticServices;
public DescriptorResolver descriptorResolver; this.overloadingConflictResolver = new OverloadingConflictResolver(semanticServices);
public TypeResolver typeResolver;
public ExpressionTypingServices expressionTypingServices;
@Inject
public void setOverloadingConflictResolver(OverloadingConflictResolver overloadingConflictResolver) {
this.overloadingConflictResolver = overloadingConflictResolver;
}
@Inject
public void setDescriptorResolver(DescriptorResolver descriptorResolver) {
this.descriptorResolver = descriptorResolver;
}
@Inject
public void setTypeResolver(TypeResolver typeResolver) {
this.typeResolver = typeResolver;
}
@Inject
public void setExpressionTypingServices(ExpressionTypingServices expressionTypingServices) {
this.expressionTypingServices = expressionTypingServices;
}
}
private final Context context;
public CallResolver(Context context, DataFlowInfo dataFlowInfo) {
this.context = context;
this.dataFlowInfo = dataFlowInfo; this.dataFlowInfo = dataFlowInfo;
this.overloadingConflictResolver = context.overloadingConflictResolver;
this.typeResolver = context.typeResolver;
} }
@NotNull @NotNull
...@@ -199,7 +165,7 @@ public class CallResolver { ...@@ -199,7 +165,7 @@ public class CallResolver {
} }
JetTypeReference typeReference = expression.getTypeReference(); JetTypeReference typeReference = expression.getTypeReference();
assert typeReference != null; assert typeReference != null;
JetType constructedType = typeResolver.resolveType(scope, typeReference, trace, true); JetType constructedType = new TypeResolver(semanticServices, trace, true).resolveType(scope, typeReference);
DeclarationDescriptor declarationDescriptor = constructedType.getConstructor().getDeclarationDescriptor(); DeclarationDescriptor declarationDescriptor = constructedType.getConstructor().getDeclarationDescriptor();
if (declarationDescriptor instanceof ClassDescriptor) { if (declarationDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor; ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
...@@ -233,7 +199,8 @@ public class CallResolver { ...@@ -233,7 +199,8 @@ public class CallResolver {
} }
else if (calleeExpression != null) { else if (calleeExpression != null) {
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2) // Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
JetType calleeType = context.expressionTypingServices.safeGetType(scope, calleeExpression, NO_EXPECTED_TYPE, trace); // We are actually expecting a function, but there seems to be no easy way of expressing this ExpressionTypingServices typingServices = new ExpressionTypingServices(semanticServices, trace);
JetType calleeType = typingServices.safeGetType(scope, calleeExpression, NO_EXPECTED_TYPE); // We are actually expecting a function, but there seems to be no easy way of expressing this
if (!JetStandardClasses.isFunctionType(calleeType)) { if (!JetStandardClasses.isFunctionType(calleeType)) {
// checkTypesWithNoCallee(trace, scope, call); // checkTypesWithNoCallee(trace, scope, call);
...@@ -577,7 +544,8 @@ public class CallResolver { ...@@ -577,7 +544,8 @@ public class CallResolver {
// and throw the results away // and throw the results away
// We'll type check the arguments later, with the inferred types expected // We'll type check the arguments later, with the inferred types expected
TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(temporaryTrace); TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(temporaryTrace);
JetType type = context.expressionTypingServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT), traceForUnknown); ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, traceForUnknown);
JetType type = temporaryServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT));
if (type != null && !ErrorUtils.isErrorType(type)) { if (type != null && !ErrorUtils.isErrorType(type)) {
constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType)); constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType));
} }
...@@ -636,7 +604,7 @@ public class CallResolver { ...@@ -636,7 +604,7 @@ public class CallResolver {
} }
JetTypeReference typeReference = projection.getTypeReference(); JetTypeReference typeReference = projection.getTypeReference();
if (typeReference != null) { if (typeReference != null) {
typeArguments.add(typeResolver.resolveType(scope, typeReference, trace, true)); typeArguments.add(new TypeResolver(semanticServices, temporaryTrace, true).resolveType(scope, typeReference));
} }
} }
int expectedTypeArgumentCount = candidate.getTypeParameters().size(); int expectedTypeArgumentCount = candidate.getTypeParameters().size();
...@@ -725,19 +693,20 @@ public class CallResolver { ...@@ -725,19 +693,20 @@ public class CallResolver {
} }
private void checkTypesWithNoCallee(BindingTrace trace, JetScope scope, Call call) { private void checkTypesWithNoCallee(BindingTrace trace, JetScope scope, Call call) {
ExpressionTypingServices typeInferrerServices = new ExpressionTypingServices(semanticServices, trace);
for (ValueArgument valueArgument : call.getValueArguments()) { for (ValueArgument valueArgument : call.getValueArguments()) {
JetExpression argumentExpression = valueArgument.getArgumentExpression(); JetExpression argumentExpression = valueArgument.getArgumentExpression();
if (argumentExpression != null) { if (argumentExpression != null) {
context.expressionTypingServices.getType(scope, argumentExpression, NO_EXPECTED_TYPE, trace); typeInferrerServices.getType(scope, argumentExpression, NO_EXPECTED_TYPE);
} }
} }
for (JetExpression expression : call.getFunctionLiteralArguments()) { for (JetExpression expression : call.getFunctionLiteralArguments()) {
context.expressionTypingServices.getType(scope, expression, NO_EXPECTED_TYPE, trace); typeInferrerServices.getType(scope, expression, NO_EXPECTED_TYPE);
} }
for (JetTypeProjection typeProjection : call.getTypeArguments()) { for (JetTypeProjection typeProjection : call.getTypeArguments()) {
typeResolver.resolveType(scope, typeProjection.getTypeReference(), trace, true); new TypeResolver(semanticServices, trace, true).resolveType(scope, typeProjection.getTypeReference());
} }
} }
...@@ -783,7 +752,7 @@ public class CallResolver { ...@@ -783,7 +752,7 @@ public class CallResolver {
JetType effectiveReceiverArgumentType = safeAccess JetType effectiveReceiverArgumentType = safeAccess
? TypeUtils.makeNotNullable(receiverArgumentType) ? TypeUtils.makeNotNullable(receiverArgumentType)
: receiverArgumentType; : receiverArgumentType;
if (!typeChecker.isSubtypeOf(effectiveReceiverArgumentType, receiverParameter.getType())) { if (!semanticServices.getTypeChecker().isSubtypeOf(effectiveReceiverArgumentType, receiverParameter.getType())) {
tracing.wrongReceiverType(candidateCall.getTrace(), receiverParameter, receiverArgument); tracing.wrongReceiverType(candidateCall.getTrace(), receiverParameter, receiverArgument);
result = OTHER_ERROR; result = OTHER_ERROR;
} }
...@@ -806,12 +775,12 @@ public class CallResolver { ...@@ -806,12 +775,12 @@ public class CallResolver {
List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions(); List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions();
for (JetExpression argumentExpression : argumentExpressions) { for (JetExpression argumentExpression : argumentExpressions) {
ExpressionTypingServices temporaryServices = context.expressionTypingServices; ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, candidateCall.getTrace());
JetType type = temporaryServices.getType(scope, argumentExpression, parameterType, dataFlowInfo, candidateCall.getTrace()); JetType type = temporaryServices.getType(scope, argumentExpression, parameterType, dataFlowInfo);
if (type == null || ErrorUtils.isErrorType(type)) { if (type == null || ErrorUtils.isErrorType(type)) {
candidateCall.argumentHasNoType(); candidateCall.argumentHasNoType();
} }
else if (!typeChecker.isSubtypeOf(type, parameterType)) { else if (!semanticServices.getTypeChecker().isSubtypeOf(type, parameterType)) {
// VariableDescriptor variableDescriptor = AutoCastUtils.getVariableDescriptorFromSimpleName(temporaryTrace.getBindingContext(), argumentExpression); // VariableDescriptor variableDescriptor = AutoCastUtils.getVariableDescriptorFromSimpleName(temporaryTrace.getBindingContext(), argumentExpression);
// if (variableDescriptor != null) { // if (variableDescriptor != null) {
// JetType autoCastType = null; // JetType autoCastType = null;
...@@ -966,7 +935,7 @@ public class CallResolver { ...@@ -966,7 +935,7 @@ public class CallResolver {
JetType typeArgument = typeArguments.get(i); JetType typeArgument = typeArguments.get(i);
JetTypeReference typeReference = jetTypeArguments.get(i).getTypeReference(); JetTypeReference typeReference = jetTypeArguments.get(i).getTypeReference();
assert typeReference != null; assert typeReference != null;
this.context.descriptorResolver.checkBounds(typeReference, typeArgument, typeParameterDescriptor, substitutor, trace); semanticServices.getClassDescriptorResolver(trace).checkBounds(typeReference, typeArgument, typeParameterDescriptor, substitutor);
} }
} }
...@@ -1034,7 +1003,7 @@ public class CallResolver { ...@@ -1034,7 +1003,7 @@ public class CallResolver {
ReceiverDescriptor functionReceiver = functionDescriptor.getReceiverParameter(); ReceiverDescriptor functionReceiver = functionDescriptor.getReceiverParameter();
if (!functionReceiver.exists()) continue; if (!functionReceiver.exists()) continue;
if (!functionDescriptor.getTypeParameters().isEmpty()) continue; if (!functionDescriptor.getTypeParameters().isEmpty()) continue;
if (!typeChecker.isSubtypeOf(receiver.getType(), functionReceiver.getType())) continue; if (!semanticServices.getTypeChecker().isSubtypeOf(receiver.getType(), functionReceiver.getType())) continue;
if (!checkValueParameters(functionDescriptor, parameterTypes))continue; if (!checkValueParameters(functionDescriptor, parameterTypes))continue;
result.add(resolvedCall); result.add(resolvedCall);
found = true; found = true;
......
...@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; ...@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.TypeUtils;
import javax.inject.Inject;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -41,7 +40,6 @@ public class OverloadingConflictResolver { ...@@ -41,7 +40,6 @@ public class OverloadingConflictResolver {
private final JetSemanticServices semanticServices; private final JetSemanticServices semanticServices;
@Inject
public OverloadingConflictResolver(@NotNull JetSemanticServices semanticServices) { public OverloadingConflictResolver(@NotNull JetSemanticServices semanticServices) {
this.semanticServices = semanticServices; this.semanticServices = semanticServices;
} }
......
...@@ -53,7 +53,6 @@ public class DataFlowInfo { ...@@ -53,7 +53,6 @@ public class DataFlowInfo {
public static DataFlowInfo EMPTY = new DataFlowInfo(ImmutableMap.<DataFlowValue, Nullability>of(), Multimaps.newListMultimap(Collections.<DataFlowValue, Collection<JetType>>emptyMap(), CommonSuppliers.<JetType>getArrayListSupplier())); public static DataFlowInfo EMPTY = new DataFlowInfo(ImmutableMap.<DataFlowValue, Nullability>of(), Multimaps.newListMultimap(Collections.<DataFlowValue, Collection<JetType>>emptyMap(), CommonSuppliers.<JetType>getArrayListSupplier()));
private final ImmutableMap<DataFlowValue, Nullability> nullabilityInfo; private final ImmutableMap<DataFlowValue, Nullability> nullabilityInfo;
/** Also immutable */
private final ListMultimap<DataFlowValue, JetType> typeInfo; private final ListMultimap<DataFlowValue, JetType> typeInfo;
private DataFlowInfo(ImmutableMap<DataFlowValue, Nullability> nullabilityInfo, ListMultimap<DataFlowValue, JetType> typeInfo) { private DataFlowInfo(ImmutableMap<DataFlowValue, Nullability> nullabilityInfo, ListMultimap<DataFlowValue, JetType> typeInfo) {
......
...@@ -185,7 +185,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ...@@ -185,7 +185,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetTypeReference right = expression.getRight(); JetTypeReference right = expression.getRight();
JetType result = null; JetType result = null;
if (right != null) { if (right != null) {
JetType targetType = context.getTypeResolver().resolveType(context.scope, right, context.trace, true); JetType targetType = context.getTypeResolver().resolveType(context.scope, right);
if (isTypeFlexible(expression.getLeft())) { if (isTypeFlexible(expression.getLeft())) {
TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(context.trace); TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(context.trace);
...@@ -346,7 +346,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ...@@ -346,7 +346,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
List<JetExpression> entries = expression.getEntries(); List<JetExpression> entries = expression.getEntries();
List<JetType> types = new ArrayList<JetType>(); List<JetType> types = new ArrayList<JetType>();
for (JetExpression entry : entries) { for (JetExpression entry : entries) {
types.add(context.getServices().safeGetType(context.scope, entry, NO_EXPECTED_TYPE, context.trace)); // TODO types.add(context.getServices().safeGetType(context.scope, entry, NO_EXPECTED_TYPE)); // TODO
} }
if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isTupleType(context.expectedType)) { if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isTupleType(context.expectedType)) {
List<JetType> enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context); List<JetType> enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context);
...@@ -417,15 +417,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ...@@ -417,15 +417,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetUserType userType = (JetUserType) typeElement; JetUserType userType = (JetUserType) typeElement;
// This may be just a superclass name even if the superclass is generic // This may be just a superclass name even if the superclass is generic
if (userType.getTypeArguments().isEmpty()) { if (userType.getTypeArguments().isEmpty()) {
classifierCandidate = context.getTypeResolver().resolveClass(context.scope, userType, context.trace); classifierCandidate = context.getTypeResolver().resolveClass(context.scope, userType);
} }
else { else {
supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true); supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier);
redundantTypeArguments = userType.getTypeArgumentList(); redundantTypeArguments = userType.getTypeArgumentList();
} }
} }
else { else {
supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true); supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier);
} }
if (supertype != null) { if (supertype != null) {
...@@ -505,7 +505,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { ...@@ -505,7 +505,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
public JetType visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context, boolean isStatement) { public JetType visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context, boolean isStatement) {
return context.getServices().getBlockReturnedType(context.scope, expression, isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION, context, context.trace); return context.getServices().getBlockReturnedType(context.scope, expression, isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION, context);
} }
@Override @Override
......
...@@ -99,16 +99,16 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { ...@@ -99,16 +99,16 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef(); JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef();
if (returnTypeRef != null) { if (returnTypeRef != null) {
returnType = context.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true); returnType = context.getTypeResolver().resolveType(context.scope, returnTypeRef);
context.getServices().checkFunctionReturnType(expression, context.replaceScope(functionInnerScope). context.getServices().checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
replaceExpectedType(returnType).replaceExpectedReturnType(returnType).replaceDataFlowInfo(context.dataFlowInfo), context.trace); replaceExpectedType(returnType).replaceExpectedReturnType(returnType).replaceDataFlowInfo(context.dataFlowInfo));
} }
else { else {
if (functionTypeExpected) { if (functionTypeExpected) {
returnType = JetStandardClasses.getReturnTypeFromFunctionType(expectedType); returnType = JetStandardClasses.getReturnTypeFromFunctionType(expectedType);
} }
returnType = context.getServices().getBlockReturnedType(functionInnerScope, bodyExpression, CoercionStrategy.COERCION_TO_UNIT, returnType = context.getServices().getBlockReturnedType(functionInnerScope, bodyExpression, CoercionStrategy.COERCION_TO_UNIT,
context.replaceExpectedType(returnType).replaceExpectedReturnType(returnType), context.trace); context.replaceExpectedType(returnType).replaceExpectedReturnType(returnType));
} }
JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("<return type>") : returnType; JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("<return type>") : returnType;
functionDescriptor.setReturnType(safeReturnType); functionDescriptor.setReturnType(safeReturnType);
...@@ -143,7 +143,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { ...@@ -143,7 +143,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
} }
} }
else { else {
effectiveReceiverType = context.getTypeResolver().resolveType(context.scope, receiverTypeRef, context.trace, true); effectiveReceiverType = context.getTypeResolver().resolveType(context.scope, receiverTypeRef);
} }
functionDescriptor.initialize(effectiveReceiverType, NO_RECEIVER, Collections.<TypeParameterDescriptor>emptyList(), valueParameterDescriptors, null, Modality.FINAL, Visibility.LOCAL); functionDescriptor.initialize(effectiveReceiverType, NO_RECEIVER, Collections.<TypeParameterDescriptor>emptyList(), valueParameterDescriptors, null, Modality.FINAL, Visibility.LOCAL);
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor); context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
...@@ -174,7 +174,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { ...@@ -174,7 +174,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetType type; JetType type;
if (typeReference != null) { if (typeReference != null) {
type = context.getTypeResolver().resolveType(context.scope, typeReference, context.trace, true); type = context.getTypeResolver().resolveType(context.scope, typeReference);
} }
else { else {
if (expectedValueParameters != null && i < expectedValueParameters.size()) { if (expectedValueParameters != null && i < expectedValueParameters.size()) {
...@@ -185,7 +185,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor { ...@@ -185,7 +185,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
type = ErrorUtils.createErrorType("Cannot be inferred"); type = ErrorUtils.createErrorType("Cannot be inferred");
} }
} }
ValueParameterDescriptor valueParameterDescriptor = context.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type, context.trace); ValueParameterDescriptor valueParameterDescriptor = context.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type);
valueParameterDescriptors.add(valueParameterDescriptor); valueParameterDescriptors.add(valueParameterDescriptor);
} }
} }
......
...@@ -92,7 +92,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -92,7 +92,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (elseBranch == null) { if (elseBranch == null) {
if (thenBranch != null) { if (thenBranch != null) {
JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(thenInfo), context.trace); JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(thenInfo));
if (type != null && JetStandardClasses.isNothing(type)) { if (type != null && JetStandardClasses.isNothing(type)) {
facade.setResultingDataFlowInfo(elseInfo); facade.setResultingDataFlowInfo(elseInfo);
} }
...@@ -101,15 +101,15 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -101,15 +101,15 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
return null; return null;
} }
if (thenBranch == null) { if (thenBranch == null) {
JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(elseInfo), context.trace); JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(elseInfo));
if (type != null && JetStandardClasses.isNothing(type)) { if (type != null && JetStandardClasses.isNothing(type)) {
facade.setResultingDataFlowInfo(thenInfo); facade.setResultingDataFlowInfo(thenInfo);
} }
return DataFlowUtils.checkImplicitCast(DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType), expression, contextWithExpectedType, isStatement); return DataFlowUtils.checkImplicitCast(DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType), expression, contextWithExpectedType, isStatement);
} }
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION; CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
JetType thenType = context.getServices().getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(thenInfo), context.trace); JetType thenType = context.getServices().getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(thenInfo));
JetType elseType = context.getServices().getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(elseInfo), context.trace); JetType elseType = context.getServices().getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(elseInfo));
JetType result; JetType result;
if (thenType == null) { if (thenType == null) {
...@@ -150,7 +150,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -150,7 +150,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (body != null) { if (body != null) {
WritableScopeImpl scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in while's condition"); WritableScopeImpl scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in while's condition");
DataFlowInfo conditionInfo = condition == null ? context.dataFlowInfo : DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, scopeToExtend, context); DataFlowInfo conditionInfo = condition == null ? context.dataFlowInfo : DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, scopeToExtend, context);
context.getServices().getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo), context.trace); context.getServices().getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo));
} }
if (!containsBreak(expression, context)) { if (!containsBreak(expression, context)) {
facade.setResultingDataFlowInfo(DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, null, context)); facade.setResultingDataFlowInfo(DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, null, context));
...@@ -197,7 +197,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -197,7 +197,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (!function.getFunctionLiteral().hasParameterSpecification()) { if (!function.getFunctionLiteral().hasParameterSpecification()) {
WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope"); WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope");
conditionScope = writableScope; conditionScope = writableScope;
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace); context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context);
context.trace.record(BindingContext.BLOCK, function); context.trace.record(BindingContext.BLOCK, function);
} else { } else {
facade.getType(body, context.replaceScope(context.scope)); facade.getType(body, context.replaceScope(context.scope));
...@@ -213,7 +213,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -213,7 +213,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
else { else {
block = Collections.<JetElement>singletonList(body); block = Collections.<JetElement>singletonList(body);
} }
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context, context.trace); context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context);
} }
JetExpression condition = expression.getCondition(); JetExpression condition = expression.getCondition();
checkCondition(conditionScope, condition, context); checkCondition(conditionScope, condition, context);
...@@ -248,7 +248,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -248,7 +248,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetTypeReference typeReference = loopParameter.getTypeReference(); JetTypeReference typeReference = loopParameter.getTypeReference();
VariableDescriptor variableDescriptor; VariableDescriptor variableDescriptor;
if (typeReference != null) { if (typeReference != null) {
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter, context.trace); variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter);
JetType actualParameterType = variableDescriptor.getType(); JetType actualParameterType = variableDescriptor.getType();
if (expectedParameterType != null && if (expectedParameterType != null &&
actualParameterType != null && actualParameterType != null &&
...@@ -260,7 +260,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -260,7 +260,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (expectedParameterType == null) { if (expectedParameterType == null) {
expectedParameterType = ErrorUtils.createErrorType("Error"); expectedParameterType = ErrorUtils.createErrorType("Error");
} }
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType, context.trace); variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
} }
{ {
...@@ -277,7 +277,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -277,7 +277,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetExpression body = expression.getBody(); JetExpression body = expression.getBody();
if (body != null) { if (body != null) {
context.getServices().getBlockReturnedTypeWithWritableScope(loopScope, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context, context.trace); context.getServices().getBlockReturnedTypeWithWritableScope(loopScope, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context);
} }
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType); return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType);
...@@ -401,7 +401,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { ...@@ -401,7 +401,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetParameter catchParameter = catchClause.getCatchParameter(); JetParameter catchParameter = catchClause.getCatchParameter();
JetExpression catchBody = catchClause.getCatchBody(); JetExpression catchBody = catchClause.getCatchBody();
if (catchParameter != null) { if (catchParameter != null) {
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace); VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter);
JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType(); JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType();
DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType)); DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
if (catchBody != null) { if (catchBody != null) {
......
...@@ -44,10 +44,8 @@ import java.util.Map; ...@@ -44,10 +44,8 @@ import java.util.Map;
* @author abreslav * @author abreslav
*/ */
/*package*/ class ExpressionTypingContext { /*package*/ class ExpressionTypingContext {
@NotNull @NotNull
public static ExpressionTypingContext newContext( public static ExpressionTypingContext newContext(
@NotNull CallResolver.Context context,
@NotNull Project project, @NotNull Project project,
@NotNull JetSemanticServices semanticServices, @NotNull JetSemanticServices semanticServices,
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo, @NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
...@@ -59,7 +57,7 @@ import java.util.Map; ...@@ -59,7 +57,7 @@ import java.util.Map;
@NotNull JetType expectedType, @NotNull JetType expectedType,
@NotNull JetType expectedReturnType, @NotNull JetType expectedReturnType,
boolean namespacesAllowed) { boolean namespacesAllowed) {
return new ExpressionTypingContext(project, context, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, return new ExpressionTypingContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed); labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
} }
...@@ -75,7 +73,6 @@ import java.util.Map; ...@@ -75,7 +73,6 @@ import java.util.Map;
// } // }
// //
public final Project project; public final Project project;
public final CallResolver.Context context;
public final JetSemanticServices semanticServices; public final JetSemanticServices semanticServices;
public final BindingTrace trace; public final BindingTrace trace;
public final JetScope scope; public final JetScope scope;
...@@ -92,11 +89,13 @@ import java.util.Map; ...@@ -92,11 +89,13 @@ import java.util.Map;
public final boolean namespacesAllowed; public final boolean namespacesAllowed;
private CallResolver callResolver; private CallResolver callResolver;
private TypeResolver typeResolver;
private DescriptorResolver descriptorResolver;
private ExpressionTypingServices services;
private CompileTimeConstantResolver compileTimeConstantResolver; private CompileTimeConstantResolver compileTimeConstantResolver;
private ExpressionTypingContext( private ExpressionTypingContext(
@NotNull Project project, @NotNull Project project,
@NotNull CallResolver.Context context,
@NotNull JetSemanticServices semanticServices, @NotNull JetSemanticServices semanticServices,
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo, @NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists, @NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
...@@ -108,7 +107,6 @@ import java.util.Map; ...@@ -108,7 +107,6 @@ import java.util.Map;
@NotNull JetType expectedReturnType, @NotNull JetType expectedReturnType,
boolean namespacesAllowed) { boolean namespacesAllowed) {
this.project = project; this.project = project;
this.context = context;
this.trace = trace; this.trace = trace;
this.patternsToBoundVariableLists = patternsToBoundVariableLists; this.patternsToBoundVariableLists = patternsToBoundVariableLists;
this.patternsToDataFlowInfo = patternsToDataFlowInfo; this.patternsToDataFlowInfo = patternsToDataFlowInfo;
...@@ -124,57 +122,66 @@ import java.util.Map; ...@@ -124,57 +122,66 @@ import java.util.Map;
@NotNull @NotNull
public ExpressionTypingContext replaceNamespacesAllowed(boolean namespacesAllowed) { public ExpressionTypingContext replaceNamespacesAllowed(boolean namespacesAllowed) {
if (namespacesAllowed == this.namespacesAllowed) return this; if (namespacesAllowed == this.namespacesAllowed) return this;
return newContext(context, project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed); return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
} }
@NotNull @NotNull
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) { public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
if (newDataFlowInfo == dataFlowInfo) return this; if (newDataFlowInfo == dataFlowInfo) return this;
return newContext(context, project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, newDataFlowInfo, expectedType, expectedReturnType, namespacesAllowed); return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, newDataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
} }
public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) { public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) {
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE); if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
if (expectedType == newExpectedType) return this; if (expectedType == newExpectedType) return this;
return newContext(context, project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, newExpectedType, expectedReturnType, namespacesAllowed); return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, newExpectedType, expectedReturnType, namespacesAllowed);
} }
public ExpressionTypingContext replaceExpectedReturnType(@Nullable JetType newExpectedReturnType) { public ExpressionTypingContext replaceExpectedReturnType(@Nullable JetType newExpectedReturnType) {
if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE); if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
if (expectedReturnType == newExpectedReturnType) return this; if (expectedReturnType == newExpectedReturnType) return this;
return newContext(context, project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, newExpectedReturnType, namespacesAllowed); return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, newExpectedReturnType, namespacesAllowed);
} }
public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) { public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) {
if (newTrace == trace) return this; if (newTrace == trace) return this;
return newContext(context, project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, newTrace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed); return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, newTrace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
} }
@NotNull @NotNull
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) { public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
if (newScope == scope) return this; if (newScope == scope) return this;
return newContext(context, project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed); return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
} }
///////////// LAZY ACCESSORS ///////////// LAZY ACCESSORS
public CallResolver getCallResolver() { public CallResolver getCallResolver() {
if (callResolver == null) { if (callResolver == null) {
callResolver = new CallResolver(context, dataFlowInfo); callResolver = new CallResolver(semanticServices, dataFlowInfo);
} }
return callResolver; return callResolver;
} }
public ExpressionTypingServices getServices() { public ExpressionTypingServices getServices() {
return context.expressionTypingServices; if (services == null) {
services = new ExpressionTypingServices(semanticServices, trace);
}
return services;
} }
public TypeResolver getTypeResolver() { public TypeResolver getTypeResolver() {
return context.typeResolver; if (typeResolver == null) {
typeResolver = new TypeResolver(semanticServices, trace, true);
}
return typeResolver;
} }
public DescriptorResolver getDescriptorResolver() { public DescriptorResolver getDescriptorResolver() {
return context.descriptorResolver; if (descriptorResolver == null) {
descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
}
return descriptorResolver;
} }
public CompileTimeConstantResolver getCompileTimeConstantResolver() { public CompileTimeConstantResolver getCompileTimeConstantResolver() {
......
...@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor; ...@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Diagnostic; import org.jetbrains.jet.lang.diagnostics.Diagnostic;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
...@@ -40,7 +39,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses; ...@@ -40,7 +39,6 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import javax.inject.Inject;
import java.util.*; import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH; import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH;
...@@ -53,28 +51,23 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE; ...@@ -53,28 +51,23 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
* @author abreslav * @author abreslav
*/ */
public class ExpressionTypingServices { public class ExpressionTypingServices {
private JetSemanticServices semanticServices; private final JetSemanticServices semanticServices;
private CallResolver.Context expressionTypingContextContext; private final BindingTrace trace;
private final ExpressionTypingFacade expressionTypingFacade = ExpressionTypingVisitorDispatcher.create(); private final ExpressionTypingFacade expressionTypingFacade = ExpressionTypingVisitorDispatcher.create();
@Inject public ExpressionTypingServices(JetSemanticServices semanticServices, BindingTrace trace) {
public void setSemanticServices(JetSemanticServices semanticServices) {
this.semanticServices = semanticServices; this.semanticServices = semanticServices;
} this.trace = trace;
@Inject
public void setExpressionTypingContextContext(CallResolver.Context expressionTypingContextContext) {
this.expressionTypingContextContext = expressionTypingContextContext;
} }
@NotNull @NotNull
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, BindingTrace trace) { public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
return safeGetType(scope, expression, expectedType, DataFlowInfo.EMPTY, trace); return safeGetType(scope, expression, expectedType, DataFlowInfo.EMPTY);
} }
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) { public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo) {
JetType type = getType(scope, expression, expectedType, dataFlowInfo, trace); JetType type = getType(scope, expression, expectedType, dataFlowInfo);
if (type != null) { if (type != null) {
return type; return type;
} }
...@@ -82,14 +75,13 @@ public class ExpressionTypingServices { ...@@ -82,14 +75,13 @@ public class ExpressionTypingServices {
} }
@Nullable @Nullable
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, BindingTrace trace) { public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
return getType(scope, expression, expectedType, DataFlowInfo.EMPTY, trace); return getType(scope, expression, expectedType, DataFlowInfo.EMPTY);
} }
@Nullable @Nullable
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) { public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo) {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
expressionTypingContextContext,
expression.getProject(), expression.getProject(),
semanticServices, semanticServices,
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(), new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
...@@ -98,9 +90,8 @@ public class ExpressionTypingServices { ...@@ -98,9 +90,8 @@ public class ExpressionTypingServices {
return expressionTypingFacade.getType(expression, context); return expressionTypingFacade.getType(expression, context);
} }
public JetType getTypeWithNamespaces(@NotNull final JetScope scope, @NotNull JetExpression expression, BindingTrace trace) { public JetType getTypeWithNamespaces(@NotNull final JetScope scope, @NotNull JetExpression expression) {
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
expressionTypingContextContext,
expression.getProject(), expression.getProject(),
semanticServices, semanticServices,
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(), new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
...@@ -111,7 +102,7 @@ public class ExpressionTypingServices { ...@@ -111,7 +102,7 @@ public class ExpressionTypingServices {
} }
@NotNull @NotNull
public JetType inferFunctionReturnType(@NotNull JetScope outerScope, JetDeclarationWithBody function, FunctionDescriptor functionDescriptor, BindingTrace trace) { public JetType inferFunctionReturnType(@NotNull JetScope outerScope, JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) {
Map<JetExpression, JetType> typeMap = collectReturnedExpressionsWithTypes(trace, outerScope, function, functionDescriptor); Map<JetExpression, JetType> typeMap = collectReturnedExpressionsWithTypes(trace, outerScope, function, functionDescriptor);
Collection<JetType> types = typeMap.values(); Collection<JetType> types = typeMap.values();
return types.isEmpty() return types.isEmpty()
...@@ -120,20 +111,20 @@ public class ExpressionTypingServices { ...@@ -120,20 +111,20 @@ public class ExpressionTypingServices {
} }
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, BindingTrace trace) { public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor) {
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, null, trace); checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, null);
} }
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @Nullable JetType expectedReturnType, BindingTrace trace) { public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @Nullable JetType expectedReturnType) {
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, expectedReturnType, trace); checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, expectedReturnType);
} }
///////////////////////////////////////////////////////// /////////////////////////////////////////////////////////
/*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) { /*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo) {
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, dataFlowInfo, null, trace); checkFunctionReturnType(functionInnerScope, function, functionDescriptor, dataFlowInfo, null);
} }
/*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, @Nullable JetType expectedReturnType, BindingTrace trace) { /*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, @Nullable JetType expectedReturnType) {
if (expectedReturnType == null) { if (expectedReturnType == null) {
expectedReturnType = functionDescriptor.getReturnType(); expectedReturnType = functionDescriptor.getReturnType();
if (!function.hasBlockBody() && !function.hasDeclaredReturnType()) { if (!function.hasBlockBody() && !function.hasDeclaredReturnType()) {
...@@ -141,14 +132,13 @@ public class ExpressionTypingServices { ...@@ -141,14 +132,13 @@ public class ExpressionTypingServices {
} }
} }
checkFunctionReturnType(function, ExpressionTypingContext.newContext( checkFunctionReturnType(function, ExpressionTypingContext.newContext(
expressionTypingContextContext,
function.getProject(), function.getProject(),
semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(), semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false
), trace); ));
} }
/*package*/ void checkFunctionReturnType(JetDeclarationWithBody function, ExpressionTypingContext context, BindingTrace trace) { /*package*/ void checkFunctionReturnType(JetDeclarationWithBody function, ExpressionTypingContext context) {
JetExpression bodyExpression = function.getBodyExpression(); JetExpression bodyExpression = function.getBodyExpression();
if (bodyExpression == null) return; if (bodyExpression == null) return;
...@@ -162,7 +152,7 @@ public class ExpressionTypingServices { ...@@ -162,7 +152,7 @@ public class ExpressionTypingServices {
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function; JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function;
JetBlockExpression blockExpression = functionLiteralExpression.getBodyExpression(); JetBlockExpression blockExpression = functionLiteralExpression.getBodyExpression();
assert blockExpression != null; assert blockExpression != null;
getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context, trace); getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context);
} }
else { else {
expressionTypingFacade.getType(bodyExpression, newContext, !blockBody); expressionTypingFacade.getType(bodyExpression, newContext, !blockBody);
...@@ -170,7 +160,7 @@ public class ExpressionTypingServices { ...@@ -170,7 +160,7 @@ public class ExpressionTypingServices {
} }
@Nullable @Nullable
/*package*/ JetType getBlockReturnedType(@NotNull JetScope outerScope, @NotNull JetBlockExpression expression, @NotNull CoercionStrategy coercionStrategyForLastExpression, ExpressionTypingContext context, BindingTrace trace) { /*package*/ JetType getBlockReturnedType(@NotNull JetScope outerScope, @NotNull JetBlockExpression expression, @NotNull CoercionStrategy coercionStrategyForLastExpression, ExpressionTypingContext context) {
List<JetElement> block = expression.getStatements(); List<JetElement> block = expression.getStatements();
if (block.isEmpty()) { if (block.isEmpty()) {
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, context); return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, context);
...@@ -179,7 +169,7 @@ public class ExpressionTypingServices { ...@@ -179,7 +169,7 @@ public class ExpressionTypingServices {
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration(); DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType"); WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
scope.changeLockLevel(WritableScope.LockLevel.BOTH); scope.changeLockLevel(WritableScope.LockLevel.BOTH);
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace); return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
} }
private Map<JetExpression, JetType> collectReturnedExpressionsWithTypes( private Map<JetExpression, JetType> collectReturnedExpressionsWithTypes(
...@@ -190,10 +180,8 @@ public class ExpressionTypingServices { ...@@ -190,10 +180,8 @@ public class ExpressionTypingServices {
JetExpression bodyExpression = function.getBodyExpression(); JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null; assert bodyExpression != null;
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
expressionTypingFacade.getType(bodyExpression, ExpressionTypingContext.newContext( expressionTypingFacade.getType(bodyExpression, ExpressionTypingContext.newContext(function.getProject(), semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
expressionTypingContextContext, trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN, false), !function.hasBlockBody());
function.getProject(), semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN, false), !function.hasBlockBody());
//todo function literals //todo function literals
final Collection<JetExpression> returnedExpressions = Lists.newArrayList(); final Collection<JetExpression> returnedExpressions = Lists.newArrayList();
if (function.hasBlockBody()) { if (function.hasBlockBody()) {
...@@ -237,7 +225,7 @@ public class ExpressionTypingServices { ...@@ -237,7 +225,7 @@ public class ExpressionTypingServices {
return typeMap; return typeMap;
} }
/*package*/ JetType getBlockReturnedTypeWithWritableScope(@NotNull WritableScope scope, @NotNull List<? extends JetElement> block, @NotNull CoercionStrategy coercionStrategyForLastExpression, ExpressionTypingContext context, BindingTrace trace) { /*package*/ JetType getBlockReturnedTypeWithWritableScope(@NotNull WritableScope scope, @NotNull List<? extends JetElement> block, @NotNull CoercionStrategy coercionStrategyForLastExpression, ExpressionTypingContext context) {
if (block.isEmpty()) { if (block.isEmpty()) {
return JetStandardClasses.getUnitType(); return JetStandardClasses.getUnitType();
} }
...@@ -321,8 +309,7 @@ public class ExpressionTypingServices { ...@@ -321,8 +309,7 @@ public class ExpressionTypingServices {
} }
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType, JetType expectedReturnType) { private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType, JetType expectedReturnType) {
return ExpressionTypingContext.newContext( return ExpressionTypingContext.newContext(oldContext.project, oldContext.semanticServices, oldContext.patternsToDataFlowInfo, oldContext.patternsToBoundVariableLists, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, oldContext.namespacesAllowed);
expressionTypingContextContext, oldContext.project, oldContext.semanticServices, oldContext.patternsToDataFlowInfo, oldContext.patternsToBoundVariableLists, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, oldContext.namespacesAllowed);
} }
private ObservableBindingTrace makeTraceInterceptingTypeMismatch(final BindingTrace trace, final JetExpression expressionToWatch, final boolean[] mismatchFound) { private ObservableBindingTrace makeTraceInterceptingTypeMismatch(final BindingTrace trace, final JetExpression expressionToWatch, final boolean[] mismatchFound) {
......
...@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; ...@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.*; import org.jetbrains.jet.lang.resolve.calls.inference.*;
import org.jetbrains.jet.lang.resolve.scopes.*; import org.jetbrains.jet.lang.resolve.scopes.*;
...@@ -149,12 +148,10 @@ public class ExpressionTypingUtils { ...@@ -149,12 +148,10 @@ public class ExpressionTypingUtils {
return expression; return expression;
} }
public static boolean isVariableIterable(@NotNull CallResolver.Context expressionTypingContextContext, public static boolean isVariableIterable(@NotNull Project project, @NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope) {
@NotNull Project project, @NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope) {
JetExpression expression = JetPsiFactory.createExpression(project, "fake"); JetExpression expression = JetPsiFactory.createExpression(project, "fake");
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getType()); ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getType());
ExpressionTypingContext context = ExpressionTypingContext.newContext( ExpressionTypingContext context = ExpressionTypingContext.newContext(
expressionTypingContextContext,
project, project,
JetSemanticServices.createSemanticServices(project), JetSemanticServices.createSemanticServices(project),
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, DataFlowInfo>(),
......
...@@ -83,7 +83,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito ...@@ -83,7 +83,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration); ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
if (classDescriptor != null) { if (classDescriptor != null) {
VariableDescriptor variableDescriptor = context.getDescriptorResolver() VariableDescriptor variableDescriptor = context.getDescriptorResolver()
.resolveObjectDeclaration(scope.getContainingDeclaration(), declaration, classDescriptor, context.trace); .resolveObjectDeclaration(scope.getContainingDeclaration(), declaration, classDescriptor);
scope.addVariableDescriptor(variableDescriptor); scope.addVariableDescriptor(variableDescriptor);
} }
return DataFlowUtils.checkStatementType(declaration, context); return DataFlowUtils.checkStatementType(declaration, context);
...@@ -106,7 +106,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito ...@@ -106,7 +106,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
context.trace.report(LOCAL_VARIABLE_WITH_SETTER.on(setter)); context.trace.report(LOCAL_VARIABLE_WITH_SETTER.on(setter));
} }
VariableDescriptor propertyDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo, context.trace); VariableDescriptor propertyDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo);
JetExpression initializer = property.getInitializer(); JetExpression initializer = property.getInitializer();
if (property.getPropertyTypeRef() != null && initializer != null) { if (property.getPropertyTypeRef() != null && initializer != null) {
JetType outType = propertyDescriptor.getType(); JetType outType = propertyDescriptor.getType();
...@@ -126,10 +126,10 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito ...@@ -126,10 +126,10 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@Override @Override
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) { public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function, context.trace); SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
scope.addFunctionDescriptor(functionDescriptor); scope.addFunctionDescriptor(functionDescriptor);
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace); JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo, context.trace); context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo);
return DataFlowUtils.checkStatementType(function, context); return DataFlowUtils.checkStatementType(function, context);
} }
......
...@@ -74,7 +74,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { ...@@ -74,7 +74,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
// TODO :change scope according to the bound value in the when header // TODO :change scope according to the bound value in the when header
final JetExpression subjectExpression = expression.getSubjectExpression(); final JetExpression subjectExpression = expression.getSubjectExpression();
final JetType subjectType = subjectExpression != null ? context.getServices().safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE, context.trace) : ErrorUtils.createErrorType("Unknown type"); final JetType subjectType = subjectExpression != null ? context.getServices().safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE) : ErrorUtils.createErrorType("Unknown type");
final DataFlowValue variableDescriptor = subjectExpression != null ? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext()) : DataFlowValue.NULL; final DataFlowValue variableDescriptor = subjectExpression != null ? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext()) : DataFlowValue.NULL;
// TODO : exhaustive patterns // TODO : exhaustive patterns
...@@ -115,7 +115,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { ...@@ -115,7 +115,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
if (bodyExpression != null) { if (bodyExpression != null) {
ExpressionTypingContext newContext = contextWithExpectedType.replaceScope(scopeToExtend).replaceDataFlowInfo(newDataFlowInfo); ExpressionTypingContext newContext = contextWithExpectedType.replaceScope(scopeToExtend).replaceDataFlowInfo(newDataFlowInfo);
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION; CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext, context.trace); JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext);
if (type != null) { if (type != null) {
expressionTypes.add(type); expressionTypes.add(type);
} }
...@@ -180,7 +180,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { ...@@ -180,7 +180,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
public void visitTypePattern(JetTypePattern typePattern) { public void visitTypePattern(JetTypePattern typePattern) {
JetTypeReference typeReference = typePattern.getTypeReference(); JetTypeReference typeReference = typePattern.getTypeReference();
if (typeReference == null) return; if (typeReference == null) return;
JetType type = context.getTypeResolver().resolveType(context.scope, typeReference, context.trace, true); JetType type = context.getTypeResolver().resolveType(context.scope, typeReference);
checkTypeCompatibility(type, subjectType, typePattern); checkTypeCompatibility(type, subjectType, typePattern);
result.set(context.dataFlowInfo.establishSubtyping(subjectVariables, type)); result.set(context.dataFlowInfo.establishSubtyping(subjectVariables, type));
} }
...@@ -251,8 +251,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { ...@@ -251,8 +251,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
public void visitBindingPattern(JetBindingPattern pattern) { public void visitBindingPattern(JetBindingPattern pattern) {
JetProperty variableDeclaration = pattern.getVariableDeclaration(); JetProperty variableDeclaration = pattern.getVariableDeclaration();
JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef(); JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef();
JetType type = propertyTypeRef == null ? subjectType : context.getTypeResolver().resolveType(context.scope, propertyTypeRef, context.trace, true); JetType type = propertyTypeRef == null ? subjectType : context.getTypeResolver().resolveType(context.scope, propertyTypeRef);
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type, context.trace); VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type);
scopeToExtend.addVariableDescriptor(variableDescriptor); scopeToExtend.addVariableDescriptor(variableDescriptor);
if (propertyTypeRef != null) { if (propertyTypeRef != null) {
if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectType, type)) { if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectType, type)) {
......
...@@ -16,19 +16,15 @@ ...@@ -16,19 +16,15 @@
package org.jetbrains.jet.resolve; package org.jetbrains.jet.resolve;
import com.google.common.base.Predicates;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.JavaPsiFacade; import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass; import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiMethod; import com.intellij.psi.PsiMethod;
import junit.framework.Test; import junit.framework.Test;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.Configuration;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
...@@ -36,7 +32,6 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; ...@@ -36,7 +32,6 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingTraceContext; import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
...@@ -140,10 +135,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase { ...@@ -140,10 +135,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
List<JetType> parameterTypeList = Arrays.asList(parameterType); List<JetType> parameterTypeList = Arrays.asList(parameterType);
// JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext()); // JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(getProject()); CallResolver callResolver = new CallResolver(JetSemanticServices.createSemanticServices(getProject()), DataFlowInfo.EMPTY);
TopDownAnalysisContext analysisContext = new TopDownAnalysisContext(semanticServices, JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false);
CallResolver callResolver = new CallResolver(analysisContext.getCallResolverContext(), DataFlowInfo.EMPTY);
OverloadResolutionResults<FunctionDescriptor> functions = callResolver.resolveExactSignature( OverloadResolutionResults<FunctionDescriptor> functions = callResolver.resolveExactSignature(
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList); classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) { for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
......
...@@ -16,17 +16,13 @@ ...@@ -16,17 +16,13 @@
package org.jetbrains.jet.types; package org.jetbrains.jet.types;
import com.google.common.base.Predicates;
import com.intellij.psi.PsiFile;
import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.Configuration;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorResolver; import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler; import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
...@@ -56,8 +52,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { ...@@ -56,8 +52,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
public void setUp() throws Exception { public void setUp() throws Exception {
JetStandardLibrary library = JetStandardLibrary.getInstance(); JetStandardLibrary library = JetStandardLibrary.getInstance();
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library); JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
TopDownAnalysisContext analysisContext = new TopDownAnalysisContext(semanticServices, JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false); descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
descriptorResolver = analysisContext.getDescriptorResolver();
scope = createScope(library.getLibraryScope()); scope = createScope(library.getLibraryScope());
} }
...@@ -77,7 +72,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { ...@@ -77,7 +72,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
private MutableClassDescriptor createClassDescriptor(ClassKind kind, JetClass aClass) { private MutableClassDescriptor createClassDescriptor(ClassKind kind, JetClass aClass) {
MutableClassDescriptor classDescriptor = new MutableClassDescriptor(JetTestUtils.DUMMY_TRACE, root, scope, kind); MutableClassDescriptor classDescriptor = new MutableClassDescriptor(JetTestUtils.DUMMY_TRACE, root, scope, kind);
descriptorResolver.resolveMutableClassDescriptor(aClass, classDescriptor, JetTestUtils.DUMMY_TRACE); descriptorResolver.resolveMutableClassDescriptor(aClass, classDescriptor);
return classDescriptor; return classDescriptor;
} }
...@@ -95,7 +90,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { ...@@ -95,7 +90,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations(); List<JetDeclaration> declarations = aClass.getDeclarations();
JetNamedFunction function = (JetNamedFunction) declarations.get(0); JetNamedFunction function = (JetNamedFunction) declarations.get(0);
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, JetTestUtils.DUMMY_TRACE); SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function);
assertEquals(expectedFunctionModality, functionDescriptor.getModality()); assertEquals(expectedFunctionModality, functionDescriptor.getModality());
} }
...@@ -106,7 +101,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { ...@@ -106,7 +101,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations(); List<JetDeclaration> declarations = aClass.getDeclarations();
JetProperty property = (JetProperty) declarations.get(0); JetProperty property = (JetProperty) declarations.get(0);
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE); PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
assertEquals(expectedPropertyModality, propertyDescriptor.getModality()); assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
} }
...@@ -118,7 +113,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture { ...@@ -118,7 +113,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations(); List<JetDeclaration> declarations = aClass.getDeclarations();
JetProperty property = (JetProperty) declarations.get(0); JetProperty property = (JetProperty) declarations.get(0);
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE); PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
PropertyAccessorDescriptor propertyAccessor = isGetter PropertyAccessorDescriptor propertyAccessor = isGetter
? propertyDescriptor.getGetter() ? propertyDescriptor.getGetter()
: propertyDescriptor.getSetter(); : propertyDescriptor.getSetter();
......
...@@ -16,12 +16,9 @@ ...@@ -16,12 +16,9 @@
package org.jetbrains.jet.types; package org.jetbrains.jet.types;
import com.google.common.base.Predicates;
import com.intellij.psi.PsiFile;
import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.Configuration;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
...@@ -29,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction; ...@@ -29,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetPsiFactory; import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.resolve.DescriptorResolver; import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.OverloadUtil; import org.jetbrains.jet.lang.resolve.OverloadUtil;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
/** /**
...@@ -47,8 +43,7 @@ public class JetOverloadTest extends JetLiteFixture { ...@@ -47,8 +43,7 @@ public class JetOverloadTest extends JetLiteFixture {
super.setUp(); super.setUp();
library = JetStandardLibrary.getInstance(); library = JetStandardLibrary.getInstance();
semanticServices = JetSemanticServices.createSemanticServices(library); semanticServices = JetSemanticServices.createSemanticServices(library);
TopDownAnalysisContext analysisContext = new TopDownAnalysisContext(semanticServices, JetTestUtils.DUMMY_TRACE, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false); descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
descriptorResolver = analysisContext.getDescriptorResolver();
} }
@Override @Override
...@@ -176,7 +171,7 @@ public class JetOverloadTest extends JetLiteFixture { ...@@ -176,7 +171,7 @@ public class JetOverloadTest extends JetLiteFixture {
private FunctionDescriptor makeFunction(String funDecl) { private FunctionDescriptor makeFunction(String funDecl) {
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl); JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function, JetTestUtils.DUMMY_TRACE); return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
} }
} }
...@@ -16,12 +16,9 @@ ...@@ -16,12 +16,9 @@
package org.jetbrains.jet.types; package org.jetbrains.jet.types;
import com.google.common.base.Predicates;
import com.intellij.psi.PsiFile;
import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.Configuration;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
...@@ -29,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction; ...@@ -29,7 +26,6 @@ import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetPsiFactory; import org.jetbrains.jet.lang.psi.JetPsiFactory;
import org.jetbrains.jet.lang.resolve.DescriptorResolver; import org.jetbrains.jet.lang.resolve.DescriptorResolver;
import org.jetbrains.jet.lang.resolve.OverridingUtil; import org.jetbrains.jet.lang.resolve.OverridingUtil;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary; import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
/** /**
...@@ -47,8 +43,7 @@ public class JetOverridingTest extends JetLiteFixture { ...@@ -47,8 +43,7 @@ public class JetOverridingTest extends JetLiteFixture {
super.setUp(); super.setUp();
library = JetStandardLibrary.getInstance(); library = JetStandardLibrary.getInstance();
semanticServices = JetSemanticServices.createSemanticServices(library); semanticServices = JetSemanticServices.createSemanticServices(library);
TopDownAnalysisContext analysisContext = new TopDownAnalysisContext(semanticServices, JetTestUtils.DUMMY_TRACE, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false); descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
descriptorResolver = analysisContext.getDescriptorResolver();
} }
@Override @Override
...@@ -166,6 +161,6 @@ public class JetOverridingTest extends JetLiteFixture { ...@@ -166,6 +161,6 @@ public class JetOverridingTest extends JetLiteFixture {
private FunctionDescriptor makeFunction(String funDecl) { private FunctionDescriptor makeFunction(String funDecl) {
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl); JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function, JetTestUtils.DUMMY_TRACE); return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
} }
} }
...@@ -16,16 +16,13 @@ ...@@ -16,16 +16,13 @@
package org.jetbrains.jet.types; package org.jetbrains.jet.types;
import com.google.common.base.Predicates;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestCaseBuilder; import org.jetbrains.jet.JetTestCaseBuilder;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.Configuration;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
...@@ -56,7 +53,6 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -56,7 +53,6 @@ public class JetTypeCheckerTest extends JetLiteFixture {
private DescriptorResolver descriptorResolver; private DescriptorResolver descriptorResolver;
private JetScope scopeWithImports; private JetScope scopeWithImports;
private TypeResolver typeResolver; private TypeResolver typeResolver;
private TopDownAnalysisContext analysisContext;
public JetTypeCheckerTest() { public JetTypeCheckerTest() {
super(""); super("");
...@@ -68,12 +64,9 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -68,12 +64,9 @@ public class JetTypeCheckerTest extends JetLiteFixture {
library = JetStandardLibrary.getInstance(); library = JetStandardLibrary.getInstance();
semanticServices = JetSemanticServices.createSemanticServices(library); semanticServices = JetSemanticServices.createSemanticServices(library);
classDefinitions = new ClassDefinitions(); classDefinitions = new ClassDefinitions();
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
analysisContext = new TopDownAnalysisContext(semanticServices, JetTestUtils.DUMMY_TRACE, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false);
descriptorResolver = analysisContext.getDescriptorResolver();
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE); scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
typeResolver = analysisContext.getTypeResolver(); typeResolver = new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true);
} }
@Override @Override
...@@ -547,14 +540,14 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -547,14 +540,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
private void assertType(String expression, JetType expectedType) { private void assertType(String expression, JetType expectedType) {
Project project = getProject(); Project project = getProject();
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression); JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
JetType type = analysisContext.getExpressionTypingServices().getType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, JetTestUtils.DUMMY_TRACE); JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).getType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE);
assertTrue(type + " != " + expectedType, type.equals(expectedType)); assertTrue(type + " != " + expectedType, type.equals(expectedType));
} }
private void assertErrorType(String expression) { private void assertErrorType(String expression) {
Project project = getProject(); Project project = getProject();
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression); JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
JetType type = analysisContext.getExpressionTypingServices().safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, JetTestUtils.DUMMY_TRACE); JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE);
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type)); assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
} }
...@@ -577,7 +570,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -577,7 +570,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
private void assertType(JetScope scope, String expression, String expectedTypeStr) { private void assertType(JetScope scope, String expression, String expectedTypeStr) {
Project project = getProject(); Project project = getProject();
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression); JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
JetType type = analysisContext.getExpressionTypingServices().getType(addImports(scope), jetExpression, TypeUtils.NO_EXPECTED_TYPE, JetTestUtils.DUMMY_TRACE); JetType type = semanticServices.getTypeInferrerServices(JetTestUtils.DUMMY_TRACE).getType(addImports(scope), jetExpression, TypeUtils.NO_EXPECTED_TYPE);
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr); JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
assertEquals(expectedType, type); assertEquals(expectedType, type);
} }
...@@ -597,7 +590,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -597,7 +590,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
} }
private JetType makeType(JetScope scope, String typeStr) { private JetType makeType(JetScope scope, String typeStr) {
return analysisContext.getTypeResolver().resolveType(scope, JetPsiFactory.createType(getProject(), typeStr), JetTestUtils.DUMMY_TRACE, true); return new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true).resolveType(scope, JetPsiFactory.createType(getProject(), typeStr));
} }
private class ClassDefinitions { private class ClassDefinitions {
...@@ -664,7 +657,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -664,7 +657,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet(); Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest"); ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest");
for (String funDecl : FUNCTION_DECLARATIONS) { for (String funDecl : FUNCTION_DECLARATIONS) {
FunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl), JetTestUtils.DUMMY_TRACE); FunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl));
if (name.equals(functionDescriptor.getName())) { if (name.equals(functionDescriptor.getName())) {
writableFunctionGroup.add(functionDescriptor); writableFunctionGroup.add(functionDescriptor);
} }
...@@ -689,14 +682,14 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -689,14 +682,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
// This call has side-effects on the parameterScope (fills it in) // This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters List<TypeParameterDescriptor> typeParameters
= descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters(), JetTestUtils.DUMMY_TRACE); = descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters());
descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters, JetTestUtils.DUMMY_TRACE); descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters);
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers(); List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
// TODO : assuming that the hierarchy is acyclic // TODO : assuming that the hierarchy is acyclic
Collection<JetType> supertypes = delegationSpecifiers.isEmpty() Collection<JetType> supertypes = delegationSpecifiers.isEmpty()
? Collections.singleton(JetStandardClasses.getAnyType()) ? Collections.singleton(JetStandardClasses.getAnyType())
: descriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver, JetTestUtils.DUMMY_TRACE, true); : descriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver);
// for (JetType supertype: supertypes) { // for (JetType supertype: supertypes) {
// if (supertype.getConstructor().isSealed()) { // if (supertype.getConstructor().isSealed()) {
// trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype); // trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype);
...@@ -713,7 +706,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -713,7 +706,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
@Override @Override
public void visitProperty(JetProperty property) { public void visitProperty(JetProperty property) {
if (property.getPropertyTypeRef() != null) { if (property.getPropertyTypeRef() != null) {
memberDeclarations.addPropertyDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property, JetTestUtils.DUMMY_TRACE)); memberDeclarations.addPropertyDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property));
} else { } else {
// TODO : Caution: a cyclic dependency possible // TODO : Caution: a cyclic dependency possible
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -723,7 +716,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -723,7 +716,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
@Override @Override
public void visitNamedFunction(JetNamedFunction function) { public void visitNamedFunction(JetNamedFunction function) {
if (function.getReturnTypeRef() != null) { if (function.getReturnTypeRef() != null) {
memberDeclarations.addFunctionDescriptor(descriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function, JetTestUtils.DUMMY_TRACE)); memberDeclarations.addFunctionDescriptor(descriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function));
} else { } else {
// TODO : Caution: a cyclic dependency possible // TODO : Caution: a cyclic dependency possible
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
...@@ -747,11 +740,11 @@ public class JetTypeCheckerTest extends JetLiteFixture { ...@@ -747,11 +740,11 @@ public class JetTypeCheckerTest extends JetLiteFixture {
null null
); );
for (JetSecondaryConstructor constructor : classElement.getSecondaryConstructors()) { for (JetSecondaryConstructor constructor : classElement.getSecondaryConstructors()) {
ConstructorDescriptorImpl functionDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor, JetTestUtils.DUMMY_TRACE); ConstructorDescriptorImpl functionDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor);
functionDescriptor.setReturnType(classDescriptor.getDefaultType()); functionDescriptor.setReturnType(classDescriptor.getDefaultType());
constructors.add(functionDescriptor); constructors.add(functionDescriptor);
} }
ConstructorDescriptorImpl primaryConstructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement, JetTestUtils.DUMMY_TRACE); ConstructorDescriptorImpl primaryConstructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement);
if (primaryConstructorDescriptor != null) { if (primaryConstructorDescriptor != null) {
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType()); primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
constructors.add(primaryConstructorDescriptor); constructors.add(primaryConstructorDescriptor);
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" /> <orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
<orderEntry type="module" module-name="j2k" /> <orderEntry type="module" module-name="j2k" />
<orderEntry type="module" module-name="js.translator" /> <orderEntry type="module" module-name="js.translator" />
<orderEntry type="library" name="guice-3.0" level="project" />
</component> </component>
</module> </module>
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
package org.jetbrains.jet.plugin.liveTemplates.macro; package org.jetbrains.jet.plugin.liveTemplates.macro;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder; import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.codeInsight.template.Expression; import com.intellij.codeInsight.template.Expression;
...@@ -33,14 +30,10 @@ import com.intellij.psi.PsiNamedElement; ...@@ -33,14 +30,10 @@ import com.intellij.psi.PsiNamedElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.compiler.TipsManager; import org.jetbrains.jet.compiler.TipsManager;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisContext;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
...@@ -58,7 +51,7 @@ public abstract class BaseJetVariableMacro extends Macro { ...@@ -58,7 +51,7 @@ public abstract class BaseJetVariableMacro extends Macro {
private JetNamedDeclaration[] getVariables(Expression[] params, ExpressionContext context) { private JetNamedDeclaration[] getVariables(Expression[] params, ExpressionContext context) {
if (params.length != 0) return null; if (params.length != 0) return null;
final Project project = context.getProject(); Project project = context.getProject();
PsiDocumentManager.getInstance(project).commitAllDocuments(); PsiDocumentManager.getInstance(project).commitAllDocuments();
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument()); PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
...@@ -73,19 +66,11 @@ public abstract class BaseJetVariableMacro extends Macro { ...@@ -73,19 +66,11 @@ public abstract class BaseJetVariableMacro extends Macro {
return null; return null;
} }
class TdacModule extends AbstractModule {
@Override
protected void configure() {
bind(JetSemanticServices.class).toInstance(JetSemanticServices.createSemanticServices(project));
}
}
CallResolver.Context callResolverContext = Guice.createInjector(new TdacModule()).getInstance(CallResolver.Context.class);
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>(); List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) { for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
if (declarationDescriptor instanceof VariableDescriptor) { if (declarationDescriptor instanceof VariableDescriptor) {
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor; VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
if (isSuitable(variableDescriptor, scope, project, callResolverContext)) { if (isSuitable(variableDescriptor, scope, project)) {
filteredDescriptors.add(variableDescriptor); filteredDescriptors.add(variableDescriptor);
} }
} }
...@@ -104,7 +89,7 @@ public abstract class BaseJetVariableMacro extends Macro { ...@@ -104,7 +89,7 @@ public abstract class BaseJetVariableMacro extends Macro {
return declarations.toArray(new JetNamedDeclaration[declarations.size()]); return declarations.toArray(new JetNamedDeclaration[declarations.size()]);
} }
protected abstract boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project, CallResolver.Context callResolverContext); protected abstract boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project);
@Nullable @Nullable
private static JetExpression findContextExpression(PsiFile psiFile, int startOffset) { private static JetExpression findContextExpression(PsiFile psiFile, int startOffset) {
......
...@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.liveTemplates.macro; ...@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.liveTemplates.macro;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.plugin.JetBundle; import org.jetbrains.jet.plugin.JetBundle;
...@@ -39,7 +38,7 @@ public class JetAnyVariableMacro extends BaseJetVariableMacro { ...@@ -39,7 +38,7 @@ public class JetAnyVariableMacro extends BaseJetVariableMacro {
} }
@Override @Override
protected boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project, CallResolver.Context callResolverContext) { protected boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project) {
return true; return true;
} }
} }
...@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.liveTemplates.macro; ...@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.liveTemplates.macro;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils; import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
import org.jetbrains.jet.plugin.JetBundle; import org.jetbrains.jet.plugin.JetBundle;
...@@ -29,10 +28,6 @@ import org.jetbrains.jet.plugin.JetBundle; ...@@ -29,10 +28,6 @@ import org.jetbrains.jet.plugin.JetBundle;
* @since 2/7/12 * @since 2/7/12
*/ */
public class JetIterableVariableMacro extends BaseJetVariableMacro { public class JetIterableVariableMacro extends BaseJetVariableMacro {
public JetIterableVariableMacro() {
}
@Override @Override
public String getName() { public String getName() {
return "kotlinIterableVariable"; return "kotlinIterableVariable";
...@@ -44,7 +39,7 @@ public class JetIterableVariableMacro extends BaseJetVariableMacro { ...@@ -44,7 +39,7 @@ public class JetIterableVariableMacro extends BaseJetVariableMacro {
} }
@Override @Override
protected boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project, CallResolver.Context callResolverContext) { protected boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project) {
return ExpressionTypingUtils.isVariableIterable(callResolverContext, project, variableDescriptor, scope); return ExpressionTypingUtils.isVariableIterable(project, variableDescriptor, scope);
} }
} }
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册