KT-224 "Overload ambiguity" when calling toString() method
This commit is contained in:
@@ -58,7 +58,7 @@ public class GenerationState {
|
|||||||
|
|
||||||
public GenerationState(Project project, ClassBuilderFactory builderFactory, FileNameTransformer fileNameTransformer) {
|
public GenerationState(Project project, ClassBuilderFactory builderFactory, FileNameTransformer fileNameTransformer) {
|
||||||
this.project = project;
|
this.project = project;
|
||||||
this.standardLibrary = JetStandardLibrary.getJetStandardLibrary(project);
|
this.standardLibrary = JetStandardLibrary.getInstance();
|
||||||
this.factory = new ClassFileFactory(builderFactory, this);
|
this.factory = new ClassFileFactory(builderFactory, this);
|
||||||
this.intrinsics = new IntrinsicMethods(project, standardLibrary);
|
this.intrinsics = new IntrinsicMethods(project, standardLibrary);
|
||||||
this.fileNameTransformer = fileNameTransformer;
|
this.fileNameTransformer = fileNameTransformer;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.intellij.mock.MockApplication;
|
|||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||||
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
import org.jetbrains.jet.plugin.compiler.PathUtil;
|
import org.jetbrains.jet.plugin.compiler.PathUtil;
|
||||||
|
|
||||||
@@ -47,6 +48,8 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
for (VirtualFile root : PathUtil.getAltHeadersRoots()) {
|
for (VirtualFile root : PathUtil.getAltHeadersRoots()) {
|
||||||
addLibraryRoot(root);
|
addLibraryRoot(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JetStandardLibrary.initialize(getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MockApplication getApplication() {
|
public MockApplication getApplication() {
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class JetSemanticServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JetSemanticServices createSemanticServices(Project project) {
|
public static JetSemanticServices createSemanticServices(Project project) {
|
||||||
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project));
|
return new JetSemanticServices(JetStandardLibrary.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final JetStandardLibrary standardLibrary;
|
private final JetStandardLibrary standardLibrary;
|
||||||
|
|||||||
@@ -47,29 +47,21 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class JetStandardLibrary {
|
public class JetStandardLibrary {
|
||||||
|
|
||||||
// TODO : consider releasing this memory
|
private static JetStandardLibrary instance = null;
|
||||||
private static JetStandardLibrary cachedLibrary = null;
|
|
||||||
// A temporary try to find a reason of KT-224
|
|
||||||
private static int wasProcessCanceledException = 0;
|
|
||||||
// private static final Map<Project, JetStandardLibrary> standardLibraryCache = new HashMap<Project, JetStandardLibrary>();
|
|
||||||
|
|
||||||
// TODO : double checked locking
|
// This method must be called at least once per application run, on any project
|
||||||
synchronized
|
// before any type checking is run
|
||||||
public static JetStandardLibrary getJetStandardLibrary(@NotNull Project project) {
|
public static synchronized void initialize(@NotNull Project project) {
|
||||||
if (cachedLibrary == null) {
|
if (instance == null) {
|
||||||
cachedLibrary = new JetStandardLibrary(project);
|
instance = new JetStandardLibrary(project);
|
||||||
}
|
}
|
||||||
return cachedLibrary;
|
|
||||||
// JetStandardLibrary standardLibrary = standardLibraryCache.get(project);
|
|
||||||
// if (standardLibrary == null) {
|
|
||||||
// standardLibrary = new JetStandardLibrary(project);
|
|
||||||
// standardLibraryCache.put(project, standardLibrary);
|
|
||||||
// }
|
|
||||||
// return standardLibrary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Project project;
|
@NotNull // This asserts that initialize() is called before any resolution happens
|
||||||
|
public static JetStandardLibrary getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
private JetScope libraryScope;
|
private JetScope libraryScope;
|
||||||
|
|
||||||
private ClassDescriptor numberClass;
|
private ClassDescriptor numberClass;
|
||||||
@@ -78,7 +70,6 @@ public class JetStandardLibrary {
|
|||||||
private ClassDescriptor stringClass;
|
private ClassDescriptor stringClass;
|
||||||
private ClassDescriptor arrayClass;
|
private ClassDescriptor arrayClass;
|
||||||
private ClassDescriptor iterableClass;
|
private ClassDescriptor iterableClass;
|
||||||
private ClassDescriptor typeInfoClass;
|
|
||||||
private ClassDescriptor comparableClass;
|
private ClassDescriptor comparableClass;
|
||||||
private ClassDescriptor volatileClass;
|
private ClassDescriptor volatileClass;
|
||||||
|
|
||||||
@@ -90,10 +81,6 @@ public class JetStandardLibrary {
|
|||||||
|
|
||||||
private JetType nullableTuple0Type;
|
private JetType nullableTuple0Type;
|
||||||
|
|
||||||
public JetType getTuple0Type() {
|
|
||||||
return tuple0Type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JetType tuple0Type;
|
private JetType tuple0Type;
|
||||||
|
|
||||||
private Set<FunctionDescriptor> typeInfoFunction;
|
private Set<FunctionDescriptor> typeInfoFunction;
|
||||||
@@ -108,8 +95,6 @@ public class JetStandardLibrary {
|
|||||||
private Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
|
private Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
|
||||||
|
|
||||||
private JetStandardLibrary(@NotNull Project project) {
|
private JetStandardLibrary(@NotNull Project project) {
|
||||||
this.project = project;
|
|
||||||
|
|
||||||
// TODO : review
|
// TODO : review
|
||||||
List<String> libraryFiles = Arrays.asList(
|
List<String> libraryFiles = Arrays.asList(
|
||||||
"Library.jet",
|
"Library.jet",
|
||||||
@@ -134,26 +119,17 @@ public class JetStandardLibrary {
|
|||||||
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);
|
||||||
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
|
||||||
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
|
|
||||||
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files);
|
TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files);
|
||||||
// this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
|
|
||||||
|
|
||||||
AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());
|
AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());
|
||||||
initStdClasses();
|
initStdClasses();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
} catch (ProcessCanceledException e) {
|
} catch (ProcessCanceledException e) {
|
||||||
wasProcessCanceledException++;
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Project getProject() {
|
|
||||||
return project;
|
|
||||||
}
|
|
||||||
|
|
||||||
public JetScope getLibraryScope() {
|
public JetScope getLibraryScope() {
|
||||||
initStdClasses();
|
initStdClasses();
|
||||||
return libraryScope;
|
return libraryScope;
|
||||||
@@ -170,8 +146,6 @@ public class JetStandardLibrary {
|
|||||||
|
|
||||||
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
|
||||||
this.comparableClass = (ClassDescriptor) libraryScope.getClassifier("Comparable");
|
this.comparableClass = (ClassDescriptor) libraryScope.getClassifier("Comparable");
|
||||||
// typeInfoNamespace = libraryScope.getNamespace("typeinfo");
|
|
||||||
this.typeInfoClass = (ClassDescriptor) libraryScope.getClassifier("TypeInfo");
|
|
||||||
this.typeInfoFunction = libraryScope.getFunctions("typeinfo");
|
this.typeInfoFunction = libraryScope.getFunctions("typeinfo");
|
||||||
|
|
||||||
this.stringType = new JetTypeImpl(getString());
|
this.stringType = new JetTypeImpl(getString());
|
||||||
@@ -296,28 +270,11 @@ public class JetStandardLibrary {
|
|||||||
return comparableClass;
|
return comparableClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public NamespaceDescriptor getTypeInfoNamespace() {
|
|
||||||
// initStdClasses();
|
|
||||||
// return typeInfoNamespace;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
public ClassDescriptor getTypeInfo() {
|
|
||||||
initStdClasses();
|
|
||||||
return typeInfoClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<FunctionDescriptor> getTypeInfoFunctions() {
|
public Set<FunctionDescriptor> getTypeInfoFunctions() {
|
||||||
initStdClasses();
|
initStdClasses();
|
||||||
return typeInfoFunction;
|
return typeInfoFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public JetType getTypeInfoType(@NotNull JetType type) {
|
|
||||||
TypeProjection typeProjection = new TypeProjection(type);
|
|
||||||
List<TypeProjection> arguments = Collections.singletonList(typeProjection);
|
|
||||||
return new JetTypeImpl(Collections.<AnnotationDescriptor>emptyList(), getTypeInfo().getTypeConstructor(), false, arguments, getTypeInfo().getMemberScope(arguments));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetType getPrimitiveJetType(PrimitiveType primitiveType) {
|
public JetType getPrimitiveJetType(PrimitiveType primitiveType) {
|
||||||
return primitiveTypeToJetType.get(primitiveType);
|
return primitiveTypeToJetType.get(primitiveType);
|
||||||
@@ -493,4 +450,8 @@ public class JetStandardLibrary {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JetType getTuple0Type() {
|
||||||
|
return tuple0Type;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -46,6 +46,7 @@ import java.util.Map;
|
|||||||
/*package*/ class ExpressionTypingContext {
|
/*package*/ class ExpressionTypingContext {
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ExpressionTypingContext newContext(
|
public static ExpressionTypingContext newContext(
|
||||||
|
@NotNull Project project,
|
||||||
@NotNull JetSemanticServices semanticServices,
|
@NotNull JetSemanticServices semanticServices,
|
||||||
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
||||||
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
||||||
@@ -56,7 +57,7 @@ import java.util.Map;
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull JetType expectedReturnType,
|
@NotNull JetType expectedReturnType,
|
||||||
boolean namespacesAllowed) {
|
boolean namespacesAllowed) {
|
||||||
return new ExpressionTypingContext(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
|
return new ExpressionTypingContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
|
||||||
labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +72,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 JetSemanticServices semanticServices;
|
public final JetSemanticServices semanticServices;
|
||||||
public final BindingTrace trace;
|
public final BindingTrace trace;
|
||||||
public final JetScope scope;
|
public final JetScope scope;
|
||||||
@@ -93,6 +95,7 @@ import java.util.Map;
|
|||||||
private CompileTimeConstantResolver compileTimeConstantResolver;
|
private CompileTimeConstantResolver compileTimeConstantResolver;
|
||||||
|
|
||||||
private ExpressionTypingContext(
|
private ExpressionTypingContext(
|
||||||
|
@NotNull Project project,
|
||||||
@NotNull JetSemanticServices semanticServices,
|
@NotNull JetSemanticServices semanticServices,
|
||||||
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
@NotNull Map<JetPattern, DataFlowInfo> patternsToDataFlowInfo,
|
||||||
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
@NotNull Map<JetPattern, List<VariableDescriptor>> patternsToBoundVariableLists,
|
||||||
@@ -103,6 +106,7 @@ import java.util.Map;
|
|||||||
@NotNull JetType expectedType,
|
@NotNull JetType expectedType,
|
||||||
@NotNull JetType expectedReturnType,
|
@NotNull JetType expectedReturnType,
|
||||||
boolean namespacesAllowed) {
|
boolean namespacesAllowed) {
|
||||||
|
this.project = project;
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
this.patternsToBoundVariableLists = patternsToBoundVariableLists;
|
this.patternsToBoundVariableLists = patternsToBoundVariableLists;
|
||||||
this.patternsToDataFlowInfo = patternsToDataFlowInfo;
|
this.patternsToDataFlowInfo = patternsToDataFlowInfo;
|
||||||
@@ -118,36 +122,36 @@ 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(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
|
||||||
if (newDataFlowInfo == dataFlowInfo) return this;
|
if (newDataFlowInfo == dataFlowInfo) return this;
|
||||||
return newContext(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, newDataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, newDataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) {
|
public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) {
|
||||||
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
|
||||||
if (expectedType == newExpectedType) return this;
|
if (expectedType == newExpectedType) return this;
|
||||||
return newContext(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, newExpectedType, expectedReturnType, namespacesAllowed);
|
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, newExpectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionTypingContext replaceExpectedReturnType(@Nullable JetType newExpectedReturnType) {
|
public ExpressionTypingContext replaceExpectedReturnType(@Nullable JetType newExpectedReturnType) {
|
||||||
if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
|
if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
|
||||||
if (expectedReturnType == newExpectedReturnType) return this;
|
if (expectedReturnType == newExpectedReturnType) return this;
|
||||||
return newContext(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, newExpectedReturnType, namespacesAllowed);
|
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, newExpectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) {
|
public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) {
|
||||||
if (newTrace == trace) return this;
|
if (newTrace == trace) return this;
|
||||||
return newContext(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, newTrace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, newTrace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
|
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
|
||||||
if (newScope == scope) return this;
|
if (newScope == scope) return this;
|
||||||
return newContext(semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
return newContext(project, semanticServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////// LAZY ACCESSORS
|
///////////// LAZY ACCESSORS
|
||||||
@@ -219,6 +223,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Project getProject() {
|
public Project getProject() {
|
||||||
return semanticServices.getStandardLibrary().getProject();
|
return project;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-2
@@ -83,6 +83,7 @@ public class ExpressionTypingServices {
|
|||||||
@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) {
|
||||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
|
expression.getProject(),
|
||||||
semanticServices,
|
semanticServices,
|
||||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
|
trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
|
||||||
@@ -92,6 +93,7 @@ public class ExpressionTypingServices {
|
|||||||
|
|
||||||
public JetType getTypeWithNamespaces(@NotNull final JetScope scope, @NotNull JetExpression expression) {
|
public JetType getTypeWithNamespaces(@NotNull final JetScope scope, @NotNull JetExpression expression) {
|
||||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
|
expression.getProject(),
|
||||||
semanticServices,
|
semanticServices,
|
||||||
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN,
|
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN,
|
||||||
@@ -131,6 +133,7 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
|
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
|
||||||
|
function.getProject(),
|
||||||
semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false
|
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false
|
||||||
));
|
));
|
||||||
@@ -178,7 +181,7 @@ 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(semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
expressionTypingFacade.getType(bodyExpression, ExpressionTypingContext.newContext(function.getProject(), semanticServices, new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
|
||||||
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN, false), !function.hasBlockBody());
|
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();
|
||||||
@@ -307,7 +310,7 @@ public class ExpressionTypingServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType, JetType expectedReturnType) {
|
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType, JetType expectedReturnType) {
|
||||||
return ExpressionTypingContext.newContext(oldContext.semanticServices, oldContext.patternsToDataFlowInfo, oldContext.patternsToBoundVariableLists, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, oldContext.namespacesAllowed);
|
return ExpressionTypingContext.newContext(oldContext.project, oldContext.semanticServices, oldContext.patternsToDataFlowInfo, oldContext.patternsToBoundVariableLists, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, oldContext.namespacesAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObservableBindingTrace makeTraceInterceptingTypeMismatch(final BindingTrace trace, final JetExpression expressionToWatch, final boolean[] mismatchFound) {
|
private ObservableBindingTrace makeTraceInterceptingTypeMismatch(final BindingTrace trace, final JetExpression expressionToWatch, final boolean[] mismatchFound) {
|
||||||
|
|||||||
+1
@@ -155,6 +155,7 @@ public class ExpressionTypingUtils {
|
|||||||
JetExpression expression = JetPsiFactory.createExpression(project, "fake");
|
JetExpression expression = JetPsiFactory.createExpression(project, "fake");
|
||||||
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getOutType());
|
ExpressionReceiver expressionReceiver = new ExpressionReceiver(expression, variableDescriptor.getOutType());
|
||||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||||
|
project,
|
||||||
JetSemanticServices.createSemanticServices(project),
|
JetSemanticServices.createSemanticServices(project),
|
||||||
new HashMap<JetPattern, DataFlowInfo>(),
|
new HashMap<JetPattern, DataFlowInfo>(),
|
||||||
new HashMap<JetPattern, List<VariableDescriptor>>(),
|
new HashMap<JetPattern, List<VariableDescriptor>>(),
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected ExpectedResolveData getExpectedResolveData() {
|
protected ExpectedResolveData getExpectedResolveData() {
|
||||||
Project project = getProject();
|
Project project = getProject();
|
||||||
JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project);
|
JetStandardLibrary lib = JetStandardLibrary.getInstance();
|
||||||
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
|
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
|
||||||
nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType()));
|
nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType()));
|
||||||
FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType());
|
FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType());
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
|
|||||||
private JetScope scope;
|
private JetScope scope;
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
JetStandardLibrary library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
JetStandardLibrary library = JetStandardLibrary.getInstance();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
|
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_EXCEPTION_ON_ERROR_TRACE);
|
||||||
scope = createScope(library.getLibraryScope());
|
scope = createScope(library.getLibraryScope());
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class JetOverloadTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getInstance();
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class JetOverridingTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getInstance();
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getInstance();
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDefinitions = new ClassDefinitions();
|
classDefinitions = new ClassDefinitions();
|
||||||
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
descriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY_TRACE);
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
<depends optional="true">JUnit</depends>
|
<depends optional="true">JUnit</depends>
|
||||||
|
|
||||||
<project-components>
|
<project-components>
|
||||||
|
<component>
|
||||||
|
<implementation-class>org.jetbrains.jet.plugin.JetStandardLibraryInitializer</implementation-class>
|
||||||
|
</component>
|
||||||
<component>
|
<component>
|
||||||
<implementation-class>org.jetbrains.jet.plugin.compiler.JetCompilerManager</implementation-class>
|
<implementation-class>org.jetbrains.jet.plugin.compiler.JetCompilerManager</implementation-class>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class JetPluginUtil {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getJetStandardLibrary(project);
|
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
JetScope libraryScope = standardLibrary.getLibraryScope();
|
JetScope libraryScope = standardLibrary.getLibraryScope();
|
||||||
|
|
||||||
DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration();
|
DeclarationDescriptor declaration = type.getMemberScope().getContainingDeclaration();
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.plugin;
|
||||||
|
|
||||||
|
import com.intellij.openapi.progress.ProgressManager;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This project component initializes JetStandardLibrary so that throwing a ProcessCanceledException while
|
||||||
|
* loading PSI from declaration files is prevented.
|
||||||
|
*
|
||||||
|
* @author abreslav
|
||||||
|
*/
|
||||||
|
public class JetStandardLibraryInitializer {
|
||||||
|
public JetStandardLibraryInitializer(@NotNull final Project project) {
|
||||||
|
ProgressManager.getInstance().executeNonCancelableSection(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
JetStandardLibrary.initialize(project);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -94,7 +94,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
|||||||
}
|
}
|
||||||
bodyBuilder.append(descriptor.getName()).append(": ").append(descriptor.getOutType());
|
bodyBuilder.append(descriptor.getName()).append(": ").append(descriptor.getOutType());
|
||||||
ImportClassHelper.addImportDirectiveIfNeeded(descriptor.getOutType(), file);
|
ImportClassHelper.addImportDirectiveIfNeeded(descriptor.getOutType(), file);
|
||||||
String initializer = defaultInitializer(descriptor.getOutType(), JetStandardLibrary.getJetStandardLibrary(project));
|
String initializer = defaultInitializer(descriptor.getOutType(), JetStandardLibrary.getInstance());
|
||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
bodyBuilder.append("=").append(initializer);
|
bodyBuilder.append("=").append(initializer);
|
||||||
}
|
}
|
||||||
@@ -122,7 +122,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
|||||||
}
|
}
|
||||||
bodyBuilder.append(")");
|
bodyBuilder.append(")");
|
||||||
final JetType returnType = descriptor.getReturnType();
|
final JetType returnType = descriptor.getReturnType();
|
||||||
final JetStandardLibrary stdlib = JetStandardLibrary.getJetStandardLibrary(project);
|
final JetStandardLibrary stdlib = JetStandardLibrary.getInstance();
|
||||||
if (!returnType.equals(stdlib.getTuple0Type())) {
|
if (!returnType.equals(stdlib.getTuple0Type())) {
|
||||||
bodyBuilder.append(": ").append(returnType.toString());
|
bodyBuilder.append(": ").append(returnType.toString());
|
||||||
ImportClassHelper.addImportDirectiveIfNeeded(returnType, file);
|
ImportClassHelper.addImportDirectiveIfNeeded(returnType, file);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public class JetPositionManager implements PositionManager {
|
|||||||
return mapper;
|
return mapper;
|
||||||
}
|
}
|
||||||
final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||||
final JetStandardLibrary standardLibrary = JetStandardLibrary.getJetStandardLibrary(myDebugProcess.getProject());
|
final JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
final JetTypeMapper typeMapper = new JetTypeMapper(standardLibrary, bindingContext);
|
final JetTypeMapper typeMapper = new JetTypeMapper(standardLibrary, bindingContext);
|
||||||
file.acceptChildren(new JetVisitorVoid() {
|
file.acceptChildren(new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class JetNameSuggester {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void addNamesForType(ArrayList<String> result, JetType jetType, JetNameValidator validator) {
|
private static void addNamesForType(ArrayList<String> result, JetType jetType, JetNameValidator validator) {
|
||||||
JetStandardLibrary standardLibrary = JetStandardLibrary.getJetStandardLibrary(validator.getProject());
|
JetStandardLibrary standardLibrary = JetStandardLibrary.getInstance();
|
||||||
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
JetTypeChecker typeChecker = JetTypeChecker.INSTANCE;
|
||||||
if (typeChecker.equalTypes(standardLibrary.getBooleanType(), jetType)) {
|
if (typeChecker.equalTypes(standardLibrary.getBooleanType(), jetType)) {
|
||||||
addName(result, "b", validator);
|
addName(result, "b", validator);
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class JetRefactoringUtil {
|
|||||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
if (expressionType == null || !(expressionType instanceof NamespaceType) &&
|
if (expressionType == null || !(expressionType instanceof NamespaceType) &&
|
||||||
!JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.
|
!JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.
|
||||||
getJetStandardLibrary(element.getProject()).getTuple0Type(), expressionType)) {
|
getInstance().getTuple0Type(), expressionType)) {
|
||||||
expressions.add(expression);
|
expressions.add(expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -102,7 +102,7 @@ public class JetIntroduceVariableHandler extends JetIntroduceHandlerBase {
|
|||||||
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression"));
|
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.namespace.expression"));
|
||||||
return;
|
return;
|
||||||
} if (expressionType != null &&
|
} if (expressionType != null &&
|
||||||
JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.getJetStandardLibrary(project).getTuple0Type(), expressionType)) {
|
JetTypeChecker.INSTANCE.equalTypes(JetStandardLibrary.getInstance().getTuple0Type(), expressionType)) {
|
||||||
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.expression.has.unit.type"));
|
showErrorHint(project, editor, JetRefactoringBundle.message("cannot.refactor.expression.has.unit.type"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user