Merge branch 'master' of github.com:JetBrains/kotlin

This commit is contained in:
James Strachan
2012-05-18 15:18:24 +01:00
250 changed files with 3683 additions and 1549 deletions
+1
View File
@@ -67,6 +67,7 @@
<inspection_tool class="FieldAccessedSynchronizedAndUnsynchronized" enabled="true" level="WARNING" enabled_by_default="true">
<option name="countGettersAndSetters" value="false" />
</inspection_tool>
<inspection_tool class="FieldMayBeFinal" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="FieldMayBeStatic" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="Finalize" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreTrivialFinalizers" value="true" />
Generated
+10
View File
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="IssueNavigationConfiguration">
<option name="links">
<list>
<IssueNavigationLink>
<option name="issueRegexp" value="[A-Z]+\-\d+" />
<option name="linkRegexp" value="http://youtrack.jetbrains.com/issue/$0" />
</IssueNavigationLink>
</list>
</option>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
Regular → Executable
View File
Regular → Executable
View File
+41 -35
View File
@@ -91,50 +91,56 @@
</java>
</target>
<target name="compilerSources" if="generate.javadoc">
<jar jarfile="${output}/kotlin-compiler-sources.jar">
<!-- TODO How to convert it from pathset or dirset ? -->
<fileset dir="compiler/frontend/src"/>
<fileset dir="compiler/frontend.java/src"/>
<fileset dir="compiler/backend/src"/>
<fileset dir="compiler/cli/src"/>
<fileset dir="compiler/util/src"/>
<fileset dir="compiler/jet.as.java.psi/src"/>
<fileset dir="runtime/src"/>
<fileset dir="js/js.translator/src"/>
<target name="compilerSources">
<if>
<istrue value="${generate.javadoc}"/>
<manifest>
<attribute name="Built-By" value="JetBrains"/>
<then>
<jar jarfile="${output}/kotlin-compiler-sources.jar">
<!-- TODO How to convert it from pathset or dirset ? -->
<fileset dir="compiler/frontend/src"/>
<fileset dir="compiler/frontend.java/src"/>
<fileset dir="compiler/backend/src"/>
<fileset dir="compiler/cli/src"/>
<fileset dir="compiler/util/src"/>
<fileset dir="compiler/jet.as.java.psi/src"/>
<fileset dir="runtime/src"/>
<fileset dir="js/js.translator/src"/>
<attribute name="Implementation-Vendor" value="JetBrains"/>
<attribute name="Implementation-Title" value="Kotlin Compiler Sources"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
<manifest>
<attribute name="Built-By" value="JetBrains"/>
<delete dir="${output}/kotlin-compiler-javadoc" failonerror="false" />
<javadoc destdir="${output}/kotlin-compiler-javadoc"
sourcepathref="compilerSources.path"
classpathref="classpath"
linksource="yes"
windowtitle="Kotlin Compiler"/>
<jar jarfile="${output}/kotlin-compiler-javadoc.jar">
<fileset dir="${output}/kotlin-compiler-javadoc"/>
<attribute name="Implementation-Vendor" value="JetBrains"/>
<attribute name="Implementation-Title" value="Kotlin Compiler Sources"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
<manifest>
<attribute name="Built-By" value="JetBrains"/>
<delete dir="${output}/kotlin-compiler-javadoc" failonerror="false" />
<javadoc destdir="${output}/kotlin-compiler-javadoc"
sourcepathref="compilerSources.path"
classpathref="classpath"
linksource="yes"
windowtitle="Kotlin Compiler"/>
<jar jarfile="${output}/kotlin-compiler-javadoc.jar">
<fileset dir="${output}/kotlin-compiler-javadoc"/>
<attribute name="Implementation-Vendor" value="JetBrains"/>
<attribute name="Implementation-Title" value="Kotlin Compiler Javadoc"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
<manifest>
<attribute name="Built-By" value="JetBrains"/>
<attribute name="Implementation-Vendor" value="JetBrains"/>
<attribute name="Implementation-Title" value="Kotlin Compiler Javadoc"/>
<attribute name="Implementation-Version" value="${build.number}"/>
</manifest>
</jar>
</then>
</if>
</target>
<target name="compiler">
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="${basedir}/dependencies/jarjar.jar"/>
<taskdef resource="proguard/ant/task.properties" classpath="${basedir}/dependencies/proguard.jar"/>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/dependencies/ant-contrib.jar"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${basedir}/dependencies/ant-contrib.jar"/>
<cleandir dir="${output}/classes/compiler"/>
<javac destdir="${output}/classes/compiler" debug="true" debuglevel="lines,vars,source" includeAntRuntime="false">
@@ -337,7 +343,7 @@
<arg value="-output"/>
<arg value="${output}/classes/jdk-headers"/>
<arg value="-mode"/>
<arg value="jdkHeaders"/>
<arg value="altHeaders"/>
</java>
<jar destfile="${kotlin-home}/lib/alt/kotlin-jdk-headers.jar">
@@ -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;
}
@@ -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<K2JSCompilerArguments, K2JSCompile
private static ExitCode translateAndGenerateOutputFile(@NotNull PrintingMessageCollector messageCollector,
@NotNull JetCoreEnvironment environmentForJS, @NotNull Config config, @NotNull String outputFile) {
try {
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), outputFile, config
);
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), outputFile, config);
}
catch (Exception e) {
messageCollector.report(CompilerMessageSeverity.ERROR, "Exception while translating:\n" + e.getMessage(),
@@ -120,9 +120,10 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
@NotNull
private static Config getConfig(@NotNull K2JSCompilerArguments arguments, @NotNull Project project) {
EcmaVersion ecmaVersion = EcmaVersion.fromString(arguments.target);
if (arguments.libzip == null) {
return Config.getEmptyConfig(project);
return Config.getEmptyConfig(project, ecmaVersion);
}
return new ZippedLibrarySourcesConfig(project, arguments.libzip);
return new ZippedLibrarySourcesConfig(project, arguments.libzip, ecmaVersion);
}
}
@@ -38,6 +38,9 @@ public class K2JSCompilerArguments extends CompilerArguments {
@Argument(value = "srcdir", description = "Sources directory")
public String srcdir;
@Argument(value = "target", description = "Generate js files for specific ECMA version (3 or 5, default ECMA 3)")
public String target;
@Argument(value = "tags", description = "Demarcate each compilation message (error, warning, etc) with an open and close tag")
public boolean tags;
@@ -19,6 +19,9 @@ package org.jetbrains.jet.cli.jvm;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.intellij.openapi.Disposable;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.CLICompiler;
@@ -55,17 +58,18 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
protected ExitCode doExecute(K2JVMCompilerArguments arguments, PrintingMessageCollector messageCollector, Disposable rootDisposable) {
CompilerSpecialMode mode = parseCompilerSpecialMode(arguments);
File jdkHeadersJar;
if (mode.includeJdkHeaders()) {
if (arguments.jdkHeaders != null) {
jdkHeadersJar = new File(arguments.jdkHeaders);
File[] altHeadersClasspath;
if (mode.includeAltHeaders()) {
File[] defaultAltHeadersPathArray = {PathUtil.getAltHeadersPath()};
if (arguments.altHeaders != null) {
altHeadersClasspath = ArrayUtil.mergeArrays(pathsToFiles(arguments.altHeaders), defaultAltHeadersPathArray);
}
else {
jdkHeadersJar = PathUtil.getAltHeadersPath();
altHeadersClasspath = defaultAltHeadersPathArray;
}
}
else {
jdkHeadersJar = null;
altHeadersClasspath = new File[0];
}
File runtimeJar;
@@ -81,7 +85,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
runtimeJar = null;
}
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), jdkHeadersJar, runtimeJar);
CompilerDependencies dependencies = new CompilerDependencies(mode, CompilerDependencies.findRtJar(), altHeadersClasspath, runtimeJar);
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(rootDisposable, dependencies);
K2JVMCompileEnvironmentConfiguration configuration =
new K2JVMCompileEnvironmentConfiguration(environment, messageCollector);
@@ -138,7 +142,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
}
else {
for (CompilerSpecialMode variant : CompilerSpecialMode.values()) {
if (arguments.mode.equalsIgnoreCase(variant.name().replaceAll("_", ""))) {
if (arguments.mode.equalsIgnoreCase(variant.name().replace("_", ""))) {
return variant;
}
}
@@ -181,4 +185,14 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, K2JVMComp
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), Iterables.toArray(classpath, String.class));
}
}
private static File[] pathsToFiles(String paths) {
return ContainerUtil.map(Iterables.toArray(Splitter.on(File.pathSeparatorChar).split(paths), String.class),
new Function<String, File>() {
@Override
public File fun(String s) {
return new File(s);
}
}, new File[0]);
}
}
@@ -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")
@@ -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);
}
}
@@ -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<VirtualFile> getJdkHeaderRoots() {
if (compilerSpecialMode.includeJdkHeaders()) {
return Collections.singletonList(PathUtil.jarFileToVirtualFile(jdkHeadersJar));
public List<VirtualFile> getAltHeaderRoots() {
if (compilerSpecialMode.includeAltHeaders()) {
return ContainerUtil.map2List(altHeadersClasspath, new Function<File, VirtualFile>() {
@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);
}
@@ -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;
}
}
@@ -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.<AnnotationDescriptor>emptyList(), // TODO
qualifiedName.isRoot() ? "<root>" : 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;
@@ -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;
}
@@ -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) {
@@ -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();
}
+3
View File
@@ -0,0 +1,3 @@
package jet
public open class Any() {}
@@ -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<in T, out R> {
public fun T.invoke() : R
}
public trait ExtensionFunction1<in T, in P1, out R> {
public fun T.invoke(p1: P1) : R
}
public trait ExtensionFunction2<in T, in P1, in P2, out R> {
public fun T.invoke(p1: P1, p2: P2) : R
}
public trait ExtensionFunction3<in T, in P1, in P2, in P3, out R> {
public fun T.invoke(p1: P1, p2: P2, p3: P3) : R
}
public trait ExtensionFunction4<in T, in P1, in P2, in P3, in P4, out R> {
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
}
public trait ExtensionFunction5<in T, in P1, in P2, in P3, in P4, in P5, out R> {
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
}
public trait ExtensionFunction6<in T, in P1, in P2, in P3, in P4, in P5, in P6, out R> {
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
}
public trait ExtensionFunction7<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> {
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
}
public trait ExtensionFunction8<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> {
public fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
}
public trait ExtensionFunction9<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> {
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
}
@@ -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<out R> {
public fun invoke() : R
}
public trait Function1<in P1, out R> {
public fun invoke(p1: P1) : R
}
public trait Function2<in P1, in P2, out R> {
public fun invoke(p1: P1, p2: P2) : R
}
public trait Function3<in P1, in P2, in P3, out R> {
public fun invoke(p1: P1, p2: P2, p3: P3) : R
}
public trait Function4<in P1, in P2, in P3, in P4, out R> {
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
}
public trait Function5<in P1, in P2, in P3, in P4, in P5, out R> {
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
}
public trait Function6<in P1, in P2, in P3, in P4, in P5, in P6, out R> {
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
}
public trait Function7<in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> {
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
}
public trait Function8<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> {
public fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
}
public trait Function9<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> {
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
}
@@ -0,0 +1,6 @@
package jet
/**
* Nothing has no instances
*/
public class Nothing private () {}
+4
View File
@@ -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.
+28
View File
@@ -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<out T1>(public val _1: T1) {}
public class Tuple2<out T1, out T2>(public val _1: T1, public val _2: T2) {}
public class Tuple3<out T1, out T2, out T3>(public val _1: T1, public val _2: T2, public val _3: T3) {}
public class Tuple4<out T1, out T2, out T3, out T4>(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4) {}
public class Tuple5<out T1, out T2, out T3, out T4, out T5>(public val _1: T1, public val _2: T2, public val _3: T3, public val _4: T4, public val _5: T5) {}
public class Tuple6<out T1, out T2, out T3, out T4, out T5, out T6>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19, out T20>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19, out T20, out T21>(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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19, out T20, out T21, out T22>(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) {}
@@ -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<in T, out R> {
fun T.invoke() : R
}
trait Function1<in T, in P1, out R> {
fun T.invoke(p1: P1) : R
}
trait Function2<in T, in P1, in P2, out R> {
fun T.invoke(p1: P1, p2: P2) : R
}
trait Function3<in T, in P1, in P2, in P3, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3) : R
}
trait Function4<in T, in P1, in P2, in P3, in P4, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
}
trait Function5<in T, in P1, in P2, in P3, in P4, in P5, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
}
trait Function6<in T, in P1, in P2, in P3, in P4, in P5, in P6, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
}
trait Function7<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
}
trait Function8<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
}
trait Function9<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> {
fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R
}
trait Function10<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> {
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<in T, in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> {
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
}
@@ -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<out R> {
fun invoke() : R
}
trait Function1<in P1, out R> {
fun invoke(p1: P1) : R
}
trait Function2<in P1, in P2, out R> {
fun invoke(p1: P1, p2: P2) : R
}
trait Function3<in P1, in P2, in P3, out R> {
fun invoke(p1: P1, p2: P2, p3: P3) : R
}
trait Function4<in P1, in P2, in P3, in P4, out R> {
fun invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R
}
trait Function5<in P1, in P2, in P3, in P4, in P5, out R> {
fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R
}
trait Function6<in P1, in P2, in P3, in P4, in P5, in P6, out R> {
fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R
}
trait Function7<in P1, in P2, in P3, in P4, in P5, in P6, in P7, out R> {
fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R
}
trait Function8<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, out R> {
fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R
}
trait Function9<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, out R> {
fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R
}
trait Function10<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, out R> {
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<in P1, in P2, in P3, in P4, in P5, in P6, in P7, in P8, in P9, in P10, in P11, in P12, in P13, in P14, in P15, in P16, in P17, in P18, in P19, in P20, in P21, in P22, out R> {
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
}
-26
View File
@@ -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<out T1>(_1: T1) {}
class Tuple2<out T1, out T2>(_1: T1, _2: T2) {}
class Tuple3<out T1, out T2, out T3>(_1: T1, _2: T2, _3: T3) {}
class Tuple4<out T1, out T2, out T3, out T4>(_1: T1, _2: T2, _3: T3, _4: T4) {}
class Tuple5<out T1, out T2, out T3, out T4, out T5>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5) {}
class Tuple6<out T1, out T2, out T3, out T4, out T5, out T6>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6) {}
class Tuple7<out T1, out T2, out T3, out T4, out T5, out T6, out T7>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7) {}
class Tuple8<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8) {}
class Tuple9<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9) {}
class Tuple10<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10) {}
class Tuple11<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11>(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11) {}
class Tuple12<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19, out T20>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19, out T20, out T21>(_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<out T1, out T2, out T3, out T4, out T5, out T6, out T7, out T8, out T9, out T10, out T11, out T12, out T13, out T14, out T15, out T16, out T17, out T18, out T19, out T20, out T21, out T22>(_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) {}
@@ -42,8 +42,8 @@ public interface ModuleConfiguration {
void addDefaultImports(@NotNull Collection<JetImportDirective> 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);
@@ -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();
}
@@ -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<SimpleFunctionDescriptor> 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<TypeParameterDescriptor> 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;
}
}
@@ -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<ConstructorDescriptor> 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<AnnotationDescriptor> 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;
}
}
@@ -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();
@@ -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<AnnotationDescriptor> annotations, @NotNull String name) {
public NamespaceDescriptorImpl(@NotNull NamespaceDescriptorParent containingDeclaration,
@NotNull List<AnnotationDescriptor> 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;
}
}
@@ -109,6 +109,9 @@ public class Visibilities {
public static final Set<Visibility> 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) {
@@ -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();
}
@@ -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;
}
@@ -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);
}
@@ -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<IElementType> tokenConsumer, boolean allowShortAnnotations) {
boolean parseModifierList(JetNodeType nodeType, @Nullable Consumer<IElementType> 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)) {
@@ -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<JetDeclaration> 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<String> parts = new ArrayList<String>();
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, ".");
}
}
@@ -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<JetDeclaration> getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
}
@@ -26,9 +26,7 @@ import java.util.List;
/**
* @author max
*/
public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner {
List<JetDeclaration> getDeclarations();
public interface JetClassOrObject extends PsiElement, PsiNameIdentifierOwner, JetDeclarationContainer {
@Nullable
JetDelegationSpecifierList getDelegationSpecifierList();
@@ -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<JetDeclaration> getDeclarations();
}
@@ -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<JetDeclaration> getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
}
@@ -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<JetDeclaration> getDeclarations() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetDeclaration.class);
}
@@ -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();
}
}
@@ -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) {
@@ -45,7 +45,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
@Override
public PsiJetClassStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
@Override
@@ -49,12 +49,12 @@ public class JetFunctionElementType extends JetStubElementType<PsiJetFunctionStu
@Override
public PsiJetFunctionStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
@Override
public JetNamedFunction createPsi(@NotNull PsiJetFunctionStub stub) {
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
@Override
@@ -54,6 +54,6 @@ public class PsiJetFileStubImpl extends PsiFileStubImpl<JetFile> 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];
}
}
@@ -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.<PsiElement>newArrayList(referenceExpression.getContainingFile());
}
return Lists.newArrayList();
}
@@ -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<JetParameter> valueParameters = function.getValueParameters();
@@ -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<JetFile, WritableScope> 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<JetObjectDeclaration, MutableClassDescriptor> 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);
}
}
@@ -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);
}
}
@@ -318,7 +318,7 @@ public class DescriptorUtils {
public static List<DeclarationDescriptor> getPathWithoutRootNsAndModule(@NotNull DeclarationDescriptor descriptor) {
List<DeclarationDescriptor> path = Lists.newArrayList();
DeclarationDescriptor current = descriptor;
for (;;) {
while (true) {
if (current instanceof NamespaceDescriptor && isRootNamespace((NamespaceDescriptor) current)) {
return Lists.reverse(path);
}
@@ -29,6 +29,8 @@ import java.util.List;
*/
public class FqNameUnsafe {
public static final String ROOT_NAME = "<root>";
@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() ? "<root>" : fqName;
return isRoot() ? ROOT_NAME : fqName;
}
@Override
@@ -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;
@@ -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, "<root>", 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, "<root>", 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() ? "<root>" : 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.<AnnotationDescriptor>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.<AnnotationDescriptor>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;
}
}
@@ -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<CallableMemberDescriptor> nonAbstractManyImpl = Lists.newArrayList();
Set<CallableMemberDescriptor> 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);
}
}
}
}
@@ -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<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap();
private JetScope rootScope;
protected final Map<JetFile, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap();
@@ -50,6 +47,13 @@ public class TopDownAnalysisContext {
private final Map<JetParameter, PropertyDescriptor> primaryConstructorParameterProperties = Maps.newHashMap();
private Map<JetDeclaration, CallableMemberDescriptor> members = null;
// File scopes - package scope extended with imports
protected final Map<JetFile, WritableScope> namespaceScopes = Maps.newHashMap();
public final Map<JetDeclarationContainer, WithDeferredResolve> forDeferredResolver = Maps.newHashMap();
public final Map<JetDeclarationContainer, JetScope> 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();
@@ -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("<dummy for object>");
TopDownAnalysisParameters topDownAnalysisParameters =
@@ -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<JetDeclarationContainer> forDeferredResolve = new LinkedList<JetDeclarationContainer>();
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<JetDeclarationContainer> 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<JetDeclarationContainer> forDeferredResolve = new ArrayList<JetDeclarationContainer>();
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<TypeParameterDescriptor>(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<out T>(val head : T, val tail : List<T>) : List<T>(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<JetClassOrObject, MutableClassDescriptor> 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.<AnnotationDescriptor>emptyList(), true);
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(), Collections.<ValueParameterDescriptor>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<JetClassOrObject, MutableClassDescriptor> 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<TypeParameterDescriptor>(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.<AnnotationDescriptor>emptyList(), true);
// TODO check set mutableClassDescriptor.getVisibility()
constructorDescriptor.initialize(Collections.<TypeParameterDescriptor>emptyList(),
Collections.<ValueParameterDescriptor>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<JetClass, MutableClassDescriptor> 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<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
@@ -292,7 +407,9 @@ public class TypeHierarchyResolver {
}
}
private static void topologicallySort(MutableClassDescriptor mutableClassDescriptor, Set<ClassDescriptor> visited, LinkedList<MutableClassDescriptor> topologicalOrder) {
private static void topologicallySort(MutableClassDescriptor mutableClassDescriptor,
Set<ClassDescriptor> visited,
LinkedList<MutableClassDescriptor> topologicalOrder) {
if (!visited.add(mutableClassDescriptor)) {
return;
}
@@ -306,7 +423,10 @@ public class TypeHierarchyResolver {
topologicalOrder.addFirst(mutableClassDescriptor);
}
private void traverseTypeHierarchy(MutableClassDescriptor currentClass, Set<ClassDescriptor> visited, Set<ClassDescriptor> beingProcessed, List<ClassDescriptor> currentPath) {
private void traverseTypeHierarchy(MutableClassDescriptor currentClass,
Set<ClassDescriptor> visited,
Set<ClassDescriptor> beingProcessed,
List<ClassDescriptor> 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<JetType> iterator = ((MutableClassDescriptor) subclassOfCurrent).getSupertypes().iterator(); iterator.hasNext(); ) {
for (Iterator<JetType> 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<ClassDescriptor> 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 {
}
}
}
}
}
@@ -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<ResolutionCandidate<D>> newCandidates = Lists.newArrayList();
for (ResolutionCandidate<D> candidate : task.getCandidates()) {
newCandidates.add(ResolutionCandidate.create(candidate.getDescriptor(), candidate.isSafeCall())); //todo check receivers are not necessary
}
ResolutionTask<D, F> newContext = new ResolutionTask<D, F>(newCandidates, task.reference, TemporaryBindingTrace.create(task.trace), task.scope, new DelegatingCall(task.call) {
ResolutionTask<D, F> newContext = new ResolutionTask<D, F>(task.getCandidates(), task.reference, TemporaryBindingTrace.create(task.trace), task.scope, new DelegatingCall(task.call) {
@NotNull
@Override
public List<JetExpression> getFunctionLiteralArguments() {
@@ -416,7 +412,7 @@ public class CallResolver {
checkTypesWithNoCallee(context.toBasic());
return;
}
checkUnknownArgumentTypes(context.toBasic(), unmappedArguments);
checkUnmappedArgumentTypes(context.toBasic(), unmappedArguments);
}
List<JetTypeProjection> jetTypeArguments = context.call.getTypeArguments();
@@ -612,8 +608,8 @@ public class CallResolver {
}
}
private void checkUnknownArgumentTypes(BasicResolutionContext context, Set<ValueArgument> unknownArguments) {
for (ValueArgument valueArgument : unknownArguments) {
private void checkUnmappedArgumentTypes(BasicResolutionContext context, Set<ValueArgument> unmappedArguments) {
for (ValueArgument valueArgument : unmappedArguments) {
JetExpression argumentExpression = valueArgument.getArgumentExpression();
if (argumentExpression != null) {
expressionTypingServices.getType(context.scope, argumentExpression, NO_EXPECTED_TYPE, context.trace);
@@ -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;
}
@@ -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<JetType> intersectedTypes;
private final int hashCode;
public IntersectionTypeConstructor(List<AnnotationDescriptor> annotations, Collection<JetType> typesToIntersect) {
super(annotations);
this.intersectedTypes = Sets.newLinkedHashSet(typesToIntersect);
this.hashCode = intersectedTypes.hashCode();
}
@NotNull
@Override
public List<TypeParameterDescriptor> 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<JetType> resultingTypes) {
StringBuilder debugName = new StringBuilder("{");
for (Iterator<JetType> 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;
}
}
@@ -193,12 +193,8 @@ public class TypeUtils {
List<AnnotationDescriptor> noAnnotations = Collections.<AnnotationDescriptor>emptyList();
TypeConstructor constructor = new TypeConstructorImpl(
null,
TypeConstructor constructor = new IntersectionTypeConstructor(
noAnnotations,
false,
makeDebugNameForIntersectionType(resultingTypes).toString(),
Collections.<TypeParameterDescriptor>emptyList(),
resultingTypes);
JetScope[] scopes = new JetScope[resultingTypes.size()];
@@ -269,20 +265,6 @@ public class TypeUtils {
}
}
private static StringBuilder makeDebugNameForIntersectionType(Iterable<JetType> resultingTypes) {
StringBuilder debugName = new StringBuilder("{");
for (Iterator<JetType> 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;
@@ -350,7 +350,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
List<JetExpression> entries = expression.getEntries();
List<JetType> types = new ArrayList<JetType>();
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<JetType> 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 {
@@ -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("<return type>") : returnType;
functionDescriptor.setReturnType(safeReturnType);
@@ -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);
}
@@ -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<JetPattern, DataFlowInfo> patternsToDataFlowInfo;
public final Map<JetPattern, List<VariableDescriptor>> 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
@@ -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<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), 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<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN,
true);
trace, scope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, true);
return expressionTypingFacade.getType(expression, context);
// return ((ExpressionTypingContext) ExpressionTyperVisitorWithNamespaces).INSTANCE.getType(expression, ExpressionTypingContext.newRootContext(semanticServices, trace, scope, DataFlowInfo.getEmpty(), TypeUtils.NO_EXPECTED_TYPE, TypeUtils.NO_EXPECTED_TYPE));
}
@@ -155,20 +149,9 @@ public class ExpressionTypingServices {
}
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, BindingTrace trace) {
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, null, trace);
}
/////////////////////////////////////////////////////////
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @Nullable JetType expectedReturnType, BindingTrace trace) {
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, DataFlowInfo.EMPTY, expectedReturnType, trace);
}
/////////////////////////////////////////////////////////
/*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, BindingTrace trace) {
checkFunctionReturnType(functionInnerScope, function, functionDescriptor, dataFlowInfo, null, trace);
}
/*package*/ void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, @Nullable JetType expectedReturnType, BindingTrace trace) {
public void checkFunctionReturnType(@NotNull JetScope functionInnerScope, @NotNull JetDeclarationWithBody function, @NotNull FunctionDescriptor functionDescriptor, @NotNull DataFlowInfo dataFlowInfo, @Nullable JetType expectedReturnType, BindingTrace trace) {
if (expectedReturnType == null) {
expectedReturnType = functionDescriptor.getReturnType();
if (!function.hasBlockBody() && !function.hasDeclaredReturnType()) {
@@ -178,7 +161,7 @@ public class ExpressionTypingServices {
checkFunctionReturnType(function, ExpressionTypingContext.newContext(
this,
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE, expectedReturnType, false
trace, functionInnerScope, dataFlowInfo, expectedReturnType != null ? expectedReturnType : NO_EXPECTED_TYPE, false
), trace);
}
@@ -190,7 +173,7 @@ public class ExpressionTypingServices {
final ExpressionTypingContext newContext =
blockBody
? context.replaceExpectedType(NO_EXPECTED_TYPE)
: context.replaceExpectedType(context.expectedReturnType == FORBIDDEN ? NO_EXPECTED_TYPE : context.expectedReturnType).replaceExpectedReturnType(FORBIDDEN);
: context;
if (function instanceof JetFunctionLiteralExpression) {
JetFunctionLiteralExpression functionLiteralExpression = (JetFunctionLiteralExpression) function;
@@ -227,7 +210,7 @@ public class ExpressionTypingServices {
expressionTypingFacade.getType(bodyExpression, ExpressionTypingContext.newContext(
this,
new HashMap<JetPattern, DataFlowInfo>(), new HashMap<JetPattern, List<VariableDescriptor>>(), new LabelResolver(),
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, FORBIDDEN, false), !function.hasBlockBody());
trace, functionInnerScope, DataFlowInfo.EMPTY, NO_EXPECTED_TYPE, false), !function.hasBlockBody());
//todo function literals
final Collection<JetExpression> returnedExpressions = Lists.newArrayList();
if (function.hasBlockBody()) {
@@ -277,7 +260,7 @@ public class ExpressionTypingServices {
}
ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(scope);
ExpressionTypingContext newContext = createContext(context, trace, scope, context.dataFlowInfo, NO_EXPECTED_TYPE, context.expectedReturnType);
ExpressionTypingContext newContext = createContext(context, trace, scope, context.dataFlowInfo, NO_EXPECTED_TYPE);
JetType result = null;
for (Iterator<? extends JetElement> iterator = block.iterator(); iterator.hasNext(); ) {
@@ -292,13 +275,13 @@ public class ExpressionTypingServices {
TemporaryBindingTrace temporaryTraceExpectingUnit = TemporaryBindingTrace.create(trace);
final boolean[] mismatch = new boolean[1];
ObservableBindingTrace errorInterceptingTrace = makeTraceInterceptingTypeMismatch(temporaryTraceExpectingUnit, statementExpression, mismatch);
newContext = createContext(newContext, errorInterceptingTrace, scope, newContext.dataFlowInfo, context.expectedType, context.expectedReturnType);
newContext = createContext(newContext, errorInterceptingTrace, scope, newContext.dataFlowInfo, context.expectedType);
result = blockLevelVisitor.getType(statementExpression, newContext, true);
if (mismatch[0]) {
TemporaryBindingTrace temporaryTraceNoExpectedType = TemporaryBindingTrace.create(trace);
mismatch[0] = false;
ObservableBindingTrace interceptingTrace = makeTraceInterceptingTypeMismatch(temporaryTraceNoExpectedType, statementExpression, mismatch);
newContext = createContext(newContext, interceptingTrace, scope, newContext.dataFlowInfo, NO_EXPECTED_TYPE, context.expectedReturnType);
newContext = createContext(newContext, interceptingTrace, scope, newContext.dataFlowInfo, NO_EXPECTED_TYPE);
result = blockLevelVisitor.getType(statementExpression, newContext, true);
if (mismatch[0]) {
temporaryTraceExpectingUnit.commit();
@@ -312,7 +295,7 @@ public class ExpressionTypingServices {
}
}
else {
newContext = createContext(newContext, trace, scope, newContext.dataFlowInfo, context.expectedType, context.expectedReturnType);
newContext = createContext(newContext, trace, scope, newContext.dataFlowInfo, context.expectedType);
result = blockLevelVisitor.getType(statementExpression, newContext, true);
}
}
@@ -347,16 +330,17 @@ public class ExpressionTypingServices {
newDataFlowInfo = context.dataFlowInfo;
}
if (newDataFlowInfo != context.dataFlowInfo) {
newContext = createContext(newContext, trace, scope, newDataFlowInfo, NO_EXPECTED_TYPE, context.expectedReturnType);
newContext = createContext(newContext, trace, scope, newDataFlowInfo, NO_EXPECTED_TYPE);
}
blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(scope);
}
return result;
}
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType, JetType expectedReturnType) {
private ExpressionTypingContext createContext(ExpressionTypingContext oldContext, BindingTrace trace, WritableScope scope, DataFlowInfo dataFlowInfo, JetType expectedType) {
return ExpressionTypingContext.newContext(
this, oldContext.patternsToDataFlowInfo, oldContext.patternsToBoundVariableLists, oldContext.labelResolver, trace, scope, dataFlowInfo, expectedType, expectedReturnType, oldContext.namespacesAllowed);
this, oldContext.patternsToDataFlowInfo, oldContext.patternsToBoundVariableLists, oldContext.labelResolver,
trace, scope, dataFlowInfo, expectedType, oldContext.namespacesAllowed);
}
private ObservableBindingTrace makeTraceInterceptingTypeMismatch(final BindingTrace trace, final JetExpression expressionToWatch, final boolean[] mismatchFound) {
@@ -163,7 +163,6 @@ public class ExpressionTypingUtils {
scope,
DataFlowInfo.EMPTY,
TypeUtils.NO_EXPECTED_TYPE,
TypeUtils.NO_EXPECTED_TYPE,
false
);
return ControlStructureTypingVisitor.checkIterableConvention(expressionReceiver, context) != null;
@@ -25,11 +25,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResultsUtil;
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
@@ -132,7 +128,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
SimpleFunctionDescriptor functionDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function, context.trace);
scope.addFunctionDescriptor(functionDescriptor);
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
context.expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo, context.trace);
context.expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo, null, context.trace);
return DataFlowUtils.checkStatementType(function, context);
}
@@ -174,7 +170,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
//There is a temporary binding trace for an opportunity to resolve set method for array if needed (the initial trace should be used there)
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(contextWithExpectedType.trace);
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE).replaceBindingTrace(temporaryBindingTrace);
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceBindingTrace(temporaryBindingTrace);
JetSimpleNameExpression operationSign = expression.getOperationReference();
IElementType operationType = operationSign.getReferencedNameElementType();
@@ -234,7 +230,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
}
protected JetType visitAssignment(JetBinaryExpression expression, ExpressionTypingContext contextWithExpectedType) {
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceExpectedReturnType(TypeUtils.NO_EXPECTED_TYPE);
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE);
JetExpression left = JetPsiUtil.deparenthesize(expression.getLeft());
JetExpression right = expression.getRight();
if (left instanceof JetArrayAccessExpression) {
@@ -77,7 +77,9 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
// TODO :change scope according to the bound value in the when header
final JetExpression subjectExpression = expression.getSubjectExpression();
final JetType subjectType = subjectExpression != null ? context.expressionTypingServices.safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE, context.trace) : ErrorUtils.createErrorType("Unknown type");
final JetType subjectType = subjectExpression != null
? context.expressionTypingServices.safeGetType(context.scope, subjectExpression, TypeUtils.NO_EXPECTED_TYPE, context.dataFlowInfo, context.trace)
: ErrorUtils.createErrorType("Unknown type");
final DataFlowValue variableDescriptor = subjectExpression != null ? DataFlowValueFactory.INSTANCE.createDataFlowValue(subjectExpression, subjectType, context.trace.getBindingContext()) : DataFlowValue.NULL;
// TODO : exhaustive patterns
@@ -18,23 +18,17 @@ package org.jetbrains.jet.lang.types.lang;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
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.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.scopes.*;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeImpl;
import org.jetbrains.jet.lang.types.NamespaceType;
import org.jetbrains.jet.lang.types.TypeConstructor;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lang.types.Variance;
import org.jetbrains.jet.lang.types.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -52,13 +46,23 @@ public class JetStandardClasses {
public static final ModuleDescriptor FAKE_STANDARD_CLASSES_MODULE = new ModuleDescriptor("<builtin>");
private static final NamespaceDescriptorImpl STANDARD_CLASSES_FAKE_ROOT_NS = new NamespaceDescriptorImpl(FAKE_STANDARD_CLASSES_MODULE, Collections.<AnnotationDescriptor>emptyList(), "<root>");
private static final NamespaceDescriptorImpl STANDARD_CLASSES_FAKE_ROOT_NS = new NamespaceDescriptorImpl(
FAKE_STANDARD_CLASSES_MODULE, Collections.<AnnotationDescriptor>emptyList(), FqNameUnsafe.ROOT_NAME);
static {
FAKE_STANDARD_CLASSES_MODULE.setRootNs(STANDARD_CLASSES_FAKE_ROOT_NS);
//WritableScopeImpl writableScope =
// new WritableScopeImpl(JetScope.EMPTY, FAKE_STANDARD_CLASSES_MODULE, RedeclarationHandler.DO_NOTHING);
//STANDARD_CLASSES_FAKE_ROOT_NS.initialize(writableScope);
//STANDARD_CLASSES_FAKE_ROOT_NS.getMemberScope().changeLockLevel(WritableScope.LockLevel.BOTH);
}
public static NamespaceDescriptorImpl STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptorImpl(STANDARD_CLASSES_FAKE_ROOT_NS, Collections.<AnnotationDescriptor>emptyList(), "jet");
public static NamespaceDescriptorImpl STANDARD_CLASSES_NAMESPACE = new NamespaceDescriptorImpl(
STANDARD_CLASSES_FAKE_ROOT_NS, Collections.<AnnotationDescriptor>emptyList(), "jet");
//
//static {
// STANDARD_CLASSES_FAKE_ROOT_NS.getMemberScope().addNamespace(STANDARD_CLASSES_NAMESPACE);
//}
public static final FqName STANDARD_CLASSES_FQNAME = DescriptorUtils.getFQName(STANDARD_CLASSES_NAMESPACE).toSafe();
@@ -232,11 +236,11 @@ public class JetStandardClasses {
private static List<TypeParameterDescriptor> createTypeParameters(int parameterCount, ClassDescriptorImpl function) {
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
for (int j = 0; j < parameterCount; j++) {
for (int j = 1; j <= parameterCount; j++) {
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
function,
Collections.<AnnotationDescriptor>emptyList(),
true, Variance.IN_VARIANCE, "P" + j, j + 1));
true, Variance.IN_VARIANCE, "P" + j, j));
}
parameters.add(TypeParameterDescriptor.createWithDefaultBound(
function,
@@ -254,12 +258,14 @@ public class JetStandardClasses {
@NotNull
public static final JetScope STANDARD_CLASSES;
public static final String UNIT_ALIAS = "Unit";
static {
WritableScope writableScope = new WritableScopeImpl(JetScope.EMPTY, STANDARD_CLASSES_NAMESPACE, RedeclarationHandler.DO_NOTHING).setDebugName("JetStandardClasses.STANDARD_CLASSES");
writableScope.changeLockLevel(WritableScope.LockLevel.BOTH);
STANDARD_CLASSES = writableScope;
writableScope.addClassifierAlias("Unit", getTuple(0));
writableScope.addClassifierAlias(UNIT_ALIAS, getTuple(0));
Field[] declaredFields = JetStandardClasses.class.getDeclaredFields();
for (Field field : declaredFields) {
@@ -458,14 +464,13 @@ public class JetStandardClasses {
@NotNull
public static List<ValueParameterDescriptor> getValueParameters(@NotNull FunctionDescriptor functionDescriptor, @NotNull JetType type) {
assert isFunctionType(type);
int receiverOffset = getReceiverType(type) != null ? 1 : 0;
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
List<TypeProjection> parameterTypes = getParameterTypeProjectionsFromFunctionType(type);
for (int i = 0; i < parameterTypes.size(); i++) {
TypeProjection parameterType = parameterTypes.get(i);
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(
functionDescriptor, i, Collections.<AnnotationDescriptor>emptyList(),
"p" + (i + receiverOffset), false, parameterType.getType(), false, null);
"p" + (i + 1), false, parameterType.getType(), false, null);
valueParameters.add(valueParameterDescriptor);
}
return valueParameters;
@@ -80,7 +80,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
private final DeclarationDescriptorVisitor<Void, StringBuilder> subVisitor = new RenderDeclarationDescriptorVisitor() {
@Override
public Void visitTypeParameterDescriptor(TypeParameterDescriptor descriptor, StringBuilder builder) {
renderTypeParameter(descriptor, builder);
renderTypeParameter(descriptor, builder, false);
return null;
}
@@ -118,7 +118,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
return escape("[NULL]");
}
else if (JetStandardClasses.isUnit(type)) {
return escape("Unit" + (type.isNullable() ? "?" : ""));
return escape(JetStandardClasses.UNIT_ALIAS + (type.isNullable() ? "?" : ""));
}
else if (JetStandardClasses.isTupleType(type)) {
return escape(renderTupleType(type, shortNamesOnly));
@@ -306,7 +306,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
type);
renderName(descriptor, builder);
builder.append(" : ").append(escape(typeString));
return super.visitVariableDescriptor(descriptor, builder);
return null;
}
private String renderPropertyPrefixAndComputeTypeString(
@@ -388,7 +388,8 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
renderName(descriptor, builder);
renderValueParameters(descriptor, builder);
builder.append(" : ").append(escape(renderType(descriptor.getReturnType())));
return super.visitFunctionDescriptor(descriptor, builder);
renderWhereSuffix(descriptor, builder);
return null;
}
private void renderValueParameters(FunctionDescriptor descriptor, StringBuilder builder) {
@@ -403,6 +404,28 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
builder.append(")");
}
private void renderWhereSuffix(@NotNull CallableMemberDescriptor callable, @NotNull StringBuilder builder) {
boolean first = true;
for (TypeParameterDescriptor typeParameter : callable.getTypeParameters()) {
if (typeParameter.getUpperBounds().size() > 1) {
for (JetType upperBound : typeParameter.getUpperBounds()) {
if (first) {
builder.append(" ");
builder.append(renderKeyword("where"));
builder.append(" ");
}
else {
builder.append(", ");
}
builder.append(typeParameter.getName());
builder.append(" : ");
builder.append(escape(renderType(upperBound)));
first = false;
}
}
}
}
@Override
public Void visitConstructorDescriptor(ConstructorDescriptor constructorDescriptor, StringBuilder builder) {
builder.append(renderKeyword("ctor")).append(" ");
@@ -434,16 +457,16 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
@Override
public Void visitTypeParameterDescriptor(TypeParameterDescriptor descriptor, StringBuilder builder) {
builder.append(lt());
renderTypeParameter(descriptor, builder);
renderTypeParameter(descriptor, builder, true);
builder.append(">");
return super.visitTypeParameterDescriptor(descriptor, builder);
return null;
}
@Override
public Void visitNamespaceDescriptor(NamespaceDescriptor namespaceDescriptor, StringBuilder builder) {
builder.append(renderKeyword(JetTokens.PACKAGE_KEYWORD.getValue())).append(" ");
renderName(namespaceDescriptor, builder);
return super.visitNamespaceDescriptor(namespaceDescriptor, builder);
return null;
}
@Override
@@ -466,7 +489,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
keyword = "class";
}
renderClassDescriptor(descriptor, builder, keyword);
return super.visitClassDescriptor(descriptor, builder);
return null;
}
private boolean isClassObjectDescriptor(ClassDescriptor descriptor) {
@@ -513,7 +536,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
stringBuilder.append(escape(descriptor.getName()));
}
protected void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder) {
protected void renderTypeParameter(TypeParameterDescriptor descriptor, StringBuilder builder, boolean topLevel) {
if (descriptor.isReified()) {
String variance = descriptor.getVariance().toString();
if (!variance.isEmpty()) {
@@ -524,15 +547,31 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
builder.append(renderKeyword("erased")).append(" ");
}
renderName(descriptor, builder);
if (!descriptor.getUpperBounds().isEmpty()) {
JetType bound = descriptor.getUpperBounds().iterator().next();
if (bound != JetStandardClasses.getDefaultBound()) {
builder.append(" : ").append(renderType(bound));
if (descriptor.getUpperBounds().size() > 1) {
builder.append(" (...)");
}
if (descriptor.getUpperBounds().size() == 1) {
JetType upperBound = descriptor.getUpperBounds().iterator().next();
if (upperBound != JetStandardClasses.getDefaultBound()) {
builder.append(" : ").append(renderType(upperBound));
}
}
else if (topLevel) {
boolean first = true;
for (JetType upperBound : descriptor.getUpperBounds()) {
if (upperBound.equals(JetStandardClasses.getDefaultBound())) {
continue;
}
if (first) {
builder.append(" : ");
}
else {
builder.append(" & ");
}
builder.append(renderType(upperBound));
first = false;
}
}
else {
// rendered with "where"
}
}
}
}
@@ -1,5 +1,5 @@
package Hello
fun main(args : Array<String>) {
System.out?.println("Hello!")
System.out.println("Hello!")
}
@@ -1,5 +1,5 @@
package Hello
fun main(args : Array<String>) {
System.out?.println("Hello!")
System.out.println("Hello!")
}
@@ -4,8 +4,8 @@ OUT -src [String] source file or directory
OUT -classpath [String] classpath to use when compiling
OUT -includeRuntime [flag]
OUT -stdlib [String] Path to the stdlib.jar
OUT -jdkHeaders [String] Path to the kotlin-jdk-headers.jar
OUT -mode [String] Special compiler modes: stubs or jdkHeaders
OUT -altHeaders [String] Path to the alternative library headers paths
OUT -mode [String] Special compiler modes: stubs or altHeaders
OUT -output [String] output directory
OUT -module [String] module to compile
OUT -tags [flag]
@@ -29,6 +29,26 @@ error:
sink:
<SINK> NEXT:[] PREV:[<END>]
=====================
== O ==
object O {
val x : Int
{
$x = 1
}
}
---------------------
l0:
<START> NEXT:[v(val x : Int)] PREV:[]
v(val x : Int) NEXT:[r(1)] PREV:[<START>]
r(1) NEXT:[w($x)] PREV:[v(val x : Int)]
w($x) NEXT:[<END>] PREV:[r(1)]
l1:
<END> NEXT:[<SINK>] PREV:[w($x)]
error:
<ERROR> NEXT:[] PREV:[]
sink:
<SINK> NEXT:[] PREV:[<END>]
=====================
== null ==
object {
val x : Int
@@ -56,26 +76,6 @@ error:
sink:
<SINK> NEXT:[] PREV:[<END>]
=====================
== O ==
object O {
val x : Int
{
$x = 1
}
}
---------------------
l0:
<START> NEXT:[v(val x : Int)] PREV:[]
v(val x : Int) NEXT:[r(1)] PREV:[<START>]
r(1) NEXT:[w($x)] PREV:[v(val x : Int)]
w($x) NEXT:[<END>] PREV:[r(1)]
l1:
<END> NEXT:[<SINK>] PREV:[w($x)]
error:
<ERROR> NEXT:[] PREV:[]
sink:
<SINK> NEXT:[] PREV:[<END>]
=====================
== doSmth ==
fun doSmth(i: Int) {}
---------------------
@@ -151,9 +151,9 @@ fun html(init : HTML.() -> Unit) : HTML {
fun <K, V> Map<K, V>.set(key : K, value : V) = this.put(key, value)
fun println(message : Any?) {
System.out?.println(message)
System.out.println(message)
}
fun print(message : Any?) {
System.out?.print(message)
System.out.print(message)
}
@@ -26,6 +26,6 @@ val d = b.<!UNRESOLVED_REFERENCE!>x<!>
val s = <!NO_CLASS_OBJECT!>System<!> // error
fun test() {
System.out?.println()
java.lang.System.out?.println()
System.out.println()
java.lang.System.out.println()
}
@@ -8,8 +8,8 @@ fun test() {
a?.plus(1)
}
val out : java.io.PrintStream? = null//= System.out
val ins = System.`in`
val out : java.io.PrintStream? = null
val ins : java.io.InputStream? = null
out?.println()
ins?.read()
@@ -35,7 +35,7 @@ fun test(<!UNUSED_PARAMETER!>l<!> : java.util.List<Int>) {
// ...
}
catch(e: Exception) {
System.out?.println(e.getMessage())
System.out.println(e.getMessage())
}
PrintStream("sdf")
@@ -22,10 +22,10 @@ fun main(args : Array<String>) {
test(al, m)
}
fun test(a : List<Int>, m : Map<String, Int>) {
System.out?.println(
System.out.println(
a.get(0) + 1
)
HashMap<Int, Int>().get(0)
if (m.get("") != null)
System.out?.println(m.get("").sure().plus(1))
System.out.println(m.get("").sure().plus(1))
}
@@ -1,8 +1,28 @@
//KT-1897 When call cannot be resolved to any function, save information about types of arguments
package a
fun foo(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String) {
}
fun bar() {}
fun foo(<!UNUSED_PARAMETER!>i<!>: Int, <!UNUSED_PARAMETER!>s<!>: String) {}
fun test() {
bar(<!TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE!>xx<!>)
bar <!TOO_MANY_ARGUMENTS, DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED!>{ }<!>
foo(<!TYPE_MISMATCH!>""<!>, <!ERROR_COMPILE_TIME_VALUE!>1<!>, <!TOO_MANY_ARGUMENTS, UNRESOLVED_REFERENCE!>xx<!>)
foo(<!NAMED_PARAMETER_NOT_FOUND!>r<!> = <!UNRESOLVED_REFERENCE!>xx<!>, i = <!TYPE_MISMATCH!>""<!>, s = "")
foo(i = 1, <!ARGUMENT_PASSED_TWICE!>i<!> = 1, s = <!ERROR_COMPILE_TIME_VALUE!>11<!>)
foo(<!TYPE_MISMATCH!>""<!>, <!MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>s<!> = <!ERROR_COMPILE_TIME_VALUE!>2<!>)
foo(i = <!TYPE_MISMATCH!>""<!>, s = <!ERROR_COMPILE_TIME_VALUE!>2<!>, <!MIXING_NAMED_AND_POSITIONED_ARGUMENTS!>33<!>)
foo(<!TYPE_MISMATCH!>""<!>, <!ERROR_COMPILE_TIME_VALUE!>1<!>) <!TOO_MANY_ARGUMENTS!>{}<!>
foo(<!TYPE_MISMATCH!>""<!>, <!ERROR_COMPILE_TIME_VALUE!>1<!>) <!TOO_MANY_ARGUMENTS!>{}<!> <!MANY_FUNCTION_LITERAL_ARGUMENTS!>{}<!>
}
@@ -3,5 +3,5 @@
fun foo(maybe: Int?) {
val i : Int = maybe ?: throw RuntimeException("No value")
System.out?.println(i)
System.out.println(i)
}
@@ -15,7 +15,7 @@ fun foo(){
}
bar()
System.out?.println(local)
System.out.println(local)
}
fun <T> Iterable<T>.foreach(operation: (element: T) -> Unit) {
@@ -0,0 +1,51 @@
package kt1977
//KT-1977 Wrong 'unused expression' in catch
fun strToInt(s : String) : Int? =
try {
Integer.parseInt(s)
} catch(e : NumberFormatException) {
null
}
//more tests
fun test1(s : String) : Int? {
return try {
<!UNUSED_EXPRESSION!>88<!>
Integer.parseInt(s)
22
}
catch (e: NumberFormatException) {
44
}
finally {
<!UNUSED_EXPRESSION!>22<!>
}
}
fun test2(s : String) : Int? {
return try {
<!UNUSED_EXPRESSION!>88<!>
Integer.parseInt(s)
22
} finally {
<!UNUSED_FUNCTION_LITERAL!>{
(x : Int) -> x
}<!>
}
}
//KT-2015 False "Expression is unused" warnings
fun foo() {
val <!UNUSED_VARIABLE!>i<!> : Int = try{
bar()
1
}
catch(e : Exception){
0
}
}
fun bar() {
}
@@ -9,7 +9,7 @@ fun main(args : Array<String>) {
2 -> i = 2 // i is surrounded by a black border
else -> <!UNRESOLVED_REFERENCE!>j<!> = 2
}
System.out?.println(i)
System.out.println(i)
}
//KT-351 Distinguish statement and expression positions
@@ -0,0 +1,27 @@
package a
fun foo() : Int {
try {
doSmth()
}
catch (e: Exception) {
<!UNREACHABLE_CODE!>return <!TYPE_MISMATCH!>""<!><!>
}
finally {
return <!TYPE_MISMATCH!>""<!>
}
}
fun bar() : Int =
try {
<!TYPE_MISMATCH!>doSmth()<!>
}
catch (e: Exception) {
<!TYPE_MISMATCH!>""<!>
}
finally {
<!UNUSED_EXPRESSION!>""<!>
}
fun doSmth() {}
@@ -0,0 +1,7 @@
class C(val f : () -> Unit)
fun test(e : Any) {
if (e is C) {
(e.f)()
}
}
@@ -0,0 +1,7 @@
class C(val f : Int)
fun test(e : Any) {
if (e is C) {
#(e.f)
}
}
@@ -0,0 +1,10 @@
trait Expr
class BinOp(val operator : String) : Expr
fun test(e : Expr) {
if (e is BinOp) {
when (e.operator) {
else -> 0
}
}
}
@@ -57,7 +57,7 @@ import outer.*
fun main(args: Array<String>) {
System.out?.print(1)
System.out.print(1)
val command = parse("")
@@ -23,6 +23,6 @@ fun <T : Any> T?.iterator() = object {
fun main(args : Array<String>) {
val i : Int? = 1
for (x in i) {
System.out?.println(x)
System.out.println(x)
}
}
@@ -0,0 +1,8 @@
//KT-1955 Half a file is red on incomplete code
package b
fun foo() {
val <!UNUSED_VARIABLE!>a<!> = 1<!SYNTAX!><!>
@@ -0,0 +1,12 @@
// FILE: Aaa.java
// http://youtrack.jetbrains.com/issue/KT-1694
public abstract class Aaa {
public abstract void foo(String... args);
}
// FILE: bbb.kt
class Bbb() : Aaa() {
override fun foo(vararg args: String?) = #()
}
@@ -7,7 +7,7 @@ fun f(s: String?) {
if (s != null) {
s.length //ok
var <!UNUSED_VARIABLE!>i<!> = s.length //error: Only safe calls are allowed on a nullable receiver
System.out?.println(s.length) //error
System.out.println(s.length) //error
}
}
@@ -0,0 +1,15 @@
trait Foo
trait Bar
trait A {
fun <T> foo()
where T : Foo, T : Bar
= #()
}
class B : A {
override fun <T> foo()
where T : Foo, T : Bar
= #()
}
@@ -5,5 +5,5 @@ class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>A<!> : (Int) -> Int {
}
class B : Function1<Int, Int> {
override fun invoke(p0 : Int) = p0
override fun invoke(p1 : Int) = p1
}
@@ -6,5 +6,5 @@ trait Y {
fun foo(a : Int = 1)
}
class <!MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE!>Z1<!> : X, Y {} // BUG
object <!MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE!>Z1O<!> : X, Y {} // BUG
class <!ABSTRACT_MEMBER_NOT_IMPLEMENTED, MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE!>Z1<!> : X, Y {} // BUG
object <!ABSTRACT_MEMBER_NOT_IMPLEMENTED, MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE!>Z1O<!> : X, Y {} // BUG

Some files were not shown because too many files have changed in this diff Show More