diff --git a/.idea/inspectionProfiles/idea_default.xml b/.idea/inspectionProfiles/idea_default.xml
index 87c20723c79..23bae163cd7 100644
--- a/.idea/inspectionProfiles/idea_default.xml
+++ b/.idea/inspectionProfiles/idea_default.xml
@@ -67,6 +67,7 @@
+
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 275077f8255..0503e944c52 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,5 +1,15 @@
+
+
+
diff --git a/bin/kotlin b/bin/kotlin
old mode 100644
new mode 100755
diff --git a/bin/run-test b/bin/run-test
old mode 100644
new mode 100755
diff --git a/build.xml b/build.xml
index bfba0a2c86a..62c1b6ff598 100644
--- a/build.xml
+++ b/build.xml
@@ -91,50 +91,56 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
-
-
-
-
+
+
+
+
+
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
@@ -337,7 +343,7 @@
-
+
diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java
index c9475688601..eeab96e059c 100644
--- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java
+++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java
@@ -105,6 +105,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
if (isInterface) {
access |= ACC_INTERFACE; // ACC_SUPER
}
+ else {
+ access |= ACC_SUPER;
+ }
if (isFinal) {
access |= ACC_FINAL;
}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java
index 27114b42a1c..c6a4107acc0 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
import org.jetbrains.k2js.config.Config;
+import org.jetbrains.k2js.config.EcmaVersion;
import org.jetbrains.k2js.config.ZippedLibrarySourcesConfig;
import org.jetbrains.k2js.facade.K2JSTranslator;
@@ -93,8 +94,7 @@ public class K2JSCompiler extends CLICompiler() {
+ @Override
+ public File fun(String s) {
+ return new File(s);
+ }
+ }, new File[0]);
+ }
}
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java
index 42abc201d44..9a91c215fdd 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompilerArguments.java
@@ -54,10 +54,10 @@ public class K2JVMCompilerArguments extends CompilerArguments {
@Argument(value = "stdlib", description = "Path to the stdlib.jar")
public String stdlib;
- @Argument(value = "jdkHeaders", description = "Path to the kotlin-jdk-headers.jar")
- public String jdkHeaders;
+ @Argument(value = "altHeaders", description = "Path to the alternative library headers paths")
+ public String altHeaders;
- @Argument(value = "mode", description = "Special compiler modes: stubs or jdkHeaders")
+ @Argument(value = "mode", description = "Special compiler modes: stubs or altHeaders")
public String mode;
@Argument(value = "output", description = "output directory")
diff --git a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java
index e9db023eee1..da4a1d6660f 100644
--- a/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java
+++ b/compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java
@@ -84,8 +84,8 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
addToClasspath(compilerDependencies.getJdkJar());
}
- if (compilerSpecialMode.includeJdkHeaders()) {
- for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
+ if (compilerSpecialMode.includeAltHeaders()) {
+ for (VirtualFile root : compilerDependencies.getAltHeaderRoots()) {
addLibraryRoot(root);
}
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java
index 226771fe4b5..2e7a2941815 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerDependencies.java
@@ -16,7 +16,11 @@
package org.jetbrains.jet.lang.resolve.java;
+import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileManager;
+import com.intellij.util.Function;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.utils.PathUtil;
@@ -34,15 +38,15 @@ public class CompilerDependencies {
private final CompilerSpecialMode compilerSpecialMode;
@Nullable
private final File jdkJar;
- @Nullable
- private final File jdkHeadersJar;
+ @NotNull
+ private final File[] altHeadersClasspath;
@Nullable
private final File runtimeJar;
- public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
+ public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkJar, @NotNull File[] altHeadersClasspath, @Nullable File runtimeJar) {
this.compilerSpecialMode = compilerSpecialMode;
this.jdkJar = jdkJar;
- this.jdkHeadersJar = jdkHeadersJar;
+ this.altHeadersClasspath = altHeadersClasspath;
this.runtimeJar = runtimeJar;
if (compilerSpecialMode.includeJdk()) {
@@ -50,9 +54,9 @@ public class CompilerDependencies {
throw new IllegalArgumentException("jdk must be included for mode " + compilerSpecialMode);
}
}
- if (compilerSpecialMode.includeJdkHeaders()) {
- if (jdkHeadersJar == null) {
- throw new IllegalArgumentException("jdkHeaders must be included for mode " + compilerSpecialMode);
+ if (compilerSpecialMode.includeAltHeaders()) {
+ if (altHeadersClasspath.length == 0) {
+ throw new IllegalArgumentException("altHeaders must be included for mode " + compilerSpecialMode);
}
}
if (compilerSpecialMode.includeKotlinRuntime()) {
@@ -72,9 +76,9 @@ public class CompilerDependencies {
return jdkJar;
}
- @Nullable
- public File getJdkHeadersJar() {
- return jdkHeadersJar;
+ @NotNull
+ public File[] getAltHeadersClassPath() {
+ return altHeadersClasspath;
}
@Nullable
@@ -83,9 +87,25 @@ public class CompilerDependencies {
}
@NotNull
- public List getJdkHeaderRoots() {
- if (compilerSpecialMode.includeJdkHeaders()) {
- return Collections.singletonList(PathUtil.jarFileToVirtualFile(jdkHeadersJar));
+ public List getAltHeaderRoots() {
+ if (compilerSpecialMode.includeAltHeaders()) {
+ return ContainerUtil.map2List(altHeadersClasspath, new Function() {
+ @Override
+ public VirtualFile fun(File file) {
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ return VirtualFileManager.getInstance()
+ .findFileByUrl("file://" + FileUtil.toSystemIndependentName(file.getAbsolutePath()));
+ }
+ else {
+ return PathUtil.jarFileToVirtualFile(file);
+ }
+ }
+ else {
+ throw new IllegalStateException("Path " + file + " does not exist.");
+ }
+ }
+ });
}
else {
return Collections.emptyList();
@@ -107,7 +127,7 @@ public class CompilerDependencies {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdk() ? findRtJar() : null,
- compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
+ compilerSpecialMode.includeAltHeaders() ? new File[]{PathUtil.getAltHeadersPath()} : new File[0],
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java
index a75759cc274..3b08b9472c8 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/CompilerSpecialMode.java
@@ -22,13 +22,13 @@ package org.jetbrains.jet.lang.resolve.java;
public enum CompilerSpecialMode {
REGULAR,
BUILTINS,
- JDK_HEADERS,
+ ALT_HEADERS,
STDLIB,
IDEA,
JS,
;
- public boolean includeJdkHeaders() {
+ public boolean includeAltHeaders() {
return this == REGULAR || this == STDLIB || this == IDEA;
}
@@ -41,6 +41,6 @@ public enum CompilerSpecialMode {
}
public boolean isStubs() {
- return this == BUILTINS || this == JDK_HEADERS;
+ return this == BUILTINS || this == ALT_HEADERS;
}
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
index 8844466d01e..8a4dab27896 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaDescriptorResolver.java
@@ -21,75 +21,15 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
-import com.intellij.psi.PsiAnnotation;
-import com.intellij.psi.PsiAnnotationMemberValue;
-import com.intellij.psi.PsiAnnotationMethod;
-import com.intellij.psi.PsiAnnotationParameterList;
-import com.intellij.psi.PsiArrayType;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiClassType;
-import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiEllipsisType;
-import com.intellij.psi.PsiLiteralExpression;
-import com.intellij.psi.PsiMethod;
-import com.intellij.psi.PsiModifier;
-import com.intellij.psi.PsiModifierListOwner;
-import com.intellij.psi.PsiNameValuePair;
-import com.intellij.psi.PsiPackage;
-import com.intellij.psi.PsiPrimitiveType;
-import com.intellij.psi.PsiType;
-import com.intellij.psi.PsiTypeParameter;
-import com.intellij.psi.PsiTypeParameterListOwner;
+import com.intellij.psi.*;
import jet.typeinfo.TypeInfoVariance;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
-import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
-import org.jetbrains.jet.lang.descriptors.ClassKind;
-import org.jetbrains.jet.lang.descriptors.ClassOrNamespaceDescriptor;
-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.DeclarationDescriptorImpl;
-import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorVisitor;
-import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility;
-import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
-import org.jetbrains.jet.lang.descriptors.FunctionDescriptorImpl;
-import org.jetbrains.jet.lang.descriptors.Modality;
-import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
-import org.jetbrains.jet.lang.descriptors.MutableClassDescriptorLite;
-import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
-import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorParent;
-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.Visibilities;
-import org.jetbrains.jet.lang.descriptors.Visibility;
+import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
-import org.jetbrains.jet.lang.resolve.BindingContext;
-import org.jetbrains.jet.lang.resolve.BindingContextUtils;
-import org.jetbrains.jet.lang.resolve.BindingTrace;
-import org.jetbrains.jet.lang.resolve.DescriptorUtils;
-import org.jetbrains.jet.lang.resolve.FqName;
-import org.jetbrains.jet.lang.resolve.NamespaceFactory;
-import org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl;
-import org.jetbrains.jet.lang.resolve.OverrideResolver;
-import org.jetbrains.jet.lang.resolve.constants.ByteValue;
-import org.jetbrains.jet.lang.resolve.constants.CharValue;
-import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
-import org.jetbrains.jet.lang.resolve.constants.DoubleValue;
-import org.jetbrains.jet.lang.resolve.constants.FloatValue;
-import org.jetbrains.jet.lang.resolve.constants.IntValue;
-import org.jetbrains.jet.lang.resolve.constants.LongValue;
-import org.jetbrains.jet.lang.resolve.constants.NullValue;
-import org.jetbrains.jet.lang.resolve.constants.ShortValue;
+import org.jetbrains.jet.lang.resolve.*;
+import org.jetbrains.jet.lang.resolve.constants.*;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.java.kt.JetClassAnnotation;
import org.jetbrains.jet.lang.types.*;
@@ -101,14 +41,7 @@ import org.jetbrains.jet.rt.signature.JetSignatureReader;
import org.jetbrains.jet.rt.signature.JetSignatureVisitor;
import javax.inject.Inject;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
/**
* @author abreslav
@@ -541,7 +474,7 @@ public class JavaDescriptorResolver {
MutableClassDescriptorLite classObject = createClassObjectDescriptor(classData.classDescriptor, psiClass);
if (classObject != null) {
- classData.classDescriptor.setClassObjectDescriptor(classObject);
+ classData.classDescriptor.getBuilder().setClassObjectDescriptor(classObject);
}
trace.record(BindingContext.CLASS, psiClass, classData.classDescriptor);
@@ -605,7 +538,8 @@ public class JavaDescriptorResolver {
checkPsiClassIsNotJet(psiClass);
FqName fqName = new FqName(classObjectPsiClass.getQualifiedName());
- ResolverBinaryClassData classData = new ResolverBinaryClassData(classObjectPsiClass, fqName, new MutableClassDescriptorLite(containing, ClassKind.OBJECT));
+ ResolverBinaryClassData classData = new ResolverBinaryClassData(classObjectPsiClass, fqName,
+ new MutableClassDescriptorLite(containing, ClassKind.OBJECT));
classDescriptorCache.put(fqName, classData);
@@ -994,7 +928,7 @@ public class JavaDescriptorResolver {
JavaNamespaceDescriptor ns = new JavaNamespaceDescriptor(
parentNs,
Collections.emptyList(), // TODO
- qualifiedName.isRoot() ? "" : qualifiedName.shortName(),
+ qualifiedName.isRoot() ? FqNameUnsafe.ROOT_NAME : qualifiedName.shortName(),
qualifiedName
);
@@ -1153,6 +1087,7 @@ public class JavaDescriptorResolver {
JetType varargElementType;
if (psiType instanceof PsiEllipsisType) {
varargElementType = JetStandardLibrary.getInstance().getArrayElementType(TypeUtils.makeNotNullable(outType));
+ outType = TypeUtils.makeNotNullable(outType);
}
else {
varargElementType = null;
@@ -1433,6 +1368,10 @@ public class JavaDescriptorResolver {
if (anyMember.getType().getPsiNotNullOwner().getModifierList().findAnnotation(JvmAbi.JETBRAINS_NOT_NULL_ANNOTATION.getFqName().getFqName()) != null) {
propertyType = TypeUtils.makeNullableAsSpecified(propertyType, false);
}
+ else if (members.getter == null && members.setter == null && members.field.getMember().isFinal() && members.field.getMember().isStatic()) {
+ // http://youtrack.jetbrains.com/issue/KT-1388
+ propertyType = TypeUtils.makeNotNullable(propertyType);
+ }
}
JetType receiverType;
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaNamespaceDescriptor.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaNamespaceDescriptor.java
index f13982f0923..87eb5d32e0d 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaNamespaceDescriptor.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/JavaNamespaceDescriptor.java
@@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.AbstractNamespaceDescriptorImpl;
-import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorParent;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.FqName;
@@ -49,6 +48,8 @@ public class JavaNamespaceDescriptor extends AbstractNamespaceDescriptorImpl {
return memberScope;
}
+ @NotNull
+ @Override
public FqName getQualifiedName() {
return qualifiedName;
}
diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderForJvm.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderForJvm.java
index 93d038f2f64..56a9a8a8b5e 100644
--- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderForJvm.java
+++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/PsiClassFinderForJvm.java
@@ -59,7 +59,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
@PostConstruct
public void initialize() {
- this.altClassFinder = new AltClassFinder(project, compilerDependencies.getJdkHeaderRoots());
+ this.altClassFinder = new AltClassFinder(project, compilerDependencies.getAltHeaderRoots());
this.javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
@Override
public boolean contains(VirtualFile file) {
diff --git a/compiler/frontend/generator/TuplesAndFunctionsGenerator.java b/compiler/frontend/generator/TuplesAndFunctionsGenerator.java
index f450390b0e5..c650b0092c5 100644
--- a/compiler/frontend/generator/TuplesAndFunctionsGenerator.java
+++ b/compiler/frontend/generator/TuplesAndFunctionsGenerator.java
@@ -26,9 +26,9 @@ public class TuplesAndFunctionsGenerator {
private static void generateTuples(PrintStream out, int count) {
generated(out);
- out.println("class Tuple0() {}");
+ out.println("public class Tuple0() {}");
for (int i = 1; i < count; i++) {
- out.print("class Tuple" + i);
+ out.print("public class Tuple" + i);
out.print("<");
for (int j = 1; j <= i; j++) {
out.print("out T" + j);
@@ -39,7 +39,7 @@ public class TuplesAndFunctionsGenerator {
out.print(">");
out.print("(");
for (int j = 1; j <= i; j++) {
- out.print("_" + j + ": " + "T" + j);
+ out.print("public val _" + j + ": " + "T" + j);
if (j < i) {
out.print(", ");
}
@@ -52,7 +52,7 @@ public class TuplesAndFunctionsGenerator {
private static void generateFunctions(PrintStream out, int count, boolean extension) {
generated(out);
for (int i = 0; i < count; i++) {
- out.print("trait Function" + i);
+ out.print("public trait " + (extension ? "ExtensionFunction" : "Function") + i);
out.print("<");
if (extension) {
out.print("in T");
@@ -65,7 +65,7 @@ public class TuplesAndFunctionsGenerator {
out.print(", ");
}
out.print("out R> {\n");
- out.print(" fun " + (extension ? "T." : "") +
+ out.print(" public fun " + (extension ? "T." : "") +
"invoke(");
for (int j = 1; j <= i; j++) {
out.print("p" + j + ": " + "P" + j);
@@ -82,21 +82,23 @@ public class TuplesAndFunctionsGenerator {
out.println("// Generated by " + TuplesAndFunctionsGenerator.class.getCanonicalName());
out.println("// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses");
out.println();
+ out.println("package jet");
+ out.println();
}
public static void main(String[] args) throws FileNotFoundException {
- File baseDir = new File("compiler/frontend/src/jet/");
+ File baseDir = new File("compiler/frontend/src/jet.src/");
assert baseDir.exists() : "Base dir does not exist: " + baseDir.getAbsolutePath();
- PrintStream tuples = new PrintStream(new File(baseDir, "Tuples.jet.src"));
+ PrintStream tuples = new PrintStream(new File(baseDir, "Tuples.jet"));
generateTuples(tuples, TUPLE_COUNT);
tuples.close();
- PrintStream functions = new PrintStream(new File(baseDir, "Functions.jet.src"));
+ PrintStream functions = new PrintStream(new File(baseDir, "Functions.jet"));
generateFunctions(functions, TUPLE_COUNT, false);
functions.close();
- PrintStream extensionFunctions = new PrintStream(new File(baseDir, "ExtensionFunctions.jet.src"));
+ PrintStream extensionFunctions = new PrintStream(new File(baseDir, "ExtensionFunctions.jet"));
generateFunctions(extensionFunctions, TUPLE_COUNT, true);
extensionFunctions.close();
}
diff --git a/compiler/frontend/src/jet.src/Any.jet b/compiler/frontend/src/jet.src/Any.jet
new file mode 100644
index 00000000000..636c32f49c1
--- /dev/null
+++ b/compiler/frontend/src/jet.src/Any.jet
@@ -0,0 +1,3 @@
+package jet
+
+public open class Any() {}
diff --git a/compiler/frontend/src/jet.src/ExtensionFunctions.jet b/compiler/frontend/src/jet.src/ExtensionFunctions.jet
new file mode 100644
index 00000000000..a3d2954fb45
--- /dev/null
+++ b/compiler/frontend/src/jet.src/ExtensionFunctions.jet
@@ -0,0 +1,74 @@
+// Generated by TuplesAndFunctionsGenerator
+// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses
+
+package jet
+
+public trait ExtensionFunction0 {
+ public fun T.invoke() : R
+}
+public trait ExtensionFunction1 {
+ public fun T.invoke(p1: P1) : R
+}
+public trait ExtensionFunction2 {
+ public fun T.invoke(p1: P1, p2: P2) : R
+}
+public trait ExtensionFunction3 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3) : R
+}
+public trait ExtensionFunction4 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
+}
+public trait ExtensionFunction5 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
+}
+public trait ExtensionFunction6 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
+}
+public trait ExtensionFunction7 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
+}
+public trait ExtensionFunction8 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
+}
+public trait ExtensionFunction9 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R
+}
+public trait ExtensionFunction10 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10) : R
+}
+public trait ExtensionFunction11 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11) : R
+}
+public trait ExtensionFunction12 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12) : R
+}
+public trait ExtensionFunction13 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13) : R
+}
+public trait ExtensionFunction14 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14) : R
+}
+public trait ExtensionFunction15 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15) : R
+}
+public trait ExtensionFunction16 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16) : R
+}
+public trait ExtensionFunction17 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17) : R
+}
+public trait ExtensionFunction18 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18) : R
+}
+public trait ExtensionFunction19 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19) : R
+}
+public trait ExtensionFunction20 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20) : R
+}
+public trait ExtensionFunction21 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21) : R
+}
+public trait ExtensionFunction22 {
+ public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22) : R
+}
diff --git a/compiler/frontend/src/jet.src/Functions.jet b/compiler/frontend/src/jet.src/Functions.jet
new file mode 100644
index 00000000000..f0e0d901d03
--- /dev/null
+++ b/compiler/frontend/src/jet.src/Functions.jet
@@ -0,0 +1,74 @@
+// Generated by TuplesAndFunctionsGenerator
+// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses
+
+package jet
+
+public trait Function0 {
+ public fun invoke() : R
+}
+public trait Function1 {
+ public fun invoke(p1: P1) : R
+}
+public trait Function2 {
+ public fun invoke(p1: P1, p2: P2) : R
+}
+public trait Function3 {
+ public fun invoke(p1: P1, p2: P2, p3: P3) : R
+}
+public trait Function4 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
+}
+public trait Function5 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
+}
+public trait Function6 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
+}
+public trait Function7 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
+}
+public trait Function8 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
+}
+public trait Function9 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R
+}
+public trait Function10 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10) : R
+}
+public trait Function11 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11) : R
+}
+public trait Function12 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12) : R
+}
+public trait Function13 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13) : R
+}
+public trait Function14 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14) : R
+}
+public trait Function15 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15) : R
+}
+public trait Function16 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16) : R
+}
+public trait Function17 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17) : R
+}
+public trait Function18 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18) : R
+}
+public trait Function19 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19) : R
+}
+public trait Function20 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20) : R
+}
+public trait Function21 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21) : R
+}
+public trait Function22 {
+ public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22) : R
+}
diff --git a/compiler/frontend/src/jet.src/Nothing.jet b/compiler/frontend/src/jet.src/Nothing.jet
new file mode 100644
index 00000000000..836cc3bfad7
--- /dev/null
+++ b/compiler/frontend/src/jet.src/Nothing.jet
@@ -0,0 +1,6 @@
+package jet
+
+/**
+ * Nothing has no instances
+ */
+public class Nothing private () {}
diff --git a/compiler/frontend/src/jet.src/README.md b/compiler/frontend/src/jet.src/README.md
new file mode 100644
index 00000000000..2aef103ac7a
--- /dev/null
+++ b/compiler/frontend/src/jet.src/README.md
@@ -0,0 +1,4 @@
+These files are used only for navigation from user code in IDE.
+
+These files are not processed by Kotlin compiler. Compiler creates Any, Nothing, tuple and function
+types on-the-fly.
\ No newline at end of file
diff --git a/compiler/frontend/src/jet.src/Tuples.jet b/compiler/frontend/src/jet.src/Tuples.jet
new file mode 100644
index 00000000000..ebbecd1e57c
--- /dev/null
+++ b/compiler/frontend/src/jet.src/Tuples.jet
@@ -0,0 +1,28 @@
+// Generated by TuplesAndFunctionsGenerator
+// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses
+
+package jet
+
+public class Tuple0() {}
+public class Tuple1(public val _1: T1) {}
+public class Tuple2(public val _1: T1, public val _2: T2) {}
+public class Tuple3(public val _1: T1, public val _2: T2, public val _3: T3) {}
+public class Tuple4(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4) {}
+public class Tuple5(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5) {}
+public class Tuple6(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6) {}
+public class Tuple7(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7) {}
+public class Tuple8(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8) {}
+public class Tuple9(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9) {}
+public class Tuple10(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10) {}
+public class Tuple11(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11) {}
+public class Tuple12(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12) {}
+public class Tuple13(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13) {}
+public class Tuple14(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14) {}
+public class Tuple15(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15) {}
+public class Tuple16(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16) {}
+public class Tuple17(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16, public val _17: T17) {}
+public class Tuple18(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16, public val _17: T17, public val _18: T18) {}
+public class Tuple19(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16, public val _17: T17, public val _18: T18, public val _19: T19) {}
+public class Tuple20(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16, public val _17: T17, public val _18: T18, public val _19: T19, public val _20: T20) {}
+public class Tuple21(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16, public val _17: T17, public val _18: T18, public val _19: T19, public val _20: T20, public val _21: T21) {}
+public class Tuple22(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5, public val _6: T6, public val _7: T7, public val _8: T8, public val _9: T9, public val _10: T10, public val _11: T11, public val _12: T12, public val _13: T13, public val _14: T14, public val _15: T15, public val _16: T16, public val _17: T17, public val _18: T18, public val _19: T19, public val _20: T20, public val _21: T21, public val _22: T22) {}
diff --git a/compiler/frontend/src/jet/ExtensionFunctions.jet.src b/compiler/frontend/src/jet/ExtensionFunctions.jet.src
deleted file mode 100644
index a4c9768d097..00000000000
--- a/compiler/frontend/src/jet/ExtensionFunctions.jet.src
+++ /dev/null
@@ -1,72 +0,0 @@
-// Generated by TuplesAndFunctionsGenerator
-// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses
-
-trait Function0 {
- fun T.invoke() : R
-}
-trait Function1 {
- fun T.invoke(p1: P1) : R
-}
-trait Function2 {
- fun T.invoke(p1: P1, p2: P2) : R
-}
-trait Function3 {
- fun T.invoke(p1: P1, p2: P2, p3: P3) : R
-}
-trait Function4 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
-}
-trait Function5 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
-}
-trait Function6 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
-}
-trait Function7 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
-}
-trait Function8 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
-}
-trait Function9 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R
-}
-trait Function10 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10) : R
-}
-trait Function11 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11) : R
-}
-trait Function12 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12) : R
-}
-trait Function13 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13) : R
-}
-trait Function14 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14) : R
-}
-trait Function15 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15) : R
-}
-trait Function16 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16) : R
-}
-trait Function17 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17) : R
-}
-trait Function18 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18) : R
-}
-trait Function19 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19) : R
-}
-trait Function20 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20) : R
-}
-trait Function21 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21) : R
-}
-trait Function22 {
- fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22) : R
-}
diff --git a/compiler/frontend/src/jet/Functions.jet.src b/compiler/frontend/src/jet/Functions.jet.src
deleted file mode 100644
index 857603314d5..00000000000
--- a/compiler/frontend/src/jet/Functions.jet.src
+++ /dev/null
@@ -1,72 +0,0 @@
-// Generated by TuplesAndFunctionsGenerator
-// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses
-
-trait Function0 {
- fun invoke() : R
-}
-trait Function1 {
- fun invoke(p1: P1) : R
-}
-trait Function2 {
- fun invoke(p1: P1, p2: P2) : R
-}
-trait Function3 {
- fun invoke(p1: P1, p2: P2, p3: P3) : R
-}
-trait Function4 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
-}
-trait Function5 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
-}
-trait Function6 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
-}
-trait Function7 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
-}
-trait Function8 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
-}
-trait Function9 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R
-}
-trait Function10 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10) : R
-}
-trait Function11 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11) : R
-}
-trait Function12 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12) : R
-}
-trait Function13 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13) : R
-}
-trait Function14 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14) : R
-}
-trait Function15 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15) : R
-}
-trait Function16 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16) : R
-}
-trait Function17 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17) : R
-}
-trait Function18 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18) : R
-}
-trait Function19 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19) : R
-}
-trait Function20 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20) : R
-}
-trait Function21 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21) : R
-}
-trait Function22 {
- fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22) : R
-}
diff --git a/compiler/frontend/src/jet/Tuples.jet.src b/compiler/frontend/src/jet/Tuples.jet.src
deleted file mode 100644
index e122ecbdeea..00000000000
--- a/compiler/frontend/src/jet/Tuples.jet.src
+++ /dev/null
@@ -1,26 +0,0 @@
-// Generated by TuplesAndFunctionsGenerator
-// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses
-
-class Tuple0() {}
-class Tuple1(_1: T1) {}
-class Tuple2(_1: T1, _2: T2) {}
-class Tuple3(_1: T1, _2: T2, _3: T3) {}
-class Tuple4(_1: T1, _2: T2, _3: T3, _4: T4) {}
-class Tuple5(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5) {}
-class Tuple6(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6) {}
-class Tuple7(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7) {}
-class Tuple8(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8) {}
-class Tuple9(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9) {}
-class Tuple10(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10) {}
-class Tuple11(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11) {}
-class Tuple12(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12) {}
-class Tuple13(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13) {}
-class Tuple14(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14) {}
-class Tuple15(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15) {}
-class Tuple16(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16) {}
-class Tuple17(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17) {}
-class Tuple18(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18) {}
-class Tuple19(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19) {}
-class Tuple20(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19, _20: T20) {}
-class Tuple21(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19, _20: T20, _21: T21) {}
-class Tuple22(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19, _20: T20, _21: T21, _22: T22) {}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/ModuleConfiguration.java b/compiler/frontend/src/org/jetbrains/jet/lang/ModuleConfiguration.java
index d5366ad5204..1d55fcf0c56 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/ModuleConfiguration.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/ModuleConfiguration.java
@@ -42,8 +42,8 @@ public interface ModuleConfiguration {
void addDefaultImports(@NotNull Collection directives);
/**
- *
- * This method is called every time a namespace descriptor is created. Use it to add extra descriptors to the namespace, e.g. merge a Java package with a Kotlin one
+ * This method is called every time a namespace descriptor is created. Use it to add extra descriptors to the namespace, e.g. merge a
+ * Java package with a Kotlin one
*/
void extendNamespaceScope(@NotNull BindingTrace trace, @NotNull NamespaceDescriptor namespaceDescriptor, @NotNull WritableScope namespaceMemberScope);
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FqNamed.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FqNamed.java
new file mode 100644
index 00000000000..80300e463d7
--- /dev/null
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FqNamed.java
@@ -0,0 +1,29 @@
+/*
+ * 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.descriptors;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.resolve.FqName;
+
+/**
+ * @author Nikolay Krasko
+ */
+public interface FqNamed {
+
+ @NotNull
+ FqName getQualifiedName();
+}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
index 6854bf0777d..1dcbe098eff 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptor.java
@@ -22,7 +22,10 @@ import org.jetbrains.jet.lang.psi.JetParameter;
import org.jetbrains.jet.lang.resolve.AbstractScopeAdapter;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace;
-import org.jetbrains.jet.lang.resolve.scopes.*;
+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.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
@@ -43,49 +46,31 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
private final WritableScope scopeForSupertypeResolution;
private WritableScope scopeForInitializers = null; //contains members + primary constructor value parameters + map for backing fields
- public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope, ClassKind kind) {
+ public MutableClassDescriptor(@NotNull DeclarationDescriptor containingDeclaration,
+ @NotNull JetScope outerScope, ClassKind kind, String name) {
super(containingDeclaration, kind);
RedeclarationHandler redeclarationHandler = RedeclarationHandler.DO_NOTHING;
- setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler).setDebugName("MemberLookup").changeLockLevel(WritableScope.LockLevel.BOTH));
- this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler).setDebugName("SupertypeResolution").changeLockLevel(WritableScope.LockLevel.BOTH);
- this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler).setDebugName("MemberResolution").changeLockLevel(WritableScope.LockLevel.BOTH);
+ setScopeForMemberLookup(new WritableScopeImpl(JetScope.EMPTY, this, redeclarationHandler)
+ .setDebugName("MemberLookup")
+ .changeLockLevel(WritableScope.LockLevel.BOTH));
+ this.scopeForSupertypeResolution = new WritableScopeImpl(outerScope, this, redeclarationHandler)
+ .setDebugName("SupertypeResolution")
+ .changeLockLevel(WritableScope.LockLevel.BOTH);
+ this.scopeForMemberResolution = new WritableScopeImpl(scopeForSupertypeResolution, this, redeclarationHandler)
+ .setDebugName("MemberResolution")
+ .changeLockLevel(WritableScope.LockLevel.BOTH);
if (getKind() == ClassKind.TRAIT) {
setUpScopeForInitializers(this);
}
+
+ setName(name);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- @Override
- public ClassObjectStatus setClassObjectDescriptor(@NotNull final MutableClassDescriptorLite classObjectDescriptor) {
- ClassObjectStatus r = super.setClassObjectDescriptor(classObjectDescriptor);
- if (r != ClassObjectStatus.OK) {
- return r;
- }
-
- // Members of the class object are accessible from the class
- // The scope must be lazy, because classObjectDescriptor may not by fully built yet
- scopeForMemberResolution.importScope(new AbstractScopeAdapter() {
- @NotNull
- @Override
- protected JetScope getWorkerScope() {
- return classObjectDescriptor.getDefaultType().getMemberScope();
- }
-
- @NotNull
- @Override
- public ReceiverDescriptor getImplicitReceiver() {
- return classObjectDescriptor.getImplicitReceiver();
- }
- }
- );
-
- return ClassObjectStatus.OK;
- }
-
@Override
public void addConstructor(@NotNull ConstructorDescriptor constructorDescriptor, @NotNull BindingTrace trace) {
super.addConstructor(constructorDescriptor, trace);
@@ -101,28 +86,6 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
}
}
- @Override
- public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
- super.addPropertyDescriptor(propertyDescriptor);
- properties.add(propertyDescriptor);
- if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
- declaredCallableMembers.add(propertyDescriptor);
- }
- allCallableMembers.add(propertyDescriptor);
- scopeForMemberResolution.addPropertyDescriptor(propertyDescriptor);
- }
-
- @Override
- public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
- super.addFunctionDescriptor(functionDescriptor);
- functions.add(functionDescriptor);
- if (functionDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
- declaredCallableMembers.add(functionDescriptor);
- }
- allCallableMembers.add(functionDescriptor);
- scopeForMemberResolution.addFunctionDescriptor(functionDescriptor);
- }
-
@NotNull
public Set getFunctions() {
return functions;
@@ -144,11 +107,6 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
}
@Override
- public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
- super.addClassifierDescriptor(classDescriptor);
- scopeForMemberResolution.addClassifierDescriptor(classDescriptor);
- }
-
public void setTypeParameterDescriptors(List typeParameters) {
super.setTypeParameterDescriptors(typeParameters);
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
@@ -197,6 +155,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
this.scopeForInitializers = new WritableScopeImpl(scopeForMemberResolution, containingDeclaration, RedeclarationHandler.DO_NOTHING).setDebugName("Initializers").changeLockLevel(WritableScope.LockLevel.BOTH);
}
+ @Override
public void lockScopes() {
super.lockScopes();
scopeForSupertypeResolution.changeLockLevel(WritableScope.LockLevel.READING);
@@ -204,4 +163,81 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
getWritableScopeForInitializers().changeLockLevel(WritableScope.LockLevel.READING);
}
+ private NamespaceLikeBuilder builder = null;
+
+ @Override
+ public NamespaceLikeBuilder getBuilder() {
+ if (builder == null) {
+ final NamespaceLikeBuilder superBuilder = super.getBuilder();
+ builder = new NamespaceLikeBuilderDummy() {
+ @NotNull
+ @Override
+ public DeclarationDescriptor getOwnerForChildren() {
+ return superBuilder.getOwnerForChildren();
+ }
+
+ @Override
+ public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
+ superBuilder.addObjectDescriptor(objectDescriptor);
+ }
+
+ @Override
+ public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
+ superBuilder.addClassifierDescriptor(classDescriptor);
+ scopeForMemberResolution.addClassifierDescriptor(classDescriptor);
+ }
+
+ @Override
+ public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
+ superBuilder.addFunctionDescriptor(functionDescriptor);
+ functions.add(functionDescriptor);
+ if (functionDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
+ declaredCallableMembers.add(functionDescriptor);
+ }
+ allCallableMembers.add(functionDescriptor);
+ scopeForMemberResolution.addFunctionDescriptor(functionDescriptor);
+ }
+
+ @Override
+ public ClassObjectStatus setClassObjectDescriptor(@NotNull final MutableClassDescriptorLite classObjectDescriptor) {
+ ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
+ if (r != ClassObjectStatus.OK) {
+ return r;
+ }
+
+ // Members of the class object are accessible from the class
+ // The scope must be lazy, because classObjectDescriptor may not by fully built yet
+ scopeForMemberResolution.importScope(new AbstractScopeAdapter() {
+ @NotNull
+ @Override
+ protected JetScope getWorkerScope() {
+ return classObjectDescriptor.getDefaultType().getMemberScope();
+ }
+
+ @NotNull
+ @Override
+ public ReceiverDescriptor getImplicitReceiver() {
+ return classObjectDescriptor.getImplicitReceiver();
+ }
+ }
+ );
+
+ return ClassObjectStatus.OK;
+ }
+
+ @Override
+ public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
+ superBuilder.addPropertyDescriptor(propertyDescriptor);
+ properties.add(propertyDescriptor);
+ if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) {
+ declaredCallableMembers.add(propertyDescriptor);
+ }
+ allCallableMembers.add(propertyDescriptor);
+ scopeForMemberResolution.addPropertyDescriptor(propertyDescriptor);
+ }
+ };
+ }
+
+ return builder;
+ }
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java
index bd5bf229f73..9ebfffaa1a7 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MutableClassDescriptorLite.java
@@ -36,7 +36,8 @@ import java.util.*;
/**
* @author Stepan Koltsov
*/
-public class MutableClassDescriptorLite extends MutableDeclarationDescriptor implements ClassDescriptor, NamespaceLikeBuilder {
+public class MutableClassDescriptorLite extends MutableDeclarationDescriptor
+ implements ClassDescriptor, WithDeferredResolve {
private ConstructorDescriptor primaryConstructor;
private final Set constructors = Sets.newLinkedHashSet();
@@ -60,11 +61,21 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
private ClassReceiver implicitReceiver;
- public MutableClassDescriptorLite(@NotNull DeclarationDescriptor containingDeclaration, ClassKind kind) {
+ public MutableClassDescriptorLite(@NotNull DeclarationDescriptor containingDeclaration,
+ @NotNull ClassKind kind) {
super(containingDeclaration);
this.kind = kind;
}
+ @Override
+ public void forceResolve() {
+
+ }
+
+ @Override
+ public boolean isAlreadyResolved() {
+ return false;
+ }
private static boolean isStatic(DeclarationDescriptor declarationDescriptor) {
if (declarationDescriptor instanceof NamespaceDescriptor) {
@@ -79,29 +90,6 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
}
}
-
- @NotNull
- @Override
- public DeclarationDescriptor getOwnerForChildren() {
- return this;
- }
-
- @Override
- public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
- if (this.classObjectDescriptor != null) return ClassObjectStatus.DUPLICATE;
- if (!isStatic(this.getContainingDeclaration())) {
- return ClassObjectStatus.NOT_ALLOWED;
- }
- assert classObjectDescriptor.getKind() == ClassKind.OBJECT;
- this.classObjectDescriptor = classObjectDescriptor;
-
- return ClassObjectStatus.OK;
- }
-
-
-
-
-
@NotNull
@Override
public TypeConstructor getTypeConstructor() {
@@ -258,20 +246,7 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
return classObjectDescriptor;
}
- @Override
- public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
- getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(propertyDescriptor);
- }
- @Override
- public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
- getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
- }
-
- @Override
- public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
- getScopeForMemberLookupAsWritableScope().addClassifierDescriptor(classDescriptor);
- }
@NotNull
@Override
@@ -279,11 +254,6 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
return innerClassesScope;
}
- @Override
- public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
- getScopeForMemberLookupAsWritableScope().addObjectDescriptor(objectDescriptor);
- }
-
public void addSupertype(@NotNull JetType supertype) {
if (!ErrorUtils.isErrorType(supertype)) {
if (TypeUtils.getClassDescriptor(supertype) != null) {
@@ -341,4 +311,59 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
public void setAnnotations(List annotations) {
this.annotations = annotations;
}
+
+ private NamespaceLikeBuilder builder = null;
+ public NamespaceLikeBuilder getBuilder() {
+ if (builder == null) {
+ builder = new NamespaceLikeBuilderDummy() {
+ @NotNull
+ @Override
+ public DeclarationDescriptor getOwnerForChildren() {
+ return MutableClassDescriptorLite.this;
+ }
+
+ @Override
+ public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
+ getScopeForMemberLookupAsWritableScope().addClassifierDescriptor(classDescriptor);
+ }
+
+ @Override
+ public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
+ getScopeForMemberLookupAsWritableScope().addObjectDescriptor(objectDescriptor);
+ }
+
+ @Override
+ public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
+ getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(functionDescriptor);
+ }
+
+ @Override
+ public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
+ getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(propertyDescriptor);
+ }
+
+ @Override
+ public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
+ if (getKind() == ClassKind.OBJECT) {
+ return ClassObjectStatus.NOT_ALLOWED;
+ }
+
+ if (MutableClassDescriptorLite.this.classObjectDescriptor != null) {
+ return ClassObjectStatus.DUPLICATE;
+ }
+
+ if (!isStatic(MutableClassDescriptorLite.this.getContainingDeclaration())) {
+ return ClassObjectStatus.NOT_ALLOWED;
+ }
+
+ assert classObjectDescriptor.getKind() == ClassKind.OBJECT;
+ MutableClassDescriptorLite.this.classObjectDescriptor = classObjectDescriptor;
+
+ return ClassObjectStatus.OK;
+ }
+ };
+ }
+
+ return builder;
+ }
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java
index 5aafdb2db18..bfc32403e32 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptor.java
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.types.NamespaceType;
/**
* @author abreslav
*/
-public interface NamespaceDescriptor extends Annotated, Named, ClassOrNamespaceDescriptor, NamespaceDescriptorParent {
+public interface NamespaceDescriptor extends Annotated, Named, FqNamed, ClassOrNamespaceDescriptor, NamespaceDescriptorParent {
@NotNull
JetScope getMemberScope();
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java
index 17990d263b2..06b3507b8bd 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/NamespaceDescriptorImpl.java
@@ -19,6 +19,8 @@ package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
+import org.jetbrains.jet.lang.resolve.DescriptorUtils;
+import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import java.util.List;
@@ -26,22 +28,22 @@ import java.util.List;
/**
* @author abreslav
*/
-public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl implements NamespaceLikeBuilder {
+public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl implements WithDeferredResolve {
private WritableScope memberScope;
- public NamespaceDescriptorImpl(@NotNull NamespaceDescriptorParent containingDeclaration, @NotNull List annotations, @NotNull String name) {
+ public NamespaceDescriptorImpl(@NotNull NamespaceDescriptorParent containingDeclaration,
+ @NotNull List annotations,
+ @NotNull String name) {
super(containingDeclaration, annotations, name);
}
public void initialize(@NotNull WritableScope memberScope) {
- this.memberScope = memberScope;
- }
+ if (this.memberScope != null) {
+ throw new IllegalStateException("Namespace member scope reinitialize");
+ }
- @NotNull
- @Override
- public DeclarationDescriptor getOwnerForChildren() {
- return this;
+ this.memberScope = memberScope;
}
@Override
@@ -50,37 +52,64 @@ public class NamespaceDescriptorImpl extends AbstractNamespaceDescriptorImpl imp
return memberScope;
}
- public NamespaceDescriptorImpl getNamespace(String name) {
- return (NamespaceDescriptorImpl) memberScope.getDeclaredNamespace(name);
- }
-
@Override
public void addNamespace(@NotNull NamespaceDescriptor namespaceDescriptor) {
- memberScope.addNamespace(namespaceDescriptor);
+ getMemberScope().addNamespace(namespaceDescriptor);
+ }
+
+ @NotNull
+ @Override
+ public FqName getQualifiedName() {
+ return DescriptorUtils.getFQName(this).toSafe();
+ }
+
+ private NamespaceLikeBuilder builder = null;
+ public NamespaceLikeBuilder getBuilder() {
+ if (builder == null) {
+ builder = new NamespaceLikeBuilder() {
+ @Override
+ public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
+ getMemberScope().addClassifierDescriptor(classDescriptor);
+ }
+
+ @Override
+ public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
+ getMemberScope().addObjectDescriptor(objectDescriptor);
+ }
+
+ @Override
+ public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
+ getMemberScope().addFunctionDescriptor(functionDescriptor);
+ }
+
+ @Override
+ public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
+ getMemberScope().addPropertyDescriptor(propertyDescriptor);
+ }
+
+ @NotNull
+ @Override
+ public DeclarationDescriptor getOwnerForChildren() {
+ return NamespaceDescriptorImpl.this;
+ }
+
+ @Override
+ public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
+ throw new IllegalStateException("Must be guaranteed not to happen by the parser");
+ }
+ };
+ }
+
+ return builder;
}
@Override
- public void addClassifierDescriptor(@NotNull MutableClassDescriptorLite classDescriptor) {
- memberScope.addClassifierDescriptor(classDescriptor);
+ public void forceResolve() {
+
}
@Override
- public void addObjectDescriptor(@NotNull MutableClassDescriptorLite objectDescriptor) {
- memberScope.addObjectDescriptor(objectDescriptor);
- }
-
- @Override
- public void addFunctionDescriptor(@NotNull SimpleFunctionDescriptor functionDescriptor) {
- memberScope.addFunctionDescriptor(functionDescriptor);
- }
-
- @Override
- public void addPropertyDescriptor(@NotNull PropertyDescriptor propertyDescriptor) {
- memberScope.addPropertyDescriptor(propertyDescriptor);
- }
-
- @Override
- public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
- throw new IllegalStateException("Must be guaranteed not to happen by the parser");
+ public boolean isAlreadyResolved() {
+ return false;
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibilities.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibilities.java
index 10df49710e6..151ee5df33b 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibilities.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/Visibilities.java
@@ -109,6 +109,9 @@ public class Visibilities {
public static final Set INTERNAL_VISIBILITIES = Sets.newHashSet(PRIVATE, INTERNAL, INTERNAL_PROTECTED, LOCAL);
+ private Visibilities() {
+ }
+
public static boolean isVisible(DeclarationDescriptorWithVisibility what, DeclarationDescriptor from) {
DeclarationDescriptorWithVisibility parent = what;
while (parent != null) {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/WithDeferredResolve.java b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/WithDeferredResolve.java
new file mode 100644
index 00000000000..da3177fa2e4
--- /dev/null
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/descriptors/WithDeferredResolve.java
@@ -0,0 +1,25 @@
+/*
+ * 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.descriptors;
+
+/**
+ * @author Nikolay Krasko
+ */
+public interface WithDeferredResolve {
+ void forceResolve();
+ boolean isAlreadyResolved();
+}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java
index be456c83593..82ca7a8ebe1 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/DiagnosticUtils.java
@@ -73,7 +73,7 @@ public class DiagnosticUtils {
public static String atLocation(PsiFile file, TextRange textRange, Document document) {
int offset = textRange.getStartOffset();
VirtualFile virtualFile = file.getVirtualFile();
- String pathSuffix = virtualFile == null ? "" : " in " + virtualFile.getPath();
+ String pathSuffix = " in " + (virtualFile == null ? file.getName() : virtualFile.getPath());
return offsetToLineAndColumn(document, offset).toString() + pathSuffix;
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java
index 997ef40c1fb..902de8fe6a4 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java
@@ -252,7 +252,7 @@ public interface Errors {
JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression;
TextRange lastBracketRange = blockExpression.getLastBracketRange();
if (lastBracketRange == null) {
- return markElement(element);
+ return Collections.emptyList();
}
return markRange(lastBracketRange);
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java
index 9d0da50c551..cb05ae1c528 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java
@@ -57,13 +57,13 @@ public class JetParsing extends AbstractJetParsing {
/*package*/ static final TokenSet TYPE_REF_FIRST = TokenSet.create(LBRACKET, IDENTIFIER, FUN_KEYWORD, LPAR, CAPITALIZED_THIS_KEYWORD, HASH);
private static final TokenSet RECEIVER_TYPE_TERMINATORS = TokenSet.create(DOT, SAFE_ACCESS);
- public static JetParsing createForTopLevel(SemanticWhitespaceAwarePsiBuilder builder) {
+ static JetParsing createForTopLevel(SemanticWhitespaceAwarePsiBuilder builder) {
JetParsing jetParsing = new JetParsing(builder);
jetParsing.myExpressionParsing = new JetExpressionParsing(builder, jetParsing);
return jetParsing;
}
- public static JetParsing createForByClause(final SemanticWhitespaceAwarePsiBuilder builder) {
+ private static JetParsing createForByClause(final SemanticWhitespaceAwarePsiBuilder builder) {
final SemanticWhitespaceAwarePsiBuilderForByClause builderForByClause = new SemanticWhitespaceAwarePsiBuilderForByClause(builder);
JetParsing jetParsing = new JetParsing(builderForByClause);
jetParsing.myExpressionParsing = new JetExpressionParsing(builderForByClause, jetParsing) {
@@ -94,7 +94,7 @@ public class JetParsing extends AbstractJetParsing {
* : preamble toplevelObject[| import]* [eof]
* ;
*/
- public void parseFile() {
+ void parseFile() {
PsiBuilder.Marker fileMarker = mark();
parsePreamble();
@@ -297,7 +297,7 @@ public class JetParsing extends AbstractJetParsing {
/*
* (modifier | attribute)*
*/
- public boolean parseModifierList(JetNodeType nodeType, boolean allowShortAnnotations) {
+ boolean parseModifierList(JetNodeType nodeType, boolean allowShortAnnotations) {
return parseModifierList(nodeType, null, allowShortAnnotations);
}
@@ -306,7 +306,7 @@ public class JetParsing extends AbstractJetParsing {
*
* Feeds modifiers (not attributes) into the passed consumer, if it is not null
*/
- public boolean parseModifierList(JetNodeType nodeType, Consumer tokenConsumer, boolean allowShortAnnotations) {
+ boolean parseModifierList(JetNodeType nodeType, @Nullable Consumer tokenConsumer, boolean allowShortAnnotations) {
PsiBuilder.Marker list = mark();
boolean empty = true;
while (!eof()) {
@@ -336,8 +336,10 @@ public class JetParsing extends AbstractJetParsing {
* : annotation*
* ;
*/
- public void parseAnnotations(boolean allowShortAnnotations) {
- while (parseAnnotation(allowShortAnnotations));
+ void parseAnnotations(boolean allowShortAnnotations) {
+ while (true) {
+ if (!(parseAnnotation(allowShortAnnotations))) break;
+ }
}
/*
@@ -417,7 +419,7 @@ public class JetParsing extends AbstractJetParsing {
* (classBody? | enumClassBody)
* ;
*/
- public IElementType parseClass(boolean enumClass) {
+ IElementType parseClass(boolean enumClass) {
assert _atSet(CLASS_KEYWORD, TRAIT_KEYWORD);
advance(); // CLASS_KEYWORD or TRAIT_KEYWORD
@@ -649,7 +651,7 @@ public class JetParsing extends AbstractJetParsing {
* : "object" SimpleName? ":" delegationSpecifier{","}? classBody?
* ;
*/
- public void parseObject(boolean named, boolean optionalBody) {
+ void parseObject(boolean named, boolean optionalBody) {
assert _at(OBJECT_KEYWORD);
advance(); // OBJECT_KEYWORD
@@ -785,7 +787,7 @@ public class JetParsing extends AbstractJetParsing {
* : modifiers "type" SimpleName (typeParameters typeConstraints)? "=" type
* ;
*/
- public JetNodeType parseTypeDef() {
+ JetNodeType parseTypeDef() {
assert _at(TYPE_KEYWORD);
advance(); // TYPE_KEYWORD
@@ -815,11 +817,11 @@ public class JetParsing extends AbstractJetParsing {
* (getter? setter? | setter? getter?) SEMI?
* ;
*/
- public JetNodeType parseProperty() {
+ private JetNodeType parseProperty() {
return parseProperty(false);
}
- public JetNodeType parseProperty(boolean local) {
+ JetNodeType parseProperty(boolean local) {
if (at(VAL_KEYWORD) || at(VAR_KEYWORD)) {
advance(); // VAL_KEYWORD or VAR_KEYWORD
}
@@ -970,7 +972,7 @@ public class JetParsing extends AbstractJetParsing {
* functionBody?
* ;
*/
- public IElementType parseFunction() {
+ IElementType parseFunction() {
assert _at(FUN_KEYWORD);
advance(); // FUN_KEYWORD
@@ -1086,7 +1088,7 @@ public class JetParsing extends AbstractJetParsing {
* : "{" (expressions)* "}"
* ;
*/
- public void parseBlock() {
+ void parseBlock() {
PsiBuilder.Marker block = mark();
myBuilder.enableNewlines();
@@ -1303,11 +1305,11 @@ public class JetParsing extends AbstractJetParsing {
* nullableType
* : typeDescriptor "?"
*/
- public void parseTypeRef() {
+ void parseTypeRef() {
parseTypeRef(TokenSet.EMPTY);
}
- public void parseTypeRef(TokenSet extraRecoverySet) {
+ void parseTypeRef(TokenSet extraRecoverySet) {
PsiBuilder.Marker typeRefMarker = parseTypeRefContents(extraRecoverySet);
typeRefMarker.done(TYPE_REFERENCE);
}
@@ -1461,7 +1463,7 @@ public class JetParsing extends AbstractJetParsing {
/*
* (optionalProjection type){","}
*/
- public PsiBuilder.Marker parseTypeArgumentList() {
+ private PsiBuilder.Marker parseTypeArgumentList() {
if (!at(LT)) return null;
PsiBuilder.Marker list = mark();
@@ -1472,7 +1474,7 @@ public class JetParsing extends AbstractJetParsing {
return list;
}
- public boolean tryParseTypeArgumentList(TokenSet extraRecoverySet) {
+ boolean tryParseTypeArgumentList(TokenSet extraRecoverySet) {
myBuilder.disableNewlines();
advance(); // LT
@@ -1605,7 +1607,7 @@ public class JetParsing extends AbstractJetParsing {
* : parameter ("=" element)?
* ;
*/
- public void parseValueParameterList(boolean isFunctionTypeContents, TokenSet recoverySet) {
+ void parseValueParameterList(boolean isFunctionTypeContents, TokenSet recoverySet) {
PsiBuilder.Marker parameters = mark();
myBuilder.disableNewlines();
@@ -1736,10 +1738,6 @@ public class JetParsing extends AbstractJetParsing {
this.tokens = TokenSet.create(token);
}
- public TokenDetector(TokenSet tokens) {
- this.tokens = tokens;
- }
-
@Override
public void consume(IElementType item) {
if (tokens.contains(item)) {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
index e126c6036a0..38186556f36 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
@@ -17,8 +17,12 @@
package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
import com.intellij.psi.StubBasedPsiElement;
import com.intellij.psi.stubs.IStubElementType;
+import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -27,6 +31,7 @@ import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
import org.jetbrains.jet.lexer.JetTokens;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -41,11 +46,10 @@ public class JetClass extends JetTypeParameterListOwner
public JetClass(@NotNull ASTNode node) {
super(node);
}
-
// TODO (stubs)
-// public JetClass(final PsiJetClassStub stub) {
-// this.stub = stub;
-// }
+ // public JetClass(final PsiJetClassStub stub) {
+ // this.stub = stub;
+ // }
@Override
public List getDeclarations() {
@@ -163,4 +167,35 @@ public class JetClass extends JetTypeParameterListOwner
public void delete() throws IncorrectOperationException {
JetPsiUtil.deleteClass(this);
}
+
+ @Override
+ public boolean isEquivalentTo(PsiElement another) {
+ if (super.isEquivalentTo(another)) {
+ return true;
+ }
+ if (another instanceof JetClass) {
+ String fq1 = getQualifiedName();
+ String fq2 = ((JetClass) another).getQualifiedName();
+ return fq1 != null && fq2 != null && fq1.equals(fq2);
+ }
+ return true;
+ }
+
+ @Nullable
+ private String getQualifiedName() {
+ List parts = new ArrayList();
+ JetClassOrObject current = this;
+ while (current != null) {
+ parts.add(current.getName());
+ current = PsiTreeUtil.getParentOfType(current, JetClassOrObject.class);
+ }
+ PsiFile file = getContainingFile();
+ if (!(file instanceof JetFile)) return null;
+ String fileQualifiedName = ((JetFile) file).getNamespaceHeader().getQualifiedName();
+ if (!fileQualifiedName.isEmpty()) {
+ parts.add(fileQualifiedName);
+ }
+ Collections.reverse(parts);
+ return StringUtil.join(parts, ".");
+ }
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java
index 853d94cc51c..11da1bacd73 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassBody.java
@@ -30,11 +30,13 @@ import java.util.List;
/**
* @author max
*/
-public class JetClassBody extends JetElement {
+public class JetClassBody extends JetElement implements JetDeclarationContainer {
public JetClassBody(@NotNull ASTNode node) {
super(node);
}
+ @Override
+ @NotNull
public List getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java
index 42e0d6d1239..a4ad2a43b6e 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClassOrObject.java
@@ -26,9 +26,7 @@ import java.util.List;
/**
* @author max
*/
-public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner {
- List getDeclarations();
-
+public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner, JetDeclarationContainer {
@Nullable
JetDelegationSpecifierList getDelegationSpecifierList();
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java
new file mode 100644
index 00000000000..07a76741a12
--- /dev/null
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDeclarationContainer.java
@@ -0,0 +1,29 @@
+/*
+ * 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.psi;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+/**
+ * @author Nikolay Krasko
+ */
+public interface JetDeclarationContainer {
+ @NotNull
+ List getDeclarations();
+}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
index 152b3d4b883..84ccdd7d97f 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
@@ -33,11 +33,12 @@ import org.jetbrains.jet.plugin.JetLanguage;
import java.util.List;
-public class JetFile extends PsiFileBase {
+public class JetFile extends PsiFileBase implements JetDeclarationContainer {
public JetFile(FileViewProvider viewProvider) {
super(viewProvider, JetLanguage.INSTANCE);
}
+ @Override
@NotNull
public FileType getFileType() {
return JetFileType.INSTANCE;
@@ -48,6 +49,8 @@ public class JetFile extends PsiFileBase {
return "JetFile: " + getName();
}
+ @NotNull
+ @Override
public List getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java
index a599f4b8e4a..bbe19cf4d8b 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceBody.java
@@ -25,11 +25,13 @@ import java.util.List;
/**
* @author max
*/
-public class JetNamespaceBody extends JetElement {
+public class JetNamespaceBody extends JetElement implements JetDeclarationContainer {
public JetNamespaceBody(@NotNull ASTNode node) {
super(node);
}
+ @NotNull
+ @Override
public List getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceHeader.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceHeader.java
index 8aa9295070f..ad4e4d725ea 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceHeader.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetNamespaceHeader.java
@@ -81,5 +81,16 @@ public class JetNamespaceHeader extends JetReferenceExpression {
public boolean isRoot() {
return getName().length() == 0;
}
+
+ public String getQualifiedName() {
+ StringBuilder builder = new StringBuilder();
+ for (JetSimpleNameExpression e : findChildrenByClass(JetSimpleNameExpression.class)) {
+ if (builder.length() > 0) {
+ builder.append(".");
+ }
+ builder.append(e.getName());
+ }
+ return builder.toString();
+ }
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java
index cde638bb6a7..bf8d3b47c2a 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.FqName;
import org.jetbrains.jet.lang.resolve.ImportPath;
+import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.Collection;
@@ -240,6 +241,17 @@ public class JetPsiUtil {
return parent;
}
}
+ if (parent instanceof JetTryExpression) {
+ JetTryExpression tryExpression = (JetTryExpression) parent;
+ if (tryExpression.getTryBlock() == block) {
+ return parent;
+ }
+ for (JetCatchClause clause : tryExpression.getCatchClauses()) {
+ if (clause.getCatchBody() == block) {
+ return parent;
+ }
+ }
+ }
return null;
}
@@ -256,6 +268,9 @@ public class JetPsiUtil {
if (expression == null) {
expression = getDirectParentOfTypeForBlock(block, JetFunctionLiteral.class);
}
+ if (expression == null) {
+ expression = getDirectParentOfTypeForBlock(block, JetTryExpression.class);
+ }
if (expression != null) {
return isImplicitlyUsed(expression);
}
@@ -307,7 +322,7 @@ public class JetPsiUtil {
return false;
}
- return "Unit".equals(typeReference.getText());
+ return JetStandardClasses.UNIT_ALIAS.equals(typeReference.getText());
}
public static boolean isSafeCall(@NotNull Call call) {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
index f81a71066f9..3037770347d 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
@@ -45,7 +45,7 @@ public class JetClassElementType extends JetStubElementType implements PsiJ
@Override
public PsiClass[] getClasses() {
- return new PsiClass[0]; //To change body of implemented methods use File | Settings | File Templates.
+ return new PsiClass[0];
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java
index 389a3fa1486..938868bd8ee 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BindingContextUtils.java
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall;
-import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
import org.jetbrains.jet.util.slicedmap.Slices;
@@ -74,11 +73,6 @@ public class BindingContextUtils {
return element;
}
- // TODO: Need to have a valid stubs for standard classes
- if (referenceExpression != null && JetStandardClasses.getAllStandardClasses().contains(declarationDescriptor)) {
- return referenceExpression.getContainingFile();
- }
-
return null;
}
@@ -94,11 +88,6 @@ public class BindingContextUtils {
return elements;
}
- // TODO: Need to have a valid stubs for standard classes
- if (referenceExpression != null && JetStandardClasses.getAllStandardClasses().contains(declarationDescriptor)) {
- return Lists.newArrayList(referenceExpression.getContainingFile());
- }
-
return Lists.newArrayList();
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java
index adb1d676230..348b203428a 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java
@@ -404,7 +404,8 @@ public class BodyResolver {
JetExpression bodyExpression = declaration.getBodyExpression();
if (bodyExpression != null) {
- expressionTypingServices.checkFunctionReturnType(scopeForConstructorBody, declaration, descriptor, JetStandardClasses.getUnitType(), trace);
+ expressionTypingServices.checkFunctionReturnType(scopeForConstructorBody, declaration, descriptor, DataFlowInfo.EMPTY,
+ JetStandardClasses.getUnitType(), trace);
}
checkDefaultParameterValues(declaration.getValueParameters(), descriptor.getValueParameters(), scopeForConstructorBody);
@@ -548,7 +549,7 @@ public class BodyResolver {
JetExpression bodyExpression = function.getBodyExpression();
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(declaringScope, functionDescriptor, trace);
if (bodyExpression != null) {
- expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, trace);
+ expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, null, trace);
}
List valueParameters = function.getValueParameters();
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java
index 26ce64163e1..684b8df60de 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java
@@ -34,9 +34,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
-import static org.jetbrains.jet.lang.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT;
-import static org.jetbrains.jet.lang.diagnostics.Errors.REDECLARATION;
-import static org.jetbrains.jet.lang.diagnostics.Errors.SECONDARY_CONSTRUCTORS_ARE_NOT_SUPPORTED;
+import static org.jetbrains.jet.lang.diagnostics.Errors.*;
/**
* @author abreslav
@@ -127,7 +125,7 @@ public class DeclarationResolver {
for (Map.Entry entry : context.getNamespaceScopes().entrySet()) {
JetFile namespace = entry.getKey();
WritableScope namespaceScope = entry.getValue();
- NamespaceLikeBuilder namespaceDescriptor = context.getNamespaceDescriptors().get(namespace);
+ NamespaceLikeBuilder namespaceDescriptor = context.getNamespaceDescriptors().get(namespace).getBuilder();
resolveFunctionAndPropertyHeaders(namespace.getDeclarations(), namespaceScope, namespaceScope, namespaceScope, namespaceDescriptor);
}
@@ -135,13 +133,14 @@ public class DeclarationResolver {
JetClass jetClass = entry.getKey();
MutableClassDescriptor classDescriptor = entry.getValue();
- resolveFunctionAndPropertyHeaders(jetClass.getDeclarations(), classDescriptor.getScopeForMemberResolution(),
+ resolveFunctionAndPropertyHeaders(
+ jetClass.getDeclarations(), classDescriptor.getScopeForMemberResolution(),
classDescriptor.getScopeForInitializers(), classDescriptor.getScopeForMemberResolution(),
- classDescriptor);
-// processPrimaryConstructor(classDescriptor, jetClass);
-// for (JetSecondaryConstructor jetConstructor : jetClass.getSecondaryConstructors()) {
-// processSecondaryConstructor(classDescriptor, jetConstructor);
-// }
+ classDescriptor.getBuilder());
+ // processPrimaryConstructor(classDescriptor, jetClass);
+ // for (JetSecondaryConstructor jetConstructor : jetClass.getSecondaryConstructors()) {
+ // processSecondaryConstructor(classDescriptor, jetConstructor);
+ // }
}
for (Map.Entry entry : context.getObjects().entrySet()) {
JetObjectDeclaration object = entry.getKey();
@@ -149,7 +148,7 @@ public class DeclarationResolver {
resolveFunctionAndPropertyHeaders(object.getDeclarations(), classDescriptor.getScopeForMemberResolution(),
classDescriptor.getScopeForInitializers(), classDescriptor.getScopeForMemberResolution(),
- classDescriptor);
+ classDescriptor.getBuilder());
}
// TODO : Extensions
@@ -186,17 +185,22 @@ public class DeclarationResolver {
@Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
- PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), trace);
+ PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(
+ namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), trace);
+
namespaceLike.addPropertyDescriptor(propertyDescriptor);
}
@Override
public void visitEnumEntry(JetEnumEntry enumEntry) {
if (enumEntry.getPrimaryConstructorParameterList() == null) {
- MutableClassDescriptorLite classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
+ // FIX: Bad cast
+ MutableClassDescriptorLite classObjectDescriptor =
+ ((MutableClassDescriptorLite)namespaceLike.getOwnerForChildren()).getClassObjectDescriptor();
assert classObjectDescriptor != null;
- PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), trace);
- classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
+ PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(
+ classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), trace);
+ classObjectDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor);
}
}
});
@@ -222,7 +226,7 @@ public class DeclarationResolver {
memberScope,
parameter, trace
);
- classDescriptor.addPropertyDescriptor(propertyDescriptor);
+ classDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor);
context.getPrimaryConstructorParameterProperties().put(parameter, propertyDescriptor);
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java
index 102cf6f271e..02b5326aa21 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DelegationResolver.java
@@ -72,7 +72,7 @@ public class DelegationResolver {
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) declarationDescriptor;
if (propertyDescriptor.getModality().isOverridable()) {
PropertyDescriptor copy = propertyDescriptor.copy(classDescriptor, true, CallableMemberDescriptor.Kind.DELEGATION, true);
- classDescriptor.addPropertyDescriptor(copy);
+ classDescriptor.getBuilder().addPropertyDescriptor(copy);
trace.record(DELEGATED, copy);
}
}
@@ -80,7 +80,7 @@ public class DelegationResolver {
SimpleFunctionDescriptor functionDescriptor = (SimpleFunctionDescriptor) declarationDescriptor;
if (functionDescriptor.getModality().isOverridable()) {
SimpleFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true, CallableMemberDescriptor.Kind.DELEGATION, true);
- classDescriptor.addFunctionDescriptor(copy);
+ classDescriptor.getBuilder().addFunctionDescriptor(copy);
trace.record(DELEGATED, copy);
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java
index 3a00c1f85eb..c1fb3d10f21 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorUtils.java
@@ -318,7 +318,7 @@ public class DescriptorUtils {
public static List getPathWithoutRootNsAndModule(@NotNull DeclarationDescriptor descriptor) {
List path = Lists.newArrayList();
DeclarationDescriptor current = descriptor;
- for (;;) {
+ while (true) {
if (current instanceof NamespaceDescriptor && isRootNamespace((NamespaceDescriptor) current)) {
return Lists.reverse(path);
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/FqNameUnsafe.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/FqNameUnsafe.java
index dc9a8d30156..2671f5e606d 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/FqNameUnsafe.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/FqNameUnsafe.java
@@ -29,6 +29,8 @@ import java.util.List;
*/
public class FqNameUnsafe {
+ public static final String ROOT_NAME = "";
+
@NotNull
private final String fqName;
@@ -196,7 +198,7 @@ public class FqNameUnsafe {
FqNameUnsafe last = new FqNameUnsafe(firstSegment, FqName.ROOT.toUnsafe(), firstSegment);
callback.segment(firstSegment, last);
- for (;;) {
+ while (true) {
int next = fqName.indexOf('.', pos + 1);
if (next < 0) {
if (this.parent == null) {
@@ -246,7 +248,7 @@ public class FqNameUnsafe {
@Override
public String toString() {
- return isRoot() ? "" : fqName;
+ return isRoot() ? ROOT_NAME : fqName;
}
@Override
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportPath.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportPath.java
index 661969e7550..720b8a469fb 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportPath.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ImportPath.java
@@ -22,8 +22,8 @@ import org.jetbrains.annotations.NotNull;
* @author Nikolay Krasko
*/
public final class ImportPath {
- final @NotNull FqName fqName;
- final boolean isAllUnder;
+ private final @NotNull FqName fqName;
+ private final boolean isAllUnder;
public ImportPath(@NotNull FqName fqName, boolean isAllUnder) {
this.fqName = fqName;
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/NamespaceFactoryImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/NamespaceFactoryImpl.java
index f1c0c8dd9bd..7b50e5601a8 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/NamespaceFactoryImpl.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/NamespaceFactoryImpl.java
@@ -17,6 +17,7 @@
package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Sets;
+import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.ModuleConfiguration;
@@ -61,14 +62,17 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
this.configuration = configuration;
}
- public NamespaceDescriptorImpl createNamespaceDescriptorPathIfNeeded(JetFile file, JetScope outerScope) {
+ @NotNull
+ public NamespaceDescriptorImpl createNamespaceDescriptorPathIfNeeded(@NotNull JetFile file,
+ @NotNull JetScope outerScope,
+ @NotNull RedeclarationHandler handler) {
JetNamespaceHeader namespaceHeader = file.getNamespaceHeader();
if (moduleDescriptor.getRootNs() == null) {
- createNamespaceDescriptorIfNeeded(null, moduleDescriptor, "", true, null);
+ createRootNamespaceDescriptorIfNeeded(null, moduleDescriptor, null, handler);
}
- NamespaceDescriptorParent currentOwner = moduleDescriptor.getRootNs();
+ NamespaceDescriptorImpl currentOwner = moduleDescriptor.getRootNs();
if (currentOwner == null) {
throw new IllegalStateException("must be initialized 5 lines above");
}
@@ -77,7 +81,7 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
String namespaceName = JetPsiUtil.safeName(nameExpression.getReferencedName());
NamespaceDescriptorImpl namespaceDescriptor = createNamespaceDescriptorIfNeeded(
- null, currentOwner, namespaceName, false, nameExpression);
+ null, currentOwner, namespaceName, nameExpression, handler);
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
trace.record(RESOLUTION_SCOPE, nameExpression, outerScope);
@@ -89,13 +93,14 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
NamespaceDescriptorImpl namespaceDescriptor;
String name;
if (namespaceHeader.isRoot()) {
- // again to register file in trace
- namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, moduleDescriptor, "", true, null);
+ // previous call to createRootNamespaceDescriptorIfNeeded couldn't store occurrence for current file.
+ namespaceDescriptor = moduleDescriptor.getRootNs();
+ storeBindingForFileAndExpression(file, null, namespaceDescriptor);
}
else {
name = namespaceHeader.getName();
- namespaceDescriptor = createNamespaceDescriptorIfNeeded(file, currentOwner, name, namespaceHeader.isRoot(),
- namespaceHeader.getLastPartExpression());
+ namespaceDescriptor = createNamespaceDescriptorIfNeeded(
+ file, currentOwner, name, namespaceHeader.getLastPartExpression(), handler);
trace.record(BindingContext.NAMESPACE_IS_SRC, namespaceDescriptor, true);
trace.record(RESOLUTION_SCOPE, namespaceHeader, outerScope);
@@ -107,49 +112,95 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
@Override
@NotNull
public NamespaceDescriptorImpl createNamespaceDescriptorPathIfNeeded(@NotNull FqName fqName) {
- NamespaceDescriptorParent owner = moduleDescriptor;
+ NamespaceDescriptorImpl owner = null;
for (FqName pathElement : fqName.path()) {
- owner = createNamespaceDescriptorIfNeeded(null,
- owner, pathElement.isRoot() ? "" : pathElement.shortName(), pathElement.isRoot(), null);
+ if (pathElement.isRoot()) {
+ owner = createRootNamespaceDescriptorIfNeeded(null,
+ moduleDescriptor,
+ null,
+ RedeclarationHandler.DO_NOTHING);
+ }
+ else {
+ assert owner != null : "Should never be null as first element in the path must be root";
+ owner = createNamespaceDescriptorIfNeeded(null,
+ owner,
+ pathElement.shortName(),
+ null,
+ RedeclarationHandler.DO_NOTHING);
+ }
+
}
- return (NamespaceDescriptorImpl) owner;
+
+ assert owner != null : "Should never be null as first element in the path must be root";
+ return owner;
+ }
+
+ private NamespaceDescriptorImpl createRootNamespaceDescriptorIfNeeded(@Nullable JetFile file,
+ @NotNull ModuleDescriptor owner,
+ @Nullable JetReferenceExpression expression,
+ @NotNull RedeclarationHandler handler) {
+ FqName fqName = FqName.ROOT;
+ NamespaceDescriptorImpl namespaceDescriptor = owner.getRootNs();
+
+ if (namespaceDescriptor == null) {
+ namespaceDescriptor = createNewNamespaceDescriptor(owner, FqNameUnsafe.ROOT_NAME, expression, handler, fqName);
+ }
+
+ storeBindingForFileAndExpression(file, expression, namespaceDescriptor);
+
+ return namespaceDescriptor;
}
@NotNull
- public NamespaceDescriptorImpl createNamespaceDescriptorIfNeeded(@Nullable JetFile file,
- @NotNull NamespaceDescriptorParent owner, @NotNull String name, boolean root, @Nullable JetReferenceExpression expression) {
- FqName fqName;
- NamespaceDescriptorImpl namespaceDescriptor;
- if (root) {
- if (!(owner instanceof ModuleDescriptor)) {
- throw new IllegalStateException();
- }
- fqName = FqName.ROOT;
- namespaceDescriptor = ((ModuleDescriptor) owner).getRootNs();
- }
- else {
- FqName ownerFqName = DescriptorUtils.getFQName(owner).toSafe();
- fqName = ownerFqName.child(name);
- namespaceDescriptor = ((NamespaceDescriptorImpl) owner).getNamespace(name);
- }
+ private NamespaceDescriptorImpl createNamespaceDescriptorIfNeeded(@Nullable JetFile file,
+ @NotNull NamespaceDescriptorImpl owner,
+ @NotNull String name,
+ @Nullable JetReferenceExpression expression,
+ @NotNull RedeclarationHandler handler) {
+ FqName ownerFqName = DescriptorUtils.getFQName(owner).toSafe();
+ FqName fqName = ownerFqName.child(name);
+ // !!!
+ NamespaceDescriptorImpl namespaceDescriptor = (NamespaceDescriptorImpl) owner.getMemberScope().getDeclaredNamespace(name);
if (namespaceDescriptor == null) {
- namespaceDescriptor = new NamespaceDescriptorImpl(
- owner,
- Collections.emptyList(), // TODO: annotations
- name
- );
- trace.record(FQNAME_TO_NAMESPACE_DESCRIPTOR, fqName, namespaceDescriptor);
- WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, RedeclarationHandler.DO_NOTHING).setDebugName("Namespace member scope");
- scope.changeLockLevel(WritableScope.LockLevel.BOTH);
- namespaceDescriptor.initialize(scope);
- configuration.extendNamespaceScope(trace, namespaceDescriptor, scope);
- owner.addNamespace(namespaceDescriptor);
- if (expression != null) {
- trace.record(BindingContext.NAMESPACE, expression, namespaceDescriptor);
- }
+ namespaceDescriptor = createNewNamespaceDescriptor(owner, name, expression, handler, fqName);
}
+ storeBindingForFileAndExpression(file, expression, namespaceDescriptor);
+
+ return namespaceDescriptor;
+ }
+
+ private NamespaceDescriptorImpl createNewNamespaceDescriptor(NamespaceDescriptorParent owner,
+ String name,
+ PsiElement expression,
+ RedeclarationHandler handler,
+ FqName fqName) {
+ NamespaceDescriptorImpl namespaceDescriptor;
+ namespaceDescriptor = new NamespaceDescriptorImpl(
+ owner,
+ Collections.emptyList(), // TODO: annotations
+ name
+ );
+ trace.record(FQNAME_TO_NAMESPACE_DESCRIPTOR, fqName, namespaceDescriptor);
+
+ WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, handler).setDebugName("Namespace member scope");
+ scope.changeLockLevel(WritableScope.LockLevel.BOTH);
+
+ namespaceDescriptor.initialize(scope);
+ scope.changeLockLevel(WritableScope.LockLevel.BOTH);
+ //
+ configuration.extendNamespaceScope(trace, namespaceDescriptor, scope);
+ owner.addNamespace(namespaceDescriptor);
+ if (expression != null) {
+ trace.record(BindingContext.NAMESPACE, expression, namespaceDescriptor);
+ }
+ return namespaceDescriptor;
+ }
+
+ private void storeBindingForFileAndExpression(@Nullable JetFile file,
+ @Nullable JetReferenceExpression expression,
+ @NotNull NamespaceDescriptor namespaceDescriptor) {
if (expression != null) {
trace.record(REFERENCE_TARGET, expression, namespaceDescriptor);
}
@@ -166,9 +217,5 @@ public class NamespaceFactoryImpl implements NamespaceFactory {
files.add(file);
trace.record(BindingContext.NAMESPACE_TO_FILES, namespaceDescriptor, files);
}
-
- return namespaceDescriptor;
}
-
-
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
index 8a8a521cc7a..d81599fdb3b 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java
@@ -138,10 +138,10 @@ public class OverrideResolver {
@Override
public void addToScope(@NotNull CallableMemberDescriptor fakeOverride) {
if (fakeOverride instanceof PropertyDescriptor) {
- classDescriptor.addPropertyDescriptor((PropertyDescriptor) fakeOverride);
+ classDescriptor.getBuilder().addPropertyDescriptor((PropertyDescriptor) fakeOverride);
}
else if (fakeOverride instanceof SimpleFunctionDescriptor) {
- classDescriptor.addFunctionDescriptor((SimpleFunctionDescriptor) fakeOverride);
+ classDescriptor.getBuilder().addFunctionDescriptor((SimpleFunctionDescriptor) fakeOverride);
}
else {
throw new IllegalStateException(fakeOverride.getClass().getName());
@@ -298,23 +298,22 @@ public class OverrideResolver {
if (overriddenDeclarations.size() == 0) {
throw new IllegalStateException("A 'fake override' must override something");
}
- else if (overriddenDeclarations.size() == 1) {
- CallableMemberDescriptor single = overriddenDeclarations.iterator().next();
- if (single.getModality() == Modality.ABSTRACT) {
- abstractNoImpl.add(single);
- }
- }
else {
List nonAbstractManyImpl = Lists.newArrayList();
Set filteredOverriddenDeclarations = OverridingUtil.filterOverrides(Sets.newHashSet(overriddenDeclarations));
+ boolean allSuperAbstract = true;
for (CallableMemberDescriptor overridden : filteredOverriddenDeclarations) {
if (overridden.getModality() != Modality.ABSTRACT) {
nonAbstractManyImpl.add(overridden);
+ allSuperAbstract = false;
}
}
if (nonAbstractManyImpl.size() > 1) {
manyImpl.addAll(nonAbstractManyImpl);
}
+ else if (allSuperAbstract) {
+ abstractNoImpl.addAll(overriddenDeclarations);
+ }
}
}
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java
index 6f7c088fae8..e9afa155b33 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalysisContext.java
@@ -16,7 +16,6 @@
package org.jetbrains.jet.lang.resolve;
-import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement;
@@ -30,7 +29,6 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import javax.inject.Inject;
import java.io.PrintStream;
import java.util.Map;
-import java.util.Set;
/**
* @author abreslav
@@ -39,7 +37,6 @@ public class TopDownAnalysisContext {
private final Map classes = Maps.newLinkedHashMap();
private final Map objects = Maps.newLinkedHashMap();
- protected final Map namespaceScopes = Maps.newHashMap();
private JetScope rootScope;
protected final Map namespaceDescriptors = Maps.newHashMap();
@@ -50,6 +47,13 @@ public class TopDownAnalysisContext {
private final Map primaryConstructorParameterProperties = Maps.newHashMap();
private Map members = null;
+ // File scopes - package scope extended with imports
+ protected final Map namespaceScopes = Maps.newHashMap();
+
+ public final Map forDeferredResolver = Maps.newHashMap();
+
+ public final Map normalScope = Maps.newHashMap();
+
private StringBuilder debugOutput;
@@ -68,7 +72,7 @@ public class TopDownAnalysisContext {
debugOutput.append(message).append("\n");
}
}
-
+
/*package*/ void enableDebugOutput() {
if (debugOutput == null) {
debugOutput = new StringBuilder();
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
index 597d0ffe38e..ec6d73ee855 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
@@ -199,7 +199,7 @@ public class TopDownAnalyzer {
}
// context.getDeclaringScopes().put(file, outerScope);
- doProcess(outerScope, standardLibraryNamespace, toAnalyze);
+ doProcess(outerScope, standardLibraryNamespace.getBuilder(), toAnalyze);
}
public static void processObject(
@@ -207,8 +207,8 @@ public class TopDownAnalyzer {
@NotNull final BindingTrace trace,
@NotNull JetScope outerScope,
@NotNull final DeclarationDescriptor containingDeclaration,
- @NotNull JetObjectDeclaration object) {
-
+ @NotNull JetObjectDeclaration object
+ ) {
ModuleDescriptor moduleDescriptor = new ModuleDescriptor("");
TopDownAnalysisParameters topDownAnalysisParameters =
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
index 6135ed5a0a0..b14137e3621 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
@@ -27,9 +27,13 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
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.WriteThroughScope;
-import org.jetbrains.jet.lang.types.*;
+import org.jetbrains.jet.lang.types.JetType;
+import org.jetbrains.jet.lang.types.SubstitutionUtils;
+import org.jetbrains.jet.lang.types.TypeConstructor;
+import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lexer.JetTokens;
@@ -82,11 +86,42 @@ public class TypeHierarchyResolver {
this.trace = trace;
}
-
-
- public void process(@NotNull JetScope outerScope, @NotNull NamespaceLikeBuilder owner, @NotNull Collection extends PsiElement> declarations) {
+ public void process(@NotNull JetScope outerScope, @NotNull NamespaceLikeBuilder owner,
+ @NotNull Collection extends PsiElement> declarations) {
context.setRootScope(outerScope);
- collectNamespacesAndClassifiers(outerScope, outerScope, owner, declarations); // namespaceScopes, classes
+
+ {
+ // TODO: Very temp code - main goal is to remove recursion from collectNamespacesAndClassifiers
+ Queue forDeferredResolve = new LinkedList();
+ forDeferredResolve.addAll(collectNamespacesAndClassifiers(outerScope, owner, declarations));
+
+ while (!forDeferredResolve.isEmpty()) {
+ JetDeclarationContainer declarationContainer = forDeferredResolve.poll();
+ assert declarationContainer != null;
+
+ WithDeferredResolve descriptorForDeferredResolve = context.forDeferredResolver.get(declarationContainer);
+ JetScope scope = context.normalScope.get(declarationContainer);
+
+ // Even more temp code
+ if (descriptorForDeferredResolve instanceof MutableClassDescriptorLite) {
+ forDeferredResolve.addAll(
+ collectNamespacesAndClassifiers(
+ scope,
+ ((MutableClassDescriptorLite) descriptorForDeferredResolve).getBuilder(),
+ declarationContainer.getDeclarations()));
+ }
+ else if (descriptorForDeferredResolve instanceof NamespaceDescriptorImpl) {
+ forDeferredResolve.addAll(
+ collectNamespacesAndClassifiers(
+ scope,
+ ((NamespaceDescriptorImpl) descriptorForDeferredResolve).getBuilder(),
+ declarationContainer.getDeclarations()));
+ }
+ else {
+ assert false;
+ }
+ }
+ }
importsResolver.processTypeImports();
@@ -106,105 +141,111 @@ public class TypeHierarchyResolver {
checkTypesInClassHeaders(); // Check bounds in the types used in generic bounds and supertype lists
}
- private void collectNamespacesAndClassifiers(
+ /**
+ * Use nearest class object scope or namespace scope
+ *
+ * @param declarationElement
+ * @param owner
+ * @return
+ */
+ @NotNull
+ private JetScope getStaticScope(PsiElement declarationElement, @NotNull NamespaceLikeBuilder owner) {
+ DeclarationDescriptor ownerDescriptor = owner.getOwnerForChildren();
+ if (ownerDescriptor instanceof NamespaceDescriptorImpl) {
+ return context.getNamespaceScopes().get(declarationElement.getContainingFile());
+ }
+
+ if (ownerDescriptor instanceof MutableClassDescriptor) {
+ MutableClassDescriptor classDescriptor = (MutableClassDescriptor) ownerDescriptor;
+ if (classDescriptor.getKind() == ClassKind.OBJECT) {
+ return classDescriptor.getScopeForMemberResolution();
+ }
+
+ DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
+ if (declaration instanceof NamespaceDescriptorImpl) {
+ return getStaticScope(declarationElement, ((NamespaceDescriptorImpl)declaration).getBuilder());
+ }
+
+ if (declaration instanceof MutableClassDescriptorLite) {
+ return getStaticScope(declarationElement, ((MutableClassDescriptorLite)declaration).getBuilder());
+ }
+ }
+
+ return null;
+ }
+
+ @Nullable
+ private Collection collectNamespacesAndClassifiers(
@NotNull final JetScope outerScope,
- @NotNull final JetScope outerScopeForStatic,
@NotNull final NamespaceLikeBuilder owner,
- @NotNull Collection extends PsiElement> declarations) {
+ @NotNull Iterable extends PsiElement> declarations
+ ) {
+ final Collection forDeferredResolve = new ArrayList();
+
for (PsiElement declaration : declarations) {
declaration.accept(new JetVisitorVoid() {
@Override
public void visitJetFile(JetFile file) {
- NamespaceDescriptorImpl namespaceDescriptor = namespaceFactory.createNamespaceDescriptorPathIfNeeded(file, outerScope);
+ NamespaceDescriptorImpl namespaceDescriptor = namespaceFactory.createNamespaceDescriptorPathIfNeeded(
+ file, outerScope, RedeclarationHandler.DO_NOTHING);
context.getNamespaceDescriptors().put(file, namespaceDescriptor);
- WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), new TraceBasedRedeclarationHandler(trace));
+ WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(),
+ new TraceBasedRedeclarationHandler(trace));
namespaceScope.changeLockLevel(WritableScope.LockLevel.BOTH);
context.getNamespaceScopes().put(file, namespaceScope);
- collectNamespacesAndClassifiers(namespaceScope, namespaceScope, namespaceDescriptor, file.getDeclarations());
+ prepareForDeferredCall(namespaceScope, namespaceDescriptor, file);
}
@Override
public void visitClass(JetClass klass) {
- MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner.getOwnerForChildren(), outerScope, getClassKind(klass));
+ MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
+ owner.getOwnerForChildren(), outerScope, getClassKind(klass), JetPsiUtil.safeName(klass.getName()));
+ context.getClasses().put(klass, mutableClassDescriptor);
trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(klass), mutableClassDescriptor);
- if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) {
- MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(trace, mutableClassDescriptor, outerScope, ClassKind.OBJECT);
- classObjectDescriptor.setName("class-object-for-" + klass.getName());
- classObjectDescriptor.setModality(Modality.FINAL);
- classObjectDescriptor.setVisibility(DescriptorResolver.resolveVisibilityFromModifiers(klass.getModifierList()));
- classObjectDescriptor.setTypeParameterDescriptors(new ArrayList(0));
- classObjectDescriptor.createTypeConstructor();
- createPrimaryConstructorForObject(null, classObjectDescriptor);
- mutableClassDescriptor.setClassObjectDescriptor(classObjectDescriptor);
- }
+ createClassObjectForEnumClass(klass, mutableClassDescriptor);
- visitClassOrObject(klass, (Map) context.getClasses(), mutableClassDescriptor);
+ JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
+
+ prepareForDeferredCall(classScope, mutableClassDescriptor, klass);
owner.addClassifierDescriptor(mutableClassDescriptor);
}
@Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) {
- final MutableClassDescriptor objectDescriptor = createClassDescriptorForObject(declaration, owner, outerScope, ClassKind.OBJECT);
+ final MutableClassDescriptor objectDescriptor = createClassDescriptorForObject(declaration, owner, outerScope);
trace.record(FQNAME_TO_CLASS_DESCRIPTOR, JetPsiUtil.getFQName(declaration), objectDescriptor);
}
@Override
public void visitEnumEntry(JetEnumEntry enumEntry) {
- MutableClassDescriptorLite classObjectDescriptor = ((MutableClassDescriptor) owner).getClassObjectDescriptor();
+ // TODO: Bad casting
+ MutableClassDescriptorLite ownerClassDescriptor = (MutableClassDescriptorLite) owner.getOwnerForChildren();
+ MutableClassDescriptorLite classObjectDescriptor = ownerClassDescriptor.getClassObjectDescriptor();
+
assert classObjectDescriptor != null : enumEntry.getParent().getText();
if (enumEntry.getPrimaryConstructorParameterList() == null) {
- createClassDescriptorForObject(enumEntry, classObjectDescriptor, outerScopeForStatic, ClassKind.ENUM_ENTRY);
- return;
+ // Simple enum entry
+
+ createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor.getBuilder());
}
- MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, classObjectDescriptor, outerScope, ClassKind.ENUM_ENTRY);
- visitClassOrObject(
- enumEntry,
- (Map) context.getClasses(),
- mutableClassDescriptor
- );
- classObjectDescriptor.addObjectDescriptor(mutableClassDescriptor);
- }
+ else {
+ // Advanced enum entry like "Cons(val head : T, val tail : List) : List(tail.size + 1)"
+ MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
+ classObjectDescriptor, outerScope, ClassKind.ENUM_ENTRY, JetPsiUtil.safeName(enumEntry.getName()));
+ context.getClasses().put(enumEntry, mutableClassDescriptor);
- private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLikeBuilder owner, JetScope scope, ClassKind classKind) {
- MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner.getOwnerForChildren(), scope, classKind) {
- @Override
- public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
- return ClassObjectStatus.NOT_ALLOWED;
- }
- };
- Map map = classKind == ClassKind.OBJECT ? (Map) context.getObjects() : (Map) context.getClasses();
- visitClassOrObject(declaration, map, mutableClassDescriptor);
- createPrimaryConstructorForObject((JetDeclaration) declaration, mutableClassDescriptor);
- owner.addObjectDescriptor(mutableClassDescriptor);
- trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor);
- return mutableClassDescriptor;
- }
+ JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
- private void createPrimaryConstructorForObject(@Nullable JetDeclaration object, MutableClassDescriptor mutableClassDescriptor) {
- ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.emptyList(), true);
- constructorDescriptor.initialize(Collections.emptyList(), Collections.emptyList(),
- Visibilities.INTERNAL);//TODO check set mutableClassDescriptor.getVisibility()
- // TODO : make the constructor private?
- mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace);
- if (object != null) {
- trace.record(CONSTRUCTOR, object, constructorDescriptor);
+ prepareForDeferredCall(classScope, mutableClassDescriptor, enumEntry);
+
+ classObjectDescriptor.getBuilder().addObjectDescriptor(mutableClassDescriptor);
}
}
- private void visitClassOrObject(@NotNull JetClassOrObject declaration, Map map, MutableClassDescriptor mutableClassDescriptor) {
- mutableClassDescriptor.setName(JetPsiUtil.safeName(declaration.getName()));
-
- map.put(declaration, mutableClassDescriptor);
-
- JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
- JetScope scopeForStatic = declaration instanceof JetObjectDeclaration ? classScope : outerScopeForStatic;
- collectNamespacesAndClassifiers(classScope, scopeForStatic, mutableClassDescriptor, declaration.getDeclarations());
- }
-
@Override
public void visitTypedef(JetTypedef typedef) {
trace.report(UNSUPPORTED.on(typedef, "TypeHierarchyResolver"));
@@ -214,7 +255,8 @@ public class TypeHierarchyResolver {
public void visitClassObject(JetClassObject classObject) {
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
if (objectDeclaration != null) {
- NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner, outerScopeForStatic, ClassKind.OBJECT));
+ MutableClassDescriptor classObjectDescriptor = createClassDescriptorForObject(objectDeclaration, owner, getStaticScope(classObject, owner));
+ NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(classObjectDescriptor);
switch (status) {
case DUPLICATE:
trace.report(MANY_CLASS_OBJECTS.on(classObject));
@@ -222,15 +264,87 @@ public class TypeHierarchyResolver {
case NOT_ALLOWED:
trace.report(CLASS_OBJECT_NOT_ALLOWED.on(classObject));
break;
+ case OK:
+ // Everything is OK so no errors to trace.
+ break;
}
}
}
+
+ private void createClassObjectForEnumClass(JetClass klass, MutableClassDescriptor mutableClassDescriptor) {
+ if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) {
+ MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(
+ mutableClassDescriptor, outerScope, ClassKind.OBJECT, "class-object-for-" + klass.getName());
+ classObjectDescriptor.setModality(Modality.FINAL);
+ classObjectDescriptor.setVisibility(DescriptorResolver.resolveVisibilityFromModifiers(klass.getModifierList()));
+ classObjectDescriptor.setTypeParameterDescriptors(new ArrayList(0));
+ classObjectDescriptor.createTypeConstructor();
+ createPrimaryConstructorForObject(null, classObjectDescriptor);
+ mutableClassDescriptor.getBuilder().setClassObjectDescriptor(classObjectDescriptor);
+ }
+ }
+
+ private MutableClassDescriptor createClassDescriptorForObject(
+ @NotNull JetObjectDeclaration declaration, @NotNull NamespaceLikeBuilder owner, JetScope scope) {
+ MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
+ owner.getOwnerForChildren(), scope, ClassKind.OBJECT, JetPsiUtil.safeName(declaration.getName()));
+ context.getObjects().put(declaration, mutableClassDescriptor);
+
+ JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
+
+ prepareForDeferredCall(classScope, mutableClassDescriptor, declaration);
+
+ createPrimaryConstructorForObject(declaration, mutableClassDescriptor);
+ owner.addObjectDescriptor(mutableClassDescriptor);
+ trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor);
+ return mutableClassDescriptor;
+ }
+
+ private MutableClassDescriptor createClassDescriptorForEnumEntry(@NotNull JetEnumEntry declaration, @NotNull NamespaceLikeBuilder owner) {
+ MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
+ owner.getOwnerForChildren(), getStaticScope(declaration, owner), ClassKind.ENUM_ENTRY, JetPsiUtil.safeName(declaration.getName()));
+ context.getClasses().put(declaration, mutableClassDescriptor);
+
+ prepareForDeferredCall(mutableClassDescriptor.getScopeForMemberResolution(), mutableClassDescriptor, declaration);
+
+ // ??? - is enum entry object?
+ createPrimaryConstructorForObject(declaration, mutableClassDescriptor);
+ owner.addObjectDescriptor(mutableClassDescriptor);
+ trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor);
+ return mutableClassDescriptor;
+ }
+
+ private void createPrimaryConstructorForObject(@Nullable PsiElement object, MutableClassDescriptor mutableClassDescriptor) {
+ ConstructorDescriptorImpl constructorDescriptor = new ConstructorDescriptorImpl(mutableClassDescriptor, Collections.emptyList(), true);
+
+ // TODO check set mutableClassDescriptor.getVisibility()
+ constructorDescriptor.initialize(Collections.emptyList(),
+ Collections.emptyList(), Visibilities.INTERNAL);
+
+ // TODO : make the constructor private?
+ mutableClassDescriptor.setPrimaryConstructor(constructorDescriptor, trace);
+ if (object != null) {
+ trace.record(CONSTRUCTOR, object, constructorDescriptor);
+ }
+ }
+
+ private void prepareForDeferredCall(@NotNull JetScope outerScope,
+ @NotNull WithDeferredResolve withDeferredResolve,
+ @NotNull JetDeclarationContainer container) {
+ forDeferredResolve.add(container);
+ context.normalScope.put(container, outerScope);
+ context.forDeferredResolver.put(container, withDeferredResolve);
+ }
});
}
+
+ return forDeferredResolve;
}
+
+
@NotNull
- private ClassKind getClassKind(@NotNull JetClass jetClass) {
+ private static ClassKind getClassKind(@NotNull JetClass jetClass) {
if (jetClass.isTrait()) return ClassKind.TRAIT;
if (jetClass.hasModifier(JetTokens.ANNOTATION_KEYWORD)) return ClassKind.ANNOTATION_CLASS;
if (jetClass.hasModifier(JetTokens.ENUM_KEYWORD)) return ClassKind.ENUM_CLASS;
@@ -258,7 +372,8 @@ public class TypeHierarchyResolver {
for (Map.Entry entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue();
- descriptorResolver.resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters(), trace);
+ descriptorResolver.resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(),
+ descriptor.getTypeConstructor().getParameters(), trace);
descriptorResolver.resolveSupertypes(jetClass, descriptor, trace);
}
for (Map.Entry entry : context.getObjects().entrySet()) {
@@ -292,7 +407,9 @@ public class TypeHierarchyResolver {
}
}
- private static void topologicallySort(MutableClassDescriptor mutableClassDescriptor, Set visited, LinkedList topologicalOrder) {
+ private static void topologicallySort(MutableClassDescriptor mutableClassDescriptor,
+ Set visited,
+ LinkedList topologicalOrder) {
if (!visited.add(mutableClassDescriptor)) {
return;
}
@@ -306,7 +423,10 @@ public class TypeHierarchyResolver {
topologicalOrder.addFirst(mutableClassDescriptor);
}
- private void traverseTypeHierarchy(MutableClassDescriptor currentClass, Set visited, Set beingProcessed, List currentPath) {
+ private void traverseTypeHierarchy(MutableClassDescriptor currentClass,
+ Set visited,
+ Set beingProcessed,
+ List currentPath) {
if (!visited.add(currentClass)) {
if (beingProcessed.contains(currentClass)) {
markCycleErrors(currentPath, currentClass);
@@ -314,7 +434,8 @@ public class TypeHierarchyResolver {
ClassDescriptor subclassOfCurrent = currentPath.get(currentPath.size() - 1);
assert subclassOfCurrent instanceof MutableClassDescriptor;
// Disconnect the loop
- for (Iterator iterator = ((MutableClassDescriptor) subclassOfCurrent).getSupertypes().iterator(); iterator.hasNext(); ) {
+ for (Iterator iterator = ((MutableClassDescriptor) subclassOfCurrent).getSupertypes().iterator();
+ iterator.hasNext(); ) {
JetType type = iterator.next();
if (type.getConstructor() == currentClass.getTypeConstructor()) {
iterator.remove();
@@ -340,11 +461,8 @@ public class TypeHierarchyResolver {
private void markCycleErrors(List currentPath, @NotNull ClassDescriptor current) {
int size = currentPath.size();
- boolean found = false;
- for (int i = 0; i < size; i++) {
+ for (int i = size - 1; i >= 0; i--) {
ClassDescriptor classDescriptor = currentPath.get(i);
- if (classDescriptor == current) found = true;
- if (!found) continue;
ClassDescriptor superclass = (i < size - 1) ? currentPath.get(i + 1) : current;
PsiElement psiElement = BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), classDescriptor);
@@ -371,6 +489,11 @@ public class TypeHierarchyResolver {
if (elementToMark != null) {
trace.report(CYCLIC_INHERITANCE_HIERARCHY.on(elementToMark));
}
+
+ if (classDescriptor == current) {
+ // Beginning of cycle is found
+ break;
+ }
}
}
@@ -408,11 +531,14 @@ public class TypeHierarchyResolver {
if (conflictingTypes.size() > 1) {
DeclarationDescriptor containingDeclaration = typeParameterDescriptor.getContainingDeclaration();
assert containingDeclaration instanceof ClassDescriptor : containingDeclaration;
- JetClassOrObject psiElement = (JetClassOrObject) BindingContextUtils.classDescriptorToDeclaration(trace.getBindingContext(), mutableClassDescriptor);
+ JetClassOrObject psiElement = (JetClassOrObject) BindingContextUtils
+ .classDescriptorToDeclaration(trace.getBindingContext(), mutableClassDescriptor);
JetDelegationSpecifierList delegationSpecifierList = psiElement.getDelegationSpecifierList();
assert delegationSpecifierList != null;
-// trace.getErrorHandler().genericError(delegationSpecifierList.getNode(), "Type parameter " + typeParameterDescriptor.getName() + " of " + containingDeclaration.getName() + " has inconsistent values: " + conflictingTypes);
- trace.report(INCONSISTENT_TYPE_PARAMETER_VALUES.on(delegationSpecifierList, typeParameterDescriptor, (ClassDescriptor) containingDeclaration, conflictingTypes));
+ // trace.getErrorHandler().genericError(delegationSpecifierList.getNode(), "Type parameter " + typeParameterDescriptor.getName() + " of " + containingDeclaration.getName() + " has inconsistent values: " + conflictingTypes);
+ trace.report(INCONSISTENT_TYPE_PARAMETER_VALUES
+ .on(delegationSpecifierList, typeParameterDescriptor, (ClassDescriptor) containingDeclaration,
+ conflictingTypes));
}
}
}
@@ -484,4 +610,4 @@ public class TypeHierarchyResolver {
}
}
}
-}
+}
\ No newline at end of file
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
index bed5e619a86..236b320ec6a 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java
@@ -212,7 +212,7 @@ public class CallResolver {
}
else if (calleeExpression != null) {
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
- JetType calleeType = expressionTypingServices.safeGetType(context.scope, calleeExpression, NO_EXPECTED_TYPE, context.trace); // We are actually expecting a function, but there seems to be no easy way of expressing this
+ JetType calleeType = expressionTypingServices.safeGetType(context.scope, calleeExpression, NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace); // We are actually expecting a function, but there seems to be no easy way of expressing this
if (!JetStandardClasses.isFunctionType(calleeType)) {
// checkTypesWithNoCallee(trace, scope, call);
@@ -328,11 +328,7 @@ public class CallResolver {
// We have some candidates that failed for some reason
// And we have a suspect: the function literal argument
// Now, we try to remove this argument and see if it helps
- Collection> newCandidates = Lists.newArrayList();
- for (ResolutionCandidate candidate : task.getCandidates()) {
- newCandidates.add(ResolutionCandidate.create(candidate.getDescriptor(), candidate.isSafeCall())); //todo check receivers are not necessary
- }
- ResolutionTask newContext = new ResolutionTask(newCandidates, task.reference, TemporaryBindingTrace.create(task.trace), task.scope, new DelegatingCall(task.call) {
+ ResolutionTask newContext = new ResolutionTask(task.getCandidates(), task.reference, TemporaryBindingTrace.create(task.trace), task.scope, new DelegatingCall(task.call) {
@NotNull
@Override
public List getFunctionLiteralArguments() {
@@ -416,7 +412,7 @@ public class CallResolver {
checkTypesWithNoCallee(context.toBasic());
return;
}
- checkUnknownArgumentTypes(context.toBasic(), unmappedArguments);
+ checkUnmappedArgumentTypes(context.toBasic(), unmappedArguments);
}
List jetTypeArguments = context.call.getTypeArguments();
@@ -612,8 +608,8 @@ public class CallResolver {
}
}
- private void checkUnknownArgumentTypes(BasicResolutionContext context, Set unknownArguments) {
- for (ValueArgument valueArgument : unknownArguments) {
+ private void checkUnmappedArgumentTypes(BasicResolutionContext context, Set unmappedArguments) {
+ for (ValueArgument valueArgument : unmappedArguments) {
JetExpression argumentExpression = valueArgument.getArgumentExpression();
if (argumentExpression != null) {
expressionTypingServices.getType(context.scope, argumentExpression, NO_EXPECTED_TYPE, context.trace);
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ValueArgumentsToParametersMapper.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ValueArgumentsToParametersMapper.java
index 105ec16e5f2..8d1a2fdd704 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ValueArgumentsToParametersMapper.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ValueArgumentsToParametersMapper.java
@@ -101,7 +101,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
if (valueParameterDescriptor == null) {
temporaryTrace.report(NAMED_PARAMETER_NOT_FOUND.on(nameReference));
unmappedArguments.add(valueArgument);
- status = ERROR;
+ status = WEAK_ERROR;
}
else {
temporaryTrace.record(REFERENCE_TARGET, nameReference, valueParameterDescriptor);
@@ -116,14 +116,14 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
}
if (somePositioned) {
temporaryTrace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(nameReference));
- status = ERROR;
+ status = WEAK_ERROR;
}
}
else {
somePositioned = true;
if (someNamed) {
temporaryTrace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(valueArgument.asElement()));
- status = ERROR;
+ status = WEAK_ERROR;
}
else {
int parameterCount = valueParameters.size();
@@ -147,7 +147,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
else {
temporaryTrace.report(TOO_MANY_ARGUMENTS.on(valueArgument.asElement(), candidate));
unmappedArguments.add(valueArgument);
- status = WEAK_ERROR;
+ status = ERROR;
}
}
}
@@ -179,7 +179,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
else {
if (!usedParameters.add(valueParameterDescriptor)) {
temporaryTrace.report(TOO_MANY_ARGUMENTS.on(possiblyLabeledFunctionLiteral, candidate));
- status = ERROR;
+ status = WEAK_ERROR;
}
else {
status = status.compose(put(candidateCall, valueParameterDescriptor, CallMaker.makeValueArgument(functionLiteral), varargs));
@@ -190,7 +190,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
for (int i = 1; i < functionLiteralArguments.size(); i++) {
JetExpression argument = functionLiteralArguments.get(i);
temporaryTrace.report(MANY_FUNCTION_LITERAL_ARGUMENTS.on(argument));
- status = ERROR;
+ status = WEAK_ERROR;
}
}
@@ -222,6 +222,8 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
status = ERROR;
}
+ assert (candidateCall.getThisObject().exists() == candidateCall.getResultingDescriptor().getExpectedThisObject().exists()) : "Shouldn't happen because of TaskPrioritizer: " + candidateCall.getCandidateDescriptor();
+
return status;
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/IntersectionTypeConstructor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/IntersectionTypeConstructor.java
new file mode 100644
index 00000000000..2a9136302ae
--- /dev/null
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/IntersectionTypeConstructor.java
@@ -0,0 +1,100 @@
+/*
+ * 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.types;
+
+
+import com.google.common.collect.Sets;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
+import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
+import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
+import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
+
+import java.util.*;
+
+/**
+ * @author abreslav
+ */
+public class IntersectionTypeConstructor extends AnnotatedImpl implements TypeConstructor {
+ private final Set intersectedTypes;
+ private final int hashCode;
+
+ public IntersectionTypeConstructor(List annotations, Collection typesToIntersect) {
+ super(annotations);
+ this.intersectedTypes = Sets.newLinkedHashSet(typesToIntersect);
+ this.hashCode = intersectedTypes.hashCode();
+ }
+
+ @NotNull
+ @Override
+ public List getParameters() {
+ return Collections.emptyList();
+ }
+
+ @NotNull
+ @Override
+ public Collection extends JetType> getSupertypes() {
+ return intersectedTypes;
+ }
+
+ @Override
+ public boolean isSealed() {
+ return false;
+ }
+
+ @Override
+ public ClassifierDescriptor getDeclarationDescriptor() {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return makeDebugNameForIntersectionType(intersectedTypes);
+ }
+
+ private static String makeDebugNameForIntersectionType(Iterable resultingTypes) {
+ StringBuilder debugName = new StringBuilder("{");
+ for (Iterator iterator = resultingTypes.iterator(); iterator.hasNext(); ) {
+ JetType type = iterator.next();
+
+ debugName.append(type.toString());
+ if (iterator.hasNext()) {
+ debugName.append(" & ");
+ }
+ }
+ debugName.append("}");
+ return debugName.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ IntersectionTypeConstructor that = (IntersectionTypeConstructor) o;
+
+ if (intersectedTypes != null ? !intersectedTypes.equals(that.intersectedTypes) : that.intersectedTypes != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
+}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
index 3e2c231da4c..bf9eabc071d 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java
@@ -193,12 +193,8 @@ public class TypeUtils {
List noAnnotations = Collections.emptyList();
- TypeConstructor constructor = new TypeConstructorImpl(
- null,
+ TypeConstructor constructor = new IntersectionTypeConstructor(
noAnnotations,
- false,
- makeDebugNameForIntersectionType(resultingTypes).toString(),
- Collections.emptyList(),
resultingTypes);
JetScope[] scopes = new JetScope[resultingTypes.size()];
@@ -269,20 +265,6 @@ public class TypeUtils {
}
}
- private static StringBuilder makeDebugNameForIntersectionType(Iterable resultingTypes) {
- StringBuilder debugName = new StringBuilder("{");
- for (Iterator iterator = resultingTypes.iterator(); iterator.hasNext(); ) {
- JetType type = iterator.next();
-
- debugName.append(type.toString());
- if (iterator.hasNext()) {
- debugName.append(" & ");
- }
- }
- debugName.append("}");
- return debugName;
- }
-
public static boolean canHaveSubtypes(JetTypeChecker typeChecker, JetType type) {
if (type.isNullable()) {
return true;
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
index aecb9c5427e..ab67e6e0e12 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
@@ -350,7 +350,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
List entries = expression.getEntries();
List types = new ArrayList();
for (JetExpression entry : entries) {
- types.add(context.expressionTypingServices.safeGetType(context.scope, entry, NO_EXPECTED_TYPE, context.trace)); // TODO
+ types.add(context.expressionTypingServices.safeGetType(context.scope, entry, NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace)); // TODO
}
if (context.expectedType != NO_EXPECTED_TYPE && JetStandardClasses.isTupleType(context.expectedType)) {
List enrichedTypes = checkArgumentTypes(types, entries, context.expectedType.getArguments(), context);
@@ -531,10 +531,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetExpression selectorExpression = expression.getSelectorExpression();
JetExpression receiverExpression = expression.getReceiverExpression();
ExpressionTypingContext contextWithNoExpectedType = context.replaceExpectedType(NO_EXPECTED_TYPE);
- JetType receiverType = facade.getType(receiverExpression,
- contextWithNoExpectedType
- .replaceExpectedReturnType(NO_EXPECTED_TYPE)
- .replaceNamespacesAllowed(true));
+ JetType receiverType = facade.getType(receiverExpression, contextWithNoExpectedType.replaceNamespacesAllowed(true));
if (selectorExpression == null) return null;
if (receiverType == null) receiverType = ErrorUtils.createErrorType("Type for " + expression.getText());
@@ -686,8 +683,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
referencedName = referencedName == null ? " >" : referencedName;
context.labelResolver.enterLabeledElement(referencedName.substring(1), baseExpression);
// TODO : Some processing for the label?
- ExpressionTypingContext newContext = context.replaceExpectedReturnType(context.expectedType);
- JetType type = facade.getType(baseExpression, newContext, isStatement);
+ JetType type = facade.getType(baseExpression, context, isStatement);
context.labelResolver.exitLabeledElement(baseExpression);
return DataFlowUtils.checkType(type, expression, context);
}
@@ -746,7 +742,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType result;
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, JetStandardClasses.getUnitType())) {
- result = ErrorUtils.createErrorType("Unit");
+ result = ErrorUtils.createErrorType(JetStandardClasses.UNIT_ALIAS);
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
}
else {
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java
index c0a400931f8..1c5bfea7e71 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ClosureExpressionsTypingVisitor.java
@@ -102,14 +102,14 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
if (returnTypeRef != null) {
returnType = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, returnTypeRef, context.trace, true);
context.expressionTypingServices.checkFunctionReturnType(expression, context.replaceScope(functionInnerScope).
- replaceExpectedType(returnType).replaceExpectedReturnType(returnType).replaceDataFlowInfo(context.dataFlowInfo), context.trace);
+ replaceExpectedType(returnType).replaceDataFlowInfo(context.dataFlowInfo), context.trace);
}
else {
if (functionTypeExpected) {
returnType = JetStandardClasses.getReturnTypeFromFunctionType(expectedType);
}
returnType = context.expressionTypingServices.getBlockReturnedType(functionInnerScope, bodyExpression, CoercionStrategy.COERCION_TO_UNIT,
- context.replaceExpectedType(returnType).replaceExpectedReturnType(returnType), context.trace);
+ context.replaceExpectedType(returnType), context.trace);
}
JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("") : returnType;
functionDescriptor.setReturnType(safeReturnType);
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java
index edcc2b2eda4..1ccf530bf4d 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java
@@ -411,7 +411,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetParameter catchParameter = catchClause.getCatchParameter();
JetExpression catchBody = catchClause.getCatchBody();
if (catchParameter != null) {
- VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace);
+ VariableDescriptor variableDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveLocalVariableDescriptor(
+ context.scope.getContainingDeclaration(), context.scope, catchParameter, context.trace);
JetType throwableType = JetStandardLibrary.getInstance().getThrowable().getDefaultType();
DataFlowUtils.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
if (catchBody != null) {
@@ -425,13 +426,9 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
}
}
if (finallyBlock != null) {
- types.clear(); // Do not need the list for the check, but need the code above to typecheck catch bodies
- JetType type = facade.getType(finallyBlock.getFinalExpression(), context.replaceScope(context.scope));
- if (type != null) {
- types.add(type);
- }
+ facade.getType(finallyBlock.getFinalExpression(), context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE));
}
- JetType type = facade.getType(tryBlock, context.replaceScope(context.scope));
+ JetType type = facade.getType(tryBlock, context);
if (type != null) {
types.add(type);
}
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java
index 6db02920ecc..bf421054e47 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingContext.java
@@ -51,10 +51,9 @@ public class ExpressionTypingContext {
@NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
- @NotNull JetType expectedReturnType,
boolean namespacesAllowed) {
return new ExpressionTypingContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists,
- labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
+ labelResolver, trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
}
// @NotNull
@@ -74,7 +73,6 @@ public class ExpressionTypingContext {
public final DataFlowInfo dataFlowInfo;
public final JetType expectedType;
- public final JetType expectedReturnType;
public final Map patternsToDataFlowInfo;
public final Map> patternsToBoundVariableLists;
@@ -94,7 +92,6 @@ public class ExpressionTypingContext {
@NotNull JetScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
- @NotNull JetType expectedReturnType,
boolean namespacesAllowed) {
this.expressionTypingServices = expressionTypingServices;
this.trace = trace;
@@ -104,43 +101,36 @@ public class ExpressionTypingContext {
this.scope = scope;
this.dataFlowInfo = dataFlowInfo;
this.expectedType = expectedType;
- this.expectedReturnType = expectedReturnType;
this.namespacesAllowed = namespacesAllowed;
}
@NotNull
public ExpressionTypingContext replaceNamespacesAllowed(boolean namespacesAllowed) {
if (namespacesAllowed == this.namespacesAllowed) return this;
- return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
+ return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, namespacesAllowed);
}
@NotNull
public ExpressionTypingContext replaceDataFlowInfo(DataFlowInfo newDataFlowInfo) {
if (newDataFlowInfo == dataFlowInfo) return this;
- return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, newDataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
+ return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, newDataFlowInfo, expectedType, namespacesAllowed);
}
public ExpressionTypingContext replaceExpectedType(@Nullable JetType newExpectedType) {
if (newExpectedType == null) return replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
if (expectedType == newExpectedType) return this;
- return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, newExpectedType, expectedReturnType, namespacesAllowed);
- }
-
- public ExpressionTypingContext replaceExpectedReturnType(@Nullable JetType newExpectedReturnType) {
- if (newExpectedReturnType == null) return replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
- if (expectedReturnType == newExpectedReturnType) return this;
- return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, expectedType, newExpectedReturnType, namespacesAllowed);
+ return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, scope, dataFlowInfo, newExpectedType, namespacesAllowed);
}
public ExpressionTypingContext replaceBindingTrace(@NotNull BindingTrace newTrace) {
if (newTrace == trace) return this;
- return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, newTrace, scope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
+ return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, newTrace, scope, dataFlowInfo, expectedType, namespacesAllowed);
}
@NotNull
public ExpressionTypingContext replaceScope(@NotNull JetScope newScope) {
if (newScope == scope) return this;
- return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, expectedReturnType, namespacesAllowed);
+ return newContext(expressionTypingServices, patternsToDataFlowInfo, patternsToBoundVariableLists, labelResolver, trace, newScope, dataFlowInfo, expectedType, namespacesAllowed);
}
///////////// LAZY ACCESSORS
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java
index 904fb305eb7..984afc97d4b 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java
@@ -107,11 +107,6 @@ public class ExpressionTypingServices {
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) {
@@ -130,7 +125,7 @@ public class ExpressionTypingServices {
ExpressionTypingContext context = ExpressionTypingContext.newContext(
this,
new HashMap(), new HashMap>(), new LabelResolver(),
- trace, scope, dataFlowInfo, expectedType, FORBIDDEN, false
+ trace, scope, dataFlowInfo, expectedType, false
);
return expressionTypingFacade.getType(expression, context);
}
@@ -139,8 +134,7 @@ public class ExpressionTypingServices {
ExpressionTypingContext context = ExpressionTypingContext.newContext(
this,
new HashMap