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