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">
|
<path id="classpath">
|
||||||
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
<fileset dir="${idea.sdk}" includes="core/*.jar"/>
|
||||||
<fileset dir="${basedir}/lib" includes="*.jar"/>
|
<fileset dir="${basedir}/lib" includes="**/*.jar"/>
|
||||||
<pathelement path="${output}/classes/runtime"/>
|
<pathelement path="${output}/classes/runtime"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -28,7 +28,6 @@ import com.intellij.psi.util.CachedValuesManager;
|
|||||||
import com.intellij.psi.util.PsiModificationTracker;
|
import com.intellij.psi.util.PsiModificationTracker;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.StandardConfiguration;
|
import org.jetbrains.jet.lang.StandardConfiguration;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
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,
|
public static BindingContext analyzeFilesWithJavaIntegration(Project project, Collection<JetFile> files, Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||||
JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
|
||||||
return AnalyzingUtils.analyzeFilesWithGivenTrace(
|
return AnalyzingUtils.analyzeFilesWithGivenTrace(
|
||||||
project,
|
project,
|
||||||
JavaBridgeConfiguration.createJavaBridgeConfiguration(project, bindingTraceContext, StandardConfiguration.createStandardConfiguration(project)),
|
JavaBridgeConfiguration.createJavaBridgeConfiguration(project, bindingTraceContext, StandardConfiguration.createStandardConfiguration(project)),
|
||||||
files,
|
files,
|
||||||
filesToAnalyzeCompletely,
|
filesToAnalyzeCompletely,
|
||||||
flowDataTraceFactory,
|
flowDataTraceFactory,
|
||||||
bindingTraceContext,
|
bindingTraceContext
|
||||||
semanticServices);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BindingContext shallowAnalyzeFiles(Collection<JetFile> files) {
|
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 com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
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.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||||
@@ -48,7 +47,7 @@ public class JavaBridgeConfiguration implements Configuration {
|
|||||||
|
|
||||||
private JavaBridgeConfiguration(Project project, BindingTrace trace, Configuration delegateConfiguration) {
|
private JavaBridgeConfiguration(Project project, BindingTrace trace, Configuration delegateConfiguration) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.javaSemanticServices = new JavaSemanticServices(project, JetSemanticServices.createSemanticServices(project), trace);
|
this.javaSemanticServices = new JavaSemanticServices(project, trace);
|
||||||
this.delegateConfiguration = delegateConfiguration;
|
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.resolve.java.kt.JetClassAnnotation;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
import org.jetbrains.jet.rt.signature.JetSignatureAdapter;
|
||||||
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
import org.jetbrains.jet.rt.signature.JetSignatureExceptionsAdapter;
|
||||||
@@ -542,7 +543,7 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitClassBound() {
|
public JetSignatureVisitor visitClassBound() {
|
||||||
return new JetTypeJetSignatureReader(semanticServices, semanticServices.getJetSemanticServices().getStandardLibrary(), typeVariableResolver) {
|
return new JetTypeJetSignatureReader(semanticServices, JetStandardLibrary.getInstance(), typeVariableResolver) {
|
||||||
@Override
|
@Override
|
||||||
protected void done(@NotNull JetType jetType) {
|
protected void done(@NotNull JetType jetType) {
|
||||||
if (isJavaLangObject(jetType)) {
|
if (isJavaLangObject(jetType)) {
|
||||||
@@ -555,7 +556,7 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitInterfaceBound() {
|
public JetSignatureVisitor visitInterfaceBound() {
|
||||||
return new JetTypeJetSignatureReader(semanticServices, semanticServices.getJetSemanticServices().getStandardLibrary(), typeVariableResolver) {
|
return new JetTypeJetSignatureReader(semanticServices, JetStandardLibrary.getInstance(), typeVariableResolver) {
|
||||||
@Override
|
@Override
|
||||||
protected void done(@NotNull JetType jetType) {
|
protected void done(@NotNull JetType jetType) {
|
||||||
upperBounds.add(jetType);
|
upperBounds.add(jetType);
|
||||||
@@ -739,7 +740,7 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetSignatureVisitor visitSuperclass() {
|
public JetSignatureVisitor visitSuperclass() {
|
||||||
return new JetTypeJetSignatureReader(semanticServices, semanticServices.getJetSemanticServices().getStandardLibrary(), typeVariableResolver) {
|
return new JetTypeJetSignatureReader(semanticServices, JetStandardLibrary.getInstance(), typeVariableResolver) {
|
||||||
@Override
|
@Override
|
||||||
protected void done(@NotNull JetType jetType) {
|
protected void done(@NotNull JetType jetType) {
|
||||||
if (!jetType.equals(JetStandardClasses.getAnyType())) {
|
if (!jetType.equals(JetStandardClasses.getAnyType())) {
|
||||||
@@ -971,7 +972,7 @@ public class JavaDescriptorResolver {
|
|||||||
|
|
||||||
JetType varargElementType;
|
JetType varargElementType;
|
||||||
if (psiType instanceof PsiEllipsisType) {
|
if (psiType instanceof PsiEllipsisType) {
|
||||||
varargElementType = semanticServices.getJetSemanticServices().getStandardLibrary().getArrayElementType(outType);
|
varargElementType = JetStandardLibrary.getInstance().getArrayElementType(outType);
|
||||||
} else {
|
} else {
|
||||||
varargElementType = null;
|
varargElementType = null;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-10
@@ -19,11 +19,11 @@ package org.jetbrains.jet.lang.resolve.java;
|
|||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -32,13 +32,11 @@ public class JavaSemanticServices {
|
|||||||
private final JavaTypeTransformer typeTransformer;
|
private final JavaTypeTransformer typeTransformer;
|
||||||
private final JavaDescriptorResolver descriptorResolver;
|
private final JavaDescriptorResolver descriptorResolver;
|
||||||
private final BindingTrace trace;
|
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.trace = trace;
|
||||||
this.descriptorResolver = new JavaDescriptorResolver(project, this);
|
this.descriptorResolver = new JavaDescriptorResolver(project, this);
|
||||||
this.typeTransformer = new JavaTypeTransformer(this, jetSemanticServices.getStandardLibrary(), descriptorResolver);
|
this.typeTransformer = new JavaTypeTransformer(this, JetStandardLibrary.getInstance(), descriptorResolver);
|
||||||
this.jetSemanticServices = jetSemanticServices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -56,14 +54,10 @@ public class JavaSemanticServices {
|
|||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetSemanticServices getJetSemanticServices() {
|
|
||||||
return jetSemanticServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ClassDescriptor getKotlinClassDescriptor(String qualifiedName) {
|
public ClassDescriptor getKotlinClassDescriptor(String qualifiedName) {
|
||||||
if (qualifiedName.startsWith("jet.")) {
|
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) {
|
if (r == null) {
|
||||||
// TODO: better error
|
// TODO: better error
|
||||||
//throw new IllegalStateException();
|
//throw new IllegalStateException();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="intellij-core" level="project" />
|
||||||
|
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -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 com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
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.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
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.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -91,8 +91,7 @@ public class AnalyzingUtils {
|
|||||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
return analyzeFilesWithGivenTrace(project, configuration, files, filesToAnalyzeCompletely, flowDataTraceFactory, bindingTraceContext);
|
||||||
return analyzeFilesWithGivenTrace(project, configuration, files, filesToAnalyzeCompletely, flowDataTraceFactory, bindingTraceContext, semanticServices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BindingContext analyzeFilesWithGivenTrace(
|
public static BindingContext analyzeFilesWithGivenTrace(
|
||||||
@@ -101,10 +100,9 @@ public class AnalyzingUtils {
|
|||||||
@NotNull Collection<JetFile> files,
|
@NotNull Collection<JetFile> files,
|
||||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely,
|
||||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||||
@NotNull BindingTraceContext bindingTraceContext,
|
@NotNull BindingTraceContext bindingTraceContext) {
|
||||||
@NotNull JetSemanticServices semanticServices) {
|
|
||||||
|
|
||||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
JetScope libraryScope = JetStandardLibrary.getInstance().getLibraryScope();
|
||||||
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
ModuleDescriptor owner = new ModuleDescriptor("<module>");
|
||||||
|
|
||||||
final WritableScope scope = new WritableScopeImpl(
|
final WritableScope scope = new WritableScopeImpl(
|
||||||
@@ -114,7 +112,7 @@ public class AnalyzingUtils {
|
|||||||
scope.importScope(libraryScope);
|
scope.importScope(libraryScope);
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
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();
|
private Map<String, NamespaceDescriptorImpl> declaredNamespaces = Maps.newHashMap();
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
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.JetType;
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -47,47 +47,50 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
|||||||
*/
|
*/
|
||||||
public class AnnotationResolver {
|
public class AnnotationResolver {
|
||||||
|
|
||||||
private final BindingTrace trace;
|
private ExpressionTypingServices expressionTypingServices;
|
||||||
private final JetSemanticServices semanticServices;
|
private CallResolver callResolver;
|
||||||
private final CallResolver callResolver;
|
|
||||||
|
|
||||||
public AnnotationResolver(JetSemanticServices semanticServices, BindingTrace trace) {
|
@Inject
|
||||||
this.trace = trace;
|
public void setExpressionTypingServices(ExpressionTypingServices expressionTypingServices) {
|
||||||
this.callResolver = new CallResolver(semanticServices, DataFlowInfo.EMPTY);
|
this.expressionTypingServices = expressionTypingServices;
|
||||||
this.semanticServices = semanticServices;
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public void setCallResolver(CallResolver callResolver) {
|
||||||
|
this.callResolver = callResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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) {
|
if (modifierList == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return resolveAnnotations(scope, modifierList.getAnnotationEntries());
|
return resolveAnnotations(scope, modifierList.getAnnotationEntries(), trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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();
|
if (annotationEntryElements.isEmpty()) return Collections.emptyList();
|
||||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||||
for (JetAnnotationEntry entryElement : annotationEntryElements) {
|
for (JetAnnotationEntry entryElement : annotationEntryElements) {
|
||||||
AnnotationDescriptor descriptor = new AnnotationDescriptor();
|
AnnotationDescriptor descriptor = new AnnotationDescriptor();
|
||||||
resolveAnnotationStub(scope, entryElement, descriptor);
|
resolveAnnotationStub(scope, entryElement, descriptor, trace);
|
||||||
result.add(descriptor);
|
result.add(descriptor);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveAnnotationStub(@NotNull JetScope scope, @NotNull JetAnnotationEntry entryElement,
|
public void resolveAnnotationStub(@NotNull JetScope scope, @NotNull JetAnnotationEntry entryElement,
|
||||||
@NotNull AnnotationDescriptor descriptor) {
|
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) {
|
||||||
OverloadResolutionResults<FunctionDescriptor> results = resolveType(scope, entryElement, descriptor);
|
OverloadResolutionResults<FunctionDescriptor> results = resolveType(scope, entryElement, descriptor, trace);
|
||||||
resolveArguments(results, descriptor);
|
resolveArguments(results, descriptor, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private OverloadResolutionResults<FunctionDescriptor> resolveType(@NotNull JetScope scope,
|
private OverloadResolutionResults<FunctionDescriptor> resolveType(@NotNull JetScope scope,
|
||||||
@NotNull JetAnnotationEntry entryElement,
|
@NotNull JetAnnotationEntry entryElement,
|
||||||
@NotNull AnnotationDescriptor descriptor) {
|
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) {
|
||||||
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(trace, scope, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, entryElement), NO_EXPECTED_TYPE);
|
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(trace, scope, CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, entryElement), NO_EXPECTED_TYPE, DataFlowInfo.EMPTY);
|
||||||
JetType annotationType = results.getResultingDescriptor().getReturnType();
|
JetType annotationType = results.getResultingDescriptor().getReturnType();
|
||||||
if (results.isSuccess()) {
|
if (results.isSuccess()) {
|
||||||
descriptor.setAnnotationType(annotationType);
|
descriptor.setAnnotationType(annotationType);
|
||||||
@@ -98,7 +101,7 @@ public class AnnotationResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resolveArguments(@NotNull OverloadResolutionResults<FunctionDescriptor> results,
|
private void resolveArguments(@NotNull OverloadResolutionResults<FunctionDescriptor> results,
|
||||||
@NotNull AnnotationDescriptor descriptor) {
|
@NotNull AnnotationDescriptor descriptor, BindingTrace trace) {
|
||||||
List<CompileTimeConstant<?>> arguments = Lists.newArrayList();
|
List<CompileTimeConstant<?>> arguments = Lists.newArrayList();
|
||||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument :
|
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> descriptorToArgument :
|
||||||
results.getResultingCall().getValueArguments().entrySet()) {
|
results.getResultingCall().getValueArguments().entrySet()) {
|
||||||
@@ -106,19 +109,18 @@ public class AnnotationResolver {
|
|||||||
List<JetExpression> argumentExpressions = descriptorToArgument.getValue().getArgumentExpressions();
|
List<JetExpression> argumentExpressions = descriptorToArgument.getValue().getArgumentExpressions();
|
||||||
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
|
ValueParameterDescriptor parameterDescriptor = descriptorToArgument.getKey();
|
||||||
for (JetExpression argument : argumentExpressions) {
|
for (JetExpression argument : argumentExpressions) {
|
||||||
arguments.add(resolveAnnotationArgument(argument, parameterDescriptor.getType()));
|
arguments.add(resolveAnnotationArgument(argument, parameterDescriptor.getType(), trace));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
descriptor.setValueArguments(arguments);
|
descriptor.setValueArguments(arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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>() {
|
JetVisitor<CompileTimeConstant<?>, Void> visitor = new JetVisitor<CompileTimeConstant<?>, Void>() {
|
||||||
@Override
|
@Override
|
||||||
public CompileTimeConstant<?> visitConstantExpression(JetConstantExpression expression, Void nothing) {
|
public CompileTimeConstant<?> visitConstantExpression(JetConstantExpression expression, Void nothing) {
|
||||||
ExpressionTypingServices typeInferrerServices = semanticServices.getTypeInferrerServices(trace);
|
JetType type = expressionTypingServices.getType(JetScope.EMPTY, expression, expectedType, DataFlowInfo.EMPTY, trace);
|
||||||
JetType type = typeInferrerServices.getType(JetScope.EMPTY, expression, expectedType, DataFlowInfo.EMPTY);
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
// TODO:
|
// TODO:
|
||||||
// trace.report(ANNOTATION_PARAMETER_SHOULD_BE_CONSTANT.on(expression));
|
// trace.report(ANNOTATION_PARAMETER_SHOULD_BE_CONSTANT.on(expression));
|
||||||
@@ -161,15 +163,15 @@ public class AnnotationResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<AnnotationDescriptor> createAnnotationStubs(@Nullable JetModifierList modifierList) {
|
public List<AnnotationDescriptor> createAnnotationStubs(@Nullable JetModifierList modifierList, BindingTrace trace) {
|
||||||
if (modifierList == null) {
|
if (modifierList == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return createAnnotationStubs(modifierList.getAnnotationEntries());
|
return createAnnotationStubs(modifierList.getAnnotationEntries(), trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<AnnotationDescriptor> createAnnotationStubs(List<JetAnnotationEntry> annotations) {
|
public List<AnnotationDescriptor> createAnnotationStubs(List<JetAnnotationEntry> annotations, BindingTrace trace) {
|
||||||
List<AnnotationDescriptor> result = Lists.newArrayList();
|
List<AnnotationDescriptor> result = Lists.newArrayList();
|
||||||
for (JetAnnotationEntry annotation : annotations) {
|
for (JetAnnotationEntry annotation : annotations) {
|
||||||
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
|
AnnotationDescriptor annotationDescriptor = new AnnotationDescriptor();
|
||||||
|
|||||||
@@ -18,11 +18,45 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.util.containers.Queue;
|
import com.intellij.util.containers.Queue;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
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.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.CallMaker;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||||
@@ -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.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
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.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.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
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.lazy.ReenteringLazyValueComputationException;
|
||||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
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.resolve.BindingContext.DEFERRED_TYPE;
|
||||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_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
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class BodyResolver {
|
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.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() {
|
public void resolveBehaviorDeclarationBodies() {
|
||||||
|
|
||||||
resolveDelegationSpecifierLists();
|
resolveDelegationSpecifierLists();
|
||||||
@@ -90,8 +173,8 @@ public class BodyResolver {
|
|||||||
final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor();
|
final ConstructorDescriptor primaryConstructor = descriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
final JetScope scopeForConstructor = primaryConstructor == null
|
final JetScope scopeForConstructor = primaryConstructor == null
|
||||||
? null
|
? null
|
||||||
: FunctionDescriptorUtil.getFunctionInnerScope(descriptor.getScopeForSupertypeResolution(), primaryConstructor, trace);
|
: FunctionDescriptorUtil.getFunctionInnerScope(descriptor.getScopeForSupertypeResolution(), primaryConstructor, context.getTrace());
|
||||||
final ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace); // TODO : flow
|
final ExpressionTypingServices typeInferrer = expressionTypingServices; // TODO : flow
|
||||||
|
|
||||||
final Map<JetTypeReference, JetType> supertypes = Maps.newLinkedHashMap();
|
final Map<JetTypeReference, JetType> supertypes = Maps.newLinkedHashMap();
|
||||||
JetVisitorVoid visitor = new JetVisitorVoid() {
|
JetVisitorVoid visitor = new JetVisitorVoid() {
|
||||||
@@ -121,8 +204,8 @@ public class BodyResolver {
|
|||||||
JetScope scope = scopeForConstructor == null
|
JetScope scope = scopeForConstructor == null
|
||||||
? descriptor.getScopeForMemberResolution()
|
? descriptor.getScopeForMemberResolution()
|
||||||
: scopeForConstructor;
|
: scopeForConstructor;
|
||||||
JetType type = typeInferrer.getType(scope, delegateExpression, NO_EXPECTED_TYPE);
|
JetType type = typeInferrer.getType(scope, delegateExpression, NO_EXPECTED_TYPE, context.getTrace());
|
||||||
if (type != null && supertype != null && !context.getSemanticServices().getTypeChecker().isSubtypeOf(type, supertype)) {
|
if (type != null && supertype != null && !JetTypeChecker.INSTANCE.isSubtypeOf(type, supertype)) {
|
||||||
context.getTrace().report(TYPE_MISMATCH.on(delegateExpression, supertype, type));
|
context.getTrace().report(TYPE_MISMATCH.on(delegateExpression, supertype, type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,9 +224,9 @@ public class BodyResolver {
|
|||||||
assert descriptor.getKind() == ClassKind.TRAIT;
|
assert descriptor.getKind() == ClassKind.TRAIT;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
OverloadResolutionResults<FunctionDescriptor> results = new CallResolver(context.getSemanticServices(), DataFlowInfo.EMPTY).resolveCall(
|
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCall(
|
||||||
context.getTrace(), scopeForConstructor,
|
context.getTrace(), scopeForConstructor,
|
||||||
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
|
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE, DataFlowInfo.EMPTY);
|
||||||
if (results.isSuccess()) {
|
if (results.isSuccess()) {
|
||||||
JetType supertype = results.getResultingDescriptor().getReturnType();
|
JetType supertype = results.getResultingDescriptor().getReturnType();
|
||||||
recordSupertype(typeReference, supertype);
|
recordSupertype(typeReference, supertype);
|
||||||
@@ -261,9 +344,8 @@ public class BodyResolver {
|
|||||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
assert primaryConstructor != null;
|
assert primaryConstructor != null;
|
||||||
final JetScope scopeForInitializers = classDescriptor.getScopeForInitializers();
|
final JetScope scopeForInitializers = classDescriptor.getScopeForInitializers();
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
|
|
||||||
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
||||||
typeInferrer.getType(scopeForInitializers, anonymousInitializer.getBody(), NO_EXPECTED_TYPE);
|
expressionTypingServices.getType(scopeForInitializers, anonymousInitializer.getBody(), NO_EXPECTED_TYPE, context.getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -298,12 +380,12 @@ public class BodyResolver {
|
|||||||
private void resolveSecondaryConstructorBody(JetSecondaryConstructor declaration, final ConstructorDescriptor descriptor) {
|
private void resolveSecondaryConstructorBody(JetSecondaryConstructor declaration, final ConstructorDescriptor descriptor) {
|
||||||
if (!context.completeAnalysisNeeded(declaration)) return;
|
if (!context.completeAnalysisNeeded(declaration)) return;
|
||||||
MutableClassDescriptor classDescriptor = (MutableClassDescriptor) descriptor.getContainingDeclaration();
|
MutableClassDescriptor classDescriptor = (MutableClassDescriptor) descriptor.getContainingDeclaration();
|
||||||
final JetScope scopeForSupertypeInitializers = FunctionDescriptorUtil.getFunctionInnerScope(classDescriptor.getScopeForSupertypeResolution(), descriptor, trace);
|
final JetScope scopeForSupertypeInitializers = FunctionDescriptorUtil.getFunctionInnerScope(classDescriptor.getScopeForSupertypeResolution(), descriptor, context.getTrace());
|
||||||
//contains only constructor parameters
|
//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
|
//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();
|
PsiElement nameElement = declaration.getNameNode().getPsi();
|
||||||
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
|
if (classDescriptor.getUnsubstitutedPrimaryConstructor() == null) {
|
||||||
@@ -320,7 +402,7 @@ public class BodyResolver {
|
|||||||
public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) {
|
public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) {
|
||||||
JetTypeReference typeReference = call.getTypeReference();
|
JetTypeReference typeReference = call.getTypeReference();
|
||||||
if (typeReference != null) {
|
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(),
|
callResolver.resolveCall(context.getTrace(),
|
||||||
scopeForSupertypeInitializers,
|
scopeForSupertypeInitializers,
|
||||||
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE);
|
CallMaker.makeCall(ReceiverDescriptor.NO_RECEIVER, null, call), NO_EXPECTED_TYPE, dataFlowInfo);
|
||||||
// call.getThisReference(),
|
// call.getThisReference(),
|
||||||
// classDescriptor,
|
// classDescriptor,
|
||||||
// classDescriptor.getDefaultType(),
|
// classDescriptor.getDefaultType(),
|
||||||
@@ -363,9 +445,8 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
JetExpression bodyExpression = declaration.getBodyExpression();
|
JetExpression bodyExpression = declaration.getBodyExpression();
|
||||||
if (bodyExpression != null) {
|
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);
|
checkDefaultParameterValues(declaration.getValueParameters(), descriptor.getValueParameters(), scopeForConstructorBody);
|
||||||
@@ -424,8 +505,8 @@ public class BodyResolver {
|
|||||||
private JetScope makeScopeForPropertyAccessor(@NotNull JetPropertyAccessor accessor, PropertyDescriptor propertyDescriptor) {
|
private JetScope makeScopeForPropertyAccessor(@NotNull JetPropertyAccessor accessor, PropertyDescriptor propertyDescriptor) {
|
||||||
JetScope declaringScope = context.getDeclaringScopes().get(accessor);
|
JetScope declaringScope = context.getDeclaringScopes().get(accessor);
|
||||||
|
|
||||||
JetScope propertyDeclarationInnerScope = context.getDescriptorResolver().getPropertyDeclarationInnerScope(
|
JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScope(
|
||||||
declaringScope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter());
|
declaringScope, propertyDescriptor, propertyDescriptor.getTypeParameters(), propertyDescriptor.getReceiverParameter(), context.getTrace());
|
||||||
WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
|
WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, declaringScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Accessor scope");
|
||||||
accessorScope.changeLockLevel(WritableScope.LockLevel.READING);
|
accessorScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
@@ -451,7 +532,7 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ObservableBindingTrace createFieldTrackingTrace(final PropertyDescriptor propertyDescriptor) {
|
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
|
@Override
|
||||||
public void handleRecord(WritableSlice<JetReferenceExpression, DeclarationDescriptor> slice, JetReferenceExpression expression, DeclarationDescriptor descriptor) {
|
public void handleRecord(WritableSlice<JetReferenceExpression, DeclarationDescriptor> slice, JetReferenceExpression expression, DeclarationDescriptor descriptor) {
|
||||||
if (expression instanceof JetSimpleNameExpression) {
|
if (expression instanceof JetSimpleNameExpression) {
|
||||||
@@ -459,7 +540,7 @@ public class BodyResolver {
|
|||||||
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
||||||
// This check may be considered redundant as long as $x is only accessible from accessors to $x
|
// This check may be considered redundant as long as $x is only accessible from accessors to $x
|
||||||
if (descriptor == propertyDescriptor) { // TODO : original?
|
if (descriptor == propertyDescriptor) { // TODO : original?
|
||||||
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) {
|
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
|
||||||
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
|
//JetFlowInformationProvider flowInformationProvider = context.getDescriptorResolver().computeFlowData(property, initializer); // TODO : flow JET-15
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
|
|
||||||
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
JetType expectedTypeForInitializer = property.getPropertyTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||||
JetType type = 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();
|
// JetType expectedType = propertyDescriptor.getInType();
|
||||||
// if (expectedType == null) {
|
// if (expectedType == null) {
|
||||||
@@ -493,7 +573,7 @@ public class BodyResolver {
|
|||||||
JetScope declaringScope = this.context.getDeclaringScopes().get(declaration);
|
JetScope declaringScope = this.context.getDeclaringScopes().get(declaration);
|
||||||
assert declaringScope != null;
|
assert declaringScope != null;
|
||||||
|
|
||||||
resolveFunctionBody(trace, declaration, descriptor, declaringScope);
|
resolveFunctionBody(context.getTrace(), declaration, descriptor, declaringScope);
|
||||||
|
|
||||||
assert descriptor.getReturnType() != null;
|
assert descriptor.getReturnType() != null;
|
||||||
}
|
}
|
||||||
@@ -509,9 +589,7 @@ public class BodyResolver {
|
|||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(declaringScope, functionDescriptor, trace);
|
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(declaringScope, functionDescriptor, trace);
|
||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
|
expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, trace);
|
||||||
|
|
||||||
typeInferrer.checkFunctionReturnType(functionInnerScope, function, functionDescriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<JetParameter> valueParameters = function.getValueParameters();
|
List<JetParameter> valueParameters = function.getValueParameters();
|
||||||
@@ -523,14 +601,13 @@ public class BodyResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkDefaultParameterValues(List<JetParameter> valueParameters, List<ValueParameterDescriptor> valueParameterDescriptors, JetScope declaringScope) {
|
private void checkDefaultParameterValues(List<JetParameter> valueParameters, List<ValueParameterDescriptor> valueParameterDescriptors, JetScope declaringScope) {
|
||||||
ExpressionTypingServices typeInferrer = context.getSemanticServices().getTypeInferrerServices(trace);
|
|
||||||
for (int i = 0; i < valueParameters.size(); i++) {
|
for (int i = 0; i < valueParameters.size(); i++) {
|
||||||
ValueParameterDescriptor valueParameterDescriptor = valueParameterDescriptors.get(i);
|
ValueParameterDescriptor valueParameterDescriptor = valueParameterDescriptors.get(i);
|
||||||
if (valueParameterDescriptor.hasDefaultValue()) {
|
if (valueParameterDescriptor.hasDefaultValue()) {
|
||||||
JetParameter jetParameter = valueParameters.get(i);
|
JetParameter jetParameter = valueParameters.get(i);
|
||||||
JetExpression defaultValue = jetParameter.getDefaultValue();
|
JetExpression defaultValue = jetParameter.getDefaultValue();
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
typeInferrer.getType(declaringScope, defaultValue, valueParameterDescriptor.getType());
|
expressionTypingServices.getType(declaringScope, defaultValue, valueParameterDescriptor.getType(), context.getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
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 {
|
public class ControlFlowAnalyzer {
|
||||||
private TopDownAnalysisContext context;
|
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;
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public void setFlowDataTraceFactory(JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||||
this.flowDataTraceFactory = flowDataTraceFactory;
|
this.flowDataTraceFactory = flowDataTraceFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
for (JetClass aClass : context.getClasses().keySet()) {
|
for (JetClass aClass : context.getClasses().keySet()) {
|
||||||
if (!context.completeAnalysisNeeded(aClass)) continue;
|
if (!context.completeAnalysisNeeded(aClass)) continue;
|
||||||
|
|||||||
@@ -16,9 +16,28 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.descriptors.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.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
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
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class DeclarationResolver {
|
public class DeclarationResolver {
|
||||||
private final AnnotationResolver annotationResolver;
|
@NotNull
|
||||||
private final TopDownAnalysisContext context;
|
private AnnotationResolver annotationResolver;
|
||||||
|
@NotNull
|
||||||
|
private TopDownAnalysisContext context;
|
||||||
|
@NotNull
|
||||||
|
private ImportsResolver importsResolver;
|
||||||
|
@NotNull
|
||||||
|
private DescriptorResolver descriptorResolver;
|
||||||
|
|
||||||
public DeclarationResolver(TopDownAnalysisContext context) {
|
|
||||||
this.context = context;
|
@Inject
|
||||||
this.annotationResolver = new AnnotationResolver(context.getSemanticServices(), context.getTrace());
|
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() {
|
public void process() {
|
||||||
resolveConstructorHeaders();
|
resolveConstructorHeaders();
|
||||||
resolveAnnotationStubsOnClassesAndConstructors();
|
resolveAnnotationStubsOnClassesAndConstructors();
|
||||||
resolveFunctionAndPropertyHeaders();
|
resolveFunctionAndPropertyHeaders();
|
||||||
context.getImportsResolver().processMembersImports();
|
importsResolver.processMembersImports();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolveConstructorHeaders() {
|
private void resolveConstructorHeaders() {
|
||||||
@@ -59,7 +102,6 @@ public class DeclarationResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resolveAnnotationStubsOnClassesAndConstructors() {
|
private void resolveAnnotationStubsOnClassesAndConstructors() {
|
||||||
AnnotationResolver annotationResolver = new AnnotationResolver(context.getSemanticServices(), context.getTrace());
|
|
||||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||||
JetClass jetClass = entry.getKey();
|
JetClass jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
@@ -75,7 +117,7 @@ public class DeclarationResolver {
|
|||||||
private void resolveAnnotationsForClassOrObject(AnnotationResolver annotationResolver, JetClassOrObject jetClass, MutableClassDescriptor descriptor) {
|
private void resolveAnnotationsForClassOrObject(AnnotationResolver annotationResolver, JetClassOrObject jetClass, MutableClassDescriptor descriptor) {
|
||||||
JetModifierList modifierList = jetClass.getModifierList();
|
JetModifierList modifierList = jetClass.getModifierList();
|
||||||
if (modifierList != null) {
|
if (modifierList != null) {
|
||||||
descriptor.getAnnotations().addAll(annotationResolver.resolveAnnotations(descriptor.getScopeForSupertypeResolution(), modifierList.getAnnotationEntries()));
|
descriptor.getAnnotations().addAll(annotationResolver.resolveAnnotations(descriptor.getScopeForSupertypeResolution(), modifierList.getAnnotationEntries(), context.getTrace()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +162,7 @@ public class DeclarationResolver {
|
|||||||
declaration.accept(new JetVisitorVoid() {
|
declaration.accept(new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
public void visitNamedFunction(JetNamedFunction function) {
|
||||||
SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function);
|
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(namespaceLike, scopeForFunctions, function, context.getTrace());
|
||||||
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
namespaceLike.addFunctionDescriptor(functionDescriptor);
|
||||||
context.getFunctions().put(function, functionDescriptor);
|
context.getFunctions().put(function, functionDescriptor);
|
||||||
context.getDeclaringScopes().put(function, scopeForFunctions);
|
context.getDeclaringScopes().put(function, scopeForFunctions);
|
||||||
@@ -128,7 +170,7 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
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);
|
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||||
context.getProperties().put(property, propertyDescriptor);
|
context.getProperties().put(property, propertyDescriptor);
|
||||||
context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
|
context.getDeclaringScopes().put(property, scopeForPropertyInitializers);
|
||||||
@@ -142,7 +184,7 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration));
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration), context.getTrace());
|
||||||
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
namespaceLike.addPropertyDescriptor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +193,7 @@ public class DeclarationResolver {
|
|||||||
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
if (enumEntry.getPrimaryConstructorParameterList() == null) {
|
||||||
MutableClassDescriptorLite classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
|
MutableClassDescriptorLite classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
|
||||||
assert classObjectDescriptor != null;
|
assert classObjectDescriptor != null;
|
||||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry));
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), context.getTrace());
|
||||||
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
|
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,13 +212,13 @@ public class DeclarationResolver {
|
|||||||
|
|
||||||
// TODO : not all the parameters are real properties
|
// TODO : not all the parameters are real properties
|
||||||
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
|
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
|
||||||
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
|
ConstructorDescriptor constructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass, context.getTrace());
|
||||||
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
|
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
|
||||||
if (parameter.getValOrVarNode() != null) {
|
if (parameter.getValOrVarNode() != null) {
|
||||||
PropertyDescriptor propertyDescriptor = context.getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePrimaryConstructorParameterToAProperty(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
memberScope,
|
memberScope,
|
||||||
parameter
|
parameter, context.getTrace()
|
||||||
);
|
);
|
||||||
classDescriptor.addPropertyDescriptor(propertyDescriptor);
|
classDescriptor.addPropertyDescriptor(propertyDescriptor);
|
||||||
context.getPrimaryConstructorParameterProperties().add(propertyDescriptor);
|
context.getPrimaryConstructorParameterProperties().add(propertyDescriptor);
|
||||||
@@ -191,10 +233,10 @@ public class DeclarationResolver {
|
|||||||
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
if (classDescriptor.getKind() == ClassKind.TRAIT) {
|
||||||
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode().getPsi()));
|
context.getTrace().report(CONSTRUCTOR_IN_TRAIT.on(constructor.getNameNode().getPsi()));
|
||||||
}
|
}
|
||||||
ConstructorDescriptor constructorDescriptor = context.getDescriptorResolver().resolveSecondaryConstructorDescriptor(
|
ConstructorDescriptor constructorDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(
|
||||||
classDescriptor.getScopeForMemberResolution(),
|
classDescriptor.getScopeForMemberResolution(),
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
constructor);
|
constructor, context.getTrace());
|
||||||
classDescriptor.addConstructor(constructorDescriptor, context.getTrace());
|
classDescriptor.addConstructor(constructorDescriptor, context.getTrace());
|
||||||
context.getConstructors().put(constructor, constructorDescriptor);
|
context.getConstructors().put(constructor, constructorDescriptor);
|
||||||
context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
|
context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -44,12 +45,16 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE;
|
|||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class DeclarationsChecker {
|
public class DeclarationsChecker {
|
||||||
|
@NotNull
|
||||||
private TopDownAnalysisContext context;
|
private TopDownAnalysisContext context;
|
||||||
|
|
||||||
public DeclarationsChecker(TopDownAnalysisContext context) {
|
|
||||||
|
@Inject
|
||||||
|
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
Map<JetClass, MutableClassDescriptor> classes = context.getClasses();
|
Map<JetClass, MutableClassDescriptor> classes = context.getClasses();
|
||||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : classes.entrySet()) {
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
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.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -28,12 +30,16 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class DelegationResolver {
|
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;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
addDelegatedMembers();
|
addDelegatedMembers();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,58 +18,140 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
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.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.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.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.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
import org.jetbrains.jet.util.lazy.LazyValue;
|
||||||
import org.jetbrains.jet.util.lazy.LazyValueWithDefault;
|
import org.jetbrains.jet.util.lazy.LazyValueWithDefault;
|
||||||
|
|
||||||
import 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
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class DescriptorResolver {
|
public class DescriptorResolver {
|
||||||
private final JetSemanticServices semanticServices;
|
@NotNull
|
||||||
private final TypeResolver typeResolver;
|
private TypeResolver typeResolver;
|
||||||
private final TypeResolver typeResolverNotCheckingBounds;
|
@NotNull
|
||||||
private final BindingTrace trace;
|
private AnnotationResolver annotationResolver;
|
||||||
private final AnnotationResolver annotationResolver;
|
@NotNull
|
||||||
|
private ExpressionTypingServices expressionTypingServices;
|
||||||
|
|
||||||
public DescriptorResolver(JetSemanticServices semanticServices, BindingTrace trace) {
|
@Inject
|
||||||
this.semanticServices = semanticServices;
|
public void setTypeResolver(@NotNull TypeResolver typeResolver) {
|
||||||
this.typeResolver = new TypeResolver(semanticServices, trace, true);
|
this.typeResolver = typeResolver;
|
||||||
this.typeResolverNotCheckingBounds = new TypeResolver(semanticServices, trace, false);
|
|
||||||
this.trace = trace;
|
|
||||||
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveMutableClassDescriptor(@NotNull JetClass classElement, @NotNull MutableClassDescriptor descriptor) {
|
@Inject
|
||||||
|
public void 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
|
// TODO : Where-clause
|
||||||
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
List<TypeParameterDescriptor> typeParameters = Lists.newArrayList();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
|
for (JetTypeParameter typeParameter : classElement.getTypeParameters()) {
|
||||||
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
|
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
|
||||||
descriptor,
|
descriptor,
|
||||||
annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
|
annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace),
|
||||||
!typeParameter.hasModifier(JetTokens.ERASED_KEYWORD),
|
!typeParameter.hasModifier(JetTokens.ERASED_KEYWORD),
|
||||||
typeParameter.getVariance(),
|
typeParameter.getVariance(),
|
||||||
JetPsiUtil.safeName(typeParameter.getName()),
|
JetPsiUtil.safeName(typeParameter.getName()),
|
||||||
@@ -87,16 +169,16 @@ public class DescriptorResolver {
|
|||||||
trace.record(BindingContext.CLASS, classElement, descriptor);
|
trace.record(BindingContext.CLASS, classElement, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resolveSupertypes(@NotNull JetClassOrObject jetClass, @NotNull MutableClassDescriptor descriptor) {
|
public void resolveSupertypes(@NotNull JetClassOrObject jetClass, @NotNull MutableClassDescriptor descriptor, BindingTrace trace) {
|
||||||
List<JetDelegationSpecifier> delegationSpecifiers = jetClass.getDelegationSpecifiers();
|
List<JetDelegationSpecifier> delegationSpecifiers = jetClass.getDelegationSpecifiers();
|
||||||
if (delegationSpecifiers.isEmpty()) {
|
if (delegationSpecifiers.isEmpty()) {
|
||||||
descriptor.addSupertype(getDefaultSupertype(jetClass));
|
descriptor.addSupertype(getDefaultSupertype(jetClass, trace));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Collection<JetType> supertypes = resolveDelegationSpecifiers(
|
Collection<JetType> supertypes = resolveDelegationSpecifiers(
|
||||||
descriptor.getScopeForSupertypeResolution(),
|
descriptor.getScopeForSupertypeResolution(),
|
||||||
delegationSpecifiers,
|
delegationSpecifiers,
|
||||||
typeResolverNotCheckingBounds);
|
typeResolver, trace, false);
|
||||||
for (JetType supertype : supertypes) {
|
for (JetType supertype : supertypes) {
|
||||||
descriptor.addSupertype(supertype);
|
descriptor.addSupertype(supertype);
|
||||||
}
|
}
|
||||||
@@ -104,7 +186,7 @@ public class DescriptorResolver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetType getDefaultSupertype(JetClassOrObject jetClass) {
|
private JetType getDefaultSupertype(JetClassOrObject jetClass, BindingTrace trace) {
|
||||||
// TODO : beautify
|
// TODO : beautify
|
||||||
if (jetClass instanceof JetEnumEntry) {
|
if (jetClass instanceof JetEnumEntry) {
|
||||||
JetClassOrObject parent = PsiTreeUtil.getParentOfType(jetClass, JetClassOrObject.class);
|
JetClassOrObject parent = PsiTreeUtil.getParentOfType(jetClass, JetClassOrObject.class);
|
||||||
@@ -120,7 +202,7 @@ public class DescriptorResolver {
|
|||||||
return JetStandardClasses.getAnyType();
|
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()) {
|
if (delegationSpecifiers.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@@ -128,7 +210,7 @@ public class DescriptorResolver {
|
|||||||
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
||||||
JetTypeReference typeReference = delegationSpecifier.getTypeReference();
|
JetTypeReference typeReference = delegationSpecifier.getTypeReference();
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
result.add(resolver.resolveType(extensibleScope, typeReference));
|
result.add(resolver.resolveType(extensibleScope, typeReference, trace, checkBounds));
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||||
while (typeElement instanceof JetNullableType) {
|
while (typeElement instanceof JetNullableType) {
|
||||||
JetNullableType nullableType = (JetNullableType) typeElement;
|
JetNullableType nullableType = (JetNullableType) typeElement;
|
||||||
@@ -153,19 +235,19 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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(
|
final SimpleFunctionDescriptorImpl functionDescriptor = new SimpleFunctionDescriptorImpl(
|
||||||
containingDescriptor,
|
containingDescriptor,
|
||||||
annotationResolver.resolveAnnotations(scope, function.getModifierList()),
|
annotationResolver.resolveAnnotations(scope, function.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(function.getName()),
|
JetPsiUtil.safeName(function.getName()),
|
||||||
CallableMemberDescriptor.Kind.DECLARATION
|
CallableMemberDescriptor.Kind.DECLARATION
|
||||||
);
|
);
|
||||||
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope");
|
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope");
|
||||||
innerScope.addLabeledDeclaration(functionDescriptor);
|
innerScope.addLabeledDeclaration(functionDescriptor);
|
||||||
|
|
||||||
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters());
|
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(functionDescriptor, innerScope, function.getTypeParameters(), trace);
|
||||||
innerScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
innerScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
resolveGenericBounds(function, innerScope, typeParameterDescriptors);
|
resolveGenericBounds(function, innerScope, typeParameterDescriptors, trace);
|
||||||
|
|
||||||
JetType receiverType = null;
|
JetType receiverType = null;
|
||||||
JetTypeReference receiverTypeRef = function.getReceiverTypeRef();
|
JetTypeReference receiverTypeRef = function.getReceiverTypeRef();
|
||||||
@@ -174,17 +256,17 @@ public class DescriptorResolver {
|
|||||||
function.hasTypeParameterListBeforeFunctionName()
|
function.hasTypeParameterListBeforeFunctionName()
|
||||||
? innerScope
|
? innerScope
|
||||||
: scope;
|
: 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);
|
innerScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
JetTypeReference returnTypeRef = function.getReturnTypeRef();
|
JetTypeReference returnTypeRef = function.getReturnTypeRef();
|
||||||
JetType returnType;
|
JetType returnType;
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
returnType = typeResolver.resolveType(innerScope, returnTypeRef);
|
returnType = typeResolver.resolveType(innerScope, returnTypeRef, trace, true);
|
||||||
}
|
}
|
||||||
else if (function.hasBlockBody()) {
|
else if (function.hasBlockBody()) {
|
||||||
returnType = JetStandardClasses.getUnitType();
|
returnType = JetStandardClasses.getUnitType();
|
||||||
@@ -196,7 +278,7 @@ public class DescriptorResolver {
|
|||||||
@Override
|
@Override
|
||||||
protected JetType compute() {
|
protected JetType compute() {
|
||||||
//JetFlowInformationProvider flowInformationProvider = computeFlowData(function, bodyExpression);
|
//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
|
@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>();
|
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||||
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
|
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
|
||||||
JetParameter valueParameter = valueParameters.get(i);
|
JetParameter valueParameter = valueParameters.get(i);
|
||||||
@@ -247,10 +329,10 @@ public class DescriptorResolver {
|
|||||||
trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter));
|
trace.report(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION.on(valueParameter));
|
||||||
type = ErrorUtils.createErrorType("Type annotation was missing");
|
type = ErrorUtils.createErrorType("Type annotation was missing");
|
||||||
} else {
|
} else {
|
||||||
type = typeResolver.resolveType(parameterScope, typeReference);
|
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);
|
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
||||||
result.add(valueParameterDescriptor);
|
result.add(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
@@ -258,7 +340,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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 varargElementType = null;
|
||||||
JetType variableType = type;
|
JetType variableType = type;
|
||||||
if (valueParameter.hasModifier(JetTokens.VARARG_KEYWORD)) {
|
if (valueParameter.hasModifier(JetTokens.VARARG_KEYWORD)) {
|
||||||
@@ -268,7 +350,7 @@ public class DescriptorResolver {
|
|||||||
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
MutableValueParameterDescriptor valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
||||||
declarationDescriptor,
|
declarationDescriptor,
|
||||||
index,
|
index,
|
||||||
annotationResolver.createAnnotationStubs(valueParameter.getModifierList()),
|
annotationResolver.createAnnotationStubs(valueParameter.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(valueParameter.getName()),
|
JetPsiUtil.safeName(valueParameter.getName()),
|
||||||
valueParameter.isMutable(),
|
valueParameter.isMutable(),
|
||||||
variableType,
|
variableType,
|
||||||
@@ -281,32 +363,31 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JetType getVarargParameterType(JetType type) {
|
private JetType getVarargParameterType(JetType type) {
|
||||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
JetType arrayType = JetStandardLibrary.getInstance().getPrimitiveArrayJetTypeByPrimitiveJetType(type);
|
||||||
JetType arrayType = standardLibrary.getPrimitiveArrayJetTypeByPrimitiveJetType(type);
|
|
||||||
if (arrayType != null) {
|
if (arrayType != null) {
|
||||||
return arrayType;
|
return arrayType;
|
||||||
} else {
|
} 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>();
|
List<TypeParameterDescriptor> result = new ArrayList<TypeParameterDescriptor>();
|
||||||
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
|
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
|
||||||
JetTypeParameter typeParameter = typeParameters.get(i);
|
JetTypeParameter typeParameter = typeParameters.get(i);
|
||||||
result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter, i));
|
result.add(resolveTypeParameter(containingDescriptor, extensibleScope, typeParameter, i, trace));
|
||||||
}
|
}
|
||||||
return result;
|
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();
|
// JetTypeReference extendsBound = typeParameter.getExtendsBound();
|
||||||
// JetType bound = extendsBound == null
|
// JetType bound = extendsBound == null
|
||||||
// ? JetStandardClasses.getDefaultBound()
|
// ? JetStandardClasses.getDefaultBound()
|
||||||
// : typeResolver.resolveType(extensibleScope, extendsBound);
|
// : typeResolver.resolveType(extensibleScope, extendsBound);
|
||||||
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
|
TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptor.createForFurtherModification(
|
||||||
containingDescriptor,
|
containingDescriptor,
|
||||||
annotationResolver.createAnnotationStubs(typeParameter.getModifierList()),
|
annotationResolver.createAnnotationStubs(typeParameter.getModifierList(), trace),
|
||||||
!typeParameter.hasModifier(JetTokens.ERASED_KEYWORD),
|
!typeParameter.hasModifier(JetTokens.ERASED_KEYWORD),
|
||||||
typeParameter.getVariance(),
|
typeParameter.getVariance(),
|
||||||
JetPsiUtil.safeName(typeParameter.getName()),
|
JetPsiUtil.safeName(typeParameter.getName()),
|
||||||
@@ -318,7 +399,7 @@ public class DescriptorResolver {
|
|||||||
return typeParameterDescriptor;
|
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();
|
List<JetTypeParameter> typeParameters = declaration.getTypeParameters();
|
||||||
Map<String, TypeParameterDescriptor> parameterByName = Maps.newHashMap();
|
Map<String, TypeParameterDescriptor> parameterByName = Maps.newHashMap();
|
||||||
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
|
for (int i = 0, typeParametersSize = typeParameters.size(); i < typeParametersSize; i++) {
|
||||||
@@ -327,7 +408,7 @@ public class DescriptorResolver {
|
|||||||
parameterByName.put(typeParameterDescriptor.getName(), typeParameterDescriptor);
|
parameterByName.put(typeParameterDescriptor.getName(), typeParameterDescriptor);
|
||||||
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
|
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
|
||||||
if (extendsBound != null) {
|
if (extendsBound != null) {
|
||||||
typeParameterDescriptor.addUpperBound(resolveAndCheckUpperBoundType(extendsBound, scope, false));
|
typeParameterDescriptor.addUpperBound(resolveAndCheckUpperBoundType(extendsBound, scope, false, trace));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (JetTypeConstraint constraint : declaration.getTypeConstaints()) {
|
for (JetTypeConstraint constraint : declaration.getTypeConstaints()) {
|
||||||
@@ -341,7 +422,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
TypeParameterDescriptor typeParameterDescriptor = parameterByName.get(referencedName);
|
TypeParameterDescriptor typeParameterDescriptor = parameterByName.get(referencedName);
|
||||||
JetTypeReference boundTypeReference = constraint.getBoundTypeReference();
|
JetTypeReference boundTypeReference = constraint.getBoundTypeReference();
|
||||||
JetType bound = boundTypeReference != null ? resolveAndCheckUpperBoundType(boundTypeReference, scope, constraint.isClassObjectContraint()) : null;
|
JetType bound = boundTypeReference != null ? resolveAndCheckUpperBoundType(boundTypeReference, scope, constraint.isClassObjectContraint(), trace) : null;
|
||||||
if (typeParameterDescriptor == null) {
|
if (typeParameterDescriptor == null) {
|
||||||
// To tell the user that we look only for locally defined type parameters
|
// To tell the user that we look only for locally defined type parameters
|
||||||
ClassifierDescriptor classifier = scope.getClassifier(referencedName);
|
ClassifierDescriptor classifier = scope.getClassifier(referencedName);
|
||||||
@@ -388,9 +469,9 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetType resolveAndCheckUpperBoundType(@NotNull JetTypeReference upperBound, @NotNull JetScope scope, boolean classObjectConstaint) {
|
private JetType resolveAndCheckUpperBoundType(@NotNull JetTypeReference upperBound, @NotNull JetScope scope, boolean classObjectConstaint, BindingTrace trace) {
|
||||||
JetType jetType = typeResolverNotCheckingBounds.resolveType(scope, upperBound);
|
JetType jetType = typeResolver.resolveType(scope, upperBound, trace, false);
|
||||||
if (!TypeUtils.canHaveSubtypes(semanticServices.getTypeChecker(), jetType)) {
|
if (!TypeUtils.canHaveSubtypes(JetTypeChecker.INSTANCE, jetType)) {
|
||||||
if (classObjectConstaint) {
|
if (classObjectConstaint) {
|
||||||
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, jetType));
|
trace.report(FINAL_CLASS_OBJECT_UPPER_BOUND.on(upperBound, jetType));
|
||||||
}
|
}
|
||||||
@@ -402,16 +483,16 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter) {
|
public VariableDescriptor resolveLocalVariableDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter, BindingTrace trace) {
|
||||||
JetType type = resolveParameterType(scope, parameter);
|
JetType type = resolveParameterType(scope, parameter, trace);
|
||||||
return resolveLocalVariableDescriptor(containingDeclaration, parameter, type);
|
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();
|
JetTypeReference typeReference = parameter.getTypeReference();
|
||||||
JetType type;
|
JetType type;
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
type = typeResolver.resolveType(scope, typeReference);
|
type = typeResolver.resolveType(scope, typeReference, trace, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Error is reported by the parser
|
// Error is reported by the parser
|
||||||
@@ -420,10 +501,10 @@ public class DescriptorResolver {
|
|||||||
return type;
|
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(
|
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotationResolver.createAnnotationStubs(parameter.getModifierList()),
|
annotationResolver.createAnnotationStubs(parameter.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(parameter.getName()),
|
JetPsiUtil.safeName(parameter.getName()),
|
||||||
type,
|
type,
|
||||||
parameter.isMutable());
|
parameter.isMutable());
|
||||||
@@ -432,19 +513,19 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public VariableDescriptor resolveLocalVariableDescriptor(DeclarationDescriptor containingDeclaration, JetScope scope, JetProperty property, DataFlowInfo dataFlowInfo) {
|
public VariableDescriptor resolveLocalVariableDescriptor(DeclarationDescriptor containingDeclaration, JetScope scope, JetProperty property, DataFlowInfo dataFlowInfo, BindingTrace trace) {
|
||||||
VariableDescriptorImpl variableDescriptor = resolveLocalVariableDescriptorWithType(containingDeclaration, property, null);
|
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);
|
variableDescriptor.setOutType(type);
|
||||||
return variableDescriptor;
|
return variableDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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(
|
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotationResolver.createAnnotationStubs(property.getModifierList()),
|
annotationResolver.createAnnotationStubs(property.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(property.getName()),
|
JetPsiUtil.safeName(property.getName()),
|
||||||
type,
|
type,
|
||||||
property.isVar());
|
property.isVar());
|
||||||
@@ -454,26 +535,26 @@ public class DescriptorResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public VariableDescriptor resolveObjectDeclaration(@NotNull DeclarationDescriptor containingDeclaration,
|
public VariableDescriptor resolveObjectDeclaration(@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull JetClassOrObject objectDeclaration,
|
@NotNull JetClassOrObject objectDeclaration,
|
||||||
@NotNull ClassDescriptor classDescriptor) {
|
@NotNull ClassDescriptor classDescriptor, BindingTrace trace) {
|
||||||
boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor)
|
boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor)
|
||||||
|| (containingDeclaration instanceof ClassDescriptor);
|
|| (containingDeclaration instanceof ClassDescriptor);
|
||||||
if (isProperty) {
|
if (isProperty) {
|
||||||
return resolveObjectDeclarationAsPropertyDescriptor(containingDeclaration, objectDeclaration, classDescriptor);
|
return resolveObjectDeclarationAsPropertyDescriptor(containingDeclaration, objectDeclaration, classDescriptor, trace);
|
||||||
} else {
|
} else {
|
||||||
return resolveObjectDeclarationAsLocalVariable(containingDeclaration, objectDeclaration, classDescriptor);
|
return resolveObjectDeclarationAsLocalVariable(containingDeclaration, objectDeclaration, classDescriptor, trace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PropertyDescriptor resolveObjectDeclarationAsPropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
|
public PropertyDescriptor resolveObjectDeclarationAsPropertyDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull JetClassOrObject objectDeclaration,
|
@NotNull JetClassOrObject objectDeclaration,
|
||||||
@NotNull ClassDescriptor classDescriptor) {
|
@NotNull ClassDescriptor classDescriptor, BindingTrace trace) {
|
||||||
JetModifierList modifierList = objectDeclaration.getModifierList();
|
JetModifierList modifierList = objectDeclaration.getModifierList();
|
||||||
Visibility visibility = resolveVisibilityFromModifiers(objectDeclaration.getModifierList());
|
Visibility visibility = resolveVisibilityFromModifiers(objectDeclaration.getModifierList());
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotationResolver.createAnnotationStubs(modifierList),
|
annotationResolver.createAnnotationStubs(modifierList, trace),
|
||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
visibility,
|
visibility,
|
||||||
false,
|
false,
|
||||||
@@ -492,11 +573,11 @@ public class DescriptorResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private VariableDescriptor resolveObjectDeclarationAsLocalVariable(@NotNull DeclarationDescriptor containingDeclaration,
|
private VariableDescriptor resolveObjectDeclarationAsLocalVariable(@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull JetClassOrObject objectDeclaration,
|
@NotNull JetClassOrObject objectDeclaration,
|
||||||
@NotNull ClassDescriptor classDescriptor) {
|
@NotNull ClassDescriptor classDescriptor, BindingTrace trace) {
|
||||||
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
VariableDescriptorImpl variableDescriptor = new LocalVariableDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotationResolver.createAnnotationStubs(objectDeclaration.getModifierList()),
|
annotationResolver.createAnnotationStubs(objectDeclaration.getModifierList(), trace),
|
||||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||||
classDescriptor.getDefaultType(),
|
classDescriptor.getDefaultType(),
|
||||||
/*isVar =*/ false);
|
/*isVar =*/ false);
|
||||||
@@ -508,8 +589,8 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope,
|
public JetScope getPropertyDeclarationInnerScope(@NotNull JetScope outerScope,
|
||||||
@NotNull PropertyDescriptor propertyDescriptor, List<TypeParameterDescriptor> typeParameters,
|
@NotNull PropertyDescriptor propertyDescriptor, List<TypeParameterDescriptor> typeParameters,
|
||||||
ReceiverDescriptor receiver) {
|
ReceiverDescriptor receiver, BindingTrace trace) {
|
||||||
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope");
|
WritableScopeImpl result = new WritableScopeImpl(outerScope, propertyDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Property declaration inner scope");
|
||||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||||
result.addTypeParameterDescriptor(typeParameterDescriptor);
|
result.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||||
@@ -522,7 +603,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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();
|
JetModifierList modifierList = property.getModifierList();
|
||||||
boolean isVar = property.isVar();
|
boolean isVar = property.isVar();
|
||||||
@@ -531,7 +612,7 @@ public class DescriptorResolver {
|
|||||||
Modality defaultModality = getDefaultModality(containingDeclaration, hasBody);
|
Modality defaultModality = getDefaultModality(containingDeclaration, hasBody);
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
annotationResolver.resolveAnnotations(scope, modifierList),
|
annotationResolver.resolveAnnotations(scope, modifierList, trace),
|
||||||
resolveModalityFromModifiers(property.getModifierList(), defaultModality),
|
resolveModalityFromModifiers(property.getModifierList(), defaultModality),
|
||||||
resolveVisibilityFromModifiers(property.getModifierList()),
|
resolveVisibilityFromModifiers(property.getModifierList()),
|
||||||
isVar,
|
isVar,
|
||||||
@@ -552,15 +633,15 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
|
WritableScope writableScope = new WritableScopeImpl(scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace)).setDebugName("Scope with type parameters of a property");
|
||||||
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters);
|
typeParameterDescriptors = resolveTypeParameters(containingDeclaration, writableScope, typeParameters, trace);
|
||||||
writableScope.changeLockLevel(WritableScope.LockLevel.READING);
|
writableScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
resolveGenericBounds(property, writableScope, typeParameterDescriptors);
|
resolveGenericBounds(property, writableScope, typeParameterDescriptors, trace);
|
||||||
scopeWithTypeParameters = writableScope;
|
scopeWithTypeParameters = writableScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
JetTypeReference receiverTypeRef = property.getReceiverTypeRef();
|
JetTypeReference receiverTypeRef = property.getReceiverTypeRef();
|
||||||
if (receiverTypeRef != null) {
|
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
|
? ReceiverDescriptor.NO_RECEIVER
|
||||||
: new ExtensionReceiver(propertyDescriptor, receiverType);
|
: 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);
|
propertyDescriptor.setType(type, typeParameterDescriptors, DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), receiverDescriptor);
|
||||||
|
|
||||||
PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
|
PropertyGetterDescriptor getter = resolvePropertyGetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace);
|
||||||
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor);
|
PropertySetterDescriptor setter = resolvePropertySetterDescriptor(scopeWithTypeParameters, property, propertyDescriptor, trace);
|
||||||
|
|
||||||
propertyDescriptor.initialize(getter, setter);
|
propertyDescriptor.initialize(getter, setter);
|
||||||
|
|
||||||
@@ -599,7 +680,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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?
|
// TODO : receiver?
|
||||||
JetTypeReference propertyTypeRef = property.getPropertyTypeRef();
|
JetTypeReference propertyTypeRef = property.getPropertyTypeRef();
|
||||||
|
|
||||||
@@ -616,7 +697,7 @@ public class DescriptorResolver {
|
|||||||
LazyValue<JetType> lazyValue = new LazyValueWithDefault<JetType>(ErrorUtils.createErrorType("Recursive dependency")) {
|
LazyValue<JetType> lazyValue = new LazyValueWithDefault<JetType>(ErrorUtils.createErrorType("Recursive dependency")) {
|
||||||
@Override
|
@Override
|
||||||
protected JetType compute() {
|
protected JetType compute() {
|
||||||
return semanticServices.getTypeInferrerServices(trace).safeGetType(scope, initializer, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo);
|
return expressionTypingServices.safeGetType(scope, initializer, TypeUtils.NO_EXPECTED_TYPE, dataFlowInfo, trace);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (allowDeferred) {
|
if (allowDeferred) {
|
||||||
@@ -627,7 +708,7 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return typeResolver.resolveType(scope, propertyTypeRef);
|
return typeResolver.resolveType(scope, propertyTypeRef, trace, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,11 +757,11 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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();
|
JetPropertyAccessor setter = property.getSetter();
|
||||||
PropertySetterDescriptor setterDescriptor = null;
|
PropertySetterDescriptor setterDescriptor = null;
|
||||||
if (setter != 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();
|
JetParameter parameter = setter.getParameter();
|
||||||
|
|
||||||
setterDescriptor = new PropertySetterDescriptor(
|
setterDescriptor = new PropertySetterDescriptor(
|
||||||
@@ -701,7 +782,7 @@ public class DescriptorResolver {
|
|||||||
type = propertyDescriptor.getType(); // TODO : this maybe unknown at this point
|
type = propertyDescriptor.getType(); // TODO : this maybe unknown at this point
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
type = typeResolver.resolveType(scope, typeReference);
|
type = typeResolver.resolveType(scope, typeReference, trace, true);
|
||||||
JetType inType = propertyDescriptor.getType();
|
JetType inType = propertyDescriptor.getType();
|
||||||
if (inType != null) {
|
if (inType != null) {
|
||||||
if (!TypeUtils.equalTypes(type, inType)) {
|
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);
|
setterDescriptor.initialize(valueParameterDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -746,17 +827,17 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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;
|
PropertyGetterDescriptor getterDescriptor;
|
||||||
JetPropertyAccessor getter = property.getGetter();
|
JetPropertyAccessor getter = property.getGetter();
|
||||||
if (getter != null) {
|
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 outType = propertyDescriptor.getType();
|
||||||
JetType returnType = outType;
|
JetType returnType = outType;
|
||||||
JetTypeReference returnTypeReference = getter.getReturnTypeReference();
|
JetTypeReference returnTypeReference = getter.getReturnTypeReference();
|
||||||
if (returnTypeReference != null) {
|
if (returnTypeReference != null) {
|
||||||
returnType = typeResolver.resolveType(scope, returnTypeReference);
|
returnType = typeResolver.resolveType(scope, returnTypeReference, trace, true);
|
||||||
if (outType != null && !TypeUtils.equalTypes(returnType, outType)) {
|
if (outType != null && !TypeUtils.equalTypes(returnType, outType)) {
|
||||||
trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType()));
|
trace.report(WRONG_GETTER_RETURN_TYPE.on(returnTypeReference, propertyDescriptor.getReturnType()));
|
||||||
}
|
}
|
||||||
@@ -786,8 +867,8 @@ public class DescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConstructorDescriptorImpl resolveSecondaryConstructorDescriptor(@NotNull JetScope scope, @NotNull ClassDescriptor classDescriptor, @NotNull JetSecondaryConstructor constructor) {
|
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());
|
return createConstructorDescriptor(scope, classDescriptor, false, constructor.getModifierList(), constructor, classDescriptor.getTypeConstructor().getParameters(), constructor.getValueParameters(), trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -797,10 +878,10 @@ public class DescriptorResolver {
|
|||||||
boolean isPrimary,
|
boolean isPrimary,
|
||||||
@Nullable JetModifierList modifierList,
|
@Nullable JetModifierList modifierList,
|
||||||
@NotNull JetDeclaration declarationToTrace,
|
@NotNull JetDeclaration declarationToTrace,
|
||||||
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters) {
|
List<TypeParameterDescriptor> typeParameters, @NotNull List<JetParameter> valueParameters, BindingTrace trace) {
|
||||||
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
annotationResolver.resolveAnnotations(scope, modifierList),
|
annotationResolver.resolveAnnotations(scope, modifierList, trace),
|
||||||
isPrimary
|
isPrimary
|
||||||
);
|
);
|
||||||
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor);
|
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor);
|
||||||
@@ -811,12 +892,12 @@ public class DescriptorResolver {
|
|||||||
resolveValueParameters(
|
resolveValueParameters(
|
||||||
constructorDescriptor,
|
constructorDescriptor,
|
||||||
parameterScope,
|
parameterScope,
|
||||||
valueParameters),
|
valueParameters, trace),
|
||||||
resolveVisibilityFromModifiers(modifierList));
|
resolveVisibilityFromModifiers(modifierList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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;
|
if (classDescriptor.getKind() == ClassKind.ENUM_ENTRY && !classElement.hasPrimaryConstructor()) return null;
|
||||||
return createConstructorDescriptor(
|
return createConstructorDescriptor(
|
||||||
scope,
|
scope,
|
||||||
@@ -824,15 +905,15 @@ public class DescriptorResolver {
|
|||||||
true,
|
true,
|
||||||
classElement.getPrimaryConstructorModifierList(),
|
classElement.getPrimaryConstructorModifierList(),
|
||||||
classElement,
|
classElement,
|
||||||
classDescriptor.getTypeConstructor().getParameters(), classElement.getPrimaryConstructorParameters());
|
classDescriptor.getTypeConstructor().getParameters(), classElement.getPrimaryConstructorParameters(), trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PropertyDescriptor resolvePrimaryConstructorParameterToAProperty(
|
public PropertyDescriptor resolvePrimaryConstructorParameterToAProperty(
|
||||||
@NotNull ClassDescriptor classDescriptor,
|
@NotNull ClassDescriptor classDescriptor,
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@NotNull JetParameter parameter) {
|
@NotNull JetParameter parameter, BindingTrace trace) {
|
||||||
JetType type = resolveParameterType(scope, parameter);
|
JetType type = resolveParameterType(scope, parameter, trace);
|
||||||
String name = parameter.getName();
|
String name = parameter.getName();
|
||||||
boolean isMutable = parameter.isMutable();
|
boolean isMutable = parameter.isMutable();
|
||||||
JetModifierList modifierList = parameter.getModifierList();
|
JetModifierList modifierList = parameter.getModifierList();
|
||||||
@@ -846,7 +927,7 @@ public class DescriptorResolver {
|
|||||||
|
|
||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||||
classDescriptor,
|
classDescriptor,
|
||||||
annotationResolver.resolveAnnotations(scope, modifierList),
|
annotationResolver.resolveAnnotations(scope, modifierList, trace),
|
||||||
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
|
resolveModalityFromModifiers(parameter.getModifierList(), Modality.FINAL),
|
||||||
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
||||||
isMutable,
|
isMutable,
|
||||||
@@ -866,7 +947,7 @@ public class DescriptorResolver {
|
|||||||
return propertyDescriptor;
|
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;
|
if (ErrorUtils.isErrorType(type)) return;
|
||||||
|
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||||
@@ -886,10 +967,10 @@ public class DescriptorResolver {
|
|||||||
if (argumentTypeReference == null) continue;
|
if (argumentTypeReference == null) continue;
|
||||||
|
|
||||||
JetType typeArgument = arguments.get(i).getType();
|
JetType typeArgument = arguments.get(i).getType();
|
||||||
checkBounds(argumentTypeReference, typeArgument);
|
checkBounds(argumentTypeReference, typeArgument, trace);
|
||||||
|
|
||||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
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 JetTypeReference argumentTypeReference,
|
||||||
@NotNull JetType typeArgument,
|
@NotNull JetType typeArgument,
|
||||||
@NotNull TypeParameterDescriptor typeParameterDescriptor,
|
@NotNull TypeParameterDescriptor typeParameterDescriptor,
|
||||||
@NotNull TypeSubstitutor substitutor) {
|
@NotNull TypeSubstitutor substitutor, BindingTrace trace) {
|
||||||
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
|
for (JetType bound : typeParameterDescriptor.getUpperBounds()) {
|
||||||
JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT);
|
JetType substitutedBound = substitutor.safeSubstitute(bound, Variance.INVARIANT);
|
||||||
if (!semanticServices.getTypeChecker().isSubtypeOf(typeArgument, substitutedBound)) {
|
if (!JetTypeChecker.INSTANCE.isSubtypeOf(typeArgument, substitutedBound)) {
|
||||||
trace.report(UPPER_BOUND_VIOLATED.on(argumentTypeReference, 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.Collections2;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.Configuration;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
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 org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -32,19 +45,35 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
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 abreslav
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class ImportsResolver {
|
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;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public void setConfiguration(@NotNull Configuration configuration) {
|
||||||
|
this.configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void processTypeImports() {
|
public void processTypeImports() {
|
||||||
processImports(true);
|
processImports(true);
|
||||||
}
|
}
|
||||||
@@ -64,7 +93,7 @@ public class ImportsResolver {
|
|||||||
}
|
}
|
||||||
Map<JetImportDirective, DeclarationDescriptor> resolvedDirectives = Maps.newHashMap();
|
Map<JetImportDirective, DeclarationDescriptor> resolvedDirectives = Maps.newHashMap();
|
||||||
Collection<JetImportDirective> defaultImportDirectives = Lists.newArrayList();
|
Collection<JetImportDirective> defaultImportDirectives = Lists.newArrayList();
|
||||||
context.getConfiguration().addDefaultImports(namespaceScope, defaultImportDirectives);
|
configuration.addDefaultImports(namespaceScope, defaultImportDirectives);
|
||||||
for (JetImportDirective defaultImportDirective : defaultImportDirectives) {
|
for (JetImportDirective defaultImportDirective : defaultImportDirectives) {
|
||||||
defaultImportResolver.processImportReference(defaultImportDirective, namespaceScope, delayedImporter);
|
defaultImportResolver.processImportReference(defaultImportDirective, namespaceScope, delayedImporter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve;
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.util.containers.MultiMap;
|
import com.intellij.util.containers.MultiMap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -35,12 +36,15 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
|||||||
* @author Stepan Koltsov
|
* @author Stepan Koltsov
|
||||||
*/
|
*/
|
||||||
public class OverloadResolver {
|
public class OverloadResolver {
|
||||||
private final TopDownAnalysisContext context;
|
private TopDownAnalysisContext context;
|
||||||
|
|
||||||
public OverloadResolver(@NotNull TopDownAnalysisContext context) {
|
|
||||||
|
@Inject
|
||||||
|
public void setContext(TopDownAnalysisContext context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
checkOverloads();
|
checkOverloads();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.util.containers.MultiMap;
|
import com.intellij.util.containers.MultiMap;
|
||||||
@@ -43,12 +44,16 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.DELEGATED;
|
|||||||
*/
|
*/
|
||||||
public class OverrideResolver {
|
public class OverrideResolver {
|
||||||
|
|
||||||
private final TopDownAnalysisContext context;
|
private TopDownAnalysisContext context;
|
||||||
|
|
||||||
public OverrideResolver(@NotNull TopDownAnalysisContext context) {
|
|
||||||
|
@Inject
|
||||||
|
public void setContext(TopDownAnalysisContext context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void process() {
|
public void process() {
|
||||||
generateOverrides();
|
generateOverrides();
|
||||||
checkOverrides();
|
checkOverrides();
|
||||||
|
|||||||
@@ -19,13 +19,27 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
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.descriptors.ConstructorDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
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.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
|
|
||||||
@@ -36,14 +50,10 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
/*package*/ class TopDownAnalysisContext {
|
public class TopDownAnalysisContext {
|
||||||
|
|
||||||
private final ObservableBindingTrace trace;
|
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<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
|
||||||
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
|
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
|
||||||
protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap();
|
protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap();
|
||||||
@@ -58,17 +68,44 @@ import java.util.Set;
|
|||||||
private final Predicate<PsiFile> analyzeCompletely;
|
private final Predicate<PsiFile> analyzeCompletely;
|
||||||
|
|
||||||
private StringBuilder debugOutput;
|
private StringBuilder debugOutput;
|
||||||
private boolean analyzingBootstrapLibrary = false;
|
private final boolean analyzingBootstrapLibrary;
|
||||||
private boolean declaredLocally;
|
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.trace = new ObservableBindingTrace(trace);
|
||||||
this.semanticServices = semanticServices;
|
|
||||||
this.descriptorResolver = semanticServices.getClassDescriptorResolver(trace);
|
|
||||||
this.importsResolver = new ImportsResolver(this);
|
|
||||||
this.analyzeCompletely = analyzeCompletely;
|
this.analyzeCompletely = analyzeCompletely;
|
||||||
this.configuration = configuration;
|
|
||||||
this.declaredLocally = declaredLocally;
|
this.declaredLocally = declaredLocally;
|
||||||
|
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Injector getInjector() {
|
||||||
|
return injector;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(Object message) {
|
public void debug(Object message) {
|
||||||
@@ -93,10 +130,6 @@ import java.util.Set;
|
|||||||
return analyzingBootstrapLibrary;
|
return analyzingBootstrapLibrary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAnalyzingBootstrapLibrary(boolean analyzingBootstrapLibrary) {
|
|
||||||
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean completeAnalysisNeeded(@NotNull PsiElement element) {
|
public boolean completeAnalysisNeeded(@NotNull PsiElement element) {
|
||||||
PsiFile containingFile = element.getContainingFile();
|
PsiFile containingFile = element.getContainingFile();
|
||||||
boolean result = containingFile != null && analyzeCompletely.apply(containingFile);
|
boolean result = containingFile != null && analyzeCompletely.apply(containingFile);
|
||||||
@@ -106,22 +139,11 @@ import java.util.Set;
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public ObservableBindingTrace getTrace() {
|
public ObservableBindingTrace getTrace() {
|
||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetSemanticServices getSemanticServices() {
|
|
||||||
return semanticServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DescriptorResolver getDescriptorResolver() {
|
|
||||||
return descriptorResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ImportsResolver getImportsResolver() {
|
|
||||||
return importsResolver;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<JetClass, MutableClassDescriptor> getClasses() {
|
public Map<JetClass, MutableClassDescriptor> getClasses() {
|
||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
@@ -158,12 +180,8 @@ import java.util.Set;
|
|||||||
return functions;
|
return functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Configuration getConfiguration() {
|
|
||||||
return configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDeclaredLocally() {
|
public boolean isDeclaredLocally() {
|
||||||
return declaredLocally;
|
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.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
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.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
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.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||||
@@ -41,23 +42,59 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class TopDownAnalyzer {
|
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(
|
public static void process(
|
||||||
@NotNull JetSemanticServices semanticServices,
|
Project project, @NotNull BindingTrace trace,
|
||||||
@NotNull BindingTrace trace,
|
|
||||||
@NotNull JetScope outerScope,
|
@NotNull JetScope outerScope,
|
||||||
@NotNull NamespaceLike owner,
|
@NotNull NamespaceLike owner,
|
||||||
@NotNull Collection<JetFile> files,
|
@NotNull Collection<JetFile> files,
|
||||||
@NotNull Predicate<PsiFile> analyzeCompletely,
|
@NotNull Predicate<PsiFile> analyzeCompletely,
|
||||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||||
@NotNull Configuration configuration
|
@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(
|
private static void process(
|
||||||
@NotNull JetSemanticServices semanticServices,
|
@NotNull Project project,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope outerScope,
|
@NotNull JetScope outerScope,
|
||||||
@NotNull NamespaceLike owner,
|
@NotNull NamespaceLike owner,
|
||||||
@@ -66,29 +103,31 @@ public class TopDownAnalyzer {
|
|||||||
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
@NotNull JetControlFlowDataTraceFactory flowDataTraceFactory,
|
||||||
@NotNull Configuration configuration,
|
@NotNull Configuration configuration,
|
||||||
boolean declaredLocally) {
|
boolean declaredLocally) {
|
||||||
TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, analyzeCompletely, configuration, declaredLocally);
|
TopDownAnalysisContext context = new TopDownAnalysisContext(project, trace, analyzeCompletely, configuration, declaredLocally, false, flowDataTraceFactory);
|
||||||
doProcess(context, outerScope, owner, declarations, flowDataTraceFactory);
|
context.getInjector().getInstance(TopDownAnalyzer.class).doProcess(context, outerScope, owner, declarations);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doProcess(
|
private void doProcess(
|
||||||
TopDownAnalysisContext context, JetScope outerScope,
|
TopDownAnalysisContext context, JetScope outerScope,
|
||||||
NamespaceLike owner,
|
NamespaceLike owner,
|
||||||
Collection<? extends PsiElement> declarations,
|
Collection<? extends PsiElement> declarations) {
|
||||||
JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
|
||||||
// context.enableDebugOutput();
|
// context.enableDebugOutput();
|
||||||
context.debug("Enter");
|
context.debug("Enter");
|
||||||
|
|
||||||
new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
|
typeHierarchyResolver.process(outerScope, owner, declarations);
|
||||||
new DeclarationResolver(context).process();
|
declarationResolver.process();
|
||||||
new DelegationResolver(context).process();
|
delegationResolver.process();
|
||||||
new OverrideResolver(context).process();
|
overrideResolver.process();
|
||||||
|
|
||||||
lockScopes(context);
|
lockScopes(context);
|
||||||
new OverloadResolver(context).process();
|
|
||||||
|
overloadResolver.process();
|
||||||
|
|
||||||
if (!context.analyzingBootstrapLibrary()) {
|
if (!context.analyzingBootstrapLibrary()) {
|
||||||
new BodyResolver(context).resolveBehaviorDeclarationBodies();
|
context.getInjector().getInstance(BodyResolver.class).resolveBehaviorDeclarationBodies();
|
||||||
new ControlFlowAnalyzer(context, flowDataTraceFactory).process();
|
context.getInjector().getInstance(ControlFlowAnalyzer.class).process();
|
||||||
new DeclarationsChecker(context).process();
|
context.getInjector().getInstance(DeclarationsChecker.class).process();
|
||||||
}
|
}
|
||||||
|
|
||||||
context.debug("Exit");
|
context.debug("Exit");
|
||||||
@@ -109,12 +148,12 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void processStandardLibraryNamespace(
|
public static void processStandardLibraryNamespace(
|
||||||
@NotNull JetSemanticServices semanticServices,
|
@NotNull Project project,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull WritableScope outerScope,
|
@NotNull WritableScope outerScope,
|
||||||
@NotNull NamespaceDescriptorImpl standardLibraryNamespace,
|
@NotNull NamespaceDescriptorImpl standardLibraryNamespace,
|
||||||
@NotNull List<JetFile> files) {
|
@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>();
|
ArrayList<JetDeclaration> toAnalyze = new ArrayList<JetDeclaration>();
|
||||||
for(JetFile file : files) {
|
for(JetFile file : files) {
|
||||||
context.getNamespaceDescriptors().put(file, standardLibraryNamespace);
|
context.getNamespaceDescriptors().put(file, standardLibraryNamespace);
|
||||||
@@ -122,18 +161,17 @@ public class TopDownAnalyzer {
|
|||||||
toAnalyze.addAll(file.getDeclarations());
|
toAnalyze.addAll(file.getDeclarations());
|
||||||
}
|
}
|
||||||
// context.getDeclaringScopes().put(file, outerScope);
|
// 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(
|
public static void processObject(
|
||||||
@NotNull JetSemanticServices semanticServices,
|
@NotNull Project project,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope outerScope,
|
@NotNull JetScope outerScope,
|
||||||
@NotNull DeclarationDescriptor containingDeclaration,
|
@NotNull DeclarationDescriptor containingDeclaration,
|
||||||
@NotNull JetObjectDeclaration object) {
|
@NotNull JetObjectDeclaration object) {
|
||||||
process(semanticServices, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) {
|
process(project, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptorImpl getNamespace(String name) {
|
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.Lists;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.google.inject.Inject;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.lang.Configuration;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
@@ -47,18 +48,45 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class TypeHierarchyResolver {
|
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;
|
private LinkedList<MutableClassDescriptor> topologicalOrder;
|
||||||
|
|
||||||
|
|
||||||
public TypeHierarchyResolver(TopDownAnalysisContext context) {
|
@Inject
|
||||||
|
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||||
this.context = 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) {
|
public void process(@NotNull JetScope outerScope, @NotNull NamespaceLike owner, @NotNull Collection<? extends PsiElement> declarations) {
|
||||||
collectNamespacesAndClassifiers(outerScope, outerScope, owner, declarations); // namespaceScopes, classes
|
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
|
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)
|
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");
|
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, new TraceBasedRedeclarationHandler(context.getTrace())).setDebugName("Namespace member scope");
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
namespaceDescriptor.initialize(scope);
|
namespaceDescriptor.initialize(scope);
|
||||||
context.getConfiguration().extendNamespaceScope(context.getTrace(), namespaceDescriptor, scope);
|
configuration.extendNamespaceScope(context.getTrace(), namespaceDescriptor, scope);
|
||||||
owner.addNamespace(namespaceDescriptor);
|
owner.addNamespace(namespaceDescriptor);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
context.getTrace().record(BindingContext.NAMESPACE, file, namespaceDescriptor);
|
context.getTrace().record(BindingContext.NAMESPACE, file, namespaceDescriptor);
|
||||||
@@ -260,7 +288,7 @@ public class TypeHierarchyResolver {
|
|||||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||||
JetClass jetClass = entry.getKey();
|
JetClass jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
context.getDescriptorResolver().resolveMutableClassDescriptor(jetClass, descriptor);
|
descriptorResolver.resolveMutableClassDescriptor(jetClass, descriptor, context.getTrace());
|
||||||
descriptor.createTypeConstructor();
|
descriptor.createTypeConstructor();
|
||||||
}
|
}
|
||||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
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()) {
|
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||||
JetClass jetClass = entry.getKey();
|
JetClass jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
context.getDescriptorResolver().resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters());
|
descriptorResolver.resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters(), context.getTrace());
|
||||||
context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor);
|
descriptorResolver.resolveSupertypes(jetClass, descriptor, context.getTrace());
|
||||||
}
|
}
|
||||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
||||||
JetClassOrObject jetClass = entry.getKey();
|
JetClassOrObject jetClass = entry.getKey();
|
||||||
MutableClassDescriptor descriptor = entry.getValue();
|
MutableClassDescriptor descriptor = entry.getValue();
|
||||||
context.getDescriptorResolver().resolveSupertypes(jetClass, descriptor);
|
descriptorResolver.resolveSupertypes(jetClass, descriptor, context.getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +506,7 @@ public class TypeHierarchyResolver {
|
|||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference);
|
JetType type = context.getTrace().getBindingContext().get(TYPE, typeReference);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
context.getDescriptorResolver().checkBounds(typeReference, type);
|
descriptorResolver.checkBounds(typeReference, type, context.getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -488,7 +516,7 @@ public class TypeHierarchyResolver {
|
|||||||
if (extendsBound != null) {
|
if (extendsBound != null) {
|
||||||
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
context.getDescriptorResolver().checkBounds(extendsBound, type);
|
descriptorResolver.checkBounds(extendsBound, type, context.getTrace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -498,7 +526,7 @@ public class TypeHierarchyResolver {
|
|||||||
if (extendsBound != null) {
|
if (extendsBound != null) {
|
||||||
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
JetType type = context.getTrace().getBindingContext().get(TYPE, extendsBound);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
context.getDescriptorResolver().checkBounds(extendsBound, type);
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
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.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
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.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
import org.jetbrains.jet.util.lazy.LazyValue;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
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;
|
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 {
|
public class TypeResolver {
|
||||||
|
|
||||||
private final JetSemanticServices semanticServices;
|
private AnnotationResolver annotationResolver;
|
||||||
private final BindingTrace trace;
|
private DescriptorResolver descriptorResolver;
|
||||||
private final boolean checkBounds;
|
|
||||||
private final AnnotationResolver annotationResolver;
|
|
||||||
|
|
||||||
public TypeResolver(JetSemanticServices semanticServices, BindingTrace trace, boolean checkBounds) {
|
@Inject
|
||||||
this.semanticServices = semanticServices;
|
public void setDescriptorResolver(DescriptorResolver descriptorResolver) {
|
||||||
this.trace = trace;
|
this.descriptorResolver = descriptorResolver;
|
||||||
this.checkBounds = checkBounds;
|
}
|
||||||
this.annotationResolver = new AnnotationResolver(semanticServices, trace);
|
|
||||||
|
@Inject
|
||||||
|
public void setAnnotationResolver(AnnotationResolver annotationResolver) {
|
||||||
|
this.annotationResolver = annotationResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference) {
|
public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference, BindingTrace trace, boolean checkBounds) {
|
||||||
JetType cachedType = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
|
JetType cachedType = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
|
||||||
if (cachedType != null) return cachedType;
|
if (cachedType != null) return cachedType;
|
||||||
|
|
||||||
final List<AnnotationDescriptor> annotations = annotationResolver.createAnnotationStubs(typeReference.getAnnotations());
|
final List<AnnotationDescriptor> annotations = annotationResolver.createAnnotationStubs(typeReference.getAnnotations(), trace);
|
||||||
|
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
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);
|
trace.record(BindingContext.TYPE, typeReference, type);
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
@@ -71,7 +92,7 @@ public class TypeResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations,
|
private JetType resolveTypeElement(final JetScope scope, final List<AnnotationDescriptor> annotations,
|
||||||
JetTypeElement typeElement, final boolean nullable) {
|
JetTypeElement typeElement, final boolean nullable, final BindingTrace trace, final boolean checkBounds) {
|
||||||
|
|
||||||
final JetType[] result = new JetType[1];
|
final JetType[] result = new JetType[1];
|
||||||
if (typeElement != null) {
|
if (typeElement != null) {
|
||||||
@@ -84,9 +105,9 @@ public class TypeResolver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassifierDescriptor classifierDescriptor = resolveClass(scope, type);
|
ClassifierDescriptor classifierDescriptor = resolveClass(scope, type, trace);
|
||||||
if (classifierDescriptor == null) {
|
if (classifierDescriptor == null) {
|
||||||
resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments());
|
resolveTypeProjections(scope, ErrorUtils.createErrorType("No type").getConstructor(), type.getTypeArguments(), trace, checkBounds);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +116,7 @@ public class TypeResolver {
|
|||||||
|
|
||||||
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, typeParameterDescriptor);
|
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, typeParameterDescriptor);
|
||||||
|
|
||||||
JetScope scopeForTypeParameter = getScopeForTypeParameter(typeParameterDescriptor);
|
JetScope scopeForTypeParameter = getScopeForTypeParameter(typeParameterDescriptor, checkBounds);
|
||||||
if (scopeForTypeParameter instanceof ErrorUtils.ErrorScope) {
|
if (scopeForTypeParameter instanceof ErrorUtils.ErrorScope) {
|
||||||
result[0] = ErrorUtils.createErrorType("?");
|
result[0] = ErrorUtils.createErrorType("?");
|
||||||
} else {
|
} 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) {
|
else if (classifierDescriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
|
||||||
|
|
||||||
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor);
|
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor);
|
||||||
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
|
TypeConstructor typeConstructor = classifierDescriptor.getTypeConstructor();
|
||||||
List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments());
|
List<TypeProjection> arguments = resolveTypeProjections(scope, typeConstructor, type.getTypeArguments(), trace, checkBounds);
|
||||||
List<TypeParameterDescriptor> parameters = typeConstructor.getParameters();
|
List<TypeParameterDescriptor> parameters = typeConstructor.getParameters();
|
||||||
int expectedArgumentCount = parameters.size();
|
int expectedArgumentCount = parameters.size();
|
||||||
int actualArgumentCount = arguments.size();
|
int actualArgumentCount = arguments.size();
|
||||||
@@ -145,7 +166,7 @@ public class TypeResolver {
|
|||||||
JetTypeReference typeReference = type.getTypeArguments().get(i).getTypeReference();
|
JetTypeReference typeReference = type.getTypeArguments().get(i).getTypeReference();
|
||||||
|
|
||||||
if (typeReference != null) {
|
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
|
@Override
|
||||||
public void visitNullableType(JetNullableType nullableType) {
|
public void visitNullableType(JetNullableType nullableType) {
|
||||||
result[0] = resolveTypeElement(scope, annotations, nullableType.getInnerType(), true);
|
result[0] = resolveTypeElement(scope, annotations, nullableType.getInnerType(), true, trace, checkBounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitTupleType(JetTupleType type) {
|
public void visitTupleType(JetTupleType type) {
|
||||||
// TODO labels
|
// TODO labels
|
||||||
result[0] = JetStandardClasses.getTupleType(resolveTypes(scope, type.getComponentTypeRefs()));
|
result[0] = JetStandardClasses.getTupleType(resolveTypes(scope, type.getComponentTypeRefs(), trace, checkBounds));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitFunctionType(JetFunctionType type) {
|
public void visitFunctionType(JetFunctionType type) {
|
||||||
JetTypeReference receiverTypeRef = type.getReceiverTypeRef();
|
JetTypeReference receiverTypeRef = type.getReceiverTypeRef();
|
||||||
JetType receiverType = receiverTypeRef == null ? null : resolveType(scope, receiverTypeRef);
|
JetType receiverType = receiverTypeRef == null ? null : resolveType(scope, receiverTypeRef, trace, checkBounds);
|
||||||
|
|
||||||
List<JetType> parameterTypes = new ArrayList<JetType>();
|
List<JetType> parameterTypes = new ArrayList<JetType>();
|
||||||
for (JetParameter parameter : type.getParameters()) {
|
for (JetParameter parameter : type.getParameters()) {
|
||||||
parameterTypes.add(resolveType(scope, parameter.getTypeReference()));
|
parameterTypes.add(resolveType(scope, parameter.getTypeReference(), trace, checkBounds));
|
||||||
}
|
}
|
||||||
|
|
||||||
JetTypeReference returnTypeRef = type.getReturnTypeRef();
|
JetTypeReference returnTypeRef = type.getReturnTypeRef();
|
||||||
JetType returnType;
|
JetType returnType;
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
returnType = resolveType(scope, returnTypeRef);
|
returnType = resolveType(scope, returnTypeRef, trace, checkBounds);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
returnType = JetStandardClasses.getUnitType();
|
returnType = JetStandardClasses.getUnitType();
|
||||||
@@ -202,7 +223,7 @@ public class TypeResolver {
|
|||||||
return result[0];
|
return result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetScope getScopeForTypeParameter(final TypeParameterDescriptor typeParameterDescriptor) {
|
private JetScope getScopeForTypeParameter(final TypeParameterDescriptor typeParameterDescriptor, boolean checkBounds) {
|
||||||
if (checkBounds) {
|
if (checkBounds) {
|
||||||
return typeParameterDescriptor.getUpperBoundsAsType().getMemberScope();
|
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>();
|
final List<JetType> arguments = new ArrayList<JetType>();
|
||||||
for (JetTypeReference argumentElement : argumentElements) {
|
for (JetTypeReference argumentElement : argumentElements) {
|
||||||
arguments.add(resolveType(scope, argumentElement));
|
arguments.add(resolveType(scope, argumentElement, trace, checkBounds));
|
||||||
}
|
}
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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>();
|
final List<TypeProjection> arguments = new ArrayList<TypeProjection>();
|
||||||
for (int i = 0, argumentElementsSize = argumentElements.size(); i < argumentElementsSize; i++) {
|
for (int i = 0, argumentElementsSize = argumentElements.size(); i < argumentElementsSize; i++) {
|
||||||
JetTypeProjection argumentElement = argumentElements.get(i);
|
JetTypeProjection argumentElement = argumentElements.get(i);
|
||||||
@@ -244,7 +265,7 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO : handle the Foo<in *> case
|
// TODO : handle the Foo<in *> case
|
||||||
type = resolveType(scope, argumentElement.getTypeReference());
|
type = resolveType(scope, argumentElement.getTypeReference(), trace, checkBounds);
|
||||||
Variance kind = null;
|
Variance kind = null;
|
||||||
switch (projectionKind) {
|
switch (projectionKind) {
|
||||||
case IN:
|
case IN:
|
||||||
@@ -265,8 +286,8 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ClassifierDescriptor resolveClass(JetScope scope, JetUserType userType) {
|
public ClassifierDescriptor resolveClass(JetScope scope, JetUserType userType, BindingTrace trace) {
|
||||||
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
|
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType, trace);
|
||||||
|
|
||||||
if (classifierDescriptor == null) {
|
if (classifierDescriptor == null) {
|
||||||
trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression()));
|
trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression()));
|
||||||
@@ -279,7 +300,7 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private ClassifierDescriptor resolveClassWithoutErrorReporting(JetScope scope, JetUserType userType) {
|
private ClassifierDescriptor resolveClassWithoutErrorReporting(JetScope scope, JetUserType userType, BindingTrace trace) {
|
||||||
JetSimpleNameExpression expression = userType.getReferenceExpression();
|
JetSimpleNameExpression expression = userType.getReferenceExpression();
|
||||||
if (expression == null) {
|
if (expression == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -292,12 +313,12 @@ public class TypeResolver {
|
|||||||
if (userType.isAbsoluteInRootNamespace()) {
|
if (userType.isAbsoluteInRootNamespace()) {
|
||||||
classifierDescriptor = JetModuleUtil.getRootNamespaceType(userType).getMemberScope().getClassifier(referencedName);
|
classifierDescriptor = JetModuleUtil.getRootNamespaceType(userType).getMemberScope().getClassifier(referencedName);
|
||||||
trace.record(BindingContext.RESOLUTION_SCOPE, userType.getReferenceExpression(),
|
trace.record(BindingContext.RESOLUTION_SCOPE, userType.getReferenceExpression(),
|
||||||
JetModuleUtil.getRootNamespaceType(userType).getMemberScope());
|
JetModuleUtil.getRootNamespaceType(userType).getMemberScope());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetUserType qualifier = userType.getQualifier();
|
JetUserType qualifier = userType.getQualifier();
|
||||||
if (qualifier != null) {
|
if (qualifier != null) {
|
||||||
scope = resolveClassLookupScope(scope, qualifier);
|
scope = resolveClassLookupScope(scope, qualifier, trace);
|
||||||
}
|
}
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
return ErrorUtils.getErrorClass();
|
return ErrorUtils.getErrorClass();
|
||||||
@@ -310,8 +331,8 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private JetScope resolveClassLookupScope(JetScope scope, JetUserType userType) {
|
private JetScope resolveClassLookupScope(JetScope scope, JetUserType userType, BindingTrace trace) {
|
||||||
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
|
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType, trace);
|
||||||
if (classifierDescriptor instanceof ClassDescriptor) {
|
if (classifierDescriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) classifierDescriptor;
|
||||||
JetType classObjectType = classDescriptor.getClassObjectType();
|
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) {
|
if (namespaceDescriptor == null) {
|
||||||
trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression()));
|
trace.report(UNRESOLVED_REFERENCE.on(userType.getReferenceExpression()));
|
||||||
return null;
|
return null;
|
||||||
@@ -329,15 +350,15 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private NamespaceDescriptor resolveNamespace(JetScope scope, JetUserType userType) {
|
private NamespaceDescriptor resolveNamespace(JetScope scope, JetUserType userType, BindingTrace trace) {
|
||||||
if (userType.isAbsoluteInRootNamespace()) {
|
if (userType.isAbsoluteInRootNamespace()) {
|
||||||
return resolveNamespace(JetModuleUtil.getRootNamespaceType(userType).getMemberScope(), userType);
|
return resolveNamespace(JetModuleUtil.getRootNamespaceType(userType).getMemberScope(), userType, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetUserType qualifier = userType.getQualifier();
|
JetUserType qualifier = userType.getQualifier();
|
||||||
NamespaceDescriptor namespace;
|
NamespaceDescriptor namespace;
|
||||||
if (qualifier != null) {
|
if (qualifier != null) {
|
||||||
NamespaceDescriptor domain = resolveNamespace(scope, qualifier);
|
NamespaceDescriptor domain = resolveNamespace(scope, qualifier, trace);
|
||||||
if (domain == null) {
|
if (domain == null) {
|
||||||
return 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.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.google.inject.Inject;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
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.ExpressionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
@@ -56,22 +57,47 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
|||||||
public class CallResolver {
|
public class CallResolver {
|
||||||
private static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
|
private static final JetType DONT_CARE = ErrorUtils.createErrorTypeWithCustomDebugName("DONT_CARE");
|
||||||
|
|
||||||
private final JetSemanticServices semanticServices;
|
private final JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||||
private final OverloadingConflictResolver overloadingConflictResolver;
|
|
||||||
private final DataFlowInfo dataFlowInfo;
|
|
||||||
|
|
||||||
public CallResolver(JetSemanticServices semanticServices, DataFlowInfo dataFlowInfo) {
|
@NotNull
|
||||||
this.semanticServices = semanticServices;
|
private OverloadingConflictResolver overloadingConflictResolver;
|
||||||
this.overloadingConflictResolver = new OverloadingConflictResolver(semanticServices);
|
@NotNull
|
||||||
this.dataFlowInfo = dataFlowInfo;
|
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
|
@NotNull
|
||||||
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(
|
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@NotNull Call call,
|
@NotNull Call call,
|
||||||
@NotNull JetType expectedType) {
|
@NotNull JetType expectedType,
|
||||||
|
@NotNull DataFlowInfo dataFlowInfo) {
|
||||||
JetExpression calleeExpression = call.getCalleeExpression();
|
JetExpression calleeExpression = call.getCalleeExpression();
|
||||||
assert calleeExpression instanceof JetSimpleNameExpression;
|
assert calleeExpression instanceof JetSimpleNameExpression;
|
||||||
JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) calleeExpression;
|
JetSimpleNameExpression nameExpression = (JetSimpleNameExpression) calleeExpression;
|
||||||
@@ -88,7 +114,7 @@ public class CallResolver {
|
|||||||
task_prioritizer = TaskPrioritizers.VARIABLE_TASK_PRIORITIZER;
|
task_prioritizer = TaskPrioritizers.VARIABLE_TASK_PRIORITIZER;
|
||||||
}
|
}
|
||||||
List<ResolutionTask<VariableDescriptor>> prioritizedTasks = task_prioritizer.computePrioritizedTasks(scope, call, referencedName, trace.getBindingContext(), dataFlowInfo);
|
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
|
@NotNull
|
||||||
@@ -96,9 +122,9 @@ public class CallResolver {
|
|||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@NotNull Call call,
|
@NotNull Call call,
|
||||||
@NotNull JetType expectedType
|
@NotNull JetType expectedType,
|
||||||
) {
|
@NotNull DataFlowInfo dataFlowInfo) {
|
||||||
return resolveSimpleCallToFunctionDescriptor(trace, scope, call, expectedType);
|
return resolveSimpleCallToFunctionDescriptor(trace, scope, call, expectedType, dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -108,10 +134,10 @@ public class CallResolver {
|
|||||||
@NotNull final Call call,
|
@NotNull final Call call,
|
||||||
@NotNull final JetReferenceExpression functionReference,
|
@NotNull final JetReferenceExpression functionReference,
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@NotNull JetType expectedType) {
|
@NotNull JetType expectedType, DataFlowInfo dataFlowInfo) {
|
||||||
List<ResolutionTask<FunctionDescriptor>> tasks = TaskPrioritizers.FUNCTION_TASK_PRIORITIZER.computePrioritizedTasks(
|
List<ResolutionTask<FunctionDescriptor>> tasks = TaskPrioritizers.FUNCTION_TASK_PRIORITIZER.computePrioritizedTasks(
|
||||||
scope, call, name, trace.getBindingContext(), dataFlowInfo);
|
scope, call, name, trace.getBindingContext(), dataFlowInfo);
|
||||||
return doResolveCall(trace, scope, call, expectedType, tasks, functionReference);
|
return doResolveCall(trace, scope, call, expectedType, tasks, functionReference, dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -119,8 +145,8 @@ public class CallResolver {
|
|||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope scope,
|
@NotNull JetScope scope,
|
||||||
@NotNull final Call call,
|
@NotNull final Call call,
|
||||||
@NotNull JetType expectedType
|
@NotNull JetType expectedType,
|
||||||
) {
|
@NotNull DataFlowInfo dataFlowInfo) {
|
||||||
List<ResolutionTask<FunctionDescriptor>> prioritizedTasks;
|
List<ResolutionTask<FunctionDescriptor>> prioritizedTasks;
|
||||||
|
|
||||||
JetExpression calleeExpression = call.getCalleeExpression();
|
JetExpression calleeExpression = call.getCalleeExpression();
|
||||||
@@ -165,7 +191,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
JetTypeReference typeReference = expression.getTypeReference();
|
JetTypeReference typeReference = expression.getTypeReference();
|
||||||
assert typeReference != null;
|
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();
|
DeclarationDescriptor declarationDescriptor = constructedType.getConstructor().getDeclarationDescriptor();
|
||||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||||
@@ -199,8 +225,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
else if (calleeExpression != null) {
|
else if (calleeExpression != null) {
|
||||||
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
||||||
ExpressionTypingServices typingServices = new ExpressionTypingServices(semanticServices, trace);
|
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
|
||||||
JetType calleeType = typingServices.safeGetType(scope, calleeExpression, NO_EXPECTED_TYPE); // We are actually expecting a function, but there seems to be no easy way of expressing this
|
|
||||||
|
|
||||||
if (!JetStandardClasses.isFunctionType(calleeType)) {
|
if (!JetStandardClasses.isFunctionType(calleeType)) {
|
||||||
// checkTypesWithNoCallee(trace, scope, call);
|
// checkTypesWithNoCallee(trace, scope, call);
|
||||||
@@ -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) {
|
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 final Call call,
|
||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull final List<ResolutionTask<D>> prioritizedTasks, // high to low priority
|
@NotNull final List<ResolutionTask<D>> prioritizedTasks, // high to low priority
|
||||||
@NotNull final JetReferenceExpression reference) {
|
@NotNull final JetReferenceExpression reference,
|
||||||
return doResolveCall(trace, scope, call, expectedType, prioritizedTasks, reference);
|
@NotNull DataFlowInfo dataFlowInfo) {
|
||||||
|
return doResolveCall(trace, scope, call, expectedType, prioritizedTasks, reference, dataFlowInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -254,7 +280,8 @@ public class CallResolver {
|
|||||||
@NotNull final Call call,
|
@NotNull final Call call,
|
||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull final List<ResolutionTask<D>> prioritizedTasks, // high to low priority
|
@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();
|
ResolutionDebugInfo.Data debugInfo = ResolutionDebugInfo.create();
|
||||||
trace.record(ResolutionDebugInfo.RESOLUTION_DEBUG_INFO, call.getCallElement(), debugInfo);
|
trace.record(ResolutionDebugInfo.RESOLUTION_DEBUG_INFO, call.getCallElement(), debugInfo);
|
||||||
@@ -402,7 +429,7 @@ public class CallResolver {
|
|||||||
OverloadResolutionResultsImpl<D> resultsForFirstNonemptyCandidateSet = null;
|
OverloadResolutionResultsImpl<D> resultsForFirstNonemptyCandidateSet = null;
|
||||||
for (ResolutionTask<D> task : prioritizedTasks) {
|
for (ResolutionTask<D> task : prioritizedTasks) {
|
||||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(trace);
|
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()) {
|
if (results.isSuccess()) {
|
||||||
temporaryTrace.commit();
|
temporaryTrace.commit();
|
||||||
|
|
||||||
@@ -435,9 +462,9 @@ public class CallResolver {
|
|||||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolutionGuardedForExtraFunctionLiteralArguments(
|
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolutionGuardedForExtraFunctionLiteralArguments(
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope scope, @NotNull JetType expectedType,
|
@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:
|
// If resolution fails, we should check for some of the following situations:
|
||||||
// class A {
|
// class A {
|
||||||
@@ -471,7 +498,7 @@ public class CallResolver {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}, task.getDataFlowInfo());
|
}, 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()) {
|
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
|
||||||
tracing.danglingFunctionLiteralArgumentSuspected(trace, task.getCall().getFunctionLiteralArguments());
|
tracing.danglingFunctionLiteralArgumentSuspected(trace, task.getCall().getFunctionLiteralArguments());
|
||||||
}
|
}
|
||||||
@@ -484,7 +511,7 @@ public class CallResolver {
|
|||||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolution(
|
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolution(
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetScope scope, @NotNull JetType expectedType,
|
@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()) {
|
for (ResolvedCallImpl<D> candidateCall : task.getCandidates()) {
|
||||||
D candidate = candidateCall.getCandidateDescriptor();
|
D candidate = candidateCall.getCandidateDescriptor();
|
||||||
@@ -544,8 +571,7 @@ public class CallResolver {
|
|||||||
// and throw the results away
|
// and throw the results away
|
||||||
// We'll type check the arguments later, with the inferred types expected
|
// We'll type check the arguments later, with the inferred types expected
|
||||||
TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(temporaryTrace);
|
TemporaryBindingTrace traceForUnknown = TemporaryBindingTrace.create(temporaryTrace);
|
||||||
ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, traceForUnknown);
|
JetType type = expressionTypingServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT), traceForUnknown);
|
||||||
JetType type = temporaryServices.getType(scope, expression, substituteDontCare.substitute(valueParameterDescriptor.getType(), Variance.INVARIANT));
|
|
||||||
if (type != null && !ErrorUtils.isErrorType(type)) {
|
if (type != null && !ErrorUtils.isErrorType(type)) {
|
||||||
constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType));
|
constraintSystem.addSubtypingConstraint(VALUE_ARGUMENT.assertSubtyping(type, effectiveExpectedType));
|
||||||
}
|
}
|
||||||
@@ -581,17 +607,17 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Here we type check the arguments with inferred types expected
|
// Here we type check the arguments with inferred types expected
|
||||||
checkValueArgumentTypes(scope, candidateCall);
|
checkValueArgumentTypes(scope, candidateCall, dataFlowInfo);
|
||||||
|
|
||||||
candidateCall.setStatus(SUCCESS);
|
candidateCall.setStatus(SUCCESS);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tracing.typeInferenceFailed(temporaryTrace, solution.getStatus());
|
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 {
|
else {
|
||||||
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall));
|
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall, dataFlowInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -604,7 +630,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
JetTypeReference typeReference = projection.getTypeReference();
|
JetTypeReference typeReference = projection.getTypeReference();
|
||||||
if (typeReference != null) {
|
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();
|
int expectedTypeArgumentCount = candidate.getTypeParameters().size();
|
||||||
@@ -623,7 +649,7 @@ public class CallResolver {
|
|||||||
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
|
TypeParameterDescriptor typeParameterDescriptor = typeParameters.get(i);
|
||||||
candidateCall.recordTypeArgument(typeParameterDescriptor, typeArguments.get(i));
|
candidateCall.recordTypeArgument(typeParameterDescriptor, typeArguments.get(i));
|
||||||
}
|
}
|
||||||
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall));
|
candidateCall.setStatus(checkAllValueArguments(scope, tracing, task, candidateCall, dataFlowInfo));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
candidateCall.setStatus(OTHER_ERROR);
|
candidateCall.setStatus(OTHER_ERROR);
|
||||||
@@ -693,20 +719,19 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkTypesWithNoCallee(BindingTrace trace, JetScope scope, Call call) {
|
private void checkTypesWithNoCallee(BindingTrace trace, JetScope scope, Call call) {
|
||||||
ExpressionTypingServices typeInferrerServices = new ExpressionTypingServices(semanticServices, trace);
|
|
||||||
for (ValueArgument valueArgument : call.getValueArguments()) {
|
for (ValueArgument valueArgument : call.getValueArguments()) {
|
||||||
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
JetExpression argumentExpression = valueArgument.getArgumentExpression();
|
||||||
if (argumentExpression != null) {
|
if (argumentExpression != null) {
|
||||||
typeInferrerServices.getType(scope, argumentExpression, NO_EXPECTED_TYPE);
|
expressionTypingServices.getType(scope, argumentExpression, NO_EXPECTED_TYPE, trace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JetExpression expression : call.getFunctionLiteralArguments()) {
|
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()) {
|
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) {
|
private <D extends CallableDescriptor> ResolutionStatus checkAllValueArguments(JetScope scope, TracingStrategy tracing, ResolutionTask<D> task, ResolvedCallImpl<D> candidateCall, DataFlowInfo dataFlowInfo) {
|
||||||
ResolutionStatus result = checkValueArgumentTypes(scope, candidateCall);
|
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().getReceiverParameter(), candidateCall.getReceiverArgument(), task));
|
||||||
result = result.combine(checkReceiver(tracing, candidateCall, candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(), task));
|
result = result.combine(checkReceiver(tracing, candidateCall, candidateCall.getResultingDescriptor().getExpectedThisObject(), candidateCall.getThisObject(), task));
|
||||||
return result;
|
return result;
|
||||||
@@ -752,7 +777,7 @@ public class CallResolver {
|
|||||||
JetType effectiveReceiverArgumentType = safeAccess
|
JetType effectiveReceiverArgumentType = safeAccess
|
||||||
? TypeUtils.makeNotNullable(receiverArgumentType)
|
? TypeUtils.makeNotNullable(receiverArgumentType)
|
||||||
: receiverArgumentType;
|
: receiverArgumentType;
|
||||||
if (!semanticServices.getTypeChecker().isSubtypeOf(effectiveReceiverArgumentType, receiverParameter.getType())) {
|
if (!typeChecker.isSubtypeOf(effectiveReceiverArgumentType, receiverParameter.getType())) {
|
||||||
tracing.wrongReceiverType(candidateCall.getTrace(), receiverParameter, receiverArgument);
|
tracing.wrongReceiverType(candidateCall.getTrace(), receiverParameter, receiverArgument);
|
||||||
result = OTHER_ERROR;
|
result = OTHER_ERROR;
|
||||||
}
|
}
|
||||||
@@ -765,7 +790,7 @@ public class CallResolver {
|
|||||||
return result;
|
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;
|
ResolutionStatus result = SUCCESS;
|
||||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : candidateCall.getValueArguments().entrySet()) {
|
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : candidateCall.getValueArguments().entrySet()) {
|
||||||
ValueParameterDescriptor parameterDescriptor = entry.getKey();
|
ValueParameterDescriptor parameterDescriptor = entry.getKey();
|
||||||
@@ -775,12 +800,11 @@ public class CallResolver {
|
|||||||
|
|
||||||
List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions();
|
List<JetExpression> argumentExpressions = resolvedArgument.getArgumentExpressions();
|
||||||
for (JetExpression argumentExpression : argumentExpressions) {
|
for (JetExpression argumentExpression : argumentExpressions) {
|
||||||
ExpressionTypingServices temporaryServices = new ExpressionTypingServices(semanticServices, candidateCall.getTrace());
|
JetType type = expressionTypingServices.getType(scope, argumentExpression, parameterType, dataFlowInfo, candidateCall.getTrace());
|
||||||
JetType type = temporaryServices.getType(scope, argumentExpression, parameterType, dataFlowInfo);
|
|
||||||
if (type == null || ErrorUtils.isErrorType(type)) {
|
if (type == null || ErrorUtils.isErrorType(type)) {
|
||||||
candidateCall.argumentHasNoType();
|
candidateCall.argumentHasNoType();
|
||||||
}
|
}
|
||||||
else if (!semanticServices.getTypeChecker().isSubtypeOf(type, parameterType)) {
|
else if (!typeChecker.isSubtypeOf(type, parameterType)) {
|
||||||
// VariableDescriptor variableDescriptor = AutoCastUtils.getVariableDescriptorFromSimpleName(temporaryTrace.getBindingContext(), argumentExpression);
|
// VariableDescriptor variableDescriptor = AutoCastUtils.getVariableDescriptorFromSimpleName(temporaryTrace.getBindingContext(), argumentExpression);
|
||||||
// if (variableDescriptor != null) {
|
// if (variableDescriptor != null) {
|
||||||
// JetType autoCastType = null;
|
// JetType autoCastType = null;
|
||||||
@@ -935,7 +959,7 @@ public class CallResolver {
|
|||||||
JetType typeArgument = typeArguments.get(i);
|
JetType typeArgument = typeArguments.get(i);
|
||||||
JetTypeReference typeReference = jetTypeArguments.get(i).getTypeReference();
|
JetTypeReference typeReference = jetTypeArguments.get(i).getTypeReference();
|
||||||
assert typeReference != null;
|
assert typeReference != null;
|
||||||
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();
|
ReceiverDescriptor functionReceiver = functionDescriptor.getReceiverParameter();
|
||||||
if (!functionReceiver.exists()) continue;
|
if (!functionReceiver.exists()) continue;
|
||||||
if (!functionDescriptor.getTypeParameters().isEmpty()) 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;
|
if (!checkValueParameters(functionDescriptor, parameterTypes))continue;
|
||||||
result.add(resolvedCall);
|
result.add(resolvedCall);
|
||||||
found = true;
|
found = true;
|
||||||
|
|||||||
+4
-9
@@ -20,16 +20,17 @@ import gnu.trove.THashSet;
|
|||||||
import gnu.trove.TObjectHashingStrategy;
|
import gnu.trove.TObjectHashingStrategy;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
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.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -38,12 +39,6 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class OverloadingConflictResolver {
|
public class OverloadingConflictResolver {
|
||||||
|
|
||||||
private final JetSemanticServices semanticServices;
|
|
||||||
|
|
||||||
public OverloadingConflictResolver(@NotNull JetSemanticServices semanticServices) {
|
|
||||||
this.semanticServices = semanticServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public <D extends CallableDescriptor> ResolvedCallImpl<D> findMaximallySpecific(Set<ResolvedCallImpl<D>> candidates, boolean discriminateGenericDescriptors) {
|
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
|
// 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) {
|
private boolean typeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
|
||||||
return semanticServices.getTypeChecker().isSubtypeOf(specific, general) ||
|
return JetTypeChecker.INSTANCE.isSubtypeOf(specific, general) ||
|
||||||
numericTypeMoreSpecific(specific, general);
|
numericTypeMoreSpecific(specific, general);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean numericTypeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
|
private boolean numericTypeMoreSpecific(@NotNull JetType specific, @NotNull JetType general) {
|
||||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
JetType _double = standardLibrary.getDoubleType();
|
JetType _double = standardLibrary.getDoubleType();
|
||||||
JetType _float = standardLibrary.getFloatType();
|
JetType _float = standardLibrary.getFloatType();
|
||||||
JetType _long = standardLibrary.getLongType();
|
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()));
|
public static DataFlowInfo EMPTY = new DataFlowInfo(ImmutableMap.<DataFlowValue, Nullability>of(), Multimaps.newListMultimap(Collections.<DataFlowValue, Collection<JetType>>emptyMap(), CommonSuppliers.<JetType>getArrayListSupplier()));
|
||||||
|
|
||||||
private final ImmutableMap<DataFlowValue, Nullability> nullabilityInfo;
|
private final ImmutableMap<DataFlowValue, Nullability> nullabilityInfo;
|
||||||
|
/** Also immutable */
|
||||||
private final ListMultimap<DataFlowValue, JetType> typeInfo;
|
private final ListMultimap<DataFlowValue, JetType> typeInfo;
|
||||||
|
|
||||||
private DataFlowInfo(ImmutableMap<DataFlowValue, Nullability> nullabilityInfo, ListMultimap<DataFlowValue, JetType> typeInfo) {
|
private DataFlowInfo(ImmutableMap<DataFlowValue, Nullability> nullabilityInfo, ListMultimap<DataFlowValue, JetType> typeInfo) {
|
||||||
|
|||||||
+11
-14
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.resolve.constants;
|
|||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetEscapeStringTemplateEntry;
|
import org.jetbrains.jet.lang.psi.JetEscapeStringTemplateEntry;
|
||||||
import org.jetbrains.jet.lang.psi.JetLiteralStringTemplateEntry;
|
import org.jetbrains.jet.lang.psi.JetLiteralStringTemplateEntry;
|
||||||
import org.jetbrains.jet.lang.psi.JetStringTemplateEntry;
|
import org.jetbrains.jet.lang.psi.JetStringTemplateEntry;
|
||||||
@@ -38,17 +37,16 @@ import java.util.List;
|
|||||||
public class CompileTimeConstantResolver {
|
public class CompileTimeConstantResolver {
|
||||||
public static final ErrorValue OUT_OF_RANGE = new ErrorValue("The value is out of range");
|
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;
|
private final BindingTrace trace;
|
||||||
|
|
||||||
public CompileTimeConstantResolver(@NotNull JetSemanticServices semanticServices, @NotNull BindingTrace trace) {
|
public CompileTimeConstantResolver(@NotNull BindingTrace trace) {
|
||||||
this.semanticServices = semanticServices;
|
this.standardLibrary = JetStandardLibrary.getInstance();
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getIntegerValue(@NotNull String text, @NotNull JetType expectedType) {
|
public CompileTimeConstant<?> getIntegerValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
|
||||||
if (noExpectedType(expectedType)) {
|
if (noExpectedType(expectedType)) {
|
||||||
Long value = parseLongValue(text);
|
Long value = parseLongValue(text);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
@@ -85,7 +83,7 @@ public class CompileTimeConstantResolver {
|
|||||||
upperBound = Byte.MAX_VALUE;
|
upperBound = Byte.MAX_VALUE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetTypeChecker typeChecker = semanticServices.getTypeChecker();
|
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||||
JetType intType = standardLibrary.getIntType();
|
JetType intType = standardLibrary.getIntType();
|
||||||
JetType longType = standardLibrary.getLongType();
|
JetType longType = standardLibrary.getLongType();
|
||||||
if (typeChecker.isSubtypeOf(intType, expectedType)) {
|
if (typeChecker.isSubtypeOf(intType, expectedType)) {
|
||||||
@@ -130,9 +128,8 @@ public class CompileTimeConstantResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getFloatValue(@NotNull String text, @NotNull JetType expectedType) {
|
public CompileTimeConstant<?> getFloatValue(@NotNull String text, @NotNull JetType expectedType) {
|
||||||
JetStandardLibrary standardLibrary = semanticServices.getStandardLibrary();
|
|
||||||
if (noExpectedType(expectedType)
|
if (noExpectedType(expectedType)
|
||||||
|| semanticServices.getTypeChecker().isSubtypeOf(standardLibrary.getDoubleType(), expectedType)) {
|
|| JetTypeChecker.INSTANCE.isSubtypeOf(standardLibrary.getDoubleType(), expectedType)) {
|
||||||
try {
|
try {
|
||||||
return new DoubleValue(Double.parseDouble(text));
|
return new DoubleValue(Double.parseDouble(text));
|
||||||
}
|
}
|
||||||
@@ -140,7 +137,7 @@ public class CompileTimeConstantResolver {
|
|||||||
return OUT_OF_RANGE;
|
return OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (semanticServices.getTypeChecker().isSubtypeOf(standardLibrary.getFloatType(), expectedType)) {
|
else if (JetTypeChecker.INSTANCE.isSubtypeOf(standardLibrary.getFloatType(), expectedType)) {
|
||||||
try {
|
try {
|
||||||
return new DoubleValue(Float.parseFloat(text));
|
return new DoubleValue(Float.parseFloat(text));
|
||||||
}
|
}
|
||||||
@@ -156,7 +153,7 @@ public class CompileTimeConstantResolver {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private CompileTimeConstant<?> checkNativeType(String text, JetType expectedType, String title, JetType nativeType) {
|
private CompileTimeConstant<?> checkNativeType(String text, JetType expectedType, String title, JetType nativeType) {
|
||||||
if (!noExpectedType(expectedType)
|
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 new ErrorValue("A " + title + " literal " + text + " does not conform to the expected type " + expectedType);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -164,7 +161,7 @@ public class CompileTimeConstantResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getBooleanValue(@NotNull String text, @NotNull JetType expectedType) {
|
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) {
|
if (error != null) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -179,7 +176,7 @@ public class CompileTimeConstantResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getCharValue(@NotNull String text, @NotNull JetType expectedType) {
|
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) {
|
if (error != null) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -265,7 +262,7 @@ public class CompileTimeConstantResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getRawStringValue(@NotNull String unescapedText, @NotNull JetType expectedType) {
|
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) {
|
if (error != null) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -275,7 +272,7 @@ public class CompileTimeConstantResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompileTimeConstant<?> getEscapedStringValue(@NotNull List<JetStringTemplateEntry> entries, @NotNull JetType expectedType) {
|
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) {
|
if (error != null) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-21
@@ -147,7 +147,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
ASTNode node = expression.getNode();
|
ASTNode node = expression.getNode();
|
||||||
IElementType elementType = node.getElementType();
|
IElementType elementType = node.getElementType();
|
||||||
String text = node.getText();
|
String text = node.getText();
|
||||||
JetStandardLibrary standardLibrary = context.semanticServices.getStandardLibrary();
|
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
CompileTimeConstantResolver compileTimeConstantResolver = context.getCompileTimeConstantResolver();
|
||||||
|
|
||||||
CompileTimeConstant<?> value;
|
CompileTimeConstant<?> value;
|
||||||
@@ -172,7 +172,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (value instanceof ErrorValue) {
|
if (value instanceof ErrorValue) {
|
||||||
ErrorValue errorValue = (ErrorValue) value;
|
ErrorValue errorValue = (ErrorValue) value;
|
||||||
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(node.getPsi(), errorValue.getMessage()));
|
context.trace.report(ERROR_COMPILE_TIME_VALUE.on(node.getPsi(), errorValue.getMessage()));
|
||||||
return getDefaultType(context.semanticServices, elementType);
|
return getDefaultType(elementType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, value);
|
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, value);
|
||||||
@@ -185,7 +185,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetTypeReference right = expression.getRight();
|
JetTypeReference right = expression.getRight();
|
||||||
JetType result = null;
|
JetType result = null;
|
||||||
if (right != null) {
|
if (right != null) {
|
||||||
JetType targetType = context.getTypeResolver().resolveType(context.scope, right);
|
JetType targetType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, right, context.trace, true);
|
||||||
|
|
||||||
if (isTypeFlexible(expression.getLeft())) {
|
if (isTypeFlexible(expression.getLeft())) {
|
||||||
TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(context.trace);
|
TemporaryBindingTrace temporaryTraceWithExpectedType = TemporaryBindingTrace.create(context.trace);
|
||||||
@@ -223,7 +223,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||||
IElementType operationType = operationSign.getReferencedNameElementType();
|
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||||
if (operationType == JetTokens.COLON) {
|
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));
|
context.trace.report(TYPE_MISMATCH.on(expression.getLeft(), targetType, actualType));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -242,7 +242,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
private void checkForCastImpossibility(JetBinaryExpressionWithTypeRHS expression, JetType actualType, JetType targetType, ExpressionTypingContext context) {
|
private void checkForCastImpossibility(JetBinaryExpressionWithTypeRHS expression, JetType actualType, JetType targetType, ExpressionTypingContext context) {
|
||||||
if (actualType == null || targetType == NO_EXPECTED_TYPE) return;
|
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(targetType, actualType)) {
|
||||||
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
||||||
context.trace.report(USELESS_CAST_STATIC_ASSERT_IS_FINE.on(expression.getOperationSign()));
|
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<JetExpression> entries = expression.getEntries();
|
||||||
List<JetType> types = new ArrayList<JetType>();
|
List<JetType> types = new ArrayList<JetType>();
|
||||||
for (JetExpression entry : entries) {
|
for (JetExpression entry : entries) {
|
||||||
types.add(context.getServices().safeGetType(context.scope, entry, NO_EXPECTED_TYPE)); // 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)) {
|
if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isTupleType(context.expectedType)) {
|
||||||
List<JetType> enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context);
|
List<JetType> enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context);
|
||||||
@@ -417,15 +417,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetUserType userType = (JetUserType) typeElement;
|
JetUserType userType = (JetUserType) typeElement;
|
||||||
// This may be just a superclass name even if the superclass is generic
|
// This may be just a superclass name even if the superclass is generic
|
||||||
if (userType.getTypeArguments().isEmpty()) {
|
if (userType.getTypeArguments().isEmpty()) {
|
||||||
classifierCandidate = context.getTypeResolver().resolveClass(context.scope, userType);
|
classifierCandidate = context.expressionTypingServices.getTypeResolver().resolveClass(context.scope, userType, context.trace);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier);
|
supertype = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
||||||
redundantTypeArguments = userType.getTypeArgumentList();
|
redundantTypeArguments = userType.getTypeArgumentList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
supertype = context.getTypeResolver().resolveType(context.scope, superTypeQualifier);
|
supertype = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supertype != null) {
|
if (supertype != null) {
|
||||||
@@ -505,7 +505,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public JetType visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
public JetType visitBlockExpression(JetBlockExpression expression, ExpressionTypingContext context, boolean isStatement) {
|
||||||
return context.getServices().getBlockReturnedType(context.scope, expression, isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION, context);
|
return context.expressionTypingServices.getBlockReturnedType(context.scope, expression, isStatement
|
||||||
|
? CoercionStrategy.COERCION_TO_UNIT
|
||||||
|
: CoercionStrategy.NO_COERCION, context, context.trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -544,9 +546,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
JetType result;
|
JetType result;
|
||||||
if (expression.getOperationSign() == JetTokens.QUEST) {
|
if (expression.getOperationSign() == JetTokens.QUEST) {
|
||||||
if (selectorReturnType != null && !isBoolean(context.semanticServices, selectorReturnType)) {
|
if (selectorReturnType != null && !isBoolean(selectorReturnType)) {
|
||||||
// TODO : more comprehensible error message
|
// 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);
|
result = TypeUtils.makeNullable(receiverType);
|
||||||
}
|
}
|
||||||
@@ -566,7 +568,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
CompileTimeConstant<?> wholeExpressionValue = context.trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression);
|
CompileTimeConstant<?> wholeExpressionValue = context.trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression);
|
||||||
DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.REFERENCE_TARGET, selectorExpression);
|
DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.REFERENCE_TARGET, selectorExpression);
|
||||||
if (wholeExpressionValue == null && receiverValue != null && !(receiverValue instanceof ErrorValue) && receiverValue.getValue() instanceof Number
|
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();
|
Number value = (Number) receiverValue.getValue();
|
||||||
String referencedName = selectorExpression.getReferencedName();
|
String referencedName = selectorExpression.getReferencedName();
|
||||||
if (OperatorConventions.NUMBER_CONVERSIONS.contains(referencedName)) {
|
if (OperatorConventions.NUMBER_CONVERSIONS.contains(referencedName)) {
|
||||||
@@ -707,13 +709,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType returnType = functionDescriptor.getResultingDescriptor().getReturnType();
|
JetType returnType = functionDescriptor.getResultingDescriptor().getReturnType();
|
||||||
JetType result;
|
JetType result;
|
||||||
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
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();
|
result = JetStandardClasses.getUnitType();
|
||||||
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
|
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetType receiverType = receiver.getType();
|
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));
|
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, name, receiverType, returnType));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -785,7 +787,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType compareToReturnType = getTypeForBinaryCall(context.scope, "compareTo", context, expression);
|
JetType compareToReturnType = getTypeForBinaryCall(context.scope, "compareTo", context, expression);
|
||||||
if (compareToReturnType != null) {
|
if (compareToReturnType != null) {
|
||||||
TypeConstructor constructor = compareToReturnType.getConstructor();
|
TypeConstructor constructor = compareToReturnType.getConstructor();
|
||||||
JetStandardLibrary standardLibrary = context.semanticServices.getStandardLibrary();
|
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
TypeConstructor intTypeConstructor = standardLibrary.getInt().getTypeConstructor();
|
TypeConstructor intTypeConstructor = standardLibrary.getInt().getTypeConstructor();
|
||||||
if (constructor.equals(intTypeConstructor)) {
|
if (constructor.equals(intTypeConstructor)) {
|
||||||
result = standardLibrary.getBooleanType();
|
result = standardLibrary.getBooleanType();
|
||||||
@@ -795,7 +797,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetType booleanType = context.semanticServices.getStandardLibrary().getBooleanType();
|
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
|
||||||
if (OperatorConventions.EQUALS_OPERATIONS.contains(operationType)) {
|
if (OperatorConventions.EQUALS_OPERATIONS.contains(operationType)) {
|
||||||
String name = "equals";
|
String name = "equals";
|
||||||
if (right != null) {
|
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
|
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 ||");
|
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));
|
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));
|
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));
|
context.trace.report(TYPE_MISMATCH.on(right, booleanType, rightType));
|
||||||
}
|
}
|
||||||
result = booleanType;
|
result = booleanType;
|
||||||
@@ -892,7 +894,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType rightType = facade.getType(right, context.replaceScope(context.scope));
|
JetType rightType = facade.getType(right, context.replaceScope(context.scope));
|
||||||
|
|
||||||
if (rightType != null) {
|
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) {
|
if (intersect == null) {
|
||||||
context.trace.report(EQUALITY_NOT_APPLICABLE.on(expression, operationSign, leftType, rightType));
|
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) {
|
if (value[0] != CompileTimeConstantResolver.OUT_OF_RANGE) {
|
||||||
context.trace.record(BindingContext.COMPILE_TIME_VALUE, expression, new StringValue(builder.toString()));
|
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
|
@Override
|
||||||
|
|||||||
+9
-9
@@ -72,7 +72,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
};
|
};
|
||||||
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(context.trace);
|
ObservableBindingTrace traceAdapter = new ObservableBindingTrace(context.trace);
|
||||||
traceAdapter.addHandler(CLASS, handler);
|
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);
|
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);
|
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
|
||||||
JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef();
|
JetTypeReference returnTypeRef = functionLiteral.getReturnTypeRef();
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
returnType = context.getTypeResolver().resolveType(context.scope, returnTypeRef);
|
returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true);
|
||||||
context.getServices().checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
|
context.expressionTypingServices.checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
|
||||||
replaceExpectedType(returnType).replaceExpectedReturnType(returnType).replaceDataFlowInfo(context.dataFlowInfo));
|
replaceExpectedType(returnType).replaceExpectedReturnType(returnType).replaceDataFlowInfo(context.dataFlowInfo), context.trace);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (functionTypeExpected) {
|
if (functionTypeExpected) {
|
||||||
returnType = JetStandardClasses.getReturnTypeFromFunctionType(expectedType);
|
returnType = JetStandardClasses.getReturnTypeFromFunctionType(expectedType);
|
||||||
}
|
}
|
||||||
returnType = context.getServices().getBlockReturnedType(functionInnerScope, bodyExpression, CoercionStrategy.COERCION_TO_UNIT,
|
returnType = context.expressionTypingServices.getBlockReturnedType(functionInnerScope, bodyExpression, CoercionStrategy.COERCION_TO_UNIT,
|
||||||
context.replaceExpectedType(returnType).replaceExpectedReturnType(returnType));
|
context.replaceExpectedType(returnType).replaceExpectedReturnType(returnType), context.trace);
|
||||||
}
|
}
|
||||||
JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("<return type>") : returnType;
|
JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("<return type>") : returnType;
|
||||||
functionDescriptor.setReturnType(safeReturnType);
|
functionDescriptor.setReturnType(safeReturnType);
|
||||||
@@ -143,7 +143,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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);
|
functionDescriptor.initialize(effectiveReceiverType, NO_RECEIVER, Collections.<TypeParameterDescriptor>emptyList(), valueParameterDescriptors, null, Modality.FINAL, Visibility.LOCAL);
|
||||||
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
|
context.trace.record(BindingContext.FUNCTION, expression, functionDescriptor);
|
||||||
@@ -174,7 +174,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
JetType type;
|
JetType type;
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
type = context.getTypeResolver().resolveType(context.scope, typeReference);
|
type = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, typeReference, context.trace, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (expectedValueParameters != null && i < expectedValueParameters.size()) {
|
if (expectedValueParameters != null && i < expectedValueParameters.size()) {
|
||||||
@@ -185,7 +185,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
type = ErrorUtils.createErrorType("Cannot be inferred");
|
type = ErrorUtils.createErrorType("Cannot be inferred");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ValueParameterDescriptor valueParameterDescriptor = context.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type);
|
ValueParameterDescriptor valueParameterDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveValueParameterDescriptor(functionDescriptor, declaredParameter, i, type, context.trace);
|
||||||
valueParameterDescriptors.add(valueParameterDescriptor);
|
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.ExpressionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -63,7 +65,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (condition != null) {
|
if (condition != null) {
|
||||||
JetType conditionType = facade.getType(condition, context.replaceScope(scope));
|
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));
|
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(condition, conditionType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +94,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
if (elseBranch == null) {
|
if (elseBranch == null) {
|
||||||
if (thenBranch != null) {
|
if (thenBranch != null) {
|
||||||
JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(thenInfo));
|
JetType type = context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(thenInfo), context.trace);
|
||||||
if (type != null && JetStandardClasses.isNothing(type)) {
|
if (type != null && JetStandardClasses.isNothing(type)) {
|
||||||
facade.setResultingDataFlowInfo(elseInfo);
|
facade.setResultingDataFlowInfo(elseInfo);
|
||||||
}
|
}
|
||||||
@@ -101,15 +103,15 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (thenBranch == null) {
|
if (thenBranch == null) {
|
||||||
JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(elseInfo));
|
JetType type = context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(elseInfo), context.trace);
|
||||||
if (type != null && JetStandardClasses.isNothing(type)) {
|
if (type != null && JetStandardClasses.isNothing(type)) {
|
||||||
facade.setResultingDataFlowInfo(thenInfo);
|
facade.setResultingDataFlowInfo(thenInfo);
|
||||||
}
|
}
|
||||||
return DataFlowUtils.checkImplicitCast(DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType), expression, contextWithExpectedType, isStatement);
|
return DataFlowUtils.checkImplicitCast(DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType), expression, contextWithExpectedType, isStatement);
|
||||||
}
|
}
|
||||||
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
|
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
|
||||||
JetType thenType = context.getServices().getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(thenInfo));
|
JetType thenType = context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(thenScope, Collections.singletonList(thenBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(thenInfo), context.trace);
|
||||||
JetType elseType = context.getServices().getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(elseInfo));
|
JetType elseType = context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(elseScope, Collections.singletonList(elseBranch), coercionStrategy, contextWithExpectedType.replaceDataFlowInfo(elseInfo), context.trace);
|
||||||
|
|
||||||
JetType result;
|
JetType result;
|
||||||
if (thenType == null) {
|
if (thenType == null) {
|
||||||
@@ -150,7 +152,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (body != null) {
|
if (body != null) {
|
||||||
WritableScopeImpl scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in while's condition");
|
WritableScopeImpl scopeToExtend = newWritableScopeImpl(context).setDebugName("Scope extended in while's condition");
|
||||||
DataFlowInfo conditionInfo = condition == null ? context.dataFlowInfo : DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, scopeToExtend, context);
|
DataFlowInfo conditionInfo = condition == null ? context.dataFlowInfo : DataFlowUtils.extractDataFlowInfoFromCondition(condition, true, scopeToExtend, context);
|
||||||
context.getServices().getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo));
|
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(body), CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo), context.trace);
|
||||||
}
|
}
|
||||||
if (!containsBreak(expression, context)) {
|
if (!containsBreak(expression, context)) {
|
||||||
facade.setResultingDataFlowInfo(DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, null, context));
|
facade.setResultingDataFlowInfo(DataFlowUtils.extractDataFlowInfoFromCondition(condition, false, null, context));
|
||||||
@@ -197,7 +199,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (!function.getFunctionLiteral().hasParameterSpecification()) {
|
if (!function.getFunctionLiteral().hasParameterSpecification()) {
|
||||||
WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope");
|
WritableScope writableScope = newWritableScopeImpl(context).setDebugName("do..while body scope");
|
||||||
conditionScope = writableScope;
|
conditionScope = writableScope;
|
||||||
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context);
|
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, function.getFunctionLiteral().getBodyExpression().getStatements(), CoercionStrategy.NO_COERCION, context, context.trace);
|
||||||
context.trace.record(BindingContext.BLOCK, function);
|
context.trace.record(BindingContext.BLOCK, function);
|
||||||
} else {
|
} else {
|
||||||
facade.getType(body, context.replaceScope(context.scope));
|
facade.getType(body, context.replaceScope(context.scope));
|
||||||
@@ -213,7 +215,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
else {
|
else {
|
||||||
block = Collections.<JetElement>singletonList(body);
|
block = Collections.<JetElement>singletonList(body);
|
||||||
}
|
}
|
||||||
context.getServices().getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context);
|
context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(writableScope, block, CoercionStrategy.NO_COERCION, context, context.trace);
|
||||||
}
|
}
|
||||||
JetExpression condition = expression.getCondition();
|
JetExpression condition = expression.getCondition();
|
||||||
checkCondition(conditionScope, condition, context);
|
checkCondition(conditionScope, condition, context);
|
||||||
@@ -248,11 +250,11 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetTypeReference typeReference = loopParameter.getTypeReference();
|
JetTypeReference typeReference = loopParameter.getTypeReference();
|
||||||
VariableDescriptor variableDescriptor;
|
VariableDescriptor variableDescriptor;
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter);
|
variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, loopParameter, context.trace);
|
||||||
JetType actualParameterType = variableDescriptor.getType();
|
JetType actualParameterType = variableDescriptor.getType();
|
||||||
if (expectedParameterType != null &&
|
if (expectedParameterType != null &&
|
||||||
actualParameterType != 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));
|
context.trace.report(TYPE_MISMATCH_IN_FOR_LOOP.on(typeReference, expectedParameterType, actualParameterType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,7 +262,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (expectedParameterType == null) {
|
if (expectedParameterType == null) {
|
||||||
expectedParameterType = ErrorUtils.createErrorType("Error");
|
expectedParameterType = ErrorUtils.createErrorType("Error");
|
||||||
}
|
}
|
||||||
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
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();
|
JetExpression body = expression.getBody();
|
||||||
if (body != null) {
|
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);
|
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType);
|
||||||
@@ -350,7 +352,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
|
|
||||||
public static OverloadResolutionResults<FunctionDescriptor> resolveFakeCall(ExpressionReceiver receiver,
|
public static OverloadResolutionResults<FunctionDescriptor> resolveFakeCall(ExpressionReceiver receiver,
|
||||||
ExpressionTypingContext context, String name) {
|
ExpressionTypingContext context, String name) {
|
||||||
JetReferenceExpression fake = JetPsiFactory.createSimpleName(context.getProject(), "fake");
|
JetReferenceExpression fake = JetPsiFactory.createSimpleName(context.expressionTypingServices.getProject(), "fake");
|
||||||
BindingTrace fakeTrace = new BindingTraceContext();
|
BindingTrace fakeTrace = new BindingTraceContext();
|
||||||
Call call = CallMaker.makeCall(fake, receiver, null, fake, Collections.<ValueArgument>emptyList());
|
Call call = CallMaker.makeCall(fake, receiver, null, fake, Collections.<ValueArgument>emptyList());
|
||||||
return context.replaceBindingTrace(fakeTrace).resolveCallWithGivenName(call, fake, name);
|
return context.replaceBindingTrace(fakeTrace).resolveCallWithGivenName(call, fake, name);
|
||||||
@@ -366,7 +368,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
} else {
|
} else {
|
||||||
assert hasNextResolutionResults.isSuccess();
|
assert hasNextResolutionResults.isSuccess();
|
||||||
JetType hasNextReturnType = hasNextResolutionResults.getResultingDescriptor().getReturnType();
|
JetType hasNextReturnType = hasNextResolutionResults.getResultingDescriptor().getReturnType();
|
||||||
if (!isBoolean(context.semanticServices, hasNextReturnType)) {
|
if (!isBoolean(hasNextReturnType)) {
|
||||||
context.trace.report(HAS_NEXT_FUNCTION_TYPE_MISMATCH.on(loopRange, hasNextReturnType));
|
context.trace.report(HAS_NEXT_FUNCTION_TYPE_MISMATCH.on(loopRange, hasNextReturnType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -384,7 +386,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
// TODO : accessibility
|
// TODO : accessibility
|
||||||
context.trace.report(HAS_NEXT_MUST_BE_READABLE.on(loopRange));
|
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));
|
context.trace.report(HAS_NEXT_PROPERTY_TYPE_MISMATCH.on(loopRange, hasNextReturnType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,8 +403,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetParameter catchParameter = catchClause.getCatchParameter();
|
JetParameter catchParameter = catchClause.getCatchParameter();
|
||||||
JetExpression catchBody = catchClause.getCatchBody();
|
JetExpression catchBody = catchClause.getCatchBody();
|
||||||
if (catchParameter != null) {
|
if (catchParameter != null) {
|
||||||
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter);
|
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace);
|
||||||
JetType throwableType = context.semanticServices.getStandardLibrary().getThrowable().getDefaultType();
|
JetType throwableType = JetStandardLibrary.getInstance().getThrowable().getDefaultType();
|
||||||
DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
|
DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
|
||||||
if (catchBody != null) {
|
if (catchBody != null) {
|
||||||
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope");
|
WritableScope catchScope = newWritableScopeImpl(context).setDebugName("Catch scope");
|
||||||
@@ -437,7 +439,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
public JetType visitThrowExpression(JetThrowExpression expression, ExpressionTypingContext context) {
|
public JetType visitThrowExpression(JetThrowExpression expression, ExpressionTypingContext context) {
|
||||||
JetExpression thrownExpression = expression.getThrownExpression();
|
JetExpression thrownExpression = expression.getThrownExpression();
|
||||||
if (thrownExpression != null) {
|
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));
|
facade.getType(thrownExpression, context.replaceExpectedType(throwableType).replaceScope(context.scope));
|
||||||
}
|
}
|
||||||
return DataFlowUtils.checkType(JetStandardClasses.getNothingType(), expression, context);
|
return DataFlowUtils.checkType(JetStandardClasses.getNothingType(), expression, context);
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class DataFlowUtils {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public static JetType checkType(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context) {
|
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 ||
|
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;
|
return expressionType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
-62
@@ -17,18 +17,13 @@
|
|||||||
package org.jetbrains.jet.lang.types.expressions;
|
package org.jetbrains.jet.lang.types.expressions;
|
||||||
|
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
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.CallMaker;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
||||||
@@ -43,11 +38,11 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
/*package*/ class ExpressionTypingContext {
|
public class ExpressionTypingContext {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ExpressionTypingContext newContext(
|
public static ExpressionTypingContext newContext(
|
||||||
@NotNull Project project,
|
@NotNull ExpressionTypingServices expressionTypingServices,
|
||||||
@NotNull JetSemanticServices semanticServices,
|
|
||||||
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
||||||
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
||||||
@NotNull LabelResolver labelResolver,
|
@NotNull LabelResolver labelResolver,
|
||||||
@@ -57,7 +52,7 @@ import java.util.Map;
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull JetType expectedReturnType,
|
@NotNull JetType expectedReturnType,
|
||||||
boolean namespacesAllowed) {
|
boolean namespacesAllowed) {
|
||||||
return new ExpressionTypingContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
|
return new ExpressionTypingContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
|
||||||
labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
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);
|
// 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 ExpressionTypingServices expressionTypingServices;
|
||||||
public final JetSemanticServices semanticServices;
|
|
||||||
public final BindingTrace trace;
|
public final BindingTrace trace;
|
||||||
public final JetScope scope;
|
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'
|
// true for positions on the lhs of a '.', i.e. allows namespace results and 'super'
|
||||||
public final boolean namespacesAllowed;
|
public final boolean namespacesAllowed;
|
||||||
|
|
||||||
private CallResolver callResolver;
|
|
||||||
private TypeResolver typeResolver;
|
|
||||||
private DescriptorResolver descriptorResolver;
|
|
||||||
private ExpressionTypingServices services;
|
|
||||||
private CompileTimeConstantResolver compileTimeConstantResolver;
|
private CompileTimeConstantResolver compileTimeConstantResolver;
|
||||||
|
|
||||||
private ExpressionTypingContext(
|
private ExpressionTypingContext(
|
||||||
@NotNull Project project,
|
@NotNull ExpressionTypingServices expressionTypingServices,
|
||||||
@NotNull JetSemanticServices semanticServices,
|
|
||||||
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
||||||
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
||||||
@NotNull LabelResolver labelResolver,
|
@NotNull LabelResolver labelResolver,
|
||||||
@@ -106,13 +95,12 @@ import java.util.Map;
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull JetType expectedReturnType,
|
@NotNull JetType expectedReturnType,
|
||||||
boolean namespacesAllowed) {
|
boolean namespacesAllowed) {
|
||||||
this.project = project;
|
this.expressionTypingServices = expressionTypingServices;
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
this.patternsToBoundVariableLists = patternsToBoundVariableLists;
|
this.patternsToBoundVariableLists = patternsToBoundVariableLists;
|
||||||
this.patternsToDataFlowInfo = patternsToDataFlowInfo;
|
this.patternsToDataFlowInfo = patternsToDataFlowInfo;
|
||||||
this.labelResolver = labelResolver;
|
this.labelResolver = labelResolver;
|
||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
this.semanticServices = semanticServices;
|
|
||||||
this.dataFlowInfo = dataFlowInfo;
|
this.dataFlowInfo = dataFlowInfo;
|
||||||
this.expectedType = expectedType;
|
this.expectedType = expectedType;
|
||||||
this.expectedReturnType = expectedReturnType;
|
this.expectedReturnType = expectedReturnType;
|
||||||
@@ -122,71 +110,43 @@ import java.util.Map;
|
|||||||
@NotNull
|
@NotNull
|
||||||
public ExpressionTypingContext replaceNamespacesAllowed(boolean namespacesAllowed) {
|
public ExpressionTypingContext replaceNamespacesAllowed(boolean namespacesAllowed) {
|
||||||
if (namespacesAllowed == this.namespacesAllowed) return this;
|
if (namespacesAllowed == this.namespacesAllowed) return this;
|
||||||
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
||||||
if (newDataFlowInfo == dataFlowInfo) return this;
|
if (newDataFlowInfo == dataFlowInfo) return this;
|
||||||
return newContext(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) {
|
public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) {
|
||||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||||
if (expectedType == newExpectedType) return this;
|
if (expectedType == newExpectedType) return this;
|
||||||
return newContext(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) {
|
public ExpressionTypingContext replaceExpectedReturnType(@Nullable JetType newExpectedReturnType) {
|
||||||
if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
|
if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
|
||||||
if (expectedReturnType == newExpectedReturnType) return this;
|
if (expectedReturnType == newExpectedReturnType) return this;
|
||||||
return newContext(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) {
|
public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) {
|
||||||
if (newTrace == trace) return this;
|
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
|
@NotNull
|
||||||
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
|
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
|
||||||
if (newScope == scope) return this;
|
if (newScope == scope) return this;
|
||||||
return newContext(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
|
///////////// 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() {
|
public CompileTimeConstantResolver getCompileTimeConstantResolver() {
|
||||||
if (compileTimeConstantResolver == null) {
|
if (compileTimeConstantResolver == null) {
|
||||||
compileTimeConstantResolver = new CompileTimeConstantResolver(semanticServices, trace);
|
compileTimeConstantResolver = new CompileTimeConstantResolver(trace);
|
||||||
}
|
}
|
||||||
return compileTimeConstantResolver;
|
return compileTimeConstantResolver;
|
||||||
}
|
}
|
||||||
@@ -195,7 +155,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public OverloadResolutionResults<FunctionDescriptor> resolveCallWithGivenName(@NotNull Call call, @NotNull JetReferenceExpression functionReference, @NotNull String name) {
|
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
|
@NotNull
|
||||||
@@ -206,23 +166,19 @@ import java.util.Map;
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public FunctionDescriptor resolveCall(@NotNull ReceiverDescriptor receiver, @Nullable ASTNode callOperationNode, @NotNull JetCallExpression callExpression) {
|
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;
|
return results.singleResult() ? results.getResultingDescriptor() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(@NotNull ReceiverDescriptor receiver, @Nullable ASTNode callOperationNode, @NotNull JetSimpleNameExpression nameExpression) {
|
public OverloadResolutionResults<VariableDescriptor> resolveSimpleProperty(@NotNull ReceiverDescriptor receiver, @Nullable ASTNode callOperationNode, @NotNull JetSimpleNameExpression nameExpression) {
|
||||||
Call call = CallMaker.makePropertyCall(receiver, callOperationNode, 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
|
@NotNull
|
||||||
public OverloadResolutionResults<FunctionDescriptor> resolveExactSignature(@NotNull ReceiverDescriptor receiver, @NotNull String name, @NotNull List<JetType> parameterTypes) {
|
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;
|
package org.jetbrains.jet.lang.types.expressions;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
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.PsiElement;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
|
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.diagnostics.Diagnostic;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.*;
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||||
@@ -37,6 +39,7 @@ import org.jetbrains.jet.lang.types.CommonSupertypes;
|
|||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -51,23 +54,67 @@ import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ExpressionTypingServices {
|
public class ExpressionTypingServices {
|
||||||
private final JetSemanticServices semanticServices;
|
|
||||||
private final BindingTrace trace;
|
|
||||||
|
|
||||||
private final ExpressionTypingFacade expressionTypingFacade = ExpressionTypingVisitorDispatcher.create();
|
private final ExpressionTypingFacade expressionTypingFacade = ExpressionTypingVisitorDispatcher.create();
|
||||||
|
|
||||||
public ExpressionTypingServices(JetSemanticServices semanticServices, BindingTrace trace) {
|
@NotNull
|
||||||
this.semanticServices = semanticServices;
|
private Project project;
|
||||||
this.trace = trace;
|
@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
|
@NotNull
|
||||||
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
|
public CallResolver getCallResolver() {
|
||||||
return safeGetType(scope, expression, expectedType, DataFlowInfo.EMPTY);
|
return callResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JetType safeGetType(@NotNull JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, @NotNull DataFlowInfo dataFlowInfo) {
|
@Inject
|
||||||
JetType type = getType(scope, expression, expectedType, dataFlowInfo);
|
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) {
|
if (type != null) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -75,25 +122,23 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType) {
|
public JetType getType(@NotNull final JetScope scope, @NotNull JetExpression expression, @NotNull JetType expectedType, BindingTrace trace) {
|
||||||
return getType(scope, expression, expectedType, DataFlowInfo.EMPTY);
|
return getType(scope, expression, expectedType, DataFlowInfo.EMPTY, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
expression.getProject(),
|
this,
|
||||||
semanticServices,
|
|
||||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
|
trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
|
||||||
);
|
);
|
||||||
return expressionTypingFacade.getType(expression, context);
|
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(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
expression.getProject(),
|
this,
|
||||||
semanticServices,
|
|
||||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN,
|
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN,
|
||||||
true);
|
true);
|
||||||
@@ -102,7 +147,7 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
Map<JetExpression, JetType> typeMap = collectReturnedExpressionsWithTypes(trace, outerScope, function, functionDescriptor);
|
||||||
Collection<JetType> types = typeMap.values();
|
Collection<JetType> types = typeMap.values();
|
||||||
return types.isEmpty()
|
return types.isEmpty()
|
||||||
@@ -111,20 +156,20 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor) {
|
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, BindingTrace trace) {
|
||||||
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, null);
|
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, null, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @Nullable JetType 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);
|
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, expectedReturnType, trace);
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo) {
|
/*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) {
|
||||||
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, dataFlowInfo, null);
|
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) {
|
if (expectedReturnType == null) {
|
||||||
expectedReturnType = functionDescriptor.getReturnType();
|
expectedReturnType = functionDescriptor.getReturnType();
|
||||||
if (!function.hasBlockBody() && !function.hasDeclaredReturnType()) {
|
if (!function.hasBlockBody() && !function.hasDeclaredReturnType()) {
|
||||||
@@ -132,13 +177,13 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
|
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
|
||||||
function.getProject(),
|
this,
|
||||||
semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false
|
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false
|
||||||
));
|
), trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*package*/ void checkFunctionReturnType(JetDeclarationWithBody function, ExpressionTypingContext context) {
|
/*package*/ void checkFunctionReturnType(JetDeclarationWithBody function, ExpressionTypingContext context, BindingTrace trace) {
|
||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
if (bodyExpression == null) return;
|
if (bodyExpression == null) return;
|
||||||
|
|
||||||
@@ -152,7 +197,7 @@ public class ExpressionTypingServices {
|
|||||||
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function;
|
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function;
|
||||||
JetBlockExpression blockExpression = functionLiteralExpression.getBodyExpression();
|
JetBlockExpression blockExpression = functionLiteralExpression.getBodyExpression();
|
||||||
assert blockExpression != null;
|
assert blockExpression != null;
|
||||||
getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context);
|
getBlockReturnedType(newContext.scope, blockExpression, CoercionStrategy.COERCION_TO_UNIT, context, trace);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
expressionTypingFacade.getType(bodyExpression, newContext, !blockBody);
|
expressionTypingFacade.getType(bodyExpression, newContext, !blockBody);
|
||||||
@@ -160,7 +205,7 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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();
|
List<JetElement> block = expression.getStatements();
|
||||||
if (block.isEmpty()) {
|
if (block.isEmpty()) {
|
||||||
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, context);
|
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, context);
|
||||||
@@ -169,7 +214,7 @@ public class ExpressionTypingServices {
|
|||||||
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
||||||
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
|
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace)).setDebugName("getBlockReturnedType");
|
||||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context);
|
return getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression, context, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<JetExpression, JetType> collectReturnedExpressionsWithTypes(
|
private Map<JetExpression, JetType> collectReturnedExpressionsWithTypes(
|
||||||
@@ -180,8 +225,10 @@ public class ExpressionTypingServices {
|
|||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
assert bodyExpression != null;
|
assert bodyExpression != null;
|
||||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
|
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
|
||||||
expressionTypingFacade.getType(bodyExpression, ExpressionTypingContext.newContext(function.getProject(), semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
expressionTypingFacade.getType(bodyExpression, ExpressionTypingContext.newContext(
|
||||||
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN, false), !function.hasBlockBody());
|
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
|
//todo function literals
|
||||||
final Collection<JetExpression> returnedExpressions = Lists.newArrayList();
|
final Collection<JetExpression> returnedExpressions = Lists.newArrayList();
|
||||||
if (function.hasBlockBody()) {
|
if (function.hasBlockBody()) {
|
||||||
@@ -225,7 +272,7 @@ public class ExpressionTypingServices {
|
|||||||
return typeMap;
|
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()) {
|
if (block.isEmpty()) {
|
||||||
return JetStandardClasses.getUnitType();
|
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) {
|
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) {
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
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.*;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||||
import org.jetbrains.jet.lang.types.Variance;
|
import org.jetbrains.jet.lang.types.Variance;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -78,8 +79,8 @@ public class ExpressionTypingUtils {
|
|||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isBoolean(@NotNull JetSemanticServices semanticServices, @NotNull JetType type) {
|
public static boolean isBoolean(@NotNull JetType type) {
|
||||||
return semanticServices.getTypeChecker().isSubtypeOf(type, semanticServices.getStandardLibrary().getBooleanType());
|
return JetTypeChecker.INSTANCE.isSubtypeOf(type, JetStandardLibrary.getInstance().getBooleanType());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean ensureBooleanResult(JetExpression operationSign, String name, JetType resultType, ExpressionTypingContext context) {
|
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) {
|
public static boolean ensureBooleanResultWithCustomSubject(JetExpression operationSign, JetType resultType, String subjectName, ExpressionTypingContext context) {
|
||||||
if (resultType != null) {
|
if (resultType != null) {
|
||||||
// TODO : Relax?
|
// TODO : Relax?
|
||||||
if (!isBoolean(context.semanticServices, resultType)) {
|
if (!isBoolean(resultType)) {
|
||||||
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, context.semanticServices.getStandardLibrary().getBooleanType(), resultType));
|
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, JetStandardLibrary.getInstance().getBooleanType(), resultType));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,18 +99,18 @@ public class ExpressionTypingUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetType getDefaultType(JetSemanticServices semanticServices, IElementType constantType) {
|
public static JetType getDefaultType(IElementType constantType) {
|
||||||
if (constantType == JetNodeTypes.INTEGER_CONSTANT) {
|
if (constantType == JetNodeTypes.INTEGER_CONSTANT) {
|
||||||
return semanticServices.getStandardLibrary().getIntType();
|
return JetStandardLibrary.getInstance().getIntType();
|
||||||
}
|
}
|
||||||
else if (constantType == JetNodeTypes.FLOAT_CONSTANT) {
|
else if (constantType == JetNodeTypes.FLOAT_CONSTANT) {
|
||||||
return semanticServices.getStandardLibrary().getDoubleType();
|
return JetStandardLibrary.getInstance().getDoubleType();
|
||||||
}
|
}
|
||||||
else if (constantType == JetNodeTypes.BOOLEAN_CONSTANT) {
|
else if (constantType == JetNodeTypes.BOOLEAN_CONSTANT) {
|
||||||
return semanticServices.getStandardLibrary().getBooleanType();
|
return JetStandardLibrary.getInstance().getBooleanType();
|
||||||
}
|
}
|
||||||
else if (constantType == JetNodeTypes.CHARACTER_CONSTANT) {
|
else if (constantType == JetNodeTypes.CHARACTER_CONSTANT) {
|
||||||
return semanticServices.getStandardLibrary().getCharType();
|
return JetStandardLibrary.getInstance().getCharType();
|
||||||
}
|
}
|
||||||
else if (constantType == JetNodeTypes.NULL) {
|
else if (constantType == JetNodeTypes.NULL) {
|
||||||
return JetStandardClasses.getNullableNothingType();
|
return JetStandardClasses.getNullableNothingType();
|
||||||
@@ -148,12 +149,12 @@ public class ExpressionTypingUtils {
|
|||||||
return expression;
|
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");
|
JetExpression expression = JetPsiFactory.createExpression(project, "fake");
|
||||||
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getType());
|
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getType());
|
||||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
project,
|
expressionTypingServices,
|
||||||
JetSemanticServices.createSemanticServices(project),
|
|
||||||
new HashMap<JetPattern, DataFlowInfo>(),
|
new HashMap<JetPattern, DataFlowInfo>(),
|
||||||
new HashMap<JetPattern, List<VariableDescriptor>>(),
|
new HashMap<JetPattern, List<VariableDescriptor>>(),
|
||||||
new LabelResolver(),
|
new LabelResolver(),
|
||||||
|
|||||||
+6
-6
@@ -79,11 +79,11 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType visitObjectDeclaration(JetObjectDeclaration declaration, ExpressionTypingContext context) {
|
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);
|
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
|
||||||
if (classDescriptor != null) {
|
if (classDescriptor != null) {
|
||||||
VariableDescriptor variableDescriptor = context.getDescriptorResolver()
|
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver()
|
||||||
.resolveObjectDeclaration(scope.getContainingDeclaration(), declaration, classDescriptor);
|
.resolveObjectDeclaration(scope.getContainingDeclaration(), declaration, classDescriptor, context.trace);
|
||||||
scope.addVariableDescriptor(variableDescriptor);
|
scope.addVariableDescriptor(variableDescriptor);
|
||||||
}
|
}
|
||||||
return DataFlowUtils.checkStatementType(declaration, context);
|
return DataFlowUtils.checkStatementType(declaration, context);
|
||||||
@@ -106,7 +106,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
context.trace.report(LOCAL_VARIABLE_WITH_SETTER.on(setter));
|
context.trace.report(LOCAL_VARIABLE_WITH_SETTER.on(setter));
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableDescriptor propertyDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo);
|
VariableDescriptor propertyDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property, context.dataFlowInfo, context.trace);
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (property.getPropertyTypeRef() != null && initializer != null) {
|
if (property.getPropertyTypeRef() != null && initializer != null) {
|
||||||
JetType outType = propertyDescriptor.getType();
|
JetType outType = propertyDescriptor.getType();
|
||||||
@@ -126,10 +126,10 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
|
public JetType visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
|
||||||
SimpleFunctionDescriptor functionDescriptor = context.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function);
|
SimpleFunctionDescriptor functionDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function, context.trace);
|
||||||
scope.addFunctionDescriptor(functionDescriptor);
|
scope.addFunctionDescriptor(functionDescriptor);
|
||||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
|
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
|
||||||
context.getServices().checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo);
|
context.expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo, context.trace);
|
||||||
return DataFlowUtils.checkStatementType(function, context);
|
return DataFlowUtils.checkStatementType(function, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-11
@@ -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.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -61,7 +63,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
context.patternsToDataFlowInfo.put(pattern, newDataFlowInfo);
|
context.patternsToDataFlowInfo.put(pattern, newDataFlowInfo);
|
||||||
context.patternsToBoundVariableLists.put(pattern, scopeToExtend.getDeclaredVariables());
|
context.patternsToBoundVariableLists.put(pattern, scopeToExtend.getDeclaredVariables());
|
||||||
}
|
}
|
||||||
return DataFlowUtils.checkType(context.semanticServices.getStandardLibrary().getBooleanType(), expression, contextWithExpectedType);
|
return DataFlowUtils.checkType(JetStandardLibrary.getInstance().getBooleanType(), expression, contextWithExpectedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -74,7 +76,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
// TODO :change scope according to the bound value in the when header
|
// TODO :change scope according to the bound value in the when header
|
||||||
final JetExpression subjectExpression = expression.getSubjectExpression();
|
final JetExpression subjectExpression = expression.getSubjectExpression();
|
||||||
|
|
||||||
final JetType subjectType = subjectExpression != null ? context.getServices().safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE) : 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;
|
final DataFlowValue variableDescriptor = subjectExpression != null ? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext()) : DataFlowValue.NULL;
|
||||||
|
|
||||||
// TODO : exhaustive patterns
|
// TODO : exhaustive patterns
|
||||||
@@ -115,7 +117,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (bodyExpression != null) {
|
if (bodyExpression != null) {
|
||||||
ExpressionTypingContext newContext = contextWithExpectedType.replaceScope(scopeToExtend).replaceDataFlowInfo(newDataFlowInfo);
|
ExpressionTypingContext newContext = contextWithExpectedType.replaceScope(scopeToExtend).replaceDataFlowInfo(newDataFlowInfo);
|
||||||
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
|
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
|
||||||
JetType type = context.getServices().getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext);
|
JetType type = context.expressionTypingServices.getBlockReturnedTypeWithWritableScope(scopeToExtend, Collections.singletonList(bodyExpression), coercionStrategy, newContext, context.trace);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
expressionTypes.add(type);
|
expressionTypes.add(type);
|
||||||
}
|
}
|
||||||
@@ -180,7 +182,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
public void visitTypePattern(JetTypePattern typePattern) {
|
public void visitTypePattern(JetTypePattern typePattern) {
|
||||||
JetTypeReference typeReference = typePattern.getTypeReference();
|
JetTypeReference typeReference = typePattern.getTypeReference();
|
||||||
if (typeReference == null) return;
|
if (typeReference == null) return;
|
||||||
JetType type = context.getTypeResolver().resolveType(context.scope, typeReference);
|
JetType type = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, typeReference, context.trace, true);
|
||||||
checkTypeCompatibility(type, subjectType, typePattern);
|
checkTypeCompatibility(type, subjectType, typePattern);
|
||||||
result.set(context.dataFlowInfo.establishSubtyping(subjectVariables, type));
|
result.set(context.dataFlowInfo.establishSubtyping(subjectVariables, type));
|
||||||
}
|
}
|
||||||
@@ -238,8 +240,8 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (expression == null) return;
|
if (expression == null) return;
|
||||||
JetType type = facade.getType(expression, context.replaceScope(scopeToExtend));
|
JetType type = facade.getType(expression, context.replaceScope(scopeToExtend));
|
||||||
if (conditionExpected) {
|
if (conditionExpected) {
|
||||||
JetType booleanType = context.semanticServices.getStandardLibrary().getBooleanType();
|
JetType booleanType = JetStandardLibrary.getInstance().getBooleanType();
|
||||||
if (type != null && !context.semanticServices.getTypeChecker().equalTypes(booleanType, type)) {
|
if (type != null && !JetTypeChecker.INSTANCE.equalTypes(booleanType, type)) {
|
||||||
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(pattern, type));
|
context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(pattern, type));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -251,11 +253,11 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
public void visitBindingPattern(JetBindingPattern pattern) {
|
public void visitBindingPattern(JetBindingPattern pattern) {
|
||||||
JetProperty variableDeclaration = pattern.getVariableDeclaration();
|
JetProperty variableDeclaration = pattern.getVariableDeclaration();
|
||||||
JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef();
|
JetTypeReference propertyTypeRef = variableDeclaration.getPropertyTypeRef();
|
||||||
JetType type = propertyTypeRef == null ? subjectType : context.getTypeResolver().resolveType(context.scope, propertyTypeRef);
|
JetType type = propertyTypeRef == null ? subjectType : context.expressionTypingServices.getTypeResolver().resolveType(context.scope, propertyTypeRef, context.trace, true);
|
||||||
VariableDescriptor variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type);
|
VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptorWithType(context.scope.getContainingDeclaration(), variableDeclaration, type, context.trace);
|
||||||
scopeToExtend.addVariableDescriptor(variableDescriptor);
|
scopeToExtend.addVariableDescriptor(variableDescriptor);
|
||||||
if (propertyTypeRef != null) {
|
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));
|
context.trace.report(TYPE_MISMATCH_IN_BINDING_PATTERN.on(propertyTypeRef, type, subjectType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,12 +280,12 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
if (type == null) {
|
if (type == null) {
|
||||||
return;
|
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));
|
context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType));
|
||||||
return;
|
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));
|
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 com.intellij.psi.PsiFileFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
@@ -54,11 +53,28 @@ public class JetStandardLibrary {
|
|||||||
|
|
||||||
private static JetStandardLibrary instance = null;
|
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
|
// This method must be called at least once per application run, on any project
|
||||||
// before any type checking is run
|
// before any type checking is run
|
||||||
public static synchronized void initialize(@NotNull Project project) {
|
public static synchronized void initialize(@NotNull Project project) {
|
||||||
if (instance == null) {
|
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);
|
files.add(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
|
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
|
||||||
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
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());
|
AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());
|
||||||
initStdClasses();
|
initStdClasses();
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<orderEntry type="module" module-name="cli" />
|
<orderEntry type="module" module-name="cli" />
|
||||||
<orderEntry type="library" name="idea-full" level="project" />
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
<orderEntry type="library" name="asm" level="project" />
|
<orderEntry type="library" name="asm" level="project" />
|
||||||
|
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import junit.framework.Test;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -112,8 +111,7 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
|
|||||||
jetCoreEnvironment.addToClasspath(tmpdir);
|
jetCoreEnvironment.addToClasspath(tmpdir);
|
||||||
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
||||||
|
|
||||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(jetCoreEnvironment.getProject());
|
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), new BindingTraceContext());
|
||||||
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), jetSemanticServices, new BindingTraceContext());
|
|
||||||
|
|
||||||
JavaDescriptorResolver javaDescriptorResolver = semanticServices.getDescriptorResolver();
|
JavaDescriptorResolver javaDescriptorResolver = semanticServices.getDescriptorResolver();
|
||||||
return javaDescriptorResolver.resolveNamespace("test");
|
return javaDescriptorResolver.resolveNamespace("test");
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import org.jetbrains.jet.JetTestUtils;
|
|||||||
import org.jetbrains.jet.codegen.ClassBuilderFactories;
|
import org.jetbrains.jet.codegen.ClassBuilderFactories;
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
import org.jetbrains.jet.codegen.GenerationState;
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
@@ -90,8 +89,7 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
|
|||||||
jetCoreEnvironment.addToClasspath(tmpdir);
|
jetCoreEnvironment.addToClasspath(tmpdir);
|
||||||
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
||||||
|
|
||||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(jetCoreEnvironment.getProject());
|
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), new BindingTraceContext());
|
||||||
JavaSemanticServices semanticServices = new JavaSemanticServices(jetCoreEnvironment.getProject(), jetSemanticServices, new BindingTraceContext());
|
|
||||||
|
|
||||||
JavaDescriptorResolver javaDescriptorResolver = semanticServices.getDescriptorResolver();
|
JavaDescriptorResolver javaDescriptorResolver = semanticServices.getDescriptorResolver();
|
||||||
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace("test");
|
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace("test");
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.project.Project;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
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.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
@@ -135,8 +134,7 @@ public abstract class ExpectedResolveData {
|
|||||||
}
|
}
|
||||||
final Set<PsiElement> unresolvedReferences = Sets.newHashSet();
|
final Set<PsiElement> unresolvedReferences = Sets.newHashSet();
|
||||||
Project project = files.iterator().next().getProject();
|
Project project = files.iterator().next().getProject();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
JetStandardLibrary lib = JetStandardLibrary.getInstance();
|
||||||
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
|
||||||
|
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.resolve;
|
package org.jetbrains.jet.resolve;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
import com.intellij.openapi.application.PathManager;
|
import com.intellij.openapi.application.PathManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
import com.intellij.psi.JavaPsiFacade;
|
||||||
@@ -25,17 +26,16 @@ import com.intellij.psi.PsiMethod;
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
@@ -119,8 +119,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private PsiClass findClass(String qualifiedName) {
|
private PsiClass findClass(String qualifiedName) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(project);
|
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, new BindingTraceContext());
|
||||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, jetSemanticServices, new BindingTraceContext());
|
|
||||||
return javaSemanticServices.getDescriptorResolver().findClass(qualifiedName);
|
return javaSemanticServices.getDescriptorResolver().findClass(qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +134,12 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
|||||||
List<JetType> parameterTypeList = Arrays.asList(parameterType);
|
List<JetType> parameterTypeList = Arrays.asList(parameterType);
|
||||||
// JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
|
// JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
|
||||||
|
|
||||||
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(
|
OverloadResolutionResults<FunctionDescriptor> functions = callResolver.resolveExactSignature(
|
||||||
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
|
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
|
||||||
for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
|
for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
|
||||||
|
|||||||
@@ -16,13 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.types;
|
package org.jetbrains.jet.types;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||||
@@ -50,9 +52,13 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
private JetScope scope;
|
private JetScope scope;
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
JetStandardLibrary library = JetStandardLibrary.getInstance();
|
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
|
@Override
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
|
protected void configureAfter() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
JetStandardLibrary library = injector.getInstance(JetStandardLibrary.class);
|
||||||
|
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||||
scope = createScope(library.getLibraryScope());
|
scope = createScope(library.getLibraryScope());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +78,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
private MutableClassDescriptor createClassDescriptor(ClassKind kind, JetClass aClass) {
|
private MutableClassDescriptor createClassDescriptor(ClassKind kind, JetClass aClass) {
|
||||||
MutableClassDescriptor classDescriptor = new MutableClassDescriptor(JetTestUtils.DUMMY_TRACE, root, scope, kind);
|
MutableClassDescriptor classDescriptor = new MutableClassDescriptor(JetTestUtils.DUMMY_TRACE, root, scope, kind);
|
||||||
descriptorResolver.resolveMutableClassDescriptor(aClass, classDescriptor);
|
descriptorResolver.resolveMutableClassDescriptor(aClass, classDescriptor, JetTestUtils.DUMMY_TRACE);
|
||||||
return classDescriptor;
|
return classDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +96,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetNamedFunction function = (JetNamedFunction) declarations.get(0);
|
JetNamedFunction function = (JetNamedFunction) declarations.get(0);
|
||||||
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function);
|
SimpleFunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function, JetTestUtils.DUMMY_TRACE);
|
||||||
|
|
||||||
assertEquals(expectedFunctionModality, functionDescriptor.getModality());
|
assertEquals(expectedFunctionModality, functionDescriptor.getModality());
|
||||||
}
|
}
|
||||||
@@ -101,7 +107,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetProperty property = (JetProperty) declarations.get(0);
|
JetProperty property = (JetProperty) declarations.get(0);
|
||||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
|
||||||
|
|
||||||
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
|
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
|
||||||
}
|
}
|
||||||
@@ -113,7 +119,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<JetDeclaration> declarations = aClass.getDeclarations();
|
List<JetDeclaration> declarations = aClass.getDeclarations();
|
||||||
JetProperty property = (JetProperty) declarations.get(0);
|
JetProperty property = (JetProperty) declarations.get(0);
|
||||||
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property);
|
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE);
|
||||||
PropertyAccessorDescriptor propertyAccessor = isGetter
|
PropertyAccessorDescriptor propertyAccessor = isGetter
|
||||||
? propertyDescriptor.getGetter()
|
? propertyDescriptor.getGetter()
|
||||||
: propertyDescriptor.getSetter();
|
: propertyDescriptor.getSetter();
|
||||||
|
|||||||
@@ -16,16 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.types;
|
package org.jetbrains.jet.types;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.OverloadUtil;
|
import org.jetbrains.jet.lang.resolve.OverloadUtil;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
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 ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||||
private JetStandardLibrary library;
|
private JetStandardLibrary library;
|
||||||
private JetSemanticServices semanticServices;
|
|
||||||
private DescriptorResolver descriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getInstance();
|
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
@Override
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
protected void configureAfter() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
library = injector.getInstance(JetStandardLibrary.class);
|
||||||
|
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -171,7 +176,7 @@ public class JetOverloadTest extends JetLiteFixture {
|
|||||||
|
|
||||||
private FunctionDescriptor makeFunction(String funDecl) {
|
private FunctionDescriptor makeFunction(String funDecl) {
|
||||||
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
||||||
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
|
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function, JetTestUtils.DUMMY_TRACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,16 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.types;
|
package org.jetbrains.jet.types;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
import com.google.inject.Injector;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
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 ModuleDescriptor root = new ModuleDescriptor("test_root");
|
||||||
private JetStandardLibrary library;
|
private JetStandardLibrary library;
|
||||||
private JetSemanticServices semanticServices;
|
|
||||||
private DescriptorResolver descriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getInstance();
|
Injector injector = Guice.createInjector(new TopDownAnalysisModule(getProject(), false) {
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
@Override
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
protected void configureAfter() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
library = injector.getInstance(JetStandardLibrary.class);
|
||||||
|
descriptorResolver = injector.getInstance(DescriptorResolver.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -161,6 +166,6 @@ public class JetOverridingTest extends JetLiteFixture {
|
|||||||
|
|
||||||
private FunctionDescriptor makeFunction(String funDecl) {
|
private FunctionDescriptor makeFunction(String funDecl) {
|
||||||
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
JetNamedFunction function = JetPsiFactory.createFunction(getProject(), funDecl);
|
||||||
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function);
|
return descriptorResolver.resolveFunctionDescriptor(root, library.getLibraryScope(), function, JetTestUtils.DUMMY_TRACE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,14 @@
|
|||||||
package org.jetbrains.jet.types;
|
package org.jetbrains.jet.types;
|
||||||
|
|
||||||
import com.google.common.collect.Sets;
|
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.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
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.ExpressionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
@@ -48,11 +51,12 @@ import java.util.*;
|
|||||||
public class JetTypeCheckerTest extends JetLiteFixture {
|
public class JetTypeCheckerTest extends JetLiteFixture {
|
||||||
|
|
||||||
private JetStandardLibrary library;
|
private JetStandardLibrary library;
|
||||||
private JetSemanticServices semanticServices;
|
|
||||||
private ClassDefinitions classDefinitions;
|
private ClassDefinitions classDefinitions;
|
||||||
private DescriptorResolver descriptorResolver;
|
private DescriptorResolver descriptorResolver;
|
||||||
private JetScope scopeWithImports;
|
private JetScope scopeWithImports;
|
||||||
private TypeResolver typeResolver;
|
private TypeResolver typeResolver;
|
||||||
|
private ExpressionTypingServices expressionTypingServices;
|
||||||
|
|
||||||
|
|
||||||
public JetTypeCheckerTest() {
|
public JetTypeCheckerTest() {
|
||||||
super("");
|
super("");
|
||||||
@@ -62,11 +66,19 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getInstance();
|
library = JetStandardLibrary.getInstance();
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
|
||||||
classDefinitions = new ClassDefinitions();
|
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);
|
scopeWithImports = addImports(classDefinitions.BASIC_SCOPE);
|
||||||
typeResolver = new TypeResolver(semanticServices, JetTestUtils.DUMMY_TRACE, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -513,7 +525,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
for (String type : types) {
|
for (String type : types) {
|
||||||
typesToIntersect.add(makeType(type));
|
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);
|
// assertNotNull("Intersection is null for " + typesToIntersect, result);
|
||||||
assertEquals(makeType(expected), result);
|
assertEquals(makeType(expected), result);
|
||||||
}
|
}
|
||||||
@@ -530,7 +542,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
private void assertSubtypingRelation(String subtype, String supertype, boolean expected) {
|
private void assertSubtypingRelation(String subtype, String supertype, boolean expected) {
|
||||||
JetType typeNode1 = makeType(subtype);
|
JetType typeNode1 = makeType(subtype);
|
||||||
JetType typeNode2 = makeType(supertype);
|
JetType typeNode2 = makeType(supertype);
|
||||||
boolean result = semanticServices.getTypeChecker().isSubtypeOf(
|
boolean result = JetTypeChecker.INSTANCE.isSubtypeOf(
|
||||||
typeNode1,
|
typeNode1,
|
||||||
typeNode2);
|
typeNode2);
|
||||||
String modifier = expected ? "not " : "";
|
String modifier = expected ? "not " : "";
|
||||||
@@ -540,14 +552,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
private void assertType(String expression, JetType expectedType) {
|
private void assertType(String expression, JetType expectedType) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||||
JetType type = 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));
|
assertTrue(type + " != " + expectedType, type.equals(expectedType));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertErrorType(String expression) {
|
private void assertErrorType(String expression) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||||
JetType type = 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));
|
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) {
|
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
JetExpression jetExpression = JetPsiFactory.createExpression(project, expression);
|
||||||
JetType type = 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);
|
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
|
||||||
assertEquals(expectedType, type);
|
assertEquals(expectedType, type);
|
||||||
}
|
}
|
||||||
@@ -578,7 +590,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
private WritableScopeImpl addImports(JetScope scope) {
|
private WritableScopeImpl addImports(JetScope scope) {
|
||||||
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING);
|
WritableScopeImpl writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), RedeclarationHandler.DO_NOTHING);
|
||||||
writableScope.importScope(library.getLibraryScope());
|
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("", JavaBridgeConfiguration.createNamespaceDescriptor(JavaDescriptorResolver.JAVA_ROOT, ""), javaSemanticServices));
|
||||||
writableScope.importScope(new JavaPackageScope("java.lang", JavaBridgeConfiguration.createNamespaceDescriptor("lang", "java.lang"), javaSemanticServices));
|
writableScope.importScope(new JavaPackageScope("java.lang", JavaBridgeConfiguration.createNamespaceDescriptor("lang", "java.lang"), javaSemanticServices));
|
||||||
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||||
@@ -590,7 +602,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JetType makeType(JetScope scope, String typeStr) {
|
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 {
|
private class ClassDefinitions {
|
||||||
@@ -657,7 +669,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
|
Set<FunctionDescriptor> writableFunctionGroup = Sets.newLinkedHashSet();
|
||||||
ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest");
|
ModuleDescriptor module = new ModuleDescriptor("TypeCheckerTest");
|
||||||
for (String funDecl : FUNCTION_DECLARATIONS) {
|
for (String funDecl : FUNCTION_DECLARATIONS) {
|
||||||
FunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl));
|
FunctionDescriptor functionDescriptor = descriptorResolver.resolveFunctionDescriptor(module, this, JetPsiFactory.createFunction(getProject(), funDecl), JetTestUtils.DUMMY_TRACE);
|
||||||
if (name.equals(functionDescriptor.getName())) {
|
if (name.equals(functionDescriptor.getName())) {
|
||||||
writableFunctionGroup.add(functionDescriptor);
|
writableFunctionGroup.add(functionDescriptor);
|
||||||
}
|
}
|
||||||
@@ -682,14 +694,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
|
|
||||||
// This call has side-effects on the parameterScope (fills it in)
|
// This call has side-effects on the parameterScope (fills it in)
|
||||||
List<TypeParameterDescriptor> typeParameters
|
List<TypeParameterDescriptor> typeParameters
|
||||||
= descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters());
|
= descriptorResolver.resolveTypeParameters(classDescriptor, parameterScope, classElement.getTypeParameters(), JetTestUtils.DUMMY_TRACE);
|
||||||
descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters);
|
descriptorResolver.resolveGenericBounds(classElement, parameterScope, typeParameters, JetTestUtils.DUMMY_TRACE);
|
||||||
|
|
||||||
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
|
List<JetDelegationSpecifier> delegationSpecifiers = classElement.getDelegationSpecifiers();
|
||||||
// TODO : assuming that the hierarchy is acyclic
|
// TODO : assuming that the hierarchy is acyclic
|
||||||
Collection<JetType> supertypes = delegationSpecifiers.isEmpty()
|
Collection<JetType> supertypes = delegationSpecifiers.isEmpty()
|
||||||
? Collections.singleton(JetStandardClasses.getAnyType())
|
? Collections.singleton(JetStandardClasses.getAnyType())
|
||||||
: descriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver);
|
: descriptorResolver.resolveDelegationSpecifiers(parameterScope, delegationSpecifiers, typeResolver, JetTestUtils.DUMMY_TRACE, true);
|
||||||
// for (JetType supertype: supertypes) {
|
// for (JetType supertype: supertypes) {
|
||||||
// if (supertype.getConstructor().isSealed()) {
|
// if (supertype.getConstructor().isSealed()) {
|
||||||
// trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype);
|
// trace.getErrorHandler().genericError(classElement.getNameAsDeclaration().getNode(), "Class " + classElement.getName() + " can not extend final type " + supertype);
|
||||||
@@ -706,7 +718,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void visitProperty(JetProperty property) {
|
public void visitProperty(JetProperty property) {
|
||||||
if (property.getPropertyTypeRef() != null) {
|
if (property.getPropertyTypeRef() != null) {
|
||||||
memberDeclarations.addPropertyDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property));
|
memberDeclarations.addPropertyDescriptor(descriptorResolver.resolvePropertyDescriptor(classDescriptor, parameterScope, property, JetTestUtils.DUMMY_TRACE));
|
||||||
} else {
|
} else {
|
||||||
// TODO : Caution: a cyclic dependency possible
|
// TODO : Caution: a cyclic dependency possible
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -716,7 +728,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void visitNamedFunction(JetNamedFunction function) {
|
public void visitNamedFunction(JetNamedFunction function) {
|
||||||
if (function.getReturnTypeRef() != null) {
|
if (function.getReturnTypeRef() != null) {
|
||||||
memberDeclarations.addFunctionDescriptor(descriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function));
|
memberDeclarations.addFunctionDescriptor(descriptorResolver.resolveFunctionDescriptor(classDescriptor, parameterScope, function, JetTestUtils.DUMMY_TRACE));
|
||||||
} else {
|
} else {
|
||||||
// TODO : Caution: a cyclic dependency possible
|
// TODO : Caution: a cyclic dependency possible
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -740,11 +752,11 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
for (JetSecondaryConstructor constructor : classElement.getSecondaryConstructors()) {
|
for (JetSecondaryConstructor constructor : classElement.getSecondaryConstructors()) {
|
||||||
ConstructorDescriptorImpl functionDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor);
|
ConstructorDescriptorImpl functionDescriptor = descriptorResolver.resolveSecondaryConstructorDescriptor(memberDeclarations, classDescriptor, constructor, JetTestUtils.DUMMY_TRACE);
|
||||||
functionDescriptor.setReturnType(classDescriptor.getDefaultType());
|
functionDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||||
constructors.add(functionDescriptor);
|
constructors.add(functionDescriptor);
|
||||||
}
|
}
|
||||||
ConstructorDescriptorImpl primaryConstructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement);
|
ConstructorDescriptorImpl primaryConstructorDescriptor = descriptorResolver.resolvePrimaryConstructorDescriptor(scope, classDescriptor, classElement, JetTestUtils.DUMMY_TRACE);
|
||||||
if (primaryConstructorDescriptor != null) {
|
if (primaryConstructorDescriptor != null) {
|
||||||
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
primaryConstructorDescriptor.setReturnType(classDescriptor.getDefaultType());
|
||||||
constructors.add(primaryConstructorDescriptor);
|
constructors.add(primaryConstructorDescriptor);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="junit-plugin" level="project" />
|
||||||
<orderEntry type="module" module-name="j2k" />
|
<orderEntry type="module" module-name="j2k" />
|
||||||
<orderEntry type="module" module-name="js.translator" />
|
<orderEntry type="module" module-name="js.translator" />
|
||||||
|
<orderEntry type="library" name="guice-3.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.liveTemplates.macro;
|
package org.jetbrains.jet.plugin.liveTemplates.macro;
|
||||||
|
|
||||||
|
import com.google.inject.Guice;
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
import com.intellij.codeInsight.lookup.LookupElement;
|
||||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||||
import com.intellij.codeInsight.template.Expression;
|
import com.intellij.codeInsight.template.Expression;
|
||||||
@@ -34,7 +35,10 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TopDownAnalysisModule;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
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 org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -51,7 +55,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
|||||||
private JetNamedDeclaration[] getVariables(Expression[] params, ExpressionContext context) {
|
private JetNamedDeclaration[] getVariables(Expression[] params, ExpressionContext context) {
|
||||||
if (params.length != 0) return null;
|
if (params.length != 0) return null;
|
||||||
|
|
||||||
Project project = context.getProject();
|
final Project project = context.getProject();
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||||
|
|
||||||
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
|
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
|
||||||
@@ -66,11 +70,17 @@ public abstract class BaseJetVariableMacro extends Macro {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ExpressionTypingServices callResolverContext = Guice.createInjector(new TopDownAnalysisModule(project, false) {
|
||||||
|
@Override
|
||||||
|
protected void configureAfter() {
|
||||||
|
}
|
||||||
|
}).getInstance(ExpressionTypingServices.class);
|
||||||
|
|
||||||
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
||||||
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
|
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
|
||||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||||
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
||||||
if (isSuitable(variableDescriptor, scope, project)) {
|
if (isSuitable(variableDescriptor, scope, project, callResolverContext)) {
|
||||||
filteredDescriptors.add(variableDescriptor);
|
filteredDescriptors.add(variableDescriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +99,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
|||||||
return declarations.toArray(new JetNamedDeclaration[declarations.size()]);
|
return declarations.toArray(new JetNamedDeclaration[declarations.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project);
|
protected abstract boolean isSuitable(@NotNull VariableDescriptor variableDescriptor, @NotNull JetScope scope, @NotNull Project project, ExpressionTypingServices callResolverContext);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JetExpression findContextExpression(PsiFile psiFile, int startOffset) {
|
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.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,7 +39,7 @@ public class JetAnyVariableMacro extends BaseJetVariableMacro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.project.Project;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
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.lang.types.expressions.ExpressionTypingUtils;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ import org.jetbrains.jet.plugin.JetBundle;
|
|||||||
* @since 2/7/12
|
* @since 2/7/12
|
||||||
*/
|
*/
|
||||||
public class JetIterableVariableMacro extends BaseJetVariableMacro {
|
public class JetIterableVariableMacro extends BaseJetVariableMacro {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "kotlinIterableVariable";
|
return "kotlinIterableVariable";
|
||||||
@@ -39,7 +41,7 @@ public class JetIterableVariableMacro extends BaseJetVariableMacro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 ExpressionTypingUtils.isVariableIterable(project, variableDescriptor, scope);
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
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.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -95,15 +94,14 @@ public final class AnalyzerFacadeForJS {
|
|||||||
public static BindingContext analyzeNamespace(@NotNull JetFile file) {
|
public static BindingContext analyzeNamespace(@NotNull JetFile file) {
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
Project project = file.getProject();
|
Project project = file.getProject();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
|
||||||
return AnalyzingUtils.analyzeFilesWithGivenTrace(
|
return AnalyzingUtils.analyzeFilesWithGivenTrace(
|
||||||
project,
|
project,
|
||||||
JsConfiguration.jsLibConfiguration(project),
|
JsConfiguration.jsLibConfiguration(project),
|
||||||
Collections.singletonList(file),
|
Collections.singletonList(file),
|
||||||
Predicates.<PsiFile>alwaysTrue(),
|
Predicates.<PsiFile>alwaysTrue(),
|
||||||
JetControlFlowDataTraceFactory.EMPTY,
|
JetControlFlowDataTraceFactory.EMPTY,
|
||||||
bindingTraceContext,
|
bindingTraceContext
|
||||||
semanticServices);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class JsConfiguration implements Configuration {
|
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