using guice to wire TopDownAnalyzer beans
attempt 2
This commit is contained in:
Generated
+13
@@ -0,0 +1,13 @@
|
||||
<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>
|
||||
<root url="jar://$PROJECT_DIR$/lib/guice/guice-3.0-src.zip!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
||||
<fileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
<fileset dir="${basedir}/lib" includes="**/*.jar"/>
|
||||
<pathelement path="${output}/classes/runtime"/>
|
||||
</path>
|
||||
|
||||
|
||||
+2
-4
@@ -28,7 +28,6 @@ import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.StandardConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
@@ -141,15 +140,14 @@ public class AnalyzerFacadeForJVM {
|
||||
public static BindingContext analyzeFilesWithJavaIntegration(Project project, Collection<JetFile> files, Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||
return AnalyzingUtils.analyzeFilesWithGivenTrace(
|
||||
project,
|
||||
JavaBridgeConfiguration.createJavaBridgeConfiguration(project, bindingTraceContext, StandardConfiguration.createStandardConfiguration(project)),
|
||||
files,
|
||||
filesToAnalyzeCompletely,
|
||||
flowDataTraceFactory,
|
||||
bindingTraceContext,
|
||||
semanticServices);
|
||||
bindingTraceContext
|
||||
);
|
||||
}
|
||||
|
||||
public static BindingContext shallowAnalyzeFiles(Collection<JetFile> files) {
|
||||
|
||||
+1
-2
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
@@ -48,7 +47,7 @@ public class JavaBridgeConfiguration implements Configuration {
|
||||
|
||||
private JavaBridgeConfiguration(Project project, BindingTrace trace, Configuration delegateConfiguration) {
|
||||
this.project = project;
|
||||
this.javaSemanticServices = new JavaSemanticServices(project, JetSemanticServices.createSemanticServices(project), trace);
|
||||
this.javaSemanticServices = new JavaSemanticServices(project, trace);
|
||||
this.delegateConfiguration = delegateConfiguration;
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.java.alt.AltClassFinder;
|
||||
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
||||
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
||||
@@ -542,7 +543,7 @@ public class JavaDescriptorResolver {
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitClassBound() {
|
||||
return new JetTypeJetSignatureReader(semanticServices, semanticServices.getJetSemanticServices().getStandardLibrary(), typeVariableResolver) {
|
||||
return new JetTypeJetSignatureReader(semanticServices, JetStandardLibrary.getInstance(), typeVariableResolver) {
|
||||
@Override
|
||||
protected void done(@NotNull JetType jetType) {
|
||||
if (isJavaLangObject(jetType)) {
|
||||
@@ -555,7 +556,7 @@ public class JavaDescriptorResolver {
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitInterfaceBound() {
|
||||
return new JetTypeJetSignatureReader(semanticServices, semanticServices.getJetSemanticServices().getStandardLibrary(), typeVariableResolver) {
|
||||
return new JetTypeJetSignatureReader(semanticServices, JetStandardLibrary.getInstance(), typeVariableResolver) {
|
||||
@Override
|
||||
protected void done(@NotNull JetType jetType) {
|
||||
upperBounds.add(jetType);
|
||||
@@ -739,7 +740,7 @@ public class JavaDescriptorResolver {
|
||||
|
||||
@Override
|
||||
public JetSignatureVisitor visitSuperclass() {
|
||||
return new JetTypeJetSignatureReader(semanticServices, semanticServices.getJetSemanticServices().getStandardLibrary(), typeVariableResolver) {
|
||||
return new JetTypeJetSignatureReader(semanticServices, JetStandardLibrary.getInstance(), typeVariableResolver) {
|
||||
@Override
|
||||
protected void done(@NotNull JetType jetType) {
|
||||
if (!jetType.equals(JetStandardClasses.getAnyType())) {
|
||||
@@ -971,7 +972,7 @@ public class JavaDescriptorResolver {
|
||||
|
||||
JetType varargElementType;
|
||||
if (psiType instanceof PsiEllipsisType) {
|
||||
varargElementType = semanticServices.getJetSemanticServices().getStandardLibrary().getArrayElementType(outType);
|
||||
varargElementType = JetStandardLibrary.getInstance().getArrayElementType(outType);
|
||||
} else {
|
||||
varargElementType = null;
|
||||
}
|
||||
|
||||
+4
-10
@@ -19,11 +19,11 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import com.intellij.openapi.project.Project;
|
||||
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.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
@@ -32,13 +32,11 @@ public class JavaSemanticServices {
|
||||
private final JavaTypeTransformer typeTransformer;
|
||||
private final JavaDescriptorResolver descriptorResolver;
|
||||
private final BindingTrace trace;
|
||||
private final JetSemanticServices jetSemanticServices;
|
||||
|
||||
public JavaSemanticServices(Project project, JetSemanticServices jetSemanticServices, BindingTrace trace) {
|
||||
public JavaSemanticServices(Project project, BindingTrace trace) {
|
||||
this.trace = trace;
|
||||
this.descriptorResolver = new JavaDescriptorResolver(project, this);
|
||||
this.typeTransformer = new JavaTypeTransformer(this, jetSemanticServices.getStandardLibrary(), descriptorResolver);
|
||||
this.jetSemanticServices = jetSemanticServices;
|
||||
this.typeTransformer = new JavaTypeTransformer(this, JetStandardLibrary.getInstance(), descriptorResolver);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -56,14 +54,10 @@ public class JavaSemanticServices {
|
||||
return trace;
|
||||
}
|
||||
|
||||
public JetSemanticServices getJetSemanticServices() {
|
||||
return jetSemanticServices;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ClassDescriptor getKotlinClassDescriptor(String qualifiedName) {
|
||||
if (qualifiedName.startsWith("jet.")) {
|
||||
ClassDescriptor r = (ClassDescriptor) jetSemanticServices.getStandardLibrary().getLibraryScope().getClassifier(qualifiedName.substring("jet.".length()));
|
||||
ClassDescriptor r = (ClassDescriptor) JetStandardLibrary.getInstance().getLibraryScope().getClassifier(qualifiedName.substring("jet.".length()));
|
||||
if (r == null) {
|
||||
// TODO: better error
|
||||
//throw new IllegalStateException();
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.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;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetSemanticServices {
|
||||
public static JetSemanticServices createSemanticServices(JetStandardLibrary standardLibrary) {
|
||||
return new JetSemanticServices(standardLibrary);
|
||||
}
|
||||
|
||||
public static JetSemanticServices createSemanticServices(Project project) {
|
||||
return new JetSemanticServices(JetStandardLibrary.getInstance());
|
||||
}
|
||||
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final JetTypeChecker typeChecker;
|
||||
|
||||
private JetSemanticServices(JetStandardLibrary standardLibrary) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
this.typeChecker = JetTypeChecker.INSTANCE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetStandardLibrary getStandardLibrary() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
@@ -35,6 +34,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -91,8 +91,7 @@ public class AnalyzingUtils {
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||
return analyzeFilesWithGivenTrace(project, configuration, files, filesToAnalyzeCompletely, flowDataTraceFactory, bindingTraceContext, semanticServices);
|
||||
return analyzeFilesWithGivenTrace(project, configuration, files, filesToAnalyzeCompletely, flowDataTraceFactory, bindingTraceContext);
|
||||
}
|
||||
|
||||
public static BindingContext analyzeFilesWithGivenTrace(
|
||||
@@ -101,10 +100,9 @@ public class AnalyzingUtils {
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
@NotNull BindingTraceContext bindingTraceContext,
|
||||
@NotNull JetSemanticServices semanticServices) {
|
||||
@NotNull BindingTraceContext bindingTraceContext) {
|
||||
|
||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
||||
JetScope libraryScope = JetStandardLibrary.getInstance().getLibraryScope();
|
||||
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||
|
||||
final WritableScope scope = new WritableScopeImpl(
|
||||
@@ -114,7 +112,7 @@ public class AnalyzingUtils {
|
||||
scope.importScope(libraryScope);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
|
||||
TopDownAnalyzer.process(project, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
|
||||
|
||||
private Map<String, NamespaceDescriptorImpl> declaredNamespaces = Maps.newHashMap();
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
@@ -36,6 +35,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,47 +47,50 @@ 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 callResolver) {
|
||||
this.callResolver = callResolver;
|
||||
}
|
||||
|
||||
@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) {
|
||||
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(trace, scope, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, entryElement), NO_EXPECTED_TYPE);
|
||||
@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, DataFlowInfo.EMPTY);
|
||||
JetType annotationType = results.getResultingDescriptor().getReturnType();
|
||||
if (results.isSuccess()) {
|
||||
descriptor.setAnnotationType(annotationType);
|
||||
@@ -98,7 +101,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 +109,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 +163,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();
|
||||
|
||||
@@ -18,11 +18,45 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.Queue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassInitializer;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorByExpressionSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToThisCall;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
@@ -31,7 +65,12 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -39,9 +78,29 @@ import org.jetbrains.jet.util.Box;
|
||||
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.BY_IN_SECONDARY_CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.DELEGATION_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.DELEGATION_NOT_TO_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.INITIALIZER_WITH_NO_ARGUMENTS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_CALLS_TO_THIS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_CLASSES_IN_SUPERTYPE_LIST;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_APPEARS_TWICE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_INITIALIZED_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_INITIALIZED;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_INITIALIZED_DEFAULT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
@@ -49,15 +108,39 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class BodyResolver {
|
||||
private final TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
@NotNull
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
@NotNull
|
||||
private CallResolver callResolver;
|
||||
|
||||
private final ObservableBindingTrace trace;
|
||||
|
||||
public BodyResolver(TopDownAnalysisContext context) {
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
this.trace = context.getTrace();
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDescriptorResolver(@NotNull DescriptorResolver descriptorResolver) {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setExpressionTypingServices(@NotNull ExpressionTypingServices expressionTypingServices) {
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setCallResolver(@NotNull CallResolver callResolver) {
|
||||
this.callResolver = callResolver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void resolveBehaviorDeclarationBodies() {
|
||||
|
||||
resolveDelegationSpecifierLists();
|
||||
@@ -74,7 +157,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 +173,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 +204,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 && !JetTypeChecker.INSTANCE.isSubtypeOf(type, supertype)) {
|
||||
context.getTrace().report(TYPE_MISMATCH.on(delegateExpression, supertype, type));
|
||||
}
|
||||
}
|
||||
@@ -141,9 +224,9 @@ public class BodyResolver {
|
||||
assert descriptor.getKind() == ClassKind.TRAIT;
|
||||
return;
|
||||
}
|
||||
OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall(
|
||||
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(
|
||||
context.getTrace(), scopeForConstructor,
|
||||
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
|
||||
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE, DataFlowInfo.EMPTY);
|
||||
if (results.isSuccess()) {
|
||||
JetType supertype = results.getResultingDescriptor().getReturnType();
|
||||
recordSupertype(typeReference, supertype);
|
||||
@@ -261,9 +344,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 +380,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 DataFlowInfo dataFlowInfo = DataFlowInfo.EMPTY; // TODO: dataFlowInfo
|
||||
|
||||
PsiElement nameElement = declaration.getNameNode().getPsi();
|
||||
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
|
||||
@@ -320,7 +402,7 @@ public class BodyResolver {
|
||||
public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) {
|
||||
JetTypeReference typeReference = call.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
callResolver.resolveCall(context.getTrace(), scopeForSupertypeInitializers, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
|
||||
callResolver.resolveCall(context.getTrace(), scopeForSupertypeInitializers, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE, dataFlowInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +414,7 @@ public class BodyResolver {
|
||||
|
||||
callResolver.resolveCall(context.getTrace(),
|
||||
scopeForSupertypeInitializers,
|
||||
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
|
||||
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE, dataFlowInfo);
|
||||
// call.getThisReference(),
|
||||
// classDescriptor,
|
||||
// classDescriptor.getDefaultType(),
|
||||
@@ -363,9 +445,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 +505,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 +532,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 +540,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 +550,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 +573,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 +589,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 +601,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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
@@ -35,13 +36,20 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
*/
|
||||
public class ControlFlowAnalyzer {
|
||||
private TopDownAnalysisContext context;
|
||||
private final JetControlFlowDataTraceFactory flowDataTraceFactory;
|
||||
private JetControlFlowDataTraceFactory flowDataTraceFactory;
|
||||
|
||||
public ControlFlowAnalyzer(TopDownAnalysisContext context, JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
|
||||
@Inject
|
||||
public void setContext(TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setFlowDataTraceFactory(JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
this.flowDataTraceFactory = flowDataTraceFactory;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
for (JetClass aClass : context.getClasses().keySet()) {
|
||||
if (!context.completeAnalysisNeeded(aClass)) continue;
|
||||
|
||||
@@ -16,9 +16,28 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptorLite;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceLike;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetParameterList;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
@@ -31,19 +50,43 @@ import static org.jetbrains.jet.lang.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DeclarationResolver {
|
||||
private final AnnotationResolver annotationResolver;
|
||||
private final TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private AnnotationResolver annotationResolver;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private ImportsResolver importsResolver;
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
|
||||
public DeclarationResolver(TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
this.annotationResolver = new AnnotationResolver(context.getSemanticServices(), context.getTrace());
|
||||
|
||||
@Inject
|
||||
public void setAnnotationResolver(@NotNull AnnotationResolver annotationResolver) {
|
||||
this.annotationResolver = annotationResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setImportsResolver(@NotNull ImportsResolver importsResolver) {
|
||||
this.importsResolver = importsResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDescriptorResolver(@NotNull DescriptorResolver descriptorResolver) {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void process() {
|
||||
resolveConstructorHeaders();
|
||||
resolveAnnotationStubsOnClassesAndConstructors();
|
||||
resolveFunctionAndPropertyHeaders();
|
||||
context.getImportsResolver().processMembersImports();
|
||||
importsResolver.processMembersImports();
|
||||
}
|
||||
|
||||
private void resolveConstructorHeaders() {
|
||||
@@ -59,7 +102,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 +117,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 +162,7 @@ public class DeclarationResolver {
|
||||
declaration.accept(new JetVisitorVoid() {
|
||||
@Override
|
||||
public void visitNamedFunction(JetNamedFunction function) {
|
||||
SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
|
||||
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function, context.getTrace());
|
||||
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
||||
context.getFunctions().put(function, functionDescriptor);
|
||||
context.getDeclaringScopes().put(function, scopeForFunctions);
|
||||
@@ -128,7 +170,7 @@ public class DeclarationResolver {
|
||||
|
||||
@Override
|
||||
public void visitProperty(JetProperty property) {
|
||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scopeForPropertyInitializers, property);
|
||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(namespaceLike, scopeForPropertyInitializers, property, context.getTrace());
|
||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||
context.getProperties().put(property, propertyDescriptor);
|
||||
context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
|
||||
@@ -142,7 +184,7 @@ public class DeclarationResolver {
|
||||
|
||||
@Override
|
||||
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration));
|
||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration), context.getTrace());
|
||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
|
||||
@@ -151,7 +193,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 = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), context.getTrace());
|
||||
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
|
||||
}
|
||||
}
|
||||
@@ -170,13 +212,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 = descriptorResolver.resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass, context.getTrace());
|
||||
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
|
||||
if (parameter.getValOrVarNode() != null) {
|
||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
|
||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePrimaryConstructorParameterToAProperty(
|
||||
classDescriptor,
|
||||
memberScope,
|
||||
parameter
|
||||
parameter, context.getTrace()
|
||||
);
|
||||
classDescriptor.addPropertyDescriptor(propertyDescriptor);
|
||||
context.getPrimaryConstructorParameterProperties().add(propertyDescriptor);
|
||||
@@ -191,10 +233,10 @@ public class DeclarationResolver {
|
||||
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
||||
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode().getPsi()));
|
||||
}
|
||||
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolveSecondaryConstructorDescriptor(
|
||||
ConstructorDescriptor constructorDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(
|
||||
classDescriptor.getScopeForMemberResolution(),
|
||||
classDescriptor,
|
||||
constructor);
|
||||
constructor, context.getTrace());
|
||||
classDescriptor.addConstructor(constructorDescriptor, context.getTrace());
|
||||
context.getConstructors().put(constructor, constructorDescriptor);
|
||||
context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
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.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -44,12 +45,16 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE;
|
||||
* @author svtk
|
||||
*/
|
||||
public class DeclarationsChecker {
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
|
||||
public DeclarationsChecker(TopDownAnalysisContext context) {
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
Map<JetClass, MutableClassDescriptor> classes = context.getClasses();
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -28,12 +30,16 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class DelegationResolver {
|
||||
private final TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
|
||||
public DelegationResolver(TopDownAnalysisContext context) {
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
addDelegatedMembers();
|
||||
}
|
||||
|
||||
@@ -18,58 +18,140 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
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.ConstructorDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Modality;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibility;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetModifierList;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetNullableType;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclarationName;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProjectionKind;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeConstraint;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeElement;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner;
|
||||
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.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
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.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
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.checker.JetTypeChecker;
|
||||
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 java.util.*;
|
||||
import java.util.ArrayList;
|
||||
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.ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONFLICTING_UPPER_BOUNDS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_CLASS_OBJECT_UPPER_BOUND;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_UPPER_BOUND;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NO_GENERICS_IN_SUPERTYPE_SPECIFIER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.NULLABLE_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.PROPERTY_WITH_NO_TYPE_NO_INITIALIZER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SETTER_PARAMETER_WITH_DEFAULT_VALUE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UNRESOLVED_REFERENCE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.UPPER_BOUND_VIOLATED;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.VAL_WITH_SETTER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_GETTER_RETURN_TYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.WRONG_SETTER_PARAMETER_TYPE;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
@NotNull
|
||||
private TypeResolver typeResolver;
|
||||
@NotNull
|
||||
private AnnotationResolver annotationResolver;
|
||||
@NotNull
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
|
||||
public DescriptorResolver(JetSemanticServices semanticServices, BindingTrace trace) {
|
||||
this.semanticServices = semanticServices;
|
||||
this.typeResolver = new TypeResolver(semanticServices, trace, true);
|
||||
this.typeResolverNotCheckingBounds = new TypeResolver(semanticServices, trace, false);
|
||||
this.trace = trace;
|
||||
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
|
||||
@Inject
|
||||
public void setTypeResolver(@NotNull TypeResolver typeResolver) {
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
|
||||
public void resolveMutableClassDescriptor(@NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) {
|
||||
@Inject
|
||||
public void setAnnotationResolver(@NotNull AnnotationResolver annotationResolver) {
|
||||
this.annotationResolver = annotationResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setExpressionTypingServices(@NotNull 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 +169,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 +186,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 +202,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 +210,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 +235,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 +256,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 +278,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 +318,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 +329,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 +340,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 +350,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,
|
||||
@@ -281,32 +363,31 @@ public class DescriptorResolver {
|
||||
}
|
||||
|
||||
private JetType getVarargParameterType(JetType type) {
|
||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
||||
JetType arrayType = standardLibrary.getPrimitiveArrayJetTypeByPrimitiveJetType(type);
|
||||
JetType arrayType = JetStandardLibrary.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(type);
|
||||
if (arrayType != null) {
|
||||
return arrayType;
|
||||
} else {
|
||||
return standardLibrary.getArrayType(type);
|
||||
return JetStandardLibrary.getInstance().getArrayType(type);
|
||||
}
|
||||
}
|
||||
|
||||
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 +399,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 +408,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 +422,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,9 +469,9 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private JetType resolveAndCheckUpperBoundType(@NotNull JetTypeReference upperBound, @NotNull JetScope scope, boolean classObjectConstaint) {
|
||||
JetType jetType = typeResolverNotCheckingBounds.resolveType(scope, upperBound);
|
||||
if (!TypeUtils.canHaveSubtypes(semanticServices.getTypeChecker(), jetType)) {
|
||||
private JetType resolveAndCheckUpperBoundType(@NotNull JetTypeReference upperBound, @NotNull JetScope scope, boolean classObjectConstaint, BindingTrace trace) {
|
||||
JetType jetType = typeResolver.resolveType(scope, upperBound, trace, false);
|
||||
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.INSTANCE, jetType)) {
|
||||
if (classObjectConstaint) {
|
||||
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, jetType));
|
||||
}
|
||||
@@ -402,16 +483,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 +501,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 +513,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 +535,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 +573,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 +589,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 +603,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 +612,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 +633,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 +649,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 +680,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 +697,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 +708,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return typeResolver.resolveType(scope, propertyTypeRef);
|
||||
return typeResolver.resolveType(scope, propertyTypeRef, trace, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,11 +757,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 +782,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 +794,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 +827,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 +867,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 +878,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 +892,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 +905,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 +927,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 +947,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 +967,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,10 +978,10 @@ 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)) {
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(typeArgument, substitutedBound)) {
|
||||
trace.report(UPPER_BOUND_VIOLATED.on(argumentTypeReference, substitutedBound));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,11 +20,24 @@ import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.Inject;
|
||||
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.Configuration;
|
||||
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 java.util.Collection;
|
||||
@@ -32,19 +45,35 @@ 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
|
||||
* @author svtk
|
||||
*/
|
||||
public class ImportsResolver {
|
||||
private final TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private Configuration configuration;
|
||||
|
||||
public ImportsResolver(@NotNull TopDownAnalysisContext context) {
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setConfiguration(@NotNull Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
public void processTypeImports() {
|
||||
processImports(true);
|
||||
}
|
||||
@@ -64,7 +93,7 @@ public class ImportsResolver {
|
||||
}
|
||||
Map<JetImportDirective, DeclarationDescriptor> resolvedDirectives = Maps.newHashMap();
|
||||
Collection<JetImportDirective> defaultImportDirectives = Lists.newArrayList();
|
||||
context.getConfiguration().addDefaultImports(namespaceScope, defaultImportDirectives);
|
||||
configuration.addDefaultImports(namespaceScope, defaultImportDirectives);
|
||||
for (JetImportDirective defaultImportDirective : defaultImportDirectives) {
|
||||
defaultImportResolver.processImportReference(defaultImportDirective, namespaceScope, delayedImporter);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,12 +36,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class OverloadResolver {
|
||||
private final TopDownAnalysisContext context;
|
||||
private TopDownAnalysisContext context;
|
||||
|
||||
public OverloadResolver(@NotNull TopDownAnalysisContext context) {
|
||||
|
||||
@Inject
|
||||
public void setContext(TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
public void process() {
|
||||
checkOverloads();
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ 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.google.inject.Inject;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
@@ -43,12 +44,16 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
||||
*/
|
||||
public class OverrideResolver {
|
||||
|
||||
private final TopDownAnalysisContext context;
|
||||
private TopDownAnalysisContext context;
|
||||
|
||||
public OverrideResolver(@NotNull TopDownAnalysisContext context) {
|
||||
|
||||
@Inject
|
||||
public void setContext(TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void process() {
|
||||
generateOverrides();
|
||||
checkOverrides();
|
||||
|
||||
@@ -19,13 +19,27 @@ 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.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
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.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
|
||||
@@ -36,14 +50,10 @@ import java.util.Set;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
/*package*/ class TopDownAnalysisContext {
|
||||
public class TopDownAnalysisContext {
|
||||
|
||||
private final ObservableBindingTrace trace;
|
||||
private final JetSemanticServices semanticServices;
|
||||
private final Configuration configuration;
|
||||
|
||||
private final DescriptorResolver descriptorResolver;
|
||||
private final ImportsResolver importsResolver;
|
||||
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
|
||||
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
|
||||
protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap();
|
||||
@@ -58,17 +68,44 @@ import java.util.Set;
|
||||
private final Predicate<PsiFile> analyzeCompletely;
|
||||
|
||||
private StringBuilder debugOutput;
|
||||
private boolean analyzingBootstrapLibrary = false;
|
||||
private final boolean analyzingBootstrapLibrary;
|
||||
private boolean declaredLocally;
|
||||
|
||||
public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace, Predicate<PsiFile> analyzeCompletely, @NotNull Configuration configuration, boolean declaredLocally) {
|
||||
private final Injector injector;
|
||||
|
||||
public TopDownAnalysisContext(
|
||||
final Project project,
|
||||
final BindingTrace trace,
|
||||
Predicate<PsiFile> analyzeCompletely,
|
||||
@NotNull final Configuration configuration,
|
||||
boolean declaredLocally,
|
||||
boolean analyzingBootstrapLibrary,
|
||||
@Nullable final JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory) {
|
||||
|
||||
if (analyzingBootstrapLibrary == (jetControlFlowDataTraceFactory != null)) {
|
||||
throw new IllegalStateException(
|
||||
"jetControlFlowDataTraceFactory must not be passed when analyzingBootstrapLibrary and vice versa");
|
||||
}
|
||||
|
||||
injector = Guice.createInjector(new TopDownAnalysisModule(project, analyzingBootstrapLibrary) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
bind(TopDownAnalysisContext.class).toInstance(TopDownAnalysisContext.this);
|
||||
bind(Configuration.class).toInstance(configuration);
|
||||
if (jetControlFlowDataTraceFactory != null) {
|
||||
bind(JetControlFlowDataTraceFactory.class).toInstance(jetControlFlowDataTraceFactory);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
|
||||
}
|
||||
|
||||
public Injector getInjector() {
|
||||
return injector;
|
||||
}
|
||||
|
||||
public void debug(Object message) {
|
||||
@@ -93,10 +130,6 @@ import java.util.Set;
|
||||
return analyzingBootstrapLibrary;
|
||||
}
|
||||
|
||||
public void setAnalyzingBootstrapLibrary(boolean analyzingBootstrapLibrary) {
|
||||
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
|
||||
}
|
||||
|
||||
public boolean completeAnalysisNeeded(@NotNull PsiElement element) {
|
||||
PsiFile containingFile = element.getContainingFile();
|
||||
boolean result = containingFile != null && analyzeCompletely.apply(containingFile);
|
||||
@@ -106,22 +139,11 @@ import java.util.Set;
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ObservableBindingTrace getTrace() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
public JetSemanticServices getSemanticServices() {
|
||||
return semanticServices;
|
||||
}
|
||||
|
||||
public DescriptorResolver getDescriptorResolver() {
|
||||
return descriptorResolver;
|
||||
}
|
||||
|
||||
public ImportsResolver getImportsResolver() {
|
||||
return importsResolver;
|
||||
}
|
||||
|
||||
public Map<JetClass, MutableClassDescriptor> getClasses() {
|
||||
return classes;
|
||||
}
|
||||
@@ -158,12 +180,8 @@ import java.util.Set;
|
||||
return functions;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Configuration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public boolean isDeclaredLocally() {
|
||||
return declaredLocally;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public abstract class TopDownAnalysisModule extends AbstractModule {
|
||||
|
||||
@NotNull
|
||||
private final Project project;
|
||||
private final boolean analyzingStdlib;
|
||||
|
||||
protected TopDownAnalysisModule(@NotNull Project project, boolean analyzingStdlib) {
|
||||
this.project = project;
|
||||
this.analyzingStdlib = analyzingStdlib;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void configure() {
|
||||
binder().disableCircularProxies();
|
||||
|
||||
bind(Project.class).toInstance(project);
|
||||
|
||||
if (!analyzingStdlib) {
|
||||
// TODO: move outside
|
||||
JetStandardLibrary.initialize(project);
|
||||
bind(JetStandardLibrary.class).toInstance(JetStandardLibrary.getInstance());
|
||||
}
|
||||
|
||||
configureAfter();
|
||||
}
|
||||
|
||||
protected abstract void configureAfter();
|
||||
}
|
||||
@@ -18,11 +18,12 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
@@ -41,23 +42,59 @@ import java.util.List;
|
||||
*/
|
||||
public class TopDownAnalyzer {
|
||||
|
||||
private TopDownAnalyzer() {}
|
||||
@NotNull
|
||||
private DeclarationResolver declarationResolver;
|
||||
@NotNull
|
||||
private TypeHierarchyResolver typeHierarchyResolver;
|
||||
@NotNull
|
||||
private DelegationResolver delegationResolver;
|
||||
@NotNull
|
||||
private OverrideResolver overrideResolver;
|
||||
@NotNull
|
||||
private OverloadResolver overloadResolver;
|
||||
|
||||
|
||||
@Inject
|
||||
public void setDeclarationResolver(@NotNull DeclarationResolver declarationResolver) {
|
||||
this.declarationResolver = declarationResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setTypeHierarchyResolver(@NotNull TypeHierarchyResolver typeHierarchyResolver) {
|
||||
this.typeHierarchyResolver = typeHierarchyResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDelegationResolver(@NotNull DelegationResolver delegationResolver) {
|
||||
this.delegationResolver = delegationResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setOverrideResolver(@NotNull OverrideResolver overrideResolver) {
|
||||
this.overrideResolver = overrideResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setOverloadResolver(@NotNull OverloadResolver overloadResolver) {
|
||||
this.overloadResolver = overloadResolver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void process(
|
||||
@NotNull JetSemanticServices semanticServices,
|
||||
@NotNull BindingTrace trace,
|
||||
Project project, @NotNull BindingTrace trace,
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull NamespaceLike owner,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Predicate<PsiFile> analyzeCompletely,
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
@NotNull Configuration configuration
|
||||
) {
|
||||
process(semanticServices, trace, outerScope, owner, files, analyzeCompletely, flowDataTraceFactory, configuration, false);
|
||||
) {
|
||||
process(project, trace, outerScope, owner, files, analyzeCompletely, flowDataTraceFactory, configuration, false);
|
||||
}
|
||||
|
||||
private static void process(
|
||||
@NotNull JetSemanticServices semanticServices,
|
||||
@NotNull Project project,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull NamespaceLike owner,
|
||||
@@ -66,29 +103,31 @@ public class TopDownAnalyzer {
|
||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||
@NotNull Configuration configuration,
|
||||
boolean declaredLocally) {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, analyzeCompletely, configuration, declaredLocally);
|
||||
doProcess(context, outerScope, owner, declarations, flowDataTraceFactory);
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(project, trace, analyzeCompletely, configuration, declaredLocally, false, flowDataTraceFactory);
|
||||
context.getInjector().getInstance(TopDownAnalyzer.class).doProcess(context, outerScope, owner, declarations);
|
||||
|
||||
}
|
||||
|
||||
private static void doProcess(
|
||||
private void doProcess(
|
||||
TopDownAnalysisContext context, JetScope outerScope,
|
||||
NamespaceLike owner,
|
||||
Collection<? extends PsiElement> declarations,
|
||||
JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||
Collection<? extends PsiElement> declarations) {
|
||||
// context.enableDebugOutput();
|
||||
context.debug("Enter");
|
||||
|
||||
new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
|
||||
new DeclarationResolver(context).process();
|
||||
new DelegationResolver(context).process();
|
||||
new OverrideResolver(context).process();
|
||||
typeHierarchyResolver.process(outerScope, owner, declarations);
|
||||
declarationResolver.process();
|
||||
delegationResolver.process();
|
||||
overrideResolver.process();
|
||||
|
||||
lockScopes(context);
|
||||
new OverloadResolver(context).process();
|
||||
|
||||
overloadResolver.process();
|
||||
|
||||
if (!context.analyzingBootstrapLibrary()) {
|
||||
new BodyResolver(context).resolveBehaviorDeclarationBodies();
|
||||
new ControlFlowAnalyzer(context, flowDataTraceFactory).process();
|
||||
new DeclarationsChecker(context).process();
|
||||
context.getInjector().getInstance(BodyResolver.class).resolveBehaviorDeclarationBodies();
|
||||
context.getInjector().getInstance(ControlFlowAnalyzer.class).process();
|
||||
context.getInjector().getInstance(DeclarationsChecker.class).process();
|
||||
}
|
||||
|
||||
context.debug("Exit");
|
||||
@@ -109,12 +148,12 @@ public class TopDownAnalyzer {
|
||||
}
|
||||
|
||||
public static void processStandardLibraryNamespace(
|
||||
@NotNull JetSemanticServices semanticServices,
|
||||
@NotNull Project project,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull WritableScope outerScope,
|
||||
@NotNull NamespaceDescriptorImpl standardLibraryNamespace,
|
||||
@NotNull List<JetFile> files) {
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false);
|
||||
TopDownAnalysisContext context = new TopDownAnalysisContext(project, trace, Predicates.<PsiFile>alwaysTrue(), Configuration.EMPTY, false, true, null);
|
||||
ArrayList<JetDeclaration> toAnalyze = new ArrayList<JetDeclaration>();
|
||||
for(JetFile file : files) {
|
||||
context.getNamespaceDescriptors().put(file, standardLibraryNamespace);
|
||||
@@ -122,18 +161,17 @@ public class TopDownAnalyzer {
|
||||
toAnalyze.addAll(file.getDeclarations());
|
||||
}
|
||||
// context.getDeclaringScopes().put(file, outerScope);
|
||||
context.setAnalyzingBootstrapLibrary(true);
|
||||
|
||||
doProcess(context, outerScope, standardLibraryNamespace, toAnalyze, JetControlFlowDataTraceFactory.EMPTY);
|
||||
context.getInjector().getInstance(TopDownAnalyzer.class).doProcess(context, outerScope, standardLibraryNamespace, toAnalyze);
|
||||
}
|
||||
|
||||
public static void processObject(
|
||||
@NotNull JetSemanticServices semanticServices,
|
||||
@NotNull Project project,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope outerScope,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull JetObjectDeclaration object) {
|
||||
process(semanticServices, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) {
|
||||
process(project, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) {
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptorImpl getNamespace(String name) {
|
||||
|
||||
@@ -19,11 +19,12 @@ 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.google.inject.Inject;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -47,18 +48,45 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class TypeHierarchyResolver {
|
||||
private final TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private ImportsResolver importsResolver;
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
@NotNull
|
||||
private Configuration configuration;
|
||||
|
||||
|
||||
// state
|
||||
private LinkedList<MutableClassDescriptor> topologicalOrder;
|
||||
|
||||
|
||||
public TypeHierarchyResolver(TopDownAnalysisContext context) {
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setImportsResolver(@NotNull ImportsResolver importsResolver) {
|
||||
this.importsResolver = importsResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDescriptorResolver(@NotNull DescriptorResolver descriptorResolver) {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setConfiguration(@NotNull Configuration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
|
||||
public void process(@NotNull JetScope outerScope, @NotNull NamespaceLike owner, @NotNull Collection<? extends PsiElement> declarations) {
|
||||
collectNamespacesAndClassifiers(outerScope, outerScope, owner, declarations); // namespaceScopes, classes
|
||||
|
||||
context.getImportsResolver().processTypeImports();
|
||||
importsResolver.processTypeImports();
|
||||
|
||||
createTypeConstructors(); // create type constructors for classes and generic parameters, supertypes are not filled in
|
||||
resolveTypesInClassHeaders(); // Generic bounds and types in supertype lists (no expressions or constructor resolution)
|
||||
@@ -238,7 +266,7 @@ public class TypeHierarchyResolver {
|
||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope");
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
namespaceDescriptor.initialize(scope);
|
||||
context.getConfiguration().extendNamespaceScope(context.getTrace(), namespaceDescriptor, scope);
|
||||
configuration.extendNamespaceScope(context.getTrace(), namespaceDescriptor, scope);
|
||||
owner.addNamespace(namespaceDescriptor);
|
||||
if (file != null) {
|
||||
context.getTrace().record(BindingContext.NAMESPACE, file, namespaceDescriptor);
|
||||
@@ -260,7 +288,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);
|
||||
descriptorResolver.resolveMutableClassDescriptor(jetClass, descriptor, context.getTrace());
|
||||
descriptor.createTypeConstructor();
|
||||
}
|
||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
||||
@@ -277,13 +305,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);
|
||||
descriptorResolver.resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters(), context.getTrace());
|
||||
descriptorResolver.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);
|
||||
descriptorResolver.resolveSupertypes(jetClass, descriptor, context.getTrace());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -478,7 +506,7 @@ public class TypeHierarchyResolver {
|
||||
if (typeReference != null) {
|
||||
JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference);
|
||||
if (type != null) {
|
||||
context.getDescriptorResolver().checkBounds(typeReference, type);
|
||||
descriptorResolver.checkBounds(typeReference, type, context.getTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -488,7 +516,7 @@ public class TypeHierarchyResolver {
|
||||
if (extendsBound != null) {
|
||||
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
||||
if (type != null) {
|
||||
context.getDescriptorResolver().checkBounds(extendsBound, type);
|
||||
descriptorResolver.checkBounds(extendsBound, type, context.getTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,7 +526,7 @@ public class TypeHierarchyResolver {
|
||||
if (extendsBound != null) {
|
||||
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
||||
if (type != null) {
|
||||
context.getDescriptorResolver().checkBounds(extendsBound, type);
|
||||
descriptorResolver.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,10 +19,10 @@ 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;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
@@ -33,6 +33,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,22 +57,47 @@ 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 OverloadingConflictResolver overloadingConflictResolver;
|
||||
private final DataFlowInfo dataFlowInfo;
|
||||
private final JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||
|
||||
public CallResolver(JetSemanticServices semanticServices, DataFlowInfo dataFlowInfo) {
|
||||
this.semanticServices = semanticServices;
|
||||
this.overloadingConflictResolver = new OverloadingConflictResolver(semanticServices);
|
||||
this.dataFlowInfo = dataFlowInfo;
|
||||
@NotNull
|
||||
private OverloadingConflictResolver overloadingConflictResolver;
|
||||
@NotNull
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
@NotNull
|
||||
private TypeResolver typeResolver;
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
|
||||
|
||||
@Inject
|
||||
public void setOverloadingConflictResolver(@NotNull OverloadingConflictResolver overloadingConflictResolver) {
|
||||
this.overloadingConflictResolver = overloadingConflictResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setExpressionTypingServices(@NotNull ExpressionTypingServices expressionTypingServices) {
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setTypeResolver(@NotNull TypeResolver typeResolver) {
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDescriptorResolver(@NotNull DescriptorResolver descriptorResolver) {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull Call call,
|
||||
@NotNull JetType expectedType) {
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo) {
|
||||
JetExpression calleeExpression = call.getCalleeExpression();
|
||||
assert calleeExpression instanceof JetSimpleNameExpression;
|
||||
JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) calleeExpression;
|
||||
@@ -88,7 +114,7 @@ public class CallResolver {
|
||||
task_prioritizer = TaskPrioritizers.VARIABLE_TASK_PRIORITIZER;
|
||||
}
|
||||
List<ResolutionTask<VariableDescriptor>> prioritizedTasks = task_prioritizer.computePrioritizedTasks(scope, call, referencedName, trace.getBindingContext(), dataFlowInfo);
|
||||
return resolveCallToDescriptor(trace, scope, call, expectedType, prioritizedTasks, nameExpression);
|
||||
return resolveCallToDescriptor(trace, scope, call, expectedType, prioritizedTasks, nameExpression, dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -96,9 +122,9 @@ public class CallResolver {
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull Call call,
|
||||
@NotNull JetType expectedType
|
||||
) {
|
||||
return resolveSimpleCallToFunctionDescriptor(trace, scope, call, expectedType);
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo) {
|
||||
return resolveSimpleCallToFunctionDescriptor(trace, scope, call, expectedType, dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -108,10 +134,10 @@ public class CallResolver {
|
||||
@NotNull final Call call,
|
||||
@NotNull final JetReferenceExpression functionReference,
|
||||
@NotNull String name,
|
||||
@NotNull JetType expectedType) {
|
||||
@NotNull JetType expectedType, DataFlowInfo dataFlowInfo) {
|
||||
List<ResolutionTask<FunctionDescriptor>> tasks = TaskPrioritizers.FUNCTION_TASK_PRIORITIZER.computePrioritizedTasks(
|
||||
scope, call, name, trace.getBindingContext(), dataFlowInfo);
|
||||
return doResolveCall(trace, scope, call, expectedType, tasks, functionReference);
|
||||
return doResolveCall(trace, scope, call, expectedType, tasks, functionReference, dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -119,8 +145,8 @@ public class CallResolver {
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
@NotNull final Call call,
|
||||
@NotNull JetType expectedType
|
||||
) {
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull DataFlowInfo dataFlowInfo) {
|
||||
List<ResolutionTask<FunctionDescriptor>> prioritizedTasks;
|
||||
|
||||
JetExpression calleeExpression = call.getCalleeExpression();
|
||||
@@ -165,7 +191,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 +225,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 = 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);
|
||||
@@ -228,7 +253,7 @@ public class CallResolver {
|
||||
}
|
||||
}
|
||||
|
||||
return resolveCallToDescriptor(trace, scope, call, expectedType, prioritizedTasks, functionReference);
|
||||
return resolveCallToDescriptor(trace, scope, call, expectedType, prioritizedTasks, functionReference, dataFlowInfo);
|
||||
}
|
||||
|
||||
private <D extends CallableDescriptor> OverloadResolutionResults<D> checkArgumentTypesAndFail(BindingTrace trace, JetScope scope, Call call) {
|
||||
@@ -243,8 +268,9 @@ public class CallResolver {
|
||||
@NotNull final Call call,
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull final List<ResolutionTask<D>> prioritizedTasks, // high to low priority
|
||||
@NotNull final JetReferenceExpression reference) {
|
||||
return doResolveCall(trace, scope, call, expectedType, prioritizedTasks, reference);
|
||||
@NotNull final JetReferenceExpression reference,
|
||||
@NotNull DataFlowInfo dataFlowInfo) {
|
||||
return doResolveCall(trace, scope, call, expectedType, prioritizedTasks, reference, dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -254,7 +280,8 @@ public class CallResolver {
|
||||
@NotNull final Call call,
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull final List<ResolutionTask<D>> prioritizedTasks, // high to low priority
|
||||
@NotNull final JetReferenceExpression reference) {
|
||||
@NotNull final JetReferenceExpression reference,
|
||||
@NotNull DataFlowInfo dataFlowInfo) {
|
||||
|
||||
ResolutionDebugInfo.Data debugInfo = ResolutionDebugInfo.create();
|
||||
trace.record(ResolutionDebugInfo.RESOLUTION_DEBUG_INFO, call.getCallElement(), debugInfo);
|
||||
@@ -402,7 +429,7 @@ public class CallResolver {
|
||||
OverloadResolutionResultsImpl<D> resultsForFirstNonemptyCandidateSet = null;
|
||||
for (ResolutionTask<D> task : prioritizedTasks) {
|
||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(trace);
|
||||
OverloadResolutionResultsImpl<D> results = performResolutionGuardedForExtraFunctionLiteralArguments(temporaryTrace, scope, expectedType, task, tracing);
|
||||
OverloadResolutionResultsImpl<D> results = performResolutionGuardedForExtraFunctionLiteralArguments(temporaryTrace, scope, expectedType, task, tracing, dataFlowInfo);
|
||||
if (results.isSuccess()) {
|
||||
temporaryTrace.commit();
|
||||
|
||||
@@ -435,9 +462,9 @@ public class CallResolver {
|
||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolutionGuardedForExtraFunctionLiteralArguments(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope, @NotNull JetType expectedType,
|
||||
@NotNull ResolutionTask<D> task, @NotNull TracingStrategy tracing
|
||||
@NotNull ResolutionTask<D> task, @NotNull TracingStrategy tracing, @NotNull DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
OverloadResolutionResultsImpl<D> results = performResolution(trace, scope, expectedType, task, tracing);
|
||||
OverloadResolutionResultsImpl<D> results = performResolution(trace, scope, expectedType, task, tracing, dataFlowInfo);
|
||||
|
||||
// If resolution fails, we should check for some of the following situations:
|
||||
// class A {
|
||||
@@ -471,7 +498,7 @@ public class CallResolver {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}, task.getDataFlowInfo());
|
||||
OverloadResolutionResultsImpl<D> resultsWithFunctionLiteralsStripped = performResolution(TemporaryBindingTrace.create(trace), scope, expectedType, newTask, tracing);
|
||||
OverloadResolutionResultsImpl<D> resultsWithFunctionLiteralsStripped = performResolution(TemporaryBindingTrace.create(trace), scope, expectedType, newTask, tracing, dataFlowInfo);
|
||||
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
|
||||
tracing.danglingFunctionLiteralArgumentSuspected(trace, task.getCall().getFunctionLiteralArguments());
|
||||
}
|
||||
@@ -484,7 +511,7 @@ public class CallResolver {
|
||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolution(
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope, @NotNull JetType expectedType,
|
||||
@NotNull ResolutionTask<D> task, @NotNull TracingStrategy tracing
|
||||
@NotNull ResolutionTask<D> task, @NotNull TracingStrategy tracing, DataFlowInfo dataFlowInfo
|
||||
) {
|
||||
for (ResolvedCallImpl<D> candidateCall : task.getCandidates()) {
|
||||
D candidate = candidateCall.getCandidateDescriptor();
|
||||
@@ -544,8 +571,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 = expressionTypingServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT), traceForUnknown);
|
||||
if (type != null && !ErrorUtils.isErrorType(type)) {
|
||||
constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType));
|
||||
}
|
||||
@@ -581,17 +607,17 @@ public class CallResolver {
|
||||
}
|
||||
|
||||
// Here we type check the arguments with inferred types expected
|
||||
checkValueArgumentTypes(scope, candidateCall);
|
||||
checkValueArgumentTypes(scope, candidateCall, dataFlowInfo);
|
||||
|
||||
candidateCall.setStatus(SUCCESS);
|
||||
}
|
||||
else {
|
||||
tracing.typeInferenceFailed(temporaryTrace, solution.getStatus());
|
||||
candidateCall.setStatus(OTHER_ERROR.combine(checkAllValueArguments(scope, tracing, task, candidateCall)));
|
||||
candidateCall.setStatus(OTHER_ERROR.combine(checkAllValueArguments(scope, tracing, task, candidateCall, dataFlowInfo)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall));
|
||||
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall, dataFlowInfo));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -604,7 +630,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, temporaryTrace, true));
|
||||
}
|
||||
}
|
||||
int expectedTypeArgumentCount = candidate.getTypeParameters().size();
|
||||
@@ -623,7 +649,7 @@ public class CallResolver {
|
||||
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
|
||||
candidateCall.recordTypeArgument(typeParameterDescriptor, typeArguments.get(i));
|
||||
}
|
||||
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall));
|
||||
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall, dataFlowInfo));
|
||||
}
|
||||
else {
|
||||
candidateCall.setStatus(OTHER_ERROR);
|
||||
@@ -693,20 +719,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);
|
||||
expressionTypingServices.getType(scope, argumentExpression, NO_EXPECTED_TYPE, trace);
|
||||
}
|
||||
}
|
||||
|
||||
for (JetExpression expression : call.getFunctionLiteralArguments()) {
|
||||
typeInferrerServices.getType(scope, expression, NO_EXPECTED_TYPE);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -728,8 +753,8 @@ public class CallResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private <D extends CallableDescriptor> ResolutionStatus checkAllValueArguments(JetScope scope, TracingStrategy tracing, ResolutionTask<D> task, ResolvedCallImpl<D> candidateCall) {
|
||||
ResolutionStatus result = checkValueArgumentTypes(scope, candidateCall);
|
||||
private <D extends CallableDescriptor> ResolutionStatus checkAllValueArguments(JetScope scope, TracingStrategy tracing, ResolutionTask<D> task, ResolvedCallImpl<D> candidateCall, DataFlowInfo dataFlowInfo) {
|
||||
ResolutionStatus result = checkValueArgumentTypes(scope, candidateCall, dataFlowInfo);
|
||||
result = result.combine(checkReceiver(tracing, candidateCall, candidateCall.getResultingDescriptor().getReceiverParameter(), candidateCall.getReceiverArgument(), task));
|
||||
result = result.combine(checkReceiver(tracing, candidateCall, candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(), task));
|
||||
return result;
|
||||
@@ -752,7 +777,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;
|
||||
}
|
||||
@@ -765,7 +790,7 @@ public class CallResolver {
|
||||
return result;
|
||||
}
|
||||
|
||||
private <D extends CallableDescriptor> ResolutionStatus checkValueArgumentTypes(JetScope scope, ResolvedCallImpl<D> candidateCall) {
|
||||
private <D extends CallableDescriptor> ResolutionStatus checkValueArgumentTypes(JetScope scope, ResolvedCallImpl<D> candidateCall, DataFlowInfo dataFlowInfo) {
|
||||
ResolutionStatus result = SUCCESS;
|
||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : candidateCall.getValueArguments().entrySet()) {
|
||||
ValueParameterDescriptor parameterDescriptor = entry.getKey();
|
||||
@@ -775,12 +800,11 @@ 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);
|
||||
JetType type = expressionTypingServices.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 +959,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);
|
||||
descriptorResolver.checkBounds(typeReference, typeArgument, typeParameterDescriptor, substitutor, trace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1003,7 +1027,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;
|
||||
|
||||
+4
-9
@@ -20,16 +20,17 @@ import gnu.trove.THashSet;
|
||||
import gnu.trove.TObjectHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
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;
|
||||
|
||||
@@ -38,12 +39,6 @@ import java.util.Set;
|
||||
*/
|
||||
public class OverloadingConflictResolver {
|
||||
|
||||
private final JetSemanticServices semanticServices;
|
||||
|
||||
public OverloadingConflictResolver(@NotNull JetSemanticServices semanticServices) {
|
||||
this.semanticServices = semanticServices;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <D extends CallableDescriptor> ResolvedCallImpl<D> findMaximallySpecific(Set<ResolvedCallImpl<D>> candidates, boolean discriminateGenericDescriptors) {
|
||||
// Different autocasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects
|
||||
@@ -128,12 +123,12 @@ public class OverloadingConflictResolver {
|
||||
}
|
||||
|
||||
private boolean typeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
|
||||
return semanticServices.getTypeChecker().isSubtypeOf(specific, general) ||
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(specific, general) ||
|
||||
numericTypeMoreSpecific(specific, general);
|
||||
}
|
||||
|
||||
private boolean numericTypeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
|
||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||
JetType _double = standardLibrary.getDoubleType();
|
||||
JetType _float = standardLibrary.getFloatType();
|
||||
JetType _long = standardLibrary.getLongType();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+11
-14
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.constants;
|
||||
import com.google.common.base.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.JetEscapeStringTemplateEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetLiteralStringTemplateEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetStringTemplateEntry;
|
||||
@@ -38,17 +37,16 @@ import java.util.List;
|
||||
public class CompileTimeConstantResolver {
|
||||
public static final ErrorValue OUT_OF_RANGE = new ErrorValue("The value is out of range");
|
||||
|
||||
private final JetSemanticServices semanticServices;
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final BindingTrace trace;
|
||||
|
||||
public CompileTimeConstantResolver(@NotNull JetSemanticServices semanticServices, @NotNull BindingTrace trace) {
|
||||
this.semanticServices = semanticServices;
|
||||
public CompileTimeConstantResolver(@NotNull BindingTrace trace) {
|
||||
this.standardLibrary = JetStandardLibrary.getInstance();
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getIntegerValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
||||
if (noExpectedType(expectedType)) {
|
||||
Long value = parseLongValue(text);
|
||||
if (value == null) {
|
||||
@@ -85,7 +83,7 @@ public class CompileTimeConstantResolver {
|
||||
upperBound = Byte.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
JetTypeChecker typeChecker = semanticServices.getTypeChecker();
|
||||
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||
JetType intType = standardLibrary.getIntType();
|
||||
JetType longType = standardLibrary.getLongType();
|
||||
if (typeChecker.isSubtypeOf(intType, expectedType)) {
|
||||
@@ -130,9 +128,8 @@ public class CompileTimeConstantResolver {
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getFloatValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
||||
if (noExpectedType(expectedType)
|
||||
|| semanticServices.getTypeChecker().isSubtypeOf(standardLibrary.getDoubleType(), expectedType)) {
|
||||
|| JetTypeChecker.INSTANCE.isSubtypeOf(standardLibrary.getDoubleType(), expectedType)) {
|
||||
try {
|
||||
return new DoubleValue(Double.parseDouble(text));
|
||||
}
|
||||
@@ -140,7 +137,7 @@ public class CompileTimeConstantResolver {
|
||||
return OUT_OF_RANGE;
|
||||
}
|
||||
}
|
||||
else if (semanticServices.getTypeChecker().isSubtypeOf(standardLibrary.getFloatType(), expectedType)) {
|
||||
else if (JetTypeChecker.INSTANCE.isSubtypeOf(standardLibrary.getFloatType(), expectedType)) {
|
||||
try {
|
||||
return new DoubleValue(Float.parseFloat(text));
|
||||
}
|
||||
@@ -156,7 +153,7 @@ public class CompileTimeConstantResolver {
|
||||
@Nullable
|
||||
private CompileTimeConstant<?> checkNativeType(String text, JetType expectedType, String title, JetType nativeType) {
|
||||
if (!noExpectedType(expectedType)
|
||||
&& !semanticServices.getTypeChecker().isSubtypeOf(nativeType, expectedType)) {
|
||||
&& !JetTypeChecker.INSTANCE.isSubtypeOf(nativeType, expectedType)) {
|
||||
return new ErrorValue("A " + title + " literal " + text + " does not conform to the expected type " + expectedType);
|
||||
}
|
||||
return null;
|
||||
@@ -164,7 +161,7 @@ public class CompileTimeConstantResolver {
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getBooleanValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||
CompileTimeConstant<?> error = checkNativeType(text, expectedType, "boolean", semanticServices.getStandardLibrary().getBooleanType());
|
||||
CompileTimeConstant<?> error = checkNativeType(text, expectedType, "boolean", standardLibrary.getBooleanType());
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
@@ -179,7 +176,7 @@ public class CompileTimeConstantResolver {
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getCharValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||
CompileTimeConstant<?> error = checkNativeType(text, expectedType, "character", semanticServices.getStandardLibrary().getCharType());
|
||||
CompileTimeConstant<?> error = checkNativeType(text, expectedType, "character", standardLibrary.getCharType());
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
@@ -265,7 +262,7 @@ public class CompileTimeConstantResolver {
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getRawStringValue(@NotNull String unescapedText, @NotNull JetType expectedType) {
|
||||
CompileTimeConstant<?> error = checkNativeType("\"\"\"...\"\"\"", expectedType, "string", semanticServices.getStandardLibrary().getStringType());
|
||||
CompileTimeConstant<?> error = checkNativeType("\"\"\"...\"\"\"", expectedType, "string", standardLibrary.getStringType());
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
@@ -275,7 +272,7 @@ public class CompileTimeConstantResolver {
|
||||
|
||||
@NotNull
|
||||
public CompileTimeConstant<?> getEscapedStringValue(@NotNull List<JetStringTemplateEntry> entries, @NotNull JetType expectedType) {
|
||||
CompileTimeConstant<?> error = checkNativeType("\"...\"", expectedType, "string", semanticServices.getStandardLibrary().getStringType());
|
||||
CompileTimeConstant<?> error = checkNativeType("\"...\"", expectedType, "string", standardLibrary.getStringType());
|
||||
if (error != null) {
|
||||
return error;
|
||||
}
|
||||
|
||||
+23
-21
@@ -147,7 +147,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
ASTNode node = expression.getNode();
|
||||
IElementType elementType = node.getElementType();
|
||||
String text = node.getText();
|
||||
JetStandardLibrary standardLibrary = context.semanticServices.getStandardLibrary();
|
||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
||||
|
||||
CompileTimeConstant<?> value;
|
||||
@@ -172,7 +172,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (value instanceof ErrorValue) {
|
||||
ErrorValue errorValue = (ErrorValue) value;
|
||||
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(node.getPsi(), errorValue.getMessage()));
|
||||
return getDefaultType(context.semanticServices, elementType);
|
||||
return getDefaultType(elementType);
|
||||
}
|
||||
else {
|
||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, value);
|
||||
@@ -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.expressionTypingServices.getTypeResolver().resolveType(context.scope, right, context.trace, true);
|
||||
|
||||
if (isTypeFlexible(expression.getLeft())) {
|
||||
TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(context.trace);
|
||||
@@ -223,7 +223,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||
if (operationType == JetTokens.COLON) {
|
||||
if (targetType != NO_EXPECTED_TYPE && !context.semanticServices.getTypeChecker().isSubtypeOf(actualType, targetType)) {
|
||||
if (targetType != NO_EXPECTED_TYPE && !JetTypeChecker.INSTANCE.isSubtypeOf(actualType, targetType)) {
|
||||
context.trace.report(TYPE_MISMATCH.on(expression.getLeft(), targetType, actualType));
|
||||
return false;
|
||||
}
|
||||
@@ -242,7 +242,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
private void checkForCastImpossibility(JetBinaryExpressionWithTypeRHS expression, JetType actualType, JetType targetType, ExpressionTypingContext context) {
|
||||
if (actualType == null || targetType == NO_EXPECTED_TYPE) return;
|
||||
|
||||
JetTypeChecker typeChecker = context.semanticServices.getTypeChecker();
|
||||
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||
if (!typeChecker.isSubtypeOf(targetType, actualType)) {
|
||||
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
||||
context.trace.report(USELESS_CAST_STATIC_ASSERT_IS_FINE.on(expression.getOperationSign()));
|
||||
@@ -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.expressionTypingServices.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.expressionTypingServices.getTypeResolver().resolveClass(context.scope, userType, context.trace);
|
||||
}
|
||||
else {
|
||||
supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier);
|
||||
supertype = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
||||
redundantTypeArguments = userType.getTypeArgumentList();
|
||||
}
|
||||
}
|
||||
else {
|
||||
supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier);
|
||||
supertype = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
||||
}
|
||||
|
||||
if (supertype != null) {
|
||||
@@ -505,7 +505,9 @@ 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.expressionTypingServices.getBlockReturnedType(context.scope, expression, isStatement
|
||||
? CoercionStrategy.COERCION_TO_UNIT
|
||||
: CoercionStrategy.NO_COERCION, context, context.trace);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -544,9 +546,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
JetType result;
|
||||
if (expression.getOperationSign() == JetTokens.QUEST) {
|
||||
if (selectorReturnType != null && !isBoolean(context.semanticServices, selectorReturnType)) {
|
||||
if (selectorReturnType != null && !isBoolean(selectorReturnType)) {
|
||||
// TODO : more comprehensible error message
|
||||
context.trace.report(TYPE_MISMATCH.on(selectorExpression, context.semanticServices.getStandardLibrary().getBooleanType(), selectorReturnType));
|
||||
context.trace.report(TYPE_MISMATCH.on(selectorExpression, JetStandardLibrary.getInstance().getBooleanType(), selectorReturnType));
|
||||
}
|
||||
result = TypeUtils.makeNullable(receiverType);
|
||||
}
|
||||
@@ -566,7 +568,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
CompileTimeConstant<?> wholeExpressionValue = context.trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression);
|
||||
DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.REFERENCE_TARGET, selectorExpression);
|
||||
if (wholeExpressionValue == null && receiverValue != null && !(receiverValue instanceof ErrorValue) && receiverValue.getValue() instanceof Number
|
||||
&& context.semanticServices.getStandardLibrary().getNumber() == declarationDescriptor) {
|
||||
&& JetStandardLibrary.getInstance().getNumber() == declarationDescriptor) {
|
||||
Number value = (Number) receiverValue.getValue();
|
||||
String referencedName = selectorExpression.getReferencedName();
|
||||
if (OperatorConventions.NUMBER_CONVERSIONS.contains(referencedName)) {
|
||||
@@ -707,13 +709,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType returnType = functionDescriptor.getResultingDescriptor().getReturnType();
|
||||
JetType result;
|
||||
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
||||
if (context.semanticServices.getTypeChecker().isSubtypeOf(returnType, JetStandardClasses.getUnitType())) {
|
||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, JetStandardClasses.getUnitType())) {
|
||||
result = JetStandardClasses.getUnitType();
|
||||
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
|
||||
}
|
||||
else {
|
||||
JetType receiverType = receiver.getType();
|
||||
if (!context.semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(returnType, receiverType)) {
|
||||
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, name, receiverType, returnType));
|
||||
}
|
||||
else {
|
||||
@@ -785,7 +787,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType compareToReturnType = getTypeForBinaryCall(context.scope, "compareTo", context, expression);
|
||||
if (compareToReturnType != null) {
|
||||
TypeConstructor constructor = compareToReturnType.getConstructor();
|
||||
JetStandardLibrary standardLibrary = context.semanticServices.getStandardLibrary();
|
||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||
TypeConstructor intTypeConstructor = standardLibrary.getInt().getTypeConstructor();
|
||||
if (constructor.equals(intTypeConstructor)) {
|
||||
result = standardLibrary.getBooleanType();
|
||||
@@ -795,7 +797,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
else {
|
||||
JetType booleanType = context.semanticServices.getStandardLibrary().getBooleanType();
|
||||
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
|
||||
if (OperatorConventions.EQUALS_OPERATIONS.contains(operationType)) {
|
||||
String name = "equals";
|
||||
if (right != null) {
|
||||
@@ -841,10 +843,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
DataFlowInfo flowInfoLeft = DataFlowUtils.extractDataFlowInfoFromCondition(left, operationType == JetTokens.ANDAND, leftScope, context); // TODO: This gets computed twice: here and in extractDataFlowInfoFromCondition() for the whole condition
|
||||
WritableScopeImpl rightScope = operationType == JetTokens.ANDAND ? leftScope : newWritableScopeImpl(context).setDebugName("Right scope of && or ||");
|
||||
JetType rightType = right == null ? null : facade.getType(right, context.replaceDataFlowInfo(flowInfoLeft).replaceScope(rightScope));
|
||||
if (leftType != null && !isBoolean(context.semanticServices, leftType)) {
|
||||
if (leftType != null && !isBoolean(leftType)) {
|
||||
context.trace.report(TYPE_MISMATCH.on(left, booleanType, leftType));
|
||||
}
|
||||
if (rightType != null && !isBoolean(context.semanticServices, rightType)) {
|
||||
if (rightType != null && !isBoolean(rightType)) {
|
||||
context.trace.report(TYPE_MISMATCH.on(right, booleanType, rightType));
|
||||
}
|
||||
result = booleanType;
|
||||
@@ -892,7 +894,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType rightType = facade.getType(right, context.replaceScope(context.scope));
|
||||
|
||||
if (rightType != null) {
|
||||
JetType intersect = TypeUtils.intersect(context.semanticServices.getTypeChecker(), new HashSet<JetType>(Arrays.asList(leftType, rightType)));
|
||||
JetType intersect = TypeUtils.intersect(JetTypeChecker.INSTANCE, new HashSet<JetType>(Arrays.asList(leftType, rightType)));
|
||||
if (intersect == null) {
|
||||
context.trace.report(EQUALITY_NOT_APPLICABLE.on(expression, operationSign, leftType, rightType));
|
||||
}
|
||||
@@ -993,7 +995,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (value[0] != CompileTimeConstantResolver.OUT_OF_RANGE) {
|
||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, new StringValue(builder.toString()));
|
||||
}
|
||||
return DataFlowUtils.checkType(context.semanticServices.getStandardLibrary().getStringType(), expression, contextWithExpectedType);
|
||||
return DataFlowUtils.checkType(JetStandardLibrary.getInstance().getStringType(), expression, contextWithExpectedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-9
@@ -72,7 +72,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
};
|
||||
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(context.trace);
|
||||
traceAdapter.addHandler(CLASS, handler);
|
||||
TopDownAnalyzer.processObject(context.semanticServices, traceAdapter, context.scope, context.scope.getContainingDeclaration(), expression.getObjectDeclaration());
|
||||
TopDownAnalyzer.processObject(context.expressionTypingServices.getProject(), traceAdapter, context.scope, context.scope.getContainingDeclaration(), expression.getObjectDeclaration());
|
||||
return DataFlowUtils.checkType(result[0], expression, context);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
context.getServices().checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
|
||||
replaceExpectedType(returnType).replaceExpectedReturnType(returnType).replaceDataFlowInfo(context.dataFlowInfo));
|
||||
returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true);
|
||||
context.expressionTypingServices.checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
|
||||
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));
|
||||
returnType = context.expressionTypingServices.getBlockReturnedType(functionInnerScope, bodyExpression, CoercionStrategy.COERCION_TO_UNIT,
|
||||
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.expressionTypingServices.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.expressionTypingServices.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.expressionTypingServices.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type, context.trace);
|
||||
valueParameterDescriptors.add(valueParameterDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-18
@@ -39,7 +39,9 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -63,7 +65,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (condition != null) {
|
||||
JetType conditionType = facade.getType(condition, context.replaceScope(scope));
|
||||
|
||||
if (conditionType != null && !isBoolean(context.semanticServices, conditionType)) {
|
||||
if (conditionType != null && !isBoolean(conditionType)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(condition, conditionType));
|
||||
}
|
||||
}
|
||||
@@ -92,7 +94,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.expressionTypingServices.getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(thenInfo), context.trace);
|
||||
if (type != null && JetStandardClasses.isNothing(type)) {
|
||||
facade.setResultingDataFlowInfo(elseInfo);
|
||||
}
|
||||
@@ -101,15 +103,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.expressionTypingServices.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.expressionTypingServices.getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(thenInfo), context.trace);
|
||||
JetType elseType = context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(elseInfo), context.trace);
|
||||
|
||||
JetType result;
|
||||
if (thenType == null) {
|
||||
@@ -150,7 +152,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.expressionTypingServices.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 +199,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.expressionTypingServices.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 +215,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
else {
|
||||
block = Collections.<JetElement>singletonList(body);
|
||||
}
|
||||
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context);
|
||||
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context, context.trace);
|
||||
}
|
||||
JetExpression condition = expression.getCondition();
|
||||
checkCondition(conditionScope, condition, context);
|
||||
@@ -248,11 +250,11 @@ 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.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter, context.trace);
|
||||
JetType actualParameterType = variableDescriptor.getType();
|
||||
if (expectedParameterType != null &&
|
||||
actualParameterType != null &&
|
||||
!context.semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
|
||||
!JetTypeChecker.INSTANCE.isSubtypeOf(expectedParameterType, actualParameterType)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_FOR_LOOP.on(typeReference, expectedParameterType, actualParameterType));
|
||||
}
|
||||
}
|
||||
@@ -260,7 +262,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (expectedParameterType == null) {
|
||||
expectedParameterType = ErrorUtils.createErrorType("Error");
|
||||
}
|
||||
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
||||
variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType, context.trace);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -277,7 +279,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.expressionTypingServices.getBlockReturnedTypeWithWritableScope(loopScope, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context, context.trace);
|
||||
}
|
||||
|
||||
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType);
|
||||
@@ -350,7 +352,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
public static OverloadResolutionResults<FunctionDescriptor> resolveFakeCall(ExpressionReceiver receiver,
|
||||
ExpressionTypingContext context, String name) {
|
||||
JetReferenceExpression fake = JetPsiFactory.createSimpleName(context.getProject(), "fake");
|
||||
JetReferenceExpression fake = JetPsiFactory.createSimpleName(context.expressionTypingServices.getProject(), "fake");
|
||||
BindingTrace fakeTrace = new BindingTraceContext();
|
||||
Call call = CallMaker.makeCall(fake, receiver, null, fake, Collections.<ValueArgument>emptyList());
|
||||
return context.replaceBindingTrace(fakeTrace).resolveCallWithGivenName(call, fake, name);
|
||||
@@ -366,7 +368,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
} else {
|
||||
assert hasNextResolutionResults.isSuccess();
|
||||
JetType hasNextReturnType = hasNextResolutionResults.getResultingDescriptor().getReturnType();
|
||||
if (!isBoolean(context.semanticServices, hasNextReturnType)) {
|
||||
if (!isBoolean(hasNextReturnType)) {
|
||||
context.trace.report(HAS_NEXT_FUNCTION_TYPE_MISMATCH.on(loopRange, hasNextReturnType));
|
||||
}
|
||||
}
|
||||
@@ -384,7 +386,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
// TODO : accessibility
|
||||
context.trace.report(HAS_NEXT_MUST_BE_READABLE.on(loopRange));
|
||||
}
|
||||
else if (!isBoolean(context.semanticServices, hasNextReturnType)) {
|
||||
else if (!isBoolean(hasNextReturnType)) {
|
||||
context.trace.report(HAS_NEXT_PROPERTY_TYPE_MISMATCH.on(loopRange, hasNextReturnType));
|
||||
}
|
||||
}
|
||||
@@ -401,8 +403,8 @@ 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);
|
||||
JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType();
|
||||
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace);
|
||||
JetType throwableType = JetStandardLibrary.getInstance().getThrowable().getDefaultType();
|
||||
DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
|
||||
if (catchBody != null) {
|
||||
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope");
|
||||
@@ -437,7 +439,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
public JetType visitThrowExpression(JetThrowExpression expression, ExpressionTypingContext context) {
|
||||
JetExpression thrownExpression = expression.getThrownExpression();
|
||||
if (thrownExpression != null) {
|
||||
JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType();
|
||||
JetType throwableType = JetStandardLibrary.getInstance().getThrowable().getDefaultType();
|
||||
facade.getType(thrownExpression, context.replaceExpectedType(throwableType).replaceScope(context.scope));
|
||||
}
|
||||
return DataFlowUtils.checkType(JetStandardClasses.getNothingType(), expression, context);
|
||||
|
||||
@@ -154,7 +154,7 @@ public class DataFlowUtils {
|
||||
@Nullable
|
||||
public static JetType checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context) {
|
||||
if (expressionType == null || context.expectedType == null || context.expectedType == TypeUtils.NO_EXPECTED_TYPE ||
|
||||
context.semanticServices.getTypeChecker().isSubtypeOf(expressionType, context.expectedType)) {
|
||||
JetTypeChecker.INSTANCE.isSubtypeOf(expressionType, context.expectedType)) {
|
||||
return expressionType;
|
||||
}
|
||||
|
||||
|
||||
+18
-62
@@ -17,18 +17,13 @@
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.TypeResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
||||
@@ -43,11 +38,11 @@ import java.util.Map;
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
/*package*/ class ExpressionTypingContext {
|
||||
public class ExpressionTypingContext {
|
||||
|
||||
@NotNull
|
||||
public static ExpressionTypingContext newContext(
|
||||
@NotNull Project project,
|
||||
@NotNull JetSemanticServices semanticServices,
|
||||
@NotNull ExpressionTypingServices expressionTypingServices,
|
||||
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
||||
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
||||
@NotNull LabelResolver labelResolver,
|
||||
@@ -57,7 +52,7 @@ import java.util.Map;
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull JetType expectedReturnType,
|
||||
boolean namespacesAllowed) {
|
||||
return new ExpressionTypingContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
|
||||
return new ExpressionTypingContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
|
||||
labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||
}
|
||||
|
||||
@@ -72,8 +67,7 @@ import java.util.Map;
|
||||
// return newContext(semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(), trace, scope, dataFlowInfo, expectedType, expectedReturnType);
|
||||
// }
|
||||
//
|
||||
public final Project project;
|
||||
public final JetSemanticServices semanticServices;
|
||||
public final ExpressionTypingServices expressionTypingServices;
|
||||
public final BindingTrace trace;
|
||||
public final JetScope scope;
|
||||
|
||||
@@ -88,15 +82,10 @@ import java.util.Map;
|
||||
// true for positions on the lhs of a '.', i.e. allows namespace results and 'super'
|
||||
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 JetSemanticServices semanticServices,
|
||||
@NotNull ExpressionTypingServices expressionTypingServices,
|
||||
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
||||
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
||||
@NotNull LabelResolver labelResolver,
|
||||
@@ -106,13 +95,12 @@ import java.util.Map;
|
||||
@NotNull JetType expectedType,
|
||||
@NotNull JetType expectedReturnType,
|
||||
boolean namespacesAllowed) {
|
||||
this.project = project;
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
this.trace = trace;
|
||||
this.patternsToBoundVariableLists = patternsToBoundVariableLists;
|
||||
this.patternsToDataFlowInfo = patternsToDataFlowInfo;
|
||||
this.labelResolver = labelResolver;
|
||||
this.scope = scope;
|
||||
this.semanticServices = semanticServices;
|
||||
this.dataFlowInfo = dataFlowInfo;
|
||||
this.expectedType = expectedType;
|
||||
this.expectedReturnType = expectedReturnType;
|
||||
@@ -122,71 +110,43 @@ 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(expressionTypingServices, 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(expressionTypingServices, 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(expressionTypingServices, 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(expressionTypingServices, 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(expressionTypingServices, 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(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||
}
|
||||
|
||||
///////////// LAZY ACCESSORS
|
||||
|
||||
public CallResolver getCallResolver() {
|
||||
if (callResolver == null) {
|
||||
callResolver = new CallResolver(semanticServices, dataFlowInfo);
|
||||
}
|
||||
return callResolver;
|
||||
}
|
||||
|
||||
public ExpressionTypingServices getServices() {
|
||||
if (services == null) {
|
||||
services = new ExpressionTypingServices(semanticServices, trace);
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
public TypeResolver getTypeResolver() {
|
||||
if (typeResolver == null) {
|
||||
typeResolver = new TypeResolver(semanticServices, trace, true);
|
||||
}
|
||||
return typeResolver;
|
||||
}
|
||||
|
||||
public DescriptorResolver getDescriptorResolver() {
|
||||
if (descriptorResolver == null) {
|
||||
descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
||||
}
|
||||
return descriptorResolver;
|
||||
}
|
||||
|
||||
public CompileTimeConstantResolver getCompileTimeConstantResolver() {
|
||||
if (compileTimeConstantResolver == null) {
|
||||
compileTimeConstantResolver = new CompileTimeConstantResolver(semanticServices, trace);
|
||||
compileTimeConstantResolver = new CompileTimeConstantResolver(trace);
|
||||
}
|
||||
return compileTimeConstantResolver;
|
||||
}
|
||||
@@ -195,7 +155,7 @@ import java.util.Map;
|
||||
|
||||
@NotNull
|
||||
public OverloadResolutionResults<FunctionDescriptor> resolveCallWithGivenName(@NotNull Call call, @NotNull JetReferenceExpression functionReference, @NotNull String name) {
|
||||
return getCallResolver().resolveCallWithGivenName(trace, scope, call, functionReference, name, expectedType);
|
||||
return expressionTypingServices.getCallResolver().resolveCallWithGivenName(trace, scope, call, functionReference, name, expectedType, dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -206,23 +166,19 @@ import java.util.Map;
|
||||
|
||||
@Nullable
|
||||
public FunctionDescriptor resolveCall(@NotNull ReceiverDescriptor receiver, @Nullable ASTNode callOperationNode, @NotNull JetCallExpression callExpression) {
|
||||
OverloadResolutionResults<FunctionDescriptor> results = getCallResolver().resolveCall(trace, scope, CallMaker.makeCall(receiver, callOperationNode, callExpression), expectedType);
|
||||
OverloadResolutionResults<FunctionDescriptor> results = expressionTypingServices.getCallResolver().resolveCall(trace, scope, CallMaker.makeCall(receiver, callOperationNode, callExpression), expectedType, dataFlowInfo);
|
||||
return results.singleResult() ? results.getResultingDescriptor() : null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(@NotNull ReceiverDescriptor receiver, @Nullable ASTNode callOperationNode, @NotNull JetSimpleNameExpression nameExpression) {
|
||||
Call call = CallMaker.makePropertyCall(receiver, callOperationNode, nameExpression);
|
||||
return getCallResolver().resolveSimpleProperty(trace, scope, call, expectedType);
|
||||
return expressionTypingServices.getCallResolver().resolveSimpleProperty(trace, scope, call, expectedType, dataFlowInfo);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public OverloadResolutionResults<FunctionDescriptor> resolveExactSignature(@NotNull ReceiverDescriptor receiver, @NotNull String name, @NotNull List<JetType> parameterTypes) {
|
||||
return getCallResolver().resolveExactSignature(scope, receiver, name, parameterTypes);
|
||||
return expressionTypingServices.getCallResolver().resolveExactSignature(scope, receiver, name, parameterTypes);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
}
|
||||
|
||||
+85
-37
@@ -17,11 +17,12 @@
|
||||
package org.jetbrains.jet.lang.types.expressions;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
|
||||
@@ -29,6 +30,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;
|
||||
@@ -37,6 +39,7 @@ import org.jetbrains.jet.lang.types.CommonSupertypes;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.*;
|
||||
@@ -51,23 +54,67 @@ 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 final ExpressionTypingFacade expressionTypingFacade = ExpressionTypingVisitorDispatcher.create();
|
||||
|
||||
public ExpressionTypingServices(JetSemanticServices semanticServices, BindingTrace trace) {
|
||||
this.semanticServices = semanticServices;
|
||||
this.trace = trace;
|
||||
@NotNull
|
||||
private Project project;
|
||||
@NotNull
|
||||
private CallResolver callResolver;
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
@NotNull
|
||||
private TypeResolver typeResolver;
|
||||
|
||||
|
||||
|
||||
@NotNull
|
||||
public Project getProject() {
|
||||
return project;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setProject(@NotNull Project project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
|
||||
return safeGetType(scope, expression, expectedType, DataFlowInfo.EMPTY);
|
||||
public CallResolver getCallResolver() {
|
||||
return callResolver;
|
||||
}
|
||||
|
||||
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo) {
|
||||
JetType type = getType(scope, expression, expectedType, dataFlowInfo);
|
||||
@Inject
|
||||
public void setCallResolver(@NotNull CallResolver callResolver) {
|
||||
this.callResolver = callResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DescriptorResolver getDescriptorResolver() {
|
||||
return descriptorResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDescriptorResolver(@NotNull DescriptorResolver descriptorResolver) {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TypeResolver getTypeResolver() {
|
||||
return typeResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setTypeResolver(@NotNull TypeResolver typeResolver) {
|
||||
this.typeResolver = typeResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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, BindingTrace trace) {
|
||||
JetType type = getType(scope, expression, expectedType, dataFlowInfo, trace);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
@@ -75,25 +122,23 @@ 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(
|
||||
expression.getProject(),
|
||||
semanticServices,
|
||||
this,
|
||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||
trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
|
||||
);
|
||||
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(
|
||||
expression.getProject(),
|
||||
semanticServices,
|
||||
this,
|
||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN,
|
||||
true);
|
||||
@@ -102,7 +147,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 +156,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 +177,13 @@ public class ExpressionTypingServices {
|
||||
}
|
||||
}
|
||||
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
|
||||
function.getProject(),
|
||||
semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||
this,
|
||||
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 +197,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 +205,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 +214,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 +225,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(
|
||||
this,
|
||||
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 +272,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 +356,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(
|
||||
this, 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) {
|
||||
|
||||
+14
-13
@@ -22,7 +22,6 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
@@ -34,10 +33,12 @@ import org.jetbrains.jet.lang.resolve.calls.inference.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -78,8 +79,8 @@ public class ExpressionTypingUtils {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public static boolean isBoolean(@NotNull JetSemanticServices semanticServices, @NotNull JetType type) {
|
||||
return semanticServices.getTypeChecker().isSubtypeOf(type, semanticServices.getStandardLibrary().getBooleanType());
|
||||
public static boolean isBoolean(@NotNull JetType type) {
|
||||
return JetTypeChecker.INSTANCE.isSubtypeOf(type, JetStandardLibrary.getInstance().getBooleanType());
|
||||
}
|
||||
|
||||
public static boolean ensureBooleanResult(JetExpression operationSign, String name, JetType resultType, ExpressionTypingContext context) {
|
||||
@@ -89,8 +90,8 @@ public class ExpressionTypingUtils {
|
||||
public static boolean ensureBooleanResultWithCustomSubject(JetExpression operationSign, JetType resultType, String subjectName, ExpressionTypingContext context) {
|
||||
if (resultType != null) {
|
||||
// TODO : Relax?
|
||||
if (!isBoolean(context.semanticServices, resultType)) {
|
||||
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, context.semanticServices.getStandardLibrary().getBooleanType(), resultType));
|
||||
if (!isBoolean(resultType)) {
|
||||
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, JetStandardLibrary.getInstance().getBooleanType(), resultType));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -98,18 +99,18 @@ public class ExpressionTypingUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getDefaultType(JetSemanticServices semanticServices, IElementType constantType) {
|
||||
public static JetType getDefaultType(IElementType constantType) {
|
||||
if (constantType == JetNodeTypes.INTEGER_CONSTANT) {
|
||||
return semanticServices.getStandardLibrary().getIntType();
|
||||
return JetStandardLibrary.getInstance().getIntType();
|
||||
}
|
||||
else if (constantType == JetNodeTypes.FLOAT_CONSTANT) {
|
||||
return semanticServices.getStandardLibrary().getDoubleType();
|
||||
return JetStandardLibrary.getInstance().getDoubleType();
|
||||
}
|
||||
else if (constantType == JetNodeTypes.BOOLEAN_CONSTANT) {
|
||||
return semanticServices.getStandardLibrary().getBooleanType();
|
||||
return JetStandardLibrary.getInstance().getBooleanType();
|
||||
}
|
||||
else if (constantType == JetNodeTypes.CHARACTER_CONSTANT) {
|
||||
return semanticServices.getStandardLibrary().getCharType();
|
||||
return JetStandardLibrary.getInstance().getCharType();
|
||||
}
|
||||
else if (constantType == JetNodeTypes.NULL) {
|
||||
return JetStandardClasses.getNullableNothingType();
|
||||
@@ -148,12 +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 ExpressionTypingServices expressionTypingServices,
|
||||
@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(
|
||||
project,
|
||||
JetSemanticServices.createSemanticServices(project),
|
||||
expressionTypingServices,
|
||||
new HashMap<JetPattern, DataFlowInfo>(),
|
||||
new HashMap<JetPattern, List<VariableDescriptor>>(),
|
||||
new LabelResolver(),
|
||||
|
||||
+6
-6
@@ -79,11 +79,11 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
|
||||
@Override
|
||||
public JetType visitObjectDeclaration(JetObjectDeclaration declaration, ExpressionTypingContext context) {
|
||||
TopDownAnalyzer.processObject(context.semanticServices, context.trace, scope, scope.getContainingDeclaration(), declaration);
|
||||
TopDownAnalyzer.processObject(context.expressionTypingServices.getProject(), context.trace, scope, scope.getContainingDeclaration(), declaration);
|
||||
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
|
||||
if (classDescriptor != null) {
|
||||
VariableDescriptor variableDescriptor = context.getDescriptorResolver()
|
||||
.resolveObjectDeclaration(scope.getContainingDeclaration(), declaration, classDescriptor);
|
||||
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver()
|
||||
.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.expressionTypingServices.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.expressionTypingServices.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.expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo, context.trace);
|
||||
return DataFlowUtils.checkStatementType(function, context);
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -32,7 +32,9 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -61,7 +63,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
context.patternsToDataFlowInfo.put(pattern, newDataFlowInfo);
|
||||
context.patternsToBoundVariableLists.put(pattern, scopeToExtend.getDeclaredVariables());
|
||||
}
|
||||
return DataFlowUtils.checkType(context.semanticServices.getStandardLibrary().getBooleanType(), expression, contextWithExpectedType);
|
||||
return DataFlowUtils.checkType(JetStandardLibrary.getInstance().getBooleanType(), expression, contextWithExpectedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +76,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.expressionTypingServices.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 +117,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.expressionTypingServices.getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext, context.trace);
|
||||
if (type != null) {
|
||||
expressionTypes.add(type);
|
||||
}
|
||||
@@ -180,7 +182,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.expressionTypingServices.getTypeResolver().resolveType(context.scope, typeReference, context.trace, true);
|
||||
checkTypeCompatibility(type, subjectType, typePattern);
|
||||
result.set(context.dataFlowInfo.establishSubtyping(subjectVariables, type));
|
||||
}
|
||||
@@ -238,8 +240,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (expression == null) return;
|
||||
JetType type = facade.getType(expression, context.replaceScope(scopeToExtend));
|
||||
if (conditionExpected) {
|
||||
JetType booleanType = context.semanticServices.getStandardLibrary().getBooleanType();
|
||||
if (type != null && !context.semanticServices.getTypeChecker().equalTypes(booleanType, type)) {
|
||||
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
|
||||
if (type != null && !JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(pattern, type));
|
||||
}
|
||||
return;
|
||||
@@ -251,11 +253,11 @@ 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.expressionTypingServices.getTypeResolver().resolveType(context.scope, propertyTypeRef, context.trace, true);
|
||||
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type, context.trace);
|
||||
scopeToExtend.addVariableDescriptor(variableDescriptor);
|
||||
if (propertyTypeRef != null) {
|
||||
if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectType, type)) {
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(subjectType, type)) {
|
||||
context.trace.report(TYPE_MISMATCH_IN_BINDING_PATTERN.on(propertyTypeRef, type, subjectType));
|
||||
}
|
||||
}
|
||||
@@ -278,12 +280,12 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
if (TypeUtils.intersect(context.semanticServices.getTypeChecker(), Sets.newHashSet(type, subjectType)) == null) {
|
||||
if (TypeUtils.intersect(JetTypeChecker.INSTANCE, Sets.newHashSet(type, subjectType)) == null) {
|
||||
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType));
|
||||
return;
|
||||
}
|
||||
|
||||
if (BasicExpressionTypingVisitor.isCastErased(subjectType, type, context.semanticServices.getTypeChecker())) {
|
||||
|
||||
if (BasicExpressionTypingVisitor.isCastErased(subjectType, type, JetTypeChecker.INSTANCE)) {
|
||||
context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(reportErrorOn, type));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
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.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
@@ -54,11 +53,28 @@ public class JetStandardLibrary {
|
||||
|
||||
private static JetStandardLibrary instance = null;
|
||||
|
||||
private static boolean initializing;
|
||||
private static Throwable initializationFailed;
|
||||
|
||||
// This method must be called at least once per application run, on any project
|
||||
// before any type checking is run
|
||||
public static synchronized void initialize(@NotNull Project project) {
|
||||
if (instance == null) {
|
||||
instance = new JetStandardLibrary(project);
|
||||
if (initializing) {
|
||||
throw new IllegalStateException("builtin library initialization loop");
|
||||
}
|
||||
if (initializationFailed != null) {
|
||||
throw new RuntimeException(
|
||||
"builtin library initialization failed previously: " + initializationFailed, initializationFailed);
|
||||
}
|
||||
initializing = true;
|
||||
try {
|
||||
instance = new JetStandardLibrary(project);
|
||||
} catch (Throwable e) {
|
||||
initializationFailed = e;
|
||||
throw new RuntimeException("builtin library initialization failed: " + e, e);
|
||||
}
|
||||
initializing = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,11 +138,10 @@ public class JetStandardLibrary {
|
||||
files.add(file);
|
||||
}
|
||||
|
||||
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
||||
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files);
|
||||
TopDownAnalyzer.processStandardLibraryNamespace(project, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files);
|
||||
|
||||
AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());
|
||||
initStdClasses();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
<orderEntry type="library" name="idea-full" level="project" />
|
||||
<orderEntry type="library" name="asm" level="project" />
|
||||
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -112,8 +111,7 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
|
||||
jetCoreEnvironment.addToClasspath(tmpdir);
|
||||
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
||||
|
||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(jetCoreEnvironment.getProject());
|
||||
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), jetSemanticServices, new BindingTraceContext());
|
||||
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), new BindingTraceContext());
|
||||
|
||||
JavaDescriptorResolver javaDescriptorResolver = semanticServices.getDescriptorResolver();
|
||||
return javaDescriptorResolver.resolveNamespace("test");
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactories;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
@@ -90,8 +89,7 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
|
||||
jetCoreEnvironment.addToClasspath(tmpdir);
|
||||
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
||||
|
||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(jetCoreEnvironment.getProject());
|
||||
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), jetSemanticServices, new BindingTraceContext());
|
||||
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), new BindingTraceContext());
|
||||
|
||||
JavaDescriptorResolver javaDescriptorResolver = semanticServices.getDescriptorResolver();
|
||||
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace("test");
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
@@ -135,8 +134,7 @@ public abstract class ExpectedResolveData {
|
||||
}
|
||||
final Set<PsiElement> unresolvedReferences = Sets.newHashSet();
|
||||
Project project = files.iterator().next().getProject();
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
||||
JetStandardLibrary lib = JetStandardLibrary.getInstance();
|
||||
|
||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
@@ -25,17 +26,16 @@ import com.intellij.psi.PsiMethod;
|
||||
import junit.framework.Test;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
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.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
@@ -119,8 +119,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
@NotNull
|
||||
private PsiClass findClass(String qualifiedName) {
|
||||
Project project = getProject();
|
||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(project);
|
||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, jetSemanticServices, new BindingTraceContext());
|
||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, new BindingTraceContext());
|
||||
return javaSemanticServices.getDescriptorResolver().findClass(qualifiedName);
|
||||
}
|
||||
|
||||
@@ -135,7 +134,12 @@ 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);
|
||||
CallResolver callResolver = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
}).getInstance(CallResolver.class);
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> functions = callResolver.resolveExactSignature(
|
||||
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
|
||||
for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
|
||||
|
||||
@@ -16,13 +16,15 @@
|
||||
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
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.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
@@ -50,9 +52,13 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
||||
private JetScope scope;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
JetStandardLibrary library = JetStandardLibrary.getInstance();
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
JetStandardLibrary library = injector.getInstance(JetStandardLibrary.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
scope = createScope(library.getLibraryScope());
|
||||
}
|
||||
|
||||
@@ -72,7 +78,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 +96,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 +107,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 +119,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,16 +16,18 @@
|
||||
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
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.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
@@ -35,15 +37,18 @@ public class JetOverloadTest extends JetLiteFixture {
|
||||
|
||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||
private JetStandardLibrary library;
|
||||
private JetSemanticServices semanticServices;
|
||||
private DescriptorResolver descriptorResolver;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
library = JetStandardLibrary.getInstance();
|
||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
library = injector.getInstance(JetStandardLibrary.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
}
|
||||
|
||||
@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,16 +16,18 @@
|
||||
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import org.jetbrains.jet.JetLiteFixture;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
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.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
|
||||
/**
|
||||
@@ -35,15 +37,18 @@ public class JetOverridingTest extends JetLiteFixture {
|
||||
|
||||
private ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||
private JetStandardLibrary library;
|
||||
private JetSemanticServices semanticServices;
|
||||
private DescriptorResolver descriptorResolver;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
library = JetStandardLibrary.getInstance();
|
||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
library = injector.getInstance(JetStandardLibrary.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,14 @@
|
||||
package org.jetbrains.jet.types;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.intellij.openapi.project.Project;
|
||||
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.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -36,6 +37,8 @@ import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
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.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
@@ -48,11 +51,12 @@ import java.util.*;
|
||||
public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
|
||||
private JetStandardLibrary library;
|
||||
private JetSemanticServices semanticServices;
|
||||
private ClassDefinitions classDefinitions;
|
||||
private DescriptorResolver descriptorResolver;
|
||||
private JetScope scopeWithImports;
|
||||
private TypeResolver typeResolver;
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
|
||||
|
||||
public JetTypeCheckerTest() {
|
||||
super("");
|
||||
@@ -62,11 +66,19 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
library = JetStandardLibrary.getInstance();
|
||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||
classDefinitions = new ClassDefinitions();
|
||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||
|
||||
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
});
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||
typeResolver = injector.getInstance(TypeResolver.class);
|
||||
expressionTypingServices = injector.getInstance(ExpressionTypingServices.class);
|
||||
|
||||
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
|
||||
typeResolver = new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -513,7 +525,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
for (String type : types) {
|
||||
typesToIntersect.add(makeType(type));
|
||||
}
|
||||
JetType result = TypeUtils.intersect(semanticServices.getTypeChecker(), typesToIntersect);
|
||||
JetType result = TypeUtils.intersect(JetTypeChecker.INSTANCE, typesToIntersect);
|
||||
// assertNotNull("Intersection is null for " + typesToIntersect, result);
|
||||
assertEquals(makeType(expected), result);
|
||||
}
|
||||
@@ -530,7 +542,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
private void assertSubtypingRelation(String subtype, String supertype, boolean expected) {
|
||||
JetType typeNode1 = makeType(subtype);
|
||||
JetType typeNode2 = makeType(supertype);
|
||||
boolean result = semanticServices.getTypeChecker().isSubtypeOf(
|
||||
boolean result = JetTypeChecker.INSTANCE.isSubtypeOf(
|
||||
typeNode1,
|
||||
typeNode2);
|
||||
String modifier = expected ? "not " : "";
|
||||
@@ -540,14 +552,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 = expressionTypingServices.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 = expressionTypingServices.safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, JetTestUtils.DUMMY_TRACE);
|
||||
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
|
||||
}
|
||||
|
||||
@@ -570,7 +582,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 = expressionTypingServices.getType(addImports(scope), jetExpression, TypeUtils.NO_EXPECTED_TYPE, JetTestUtils.DUMMY_TRACE);
|
||||
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
|
||||
assertEquals(expectedType, type);
|
||||
}
|
||||
@@ -578,7 +590,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
private WritableScopeImpl addImports(JetScope scope) {
|
||||
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING);
|
||||
writableScope.importScope(library.getLibraryScope());
|
||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), semanticServices, JetTestUtils.DUMMY_TRACE);
|
||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(getProject(), JetTestUtils.DUMMY_TRACE);
|
||||
writableScope.importScope(new JavaPackageScope("", JavaBridgeConfiguration.createNamespaceDescriptor(JavaDescriptorResolver.JAVA_ROOT, ""), javaSemanticServices));
|
||||
writableScope.importScope(new JavaPackageScope("java.lang", JavaBridgeConfiguration.createNamespaceDescriptor("lang", "java.lang"), javaSemanticServices));
|
||||
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
@@ -590,7 +602,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 typeResolver.resolveType(scope, JetPsiFactory.createType(getProject(), typeStr), JetTestUtils.DUMMY_TRACE, true);
|
||||
}
|
||||
|
||||
private class ClassDefinitions {
|
||||
@@ -657,7 +669,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 +694,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 +718,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 +728,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 +752,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,7 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.liveTemplates.macro;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.codeInsight.template.Expression;
|
||||
@@ -34,7 +35,10 @@ 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.TopDownAnalysisModule;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -51,7 +55,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 +70,17 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
return null;
|
||||
}
|
||||
|
||||
ExpressionTypingServices callResolverContext = Guice.createInjector(new TopDownAnalysisModule(project, false) {
|
||||
@Override
|
||||
protected void configureAfter() {
|
||||
}
|
||||
}).getInstance(ExpressionTypingServices.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 +99,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, ExpressionTypingServices callResolverContext);
|
||||
|
||||
@Nullable
|
||||
private static JetExpression findContextExpression(PsiFile psiFile, int startOffset) {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
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, ExpressionTypingServices callResolverContext) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
@@ -28,6 +29,7 @@ import org.jetbrains.jet.plugin.JetBundle;
|
||||
* @since 2/7/12
|
||||
*/
|
||||
public class JetIterableVariableMacro extends BaseJetVariableMacro {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "kotlinIterableVariable";
|
||||
@@ -39,7 +41,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, ExpressionTypingServices callResolverContext) {
|
||||
return ExpressionTypingUtils.isVariableIterable(callResolverContext, project, variableDescriptor, scope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -95,15 +94,14 @@ public final class AnalyzerFacadeForJS {
|
||||
public static BindingContext analyzeNamespace(@NotNull JetFile file) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
Project project = file.getProject();
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||
return AnalyzingUtils.analyzeFilesWithGivenTrace(
|
||||
project,
|
||||
JsConfiguration.jsLibConfiguration(project),
|
||||
Collections.singletonList(file),
|
||||
Predicates.<PsiFile>alwaysTrue(),
|
||||
JetControlFlowDataTraceFactory.EMPTY,
|
||||
bindingTraceContext,
|
||||
semanticServices);
|
||||
bindingTraceContext
|
||||
);
|
||||
}
|
||||
|
||||
private static final class JsConfiguration implements Configuration {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user