script parameters
still a lot of things to do
This commit is contained in:
@@ -21,10 +21,12 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BodiesResolveContext;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -34,10 +36,12 @@ public interface AnalyzerFacade {
|
||||
@NotNull
|
||||
AnalyzeExhaust analyzeFiles(@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull List<AnalyzerScriptParameter> scriptParameters,
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely);
|
||||
|
||||
@NotNull
|
||||
AnalyzeExhaust analyzeBodiesInFiles(@NotNull Project project,
|
||||
@NotNull List<AnalyzerScriptParameter> scriptParameters,
|
||||
@NotNull Predicate<PsiFile> filesForBodiesResolve,
|
||||
@NotNull BindingTrace traceContext,
|
||||
@NotNull BodiesResolveContext bodiesResolveContext);
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.types.DependencyClassByQualifiedNameResolverDummyImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DeclarationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
@@ -41,6 +42,7 @@ import org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadResolver;
|
||||
import org.jetbrains.jet.lang.resolve.OverrideResolver;
|
||||
import org.jetbrains.jet.lang.resolve.TypeHierarchyResolver;
|
||||
import org.jetbrains.jet.lang.resolve.ScriptResolver;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
|
||||
@@ -63,6 +65,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
private final ObservableBindingTrace observableBindingTrace;
|
||||
private final ModuleDescriptor moduleDescriptor;
|
||||
private final ModuleConfiguration moduleConfiguration;
|
||||
private DependencyClassByQualifiedNameResolverDummyImpl dependencyClassByQualifiedNameResolverDummyImpl;
|
||||
private DeclarationResolver declarationResolver;
|
||||
private AnnotationResolver annotationResolver;
|
||||
private CallResolver callResolver;
|
||||
@@ -76,6 +79,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
private OverloadResolver overloadResolver;
|
||||
private OverrideResolver overrideResolver;
|
||||
private TypeHierarchyResolver typeHierarchyResolver;
|
||||
private ScriptResolver scriptResolver;
|
||||
|
||||
public InjectorForTopDownAnalyzerBasic(
|
||||
@NotNull Project project,
|
||||
@@ -95,6 +99,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.observableBindingTrace = observableBindingTrace;
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.moduleConfiguration = moduleConfiguration;
|
||||
this.dependencyClassByQualifiedNameResolverDummyImpl = new DependencyClassByQualifiedNameResolverDummyImpl();
|
||||
this.declarationResolver = new DeclarationResolver();
|
||||
this.annotationResolver = new AnnotationResolver();
|
||||
this.callResolver = new CallResolver();
|
||||
@@ -108,6 +113,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.overloadResolver = new OverloadResolver();
|
||||
this.overrideResolver = new OverrideResolver();
|
||||
this.typeHierarchyResolver = new TypeHierarchyResolver();
|
||||
this.scriptResolver = new ScriptResolver();
|
||||
|
||||
this.topDownAnalyzer.setBodyResolver(bodyResolver);
|
||||
this.topDownAnalyzer.setContext(topDownAnalysisContext);
|
||||
@@ -115,6 +121,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.topDownAnalyzer.setDeclarationResolver(declarationResolver);
|
||||
this.topDownAnalyzer.setDeclarationsChecker(declarationsChecker);
|
||||
this.topDownAnalyzer.setDelegationResolver(delegationResolver);
|
||||
this.topDownAnalyzer.setDependencyClassByQualifiedNameResolver(dependencyClassByQualifiedNameResolverDummyImpl);
|
||||
this.topDownAnalyzer.setModuleDescriptor(moduleDescriptor);
|
||||
this.topDownAnalyzer.setNamespaceFactory(namespaceFactoryImpl);
|
||||
this.topDownAnalyzer.setOverloadResolver(overloadResolver);
|
||||
@@ -128,6 +135,7 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
this.bodyResolver.setCallResolver(callResolver);
|
||||
this.bodyResolver.setDescriptorResolver(descriptorResolver);
|
||||
this.bodyResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
this.bodyResolver.setScriptResolver(scriptResolver);
|
||||
this.bodyResolver.setTopDownAnalysisParameters(topDownAnalysisParameters);
|
||||
this.bodyResolver.setTrace(observableBindingTrace);
|
||||
|
||||
@@ -186,8 +194,17 @@ public class InjectorForTopDownAnalyzerBasic {
|
||||
typeHierarchyResolver.setDescriptorResolver(descriptorResolver);
|
||||
typeHierarchyResolver.setImportsResolver(importsResolver);
|
||||
typeHierarchyResolver.setNamespaceFactory(namespaceFactoryImpl);
|
||||
typeHierarchyResolver.setScriptResolver(scriptResolver);
|
||||
typeHierarchyResolver.setTrace(observableBindingTrace);
|
||||
|
||||
scriptResolver.setContext(topDownAnalysisContext);
|
||||
scriptResolver.setDependencyClassByQualifiedNameResolver(dependencyClassByQualifiedNameResolverDummyImpl);
|
||||
scriptResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
scriptResolver.setModuleDescriptor(moduleDescriptor);
|
||||
scriptResolver.setNamespaceFactory(namespaceFactoryImpl);
|
||||
scriptResolver.setTopDownAnalysisParameters(topDownAnalysisParameters);
|
||||
scriptResolver.setTrace(observableBindingTrace);
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -32,13 +33,15 @@ public class ScriptDescriptor extends DeclarationDescriptorImpl {
|
||||
private static final Name NAME = Name.special("<script>");
|
||||
|
||||
private JetType returnType;
|
||||
private List<ValueParameterDescriptor> valueParameters;
|
||||
|
||||
public ScriptDescriptor(@Nullable DeclarationDescriptor containingDeclaration) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), NAME);
|
||||
}
|
||||
|
||||
public void initialize(@NotNull JetType returnType) {
|
||||
public void initialize(@NotNull JetType returnType, @NotNull List<ValueParameterDescriptor> valueParameters) {
|
||||
this.returnType = returnType;
|
||||
this.valueParameters = valueParameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -46,6 +49,11 @@ public class ScriptDescriptor extends DeclarationDescriptorImpl {
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
return valueParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor substitute(TypeSubstitutor substitutor) {
|
||||
throw new IllegalStateException("nothing to substitute in script");
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.resolve;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class AnalyzerScriptParameter {
|
||||
@NotNull
|
||||
private final Name name;
|
||||
@NotNull
|
||||
private final JetTypeName type;
|
||||
|
||||
public AnalyzerScriptParameter(@NotNull Name name, @NotNull JetTypeName type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Name getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetTypeName getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,41 @@ import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.Queue;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertySetterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassInitializer;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegationSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorByExpressionSpecifier;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToThisCall;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSecondaryConstructor;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList;
|
||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
@@ -31,12 +64,13 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.CoercionStrategy;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.expressions.LabelResolver;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.Box;
|
||||
@@ -44,9 +78,29 @@ import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.ANONYMOUS_INITIALIZER_WITHOUT_CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.BY_IN_SECONDARY_CONSTRUCTOR;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.DELEGATION_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.DELEGATION_NOT_TO_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.FINAL_SUPERTYPE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.INITIALIZER_WITH_NO_ARGUMENTS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_CALLS_TO_THIS;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.MANY_CLASSES_IN_SUPERTYPE_LIST;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTOR_BUT_NO_PRIMARY;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTOR_NO_INITIALIZER_LIST;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_APPEARS_TWICE;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_INITIALIZED_IN_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_INITIALIZED;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPERTYPE_NOT_INITIALIZED_DEFAULT;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPE_MISMATCH;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
@@ -61,6 +115,8 @@ public class BodyResolver {
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
@NotNull
|
||||
private ScriptResolver scriptResolver;
|
||||
@NotNull
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
@NotNull
|
||||
private CallResolver callResolver;
|
||||
@@ -77,6 +133,11 @@ public class BodyResolver {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setScriptResolver(@NotNull ScriptResolver scriptResolver) {
|
||||
this.scriptResolver = scriptResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setExpressionTypingServices(@NotNull ExpressionTypingServices expressionTypingServices) {
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
@@ -106,7 +167,7 @@ public class BodyResolver {
|
||||
resolveSecondaryConstructorBodies();
|
||||
resolveFunctionBodies();
|
||||
|
||||
resolveScripts();
|
||||
scriptResolver.resolveScripts();
|
||||
|
||||
if (!topDownAnalysisParameters.isDeclaredLocally()) {
|
||||
computeDeferredTypes();
|
||||
@@ -613,23 +674,4 @@ public class BodyResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveScripts() {
|
||||
for (Map.Entry<JetScript, ScriptDescriptor> e : context.getScripts().entrySet()) {
|
||||
JetScript declaration = e.getKey();
|
||||
ScriptDescriptor descriptor = e.getValue();
|
||||
JetScope scope = context.getScriptScopes().get(declaration);
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
expressionTypingServices,
|
||||
Maps.<JetPattern, DataFlowInfo>newHashMap(),
|
||||
Maps.<JetPattern, List<VariableDescriptor>>newHashMap(),
|
||||
new LabelResolver(),
|
||||
trace,
|
||||
scope,
|
||||
DataFlowInfo.EMPTY,
|
||||
NO_EXPECTED_TYPE,
|
||||
false);
|
||||
JetType returnType = expressionTypingServices.getBlockReturnedType(scope, declaration.getBlockExpression(), CoercionStrategy.NO_COERCION, context, trace);
|
||||
descriptor.initialize(returnType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||
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.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetPattern;
|
||||
import org.jetbrains.jet.lang.psi.JetScript;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.DependencyClassByQualifiedNameResolver;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.expressions.CoercionStrategy;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingContext;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.expressions.LabelResolver;
|
||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class ScriptResolver {
|
||||
|
||||
@NotNull
|
||||
private NamespaceFactory namespaceFactory;
|
||||
@NotNull
|
||||
private DependencyClassByQualifiedNameResolver dependencyClassByQualifiedNameResolver;
|
||||
@NotNull
|
||||
private ModuleDescriptor moduleDescriptor;
|
||||
@NotNull
|
||||
private TopDownAnalysisContext context;
|
||||
@NotNull
|
||||
private ExpressionTypingServices expressionTypingServices;
|
||||
@NotNull
|
||||
private ObservableBindingTrace trace;
|
||||
@NotNull
|
||||
private TopDownAnalysisParameters topDownAnalysisParameters;
|
||||
|
||||
@Inject
|
||||
public void setNamespaceFactory(@NotNull NamespaceFactory namespaceFactory) {
|
||||
this.namespaceFactory = namespaceFactory;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDependencyClassByQualifiedNameResolver(@NotNull DependencyClassByQualifiedNameResolver dependencyClassByQualifiedNameResolver) {
|
||||
this.dependencyClassByQualifiedNameResolver = dependencyClassByQualifiedNameResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setModuleDescriptor(@NotNull ModuleDescriptor moduleDescriptor) {
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setContext(@NotNull TopDownAnalysisContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setExpressionTypingServices(@NotNull ExpressionTypingServices expressionTypingServices) {
|
||||
this.expressionTypingServices = expressionTypingServices;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setTrace(@NotNull ObservableBindingTrace trace) {
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setTopDownAnalysisParameters(@NotNull TopDownAnalysisParameters topDownAnalysisParameters) {
|
||||
this.topDownAnalysisParameters = topDownAnalysisParameters;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private ClassDescriptor resolveClass(@NotNull FqName className) {
|
||||
ClassDescriptor classDescriptor = dependencyClassByQualifiedNameResolver.resolveClass(className);
|
||||
if (classDescriptor == null) {
|
||||
throw new IllegalStateException("dependency class not found by name: " + className);
|
||||
}
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetType resolveTypeName(@NotNull JetTypeName typeName) {
|
||||
List<JetType> typeArguments = new ArrayList<JetType>();
|
||||
for (JetTypeName typeArgumentName : typeName.getArguments()) {
|
||||
typeArguments.add(resolveTypeName(typeArgumentName));
|
||||
}
|
||||
ClassDescriptor classDescriptor = resolveClass(typeName.getClassName());
|
||||
return TypeUtils.substituteParameters(classDescriptor, typeArguments);
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
private ValueParameterDescriptor resolveScriptParameter(
|
||||
@NotNull AnalyzerScriptParameter scriptParameter,
|
||||
int index,
|
||||
@NotNull ScriptDescriptor script) {
|
||||
JetType type = resolveTypeName(scriptParameter.getType());
|
||||
return new ValueParameterDescriptorImpl(script, index, Collections.<AnnotationDescriptor>emptyList(), scriptParameter.getName(), false, type, false, null);
|
||||
}
|
||||
|
||||
public void processScriptHierarchy(@NotNull JetScript script, @NotNull JetScope outerScope) {
|
||||
NamespaceDescriptorImpl ns = namespaceFactory.createNamespaceDescriptorPathIfNeeded(FqName.ROOT);
|
||||
ScriptDescriptor scriptDescriptor = new ScriptDescriptor(ns);
|
||||
//WriteThroughScope scriptScope = new WriteThroughScope(
|
||||
// outerScope, ns.getMemberScope(), new TraceBasedRedeclarationHandler(trace));
|
||||
WritableScopeImpl scriptScope = new WritableScopeImpl(outerScope, scriptDescriptor, RedeclarationHandler.DO_NOTHING);
|
||||
scriptScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
context.getScriptScopes().put(script, scriptScope);
|
||||
context.getScripts().put(script, scriptDescriptor);
|
||||
trace.record(BindingContext.SCRIPT, script, scriptDescriptor);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void resolveScripts() {
|
||||
for (Map.Entry<JetScript, ScriptDescriptor> e : context.getScripts().entrySet()) {
|
||||
JetScript declaration = e.getKey();
|
||||
ScriptDescriptor descriptor = e.getValue();
|
||||
WritableScope scope = context.getScriptScopes().get(declaration);
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
|
||||
|
||||
int index = 0;
|
||||
for (AnalyzerScriptParameter scriptParameter : topDownAnalysisParameters.getScriptParameters()) {
|
||||
ValueParameterDescriptor parameter = resolveScriptParameter(scriptParameter, index, descriptor);
|
||||
valueParameters.add(parameter);
|
||||
scope.addVariableDescriptor(parameter);
|
||||
++index;
|
||||
}
|
||||
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
expressionTypingServices,
|
||||
Maps.<JetPattern, DataFlowInfo>newHashMap(),
|
||||
Maps.<JetPattern, List<VariableDescriptor>>newHashMap(),
|
||||
new LabelResolver(),
|
||||
trace,
|
||||
scope,
|
||||
DataFlowInfo.EMPTY,
|
||||
NO_EXPECTED_TYPE,
|
||||
false);
|
||||
JetType returnType = expressionTypingServices.getBlockReturnedType(scope, declaration.getBlockExpression(), CoercionStrategy.NO_COERCION, context, trace);
|
||||
if (returnType == null) {
|
||||
returnType = ErrorUtils.createErrorType("getBlockReturnedType returned null");
|
||||
}
|
||||
descriptor.initialize(returnType, valueParameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+12
-1
@@ -20,6 +20,8 @@ import com.google.common.base.Predicate;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Various junk that cannot be placed into context (yet).
|
||||
*
|
||||
@@ -30,14 +32,18 @@ public class TopDownAnalysisParameters {
|
||||
private final Predicate<PsiFile> analyzeCompletely;
|
||||
private final boolean analyzingBootstrapLibrary;
|
||||
private final boolean declaredLocally;
|
||||
@NotNull
|
||||
private final List<AnalyzerScriptParameter> scriptParameters;
|
||||
|
||||
public TopDownAnalysisParameters(
|
||||
@NotNull Predicate<PsiFile> analyzeCompletely,
|
||||
boolean analyzingBootstrapLibrary,
|
||||
boolean declaredLocally) {
|
||||
boolean declaredLocally,
|
||||
@NotNull List<AnalyzerScriptParameter> scriptParameters) {
|
||||
this.analyzeCompletely = analyzeCompletely;
|
||||
this.analyzingBootstrapLibrary = analyzingBootstrapLibrary;
|
||||
this.declaredLocally = declaredLocally;
|
||||
this.scriptParameters = scriptParameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -52,4 +58,9 @@ public class TopDownAnalysisParameters {
|
||||
public boolean isDeclaredLocally() {
|
||||
return declaredLocally;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<AnalyzerScriptParameter> getScriptParameters() {
|
||||
return scriptParameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerBasic;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
@@ -32,7 +33,11 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.DependencyClassByQualifiedNameResolver;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
@@ -65,6 +70,8 @@ public class TopDownAnalyzer {
|
||||
private ModuleDescriptor moduleDescriptor;
|
||||
@NotNull
|
||||
private NamespaceFactoryImpl namespaceFactory;
|
||||
@NotNull
|
||||
private DependencyClassByQualifiedNameResolver dependencyClassByQualifiedNameResolver;
|
||||
|
||||
private BodyResolver bodyResolver;
|
||||
private ControlFlowAnalyzer controlFlowAnalyzer;
|
||||
@@ -135,6 +142,12 @@ public class TopDownAnalyzer {
|
||||
this.declarationsChecker = declarationsChecker;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setDependencyClassByQualifiedNameResolver(@NotNull DependencyClassByQualifiedNameResolver dependencyClassByQualifiedNameResolver) {
|
||||
this.dependencyClassByQualifiedNameResolver = dependencyClassByQualifiedNameResolver;
|
||||
}
|
||||
|
||||
|
||||
public void doProcess(
|
||||
JetScope outerScope,
|
||||
NamespaceLikeBuilder owner,
|
||||
@@ -184,7 +197,8 @@ public class TopDownAnalyzer {
|
||||
@NotNull NamespaceDescriptorImpl standardLibraryNamespace,
|
||||
@NotNull List<JetFile> files) {
|
||||
|
||||
TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters(Predicates.<PsiFile>alwaysFalse(), true, false);
|
||||
TopDownAnalysisParameters topDownAnalysisParameters = new TopDownAnalysisParameters(
|
||||
Predicates.<PsiFile>alwaysFalse(), true, false, Collections.<AnalyzerScriptParameter>emptyList());
|
||||
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
||||
project, topDownAnalysisParameters, new ObservableBindingTrace(trace),
|
||||
JetStandardClasses.FAKE_STANDARD_CLASSES_MODULE, ModuleConfiguration.EMPTY);
|
||||
@@ -215,7 +229,8 @@ public class TopDownAnalyzer {
|
||||
ModuleDescriptor moduleDescriptor = new ModuleDescriptor(Name.special("<dummy for object>"));
|
||||
|
||||
TopDownAnalysisParameters topDownAnalysisParameters =
|
||||
new TopDownAnalysisParameters(Predicates.equalTo(object.getContainingFile()), false, true);
|
||||
new TopDownAnalysisParameters(Predicates.equalTo(object.getContainingFile()),
|
||||
false, true, Collections.<AnalyzerScriptParameter>emptyList());
|
||||
|
||||
InjectorForTopDownAnalyzerBasic injector = new InjectorForTopDownAnalyzerBasic(
|
||||
project, topDownAnalysisParameters, new ObservableBindingTrace(trace), moduleDescriptor,
|
||||
@@ -256,11 +271,13 @@ public class TopDownAnalyzer {
|
||||
}, Collections.<PsiElement>singletonList(object));
|
||||
}
|
||||
|
||||
|
||||
public void analyzeFiles(Collection<JetFile> files) {
|
||||
public void analyzeFiles(
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull List<AnalyzerScriptParameter> scriptParameters) {
|
||||
final WritableScope scope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, moduleDescriptor,
|
||||
new TraceBasedRedeclarationHandler(trace)).setDebugName("Root scope in analyzeNamespace");
|
||||
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
|
||||
NamespaceDescriptorImpl rootNs = namespaceFactory.createNamespaceDescriptorPathIfNeeded(FqName.ROOT);
|
||||
|
||||
@@ -57,6 +57,8 @@ public class TypeHierarchyResolver {
|
||||
@NotNull
|
||||
private DescriptorResolver descriptorResolver;
|
||||
@NotNull
|
||||
private ScriptResolver scriptResolver;
|
||||
@NotNull
|
||||
private NamespaceFactoryImpl namespaceFactory;
|
||||
@NotNull
|
||||
private BindingTrace trace;
|
||||
@@ -79,6 +81,11 @@ public class TypeHierarchyResolver {
|
||||
this.descriptorResolver = descriptorResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setScriptResolver(@NotNull ScriptResolver scriptResolver) {
|
||||
this.scriptResolver = scriptResolver;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setNamespaceFactory(@NotNull NamespaceFactoryImpl namespaceFactory) {
|
||||
this.namespaceFactory = namespaceFactory;
|
||||
@@ -192,7 +199,7 @@ public class TypeHierarchyResolver {
|
||||
public void visitJetFile(JetFile file) {
|
||||
if (file.isScript()) {
|
||||
JetScript script = file.getScript();
|
||||
processScript(script);
|
||||
scriptResolver.processScriptHierarchy(script, outerScope);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -208,18 +215,6 @@ public class TypeHierarchyResolver {
|
||||
prepareForDeferredCall(namespaceScope, namespaceDescriptor, file);
|
||||
}
|
||||
|
||||
private void processScript(JetScript script) {
|
||||
NamespaceDescriptorImpl ns = namespaceFactory.createNamespaceDescriptorPathIfNeeded(FqName.ROOT);
|
||||
ScriptDescriptor scriptDescriptor = new ScriptDescriptor(ns);
|
||||
//WriteThroughScope scriptScope = new WriteThroughScope(
|
||||
// outerScope, ns.getMemberScope(), new TraceBasedRedeclarationHandler(trace));
|
||||
WritableScopeImpl scriptScope = new WritableScopeImpl(outerScope, scriptDescriptor, RedeclarationHandler.DO_NOTHING);
|
||||
scriptScope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
context.getScriptScopes().put(script, scriptScope);
|
||||
context.getScripts().put(script, scriptDescriptor);
|
||||
trace.record(BindingContext.SCRIPT, script, scriptDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(JetClass klass) {
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.ref.JetTypeName;
|
||||
import org.jetbrains.jet.util.lazy.LazyValue;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@@ -400,6 +400,25 @@ public class TypeUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType substituteParameters(@NotNull ClassDescriptor clazz, @NotNull List<JetType> actualTypeParameters) {
|
||||
List<TypeParameterDescriptor> clazzTypeParameters = clazz.getTypeConstructor().getParameters();
|
||||
|
||||
if (clazzTypeParameters.size() != actualTypeParameters.size()) {
|
||||
throw new IllegalArgumentException("type parameter counts do not match: " + clazz + ", " + actualTypeParameters);
|
||||
}
|
||||
|
||||
Map<TypeConstructor, TypeProjection> substitutions = Maps.newHashMap();
|
||||
|
||||
for (int i = 0; i < clazzTypeParameters.size(); ++i) {
|
||||
TypeConstructor typeConstructor = clazzTypeParameters.get(i).getTypeConstructor();
|
||||
TypeProjection typeProjection = new TypeProjection(actualTypeParameters.get(i));
|
||||
substitutions.put(typeConstructor, typeProjection);
|
||||
}
|
||||
|
||||
return TypeSubstitutor.create(substitutions).substitute(clazz.getDefaultType(), Variance.INVARIANT);
|
||||
}
|
||||
|
||||
private static void addAllClassDescriptors(@NotNull JetType type, @NotNull Set<ClassDescriptor> set) {
|
||||
ClassDescriptor cd = getClassDescriptor(type);
|
||||
if (cd != null) {
|
||||
|
||||
Reference in New Issue
Block a user