Merge remote-tracking branch 'origin/master'
Conflicts: build-tools/core/src/org/jetbrains/jet/buildtools/core/BytecodeCompiler.java compiler/cli/src/org/jetbrains/jet/cli/jvm/K2JVMCompiler.java compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/CompileEnvironmentConfiguration.java compiler/cli/src/org/jetbrains/jet/cli/jvm/compiler/JetCoreEnvironment.java compiler/tests/org/jetbrains/jet/JetTestUtils.java compiler/tests/org/jetbrains/jet/codegen/CompileTextTest.java
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ patches-master
|
|||||||
out
|
out
|
||||||
dist
|
dist
|
||||||
ideaSDK
|
ideaSDK
|
||||||
PluginVerifier
|
dependencies
|
||||||
.idea/dictionaries/yozh.xml
|
.idea/dictionaries/yozh.xml
|
||||||
.idea/workspace.xml
|
.idea/workspace.xml
|
||||||
tmp
|
tmp
|
||||||
|
|||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
<component name="ProjectRunConfigurationManager">
|
||||||
|
<configuration default="false" name="Integration Tests" type="JUnit" factoryName="JUnit">
|
||||||
|
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea">
|
||||||
|
<pattern>
|
||||||
|
<option name="PATTERN" value="org.jetbrains.jet.*" />
|
||||||
|
<option name="ENABLED" value="true" />
|
||||||
|
</pattern>
|
||||||
|
</extension>
|
||||||
|
<module name="compiler-integration-tests" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
|
||||||
|
<option name="ALTERNATIVE_JRE_PATH" value="" />
|
||||||
|
<option name="PACKAGE_NAME" value="org.jetbrains.kotlin" />
|
||||||
|
<option name="MAIN_CLASS_NAME" value="" />
|
||||||
|
<option name="METHOD_NAME" value="" />
|
||||||
|
<option name="TEST_OBJECT" value="package" />
|
||||||
|
<option name="VM_PARAMETERS" value="-ea -XX:+HeapDumpOnOutOfMemoryError -Xmx350m -XX:MaxPermSize=320m" />
|
||||||
|
<option name="PARAMETERS" value="" />
|
||||||
|
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
|
||||||
|
<option name="ENV_VARIABLES" />
|
||||||
|
<option name="PASS_PARENT_ENVS" value="true" />
|
||||||
|
<option name="TEST_SEARCH_SCOPE">
|
||||||
|
<value defaultName="moduleWithDependencies" />
|
||||||
|
</option>
|
||||||
|
<envs />
|
||||||
|
<patterns />
|
||||||
|
<RunnerSettings RunnerId="Profile ">
|
||||||
|
<option name="myExternalizedOptions" value=" additional-options2=onexit\=snapshot " />
|
||||||
|
</RunnerSettings>
|
||||||
|
<RunnerSettings RunnerId="Run" />
|
||||||
|
<ConfigurationWrapper RunnerId="Run" />
|
||||||
|
<method />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
<property name="compiler.version.java.bk" value="${compiler.version.java}.bk"/>
|
<property name="compiler.version.java.bk" value="${compiler.version.java}.bk"/>
|
||||||
<property name="compiler.version.java.versioned" value="${compiler.version.java}.versioned" />
|
<property name="compiler.version.java.versioned" value="${compiler.version.java}.versioned" />
|
||||||
|
|
||||||
<property name="plugin.verifier" value="${basedir}/PluginVerifier/plugin-verifier-1.0-SNAPSHOT.jar"/>
|
<property name="plugin.verifier" value="${basedir}/dependencies/plugin-verifier.jar"/>
|
||||||
<property name="plugin.zip" value="${artifact.output.path}/kotlin-plugin-${build.number}.zip" />
|
<property name="plugin.zip" value="${artifact.output.path}/kotlin-plugin-${build.number}.zip" />
|
||||||
|
|
||||||
<macrodef name="echoprop">
|
<macrodef name="echoprop">
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ classpath="$classpath:$root/out/production/stdlib"
|
|||||||
classpath="$classpath:$root/lib/*:$ideaRoot/lib/*:$ideaRoot/lib/rt/*"
|
classpath="$classpath:$root/lib/*:$ideaRoot/lib/*:$ideaRoot/lib/rt/*"
|
||||||
|
|
||||||
exec java $JAVA_OPTS \
|
exec java $JAVA_OPTS \
|
||||||
|
-ea \
|
||||||
-classpath "$classpath" \
|
-classpath "$classpath" \
|
||||||
org.jetbrains.jet.cli.jvm.K2JVMCompiler \
|
org.jetbrains.jet.cli.jvm.K2JVMCompiler \
|
||||||
"$@"
|
"$@"
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ public class BytecodeCompiler {
|
|||||||
*/
|
*/
|
||||||
private CompileEnvironmentConfiguration env( String stdlib, String[] classpath ) {
|
private CompileEnvironmentConfiguration env( String stdlib, String[] classpath ) {
|
||||||
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
CompilerDependencies dependencies = CompilerDependencies.compilerDependenciesForProduction(CompilerSpecialMode.REGULAR);
|
||||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
||||||
CompileEnvironmentConfiguration env = new CompileEnvironmentConfiguration(environment, dependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
CompileEnvironmentConfiguration env = new CompileEnvironmentConfiguration(environment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||||
|
|
||||||
if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) {
|
if (( stdlib != null ) && ( stdlib.trim().length() > 0 )) {
|
||||||
File file = new File(stdlib);
|
File file = new File(stdlib);
|
||||||
|
|||||||
@@ -170,9 +170,12 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jarjar">
|
<target name="jarjar">
|
||||||
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="${basedir}/build/jarjar-1.2.jar"/>
|
<taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="${basedir}/dependencies/jarjar.jar"/>
|
||||||
|
<taskdef resource="proguard/ant/task.properties" classpath="${basedir}/dependencies/proguard.jar"/>
|
||||||
|
|
||||||
<jarjar jarfile="${output}/kotlin-compiler-tmp.jar">
|
<!-- JarJar Kotlin compiler & dependencies -->
|
||||||
|
<delete file="${output}/kotlin-compiler-jarjar.jar" failonerror="false"/>
|
||||||
|
<jarjar jarfile="${output}/kotlin-compiler-jarjar.jar">
|
||||||
<fileset dir="${output}/classes/compiler"/>
|
<fileset dir="${output}/classes/compiler"/>
|
||||||
<fileset dir="${output}/classes/runtime"/>
|
<fileset dir="${output}/classes/runtime"/>
|
||||||
<fileset dir="${basedir}/compiler/frontend/src" includes="jet/**"/>
|
<fileset dir="${basedir}/compiler/frontend/src" includes="jet/**"/>
|
||||||
@@ -180,7 +183,24 @@
|
|||||||
<zipgroupfileset dir="${basedir}/lib" includes="*.jar"/>
|
<zipgroupfileset dir="${basedir}/lib" includes="*.jar"/>
|
||||||
<zipgroupfileset dir="${basedir}/ideaSDK/core" includes="*.jar"/>
|
<zipgroupfileset dir="${basedir}/ideaSDK/core" includes="*.jar"/>
|
||||||
|
|
||||||
|
<zap pattern="com.thoughtworks.xstream.converters.extended.ISO8601*"/>
|
||||||
|
<zap pattern="com.thoughtworks.xstream.converters.reflection.CGLIBEnhancedConverter*"/>
|
||||||
|
<zap pattern="com.thoughtworks.xstream.io.xml.Dom4J*"/>
|
||||||
|
<zap pattern="com.thoughtworks.xstream.io.xml.Xom*"/>
|
||||||
|
<zap pattern="com.thoughtworks.xstream.mapper.CGLIBMapper*"/>
|
||||||
|
|
||||||
|
<zap pattern="org.apache.log4j.jmx.Agent"/>
|
||||||
|
<zap pattern="org.apache.log4j.net.JMS*"/>
|
||||||
|
<zap pattern="org.apache.log4j.net.SMTP*"/>
|
||||||
|
<zap pattern="org.apache.log4j.or.jms.MessageRenderer"/>
|
||||||
|
|
||||||
|
<zap pattern="org.jdom.xpath.Jaxen*"/>
|
||||||
|
|
||||||
<rule pattern="com.intellij.**" result="kotlinc.internal.com.intellij.@1"/>
|
<rule pattern="com.intellij.**" result="kotlinc.internal.com.intellij.@1"/>
|
||||||
|
<rule pattern="com.sun.jna.**" result="kotlinc.internal.com.sun.jna.@1"/>
|
||||||
|
<rule pattern="org.apache.log4j.**" result="kotlinc.internal.org.apache.log4j.@1"/>
|
||||||
|
<rule pattern="org.jdom.**" result="kotlinc.internal.org.jdom.@1"/>
|
||||||
|
<rule pattern="JDOMAbout**" result="kotlinc.internal.org.jdom.JDOMAbout@1"/>
|
||||||
<rule pattern="org.intellij.lang.annotations.**" result="kotlinc.internal.org.intellij.lang.annotations.@1"/>
|
<rule pattern="org.intellij.lang.annotations.**" result="kotlinc.internal.org.intellij.lang.annotations.@1"/>
|
||||||
<rule pattern="org.jetbrains.annotations.**" result="kotlinc.internal.org.jetbrains.annotations.@1"/>
|
<rule pattern="org.jetbrains.annotations.**" result="kotlinc.internal.org.jetbrains.annotations.@1"/>
|
||||||
<rule pattern="com.google.**" result="kotlinc.internal.com.google.@1"/>
|
<rule pattern="com.google.**" result="kotlinc.internal.com.google.@1"/>
|
||||||
@@ -193,11 +213,13 @@
|
|||||||
|
|
||||||
<delete failonerror="false" dir="${output}/kotlin-compiler.exploded"/>
|
<delete failonerror="false" dir="${output}/kotlin-compiler.exploded"/>
|
||||||
<mkdir dir="${output}/kotlin-compiler.exploded"/>
|
<mkdir dir="${output}/kotlin-compiler.exploded"/>
|
||||||
|
<unzip src="${output}/kotlin-compiler-jarjar.jar" dest="${output}/kotlin-compiler.exploded"/>
|
||||||
|
|
||||||
<unzip src="${output}/kotlin-compiler-tmp.jar" dest="${output}/kotlin-compiler.exploded"/>
|
<delete file="${output}/kotlin-compiler-jarjar.jar"/>
|
||||||
<delete file="${output}/kotlin-compiler-tmp.jar"/>
|
|
||||||
|
|
||||||
<jar jarfile="${output}/kotlin-compiler-standalone.jar">
|
<!-- Clean JarJar result -->
|
||||||
|
<delete file="${output}/kotlin-compiler-clean.jar" failonerror="false"/>
|
||||||
|
<jar jarfile="${output}/kotlin-compiler-clean.jar">
|
||||||
<fileset dir="${output}/kotlin-compiler.exploded">
|
<fileset dir="${output}/kotlin-compiler.exploded">
|
||||||
<include name="**/*.class"/>
|
<include name="**/*.class"/>
|
||||||
<include name="**/*.jet"/>
|
<include name="**/*.jet"/>
|
||||||
@@ -217,8 +239,57 @@
|
|||||||
<attribute name="Main-Class" value="org.jetbrains.jet.cli.jvm.K2JVMCompiler"/>
|
<attribute name="Main-Class" value="org.jetbrains.jet.cli.jvm.K2JVMCompiler"/>
|
||||||
</manifest>
|
</manifest>
|
||||||
</jar>
|
</jar>
|
||||||
|
|
||||||
<delete dir="${output}/kotlin-compiler.exploded" />
|
<delete dir="${output}/kotlin-compiler.exploded" />
|
||||||
|
|
||||||
|
<available property="rtjar" value="${java.home}/lib/rt.jar" file="${java.home}/lib/rt.jar" />
|
||||||
|
<available property="rtjar" value="${java.home}/../Classes/classes.jar" file="${java.home}/../Classes/classes.jar" />
|
||||||
|
|
||||||
|
<delete file="${output}/kotlin-compiler.jar" failonerror="false"/>
|
||||||
|
<proguard><![CDATA[
|
||||||
|
-injars '${output}/kotlin-compiler-clean.jar'
|
||||||
|
-outjars '${output}/kotlin-compiler.jar'
|
||||||
|
|
||||||
|
-libraryjars '${rtjar}'
|
||||||
|
|
||||||
|
-target 1.6
|
||||||
|
-dontoptimize
|
||||||
|
-dontobfuscate
|
||||||
|
|
||||||
|
# Keep application classes, along with their 'main' methods.
|
||||||
|
-keepclasseswithmembers public class * {
|
||||||
|
public static void main(java.lang.String[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclasseswithmembers class * {
|
||||||
|
# Various dynamically called methods
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
void dispose();
|
||||||
|
** getFileSystem();
|
||||||
|
** isVarArgs();
|
||||||
|
** getApplication();
|
||||||
|
** executeOnPooledThread(java.lang.Runnable);
|
||||||
|
int getBooleanAttributes(java.io.File);
|
||||||
|
<init>(kotlinc.internal.com.intellij.lang.ASTNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Keep the special static methods that are required in enumeration classes.
|
||||||
|
-keepclassmembers enum * {
|
||||||
|
public static **[] values();
|
||||||
|
public static ** valueOf(java.lang.String);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keepclassmembers class * {
|
||||||
|
** toString();
|
||||||
|
** hashCode();
|
||||||
|
** project();
|
||||||
|
|
||||||
|
** TYPE;
|
||||||
|
** ourInstance;
|
||||||
|
}
|
||||||
|
]]></proguard>
|
||||||
|
<delete file="${output}/kotlin-compiler-clean.jar" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="clean">
|
<target name="clean">
|
||||||
|
|||||||
Binary file not shown.
@@ -154,7 +154,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
catch (Throwable error) {
|
catch (Throwable error) {
|
||||||
throw new CompilationException(error.getMessage(), error, selector);
|
String message = error.getMessage();
|
||||||
|
throw new CompilationException(message != null ? message : "null", error, selector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -179,8 +179,8 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments, CompileEn
|
|||||||
@NotNull K2JVMCompilerArguments arguments) {
|
@NotNull K2JVMCompilerArguments arguments) {
|
||||||
super.configureEnvironment(configuration, arguments);
|
super.configureEnvironment(configuration, arguments);
|
||||||
|
|
||||||
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
||||||
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
CompileEnvironmentUtil.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.classpath != null) {
|
if (arguments.classpath != null) {
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ public class CompileEnvironmentUtil {
|
|||||||
scriptEnvironment.addSources(moduleScriptFile);
|
scriptEnvironment.addSources(moduleScriptFile);
|
||||||
|
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.cli.jvm.compiler;
|
package org.jetbrains.jet.cli.jvm.compiler;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.intellij.core.JavaCoreEnvironment;
|
import com.intellij.core.JavaCoreEnvironment;
|
||||||
import com.intellij.lang.java.JavaParserDefinition;
|
import com.intellij.lang.java.JavaParserDefinition;
|
||||||
import com.intellij.mock.MockApplication;
|
import com.intellij.mock.MockApplication;
|
||||||
@@ -39,44 +38,23 @@ import org.jetbrains.jet.plugin.JetFileType;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
*/
|
*/
|
||||||
public class JetCoreEnvironment extends JavaCoreEnvironment {
|
public class JetCoreEnvironment extends JavaCoreEnvironment {
|
||||||
private final List<JetFile> sourceFiles = Lists.newArrayList();
|
private final List<JetFile> sourceFiles = new ArrayList<JetFile>();
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetCoreEnvironment getCoreEnvironmentForJVM(@NotNull Disposable disposable,
|
private final CompilerDependencies compilerDependencies;
|
||||||
@NotNull CompilerDependencies compilerDependencies) {
|
|
||||||
JetCoreEnvironment coreEnvironment = new JetCoreEnvironment(disposable);
|
|
||||||
|
|
||||||
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
public JetCoreEnvironment(Disposable parentDisposable, @NotNull CompilerDependencies compilerDependencies) {
|
||||||
|
|
||||||
coreEnvironment.addToClasspath(compilerDependencies.getJdkJar());
|
|
||||||
|
|
||||||
if (compilerSpecialMode.includeJdkHeaders()) {
|
|
||||||
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
|
|
||||||
coreEnvironment.addLibraryRoot(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (compilerSpecialMode.includeKotlinRuntime()) {
|
|
||||||
for (VirtualFile root : compilerDependencies.getRuntimeRoots()) {
|
|
||||||
coreEnvironment.addLibraryRoot(root);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return coreEnvironment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JetCoreEnvironment getCoreEnvironmentForJS(@NotNull Disposable disposable) {
|
|
||||||
return new JetCoreEnvironment(disposable);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JetCoreEnvironment(Disposable parentDisposable) {
|
|
||||||
super(parentDisposable);
|
super(parentDisposable);
|
||||||
|
|
||||||
|
this.compilerDependencies = compilerDependencies;
|
||||||
|
|
||||||
registerFileType(JetFileType.INSTANCE, "kt");
|
registerFileType(JetFileType.INSTANCE, "kt");
|
||||||
registerFileType(JetFileType.INSTANCE, "kts");
|
registerFileType(JetFileType.INSTANCE, "kts");
|
||||||
registerFileType(JetFileType.INSTANCE, "ktm");
|
registerFileType(JetFileType.INSTANCE, "ktm");
|
||||||
@@ -90,6 +68,19 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
||||||
.registerExtension(new JavaElementFinder(myProject));
|
.registerExtension(new JavaElementFinder(myProject));
|
||||||
|
|
||||||
|
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
|
||||||
|
|
||||||
|
addToClasspath(compilerDependencies.getJdkJar());
|
||||||
|
|
||||||
|
if (compilerSpecialMode.includeJdkHeaders()) {
|
||||||
|
for (VirtualFile root : compilerDependencies.getJdkHeaderRoots()) {
|
||||||
|
addLibraryRoot(root);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (compilerSpecialMode.includeKotlinRuntime()) {
|
||||||
|
addToClasspath(compilerDependencies.getRuntimeJar());
|
||||||
|
}
|
||||||
|
|
||||||
JetStandardLibrary.initialize(getProject());
|
JetStandardLibrary.initialize(getProject());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +89,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addSources(File file) {
|
private void addSources(File file) {
|
||||||
if (file.isDirectory()) {
|
if(file.isDirectory()) {
|
||||||
File[] files = file.listFiles();
|
File[] files = file.listFiles();
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
for (File child : files) {
|
for (File child : files) {
|
||||||
@@ -110,7 +101,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
VirtualFile fileByPath = getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
VirtualFile fileByPath = getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
||||||
if (fileByPath != null) {
|
if (fileByPath != null) {
|
||||||
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(fileByPath);
|
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(fileByPath);
|
||||||
if (psiFile instanceof JetFile) {
|
if(psiFile instanceof JetFile) {
|
||||||
sourceFiles.add((JetFile)psiFile);
|
sourceFiles.add((JetFile)psiFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,7 +109,7 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addSources(VirtualFile vFile) {
|
public void addSources(VirtualFile vFile) {
|
||||||
if (vFile.isDirectory()) {
|
if (vFile.isDirectory()) {
|
||||||
for (VirtualFile virtualFile : vFile.getChildren()) {
|
for (VirtualFile virtualFile : vFile.getChildren()) {
|
||||||
addSources(virtualFile);
|
addSources(virtualFile);
|
||||||
}
|
}
|
||||||
@@ -134,9 +125,8 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addSources(String path) {
|
public void addSources(String path) {
|
||||||
if (path == null) {
|
if(path == null)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
VirtualFile vFile = getLocalFileSystem().findFileByPath(path);
|
VirtualFile vFile = getLocalFileSystem().findFileByPath(path);
|
||||||
if (vFile == null) {
|
if (vFile == null) {
|
||||||
@@ -155,17 +145,20 @@ public class JetCoreEnvironment extends JavaCoreEnvironment {
|
|||||||
|
|
||||||
public void addToClasspathFromClassLoader(ClassLoader loader) {
|
public void addToClasspathFromClassLoader(ClassLoader loader) {
|
||||||
ClassLoader parent = loader.getParent();
|
ClassLoader parent = loader.getParent();
|
||||||
if (parent != null) {
|
if(parent != null)
|
||||||
addToClasspathFromClassLoader(parent);
|
addToClasspathFromClassLoader(parent);
|
||||||
}
|
|
||||||
|
|
||||||
if (loader instanceof URLClassLoader) {
|
if(loader instanceof URLClassLoader) {
|
||||||
for (URL url : ((URLClassLoader)loader).getURLs()) {
|
for (URL url : ((URLClassLoader) loader).getURLs()) {
|
||||||
File file = new File(url.getPath());
|
File file = new File(url.getPath());
|
||||||
if (file.exists() && (!file.isFile() || file.getPath().endsWith(".jar"))) {
|
if(file.exists() && (!file.isFile() || file.getPath().endsWith(".jar")))
|
||||||
addToClasspath(file);
|
addToClasspath(file);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public CompilerDependencies getCompilerDependencies() {
|
||||||
|
return compilerDependencies;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -72,7 +72,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
configuration.getEnvironment().addToClasspath(new File(classpathRoot));
|
configuration.getEnvironment().addToClasspath(new File(classpathRoot));
|
||||||
}
|
}
|
||||||
|
|
||||||
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getCompilerDependencies());
|
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies());
|
||||||
|
|
||||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
@@ -93,9 +93,9 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
for (Module moduleBuilder : modules) {
|
for (Module moduleBuilder : modules) {
|
||||||
// TODO: this should be done only once for the environment
|
// TODO: this should be done only once for the environment
|
||||||
if (configuration.getCompilerDependencies().getRuntimeJar() != null) {
|
if (configuration.getEnvironment().getCompilerDependencies().getRuntimeJar() != null) {
|
||||||
CompileEnvironmentUtil
|
CompileEnvironmentUtil
|
||||||
.addToClasspath(configuration.getEnvironment(), configuration.getCompilerDependencies().getRuntimeJar());
|
.addToClasspath(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies().getRuntimeJar());
|
||||||
}
|
}
|
||||||
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
|
ClassFileFactory moduleFactory = compileModule(configuration, moduleBuilder, directory);
|
||||||
if (moduleFactory == null) {
|
if (moduleFactory == null) {
|
||||||
@@ -132,7 +132,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getCompilerDependencies());
|
CompileEnvironmentUtil.ensureRuntime(configuration.getEnvironment(), configuration.getEnvironment().getCompilerDependencies());
|
||||||
|
|
||||||
GenerationState generationState = analyzeAndGenerate(configuration);
|
GenerationState generationState = analyzeAndGenerate(configuration);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
@@ -198,7 +198,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
|
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
|
||||||
return analyzeAndGenerate(configuration, configuration.getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
return analyzeAndGenerate(configuration, configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -233,7 +233,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
return AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
|
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely,
|
||||||
JetControlFlowDataTraceFactory.EMPTY,
|
JetControlFlowDataTraceFactory.EMPTY,
|
||||||
configuration.getCompilerDependencies());
|
configuration.getEnvironment().getCompilerDependencies());
|
||||||
}
|
}
|
||||||
}, environment.getSourceFiles()
|
}, environment.getSourceFiles()
|
||||||
);
|
);
|
||||||
@@ -256,7 +256,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
};
|
};
|
||||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
||||||
exhaust, environment.getSourceFiles(),
|
exhaust, environment.getSourceFiles(),
|
||||||
configuration.getCompilerDependencies().getCompilerSpecialMode());
|
configuration.getEnvironment().getCompilerDependencies().getCompilerSpecialMode());
|
||||||
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
|
|
||||||
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
||||||
|
|||||||
+1
-1
@@ -959,7 +959,7 @@ public class JavaDescriptorResolver {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType transform = semanticServices.getTypeTransformer().transformToType(type, typeVariableResolver);
|
JetType transform = semanticServices.getTypeTransformer().transformToType(type, JavaTypeTransformer.TypeUsage.SUPERTYPE, typeVariableResolver);
|
||||||
|
|
||||||
result.add(TypeUtils.makeNotNullable(transform));
|
result.add(TypeUtils.makeNotNullable(transform));
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-20
@@ -33,11 +33,9 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
|||||||
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
import org.jetbrains.jet.rt.signature.JetSignatureReader;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import static org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer.TypeUsage.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -66,9 +64,11 @@ public class JavaTypeTransformer {
|
|||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public TypeProjection transformToTypeProjection(@NotNull final PsiType javaType,
|
private TypeProjection transformToTypeProjection(@NotNull final PsiType javaType,
|
||||||
@NotNull final TypeParameterDescriptor typeParameterDescriptor,
|
@NotNull final TypeParameterDescriptor typeParameterDescriptor,
|
||||||
@NotNull final TypeVariableResolver typeVariableByPsiResolver) {
|
@NotNull final TypeVariableResolver typeVariableByPsiResolver,
|
||||||
|
@NotNull final TypeUsage howThisTypeIsUsed
|
||||||
|
) {
|
||||||
TypeProjection result = javaType.accept(new PsiTypeVisitor<TypeProjection>() {
|
TypeProjection result = javaType.accept(new PsiTypeVisitor<TypeProjection>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -85,12 +85,12 @@ public class JavaTypeTransformer {
|
|||||||
|
|
||||||
PsiType bound = wildcardType.getBound();
|
PsiType bound = wildcardType.getBound();
|
||||||
assert bound != null;
|
assert bound != null;
|
||||||
return new TypeProjection(variance, transformToType(bound, TypeUsage.UPPER_BOUND, typeVariableByPsiResolver));
|
return new TypeProjection(variance, transformToType(bound, UPPER_BOUND, typeVariableByPsiResolver));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeProjection visitType(PsiType type) {
|
public TypeProjection visitType(PsiType type) {
|
||||||
return new TypeProjection(transformToType(type, TypeUsage.TYPE_ARGUMENT, typeVariableByPsiResolver));
|
return new TypeProjection(transformToType(type, howThisTypeIsUsed, typeVariableByPsiResolver));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
@@ -136,7 +136,7 @@ public class JavaTypeTransformer {
|
|||||||
if (psiMethod.isConstructor()) {
|
if (psiMethod.isConstructor()) {
|
||||||
Set<JetType> supertypesJet = Sets.newHashSet();
|
Set<JetType> supertypesJet = Sets.newHashSet();
|
||||||
for (PsiClassType supertype : typeParameter.getExtendsListTypes()) {
|
for (PsiClassType supertype : typeParameter.getExtendsListTypes()) {
|
||||||
supertypesJet.add(transformToType(supertype, TypeUsage.UPPER_BOUND, typeVariableResolver));
|
supertypesJet.add(transformToType(supertype, UPPER_BOUND, typeVariableResolver));
|
||||||
}
|
}
|
||||||
return TypeUtils.intersect(JetTypeChecker.INSTANCE, supertypesJet);
|
return TypeUtils.intersect(JetTypeChecker.INSTANCE, supertypesJet);
|
||||||
}
|
}
|
||||||
@@ -144,20 +144,24 @@ public class JavaTypeTransformer {
|
|||||||
|
|
||||||
TypeParameterDescriptor typeParameterDescriptor = typeVariableResolver.getTypeVariable(typeParameter.getName());
|
TypeParameterDescriptor typeParameterDescriptor = typeVariableResolver.getTypeVariable(typeParameter.getName());
|
||||||
|
|
||||||
if (howThisTypeIsUsed == TypeUsage.TYPE_ARGUMENT || howThisTypeIsUsed == TypeUsage.UPPER_BOUND) {
|
// In Java: ArrayList<T>
|
||||||
// In Java: ArrayList<T>
|
// In Kotlin: ArrayList<T>, not ArrayList<T?>
|
||||||
// In Kotlin: ArrayList<T>, not ArrayList<T?>
|
// nullability will be taken care of in individual member signatures
|
||||||
// nullability will be taken care of in individual member signatures
|
boolean nullable = !EnumSet.of(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT).contains(howThisTypeIsUsed);
|
||||||
return typeParameterDescriptor.getDefaultType();
|
if (nullable) {
|
||||||
|
return TypeUtils.makeNullable(typeParameterDescriptor.getDefaultType());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return TypeUtils.makeNullable(typeParameterDescriptor.getDefaultType());
|
return typeParameterDescriptor.getDefaultType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// 'L extends List<T>' in Java is a List<T> in Kotlin, not a List<T?>
|
||||||
|
boolean nullable = !EnumSet.of(SUPERTYPE_ARGUMENT, SUPERTYPE).contains(howThisTypeIsUsed);
|
||||||
|
|
||||||
JetType jetAnalog = getKotlinAnalog(new FqName(psiClass.getQualifiedName()));
|
JetType jetAnalog = getKotlinAnalog(new FqName(psiClass.getQualifiedName()));
|
||||||
if (jetAnalog != null) {
|
if (jetAnalog != null) {
|
||||||
return jetAnalog;
|
return TypeUtils.makeNullableAsSpecified(jetAnalog, nullable);
|
||||||
}
|
}
|
||||||
|
|
||||||
final ClassDescriptor classData =
|
final ClassDescriptor classData =
|
||||||
@@ -187,13 +191,15 @@ public class JavaTypeTransformer {
|
|||||||
PsiType psiArgument = psiArguments[i];
|
PsiType psiArgument = psiArguments[i];
|
||||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
||||||
|
|
||||||
arguments.add(transformToTypeProjection(psiArgument, typeParameterDescriptor, typeVariableResolver));
|
TypeUsage howTheProjectionIsUsed = howThisTypeIsUsed == SUPERTYPE ? SUPERTYPE_ARGUMENT : TYPE_ARGUMENT;
|
||||||
|
arguments.add(transformToTypeProjection(psiArgument, typeParameterDescriptor, typeVariableResolver, howTheProjectionIsUsed));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JetTypeImpl(
|
return new JetTypeImpl(
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
classData.getTypeConstructor(),
|
classData.getTypeConstructor(),
|
||||||
true,
|
nullable,
|
||||||
arguments,
|
arguments,
|
||||||
classData.getMemberScope(arguments));
|
classData.getMemberScope(arguments));
|
||||||
}
|
}
|
||||||
@@ -291,6 +297,7 @@ public class JavaTypeTransformer {
|
|||||||
MEMBER_SIGNATURE_COVARIANT,
|
MEMBER_SIGNATURE_COVARIANT,
|
||||||
MEMBER_SIGNATURE_CONTRAVARIANT,
|
MEMBER_SIGNATURE_CONTRAVARIANT,
|
||||||
MEMBER_SIGNATURE_INVARIANT,
|
MEMBER_SIGNATURE_INVARIANT,
|
||||||
SUPERTYPE
|
SUPERTYPE,
|
||||||
|
SUPERTYPE_ARGUMENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-1
@@ -127,10 +127,20 @@ public class FunctionDescriptorUtil {
|
|||||||
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
JetStandardClasses.getValueParameters(functionDescriptor, functionType),
|
||||||
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
JetStandardClasses.getReturnTypeFromFunctionType(functionType),
|
||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
Visibilities.LOCAL);
|
Visibilities.PUBLIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
|
public static <D extends CallableDescriptor> D alphaConvertTypeParameters(D candidate) {
|
||||||
return (D) candidate.substitute(MAKE_TYPE_PARAMETERS_FRESH);
|
return (D) candidate.substitute(MAKE_TYPE_PARAMETERS_FRESH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FunctionDescriptor getInvokeFunction(@NotNull JetType functionType) {
|
||||||
|
assert JetStandardClasses.isFunctionType(functionType);
|
||||||
|
|
||||||
|
ClassifierDescriptor classDescriptorForFunction = functionType.getConstructor().getDeclarationDescriptor();
|
||||||
|
assert classDescriptorForFunction instanceof ClassDescriptor;
|
||||||
|
Set<FunctionDescriptor> invokeFunctions = ((ClassDescriptor) classDescriptorForFunction).getMemberScope(functionType.getArguments()).getFunctions("invoke");
|
||||||
|
assert invokeFunctions.size() == 1;
|
||||||
|
return invokeFunctions.iterator().next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public interface Errors {
|
|||||||
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
|
//Elements with "INVISIBLE_REFERENCE" error are marked as unresolved, unlike elements with "INVISIBLE_MEMBER" error
|
||||||
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_REFERENCE =
|
DiagnosticFactory2<JetSimpleNameExpression, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_REFERENCE =
|
||||||
DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory2<PsiElement, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2<PsiElement, DeclarationDescriptor, DeclarationDescriptor> INVISIBLE_MEMBER = DiagnosticFactory2.create(ERROR, PositioningStrategies.CALL_ELEMENT);
|
||||||
|
|
||||||
RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(ERROR);
|
RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(ERROR);
|
||||||
RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(WARNING);
|
RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(WARNING);
|
||||||
@@ -247,12 +247,12 @@ public interface Errors {
|
|||||||
public List<TextRange> mark(@NotNull JetDeclarationWithBody element) {
|
public List<TextRange> mark(@NotNull JetDeclarationWithBody element) {
|
||||||
JetExpression bodyExpression = element.getBodyExpression();
|
JetExpression bodyExpression = element.getBodyExpression();
|
||||||
if (!(bodyExpression instanceof JetBlockExpression)) {
|
if (!(bodyExpression instanceof JetBlockExpression)) {
|
||||||
return Collections.emptyList();
|
return markElement(element);
|
||||||
}
|
}
|
||||||
JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression;
|
JetBlockExpression blockExpression = (JetBlockExpression)bodyExpression;
|
||||||
TextRange lastBracketRange = blockExpression.getLastBracketRange();
|
TextRange lastBracketRange = blockExpression.getLastBracketRange();
|
||||||
if (lastBracketRange == null) {
|
if (lastBracketRange == null) {
|
||||||
return Collections.emptyList();
|
return markElement(element);
|
||||||
}
|
}
|
||||||
return markRange(lastBracketRange);
|
return markRange(lastBracketRange);
|
||||||
}
|
}
|
||||||
@@ -288,7 +288,6 @@ public interface Errors {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<TextRange> mark(@NotNull JetWhenExpression element) {
|
public List<TextRange> mark(@NotNull JetWhenExpression element) {
|
||||||
if (hasSyntaxError(element)) return Collections.emptyList();
|
|
||||||
return markElement(element.getWhenKeywordElement());
|
return markElement(element.getWhenKeywordElement());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -403,7 +402,7 @@ public interface Errors {
|
|||||||
JetClass klass = (JetClass)jetDeclaration;
|
JetClass klass = (JetClass)jetDeclaration;
|
||||||
PsiElement nameAsDeclaration = klass.getNameIdentifier();
|
PsiElement nameAsDeclaration = klass.getNameIdentifier();
|
||||||
if (nameAsDeclaration == null) {
|
if (nameAsDeclaration == null) {
|
||||||
return markRange(klass.getTextRange());
|
return markElement(klass);
|
||||||
}
|
}
|
||||||
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
|
PsiElement primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
|
||||||
if (primaryConstructorParameterList == null) {
|
if (primaryConstructorParameterList == null) {
|
||||||
@@ -416,7 +415,7 @@ public interface Errors {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// safe way
|
// safe way
|
||||||
return markRange(jetDeclaration.getTextRange());
|
return markElement(jetDeclaration);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -449,7 +448,7 @@ public interface Errors {
|
|||||||
class Initializer {
|
class Initializer {
|
||||||
static {
|
static {
|
||||||
for (Field field : Errors.class.getFields()) {
|
for (Field field : Errors.class.getFields()) {
|
||||||
if ((field.getModifiers() & Modifier.STATIC) != 0) {
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
try {
|
try {
|
||||||
Object value = field.get(null);
|
Object value = field.get(null);
|
||||||
if (value instanceof AbstractDiagnosticFactory) {
|
if (value instanceof AbstractDiagnosticFactory) {
|
||||||
|
|||||||
+20
-10
@@ -59,10 +59,9 @@ public class PositioningStrategies {
|
|||||||
returnTypeRef = accessor.getReturnTypeReference();
|
returnTypeRef = accessor.getReturnTypeReference();
|
||||||
nameNode = accessor.getNamePlaceholder().getNode();
|
nameNode = accessor.getNamePlaceholder().getNode();
|
||||||
}
|
}
|
||||||
if (returnTypeRef != null) return Collections.singletonList(returnTypeRef.getTextRange());
|
if (returnTypeRef != null) return markElement(returnTypeRef);
|
||||||
if (nameNode != null) return Collections.singletonList(nameNode.getTextRange());
|
if (nameNode != null) return markNode(nameNode);
|
||||||
return super.mark(declaration);
|
return markElement(declaration);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ASTNode getNameNode(JetNamedDeclaration function) {
|
private ASTNode getNameNode(JetNamedDeclaration function) {
|
||||||
@@ -75,14 +74,11 @@ public class PositioningStrategies {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<TextRange> mark(@NotNull PsiNameIdentifierOwner element) {
|
public List<TextRange> mark(@NotNull PsiNameIdentifierOwner element) {
|
||||||
if (element.getLastChild() instanceof PsiErrorElement) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
PsiElement nameIdentifier = element.getNameIdentifier();
|
PsiElement nameIdentifier = element.getNameIdentifier();
|
||||||
if (nameIdentifier != null) {
|
if (nameIdentifier != null) {
|
||||||
return markElement(nameIdentifier);
|
return markElement(nameIdentifier);
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return markElement(element);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -100,9 +96,9 @@ public class PositioningStrategies {
|
|||||||
assert modifierList != null;
|
assert modifierList != null;
|
||||||
ASTNode node = modifierList.getModifierNode(token);
|
ASTNode node = modifierList.getModifierNode(token);
|
||||||
assert node != null;
|
assert node != null;
|
||||||
return Collections.singletonList(node.getTextRange());
|
return markNode(node);
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return markElement(modifierListOwner);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -151,4 +147,18 @@ public class PositioningStrategies {
|
|||||||
return markNode(element.getDefaultValue().getNode());
|
return markNode(element.getDefaultValue().getNode());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static PositioningStrategy<PsiElement> CALL_ELEMENT = new PositioningStrategy<PsiElement>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<TextRange> mark(@NotNull PsiElement callElement) {
|
||||||
|
if (callElement instanceof JetCallElement) {
|
||||||
|
JetExpression calleeExpression = ((JetCallElement) callElement).getCalleeExpression();
|
||||||
|
if (calleeExpression != null) {
|
||||||
|
return markElement(calleeExpression);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return markElement(callElement);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
+4
-1
@@ -34,7 +34,10 @@ public class UnresolvedReferenceDiagnosticFactory extends DiagnosticFactory1<Jet
|
|||||||
@Override
|
@Override
|
||||||
public List<TextRange> mark(@NotNull JetReferenceExpression element) {
|
public List<TextRange> mark(@NotNull JetReferenceExpression element) {
|
||||||
if (element instanceof JetArrayAccessExpression) {
|
if (element instanceof JetArrayAccessExpression) {
|
||||||
return ((JetArrayAccessExpression) element).getBracketRanges();
|
List<TextRange> ranges = ((JetArrayAccessExpression) element).getBracketRanges();
|
||||||
|
if (!ranges.isEmpty()) {
|
||||||
|
return ranges;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Collections.singletonList(element.getTextRange());
|
return Collections.singletonList(element.getTextRange());
|
||||||
}
|
}
|
||||||
|
|||||||
+20
@@ -17,7 +17,9 @@
|
|||||||
package org.jetbrains.jet.lang.diagnostics.rendering;
|
package org.jetbrains.jet.lang.diagnostics.rendering;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.AbstractDiagnosticFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetTypeConstraint;
|
import org.jetbrains.jet.lang.psi.JetTypeConstraint;
|
||||||
@@ -25,6 +27,8 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
@@ -401,6 +405,22 @@ public class DefaultErrorMessages {
|
|||||||
"This may cause problems when calling this function with named arguments.", commaSeparated(TO_STRING), TO_STRING);
|
"This may cause problems when calling this function with named arguments.", commaSeparated(TO_STRING), TO_STRING);
|
||||||
|
|
||||||
MAP.setImmutable();
|
MAP.setImmutable();
|
||||||
|
|
||||||
|
for (Field field : Errors.class.getFields()) {
|
||||||
|
if (Modifier.isStatic(field.getModifiers())) {
|
||||||
|
try {
|
||||||
|
Object fieldValue = field.get(null);
|
||||||
|
if (fieldValue instanceof AbstractDiagnosticFactory) {
|
||||||
|
if (MAP.get((AbstractDiagnosticFactory) fieldValue) == null) {
|
||||||
|
throw new IllegalStateException("No default diagnostic renderer is provided for " + ((AbstractDiagnosticFactory)fieldValue).getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IllegalAccessException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultErrorMessages() {
|
private DefaultErrorMessages() {
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public interface Call {
|
|||||||
@NotNull
|
@NotNull
|
||||||
ReceiverDescriptor getExplicitReceiver();
|
ReceiverDescriptor getExplicitReceiver();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
ReceiverDescriptor getThisObject();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
JetExpression getCalleeExpression();
|
JetExpression getCalleeExpression();
|
||||||
|
|
||||||
|
|||||||
@@ -20,14 +20,10 @@ import com.google.common.collect.Lists;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableAsFunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||||
import org.jetbrains.jet.util.slicedmap.Slices;
|
import org.jetbrains.jet.util.slicedmap.Slices;
|
||||||
@@ -68,7 +64,7 @@ public class BindingContextUtils {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static PsiElement resolveToDeclarationPsiElement(@NotNull BindingContext bindingContext, @Nullable JetReferenceExpression referenceExpression) {
|
public static PsiElement resolveToDeclarationPsiElement(@NotNull BindingContext bindingContext, @Nullable JetReferenceExpression referenceExpression) {
|
||||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, referenceExpression);
|
DeclarationDescriptor declarationDescriptor = referenceToDescriptor(bindingContext, referenceExpression);
|
||||||
if (declarationDescriptor == null) {
|
if (declarationDescriptor == null) {
|
||||||
return bindingContext.get(BindingContext.LABEL_TARGET, referenceExpression);
|
return bindingContext.get(BindingContext.LABEL_TARGET, referenceExpression);
|
||||||
}
|
}
|
||||||
@@ -88,7 +84,7 @@ public class BindingContextUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<PsiElement> resolveToDeclarationPsiElements(@NotNull BindingContext bindingContext, @Nullable JetReferenceExpression referenceExpression) {
|
public static List<PsiElement> resolveToDeclarationPsiElements(@NotNull BindingContext bindingContext, @Nullable JetReferenceExpression referenceExpression) {
|
||||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, referenceExpression);
|
DeclarationDescriptor declarationDescriptor = referenceToDescriptor(bindingContext, referenceExpression);
|
||||||
if (declarationDescriptor == null) {
|
if (declarationDescriptor == null) {
|
||||||
return Lists.newArrayList(bindingContext.get(BindingContext.LABEL_TARGET, referenceExpression));
|
return Lists.newArrayList(bindingContext.get(BindingContext.LABEL_TARGET, referenceExpression));
|
||||||
}
|
}
|
||||||
@@ -114,7 +110,7 @@ public class BindingContextUtils {
|
|||||||
descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
|
descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
|
||||||
}
|
}
|
||||||
else if (element instanceof JetSimpleNameExpression) {
|
else if (element instanceof JetSimpleNameExpression) {
|
||||||
descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) element);
|
descriptor = referenceToDescriptor(bindingContext, (JetSimpleNameExpression) element);
|
||||||
}
|
}
|
||||||
else if (element instanceof JetQualifiedExpression) {
|
else if (element instanceof JetQualifiedExpression) {
|
||||||
descriptor = extractVariableDescriptorIfAny(bindingContext, ((JetQualifiedExpression) element).getSelectorExpression(), onlyReference);
|
descriptor = extractVariableDescriptorIfAny(bindingContext, ((JetQualifiedExpression) element).getSelectorExpression(), onlyReference);
|
||||||
@@ -128,6 +124,16 @@ public class BindingContextUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static DeclarationDescriptor referenceToDescriptor(@NotNull BindingContext bindingContext, @Nullable JetReferenceExpression element) {
|
||||||
|
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, element);
|
||||||
|
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, element);
|
||||||
|
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||||
|
descriptor = ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall().getResultingDescriptor();
|
||||||
|
}
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO these helper methods are added as a workaround to some compiler bugs in Kotlin...
|
// TODO these helper methods are added as a workaround to some compiler bugs in Kotlin...
|
||||||
|
|
||||||
// NOTE this is used by KDoc
|
// NOTE this is used by KDoc
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.resolve;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public class ChainedTemporaryBindingTrace extends TemporaryBindingTrace {
|
||||||
|
|
||||||
|
public static ChainedTemporaryBindingTrace create(TemporaryBindingTrace trace) {
|
||||||
|
return new ChainedTemporaryBindingTrace(trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ChainedTemporaryBindingTrace(TemporaryBindingTrace trace) {
|
||||||
|
super(trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void commit() {
|
||||||
|
super.commit();
|
||||||
|
((TemporaryBindingTrace) trace).commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,6 +45,11 @@ public final class ImportPath {
|
|||||||
return fqName.getFqName() + (isAllUnder ? ".*" : "");
|
return fqName.getFqName() + (isAllUnder ? ".*" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getPathStr();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public FqName fqnPart() {
|
public FqName fqnPart() {
|
||||||
return fqName;
|
return fqName;
|
||||||
|
|||||||
@@ -25,10 +25,9 @@ public class TemporaryBindingTrace extends DelegatingBindingTrace {
|
|||||||
return new TemporaryBindingTrace(trace);
|
return new TemporaryBindingTrace(trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BindingTrace trace;
|
protected final BindingTrace trace;
|
||||||
|
|
||||||
|
protected TemporaryBindingTrace(BindingTrace trace) {
|
||||||
private TemporaryBindingTrace(BindingTrace trace) {
|
|
||||||
super(trace.getBindingContext());
|
super(trace.getBindingContext());
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,6 +98,12 @@ public class CallMaker {
|
|||||||
return explicitReceiver;
|
return explicitReceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getThisObject() {
|
||||||
|
return ReceiverDescriptor.NO_RECEIVER;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JetExpression getCalleeExpression() {
|
public JetExpression getCalleeExpression() {
|
||||||
return calleeExpression;
|
return calleeExpression;
|
||||||
@@ -199,6 +205,12 @@ public class CallMaker {
|
|||||||
return explicitReceiver;
|
return explicitReceiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getThisObject() {
|
||||||
|
return ReceiverDescriptor.NO_RECEIVER;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetExpression getCalleeExpression() {
|
public JetExpression getCalleeExpression() {
|
||||||
return callElement.getCalleeExpression();
|
return callElement.getCalleeExpression();
|
||||||
|
|||||||
+10
-4
@@ -20,21 +20,27 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.Call;
|
import org.jetbrains.jet.lang.psi.Call;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public final class CallResolutionContext<D extends CallableDescriptor> extends ResolutionContext {
|
public final class CallResolutionContext<D extends CallableDescriptor, F extends D> extends ResolutionContext {
|
||||||
/*package*/ final ResolvedCallImpl<D> candidateCall;
|
/*package*/ final ResolvedCallImpl<D> candidateCall;
|
||||||
/*package*/ final TracingStrategy tracing;
|
/*package*/ final TracingStrategy tracing;
|
||||||
|
/*package*/ ReceiverDescriptor receiverForVariableAsFunctionSecondCall = ReceiverDescriptor.NO_RECEIVER;
|
||||||
|
|
||||||
public CallResolutionContext(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing, @NotNull Call call) {
|
private CallResolutionContext(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing, @NotNull Call call) {
|
||||||
super(trace, task.scope, call, task.expectedType, task.dataFlowInfo);
|
super(trace, task.scope, call, task.expectedType, task.dataFlowInfo);
|
||||||
this.candidateCall = candidateCall;
|
this.candidateCall = candidateCall;
|
||||||
this.tracing = tracing;
|
this.tracing = tracing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CallResolutionContext(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing) {
|
public static <D extends CallableDescriptor, F extends D> CallResolutionContext<D, F> create(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing, @NotNull Call call) {
|
||||||
this(candidateCall, task, trace, tracing, task.call);
|
return new CallResolutionContext<D, F>(candidateCall, task, trace, tracing, call);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <D extends CallableDescriptor, F extends D> CallResolutionContext<D, F> create(@NotNull ResolvedCallImpl<D> candidateCall, @NotNull ResolutionTask<D, F> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing) {
|
||||||
|
return create(candidateCall, task, trace, tracing, task.call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,16 +102,16 @@ public class CallResolver {
|
|||||||
if (referencedName == null) {
|
if (referencedName == null) {
|
||||||
return OverloadResolutionResultsImpl.nameNotFound();
|
return OverloadResolutionResultsImpl.nameNotFound();
|
||||||
}
|
}
|
||||||
List<MemberPrioritizer<VariableDescriptor>> memberPrioritizers = Lists.newArrayList();
|
List<CallableDescriptorCollector<? extends VariableDescriptor>> callableDescriptorCollectors = Lists.newArrayList();
|
||||||
if (nameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
if (nameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
||||||
referencedName = referencedName.substring(1);
|
referencedName = referencedName.substring(1);
|
||||||
memberPrioritizers.add(MemberPrioritizers.PROPERTY_TASK_PRIORITIZER);
|
callableDescriptorCollectors.add(CallableDescriptorCollectors.PROPERTIES);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memberPrioritizers.add(MemberPrioritizers.VARIABLE_TASK_PRIORITIZER);
|
callableDescriptorCollectors.add(CallableDescriptorCollectors.VARIABLES);
|
||||||
}
|
}
|
||||||
List<ResolutionTask<VariableDescriptor>> prioritizedTasks = TaskPrioritizer.computePrioritizedTasks(context, referencedName, nameExpression, memberPrioritizers);
|
List<ResolutionTask<VariableDescriptor, VariableDescriptor>> prioritizedTasks = TaskPrioritizer.computePrioritizedTasks(context, referencedName, nameExpression, callableDescriptorCollectors);
|
||||||
return doResolveCall(context, prioritizedTasks, CallTransformationStrategy.PROPERTY_CALL_TRANSFORMATION_STRATEGY, nameExpression);
|
return doResolveCall(context, prioritizedTasks, CallTransformer.PROPERTY_CALL_TRANSFORMER, nameExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -119,9 +119,8 @@ public class CallResolver {
|
|||||||
@NotNull BasicResolutionContext context,
|
@NotNull BasicResolutionContext context,
|
||||||
@NotNull final JetReferenceExpression functionReference,
|
@NotNull final JetReferenceExpression functionReference,
|
||||||
@NotNull String name) {
|
@NotNull String name) {
|
||||||
List<ResolutionTask<FunctionDescriptor>> tasks = TaskPrioritizer.computePrioritizedTasks(
|
List<ResolutionTask<CallableDescriptor, FunctionDescriptor>> tasks = TaskPrioritizer.computePrioritizedTasks(context, name, functionReference, CallableDescriptorCollectors.FUNCTIONS_AND_VARIABLES);
|
||||||
context, name, functionReference, Collections.singletonList(MemberPrioritizers.FUNCTION_TASK_PRIORITIZER));
|
return doResolveCall(context, tasks, CallTransformer.FUNCTION_CALL_TRANSFORMER, functionReference);
|
||||||
return doResolveCall(context, tasks, CallTransformationStrategy.FUNCTION_CALL_TRANSFORMATION_STRATEGY, functionReference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -131,7 +130,7 @@ public class CallResolver {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(@NotNull BasicResolutionContext context) {
|
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(@NotNull BasicResolutionContext context) {
|
||||||
List<ResolutionTask<FunctionDescriptor>> prioritizedTasks;
|
List<ResolutionTask<CallableDescriptor, FunctionDescriptor>> prioritizedTasks;
|
||||||
|
|
||||||
JetExpression calleeExpression = context.call.getCalleeExpression();
|
JetExpression calleeExpression = context.call.getCalleeExpression();
|
||||||
final JetReferenceExpression functionReference;
|
final JetReferenceExpression functionReference;
|
||||||
@@ -142,7 +141,7 @@ public class CallResolver {
|
|||||||
String name = expression.getReferencedName();
|
String name = expression.getReferencedName();
|
||||||
if (name == null) return checkArgumentTypesAndFail(context);
|
if (name == null) return checkArgumentTypesAndFail(context);
|
||||||
|
|
||||||
prioritizedTasks = TaskPrioritizer.computePrioritizedTasks(context, name, functionReference, Collections.singletonList(MemberPrioritizers.FUNCTION_TASK_PRIORITIZER));
|
prioritizedTasks = TaskPrioritizer.computePrioritizedTasks(context, name, functionReference, CallableDescriptorCollectors.FUNCTIONS_AND_VARIABLES);
|
||||||
ResolutionTask.DescriptorCheckStrategy abstractConstructorCheck = new ResolutionTask.DescriptorCheckStrategy() {
|
ResolutionTask.DescriptorCheckStrategy abstractConstructorCheck = new ResolutionTask.DescriptorCheckStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing) {
|
public <D extends CallableDescriptor> boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing) {
|
||||||
@@ -184,8 +183,8 @@ public class CallResolver {
|
|||||||
context.trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
context.trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
||||||
return checkArgumentTypesAndFail(context);
|
return checkArgumentTypesAndFail(context);
|
||||||
}
|
}
|
||||||
Collection<ResolutionCandidate<FunctionDescriptor>> candidates = TaskPrioritizer.<FunctionDescriptor>convertWithImpliedThis(context.scope, Collections.<ReceiverDescriptor>singletonList(NO_RECEIVER), constructors);
|
Collection<ResolutionCandidate<CallableDescriptor>> candidates = TaskPrioritizer.<CallableDescriptor>convertWithImpliedThis(context.scope, Collections.<ReceiverDescriptor>singletonList(NO_RECEIVER), constructors);
|
||||||
prioritizedTasks.add(new ResolutionTask<FunctionDescriptor>(candidates, functionReference, context)); // !! DataFlowInfo.EMPTY
|
prioritizedTasks.add(new ResolutionTask<CallableDescriptor, FunctionDescriptor>(candidates, functionReference, context)); // !! DataFlowInfo.EMPTY
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
context.trace.report(NOT_A_CLASS.on(calleeExpression));
|
context.trace.report(NOT_A_CLASS.on(calleeExpression));
|
||||||
@@ -206,8 +205,8 @@ public class CallResolver {
|
|||||||
context.trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
context.trace.report(NO_CONSTRUCTOR.on(reportAbsenceOn));
|
||||||
return checkArgumentTypesAndFail(context);
|
return checkArgumentTypesAndFail(context);
|
||||||
}
|
}
|
||||||
List<ResolutionCandidate<FunctionDescriptor>> candidates = ResolutionCandidate.<FunctionDescriptor>convertCollection(constructors);
|
List<ResolutionCandidate<CallableDescriptor>> candidates = ResolutionCandidate.<CallableDescriptor>convertCollection(constructors);
|
||||||
prioritizedTasks = Collections.singletonList(new ResolutionTask<FunctionDescriptor>(candidates, functionReference, context)); // !! DataFlowInfo.EMPTY
|
prioritizedTasks = Collections.singletonList(new ResolutionTask<CallableDescriptor, FunctionDescriptor>(candidates, functionReference, context)); // !! DataFlowInfo.EMPTY
|
||||||
}
|
}
|
||||||
else if (calleeExpression != null) {
|
else if (calleeExpression != null) {
|
||||||
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
// Here we handle the case where the callee expression must be something of type function, e.g. (foo.bar())(1, 2)
|
||||||
@@ -223,7 +222,7 @@ public class CallResolver {
|
|||||||
|
|
||||||
FunctionDescriptorImpl functionDescriptor = new ExpressionAsFunctionDescriptor(context.scope.getContainingDeclaration(), "[for expression " + calleeExpression.getText() + "]");
|
FunctionDescriptorImpl functionDescriptor = new ExpressionAsFunctionDescriptor(context.scope.getContainingDeclaration(), "[for expression " + calleeExpression.getText() + "]");
|
||||||
FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, calleeType, NO_RECEIVER);
|
FunctionDescriptorUtil.initializeFromFunctionType(functionDescriptor, calleeType, NO_RECEIVER);
|
||||||
ResolutionCandidate<FunctionDescriptor> resolutionCandidate = ResolutionCandidate.<FunctionDescriptor>create(functionDescriptor);
|
ResolutionCandidate<CallableDescriptor> resolutionCandidate = ResolutionCandidate.<CallableDescriptor>create(functionDescriptor);
|
||||||
resolutionCandidate.setReceiverArgument(context.call.getExplicitReceiver());
|
resolutionCandidate.setReceiverArgument(context.call.getExplicitReceiver());
|
||||||
|
|
||||||
// strictly speaking, this is a hack:
|
// strictly speaking, this is a hack:
|
||||||
@@ -231,7 +230,7 @@ public class CallResolver {
|
|||||||
// so we wrap what we have into a fake reference and pass it on (unwrap on the other end)
|
// so we wrap what we have into a fake reference and pass it on (unwrap on the other end)
|
||||||
functionReference = new JetFakeReference(calleeExpression);
|
functionReference = new JetFakeReference(calleeExpression);
|
||||||
|
|
||||||
prioritizedTasks = Collections.singletonList(new ResolutionTask<FunctionDescriptor>(Collections.singleton(resolutionCandidate), functionReference, context));
|
prioritizedTasks = Collections.singletonList(new ResolutionTask<CallableDescriptor, FunctionDescriptor>(Collections.singleton(resolutionCandidate), functionReference, context));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// checkTypesWithNoCallee(trace, scope, call);
|
// checkTypesWithNoCallee(trace, scope, call);
|
||||||
@@ -239,7 +238,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return doResolveCall(context, prioritizedTasks, CallTransformationStrategy.FUNCTION_CALL_TRANSFORMATION_STRATEGY, functionReference);
|
return doResolveCall(context, prioritizedTasks, CallTransformer.FUNCTION_CALL_TRANSFORMER, functionReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> OverloadResolutionResults<D> checkArgumentTypesAndFail(BasicResolutionContext context) {
|
private <D extends CallableDescriptor> OverloadResolutionResults<D> checkArgumentTypesAndFail(BasicResolutionContext context) {
|
||||||
@@ -248,10 +247,10 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private <D extends CallableDescriptor> OverloadResolutionResults<D> doResolveCall(
|
private <D extends CallableDescriptor, F extends D> OverloadResolutionResults<F> doResolveCall(
|
||||||
@NotNull final BasicResolutionContext context,
|
@NotNull final BasicResolutionContext context,
|
||||||
@NotNull final List<ResolutionTask<D>> prioritizedTasks, // high to low priority
|
@NotNull final List<ResolutionTask<D, F>> prioritizedTasks, // high to low priority
|
||||||
@NotNull CallTransformationStrategy<D, D> callTransformationStrategy,
|
@NotNull CallTransformer<D, F> callTransformer,
|
||||||
@NotNull final JetReferenceExpression reference) {
|
@NotNull final JetReferenceExpression reference) {
|
||||||
|
|
||||||
ResolutionDebugInfo.Data debugInfo = ResolutionDebugInfo.create();
|
ResolutionDebugInfo.Data debugInfo = ResolutionDebugInfo.create();
|
||||||
@@ -265,10 +264,11 @@ public class CallResolver {
|
|||||||
debugInfo.set(ResolutionDebugInfo.TASKS, prioritizedTasks);
|
debugInfo.set(ResolutionDebugInfo.TASKS, prioritizedTasks);
|
||||||
|
|
||||||
TemporaryBindingTrace traceForFirstNonemptyCandidateSet = null;
|
TemporaryBindingTrace traceForFirstNonemptyCandidateSet = null;
|
||||||
OverloadResolutionResultsImpl<D> resultsForFirstNonemptyCandidateSet = null;
|
OverloadResolutionResultsImpl<F> resultsForFirstNonemptyCandidateSet = null;
|
||||||
for (ResolutionTask<D> task : prioritizedTasks) {
|
for (ResolutionTask<D, F> task : prioritizedTasks) {
|
||||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace);
|
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(context.trace);
|
||||||
OverloadResolutionResultsImpl<D> results = performResolutionGuardedForExtraFunctionLiteralArguments(task.withTrace(temporaryTrace), callTransformationStrategy);
|
OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(task.withTrace(temporaryTrace),
|
||||||
|
callTransformer);
|
||||||
if (results.isSuccess() || results.isAmbiguity()) {
|
if (results.isSuccess() || results.isAmbiguity()) {
|
||||||
temporaryTrace.commit();
|
temporaryTrace.commit();
|
||||||
|
|
||||||
@@ -294,15 +294,15 @@ public class CallResolver {
|
|||||||
context.trace.report(UNRESOLVED_REFERENCE.on(reference));
|
context.trace.report(UNRESOLVED_REFERENCE.on(reference));
|
||||||
checkTypesWithNoCallee(context);
|
checkTypesWithNoCallee(context);
|
||||||
}
|
}
|
||||||
return resultsForFirstNonemptyCandidateSet != null ? resultsForFirstNonemptyCandidateSet : OverloadResolutionResultsImpl.<D>nameNotFound();
|
return resultsForFirstNonemptyCandidateSet != null ? resultsForFirstNonemptyCandidateSet : OverloadResolutionResultsImpl.<F>nameNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolutionGuardedForExtraFunctionLiteralArguments(@NotNull ResolutionTask<D> task,
|
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolutionGuardedForExtraFunctionLiteralArguments(@NotNull ResolutionTask<D, F> task,
|
||||||
@NotNull CallTransformationStrategy<D, D> callTransformationStrategy) {
|
@NotNull CallTransformer<D, F> callTransformer) {
|
||||||
OverloadResolutionResultsImpl<D> results = performResolution(task, callTransformationStrategy);
|
OverloadResolutionResultsImpl<F> results = performResolution(task, callTransformer);
|
||||||
|
|
||||||
// If resolution fails, we should check for some of the following situations:
|
// If resolution fails, we should check for some of the following situations:
|
||||||
// class A {
|
// class A {
|
||||||
@@ -329,14 +329,14 @@ public class CallResolver {
|
|||||||
for (ResolutionCandidate<D> candidate : task.getCandidates()) {
|
for (ResolutionCandidate<D> candidate : task.getCandidates()) {
|
||||||
newCandidates.add(ResolutionCandidate.create(candidate.getDescriptor()));
|
newCandidates.add(ResolutionCandidate.create(candidate.getDescriptor()));
|
||||||
}
|
}
|
||||||
ResolutionTask<D> newContext = new ResolutionTask<D>(newCandidates, task.reference, TemporaryBindingTrace.create(task.trace), task.scope, new DelegatingCall(task.call) {
|
ResolutionTask<D, F> newContext = new ResolutionTask<D, F>(newCandidates, task.reference, TemporaryBindingTrace.create(task.trace), task.scope, new DelegatingCall(task.call) {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<JetExpression> getFunctionLiteralArguments() {
|
public List<JetExpression> getFunctionLiteralArguments() {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
}, task.expectedType, task.dataFlowInfo);
|
}, task.expectedType, task.dataFlowInfo);
|
||||||
OverloadResolutionResultsImpl<D> resultsWithFunctionLiteralsStripped = performResolution(newContext, callTransformationStrategy);
|
OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newContext, callTransformer);
|
||||||
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
|
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
|
||||||
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments());
|
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments());
|
||||||
}
|
}
|
||||||
@@ -346,23 +346,28 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> performResolution(@NotNull ResolutionTask<D> task,
|
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolution(@NotNull ResolutionTask<D, F> task,
|
||||||
@NotNull CallTransformationStrategy<D, D> callTransformationStrategy) {
|
@NotNull CallTransformer<D, F> callTransformer) {
|
||||||
|
|
||||||
for (ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
|
for (ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
|
||||||
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(task.trace);
|
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(task.trace);
|
||||||
CallResolutionContext<D> context = callTransformationStrategy.createCallContext(resolutionCandidate, task, temporaryTrace, task.tracing);
|
Collection<CallResolutionContext<D, F>> contexts = callTransformer.createCallContexts(resolutionCandidate, task, temporaryTrace);
|
||||||
performResolutionForCandidateCall(context, task, temporaryTrace);
|
Collection<ResolvedCallWithTrace<F>> calls = Lists.newArrayList();
|
||||||
|
for (CallResolutionContext<D, F> context : contexts) {
|
||||||
|
|
||||||
Collection<ResolvedCallImpl<D>> calls = callTransformationStrategy.transformResultCall(context, this, task);
|
performResolutionForCandidateCall(context, task);
|
||||||
for (ResolvedCallImpl<D> call : calls) {
|
calls.addAll(callTransformer.transformCall(context, this, task));
|
||||||
task.getResolvedCallMap().put(resolutionCandidate, call);
|
}
|
||||||
|
for (ResolvedCallWithTrace<F> call : calls) {
|
||||||
|
|
||||||
|
task.tracing.bindResolvedCall(call.getTrace(), call);
|
||||||
|
task.getResolvedCalls().add(call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ResolvedCallImpl<D>> successfulCandidates = Sets.newLinkedHashSet();
|
Set<ResolvedCallWithTrace<F>> successfulCandidates = Sets.newLinkedHashSet();
|
||||||
Set<ResolvedCallImpl<D>> failedCandidates = Sets.newLinkedHashSet();
|
Set<ResolvedCallWithTrace<F>> failedCandidates = Sets.newLinkedHashSet();
|
||||||
for (ResolvedCallImpl<D> candidateCall : task.getResolvedCallMap().values()) {
|
for (ResolvedCallWithTrace<F> candidateCall : task.getResolvedCalls()) {
|
||||||
ResolutionStatus status = candidateCall.getStatus();
|
ResolutionStatus status = candidateCall.getStatus();
|
||||||
if (status.isSuccess()) {
|
if (status.isSuccess()) {
|
||||||
successfulCandidates.add(candidateCall);
|
successfulCandidates.add(candidateCall);
|
||||||
@@ -373,23 +378,19 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
OverloadResolutionResultsImpl<D> results = computeResultAndReportErrors(task.trace, task.tracing, successfulCandidates, failedCandidates);
|
OverloadResolutionResultsImpl<F> results = computeResultAndReportErrors(task.trace, task.tracing, successfulCandidates, failedCandidates);
|
||||||
if (!results.isSingleResult()) {
|
if (!results.isSingleResult()) {
|
||||||
checkTypesWithNoCallee(task.toBasic());
|
checkTypesWithNoCallee(task.toBasic());
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> void performResolutionForCandidateCall(@NotNull CallResolutionContext<D> context,
|
private <D extends CallableDescriptor, F extends D> void performResolutionForCandidateCall(@NotNull CallResolutionContext<D, F> context,
|
||||||
@NotNull ResolutionTask<D> task,
|
@NotNull ResolutionTask<D, F> task) {
|
||||||
@NotNull TemporaryBindingTrace temporaryTrace) {
|
|
||||||
ResolvedCallImpl<D> candidateCall = context.candidateCall;
|
ResolvedCallImpl<D> candidateCall = context.candidateCall;
|
||||||
|
|
||||||
candidateCall.setTrace(temporaryTrace);
|
|
||||||
D candidate = candidateCall.getCandidateDescriptor();
|
D candidate = candidateCall.getCandidateDescriptor();
|
||||||
|
|
||||||
context.tracing.bindReference(context.trace, candidateCall);
|
|
||||||
|
|
||||||
if (ErrorUtils.isError(candidate)) {
|
if (ErrorUtils.isError(candidate)) {
|
||||||
candidateCall.addStatus(SUCCESS);
|
candidateCall.addStatus(SUCCESS);
|
||||||
checkTypesWithNoCallee(context.toBasic());
|
checkTypesWithNoCallee(context.toBasic());
|
||||||
@@ -477,7 +478,7 @@ public class CallResolver {
|
|||||||
recordAutoCastIfNecessary(candidateCall.getThisObject(), candidateCall.getTrace());
|
recordAutoCastIfNecessary(candidateCall.getThisObject(), candidateCall.getTrace());
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> ResolutionStatus inferTypeArguments(CallResolutionContext<D> context) {
|
private <D extends CallableDescriptor, F extends D> ResolutionStatus inferTypeArguments(CallResolutionContext<D, F> context) {
|
||||||
ResolvedCallImpl<D> candidateCall = context.candidateCall;
|
ResolvedCallImpl<D> candidateCall = context.candidateCall;
|
||||||
D candidate = candidateCall.getCandidateDescriptor();
|
D candidate = candidateCall.getCandidateDescriptor();
|
||||||
|
|
||||||
@@ -624,7 +625,7 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> ResolutionStatus checkAllValueArguments(CallResolutionContext<D> context) {
|
private <D extends CallableDescriptor, F extends D> ResolutionStatus checkAllValueArguments(CallResolutionContext<D, F> context) {
|
||||||
ResolutionStatus result = checkValueArgumentTypes(context);
|
ResolutionStatus result = checkValueArgumentTypes(context);
|
||||||
ResolvedCall candidateCall = context.candidateCall;
|
ResolvedCall candidateCall = context.candidateCall;
|
||||||
result = result.combine(checkReceiver(context, candidateCall.getResultingDescriptor().getReceiverParameter(), candidateCall.getReceiverArgument()));
|
result = result.combine(checkReceiver(context, candidateCall.getResultingDescriptor().getReceiverParameter(), candidateCall.getReceiverArgument()));
|
||||||
@@ -632,7 +633,7 @@ public class CallResolver {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> ResolutionStatus checkReceiver(CallResolutionContext<D> context, ReceiverDescriptor receiverParameter, ReceiverDescriptor receiverArgument) {
|
private <D extends CallableDescriptor, F extends D> ResolutionStatus checkReceiver(CallResolutionContext<D, F> context, ReceiverDescriptor receiverParameter, ReceiverDescriptor receiverArgument) {
|
||||||
ResolutionStatus result = SUCCESS;
|
ResolutionStatus result = SUCCESS;
|
||||||
if (receiverParameter.exists() && receiverArgument.exists()) {
|
if (receiverParameter.exists() && receiverArgument.exists()) {
|
||||||
ASTNode callOperationNode = context.call.getCallOperationNode();
|
ASTNode callOperationNode = context.call.getCallOperationNode();
|
||||||
@@ -660,7 +661,7 @@ public class CallResolver {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> ResolutionStatus checkValueArgumentTypes(CallResolutionContext<D> context) {
|
private <D extends CallableDescriptor, F extends D> ResolutionStatus checkValueArgumentTypes(CallResolutionContext<D, F> context) {
|
||||||
ResolutionStatus result = SUCCESS;
|
ResolutionStatus result = SUCCESS;
|
||||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : context.candidateCall.getValueArguments().entrySet()) {
|
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : context.candidateCall.getValueArguments().entrySet()) {
|
||||||
ValueParameterDescriptor parameterDescriptor = entry.getKey();
|
ValueParameterDescriptor parameterDescriptor = entry.getKey();
|
||||||
@@ -734,8 +735,8 @@ public class CallResolver {
|
|||||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeResultAndReportErrors(
|
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> computeResultAndReportErrors(
|
||||||
BindingTrace trace,
|
BindingTrace trace,
|
||||||
TracingStrategy tracing,
|
TracingStrategy tracing,
|
||||||
Set<ResolvedCallImpl<D>> successfulCandidates,
|
Set<ResolvedCallWithTrace<D>> successfulCandidates,
|
||||||
Set<ResolvedCallImpl<D>> failedCandidates) {
|
Set<ResolvedCallWithTrace<D>> failedCandidates) {
|
||||||
// TODO : maybe it's better to filter overrides out first, and only then look for the maximally specific
|
// TODO : maybe it's better to filter overrides out first, and only then look for the maximally specific
|
||||||
|
|
||||||
if (successfulCandidates.size() > 0) {
|
if (successfulCandidates.size() > 0) {
|
||||||
@@ -756,8 +757,8 @@ public class CallResolver {
|
|||||||
// and some are not OK at all. In this case we'd like to say "unsafe call" rather than "none applicable"
|
// and some are not OK at all. In this case we'd like to say "unsafe call" rather than "none applicable"
|
||||||
// Used to be: weak errors. Generalized for future extensions
|
// Used to be: weak errors. Generalized for future extensions
|
||||||
for (EnumSet<ResolutionStatus> severityLevel : SEVERITY_LEVELS) {
|
for (EnumSet<ResolutionStatus> severityLevel : SEVERITY_LEVELS) {
|
||||||
Set<ResolvedCallImpl<D>> thisLevel = Sets.newLinkedHashSet();
|
Set<ResolvedCallWithTrace<D>> thisLevel = Sets.newLinkedHashSet();
|
||||||
for (ResolvedCallImpl<D> candidate : failedCandidates) {
|
for (ResolvedCallWithTrace<D> candidate : failedCandidates) {
|
||||||
if (severityLevel.contains(candidate.getStatus())) {
|
if (severityLevel.contains(candidate.getStatus())) {
|
||||||
thisLevel.add(candidate);
|
thisLevel.add(candidate);
|
||||||
}
|
}
|
||||||
@@ -777,7 +778,7 @@ public class CallResolver {
|
|||||||
|
|
||||||
assert false : "Should not be reachable, cause every status must belong to some level";
|
assert false : "Should not be reachable, cause every status must belong to some level";
|
||||||
|
|
||||||
Set<ResolvedCallImpl<D>> noOverrides = OverridingUtil.filterOverrides(failedCandidates, MAP_TO_CANDIDATE);
|
Set<ResolvedCallWithTrace<D>> noOverrides = OverridingUtil.filterOverrides(failedCandidates, MAP_TO_CANDIDATE);
|
||||||
if (noOverrides.size() != 1) {
|
if (noOverrides.size() != 1) {
|
||||||
tracing.noneApplicable(trace, noOverrides);
|
tracing.noneApplicable(trace, noOverrides);
|
||||||
tracing.recordAmbiguity(trace, noOverrides);
|
tracing.recordAmbiguity(trace, noOverrides);
|
||||||
@@ -787,7 +788,7 @@ public class CallResolver {
|
|||||||
failedCandidates = noOverrides;
|
failedCandidates = noOverrides;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvedCallImpl<D> failed = failedCandidates.iterator().next();
|
ResolvedCallWithTrace<D> failed = failedCandidates.iterator().next();
|
||||||
failed.getTrace().commit();
|
failed.getTrace().commit();
|
||||||
return OverloadResolutionResultsImpl.singleFailedCandidate(failed);
|
return OverloadResolutionResultsImpl.singleFailedCandidate(failed);
|
||||||
}
|
}
|
||||||
@@ -797,18 +798,18 @@ public class CallResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <D extends CallableDescriptor> boolean allClean(Collection<ResolvedCallImpl<D>> results) {
|
private static <D extends CallableDescriptor> boolean allClean(Collection<ResolvedCallWithTrace<D>> results) {
|
||||||
for (ResolvedCallImpl<D> result : results) {
|
for (ResolvedCallWithTrace<D> result : results) {
|
||||||
if (result.isDirty()) return false;
|
if (result.isDirty()) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> chooseAndReportMaximallySpecific(Set<ResolvedCallImpl<D>> candidates, boolean discriminateGenerics) {
|
private <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> chooseAndReportMaximallySpecific(Set<ResolvedCallWithTrace<D>> candidates, boolean discriminateGenerics) {
|
||||||
if (candidates.size() != 1) {
|
if (candidates.size() != 1) {
|
||||||
Set<ResolvedCallImpl<D>> cleanCandidates = Sets.newLinkedHashSet(candidates);
|
Set<ResolvedCallWithTrace<D>> cleanCandidates = Sets.newLinkedHashSet(candidates);
|
||||||
for (Iterator<ResolvedCallImpl<D>> iterator = cleanCandidates.iterator(); iterator.hasNext(); ) {
|
for (Iterator<ResolvedCallWithTrace<D>> iterator = cleanCandidates.iterator(); iterator.hasNext(); ) {
|
||||||
ResolvedCallImpl<D> candidate = iterator.next();
|
ResolvedCallWithTrace<D> candidate = iterator.next();
|
||||||
if (candidate.isDirty()) {
|
if (candidate.isDirty()) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
@@ -817,27 +818,31 @@ public class CallResolver {
|
|||||||
if (cleanCandidates.isEmpty()) {
|
if (cleanCandidates.isEmpty()) {
|
||||||
cleanCandidates = candidates;
|
cleanCandidates = candidates;
|
||||||
}
|
}
|
||||||
ResolvedCallImpl<D> maximallySpecific = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, false);
|
ResolvedCallWithTrace<D> maximallySpecific = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, false);
|
||||||
if (maximallySpecific != null) {
|
if (maximallySpecific != null) {
|
||||||
return OverloadResolutionResultsImpl.success(maximallySpecific);
|
return OverloadResolutionResultsImpl.success(maximallySpecific);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (discriminateGenerics) {
|
if (discriminateGenerics) {
|
||||||
ResolvedCallImpl<D> maximallySpecificGenericsDiscriminated = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, true);
|
ResolvedCallWithTrace<D> maximallySpecificGenericsDiscriminated = overloadingConflictResolver.findMaximallySpecific(cleanCandidates, true);
|
||||||
if (maximallySpecificGenericsDiscriminated != null) {
|
if (maximallySpecificGenericsDiscriminated != null) {
|
||||||
return OverloadResolutionResultsImpl.success(maximallySpecificGenericsDiscriminated);
|
return OverloadResolutionResultsImpl.success(maximallySpecificGenericsDiscriminated);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<ResolvedCallImpl<D>> noOverrides = OverridingUtil.filterOverrides(candidates, MAP_TO_RESULT);
|
Set<ResolvedCallWithTrace<D>> noOverrides = OverridingUtil.filterOverrides(candidates, MAP_TO_RESULT);
|
||||||
|
|
||||||
return OverloadResolutionResultsImpl.ambiguity(noOverrides);
|
return OverloadResolutionResultsImpl.ambiguity(noOverrides);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ResolvedCallImpl<D> result = candidates.iterator().next();
|
ResolvedCallWithTrace<D> result = candidates.iterator().next();
|
||||||
|
|
||||||
TemporaryBindingTrace temporaryTrace = result.getTrace();
|
TemporaryBindingTrace temporaryTrace = result.getTrace();
|
||||||
temporaryTrace.commit();
|
temporaryTrace.commit();
|
||||||
|
|
||||||
|
if (result instanceof VariableAsFunctionResolvedCall) {
|
||||||
|
((VariableAsFunctionResolvedCall)result).getVariableCall().getTrace().commit();
|
||||||
|
}
|
||||||
return OverloadResolutionResultsImpl.success(result);
|
return OverloadResolutionResultsImpl.success(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -868,13 +873,12 @@ public class CallResolver {
|
|||||||
|
|
||||||
BindingTraceContext trace = new BindingTraceContext();
|
BindingTraceContext trace = new BindingTraceContext();
|
||||||
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(trace);
|
TemporaryBindingTrace temporaryBindingTrace = TemporaryBindingTrace.create(trace);
|
||||||
Set<ResolvedCallImpl<FunctionDescriptor>> calls = Sets.newLinkedHashSet();
|
Set<ResolvedCallWithTrace<FunctionDescriptor>> calls = Sets.newLinkedHashSet();
|
||||||
for (ResolutionCandidate<FunctionDescriptor> candidate : candidates) {
|
for (ResolutionCandidate<FunctionDescriptor> candidate : candidates) {
|
||||||
ResolvedCallImpl<FunctionDescriptor> call = ResolvedCallImpl.create(candidate);
|
ResolvedCallImpl<FunctionDescriptor> call = ResolvedCallImpl.create(candidate, temporaryBindingTrace);
|
||||||
call.setTrace(temporaryBindingTrace);
|
|
||||||
calls.add(call);
|
calls.add(call);
|
||||||
}
|
}
|
||||||
return computeResultAndReportErrors(trace, TracingStrategy.EMPTY, calls, Collections.<ResolvedCallImpl<FunctionDescriptor>>emptySet());
|
return computeResultAndReportErrors(trace, TracingStrategy.EMPTY, calls, Collections.<ResolvedCallWithTrace<FunctionDescriptor>>emptySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ResolutionCandidate<FunctionDescriptor>> findCandidatesByExactSignature(JetScope scope, ReceiverDescriptor receiver,
|
private List<ResolutionCandidate<FunctionDescriptor>> findCandidatesByExactSignature(JetScope scope, ReceiverDescriptor receiver,
|
||||||
|
|||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author svtk
|
|
||||||
*/
|
|
||||||
public interface CallTransformationStrategy<D extends CallableDescriptor, R extends D> {
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
CallResolutionContext<D> createCallContext(@NotNull ResolutionCandidate<D> candidate,
|
|
||||||
@NotNull ResolutionTask<D> task,
|
|
||||||
@NotNull BindingTrace trace,
|
|
||||||
@NotNull TracingStrategy tracing);
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
Collection<ResolvedCallImpl<R>> transformResultCall(@NotNull CallResolutionContext<D> callResolutionContext,
|
|
||||||
@NotNull CallResolver callResolver,
|
|
||||||
@NotNull ResolutionTask<D> task);
|
|
||||||
|
|
||||||
CallTransformationStrategy<VariableDescriptor, VariableDescriptor>
|
|
||||||
PROPERTY_CALL_TRANSFORMATION_STRATEGY = new CallTransformationStrategy<VariableDescriptor, VariableDescriptor>() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public CallResolutionContext<VariableDescriptor> createCallContext(@NotNull ResolutionCandidate<VariableDescriptor> candidate,
|
|
||||||
@NotNull ResolutionTask<VariableDescriptor> task, @NotNull BindingTrace trace, @NotNull TracingStrategy tracing) {
|
|
||||||
ResolvedCallImpl<VariableDescriptor> candidateCall = ResolvedCallImpl.create(candidate);
|
|
||||||
return new CallResolutionContext<VariableDescriptor>(candidateCall, task, trace, tracing);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<ResolvedCallImpl<VariableDescriptor>> transformResultCall(@NotNull CallResolutionContext<VariableDescriptor> context,
|
|
||||||
@NotNull CallResolver callResolver, @NotNull ResolutionTask<VariableDescriptor> task) {
|
|
||||||
return Collections.singleton(context.candidateCall);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CallTransformationStrategy<FunctionDescriptor, FunctionDescriptor>
|
|
||||||
FUNCTION_CALL_TRANSFORMATION_STRATEGY = new CallTransformationStrategy<FunctionDescriptor, FunctionDescriptor>() {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public CallResolutionContext<FunctionDescriptor> createCallContext(@NotNull ResolutionCandidate<FunctionDescriptor> candidate,
|
|
||||||
@NotNull ResolutionTask<FunctionDescriptor> task,
|
|
||||||
@NotNull BindingTrace trace,
|
|
||||||
@NotNull TracingStrategy tracing) {
|
|
||||||
if (candidate.getDescriptor() instanceof FunctionDescriptor) {
|
|
||||||
return new CallResolutionContext<FunctionDescriptor>(ResolvedCallImpl.create(candidate), task, trace, tracing);
|
|
||||||
}
|
|
||||||
assert candidate.getDescriptor() instanceof VariableDescriptor;
|
|
||||||
Call propertyCall = new DelegatingCall(task.call) {
|
|
||||||
@Override
|
|
||||||
public JetValueArgumentList getValueArgumentList() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<JetExpression> getFunctionLiteralArguments() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<JetTypeProjection> getTypeArguments() {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JetTypeArgumentList getTypeArgumentList() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return new CallResolutionContext<FunctionDescriptor>(ResolvedCallImpl.create(candidate), task, trace, tracing, propertyCall);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public Collection<ResolvedCallImpl<FunctionDescriptor>> transformResultCall(@NotNull CallResolutionContext<FunctionDescriptor> context,
|
|
||||||
@NotNull CallResolver callResolver, @NotNull ResolutionTask<FunctionDescriptor> task) {
|
|
||||||
FunctionDescriptor descriptor = context.candidateCall.getCandidateDescriptor();
|
|
||||||
if (descriptor instanceof FunctionDescriptor) {
|
|
||||||
return Collections.singleton(context.candidateCall);
|
|
||||||
}
|
|
||||||
assert descriptor instanceof VariableDescriptor;
|
|
||||||
BasicResolutionContext basicResolutionContext =
|
|
||||||
BasicResolutionContext.create(context.trace, context.scope, task.call, context.expectedType, context.dataFlowInfo);
|
|
||||||
OverloadResolutionResults<FunctionDescriptor> results =
|
|
||||||
callResolver.resolveCallWithGivenName(basicResolutionContext, task.reference, "invoke");
|
|
||||||
return ((OverloadResolutionResultsImpl<FunctionDescriptor>)results).getResultingCalls();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.Collections2;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CallTransformer treats specially 'variable as function' call case, other cases keeps unchanged (base realization).
|
||||||
|
*
|
||||||
|
* For the call 'b.foo(1)' where foo is a variable that has method 'invoke' (for example of function type)
|
||||||
|
* CallTransformer creates two contexts, two calls in each, and performs second ('invoke') call resolution:
|
||||||
|
*
|
||||||
|
* context#1. calls: 'b.foo' 'invoke(1)'
|
||||||
|
* context#2. calls: 'foo' 'b.invoke(1)'
|
||||||
|
*
|
||||||
|
* If success VariableAsFunctionResolvedCall is created.
|
||||||
|
*
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public class CallTransformer<D extends CallableDescriptor, F extends D> {
|
||||||
|
private CallTransformer() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns two contexts for 'variable as function' case (in FUNCTION_CALL_TRANSFORMER), one context otherwise
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public Collection<CallResolutionContext<D, F>> createCallContexts(@NotNull ResolutionCandidate<D> candidate,
|
||||||
|
@NotNull ResolutionTask<D, F> task,
|
||||||
|
@NotNull TemporaryBindingTrace temporaryTrace) {
|
||||||
|
|
||||||
|
ResolvedCallImpl<D> candidateCall = ResolvedCallImpl.create(candidate, temporaryTrace);
|
||||||
|
return Collections.singleton(CallResolutionContext.create(candidateCall, task, temporaryTrace, task.tracing));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns collection of resolved calls for 'invoke' for 'variable as function' case (in FUNCTION_CALL_TRANSFORMER),
|
||||||
|
* the resolved call from callResolutionContext otherwise
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public Collection<ResolvedCallWithTrace<F>> transformCall(@NotNull CallResolutionContext<D, F> callResolutionContext,
|
||||||
|
@NotNull CallResolver callResolver,
|
||||||
|
@NotNull ResolutionTask<D, F> task) {
|
||||||
|
|
||||||
|
return Collections.singleton((ResolvedCallWithTrace<F>)callResolutionContext.candidateCall);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static CallTransformer<VariableDescriptor, VariableDescriptor> PROPERTY_CALL_TRANSFORMER = new CallTransformer<VariableDescriptor, VariableDescriptor>();
|
||||||
|
|
||||||
|
public static CallTransformer<CallableDescriptor, FunctionDescriptor> FUNCTION_CALL_TRANSFORMER = new CallTransformer<CallableDescriptor, FunctionDescriptor>() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<CallResolutionContext<CallableDescriptor, FunctionDescriptor>> createCallContexts(@NotNull ResolutionCandidate<CallableDescriptor> candidate,
|
||||||
|
@NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task, @NotNull TemporaryBindingTrace temporaryTrace) {
|
||||||
|
|
||||||
|
if (candidate.getDescriptor() instanceof FunctionDescriptor) {
|
||||||
|
return super.createCallContexts(candidate, task, temporaryTrace);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert candidate.getDescriptor() instanceof VariableDescriptor;
|
||||||
|
|
||||||
|
boolean hasReceiver = candidate.getReceiverArgument().exists();
|
||||||
|
Call variableCall = stripCallArguments(task);
|
||||||
|
if (!hasReceiver) {
|
||||||
|
CallResolutionContext<CallableDescriptor, FunctionDescriptor> context = CallResolutionContext.create(
|
||||||
|
ResolvedCallImpl.create(candidate, temporaryTrace), task, temporaryTrace, task.tracing, variableCall);
|
||||||
|
return Collections.singleton(context);
|
||||||
|
}
|
||||||
|
Call variableCallWithoutReceiver = stripReceiver(variableCall);
|
||||||
|
CallResolutionContext<CallableDescriptor, FunctionDescriptor> contextWithReceiver = createContextWithChainedTrace(
|
||||||
|
candidate, variableCall, temporaryTrace, task);
|
||||||
|
|
||||||
|
ResolutionCandidate<CallableDescriptor> candidateWithoutReceiver = ResolutionCandidate.create(
|
||||||
|
candidate.getDescriptor(), candidate.getThisObject(), ReceiverDescriptor.NO_RECEIVER);
|
||||||
|
|
||||||
|
CallResolutionContext<CallableDescriptor, FunctionDescriptor> contextWithoutReceiver = createContextWithChainedTrace(
|
||||||
|
candidateWithoutReceiver, variableCallWithoutReceiver, temporaryTrace, task);
|
||||||
|
|
||||||
|
contextWithoutReceiver.receiverForVariableAsFunctionSecondCall = variableCall.getExplicitReceiver();
|
||||||
|
|
||||||
|
return Lists.newArrayList(contextWithReceiver, contextWithoutReceiver);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CallResolutionContext<CallableDescriptor, FunctionDescriptor> createContextWithChainedTrace(ResolutionCandidate<CallableDescriptor> candidate,
|
||||||
|
Call call, TemporaryBindingTrace temporaryTrace, ResolutionTask<CallableDescriptor, FunctionDescriptor> task) {
|
||||||
|
|
||||||
|
ChainedTemporaryBindingTrace chainedTrace = ChainedTemporaryBindingTrace.create(temporaryTrace);
|
||||||
|
ResolvedCallImpl<CallableDescriptor> resolvedCall = ResolvedCallImpl.create(candidate, chainedTrace);
|
||||||
|
return CallResolutionContext.create(resolvedCall, task, chainedTrace, task.tracing, call);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Call stripCallArguments(@NotNull ResolutionTask<CallableDescriptor, FunctionDescriptor> task) {
|
||||||
|
return new DelegatingCall(task.call) {
|
||||||
|
@Override
|
||||||
|
public JetValueArgumentList getValueArgumentList() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<? extends ValueArgument> getValueArguments() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetExpression> getFunctionLiteralArguments() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<JetTypeProjection> getTypeArguments() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetTypeArgumentList getTypeArgumentList() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private Call stripReceiver(@NotNull Call variableCall) {
|
||||||
|
return new DelegatingCall(variableCall) {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getExplicitReceiver() {
|
||||||
|
return ReceiverDescriptor.NO_RECEIVER;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<ResolvedCallWithTrace<FunctionDescriptor>> transformCall(@NotNull final CallResolutionContext<CallableDescriptor, FunctionDescriptor> context,
|
||||||
|
@NotNull CallResolver callResolver, @NotNull final ResolutionTask<CallableDescriptor, FunctionDescriptor> task) {
|
||||||
|
|
||||||
|
final CallableDescriptor descriptor = context.candidateCall.getCandidateDescriptor();
|
||||||
|
if (descriptor instanceof FunctionDescriptor) {
|
||||||
|
return super.transformCall(context, callResolver, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert descriptor instanceof VariableDescriptor;
|
||||||
|
JetType returnType = descriptor.getReturnType();
|
||||||
|
if (returnType == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
final ResolvedCallWithTrace<VariableDescriptor> variableResolvedCall = (ResolvedCallWithTrace)context.candidateCall;
|
||||||
|
|
||||||
|
Call functionCall = createFunctionCall(context, task, returnType);
|
||||||
|
|
||||||
|
final TemporaryBindingTrace variableCallTrace = context.candidateCall.getTrace();
|
||||||
|
BasicResolutionContext basicResolutionContext = BasicResolutionContext.create(variableCallTrace, context.scope, functionCall, context.expectedType, context.dataFlowInfo);
|
||||||
|
|
||||||
|
// 'invoke' call resolve
|
||||||
|
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithGivenName(basicResolutionContext, task.reference, "invoke");
|
||||||
|
Collection<ResolvedCallWithTrace<FunctionDescriptor>> calls = ((OverloadResolutionResultsImpl<FunctionDescriptor>)results).getResultingCalls();
|
||||||
|
|
||||||
|
return Collections2.transform(calls, new Function<ResolvedCallWithTrace<FunctionDescriptor>, ResolvedCallWithTrace<FunctionDescriptor>>() {
|
||||||
|
@Override
|
||||||
|
public ResolvedCallWithTrace<FunctionDescriptor> apply(ResolvedCallWithTrace<FunctionDescriptor> functionResolvedCall) {
|
||||||
|
return new VariableAsFunctionResolvedCall(functionResolvedCall, variableResolvedCall);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private Call createFunctionCall(final CallResolutionContext<CallableDescriptor, FunctionDescriptor> context,
|
||||||
|
final ResolutionTask<CallableDescriptor, FunctionDescriptor> task, JetType returnType) {
|
||||||
|
|
||||||
|
final ExpressionReceiver receiverFromVariable = new ExpressionReceiver(task.reference, returnType);
|
||||||
|
final JetSimpleNameExpression invokeExpression = (JetSimpleNameExpression) JetPsiFactory.createExpression(
|
||||||
|
task.call.getCallElement().getProject(), "invoke");
|
||||||
|
|
||||||
|
return new DelegatingCall(task.call) {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getExplicitReceiver() {
|
||||||
|
return context.receiverForVariableAsFunctionSecondCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getThisObject() {
|
||||||
|
return receiverFromVariable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JetExpression getCalleeExpression() {
|
||||||
|
return invokeExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiElement getCallElement() {
|
||||||
|
if (task.call.getCallElement() instanceof JetCallElement) {
|
||||||
|
//to report errors properly
|
||||||
|
JetValueArgumentList list = ((JetCallElement)task.call.getCallElement()).getValueArgumentList();
|
||||||
|
if (list != null) {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return invokeExpression;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
+2
-2
@@ -26,7 +26,7 @@ import java.util.Collection;
|
|||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public interface MemberPrioritizer<D extends CallableDescriptor> {
|
public interface CallableDescriptorCollector<D extends CallableDescriptor> {
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<D> getNonExtensionsByName(JetScope scope, String name);
|
Collection<D> getNonExtensionsByName(JetScope scope, String name);
|
||||||
|
|
||||||
@@ -34,5 +34,5 @@ public interface MemberPrioritizer<D extends CallableDescriptor> {
|
|||||||
Collection<D> getMembersByName(@NotNull JetType receiver, String name);
|
Collection<D> getMembersByName(@NotNull JetType receiver, String name);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Collection<D> getExtensionsByName(JetScope scope, String name);
|
Collection<D> getNonMembersByName(JetScope scope, String name);
|
||||||
}
|
}
|
||||||
+23
-47
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -34,11 +33,9 @@ import java.util.*;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class MemberPrioritizers {
|
public class CallableDescriptorCollectors {
|
||||||
|
|
||||||
|
|
||||||
/*package*/ static MemberPrioritizer<FunctionDescriptor> FUNCTION_TASK_PRIORITIZER = new MemberPrioritizer<FunctionDescriptor>() {
|
|
||||||
|
|
||||||
|
/*package*/ static CallableDescriptorCollector<FunctionDescriptor> FUNCTIONS = new CallableDescriptorCollector<FunctionDescriptor>() {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -51,8 +48,6 @@ public class MemberPrioritizers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
addConstructors(scope, name, functions);
|
addConstructors(scope, name, functions);
|
||||||
|
|
||||||
addVariableAsFunction(scope, name, functions, false);
|
|
||||||
return functions;
|
return functions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,22 +57,13 @@ public class MemberPrioritizers {
|
|||||||
JetScope receiverScope = receiverType.getMemberScope();
|
JetScope receiverScope = receiverType.getMemberScope();
|
||||||
Set<FunctionDescriptor> members = Sets.newHashSet(receiverScope.getFunctions(name));
|
Set<FunctionDescriptor> members = Sets.newHashSet(receiverScope.getFunctions(name));
|
||||||
addConstructors(receiverScope, name, members);
|
addConstructors(receiverScope, name, members);
|
||||||
addVariableAsFunction(receiverScope, name, members, false);
|
|
||||||
return members;
|
return members;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<FunctionDescriptor> getExtensionsByName(JetScope scope, String name) {
|
public Collection<FunctionDescriptor> getNonMembersByName(JetScope scope, String name) {
|
||||||
Set<FunctionDescriptor> extensionFunctions = Sets.newHashSet(scope.getFunctions(name));
|
return scope.getFunctions(name);
|
||||||
for (Iterator<FunctionDescriptor> iterator = extensionFunctions.iterator(); iterator.hasNext(); ) {
|
|
||||||
FunctionDescriptor descriptor = iterator.next();
|
|
||||||
if (!descriptor.getReceiverParameter().exists()) {
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
addVariableAsFunction(scope, name, extensionFunctions, true);
|
|
||||||
return extensionFunctions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConstructors(JetScope scope, String name, Collection<FunctionDescriptor> functions) {
|
private void addConstructors(JetScope scope, String name, Collection<FunctionDescriptor> functions) {
|
||||||
@@ -87,25 +73,9 @@ public class MemberPrioritizers {
|
|||||||
functions.addAll(classDescriptor.getConstructors());
|
functions.addAll(classDescriptor.getConstructors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVariableAsFunction(JetScope scope, String name, Set<FunctionDescriptor> functions, boolean receiverNeeded) {
|
|
||||||
VariableDescriptor variable = scope.getLocalVariable(name);
|
|
||||||
if (variable == null) {
|
|
||||||
variable = DescriptorUtils.filterNonExtensionProperty(scope.getProperties(name));
|
|
||||||
}
|
|
||||||
if (variable != null) {
|
|
||||||
JetType outType = variable.getType();
|
|
||||||
if (outType != null && JetStandardClasses.isFunctionType(outType)) {
|
|
||||||
VariableAsFunctionDescriptor functionDescriptor = VariableAsFunctionDescriptor.create(variable);
|
|
||||||
if ((functionDescriptor.getReceiverParameter().exists()) == receiverNeeded) {
|
|
||||||
functions.add(functionDescriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*package*/ static MemberPrioritizer<VariableDescriptor> VARIABLE_TASK_PRIORITIZER = new MemberPrioritizer<VariableDescriptor>() {
|
/*package*/ static CallableDescriptorCollector<VariableDescriptor> VARIABLES = new CallableDescriptorCollector<VariableDescriptor>() {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@@ -126,17 +96,19 @@ public class MemberPrioritizers {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<VariableDescriptor> getExtensionsByName(JetScope scope, String name) {
|
public Collection<VariableDescriptor> getNonMembersByName(JetScope scope, String name) {
|
||||||
return Collections2.filter(scope.getProperties(name), new Predicate<VariableDescriptor>() {
|
Collection<VariableDescriptor> result = Sets.newLinkedHashSet();
|
||||||
@Override
|
|
||||||
public boolean apply(@Nullable VariableDescriptor variableDescriptor) {
|
VariableDescriptor localVariable = scope.getLocalVariable(name);
|
||||||
return (variableDescriptor != null) && variableDescriptor.getReceiverParameter().exists();
|
if (localVariable != null) {
|
||||||
}
|
result.add(localVariable);
|
||||||
});
|
}
|
||||||
|
result.addAll(scope.getProperties(name));
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*package*/ static MemberPrioritizer<VariableDescriptor> PROPERTY_TASK_PRIORITIZER = new MemberPrioritizer<VariableDescriptor>() {
|
/*package*/ static CallableDescriptorCollector<VariableDescriptor> PROPERTIES = new CallableDescriptorCollector<VariableDescriptor>() {
|
||||||
private Collection<VariableDescriptor> filterProperties(Collection<? extends VariableDescriptor> variableDescriptors) {
|
private Collection<VariableDescriptor> filterProperties(Collection<? extends VariableDescriptor> variableDescriptors) {
|
||||||
ArrayList<VariableDescriptor> properties = Lists.newArrayList();
|
ArrayList<VariableDescriptor> properties = Lists.newArrayList();
|
||||||
for (VariableDescriptor descriptor : variableDescriptors) {
|
for (VariableDescriptor descriptor : variableDescriptors) {
|
||||||
@@ -150,19 +122,23 @@ public class MemberPrioritizers {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<VariableDescriptor> getNonExtensionsByName(JetScope scope, String name) {
|
public Collection<VariableDescriptor> getNonExtensionsByName(JetScope scope, String name) {
|
||||||
return filterProperties(VARIABLE_TASK_PRIORITIZER.getNonExtensionsByName(scope, name));
|
return filterProperties(VARIABLES.getNonExtensionsByName(scope, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<VariableDescriptor> getMembersByName(@NotNull JetType receiver, String name) {
|
public Collection<VariableDescriptor> getMembersByName(@NotNull JetType receiver, String name) {
|
||||||
return filterProperties(VARIABLE_TASK_PRIORITIZER.getMembersByName(receiver, name));
|
return filterProperties(VARIABLES.getMembersByName(receiver, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<VariableDescriptor> getExtensionsByName(JetScope scope, String name) {
|
public Collection<VariableDescriptor> getNonMembersByName(JetScope scope, String name) {
|
||||||
return filterProperties(VARIABLE_TASK_PRIORITIZER.getExtensionsByName(scope, name));
|
return filterProperties(VARIABLES.getNonMembersByName(scope, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*package*/ static List<CallableDescriptorCollector<? extends CallableDescriptor>> FUNCTIONS_AND_VARIABLES = Lists.newArrayList(
|
||||||
|
FUNCTIONS, VARIABLES);
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,12 @@ public class DelegatingCall implements Call {
|
|||||||
return delegate.getExplicitReceiver();
|
return delegate.getExplicitReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getThisObject() {
|
||||||
|
return delegate.getThisObject();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetExpression getCalleeExpression() {
|
public JetExpression getCalleeExpression() {
|
||||||
|
|||||||
+9
-9
@@ -27,42 +27,42 @@ import java.util.Collections;
|
|||||||
*/
|
*/
|
||||||
/*package*/ class OverloadResolutionResultsImpl<D extends CallableDescriptor> implements OverloadResolutionResults<D> {
|
/*package*/ class OverloadResolutionResultsImpl<D extends CallableDescriptor> implements OverloadResolutionResults<D> {
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> success(@NotNull ResolvedCallImpl<D> descriptor) {
|
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> success(@NotNull ResolvedCallWithTrace<D> descriptor) {
|
||||||
return new OverloadResolutionResultsImpl<D>(Code.SUCCESS, Collections.singleton(descriptor));
|
return new OverloadResolutionResultsImpl<D>(Code.SUCCESS, Collections.singleton(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> nameNotFound() {
|
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> nameNotFound() {
|
||||||
return new OverloadResolutionResultsImpl<D>(Code.NAME_NOT_FOUND, Collections.<ResolvedCallImpl<D>>emptyList());
|
return new OverloadResolutionResultsImpl<D>(Code.NAME_NOT_FOUND, Collections.<ResolvedCallWithTrace<D>>emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> singleFailedCandidate(ResolvedCallImpl<D> candidate) {
|
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> singleFailedCandidate(ResolvedCallWithTrace<D> candidate) {
|
||||||
return new OverloadResolutionResultsImpl<D>(Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH, Collections.singleton(candidate));
|
return new OverloadResolutionResultsImpl<D>(Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH, Collections.singleton(candidate));
|
||||||
}
|
}
|
||||||
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> manyFailedCandidates(Collection<ResolvedCallImpl<D>> failedCandidates) {
|
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> manyFailedCandidates(Collection<ResolvedCallWithTrace<D>> failedCandidates) {
|
||||||
return new OverloadResolutionResultsImpl<D>(Code.MANY_FAILED_CANDIDATES, failedCandidates);
|
return new OverloadResolutionResultsImpl<D>(Code.MANY_FAILED_CANDIDATES, failedCandidates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> ambiguity(Collection<ResolvedCallImpl<D>> descriptors) {
|
public static <D extends CallableDescriptor> OverloadResolutionResultsImpl<D> ambiguity(Collection<ResolvedCallWithTrace<D>> descriptors) {
|
||||||
return new OverloadResolutionResultsImpl<D>(Code.AMBIGUITY, descriptors);
|
return new OverloadResolutionResultsImpl<D>(Code.AMBIGUITY, descriptors);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Collection<ResolvedCallImpl<D>> results;
|
private final Collection<ResolvedCallWithTrace<D>> results;
|
||||||
private final Code resultCode;
|
private final Code resultCode;
|
||||||
|
|
||||||
private OverloadResolutionResultsImpl(@NotNull Code resultCode, @NotNull Collection<ResolvedCallImpl<D>> results) {
|
private OverloadResolutionResultsImpl(@NotNull Code resultCode, @NotNull Collection<ResolvedCallWithTrace<D>> results) {
|
||||||
this.results = results;
|
this.results = results;
|
||||||
this.resultCode = resultCode;
|
this.resultCode = resultCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public Collection<ResolvedCallImpl<D>> getResultingCalls() {
|
public Collection<ResolvedCallWithTrace<D>> getResultingCalls() {
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public ResolvedCallImpl<D> getResultingCall() {
|
public ResolvedCallWithTrace<D> getResultingCall() {
|
||||||
assert isSingleResult();
|
assert isSingleResult();
|
||||||
return results.iterator().next();
|
return results.iterator().next();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -30,9 +30,9 @@ import java.util.Collection;
|
|||||||
public class OverloadResolutionResultsUtil {
|
public class OverloadResolutionResultsUtil {
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <D extends CallableDescriptor> OverloadResolutionResults<D> ambiguity(OverloadResolutionResults<D> results1, OverloadResolutionResults<D> results2) {
|
public static <D extends CallableDescriptor> OverloadResolutionResults<D> ambiguity(OverloadResolutionResults<D> results1, OverloadResolutionResults<D> results2) {
|
||||||
Collection<ResolvedCallImpl<D>> resultingCalls = Lists.newArrayList();
|
Collection<ResolvedCallWithTrace<D>> resultingCalls = Lists.newArrayList();
|
||||||
resultingCalls.addAll((Collection<ResolvedCallImpl<D>>) results1.getResultingCalls());
|
resultingCalls.addAll((Collection<ResolvedCallWithTrace<D>>) results1.getResultingCalls());
|
||||||
resultingCalls.addAll((Collection<ResolvedCallImpl<D>>) results2.getResultingCalls());
|
resultingCalls.addAll((Collection<ResolvedCallWithTrace<D>>) results2.getResultingCalls());
|
||||||
return OverloadResolutionResultsImpl.ambiguity(resultingCalls);
|
return OverloadResolutionResultsImpl.ambiguity(resultingCalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-7
@@ -39,23 +39,23 @@ import java.util.Set;
|
|||||||
public class OverloadingConflictResolver {
|
public class OverloadingConflictResolver {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public <D extends CallableDescriptor> ResolvedCallImpl<D> findMaximallySpecific(Set<ResolvedCallImpl<D>> candidates, boolean discriminateGenericDescriptors) {
|
public <D extends CallableDescriptor> ResolvedCallWithTrace<D> findMaximallySpecific(Set<ResolvedCallWithTrace<D>> candidates, boolean discriminateGenericDescriptors) {
|
||||||
// Different autocasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects
|
// Different autocasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects
|
||||||
Set<ResolvedCallImpl<D>> maximallySpecific = new THashSet<ResolvedCallImpl<D>>(new TObjectHashingStrategy<ResolvedCallImpl<D>>() {
|
Set<ResolvedCallWithTrace<D>> maximallySpecific = new THashSet<ResolvedCallWithTrace<D>>(new TObjectHashingStrategy<ResolvedCallWithTrace<D>>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(ResolvedCallImpl<D> o1, ResolvedCallImpl<D> o2) {
|
public boolean equals(ResolvedCallWithTrace<D> o1, ResolvedCallWithTrace<D> o2) {
|
||||||
return o1 == null ? o2 == null : o1.getResultingDescriptor().equals(o2.getResultingDescriptor());
|
return o1 == null ? o2 == null : o1.getResultingDescriptor().equals(o2.getResultingDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int computeHashCode(ResolvedCallImpl<D> object) {
|
public int computeHashCode(ResolvedCallWithTrace<D> object) {
|
||||||
return object == null ? 0 : object.getResultingDescriptor().hashCode();
|
return object == null ? 0 : object.getResultingDescriptor().hashCode();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
meLoop:
|
meLoop:
|
||||||
for (ResolvedCallImpl<D> candidateCall : candidates) {
|
for (ResolvedCallWithTrace<D> candidateCall : candidates) {
|
||||||
D me = candidateCall.getResultingDescriptor();
|
D me = candidateCall.getResultingDescriptor();
|
||||||
for (ResolvedCallImpl<D> otherCall : candidates) {
|
for (ResolvedCallWithTrace<D> otherCall : candidates) {
|
||||||
D other = otherCall.getResultingDescriptor();
|
D other = otherCall.getResultingDescriptor();
|
||||||
if (other == me) continue;
|
if (other == me) continue;
|
||||||
if (!moreSpecific(me, other, discriminateGenericDescriptors) || moreSpecific(other, me, discriminateGenericDescriptors)) {
|
if (!moreSpecific(me, other, discriminateGenericDescriptors) || moreSpecific(other, me, discriminateGenericDescriptors)) {
|
||||||
@@ -65,7 +65,7 @@ public class OverloadingConflictResolver {
|
|||||||
maximallySpecific.add(candidateCall);
|
maximallySpecific.add(candidateCall);
|
||||||
}
|
}
|
||||||
if (maximallySpecific.size() == 1) {
|
if (maximallySpecific.size() == 1) {
|
||||||
ResolvedCallImpl<D> result = maximallySpecific.iterator().next();
|
ResolvedCallWithTrace<D> result = maximallySpecific.iterator().next();
|
||||||
result.getTrace().commit();
|
result.getTrace().commit();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -31,15 +31,21 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
*/
|
*/
|
||||||
public class ResolutionCandidate<D extends CallableDescriptor> {
|
public class ResolutionCandidate<D extends CallableDescriptor> {
|
||||||
private final D candidateDescriptor;
|
private final D candidateDescriptor;
|
||||||
private ReceiverDescriptor thisObject = NO_RECEIVER; // receiver object of a method
|
private ReceiverDescriptor thisObject; // receiver object of a method
|
||||||
private ReceiverDescriptor receiverArgument = NO_RECEIVER; // receiver of an extension function
|
private ReceiverDescriptor receiverArgument; // receiver of an extension function
|
||||||
|
|
||||||
private ResolutionCandidate(@NotNull D descriptor) {
|
private ResolutionCandidate(@NotNull D descriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument) {
|
||||||
candidateDescriptor = descriptor;
|
this.candidateDescriptor = descriptor;
|
||||||
|
this.thisObject = thisObject;
|
||||||
|
this.receiverArgument = receiverArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor) {
|
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor) {
|
||||||
return new ResolutionCandidate<D>(descriptor);
|
return new ResolutionCandidate<D>(descriptor, NO_RECEIVER, NO_RECEIVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <D extends CallableDescriptor> ResolutionCandidate<D> create(@NotNull D descriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument) {
|
||||||
|
return new ResolutionCandidate<D>(descriptor, thisObject, receiverArgument);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThisObject(@NotNull ReceiverDescriptor thisObject) {
|
public void setThisObject(@NotNull ReceiverDescriptor thisObject) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import java.util.Map;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ResolutionDebugInfo {
|
public class ResolutionDebugInfo {
|
||||||
public static final WritableSlice<One, List<? extends ResolutionTask<? extends CallableDescriptor>>> TASKS = Slices.createSimpleSlice();
|
public static final WritableSlice<One, List<? extends ResolutionTask<? extends CallableDescriptor, ?>>> TASKS = Slices.createSimpleSlice();
|
||||||
public static final WritableSlice<One, ResolvedCall<? extends CallableDescriptor>> RESULT = Slices.createSimpleSlice();
|
public static final WritableSlice<One, ResolvedCall<? extends CallableDescriptor>> RESULT = Slices.createSimpleSlice();
|
||||||
|
|
||||||
public static final WritableSlice<ResolvedCall<? extends CallableDescriptor>, StringBuilder> ERRORS = Slices.createSimpleSlice();
|
public static final WritableSlice<ResolvedCall<? extends CallableDescriptor>, StringBuilder> ERRORS = Slices.createSimpleSlice();
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls;
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
import com.google.common.collect.LinkedHashMultimap;
|
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
@@ -39,6 +38,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||||
@@ -48,9 +48,9 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
|||||||
*
|
*
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ResolutionTask<D extends CallableDescriptor> extends ResolutionContext {
|
public class ResolutionTask<D extends CallableDescriptor, F extends D> extends ResolutionContext {
|
||||||
private final Collection<ResolutionCandidate<D>> candidates;
|
private final Collection<ResolutionCandidate<D>> candidates;
|
||||||
private final Multimap<ResolutionCandidate<D>, ResolvedCallImpl<D>> resolvedCallMap = LinkedHashMultimap.create();
|
private final Set<ResolvedCallWithTrace<F>> resolvedCalls = Sets.newLinkedHashSet();
|
||||||
/*package*/ final JetReferenceExpression reference;
|
/*package*/ final JetReferenceExpression reference;
|
||||||
private DescriptorCheckStrategy checkingStrategy;
|
private DescriptorCheckStrategy checkingStrategy;
|
||||||
|
|
||||||
@@ -71,8 +71,8 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Multimap<ResolutionCandidate<D>, ResolvedCallImpl<D>> getResolvedCallMap() {
|
public Set<ResolvedCallWithTrace<F>> getResolvedCalls() {
|
||||||
return resolvedCallMap;
|
return resolvedCalls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCheckingStrategy(DescriptorCheckStrategy strategy) {
|
public void setCheckingStrategy(DescriptorCheckStrategy strategy) {
|
||||||
@@ -86,8 +86,8 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolutionTask<D> withTrace(BindingTrace newTrace) {
|
public ResolutionTask<D, F> withTrace(BindingTrace newTrace) {
|
||||||
ResolutionTask<D> newTask = new ResolutionTask<D>(candidates, reference, newTrace, scope, call, expectedType, dataFlowInfo);
|
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(candidates, reference, newTrace, scope, call, expectedType, dataFlowInfo);
|
||||||
newTask.setCheckingStrategy(checkingStrategy);
|
newTask.setCheckingStrategy(checkingStrategy);
|
||||||
return newTask;
|
return newTask;
|
||||||
}
|
}
|
||||||
@@ -98,22 +98,15 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
|
|
||||||
public final TracingStrategy tracing = new TracingStrategy() {
|
public final TracingStrategy tracing = new TracingStrategy() {
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl<D> resolvedCall) {
|
public <D extends CallableDescriptor> void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace<D> resolvedCall) {
|
||||||
D descriptor = resolvedCall.getCandidateDescriptor();
|
trace.record(REFERENCE_TARGET, reference, resolvedCall.getResultingDescriptor());
|
||||||
// if (descriptor instanceof VariableAsFunctionDescriptor) {
|
|
||||||
// VariableAsFunctionDescriptor variableAsFunctionDescriptor = (VariableAsFunctionDescriptor) descriptor;
|
|
||||||
// trace.record(REFERENCE_TARGET, reference, variableAsFunctionDescriptor.getVariableDescriptor());
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// }
|
|
||||||
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
||||||
trace.record(REFERENCE_TARGET, reference, descriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallImpl<D>> candidates) {
|
public <D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallWithTrace<D>> candidates) {
|
||||||
Collection<D> descriptors = Sets.newHashSet();
|
Collection<D> descriptors = Sets.newHashSet();
|
||||||
for (ResolvedCallImpl<D> candidate : candidates) {
|
for (ResolvedCallWithTrace<D> candidate : candidates) {
|
||||||
descriptors.add(candidate.getCandidateDescriptor());
|
descriptors.add(candidate.getCandidateDescriptor());
|
||||||
}
|
}
|
||||||
trace.record(AMBIGUOUS_REFERENCE_TARGET, reference, descriptors);
|
trace.record(AMBIGUOUS_REFERENCE_TARGET, reference, descriptors);
|
||||||
@@ -155,7 +148,14 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
public void noReceiverAllowed(@NotNull BindingTrace trace) {
|
||||||
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
if (reference instanceof JetSimpleNameExpression) {
|
||||||
|
//todo temporary hack
|
||||||
|
//should be stored that the reference is unresolved (and not trace the candidate descriptor)
|
||||||
|
trace.report(UNRESOLVED_REFERENCE.on(reference));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
trace.report(NO_RECEIVER_ADMITTED.on(reference));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -170,12 +170,12 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
|
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallWithTrace<D>> descriptors) {
|
||||||
trace.report(OVERLOAD_RESOLUTION_AMBIGUITY.on(call.getCallElement(), descriptors));
|
trace.report(OVERLOAD_RESOLUTION_AMBIGUITY.on(call.getCallElement(), descriptors));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {
|
public <D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallWithTrace<D>> descriptors) {
|
||||||
trace.report(NONE_APPLICABLE.on(reference, descriptors));
|
trace.report(NONE_APPLICABLE.on(reference, descriptors));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,8 +233,7 @@ public class ResolutionTask<D extends CallableDescriptor> extends ResolutionCont
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor descriptor) {
|
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor descriptor) {
|
||||||
JetExpression expression = call.getCalleeExpression();
|
trace.report(INVISIBLE_MEMBER.on(call.getCallElement(), descriptor, descriptor.getContainingDeclaration()));
|
||||||
trace.report(INVISIBLE_MEMBER.on(expression != null ? expression : call.getCallElement(), descriptor, descriptor.getContainingDeclaration()));
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -31,7 +31,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author svtk
|
* @author svtk
|
||||||
*/
|
*/
|
||||||
public class ResolutionTaskHolder<D extends CallableDescriptor> {
|
public class ResolutionTaskHolder<D extends CallableDescriptor, F extends D> {
|
||||||
private final JetReferenceExpression reference;
|
private final JetReferenceExpression reference;
|
||||||
private final BasicResolutionContext basicResolutionContext;
|
private final BasicResolutionContext basicResolutionContext;
|
||||||
private final Predicate<ResolutionCandidate<D>> visibleStrategy;
|
private final Predicate<ResolutionCandidate<D>> visibleStrategy;
|
||||||
@@ -40,7 +40,7 @@ public class ResolutionTaskHolder<D extends CallableDescriptor> {
|
|||||||
private final Collection<Collection<ResolutionCandidate<D>>> members = Sets.newLinkedHashSet();
|
private final Collection<Collection<ResolutionCandidate<D>>> members = Sets.newLinkedHashSet();
|
||||||
private final Collection<Collection<ResolutionCandidate<D>>> nonLocalExtensions = Sets.newLinkedHashSet();
|
private final Collection<Collection<ResolutionCandidate<D>>> nonLocalExtensions = Sets.newLinkedHashSet();
|
||||||
|
|
||||||
private List<ResolutionTask<D>> tasks = null;
|
private List<ResolutionTask<D, F>> tasks = null;
|
||||||
|
|
||||||
public ResolutionTaskHolder(@NotNull JetReferenceExpression reference,
|
public ResolutionTaskHolder(@NotNull JetReferenceExpression reference,
|
||||||
@NotNull BasicResolutionContext basicResolutionContext,
|
@NotNull BasicResolutionContext basicResolutionContext,
|
||||||
@@ -68,7 +68,7 @@ public class ResolutionTaskHolder<D extends CallableDescriptor> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ResolutionTask<D>> getTasks() {
|
public List<ResolutionTask<D, F>> getTasks() {
|
||||||
if (tasks == null) {
|
if (tasks == null) {
|
||||||
tasks = Lists.newArrayList();
|
tasks = Lists.newArrayList();
|
||||||
List<Collection<ResolutionCandidate<D>>> candidateList = Lists.newArrayList();
|
List<Collection<ResolutionCandidate<D>>> candidateList = Lists.newArrayList();
|
||||||
@@ -89,7 +89,7 @@ public class ResolutionTaskHolder<D extends CallableDescriptor> {
|
|||||||
for (Collection<ResolutionCandidate<D>> candidates : candidateList) {
|
for (Collection<ResolutionCandidate<D>> candidates : candidateList) {
|
||||||
Collection<ResolutionCandidate<D>> filteredCandidates = Collections2.filter(candidates, visibilityStrategy);
|
Collection<ResolutionCandidate<D>> filteredCandidates = Collections2.filter(candidates, visibilityStrategy);
|
||||||
if (!filteredCandidates.isEmpty()) {
|
if (!filteredCandidates.isEmpty()) {
|
||||||
tasks.add(new ResolutionTask<D>(filteredCandidates, reference, basicResolutionContext));
|
tasks.add(new ResolutionTask<D, F>(filteredCandidates, reference, basicResolutionContext));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.calls;
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -28,7 +27,6 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
|||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -37,25 +35,30 @@ import static org.jetbrains.jet.lang.resolve.calls.ResolutionStatus.UNKNOWN_STAT
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedCall<D> {
|
public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedCallWithTrace<D> {
|
||||||
|
|
||||||
public static final Function<ResolvedCallImpl<? extends CallableDescriptor>, CallableDescriptor> MAP_TO_CANDIDATE = new Function<ResolvedCallImpl<? extends CallableDescriptor>, CallableDescriptor>() {
|
public static final Function<ResolvedCallWithTrace<? extends CallableDescriptor>, CallableDescriptor> MAP_TO_CANDIDATE = new Function<ResolvedCallWithTrace<? extends CallableDescriptor>, CallableDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
public CallableDescriptor fun(ResolvedCallImpl<? extends CallableDescriptor> resolvedCall) {
|
public CallableDescriptor fun(ResolvedCallWithTrace<? extends CallableDescriptor> resolvedCall) {
|
||||||
return resolvedCall.getCandidateDescriptor();
|
return resolvedCall.getCandidateDescriptor();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final Function<ResolvedCallImpl<? extends CallableDescriptor>, CallableDescriptor> MAP_TO_RESULT = new Function<ResolvedCallImpl<? extends CallableDescriptor>, CallableDescriptor>() {
|
public static final Function<ResolvedCallWithTrace<? extends CallableDescriptor>, CallableDescriptor> MAP_TO_RESULT = new Function<ResolvedCallWithTrace<? extends CallableDescriptor>, CallableDescriptor>() {
|
||||||
@Override
|
@Override
|
||||||
public CallableDescriptor fun(ResolvedCallImpl<? extends CallableDescriptor> resolvedCall) {
|
public CallableDescriptor fun(ResolvedCallWithTrace<? extends CallableDescriptor> resolvedCall) {
|
||||||
return resolvedCall.getResultingDescriptor();
|
return resolvedCall.getResultingDescriptor();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <D extends CallableDescriptor> ResolvedCallImpl<D> create(@NotNull ResolutionCandidate<D> candidate) {
|
public static <D extends CallableDescriptor> ResolvedCallImpl<D> create(@NotNull ResolutionCandidate<D> candidate, @NotNull TemporaryBindingTrace trace) {
|
||||||
return new ResolvedCallImpl<D>(candidate.getDescriptor(), candidate.getThisObject(), candidate.getReceiverArgument());
|
return create(candidate.getDescriptor(), candidate.getThisObject(), candidate.getReceiverArgument(), trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static <D extends CallableDescriptor> ResolvedCallImpl<D> create(@NotNull D descriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument, @NotNull TemporaryBindingTrace trace) {
|
||||||
|
return new ResolvedCallImpl<D>(descriptor, thisObject, receiverArgument, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final D candidateDescriptor;
|
private final D candidateDescriptor;
|
||||||
@@ -70,10 +73,11 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
|||||||
private TemporaryBindingTrace trace;
|
private TemporaryBindingTrace trace;
|
||||||
private ResolutionStatus status = UNKNOWN_STATUS;
|
private ResolutionStatus status = UNKNOWN_STATUS;
|
||||||
|
|
||||||
private ResolvedCallImpl(@NotNull D candidateDescriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument) {
|
private ResolvedCallImpl(@NotNull D candidateDescriptor, @NotNull ReceiverDescriptor thisObject, @NotNull ReceiverDescriptor receiverArgument, @NotNull TemporaryBindingTrace trace) {
|
||||||
this.candidateDescriptor = candidateDescriptor;
|
this.candidateDescriptor = candidateDescriptor;
|
||||||
this.thisObject = thisObject;
|
this.thisObject = thisObject;
|
||||||
this.receiverArgument = receiverArgument;
|
this.receiverArgument = receiverArgument;
|
||||||
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -90,10 +94,6 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
|||||||
return trace;
|
return trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTrace(@NotNull TemporaryBindingTrace trace) {
|
|
||||||
this.trace = trace;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public D getCandidateDescriptor() {
|
public D getCandidateDescriptor() {
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public interface ResolvedCallWithTrace<D extends CallableDescriptor> extends ResolvedCall<D> {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
ResolutionStatus getStatus();
|
||||||
|
|
||||||
|
boolean isDirty();
|
||||||
|
|
||||||
|
TemporaryBindingTrace getTrace();
|
||||||
|
}
|
||||||
@@ -74,8 +74,8 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static <D extends CallableDescriptor> List<ResolutionTask<D>> computePrioritizedTasks(@NotNull BasicResolutionContext context, @NotNull String name,
|
public static <D extends CallableDescriptor, F extends D> List<ResolutionTask<D, F>> computePrioritizedTasks(@NotNull BasicResolutionContext context, @NotNull String name,
|
||||||
@NotNull JetReferenceExpression functionReference, @NotNull List<MemberPrioritizer<D>> memberPrioritizers) {
|
@NotNull JetReferenceExpression functionReference, @NotNull List<CallableDescriptorCollector<? extends D>> callableDescriptorCollectors) {
|
||||||
ReceiverDescriptor explicitReceiver = context.call.getExplicitReceiver();
|
ReceiverDescriptor explicitReceiver = context.call.getExplicitReceiver();
|
||||||
final JetScope scope;
|
final JetScope scope;
|
||||||
if (explicitReceiver.exists() && explicitReceiver.getType() instanceof NamespaceType) {
|
if (explicitReceiver.exists() && explicitReceiver.getType() instanceof NamespaceType) {
|
||||||
@@ -96,23 +96,26 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ResolutionTaskHolder<D> result = new ResolutionTaskHolder<D>(functionReference, context, visibleStrategy );
|
ResolutionTaskHolder<D, F> result = new ResolutionTaskHolder<D, F>(functionReference, context, visibleStrategy );
|
||||||
doComputeTasks(scope, explicitReceiver, name, result, context, memberPrioritizers);
|
for (CallableDescriptorCollector<? extends D> callableDescriptorCollector : callableDescriptorCollectors) {
|
||||||
|
doComputeTasks(scope, explicitReceiver, name, result, context, callableDescriptorCollector);
|
||||||
|
}
|
||||||
return result.getTasks();
|
return result.getTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <D extends CallableDescriptor> void doComputeTasks(@NotNull JetScope scope, @NotNull ReceiverDescriptor receiver,
|
private static <D extends CallableDescriptor, F extends D> void doComputeTasks(@NotNull JetScope scope, @NotNull ReceiverDescriptor receiver,
|
||||||
@NotNull String name, @NotNull ResolutionTaskHolder<D> result,
|
@NotNull String name, @NotNull ResolutionTaskHolder<D, F> result,
|
||||||
@NotNull BasicResolutionContext context, @NotNull List<MemberPrioritizer<D>> memberPrioritizers) {
|
@NotNull BasicResolutionContext context, @NotNull CallableDescriptorCollector<? extends D> callableDescriptorCollector) {
|
||||||
MemberPrioritizer<D> memberPrioritizer = memberPrioritizers.get(0);
|
|
||||||
AutoCastServiceImpl autoCastService = new AutoCastServiceImpl(context.dataFlowInfo, context.trace.getBindingContext());
|
AutoCastServiceImpl autoCastService = new AutoCastServiceImpl(context.dataFlowInfo, context.trace.getBindingContext());
|
||||||
List<ReceiverDescriptor> implicitReceivers = Lists.newArrayList();
|
List<ReceiverDescriptor> implicitReceivers = Lists.newArrayList();
|
||||||
scope.getImplicitReceiversHierarchy(implicitReceivers);
|
scope.getImplicitReceiversHierarchy(implicitReceivers);
|
||||||
|
if (context.call.getThisObject().exists()) {
|
||||||
|
implicitReceivers.add(context.call.getThisObject());
|
||||||
|
}
|
||||||
if (receiver.exists()) {
|
if (receiver.exists()) {
|
||||||
List<ReceiverDescriptor> variantsForExplicitReceiver = autoCastService.getVariantsForReceiver(receiver);
|
List<ReceiverDescriptor> variantsForExplicitReceiver = autoCastService.getVariantsForReceiver(receiver);
|
||||||
|
|
||||||
Collection<ResolutionCandidate<D>> extensionFunctions = convertWithImpliedThis(scope, variantsForExplicitReceiver, memberPrioritizer.getExtensionsByName(scope, name));
|
Collection<ResolutionCandidate<D>> extensionFunctions = convertWithImpliedThis(scope, variantsForExplicitReceiver, callableDescriptorCollector.getNonMembersByName(scope, name));
|
||||||
List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
|
List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
|
||||||
List<ResolutionCandidate<D>> locals = Lists.newArrayList();
|
List<ResolutionCandidate<D>> locals = Lists.newArrayList();
|
||||||
//noinspection unchecked,RedundantTypeArguments
|
//noinspection unchecked,RedundantTypeArguments
|
||||||
@@ -120,7 +123,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
|
|
||||||
Collection<ResolutionCandidate<D>> members = Lists.newArrayList();
|
Collection<ResolutionCandidate<D>> members = Lists.newArrayList();
|
||||||
for (ReceiverDescriptor variant : variantsForExplicitReceiver) {
|
for (ReceiverDescriptor variant : variantsForExplicitReceiver) {
|
||||||
Collection<D> membersForThisVariant = memberPrioritizer.getMembersByName(variant.getType(), name);
|
Collection<? extends D> membersForThisVariant = callableDescriptorCollector.getMembersByName(variant.getType(), name);
|
||||||
convertWithReceivers(membersForThisVariant, Collections.singletonList(variant), Collections.singletonList(NO_RECEIVER), members);
|
convertWithReceivers(membersForThisVariant, Collections.singletonList(variant), Collections.singletonList(NO_RECEIVER), members);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +131,8 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
result.addMembers(members);
|
result.addMembers(members);
|
||||||
|
|
||||||
for (ReceiverDescriptor implicitReceiver : implicitReceivers) {
|
for (ReceiverDescriptor implicitReceiver : implicitReceivers) {
|
||||||
Collection<D> memberExtensions = memberPrioritizer.getExtensionsByName(implicitReceiver.getType().getMemberScope(), name);
|
Collection<? extends D> memberExtensions = callableDescriptorCollector.getNonMembersByName(
|
||||||
|
implicitReceiver.getType().getMemberScope(), name);
|
||||||
List<ReceiverDescriptor> variantsForImplicitReceiver = autoCastService.getVariantsForReceiver(implicitReceiver);
|
List<ReceiverDescriptor> variantsForImplicitReceiver = autoCastService.getVariantsForReceiver(implicitReceiver);
|
||||||
result.addNonLocalExtensions(convertWithReceivers(memberExtensions, variantsForImplicitReceiver, variantsForExplicitReceiver));
|
result.addNonLocalExtensions(convertWithReceivers(memberExtensions, variantsForImplicitReceiver, variantsForExplicitReceiver));
|
||||||
}
|
}
|
||||||
@@ -136,7 +140,8 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
result.addNonLocalExtensions(nonlocals);
|
result.addNonLocalExtensions(nonlocals);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Collection<ResolutionCandidate<D>> functions = convertWithImpliedThis(scope, Collections.singletonList(receiver), memberPrioritizer.getNonExtensionsByName(scope, name));
|
Collection<ResolutionCandidate<D>> functions = convertWithImpliedThis(scope, Collections.singletonList(receiver), callableDescriptorCollector
|
||||||
|
.getNonExtensionsByName(scope, name));
|
||||||
|
|
||||||
List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
|
List<ResolutionCandidate<D>> nonlocals = Lists.newArrayList();
|
||||||
List<ResolutionCandidate<D>> locals = Lists.newArrayList();
|
List<ResolutionCandidate<D>> locals = Lists.newArrayList();
|
||||||
@@ -147,18 +152,18 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
result.addNonLocalExtensions(nonlocals);
|
result.addNonLocalExtensions(nonlocals);
|
||||||
|
|
||||||
for (ReceiverDescriptor implicitReceiver : implicitReceivers) {
|
for (ReceiverDescriptor implicitReceiver : implicitReceivers) {
|
||||||
doComputeTasks(scope, implicitReceiver, name, result, context, memberPrioritizers);
|
doComputeTasks(scope, implicitReceiver, name, result, context, callableDescriptorCollector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <D extends CallableDescriptor> Collection<ResolutionCandidate<D>> convertWithReceivers(Collection<D> descriptors, Iterable<ReceiverDescriptor> thisObjects, Iterable<ReceiverDescriptor> receiverParameters) {
|
private static <D extends CallableDescriptor> Collection<ResolutionCandidate<D>> convertWithReceivers(Collection<? extends D> descriptors, Iterable<ReceiverDescriptor> thisObjects, Iterable<ReceiverDescriptor> receiverParameters) {
|
||||||
Collection<ResolutionCandidate<D>> result = Lists.newArrayList();
|
Collection<ResolutionCandidate<D>> result = Lists.newArrayList();
|
||||||
convertWithReceivers(descriptors, thisObjects, receiverParameters, result);
|
convertWithReceivers(descriptors, thisObjects, receiverParameters, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <D extends CallableDescriptor> void convertWithReceivers(Collection<D> descriptors, Iterable<ReceiverDescriptor> thisObjects, Iterable<ReceiverDescriptor> receiverParameters, Collection<ResolutionCandidate<D>> result) {
|
private static <D extends CallableDescriptor> void convertWithReceivers(Collection<? extends D> descriptors, Iterable<ReceiverDescriptor> thisObjects, Iterable<ReceiverDescriptor> receiverParameters, Collection<ResolutionCandidate<D>> result) {
|
||||||
for (ReceiverDescriptor thisObject : thisObjects) {
|
for (ReceiverDescriptor thisObject : thisObjects) {
|
||||||
for (ReceiverDescriptor receiverParameter : receiverParameters) {
|
for (ReceiverDescriptor receiverParameter : receiverParameters) {
|
||||||
for (D extension : descriptors) {
|
for (D extension : descriptors) {
|
||||||
|
|||||||
@@ -34,14 +34,15 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
/*package*/ interface TracingStrategy {
|
/*package*/ interface TracingStrategy {
|
||||||
TracingStrategy EMPTY = new TracingStrategy() {
|
TracingStrategy EMPTY = new TracingStrategy() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl<D> resolvedCall) {}
|
public <D extends CallableDescriptor> void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace<D> resolvedCall) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unresolvedReference(@NotNull BindingTrace trace) {}
|
public void unresolvedReference(@NotNull BindingTrace trace) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallImpl<D>> candidates) {}
|
public <D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallWithTrace<D>> candidates) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver) {}
|
public void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver) {}
|
||||||
@@ -59,10 +60,10 @@ import java.util.List;
|
|||||||
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {}
|
public void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {}
|
public <D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallWithTrace<D>> descriptors) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors) {}
|
public <D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallWithTrace<D>> descriptors) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {}
|
public void instantiationOfAbstractClass(@NotNull BindingTrace trace) {}
|
||||||
@@ -83,11 +84,11 @@ import java.util.List;
|
|||||||
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor descriptor) {}
|
public void invisibleMember(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor descriptor) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
<D extends CallableDescriptor> void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCallImpl<D> resolvedCall);
|
<D extends CallableDescriptor> void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace<D> resolvedCall);
|
||||||
|
|
||||||
void unresolvedReference(@NotNull BindingTrace trace);
|
void unresolvedReference(@NotNull BindingTrace trace);
|
||||||
|
|
||||||
<D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallImpl<D>> candidates);
|
<D extends CallableDescriptor> void recordAmbiguity(BindingTrace trace, Collection<ResolvedCallWithTrace<D>> candidates);
|
||||||
|
|
||||||
void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver);
|
void missingReceiver(@NotNull BindingTrace trace, @NotNull ReceiverDescriptor expectedReceiver);
|
||||||
|
|
||||||
@@ -99,9 +100,9 @@ import java.util.List;
|
|||||||
|
|
||||||
void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount);
|
void wrongNumberOfTypeArguments(@NotNull BindingTrace trace, int expectedTypeArgumentCount);
|
||||||
|
|
||||||
<D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors);
|
<D extends CallableDescriptor> void ambiguity(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallWithTrace<D>> descriptors);
|
||||||
|
|
||||||
<D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallImpl<D>> descriptors);
|
<D extends CallableDescriptor> void noneApplicable(@NotNull BindingTrace trace, @NotNull Collection<ResolvedCallWithTrace<D>> descriptors);
|
||||||
|
|
||||||
void instantiationOfAbstractClass(@NotNull BindingTrace trace);
|
void instantiationOfAbstractClass(@NotNull BindingTrace trace);
|
||||||
|
|
||||||
|
|||||||
+119
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.lang.resolve.calls;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author svtk
|
||||||
|
*/
|
||||||
|
public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
|
||||||
|
private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
|
||||||
|
private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
|
||||||
|
private final VariableAsFunctionDescriptor variableAsFunctionDescriptor;
|
||||||
|
|
||||||
|
public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
|
||||||
|
@NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
|
||||||
|
this.functionCall = functionCall;
|
||||||
|
this.variableCall = variableCall;
|
||||||
|
if (JetStandardClasses.isFunctionType(variableCall.getResultingDescriptor().getType())) {
|
||||||
|
variableAsFunctionDescriptor = VariableAsFunctionDescriptor.create(variableCall.getResultingDescriptor());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
variableAsFunctionDescriptor = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
|
||||||
|
return functionCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResolvedCallWithTrace<VariableDescriptor> getVariableCall() {
|
||||||
|
return variableCall;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public FunctionDescriptor getCandidateDescriptor() {
|
||||||
|
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public FunctionDescriptor getResultingDescriptor() {
|
||||||
|
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getReceiverArgument() {
|
||||||
|
ReceiverDescriptor receiverArgument = variableCall.getReceiverArgument();
|
||||||
|
return receiverArgument.exists() ? receiverArgument : functionCall.getReceiverArgument();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ReceiverDescriptor getThisObject() {
|
||||||
|
return variableCall.getThisObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Map<ValueParameterDescriptor, ResolvedValueArgument> getValueArguments() {
|
||||||
|
return functionCall.getValueArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public List<ResolvedValueArgument> getValueArgumentsByIndex() {
|
||||||
|
return functionCall.getValueArgumentsByIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Map<TypeParameterDescriptor, JetType> getTypeArguments() {
|
||||||
|
return functionCall.getTypeArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ResolutionStatus getStatus() {
|
||||||
|
if (variableCall.getStatus() == ResolutionStatus.SUCCESS) {
|
||||||
|
return functionCall.getStatus();
|
||||||
|
}
|
||||||
|
return variableCall.getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDirty() {
|
||||||
|
return functionCall.isDirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TemporaryBindingTrace getTrace() {
|
||||||
|
//functionCall.trace is temporary trace above variableCall.trace and is committed already
|
||||||
|
return variableCall.getTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.types.lang;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.intellij.openapi.util.Pair;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -25,6 +26,8 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
|||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
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.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||||
@@ -189,16 +192,23 @@ public class JetStandardClasses {
|
|||||||
STANDARD_CLASSES_NAMESPACE,
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
"Function" + i);
|
"Function" + i);
|
||||||
|
|
||||||
|
SimpleFunctionDescriptorImpl invoke = new SimpleFunctionDescriptorImpl(function, Collections.<AnnotationDescriptor>emptyList(), "invoke", CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
|
WritableScope scopeForInvoke = createScopeForInvokeFunction(function, invoke);
|
||||||
|
List<TypeParameterDescriptor> typeParameters = createTypeParameters(i, function);
|
||||||
FUNCTION[i] = function.initialize(
|
FUNCTION[i] = function.initialize(
|
||||||
false,
|
false,
|
||||||
createTypeParameters(i, function),
|
typeParameters,
|
||||||
Collections.singleton(getAnyType()), STUB, Collections.<ConstructorDescriptor>emptySet(), null);
|
Collections.singleton(getAnyType()), scopeForInvoke, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||||
FUNCTION_TYPE_CONSTRUCTORS.add(FUNCTION[i].getTypeConstructor());
|
FUNCTION_TYPE_CONSTRUCTORS.add(FUNCTION[i].getTypeConstructor());
|
||||||
|
FunctionDescriptorUtil.initializeFromFunctionType(invoke, function.getDefaultType(), new ClassReceiver(FUNCTION[i]));
|
||||||
|
|
||||||
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
|
ClassDescriptorImpl receiverFunction = new ClassDescriptorImpl(
|
||||||
STANDARD_CLASSES_NAMESPACE,
|
STANDARD_CLASSES_NAMESPACE,
|
||||||
Collections.<AnnotationDescriptor>emptyList(),
|
Collections.<AnnotationDescriptor>emptyList(),
|
||||||
"ExtensionFunction" + i);
|
"ExtensionFunction" + i);
|
||||||
|
SimpleFunctionDescriptorImpl invokeWithReceiver = new SimpleFunctionDescriptorImpl(receiverFunction, Collections.<AnnotationDescriptor>emptyList(), "invoke", CallableMemberDescriptor.Kind.DECLARATION);
|
||||||
|
WritableScope scopeForInvokeWithReceiver = createScopeForInvokeFunction(receiverFunction, invokeWithReceiver);
|
||||||
List<TypeParameterDescriptor> parameters = createTypeParameters(i, receiverFunction);
|
List<TypeParameterDescriptor> parameters = createTypeParameters(i, receiverFunction);
|
||||||
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
|
parameters.add(0, TypeParameterDescriptor.createWithDefaultBound(
|
||||||
receiverFunction,
|
receiverFunction,
|
||||||
@@ -207,11 +217,19 @@ public class JetStandardClasses {
|
|||||||
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
|
RECEIVER_FUNCTION[i] = receiverFunction.initialize(
|
||||||
false,
|
false,
|
||||||
parameters,
|
parameters,
|
||||||
Collections.singleton(getAnyType()), STUB, Collections.<ConstructorDescriptor>emptySet(), null);
|
Collections.singleton(getAnyType()), scopeForInvokeWithReceiver, Collections.<ConstructorDescriptor>emptySet(), null);
|
||||||
RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor());
|
RECEIVER_FUNCTION_TYPE_CONSTRUCTORS.add(RECEIVER_FUNCTION[i].getTypeConstructor());
|
||||||
|
FunctionDescriptorUtil.initializeFromFunctionType(invokeWithReceiver, receiverFunction.getDefaultType(), new ClassReceiver(RECEIVER_FUNCTION[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static WritableScope createScopeForInvokeFunction(ClassDescriptorImpl function, SimpleFunctionDescriptorImpl invoke) {
|
||||||
|
WritableScope scopeForInvoke = new WritableScopeImpl(STUB, function, RedeclarationHandler.THROW_EXCEPTION).setDebugName("Scope for function type");
|
||||||
|
scopeForInvoke.addFunctionDescriptor(invoke);
|
||||||
|
scopeForInvoke.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
return scopeForInvoke;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<TypeParameterDescriptor> createTypeParameters(int parameterCount, ClassDescriptorImpl function) {
|
private static List<TypeParameterDescriptor> createTypeParameters(int parameterCount, ClassDescriptorImpl function) {
|
||||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
|
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>();
|
||||||
for (int j = 0; j < parameterCount; j++) {
|
for (int j = 0; j < parameterCount; j++) {
|
||||||
@@ -411,8 +429,9 @@ public class JetStandardClasses {
|
|||||||
}
|
}
|
||||||
arguments.add(defaultProjection(returnType));
|
arguments.add(defaultProjection(returnType));
|
||||||
int size = parameterTypes.size();
|
int size = parameterTypes.size();
|
||||||
TypeConstructor constructor = receiverType == null ? FUNCTION[size].getTypeConstructor() : RECEIVER_FUNCTION[size].getTypeConstructor();
|
ClassDescriptor classDescriptor = receiverType == null ? FUNCTION[size] : RECEIVER_FUNCTION[size];
|
||||||
return new JetTypeImpl(annotations, constructor, false, arguments, STUB);
|
TypeConstructor constructor = classDescriptor.getTypeConstructor();
|
||||||
|
return new JetTypeImpl(annotations, constructor, false, arguments, classDescriptor.getMemberScope(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TypeProjection defaultProjection(JetType returnType) {
|
private static TypeProjection defaultProjection(JetType returnType) {
|
||||||
|
|||||||
@@ -111,18 +111,19 @@ public abstract class KotlinIntegrationTestBase {
|
|||||||
|
|
||||||
protected void check(String baseName, StringBuilder content) throws IOException {
|
protected void check(String baseName, StringBuilder content) throws IOException {
|
||||||
final File tmpFile = new File(getTestDataDirectory(), baseName + ".tmp");
|
final File tmpFile = new File(getTestDataDirectory(), baseName + ".tmp");
|
||||||
final File goldFile = new File(getTestDataDirectory(), baseName + ".gold");
|
final File expectedFile = new File(getTestDataDirectory(), baseName + ".expected");
|
||||||
|
|
||||||
if (!goldFile.isFile()) {
|
if (!expectedFile.isFile()) {
|
||||||
Files.write(content, tmpFile, Charsets.UTF_8);
|
Files.write(content, tmpFile, Charsets.UTF_8);
|
||||||
fail("No gold file " + goldFile);
|
fail("No .expected file " + expectedFile);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final String goldContent = Files.toString(goldFile, UTF_8);
|
final String goldContent = Files.toString(expectedFile, UTF_8);
|
||||||
if (!goldContent.equals(content.toString())) {
|
if (!goldContent.equals(content.toString())) {
|
||||||
Files.write(content, tmpFile, Charsets.UTF_8);
|
Files.write(content, tmpFile, Charsets.UTF_8);
|
||||||
fail("tmp and gold differ, tmp file: " + tmpFile);
|
fail(".tmp and .expected files differ, tmp file: " + tmpFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpFile.delete();
|
tmpFile.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class ArrayWrapper<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
fun get(index: Int): T {
|
||||||
return contents.get(index)
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ArrayWrapper<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
fun get(index: Int): T {
|
||||||
return contents.get(index)
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ArrayWrapper<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
fun get(index: Int): T {
|
||||||
return contents.get(index)
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class ArrayWrapper<T>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun get(index: Int): T {
|
fun get(index: Int): T {
|
||||||
return contents.get(index)
|
return contents.get(index)!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,28 +19,28 @@ fun box() : String {
|
|||||||
val c1: java.lang.Iterable<Int> = MyCollection1()
|
val c1: java.lang.Iterable<Int> = MyCollection1()
|
||||||
sum = 0
|
sum = 0
|
||||||
for (el in c1) {
|
for (el in c1) {
|
||||||
sum = sum + el
|
sum = sum + el!!
|
||||||
}
|
}
|
||||||
if(sum != 15) return "c1 failed"
|
if(sum != 15) return "c1 failed"
|
||||||
|
|
||||||
val c2 = MyCollection1()
|
val c2 = MyCollection1()
|
||||||
sum = 0
|
sum = 0
|
||||||
for (el in c2) {
|
for (el in c2) {
|
||||||
sum = sum + el
|
sum = sum + el!!
|
||||||
}
|
}
|
||||||
if(sum != 15) return "c2 failed"
|
if(sum != 15) return "c2 failed"
|
||||||
|
|
||||||
val c3: Iterable<Int> = MyCollection2()
|
val c3: Iterable<Int> = MyCollection2()
|
||||||
sum = 0
|
sum = 0
|
||||||
for (el in c3) {
|
for (el in c3) {
|
||||||
sum = sum + el
|
sum = sum + el!!
|
||||||
}
|
}
|
||||||
if(sum != 15) return "c3 failed"
|
if(sum != 15) return "c3 failed"
|
||||||
|
|
||||||
val c4 = MyCollection2()
|
val c4 = MyCollection2()
|
||||||
sum = 0
|
sum = 0
|
||||||
for (el in c4) {
|
for (el in c4) {
|
||||||
sum = sum + el
|
sum = sum + el!!
|
||||||
}
|
}
|
||||||
if(sum != 15) return "c4 failed"
|
if(sum != 15) return "c4 failed"
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ fun box() : String {
|
|||||||
}
|
}
|
||||||
sum = 0
|
sum = 0
|
||||||
for (el in a) {
|
for (el in a) {
|
||||||
sum = sum + el
|
sum = sum + el!!
|
||||||
}
|
}
|
||||||
if(sum != 10) return "a failed"
|
if(sum != 10) return "a failed"
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ fun box() : String {
|
|||||||
val c7 = MyCollection5()
|
val c7 = MyCollection5()
|
||||||
sum = 0
|
sum = 0
|
||||||
for (el in c7) {
|
for (el in c7) {
|
||||||
sum = sum + el
|
sum = sum + el!!
|
||||||
}
|
}
|
||||||
if(sum != 0) return "c7 failed"
|
if(sum != 0) return "c7 failed"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package invoke
|
||||||
|
|
||||||
|
fun test1(predicate: (Int) -> Int, i: Int) = predicate(i)
|
||||||
|
|
||||||
|
fun test2(predicate: (Int) -> Int, i: Int) = predicate.invoke(i)
|
||||||
|
|
||||||
|
class Method {
|
||||||
|
fun invoke(i: Int) = i
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test3(method: Method, i: Int) = method.invoke(i)
|
||||||
|
|
||||||
|
//todo
|
||||||
|
//fun test4(method: Method, i: Int) = method(i)
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
if (test1({ it }, 1) != 1) return "fail 1"
|
||||||
|
if (test2({ it }, 2) != 2) return "fail 2"
|
||||||
|
if (test3(Method(), 3) != 3) return "fail 3"
|
||||||
|
//if (test4(Method(), 4) != 4) return "fail 4"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val a = ArrayList<Int>()
|
||||||
|
a.add(74)
|
||||||
|
a.add(75)
|
||||||
|
val i: Int = a.get(0)
|
||||||
|
val j: Int = a.get(1)
|
||||||
|
if (i != 74) return "fail 1"
|
||||||
|
if (j != 75) return "fail 2"
|
||||||
|
if (a.size() != 2) return "epic fail"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import java.util.*
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val map: Map<String, Int> = HashMap<String, Int>()
|
||||||
|
map.put("a", 1)
|
||||||
|
map.put("bb", 2)
|
||||||
|
map.put("ccc", 3)
|
||||||
|
map.put("dddd", 4)
|
||||||
|
if (map.get("a") != 1) return "fail 1"
|
||||||
|
if (map.size() != 4) return "fail 2"
|
||||||
|
if (map.get("eeeee") != null) return "fail 3"
|
||||||
|
if (!map.containsKey("bb")) return "fail 4"
|
||||||
|
if (map.entrySet().contains("ffffff")) return "fail 5"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -1,5 +1,3 @@
|
|||||||
import java.util.ArrayList
|
|
||||||
|
|
||||||
class MyNumber(val i: Int) {
|
class MyNumber(val i: Int) {
|
||||||
fun inc(): MyNumber = MyNumber(i+1)
|
fun inc(): MyNumber = MyNumber(i+1)
|
||||||
}
|
}
|
||||||
@@ -52,21 +50,32 @@ fun test6() : Boolean {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArrayList without jdk-headers cannot be used in these tests
|
||||||
|
class MyArrayList<T>(var value: T) {
|
||||||
|
fun get(index: Int): T {
|
||||||
|
if (index != 17)
|
||||||
|
throw Exception()
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
fun set(index: Int, value: T): Unit {
|
||||||
|
if (index != 17)
|
||||||
|
throw Exception()
|
||||||
|
this.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun test7() : Boolean {
|
fun test7() : Boolean {
|
||||||
var mnr = ArrayList<MyNumber>()
|
var mnr = MyArrayList<MyNumber>(MyNumber(42))
|
||||||
mnr.add(MyNumber(42))
|
mnr[17]++
|
||||||
mnr[0]++
|
if (mnr[17].i != 43) return false
|
||||||
if (mnr[0].i != 43) return false
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test8() : Boolean {
|
fun test8() : Boolean {
|
||||||
var mnr = ArrayList<MyNumber>()
|
var mnr = MyArrayList<MyNumber>(MyNumber(42))
|
||||||
mnr.add(MyNumber(42))
|
val old = mnr[17]++
|
||||||
mnr.add(MyNumber(41))
|
if (old.i != 42) return false
|
||||||
mnr[1] = mnr[0]++
|
if (mnr[17].i != 43) return false
|
||||||
if (mnr[0].i != 43) return false
|
|
||||||
if (mnr[1].i != 42) return false
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ var <T> ArrayList<T>.length : Int
|
|||||||
set(value: Int) = throw java.lang.Error()
|
set(value: Int) = throw java.lang.Error()
|
||||||
|
|
||||||
var <T> ArrayList<T>.last : T
|
var <T> ArrayList<T>.last : T
|
||||||
get() = get(size()-1)
|
get() = get(size()-1)!!
|
||||||
set(el : T) { set(size()-1, el) }
|
set(el : T) { set(size()-1, el) }
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
class N() : ArrayList<Any>() {
|
class N() : ArrayList<Any>() {
|
||||||
override fun add(el: Any) : Boolean {
|
override fun add(el: Any?) : Boolean {
|
||||||
if (!super<ArrayList>.add(el)) {
|
if (!super<ArrayList>.add(el)) {
|
||||||
throw Exception()
|
throw Exception()
|
||||||
}
|
}
|
||||||
|
|||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
// FILE: A.java
|
||||||
|
public class A {}
|
||||||
|
|
||||||
|
// FILE: X.java
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class X<T> {
|
||||||
|
@NotNull T fooN() {return null;}
|
||||||
|
void barN(@NotNull T a) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: Y.java
|
||||||
|
public class Y extends X<String> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Y().fooN() : Any
|
||||||
|
Y().barN(<!ERROR_COMPILE_TIME_VALUE!>null<!>);
|
||||||
|
}
|
||||||
|
|
||||||
+23
@@ -0,0 +1,23 @@
|
|||||||
|
// FILE: A.java
|
||||||
|
public class A {}
|
||||||
|
|
||||||
|
// FILE: X.java
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class X<T> {
|
||||||
|
@NotNull T fooN() {return null;}
|
||||||
|
void barN(@NotNull T a) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: Y.java
|
||||||
|
public class Y extends X<A> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Y().fooN() : Any
|
||||||
|
Y().barN(<!ERROR_COMPILE_TIME_VALUE!>null<!>);
|
||||||
|
}
|
||||||
|
|
||||||
+21
@@ -0,0 +1,21 @@
|
|||||||
|
// FILE: A.java
|
||||||
|
public class A {}
|
||||||
|
|
||||||
|
// FILE: X.java
|
||||||
|
public class X<T> {
|
||||||
|
T foo() {return null;}
|
||||||
|
void bar(T a) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: Y.java
|
||||||
|
public class Y extends X<String> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Y().foo()<!UNSAFE_CALL!>.<!>length
|
||||||
|
Y().bar(null)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// FILE: A.java
|
||||||
|
public class A {}
|
||||||
|
|
||||||
|
// FILE: X.java
|
||||||
|
public class X<T> {
|
||||||
|
T foo() {return null;}
|
||||||
|
void bar(T a) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: Y.java
|
||||||
|
public class Y extends X<A> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
Y().foo()<!UNSAFE_CALL!>.<!>hashCode()
|
||||||
|
Y().bar(null)
|
||||||
|
}
|
||||||
|
|
||||||
Binary file not shown.
@@ -30,8 +30,10 @@ import com.intellij.testFramework.LightVirtualFile;
|
|||||||
import com.intellij.testFramework.TestDataFile;
|
import com.intellij.testFramework.TestDataFile;
|
||||||
import com.intellij.testFramework.UsefulTestCase;
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -65,14 +67,26 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
createEnvironmentWithMockJdk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createEnvironmentWithMockJdk() {
|
protected void createEnvironmentWithMockJdk() {
|
||||||
|
if (myEnvironment != null) {
|
||||||
|
throw new IllegalStateException("must not set up myEnvironemnt twice");
|
||||||
|
}
|
||||||
myEnvironment = JetTestUtils.createEnvironmentWithMockJdk(getTestRootDisposable());
|
myEnvironment = JetTestUtils.createEnvironmentWithMockJdk(getTestRootDisposable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createEnvironmentWithMockJdk(@NotNull CompilerSpecialMode compilerSpecialMode) {
|
||||||
|
if (myEnvironment != null) {
|
||||||
|
throw new IllegalStateException("must not set up myEnvironemnt twice");
|
||||||
|
}
|
||||||
|
myEnvironment = JetTestUtils.createEnvironmentWithMockJdk(getTestRootDisposable(), compilerSpecialMode);
|
||||||
|
}
|
||||||
|
|
||||||
protected void createEnvironmentWithFullJdk() {
|
protected void createEnvironmentWithFullJdk() {
|
||||||
|
if (myEnvironment != null) {
|
||||||
|
throw new IllegalStateException("must not set up myEnvironemnt twice");
|
||||||
|
}
|
||||||
myEnvironment = JetTestUtils.createEnvironmentWithFullJdk(getTestRootDisposable());
|
myEnvironment = JetTestUtils.createEnvironmentWithFullJdk(getTestRootDisposable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnosticFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||||
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnosticFactory;
|
|
||||||
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
import org.jetbrains.jet.lang.diagnostics.rendering.DefaultErrorMessages;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
@@ -163,9 +163,7 @@ public class JetTestUtils {
|
|||||||
|
|
||||||
public static AnalyzeExhaust analyzeFile(@NotNull JetFile namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
public static AnalyzeExhaust analyzeFile(@NotNull JetFile namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||||
return AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(namespace, flowDataTraceFactory,
|
return AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(namespace, flowDataTraceFactory,
|
||||||
CompileCompilerDependenciesTest
|
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, true));
|
||||||
.compilerDependenciesForTests(CompilerSpecialMode.REGULAR,
|
|
||||||
true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
||||||
@@ -173,8 +171,10 @@ public class JetTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable, @NotNull CompilerSpecialMode compilerSpecialMode) {
|
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable, @NotNull CompilerSpecialMode compilerSpecialMode) {
|
||||||
return JetCoreEnvironment.getCoreEnvironmentForJVM(disposable, CompileCompilerDependenciesTest
|
JetCoreEnvironment environment =
|
||||||
.compilerDependenciesForTests(compilerSpecialMode, true));
|
new JetCoreEnvironment(disposable, CompileCompilerDependenciesTest.compilerDependenciesForTests(compilerSpecialMode, true));
|
||||||
|
environment.addToClasspath(getAnnotationsJar());
|
||||||
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File findMockJdkRtJar() {
|
public static File findMockJdkRtJar() {
|
||||||
@@ -234,7 +234,7 @@ public class JetTestUtils {
|
|||||||
public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
|
public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
|
||||||
|
|
||||||
public static JetCoreEnvironment createEnvironmentWithFullJdk(Disposable disposable) {
|
public static JetCoreEnvironment createEnvironmentWithFullJdk(Disposable disposable) {
|
||||||
return JetCoreEnvironment.getCoreEnvironmentForJVM(disposable,
|
return new JetCoreEnvironment(disposable,
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, false));
|
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import org.jetbrains.jet.JetTestUtils;
|
|||||||
import org.jetbrains.jet.lang.cfg.LoopInfo;
|
import org.jetbrains.jet.lang.cfg.LoopInfo;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.*;
|
import org.jetbrains.jet.lang.cfg.pseudocode.*;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@@ -50,6 +51,13 @@ public class JetControlFlowTest extends JetLiteFixture {
|
|||||||
myName = name;
|
myName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.STDLIB);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "test" + myName;
|
return "test" + myName;
|
||||||
|
|||||||
@@ -40,6 +40,13 @@ public class CheckerTestUtilTest extends JetLiteFixture {
|
|||||||
super("diagnostics/checkerTestUtil");
|
super("diagnostics/checkerTestUtil");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void doTest(TheTest theTest) throws Exception {
|
protected void doTest(TheTest theTest) throws Exception {
|
||||||
prepareForTest("test");
|
prepareForTest("test");
|
||||||
theTest.test(myFile);
|
theTest.test(myFile);
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.STDLIB);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "test" + name;
|
return "test" + name;
|
||||||
@@ -169,7 +175,7 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
|
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
getProject(), jetFiles, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY,
|
getProject(), jetFiles, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY,
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, true))
|
myEnvironment.getCompilerDependencies())
|
||||||
.getBindingContext();
|
.getBindingContext();
|
||||||
|
|
||||||
boolean ok = true;
|
boolean ok = true;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class JavaDescriptorResolverTest extends TestCaseWithTmpdir {
|
|||||||
jetCoreEnvironment.addToClasspath(tmpdir);
|
jetCoreEnvironment.addToClasspath(tmpdir);
|
||||||
|
|
||||||
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
|
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS, true), jetCoreEnvironment.getProject());
|
jetCoreEnvironment.getCompilerDependencies(), jetCoreEnvironment.getProject());
|
||||||
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||||
ClassDescriptor classDescriptor = javaDescriptorResolver.resolveClass(fqName, DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
ClassDescriptor classDescriptor = javaDescriptorResolver.resolveClass(fqName, DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
||||||
Assert.assertNotNull(classDescriptor);
|
Assert.assertNotNull(classDescriptor);
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
|
|||||||
|
|
||||||
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
||||||
psiFile, JetControlFlowDataTraceFactory.EMPTY,
|
psiFile, JetControlFlowDataTraceFactory.EMPTY,
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS, true))
|
jetCoreEnvironment.getCompilerDependencies())
|
||||||
.getBindingContext();
|
.getBindingContext();
|
||||||
return bindingContext.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, FqName.topLevel("test"));
|
return bindingContext.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, FqName.topLevel("test"));
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ public class ReadJavaBinaryClassTest extends TestCaseWithTmpdir {
|
|||||||
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
||||||
|
|
||||||
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
|
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS, true), jetCoreEnvironment.getProject());
|
jetCoreEnvironment.getCompilerDependencies(), jetCoreEnvironment.getProject());
|
||||||
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||||
return javaDescriptorResolver.resolveNamespace(FqName.topLevel("test"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
return javaDescriptorResolver.resolveNamespace(FqName.topLevel("test"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class ReadKotlinBinaryClassTest extends TestCaseWithTmpdir {
|
|||||||
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
jetCoreEnvironment.addToClasspath(new File("out/production/runtime"));
|
||||||
|
|
||||||
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
|
InjectorForJavaSemanticServices injector = new InjectorForJavaSemanticServices(
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.JDK_HEADERS, true), jetCoreEnvironment.getProject());
|
jetCoreEnvironment.getCompilerDependencies(), jetCoreEnvironment.getProject());
|
||||||
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
JavaDescriptorResolver javaDescriptorResolver = injector.getJavaDescriptorResolver();
|
||||||
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace(FqName.topLevel("test"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
NamespaceDescriptor namespaceFromClass = javaDescriptorResolver.resolveNamespace(FqName.topLevel("test"), DescriptorSearchRule.ERROR_IF_FOUND_IN_KOTLIN);
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import jet.JetObject;
|
import jet.JetObject;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@@ -24,6 +25,13 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class AnnotationGenTest extends CodegenTestCase {
|
public class AnnotationGenTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testPropField() throws NoSuchFieldException, NoSuchMethodException {
|
public void testPropField() throws NoSuchFieldException, NoSuchMethodException {
|
||||||
loadText("[Deprecated] var x = 0");
|
loadText("[Deprecated] var x = 0");
|
||||||
Class aClass = generateNamespaceClass();
|
Class aClass = generateNamespaceClass();
|
||||||
|
|||||||
@@ -16,9 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class ArrayGenTest extends CodegenTestCase {
|
public class ArrayGenTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testKt238 () throws Exception {
|
public void testKt238 () throws Exception {
|
||||||
blackBoxFile("regressions/kt238.jet");
|
blackBoxFile("regressions/kt238.jet");
|
||||||
}
|
}
|
||||||
@@ -237,7 +246,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
public void testCollectionAssignGetMultiIndex () throws Exception {
|
public void testCollectionAssignGetMultiIndex () throws Exception {
|
||||||
loadText("import java.util.ArrayList\n" +
|
loadText("import java.util.ArrayList\n" +
|
||||||
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[2,-2] }\n" +
|
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[2,-2] }\n" +
|
||||||
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
|
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
|
||||||
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
Method foo = generateFunction("box");
|
Method foo = generateFunction("box");
|
||||||
@@ -257,7 +266,7 @@ public class ArrayGenTest extends CodegenTestCase {
|
|||||||
public void testCollectionGetMultiIndex () throws Exception {
|
public void testCollectionGetMultiIndex () throws Exception {
|
||||||
loadText("import java.util.ArrayList\n" +
|
loadText("import java.util.ArrayList\n" +
|
||||||
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; return s[2, -2] }\n" +
|
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; return s[2, -2] }\n" +
|
||||||
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
|
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
|
||||||
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
Method foo = generateFunction("box");
|
Method foo = generateFunction("box");
|
||||||
|
|||||||
@@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
public class BridgeMethodGenTest extends CodegenTestCase {
|
public class BridgeMethodGenTest extends CodegenTestCase {
|
||||||
public void testBridgeMethod () throws Exception {
|
public void testBridgeMethod () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("bridge.jet");
|
blackBoxFile("bridge.jet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -26,7 +28,14 @@ import java.util.List;
|
|||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class ClassGenTest extends CodegenTestCase {
|
public class ClassGenTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
public void testPSVMClass() throws Exception {
|
public void testPSVMClass() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("classes/simpleClass.jet");
|
loadFile("classes/simpleClass.jet");
|
||||||
|
|
||||||
final Class aClass = loadClass("SimpleClass", generateClassesInFile());
|
final Class aClass = loadClass("SimpleClass", generateClassesInFile());
|
||||||
@@ -37,6 +46,7 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayListInheritance() throws Exception {
|
public void testArrayListInheritance() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("classes/inheritingFromArrayList.jet");
|
loadFile("classes/inheritingFromArrayList.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Class aClass = loadClass("Foo", generateClassesInFile());
|
final Class aClass = loadClass("Foo", generateClassesInFile());
|
||||||
@@ -44,30 +54,37 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritanceAndDelegation_DelegatingDefaultConstructorProperties() throws Exception {
|
public void testInheritanceAndDelegation_DelegatingDefaultConstructorProperties() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/inheritance.jet");
|
blackBoxFile("classes/inheritance.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritanceAndDelegation2() throws Exception {
|
public void testInheritanceAndDelegation2() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/delegation2.kt");
|
blackBoxFile("classes/delegation2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFunDelegation() throws Exception {
|
public void testFunDelegation() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/funDelegation.jet");
|
blackBoxFile("classes/funDelegation.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertyDelegation() throws Exception {
|
public void testPropertyDelegation() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/propertyDelegation.jet");
|
blackBoxFile("classes/propertyDelegation.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDiamondInheritance() throws Exception {
|
public void testDiamondInheritance() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/diamondInheritance.jet");
|
blackBoxFile("classes/diamondInheritance.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRightHandOverride() throws Exception {
|
public void testRightHandOverride() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/rightHandOverride.jet");
|
blackBoxFile("classes/rightHandOverride.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNewInstanceExplicitConstructor() throws Exception {
|
public void testNewInstanceExplicitConstructor() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("classes/newInstanceDefaultConstructor.jet");
|
loadFile("classes/newInstanceDefaultConstructor.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method method = generateFunction("test");
|
final Method method = generateFunction("test");
|
||||||
@@ -76,18 +93,22 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testInnerClass() throws Exception {
|
public void testInnerClass() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/innerClass.jet");
|
blackBoxFile("classes/innerClass.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritedInnerClass() throws Exception {
|
public void testInheritedInnerClass() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/inheritedInnerClass.jet");
|
blackBoxFile("classes/inheritedInnerClass.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInitializerBlock() throws Exception {
|
public void testInitializerBlock() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/initializerBlock.jet");
|
blackBoxFile("classes/initializerBlock.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbstractMethod() throws Exception {
|
public void testAbstractMethod() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("abstract class Foo { abstract fun x(): String; fun y(): Int = 0 }");
|
loadText("abstract class Foo { abstract fun x(): String; fun y(): Int = 0 }");
|
||||||
|
|
||||||
final ClassFileFactory codegens = generateClassesInFile();
|
final ClassFileFactory codegens = generateClassesInFile();
|
||||||
@@ -97,34 +118,42 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testInheritedMethod() throws Exception {
|
public void testInheritedMethod() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/inheritedMethod.jet");
|
blackBoxFile("classes/inheritedMethod.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInitializerBlockDImpl() throws Exception {
|
public void testInitializerBlockDImpl() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/initializerBlockDImpl.jet");
|
blackBoxFile("classes/initializerBlockDImpl.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertyInInitializer() throws Exception {
|
public void testPropertyInInitializer() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/propertyInInitializer.jet");
|
blackBoxFile("classes/propertyInInitializer.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOuterThis() throws Exception {
|
public void testOuterThis() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/outerThis.jet");
|
blackBoxFile("classes/outerThis.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSecondaryConstructors() throws Exception {
|
public void testSecondaryConstructors() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/secondaryConstructors.jet");
|
blackBoxFile("classes/secondaryConstructors.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExceptionConstructor() throws Exception {
|
public void testExceptionConstructor() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/exceptionConstructor.jet");
|
blackBoxFile("classes/exceptionConstructor.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleBox() throws Exception {
|
public void testSimpleBox() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/simpleBox.jet");
|
blackBoxFile("classes/simpleBox.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAbstractClass() throws Exception {
|
public void testAbstractClass() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("abstract class SimpleClass() { }");
|
loadText("abstract class SimpleClass() { }");
|
||||||
|
|
||||||
final Class aClass = createClassLoader(generateClassesInFile()).loadClass("SimpleClass");
|
final Class aClass = createClassLoader(generateClassesInFile()).loadClass("SimpleClass");
|
||||||
@@ -132,15 +161,18 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testClassObject() throws Exception {
|
public void testClassObject() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/classObject.jet");
|
blackBoxFile("classes/classObject.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassObjectMethod() throws Exception {
|
public void testClassObjectMethod() throws Exception {
|
||||||
// todo to be implemented after removal of type info
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
// todo to be implemented after removal of type info
|
||||||
// blackBoxFile("classes/classObjectMethod.jet");
|
// blackBoxFile("classes/classObjectMethod.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClassObjectInterface() throws Exception {
|
public void testClassObjectInterface() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("classes/classObjectInterface.jet");
|
loadFile("classes/classObjectInterface.jet");
|
||||||
final Method method = generateFunction();
|
final Method method = generateFunction();
|
||||||
Object result = method.invoke(null);
|
Object result = method.invoke(null);
|
||||||
@@ -148,26 +180,32 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testOverloadBinaryOperator() throws Exception {
|
public void testOverloadBinaryOperator() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/overloadBinaryOperator.jet");
|
blackBoxFile("classes/overloadBinaryOperator.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverloadUnaryOperator() throws Exception {
|
public void testOverloadUnaryOperator() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/overloadUnaryOperator.jet");
|
blackBoxFile("classes/overloadUnaryOperator.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverloadPlusAssign() throws Exception {
|
public void testOverloadPlusAssign() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/overloadPlusAssign.jet");
|
blackBoxFile("classes/overloadPlusAssign.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverloadPlusAssignReturn() throws Exception {
|
public void testOverloadPlusAssignReturn() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/overloadPlusAssignReturn.jet");
|
blackBoxFile("classes/overloadPlusAssignReturn.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOverloadPlusToPlusAssign() throws Exception {
|
public void testOverloadPlusToPlusAssign() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/overloadPlusToPlusAssign.jet");
|
blackBoxFile("classes/overloadPlusToPlusAssign.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEnumClass() throws Exception {
|
public void testEnumClass() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("enum class Direction { NORTH; SOUTH; EAST; WEST }");
|
loadText("enum class Direction { NORTH; SOUTH; EAST; WEST }");
|
||||||
final Class direction = createClassLoader(generateClassesInFile()).loadClass("Direction");
|
final Class direction = createClassLoader(generateClassesInFile()).loadClass("Direction");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
@@ -177,6 +215,7 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testEnumConstantConstructors() throws Exception {
|
public void testEnumConstantConstructors() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("enum class Color(val rgb: Int) { RED: Color(0xFF0000); GREEN: Color(0x00FF00); }");
|
loadText("enum class Color(val rgb: Int) { RED: Color(0xFF0000); GREEN: Color(0x00FF00); }");
|
||||||
final Class colorClass = createClassLoader(generateClassesInFile()).loadClass("Color");
|
final Class colorClass = createClassLoader(generateClassesInFile()).loadClass("Color");
|
||||||
final Field redField = colorClass.getField("RED");
|
final Field redField = colorClass.getField("RED");
|
||||||
@@ -186,21 +225,25 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testClassObjFields() throws Exception {
|
public void testClassObjFields() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("class A() { class object { val value = 10 } }\n" +
|
loadText("class A() { class object { val value = 10 } }\n" +
|
||||||
"fun box() = if(A.value == 10) \"OK\" else \"fail\"");
|
"fun box() = if(A.value == 10) \"OK\" else \"fail\"");
|
||||||
blackBox();
|
blackBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt249() throws Exception {
|
public void testKt249() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt249.jet");
|
blackBoxFile("regressions/kt249.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt48 () throws Exception {
|
public void testKt48 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt48.jet");
|
blackBoxFile("regressions/kt48.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt309 () throws Exception {
|
public void testKt309 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun box() = null");
|
loadText("fun box() = null");
|
||||||
final Method method = generateFunction("box");
|
final Method method = generateFunction("box");
|
||||||
assertEquals(method.getReturnType().getName(), "java.lang.Object");
|
assertEquals(method.getReturnType().getName(), "java.lang.Object");
|
||||||
@@ -208,65 +251,78 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt343 () throws Exception {
|
public void testKt343 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt343.jet");
|
blackBoxFile("regressions/kt343.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt508 () throws Exception {
|
public void testKt508 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("regressions/kt508.jet");
|
loadFile("regressions/kt508.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
blackBox();
|
blackBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt504 () throws Exception {
|
public void testKt504 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("regressions/kt504.jet");
|
loadFile("regressions/kt504.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
blackBox();
|
blackBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt501 () throws Exception {
|
public void testKt501 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt501.jet");
|
blackBoxFile("regressions/kt501.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt496 () throws Exception {
|
public void testKt496 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt496.jet");
|
blackBoxFile("regressions/kt496.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt500 () throws Exception {
|
public void testKt500 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt500.jet");
|
blackBoxFile("regressions/kt500.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt694 () throws Exception {
|
public void testKt694 () throws Exception {
|
||||||
// blackBoxFile("regressions/kt694.jet");
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
// blackBoxFile("regressions/kt694.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt285 () throws Exception {
|
public void testKt285 () throws Exception {
|
||||||
// blackBoxFile("regressions/kt285.jet");
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
// blackBoxFile("regressions/kt285.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt707 () throws Exception {
|
public void testKt707 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt707.jet");
|
blackBoxFile("regressions/kt707.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt857 () throws Exception {
|
public void testKt857 () throws Exception {
|
||||||
// blackBoxFile("regressions/kt857.jet");
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
// blackBoxFile("regressions/kt857.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt903 () throws Exception {
|
public void testKt903 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt903.jet");
|
blackBoxFile("regressions/kt903.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt940 () throws Exception {
|
public void testKt940 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt940.kt");
|
blackBoxFile("regressions/kt940.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1018 () throws Exception {
|
public void testKt1018 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1018.kt");
|
blackBoxFile("regressions/kt1018.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1120 () throws Exception {
|
public void testKt1120 () throws Exception {
|
||||||
// createEnvironmentWithFullJdk();
|
createEnvironmentWithFullJdk();
|
||||||
// blackBoxFile("regressions/kt1120.kt");
|
// blackBoxFile("regressions/kt1120.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,47 +332,58 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1134() throws Exception {
|
public void testKt1134() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1134.kt");
|
blackBoxFile("regressions/kt1134.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1157() throws Exception {
|
public void testKt1157() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1157.kt");
|
blackBoxFile("regressions/kt1157.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt471() throws Exception {
|
public void testKt471() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt471.kt");
|
blackBoxFile("regressions/kt471.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1213() throws Exception {
|
public void testKt1213() throws Exception {
|
||||||
// blackBoxFile("regressions/kt1213.kt");
|
createEnvironmentWithMockJdk();
|
||||||
|
// blackBoxFile("regressions/kt1213.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt723() throws Exception {
|
public void testKt723() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt723.kt");
|
blackBoxFile("regressions/kt723.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt725() throws Exception {
|
public void testKt725() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt725.kt");
|
blackBoxFile("regressions/kt725.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt633() throws Exception {
|
public void testKt633() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt633.kt");
|
blackBoxFile("regressions/kt633.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testKt1345() throws Exception {
|
public void testKt1345() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1345.kt");
|
blackBoxFile("regressions/kt1345.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1538() throws Exception {
|
public void testKt1538() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1538.kt");
|
blackBoxFile("regressions/kt1538.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1759() throws Exception {
|
public void testKt1759() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1759.kt");
|
blackBoxFile("regressions/kt1759.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testResolveOrder() throws Exception {
|
public void testResolveOrder() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("classes/resolveOrder.jet");
|
blackBoxFile("classes/resolveOrder.jet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author max
|
* @author max
|
||||||
*/
|
*/
|
||||||
public class ClosuresGenTest extends CodegenTestCase {
|
public class ClosuresGenTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSimplestClosure() throws Exception {
|
public void testSimplestClosure() throws Exception {
|
||||||
blackBoxFile("classes/simplestClosure.jet");
|
blackBoxFile("classes/simplestClosure.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
|||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||||
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
@@ -127,8 +128,9 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
|||||||
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
|
private GenerationState generateCommon(ClassBuilderFactory classBuilderFactory) {
|
||||||
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
final AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegrationAndCheckForErrors(
|
||||||
myFile, JetControlFlowDataTraceFactory.EMPTY,
|
myFile, JetControlFlowDataTraceFactory.EMPTY,
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, false));
|
myEnvironment.getCompilerDependencies());
|
||||||
analyzeExhaust.throwIfError();
|
analyzeExhaust.throwIfError();
|
||||||
|
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
|
||||||
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
|
GenerationState state = new GenerationState(getProject(), classBuilderFactory, analyzeExhaust, Collections.singletonList(myFile));
|
||||||
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
state.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
return state;
|
return state;
|
||||||
@@ -194,8 +196,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
|||||||
|
|
||||||
r = method;
|
r = method;
|
||||||
}
|
}
|
||||||
if (r == null)
|
if (r == null) { throw new AssertionError(); }
|
||||||
throw new AssertionError();
|
|
||||||
return r;
|
return r;
|
||||||
} catch (Error e) {
|
} catch (Error e) {
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
|
|||||||
@@ -16,24 +16,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentUtil;
|
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class CompileTextTest extends CodegenTestCase {
|
public class CompileTextTest extends CodegenTestCase {
|
||||||
public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
public void testMe() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk();
|
||||||
String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()";
|
String text = "import org.jetbrains.jet.codegen.CompileTextTest; fun x() = CompileTextTest()";
|
||||||
CompilerDependencies dependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, false);
|
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(
|
||||||
JetCoreEnvironment environment = JetCoreEnvironment.getCoreEnvironmentForJVM(CompileEnvironmentUtil.createMockDisposable(), dependencies);
|
myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
||||||
CompileEnvironmentConfiguration configuration = new CompileEnvironmentConfiguration(environment, dependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
|
|
||||||
configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader());
|
configuration.getEnvironment().addToClasspathFromClassLoader(getClass().getClassLoader());
|
||||||
ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text);
|
ClassLoader classLoader = KotlinToJVMBytecodeCompiler.compileText(configuration, text);
|
||||||
Class<?> namespace = classLoader.loadClass("namespace");
|
Class<?> namespace = classLoader.loadClass("namespace");
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -31,6 +33,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIf() throws Exception {
|
public void testIf() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
|
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
@@ -40,6 +43,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testSingleBranchIf() throws Exception {
|
public void testSingleBranchIf() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
|
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
@@ -61,6 +65,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
|
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile(name);
|
loadFile(name);
|
||||||
|
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
@@ -70,6 +75,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testContinue() throws Exception {
|
public void testContinue() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -78,6 +84,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIfNoElse() throws Exception {
|
public void testIfNoElse() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -86,6 +93,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCondJumpOnStack() throws Exception {
|
public void testCondJumpOnStack() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("import java.lang.Boolean as jlBoolean; fun foo(a: String): Int = if (jlBoolean.parseBoolean(a)) 5 else 10");
|
loadText("import java.lang.Boolean as jlBoolean; fun foo(a: String): Int = if (jlBoolean.parseBoolean(a)) 5 else 10");
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
assertEquals(5, main.invoke(null, "true"));
|
assertEquals(5, main.invoke(null, "true"));
|
||||||
@@ -93,6 +101,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testFor() throws Exception {
|
public void testFor() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -101,6 +110,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIfBlock() throws Exception {
|
public void testIfBlock() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -111,6 +121,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testForInArray() throws Exception {
|
public void testForInArray() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -119,6 +130,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testForInRange() throws Exception {
|
public void testForInRange() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun foo(sb: StringBuilder) { for(x in 1..4) sb.append(x) }");
|
loadText("fun foo(sb: StringBuilder) { for(x in 1..4) sb.append(x) }");
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
@@ -127,6 +139,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testThrowCheckedException() throws Exception {
|
public void testThrowCheckedException() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun foo() { throw Exception(); }");
|
loadText("fun foo() { throw Exception(); }");
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
boolean caught = false;
|
boolean caught = false;
|
||||||
@@ -141,6 +154,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testTryCatch() throws Exception {
|
public void testTryCatch() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -149,6 +163,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testTryFinally() throws Exception {
|
public void testTryFinally() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -168,30 +183,37 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testForUserType() throws Exception {
|
public void testForUserType() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("controlStructures/forUserType.jet");
|
blackBoxFile("controlStructures/forUserType.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForIntArray() throws Exception {
|
public void testForIntArray() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("controlStructures/forIntArray.jet");
|
blackBoxFile("controlStructures/forIntArray.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForPrimitiveIntArray() throws Exception {
|
public void testForPrimitiveIntArray() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("controlStructures/forPrimitiveIntArray.jet");
|
blackBoxFile("controlStructures/forPrimitiveIntArray.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForNullableIntArray() throws Exception {
|
public void testForNullableIntArray() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("controlStructures/forNullableIntArray.jet");
|
blackBoxFile("controlStructures/forNullableIntArray.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testForIntRange() {
|
public void testForIntRange() {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("controlStructures/forIntRange.jet");
|
blackBoxFile("controlStructures/forIntRange.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt237() throws Exception {
|
public void testKt237() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt237.jet");
|
blackBoxFile("regressions/kt237.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCompareToNull() throws Exception {
|
public void testCompareToNull() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b");
|
loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b");
|
||||||
String text = generateToText();
|
String text = generateToText();
|
||||||
assertTrue(!text.contains("java/lang/Object.equals"));
|
assertTrue(!text.contains("java/lang/Object.equals"));
|
||||||
@@ -202,6 +224,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCompareToNonnullableEq() throws Exception {
|
public void testCompareToNonnullableEq() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun foo(a: String?, b: String): Boolean = a == b || b == a");
|
loadText("fun foo(a: String?, b: String): Boolean = a == b || b == a");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -210,6 +233,7 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testCompareToNonnullableNotEq() throws Exception {
|
public void testCompareToNonnullableNotEq() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun foo(a: String?, b: String): Boolean = a != b");
|
loadText("fun foo(a: String?, b: String): Boolean = a != b");
|
||||||
String text = generateToText();
|
String text = generateToText();
|
||||||
// System.out.println(text);
|
// System.out.println(text);
|
||||||
@@ -220,15 +244,18 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt299() throws Exception {
|
public void testKt299() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt299.jet");
|
blackBoxFile("regressions/kt299.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt416() throws Exception {
|
public void testKt416() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt416.jet");
|
blackBoxFile("regressions/kt416.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt513() throws Exception {
|
public void testKt513() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt513.jet");
|
blackBoxFile("regressions/kt513.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,31 +265,37 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt769() throws Exception {
|
public void testKt769() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt769.jet");
|
blackBoxFile("regressions/kt769.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt773() throws Exception {
|
public void testKt773() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt773.jet");
|
blackBoxFile("regressions/kt773.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt772() throws Exception {
|
public void testKt772() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt772.jet");
|
blackBoxFile("regressions/kt772.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt870() throws Exception {
|
public void testKt870() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt870.jet");
|
blackBoxFile("regressions/kt870.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt958() throws Exception {
|
public void testKt958() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt958.jet");
|
blackBoxFile("regressions/kt958.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testQuicksort() throws Exception {
|
public void testQuicksort() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("controlStructures/quicksort.jet");
|
blackBoxFile("controlStructures/quicksort.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
@@ -280,18 +313,22 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1076() throws Exception {
|
public void testKt1076() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1076.kt");
|
blackBoxFile("regressions/kt1076.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt998() throws Exception {
|
public void testKt998() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt998.kt");
|
blackBoxFile("regressions/kt998.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt628() throws Exception {
|
public void testKt628() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt628.kt");
|
blackBoxFile("regressions/kt628.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1441() throws Exception {
|
public void testKt1441() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1441.kt");
|
blackBoxFile("regressions/kt1441.kt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,6 +31,7 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
final Method foo = generateFunction("foo");
|
final Method foo = generateFunction("foo");
|
||||||
final Character c = (Character) foo.invoke(null);
|
final Character c = (Character) foo.invoke(null);
|
||||||
@@ -36,6 +39,7 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testWhenFail() throws Exception {
|
public void testWhenFail() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
Method foo = generateFunction("foo");
|
Method foo = generateFunction("foo");
|
||||||
@@ -43,15 +47,18 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testVirtual() throws Exception {
|
public void testVirtual() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("extensionFunctions/virtual.jet");
|
blackBoxFile("extensionFunctions/virtual.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShared() throws Exception {
|
public void testShared() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("extensionFunctions/shared.kt");
|
blackBoxFile("extensionFunctions/shared.kt");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt475() throws Exception {
|
public void testKt475() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt475.jet");
|
blackBoxFile("regressions/kt475.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@@ -23,6 +25,12 @@ import java.lang.reflect.Method;
|
|||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class FunctionGenTest extends CodegenTestCase {
|
public class FunctionGenTest extends CodegenTestCase {
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testDefaultArgs() throws Exception {
|
public void testDefaultArgs() throws Exception {
|
||||||
blackBoxFile("functions/defaultargs.jet");
|
blackBoxFile("functions/defaultargs.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
@@ -101,4 +109,8 @@ public class FunctionGenTest extends CodegenTestCase {
|
|||||||
public void testLocalFunction () throws InvocationTargetException, IllegalAccessException {
|
public void testLocalFunction () throws InvocationTargetException, IllegalAccessException {
|
||||||
blackBoxFile("functions/localFunction.kt");
|
blackBoxFile("functions/localFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInvoke() {
|
||||||
|
blackBoxFile("functions/invoke.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test correct code is generated for descriptors loaded as alt jdk headers
|
||||||
|
*
|
||||||
|
* @author Stepan Koltsov
|
||||||
|
*/
|
||||||
|
public class JdkHeadersTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.STDLIB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testArrayList() {
|
||||||
|
blackBoxFile("jdk-headers/arrayList.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testHashMap() {
|
||||||
|
blackBoxFile("jdk-headers/hashMap.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen;
|
|||||||
import jet.IntRange;
|
import jet.IntRange;
|
||||||
import jet.Tuple2;
|
import jet.Tuple2;
|
||||||
import jet.Tuple4;
|
import jet.Tuple4;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
@@ -30,6 +31,13 @@ import java.util.Arrays;
|
|||||||
* @author yole
|
* @author yole
|
||||||
*/
|
*/
|
||||||
public class NamespaceGenTest extends CodegenTestCase {
|
public class NamespaceGenTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testPSVM() throws Exception {
|
public void testPSVM() throws Exception {
|
||||||
loadFile("PSVM.jet");
|
loadFile("PSVM.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
|
|||||||
@@ -16,11 +16,19 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class ObjectGenTest extends CodegenTestCase {
|
public class ObjectGenTest extends CodegenTestCase {
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSimpleObject() throws Exception {
|
public void testSimpleObject() throws Exception {
|
||||||
blackBoxFile("objects/simpleObject.jet");
|
blackBoxFile("objects/simpleObject.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import jet.Tuple2;
|
import jet.Tuple2;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@@ -24,6 +25,13 @@ import java.lang.reflect.Method;
|
|||||||
* @author yole
|
* @author yole
|
||||||
*/
|
*/
|
||||||
public class PatternMatchingTest extends CodegenTestCase {
|
public class PatternMatchingTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPrefix() {
|
protected String getPrefix() {
|
||||||
return "patternMatching";
|
return "patternMatching";
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,6 +25,13 @@ import java.lang.reflect.Method;
|
|||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class PrimitiveTypesTest extends CodegenTestCase {
|
public class PrimitiveTypesTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testPlus() throws Exception {
|
public void testPlus() throws Exception {
|
||||||
loadText("fun f(a: Int, b: Int): Int { return a + b }");
|
loadText("fun f(a: Int, b: Int): Int { return a + b }");
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
@@ -31,6 +33,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPrivateVal() throws Exception {
|
public void testPrivateVal() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVal");
|
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVal");
|
||||||
final Field[] fields = aClass.getDeclaredFields();
|
final Field[] fields = aClass.getDeclaredFields();
|
||||||
@@ -40,6 +43,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPrivateVar() throws Exception {
|
public void testPrivateVar() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVar");
|
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVar");
|
||||||
final Object instance = aClass.newInstance();
|
final Object instance = aClass.newInstance();
|
||||||
@@ -50,6 +54,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPublicVar() throws Exception {
|
public void testPublicVar() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("class PublicVar() { public var foo : Int = 0; }");
|
loadText("class PublicVar() { public var foo : Int = 0; }");
|
||||||
final Class aClass = loadImplementationClass(generateClassesInFile(), "PublicVar");
|
final Class aClass = loadImplementationClass(generateClassesInFile(), "PublicVar");
|
||||||
final Object instance = aClass.newInstance();
|
final Object instance = aClass.newInstance();
|
||||||
@@ -60,6 +65,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAccessorsInInterface() {
|
public void testAccessorsInInterface() {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("class AccessorsInInterface() { public var foo : Int = 0; }");
|
loadText("class AccessorsInInterface() { public var foo : Int = 0; }");
|
||||||
final Class aClass = loadClass("AccessorsInInterface", generateClassesInFile());
|
final Class aClass = loadClass("AccessorsInInterface", generateClassesInFile());
|
||||||
assertNotNull(findMethodByName(aClass, "getFoo"));
|
assertNotNull(findMethodByName(aClass, "getFoo"));
|
||||||
@@ -67,6 +73,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPrivatePropertyInNamespace() throws Exception {
|
public void testPrivatePropertyInNamespace() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("private val x = 239");
|
loadText("private val x = 239");
|
||||||
final Class nsClass = generateNamespaceClass();
|
final Class nsClass = generateNamespaceClass();
|
||||||
final Field[] fields = nsClass.getDeclaredFields();
|
final Field[] fields = nsClass.getDeclaredFields();
|
||||||
@@ -79,6 +86,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testFieldPropertyAccess() throws Exception {
|
public void testFieldPropertyAccess() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile("properties/fieldPropertyAccess.jet");
|
loadFile("properties/fieldPropertyAccess.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method method = generateFunction();
|
final Method method = generateFunction();
|
||||||
@@ -87,12 +95,14 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testFieldGetter() throws Exception {
|
public void testFieldGetter() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("val now: Long get() = System.currentTimeMillis(); fun foo() = now");
|
loadText("val now: Long get() = System.currentTimeMillis(); fun foo() = now");
|
||||||
final Method method = generateFunction("foo");
|
final Method method = generateFunction("foo");
|
||||||
assertIsCurrentTime((Long) method.invoke(null));
|
assertIsCurrentTime((Long) method.invoke(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFieldSetter() throws Exception {
|
public void testFieldSetter() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
final Method method = generateFunction("append");
|
final Method method = generateFunction("append");
|
||||||
method.invoke(null, "IntelliJ ");
|
method.invoke(null, "IntelliJ ");
|
||||||
@@ -104,6 +114,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testFieldSetterPlusEq() throws Exception {
|
public void testFieldSetterPlusEq() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
final Method method = generateFunction("append");
|
final Method method = generateFunction("append");
|
||||||
method.invoke(null, "IntelliJ ");
|
method.invoke(null, "IntelliJ ");
|
||||||
@@ -112,6 +123,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAccessorsWithoutBody() throws Exception {
|
public void testAccessorsWithoutBody() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("class AccessorsWithoutBody() { protected var foo: Int = 349\n get\n private set\n fun setter() { foo = 610; } } ");
|
loadText("class AccessorsWithoutBody() { protected var foo: Int = 349\n get\n private set\n fun setter() { foo = 610; } } ");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Class aClass = loadImplementationClass(generateClassesInFile(), "AccessorsWithoutBody");
|
final Class aClass = loadImplementationClass(generateClassesInFile(), "AccessorsWithoutBody");
|
||||||
@@ -129,6 +141,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testInitializersForNamespaceProperties() throws Exception {
|
public void testInitializersForNamespaceProperties() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("val x = System.currentTimeMillis()");
|
loadText("val x = System.currentTimeMillis()");
|
||||||
final Method method = generateFunction("getX");
|
final Method method = generateFunction("getX");
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
@@ -136,6 +149,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testPropertyReceiverOnStack() throws Exception {
|
public void testPropertyReceiverOnStack() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadFile();
|
loadFile();
|
||||||
final Class aClass = loadImplementationClass(generateClassesInFile(), "Evaluator");
|
final Class aClass = loadImplementationClass(generateClassesInFile(), "Evaluator");
|
||||||
final Constructor constructor = aClass.getConstructor(StringBuilder.class);
|
final Constructor constructor = aClass.getConstructor(StringBuilder.class);
|
||||||
@@ -147,6 +161,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAbstractVal() throws Exception {
|
public void testAbstractVal() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("abstract class Foo { public abstract val x: String }");
|
loadText("abstract class Foo { public abstract val x: String }");
|
||||||
final ClassFileFactory codegens = generateClassesInFile();
|
final ClassFileFactory codegens = generateClassesInFile();
|
||||||
final Class aClass = loadClass("Foo", codegens);
|
final Class aClass = loadClass("Foo", codegens);
|
||||||
@@ -154,6 +169,7 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testVolatileProperty() throws Exception {
|
public void testVolatileProperty() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("abstract class Foo { public volatile var x: String = \"\"; }");
|
loadText("abstract class Foo { public volatile var x: String = \"\"; }");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final ClassFileFactory codegens = generateClassesInFile();
|
final ClassFileFactory codegens = generateClassesInFile();
|
||||||
@@ -163,15 +179,18 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt257 () throws Exception {
|
public void testKt257 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt257.jet");
|
blackBoxFile("regressions/kt257.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt613 () throws Exception {
|
public void testKt613 () throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt613.jet");
|
blackBoxFile("regressions/kt613.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt160() throws Exception {
|
public void testKt160() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("internal val s = java.lang.Double.toString(1.0)");
|
loadText("internal val s = java.lang.Double.toString(1.0)");
|
||||||
final Method method = generateFunction("getS");
|
final Method method = generateFunction("getS");
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
@@ -179,10 +198,12 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1165() throws Exception {
|
public void testKt1165() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1165.kt");
|
blackBoxFile("regressions/kt1165.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1168() throws Exception {
|
public void testKt1168() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1168.kt");
|
blackBoxFile("regressions/kt1168.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,14 +213,17 @@ public class PropertyGenTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1159() throws Exception {
|
public void testKt1159() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1159.kt");
|
blackBoxFile("regressions/kt1159.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1417() throws Exception {
|
public void testKt1417() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1417.kt");
|
blackBoxFile("regressions/kt1417.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testKt1398() throws Exception {
|
public void testKt1398() throws Exception {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt1398.kt");
|
blackBoxFile("regressions/kt1398.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,15 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
public class SafeRefTest extends CodegenTestCase {
|
public class SafeRefTest extends CodegenTestCase {
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void test247 () throws Exception {
|
public void test247 () throws Exception {
|
||||||
blackBoxFile("regressions/kt247.jet");
|
blackBoxFile("regressions/kt247.jet");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@@ -25,6 +27,12 @@ import java.lang.reflect.Method;
|
|||||||
*/
|
*/
|
||||||
public class StringsTest extends CodegenTestCase {
|
public class StringsTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testAnyToString () throws InvocationTargetException, IllegalAccessException {
|
public void testAnyToString () throws InvocationTargetException, IllegalAccessException {
|
||||||
loadText("fun foo(x: Any) = x.toString()");
|
loadText("fun foo(x: Any) = x.toString()");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
|
|||||||
@@ -16,7 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
public class SuperGenTest extends CodegenTestCase {
|
public class SuperGenTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
public void testBasicProperty () {
|
public void testBasicProperty () {
|
||||||
blackBoxFile("/super/basicproperty.jet");
|
blackBoxFile("/super/basicproperty.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import gnu.trove.THashSet;
|
|||||||
import junit.framework.Test;
|
import junit.framework.Test;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
|
||||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
import org.jetbrains.jet.cli.jvm.compiler.CompileEnvironmentConfiguration;
|
||||||
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
import org.jetbrains.jet.cli.jvm.compiler.KotlinToJVMBytecodeCompiler;
|
||||||
@@ -32,8 +31,6 @@ import org.jetbrains.jet.lang.psi.JetDeclaration;
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
|
|
||||||
@@ -75,7 +72,6 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
|
|
||||||
private TestSuite doBuildSuite() {
|
private TestSuite doBuildSuite() {
|
||||||
try {
|
try {
|
||||||
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, false);
|
|
||||||
File junitJar = new File("libraries/lib/junit-4.9.jar");
|
File junitJar = new File("libraries/lib/junit-4.9.jar");
|
||||||
|
|
||||||
if (!junitJar.exists()) {
|
if (!junitJar.exists()) {
|
||||||
@@ -84,14 +80,14 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
|
|
||||||
myEnvironment.addToClasspath(junitJar);
|
myEnvironment.addToClasspath(junitJar);
|
||||||
|
|
||||||
myEnvironment.addToClasspath(compilerDependencies.getRuntimeJar());
|
myEnvironment.addToClasspath(myEnvironment.getCompilerDependencies().getRuntimeJar());
|
||||||
|
|
||||||
CoreLocalFileSystem localFileSystem = myEnvironment.getLocalFileSystem();
|
CoreLocalFileSystem localFileSystem = myEnvironment.getLocalFileSystem();
|
||||||
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test"));
|
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test"));
|
||||||
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src"));
|
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src"));
|
||||||
|
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||||
.analyzeAndGenerate(new CompileEnvironmentConfiguration(myEnvironment, compilerDependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false);
|
.analyzeAndGenerate(new CompileEnvironmentConfiguration(myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false);
|
||||||
|
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
throw new RuntimeException("There were compilation errors");
|
throw new RuntimeException("There were compilation errors");
|
||||||
|
|||||||
@@ -16,7 +16,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
public class TraitsTest extends CodegenTestCase {
|
public class TraitsTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPrefix() {
|
protected String getPrefix() {
|
||||||
return "traits";
|
return "traits";
|
||||||
|
|||||||
@@ -16,8 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
public class TupleGenTest extends CodegenTestCase {
|
public class TupleGenTest extends CodegenTestCase {
|
||||||
public void testBasic() {
|
public void testBasic() {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("/tuples/basic.jet");
|
blackBoxFile("/tuples/basic.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import jet.TypeCastException;
|
import jet.TypeCastException;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
@@ -25,6 +26,13 @@ import java.lang.reflect.Method;
|
|||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class TypeInfoTest extends CodegenTestCase {
|
public class TypeInfoTest extends CodegenTestCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getPrefix() {
|
protected String getPrefix() {
|
||||||
return "typeInfo";
|
return "typeInfo";
|
||||||
|
|||||||
@@ -16,16 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author alex.tkachman
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class VarArgTest extends CodegenTestCase {
|
public class VarArgTest extends CodegenTestCase {
|
||||||
public void testStringArray () throws InvocationTargetException, IllegalAccessException {
|
public void testStringArray () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test(vararg ts: String) = ts");
|
loadText("fun test(vararg ts: String) = ts");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -34,6 +36,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIntArray () throws InvocationTargetException, IllegalAccessException {
|
public void testIntArray () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test(vararg ts: Int) = ts");
|
loadText("fun test(vararg ts: Int) = ts");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction();
|
final Method main = generateFunction();
|
||||||
@@ -42,6 +45,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIntArrayKotlinNoArgs () throws InvocationTargetException, IllegalAccessException {
|
public void testIntArrayKotlinNoArgs () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test() = testf(); fun testf(vararg ts: Int) = ts");
|
loadText("fun test() = testf(); fun testf(vararg ts: Int) = ts");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
@@ -50,6 +54,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIntArrayKotlin () throws InvocationTargetException, IllegalAccessException {
|
public void testIntArrayKotlin () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test() = testf(239, 7); fun testf(vararg ts: Int) = ts");
|
loadText("fun test() = testf(239, 7); fun testf(vararg ts: Int) = ts");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
@@ -60,6 +65,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testNullableIntArrayKotlin () throws InvocationTargetException, IllegalAccessException {
|
public void testNullableIntArrayKotlin () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test() = testf(239.toByte(), 7.toByte()); fun testf(vararg ts: Byte?) = ts");
|
loadText("fun test() = testf(239.toByte(), 7.toByte()); fun testf(vararg ts: Byte?) = ts");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
@@ -70,6 +76,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testIntArrayKotlinObj () throws InvocationTargetException, IllegalAccessException {
|
public void testIntArrayKotlinObj () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test() = testf(\"239\"); fun testf(vararg ts: String) = ts");
|
loadText("fun test() = testf(\"239\"); fun testf(vararg ts: String) = ts");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
@@ -79,6 +86,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayT () throws InvocationTargetException, IllegalAccessException {
|
public void testArrayT () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("fun test() = _array(2, 4); fun <T> _array(vararg elements : T) = elements");
|
loadText("fun test() = _array(2, 4); fun <T> _array(vararg elements : T) = elements");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
@@ -94,10 +102,12 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testKt797() {
|
public void testKt797() {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
blackBoxFile("regressions/kt796_797.jet");
|
blackBoxFile("regressions/kt796_797.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayAsVararg () throws InvocationTargetException, IllegalAccessException {
|
public void testArrayAsVararg () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("private fun asList(vararg elems: String) = elems; fun test(ts: Array<String>) = asList(*ts); ");
|
loadText("private fun asList(vararg elems: String) = elems; fun test(ts: Array<String>) = asList(*ts); ");
|
||||||
//System.out.println(generateToText());
|
//System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
@@ -106,6 +116,7 @@ public class VarArgTest extends CodegenTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testArrayAsVararg2 () throws InvocationTargetException, IllegalAccessException {
|
public void testArrayAsVararg2 () throws InvocationTargetException, IllegalAccessException {
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.JDK_HEADERS);
|
||||||
loadText("private fun asList(vararg elems: String) = elems; fun test(ts1: Array<String>, ts2: String) = asList(*ts1, ts2); ");
|
loadText("private fun asList(vararg elems: String) = elems; fun test(ts1: Array<String>, ts2: String) = asList(*ts1, ts2); ");
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
final Method main = generateFunction("test");
|
final Method main = generateFunction("test");
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ import java.util.List;
|
|||||||
* @since 4/6/12
|
* @since 4/6/12
|
||||||
*/
|
*/
|
||||||
public class DescriptorRendererTest extends JetLiteFixture {
|
public class DescriptorRendererTest extends JetLiteFixture {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
createEnvironmentWithMockJdk();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testGlobalProperties() throws IOException {
|
public void testGlobalProperties() throws IOException {
|
||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
@@ -72,7 +80,7 @@ public class DescriptorRendererTest extends JetLiteFixture {
|
|||||||
AnalyzeExhaust analyzeExhaust =
|
AnalyzeExhaust analyzeExhaust =
|
||||||
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(
|
AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(
|
||||||
(JetFile) psiFile, JetControlFlowDataTraceFactory.EMPTY,
|
(JetFile) psiFile, JetControlFlowDataTraceFactory.EMPTY,
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, true));
|
myEnvironment.getCompilerDependencies());
|
||||||
final BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
final BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
||||||
final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();
|
final List<DeclarationDescriptor> descriptors = new ArrayList<DeclarationDescriptor>();
|
||||||
psiFile.acceptChildren(new JetVisitorVoid() {
|
psiFile.acceptChildren(new JetVisitorVoid() {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
|
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
@@ -78,9 +79,13 @@ public abstract class ExpectedResolveData {
|
|||||||
private final Map<String, DeclarationDescriptor> nameToDescriptor;
|
private final Map<String, DeclarationDescriptor> nameToDescriptor;
|
||||||
private final Map<String, PsiElement> nameToPsiElement;
|
private final Map<String, PsiElement> nameToPsiElement;
|
||||||
|
|
||||||
public ExpectedResolveData(Map<String, DeclarationDescriptor> nameToDescriptor, Map<String, PsiElement> nameToPsiElement) {
|
@NotNull
|
||||||
|
private final JetCoreEnvironment jetCoreEnvironment;
|
||||||
|
|
||||||
|
public ExpectedResolveData(Map<String, DeclarationDescriptor> nameToDescriptor, Map<String, PsiElement> nameToPsiElement, @NotNull JetCoreEnvironment environment) {
|
||||||
this.nameToDescriptor = nameToDescriptor;
|
this.nameToDescriptor = nameToDescriptor;
|
||||||
this.nameToPsiElement = nameToPsiElement;
|
this.nameToPsiElement = nameToPsiElement;
|
||||||
|
jetCoreEnvironment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final JetFile createFileFromMarkedUpText(String fileName, String text) {
|
public final JetFile createFileFromMarkedUpText(String fileName, String text) {
|
||||||
@@ -143,7 +148,7 @@ public abstract class ExpectedResolveData {
|
|||||||
|
|
||||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files,
|
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files,
|
||||||
Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY,
|
Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY,
|
||||||
CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR, true));
|
jetCoreEnvironment.getCompilerDependencies());
|
||||||
BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
BindingContext bindingContext = analyzeExhaust.getBindingContext();
|
||||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||||
if (diagnostic.getFactory() instanceof UnresolvedReferenceDiagnosticFactory) {
|
if (diagnostic.getFactory() instanceof UnresolvedReferenceDiagnosticFactory) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NonNls;
|
|||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -32,6 +33,9 @@ public abstract class ExtensibleResolveTestCase extends JetLiteFixture {
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
|
createEnvironmentWithMockJdk(CompilerSpecialMode.STDLIB);
|
||||||
|
|
||||||
expectedResolveData = getExpectedResolveData();
|
expectedResolveData = getExpectedResolveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user