Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -9,6 +9,11 @@
|
|||||||
<pathelement path="${output}/classes/runtime"/>
|
<pathelement path="${output}/classes/runtime"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
|
<path id="classpath.kotlin">
|
||||||
|
<path refid="classpath"/>
|
||||||
|
<pathelement path="${output}/classes/compiler"/>
|
||||||
|
</path>
|
||||||
|
|
||||||
<path id="sourcepath">
|
<path id="sourcepath">
|
||||||
<dirset dir="${basedir}/compiler">
|
<dirset dir="${basedir}/compiler">
|
||||||
<include name="frontend/src"/>
|
<include name="frontend/src"/>
|
||||||
@@ -26,9 +31,21 @@
|
|||||||
</javac>
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jarRT" depends="compileRT">
|
<target name="compileStdlib" depends="compile">
|
||||||
|
<mkdir dir="${output}/classes/stdlib"/>
|
||||||
|
<java classname="org.jetbrains.jet.cli.KotlinCompiler">
|
||||||
|
<classpath refid="classpath.kotlin"/>
|
||||||
|
<arg value="-src"/>
|
||||||
|
<arg value="${basedir}/stdlib/ktSrc"/>
|
||||||
|
<arg value="-output"/>
|
||||||
|
<arg value="${basedir}/classes/stdlib"/>
|
||||||
|
</java>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jarRT" depends="compileStdlib">
|
||||||
<jar destfile="${output}/kotlin-runtime.jar">
|
<jar destfile="${output}/kotlin-runtime.jar">
|
||||||
<fileset dir="${output}/classes/runtime"/>
|
<fileset dir="${output}/classes/runtime"/>
|
||||||
|
<fileset dir="${output}/classes/stdlib"/>
|
||||||
<fileset dir="${basedir}/stdlib/ktSrc"/>
|
<fileset dir="${basedir}/stdlib/ktSrc"/>
|
||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
@@ -49,7 +66,11 @@
|
|||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="dist" depends="jarRT,jar">
|
<target name="clean">
|
||||||
|
<delete dir="${output}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="dist" depends="clean,jarRT,jar">
|
||||||
<zip destfile="${output}/${output.name}.zip">
|
<zip destfile="${output}/${output.name}.zip">
|
||||||
<zipfileset prefix="${output.name}/bin" filemode="755" dir="${basedir}/compiler/cli/bin"/>
|
<zipfileset prefix="${output.name}/bin" filemode="755" dir="${basedir}/compiler/cli/bin"/>
|
||||||
<zipfileset prefix="${output.name}/lib" dir="${basedir}/ideaSDK"/>
|
<zipfileset prefix="${output.name}/lib" dir="${basedir}/ideaSDK"/>
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ import com.intellij.openapi.application.PathManager;
|
|||||||
import com.intellij.openapi.util.Disposer;
|
import com.intellij.openapi.util.Disposer;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import jet.modules.IModuleBuilder;
|
import jet.modules.IModuleBuilder;
|
||||||
@@ -22,6 +24,8 @@ import java.io.*;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.*;
|
import java.util.jar.*;
|
||||||
|
|
||||||
@@ -53,14 +57,18 @@ public class CompileEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean initializeKotlinRuntime() {
|
public boolean initializeKotlinRuntime() {
|
||||||
|
return initializeKotlinRuntime(myEnvironment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean initializeKotlinRuntime(JetCoreEnvironment environment) {
|
||||||
final File unpackedRuntimePath = getUnpackedRuntimePath();
|
final File unpackedRuntimePath = getUnpackedRuntimePath();
|
||||||
if (unpackedRuntimePath != null) {
|
if (unpackedRuntimePath != null) {
|
||||||
myEnvironment.addToClasspath(unpackedRuntimePath);
|
environment.addToClasspath(unpackedRuntimePath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final File runtimeJarPath = getRuntimeJarPath();
|
final File runtimeJarPath = getRuntimeJarPath();
|
||||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||||
myEnvironment.addToClasspath(runtimeJarPath);
|
environment.addToClasspath(runtimeJarPath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
@@ -147,7 +155,7 @@ public class CompileEnvironment {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compileModuleScript(String moduleFile) {
|
public void compileModuleScript(String moduleFile, String jarPath, boolean jarRuntime) {
|
||||||
final IModuleSetBuilder moduleSetBuilder = loadModuleScript(moduleFile);
|
final IModuleSetBuilder moduleSetBuilder = loadModuleScript(moduleFile);
|
||||||
if (moduleSetBuilder == null) {
|
if (moduleSetBuilder == null) {
|
||||||
return;
|
return;
|
||||||
@@ -156,9 +164,9 @@ public class CompileEnvironment {
|
|||||||
final String directory = new File(moduleFile).getParent();
|
final String directory = new File(moduleFile).getParent();
|
||||||
for (IModuleBuilder moduleBuilder : moduleSetBuilder.getModules()) {
|
for (IModuleBuilder moduleBuilder : moduleSetBuilder.getModules()) {
|
||||||
ClassFileFactory moduleFactory = compileModule(moduleBuilder, directory);
|
ClassFileFactory moduleFactory = compileModule(moduleBuilder, directory);
|
||||||
final String path = new File(directory, moduleBuilder.getModuleName() + ".jar").getPath();
|
final String path = jarPath != null ? jarPath : new File(directory, moduleBuilder.getModuleName() + ".jar").getPath();
|
||||||
try {
|
try {
|
||||||
writeToJar(moduleFactory, new FileOutputStream(path), null, true);
|
writeToJar(moduleFactory, new FileOutputStream(path), null, jarRuntime);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new CompileEnvironmentException("Invalid jar path " + path, e);
|
throw new CompileEnvironmentException("Invalid jar path " + path, e);
|
||||||
}
|
}
|
||||||
@@ -168,25 +176,7 @@ public class CompileEnvironment {
|
|||||||
public IModuleSetBuilder loadModuleScript(String moduleFile) {
|
public IModuleSetBuilder loadModuleScript(String moduleFile) {
|
||||||
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
||||||
scriptCompileSession.addSources(moduleFile);
|
scriptCompileSession.addSources(moduleFile);
|
||||||
|
scriptCompileSession.addStdLibSources();
|
||||||
URL url = CompileEnvironment.class.getClassLoader().getResource("ModuleBuilder.kt");
|
|
||||||
if (url != null) {
|
|
||||||
String path = url.getPath();
|
|
||||||
if (path.startsWith("file:")) {
|
|
||||||
path = path.substring(5);
|
|
||||||
}
|
|
||||||
final VirtualFile vFile = myEnvironment.getJarFileSystem().findFileByPath(path);
|
|
||||||
if (vFile == null) {
|
|
||||||
throw new CompileEnvironmentException("Couldn't load ModuleBuilder.kt from runtime jar: "+ url);
|
|
||||||
}
|
|
||||||
scriptCompileSession.addSources(vFile);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// building from source
|
|
||||||
final String homeDirectory = getHomeDirectory();
|
|
||||||
final File file = new File(homeDirectory, "stdlib/ktSrc/ModuleBuilder.kt");
|
|
||||||
scriptCompileSession.addSources(myEnvironment.getLocalFileSystem().findFileByPath(file.getPath()));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!scriptCompileSession.analyze(myErrorStream)) {
|
if (!scriptCompileSession.analyze(myErrorStream)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -223,6 +213,7 @@ public class CompileEnvironment {
|
|||||||
|
|
||||||
public ClassFileFactory compileModule(IModuleBuilder moduleBuilder, String directory) {
|
public ClassFileFactory compileModule(IModuleBuilder moduleBuilder, String directory) {
|
||||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||||
|
moduleCompileSession.addStdLibSources();
|
||||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||||
moduleCompileSession.addSources(new File(directory, sourceFile).getPath());
|
moduleCompileSession.addSources(new File(directory, sourceFile).getPath());
|
||||||
}
|
}
|
||||||
@@ -239,6 +230,17 @@ public class CompileEnvironment {
|
|||||||
return new File(PathManager.getResourceRoot(CompileEnvironment.class, "/org/jetbrains/jet/compiler/CompileEnvironment.class")).getParentFile().getParentFile().getParent();
|
return new File(PathManager.getResourceRoot(CompileEnvironment.class, "/org/jetbrains/jet/compiler/CompileEnvironment.class")).getParentFile().getParentFile().getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final List<String> sanitized = Arrays.asList("kotlin/", "std/");
|
||||||
|
public static boolean skipFile(String name) {
|
||||||
|
boolean skip = false;
|
||||||
|
for (String prefix : sanitized) {
|
||||||
|
if(name.startsWith(prefix)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) {
|
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) {
|
||||||
try {
|
try {
|
||||||
Manifest manifest = new Manifest();
|
Manifest manifest = new Manifest();
|
||||||
@@ -251,8 +253,10 @@ public class CompileEnvironment {
|
|||||||
JarOutputStream stream = new JarOutputStream(fos, manifest);
|
JarOutputStream stream = new JarOutputStream(fos, manifest);
|
||||||
try {
|
try {
|
||||||
for (String file : factory.files()) {
|
for (String file : factory.files()) {
|
||||||
stream.putNextEntry(new JarEntry(file));
|
if(!skipFile(file)) {
|
||||||
stream.write(factory.asBytes(file));
|
stream.putNextEntry(new JarEntry(file));
|
||||||
|
stream.write(factory.asBytes(file));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (includeRuntime) {
|
if (includeRuntime) {
|
||||||
writeRuntimeToJar(stream);
|
writeRuntimeToJar(stream);
|
||||||
@@ -316,9 +320,10 @@ public class CompileEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir) {
|
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||||
CompileSession session = new CompileSession(myEnvironment);
|
CompileSession session = new CompileSession(myEnvironment);
|
||||||
session.addSources(sourceFileOrDir);
|
session.addSources(sourceFileOrDir);
|
||||||
|
session.addStdLibSources();
|
||||||
|
|
||||||
String mainClass = null;
|
String mainClass = null;
|
||||||
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
||||||
@@ -334,7 +339,7 @@ public class CompileEnvironment {
|
|||||||
ClassFileFactory factory = session.generate();
|
ClassFileFactory factory = session.generate();
|
||||||
if (jar != null) {
|
if (jar != null) {
|
||||||
try {
|
try {
|
||||||
writeToJar(factory, new FileOutputStream(jar), mainClass, true);
|
writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new CompileEnvironmentException("Invalid jar path " + jar, e);
|
throw new CompileEnvironmentException("Invalid jar path " + jar, e);
|
||||||
}
|
}
|
||||||
@@ -350,13 +355,14 @@ public class CompileEnvironment {
|
|||||||
private static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
|
private static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
|
||||||
List<String> files = factory.files();
|
List<String> files = factory.files();
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
File target = new File(outputDir, file);
|
if(!skipFile(file)) {
|
||||||
try {
|
File target = new File(outputDir, file);
|
||||||
FileUtil.writeToFile(target, factory.asBytes(file));
|
try {
|
||||||
} catch (IOException e) {
|
FileUtil.writeToFile(target, factory.asBytes(file));
|
||||||
throw new CompileEnvironmentException(e);
|
} catch (IOException e) {
|
||||||
|
throw new CompileEnvironmentException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports;
|
import org.jetbrains.jet.lang.resolve.java.JavaDefaultImports;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -47,7 +48,22 @@ public class CompileSession {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addSources(vFile);
|
addSources(new File(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSources(File file) {
|
||||||
|
if(file.isDirectory()) {
|
||||||
|
for (File child : file.listFiles()) {
|
||||||
|
addSources(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
VirtualFile fileByPath = myEnvironment.getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
||||||
|
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(fileByPath);
|
||||||
|
if(psiFile instanceof JetFile) {
|
||||||
|
mySourceFileNamespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSources(VirtualFile vFile) {
|
public void addSources(VirtualFile vFile) {
|
||||||
@@ -66,13 +82,6 @@ public class CompileSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLibrarySources(VirtualFile vFile) {
|
|
||||||
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(vFile);
|
|
||||||
if (psiFile instanceof JetFile) {
|
|
||||||
myLibrarySourceFileNamespaces.add(((JetFile) psiFile).getRootNamespace());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<JetNamespace> getSourceFileNamespaces() {
|
public List<JetNamespace> getSourceFileNamespaces() {
|
||||||
return mySourceFileNamespaces;
|
return mySourceFileNamespaces;
|
||||||
}
|
}
|
||||||
@@ -104,4 +113,22 @@ public class CompileSession {
|
|||||||
generationState.compileCorrectNamespaces(myBindingContext, mySourceFileNamespaces);
|
generationState.compileCorrectNamespaces(myBindingContext, mySourceFileNamespaces);
|
||||||
return generationState.createText();
|
return generationState.createText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean addStdLibSources() {
|
||||||
|
final File unpackedRuntimePath = CompileEnvironment.getUnpackedRuntimePath();
|
||||||
|
if (unpackedRuntimePath != null) {
|
||||||
|
addSources(new File(unpackedRuntimePath, "../../../stdlib/ktSrc").getAbsoluteFile());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final File runtimeJarPath = CompileEnvironment.getRuntimeJarPath();
|
||||||
|
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||||
|
// todo
|
||||||
|
throw new UnsupportedOperationException("Loading of stdlib sources from jar");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ public class KotlinCompiler {
|
|||||||
public String src;
|
public String src;
|
||||||
@Argument(value = "module", description = "module to compile")
|
@Argument(value = "module", description = "module to compile")
|
||||||
public String module;
|
public String module;
|
||||||
|
@Argument(value = "includeRuntime", description = "include Kotlin runtime in to resulting jar")
|
||||||
|
public boolean includeRuntime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -32,7 +34,7 @@ public class KotlinCompiler {
|
|||||||
Args.parse(arguments, args);
|
Args.parse(arguments, args);
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
System.out.println("Usage: KotlinCompiler [-output <outputDir>|-jar <jarFileName>] -src <filename or dirname>");
|
System.out.println("Usage: KotlinCompiler [-output <outputDir>|-jar <jarFileName>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -47,11 +49,11 @@ public class KotlinCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.module != null) {
|
if (arguments.module != null) {
|
||||||
environment.compileModuleScript(arguments.module);
|
environment.compileModuleScript(arguments.module, arguments.jar, arguments.includeRuntime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir);
|
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
||||||
}
|
}
|
||||||
} catch (CompileEnvironmentException e) {
|
} catch (CompileEnvironmentException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ public interface Errors {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = new UnresolvedReferenceDiagnosticFactory("Unresolved reference");
|
UnresolvedReferenceDiagnosticFactory UNRESOLVED_REFERENCE = new UnresolvedReferenceDiagnosticFactory("Unresolved reference");
|
||||||
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.INSTANCE;
|
|
||||||
|
RedeclarationDiagnosticFactory REDECLARATION = RedeclarationDiagnosticFactory.REDECLARATION;
|
||||||
|
RedeclarationDiagnosticFactory NAME_SHADOWING = RedeclarationDiagnosticFactory.NAME_SHADOWING;
|
||||||
|
|
||||||
PsiElementOnlyDiagnosticFactory2<PsiElement, JetType, JetType> TYPE_MISMATCH = PsiElementOnlyDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected");
|
PsiElementOnlyDiagnosticFactory2<PsiElement, JetType, JetType> TYPE_MISMATCH = PsiElementOnlyDiagnosticFactory2.create(ERROR, "Type mismatch: inferred type is {1} but {0} was expected");
|
||||||
ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS = new ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>>(ERROR, "Incompatible modifiers: ''{0}''") {
|
ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS = new ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>>(ERROR, "Incompatible modifiers: ''{0}''") {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+8
-6
@@ -15,8 +15,8 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
|||||||
public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiElement> {
|
public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiElement> {
|
||||||
public class SimpleRedeclarationDiagnostic extends DiagnosticWithPsiElementImpl<PsiElement> implements RedeclarationDiagnostic {
|
public class SimpleRedeclarationDiagnostic extends DiagnosticWithPsiElementImpl<PsiElement> implements RedeclarationDiagnostic {
|
||||||
|
|
||||||
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name) {
|
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name, RedeclarationDiagnosticFactory factory) {
|
||||||
super(RedeclarationDiagnosticFactory.INSTANCE, ERROR, "Redeclaration: " + name, psiElement);
|
super(factory, factory.severity, factory.makeMessage(name), psiElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,11 +24,13 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
|
|||||||
|
|
||||||
private final DeclarationDescriptor duplicatingDescriptor;
|
private final DeclarationDescriptor duplicatingDescriptor;
|
||||||
private final BindingContext contextToResolveToDeclaration;
|
private final BindingContext contextToResolveToDeclaration;
|
||||||
|
private final RedeclarationDiagnosticFactory factory;
|
||||||
private PsiElement element;
|
private PsiElement element;
|
||||||
|
|
||||||
public RedeclarationDiagnosticWithDeferredResolution(@NotNull DeclarationDescriptor duplicatingDescriptor, @NotNull BindingContext contextToResolveToDeclaration) {
|
public RedeclarationDiagnosticWithDeferredResolution(@NotNull DeclarationDescriptor duplicatingDescriptor, @NotNull BindingContext contextToResolveToDeclaration, RedeclarationDiagnosticFactory factory) {
|
||||||
this.duplicatingDescriptor = duplicatingDescriptor;
|
this.duplicatingDescriptor = duplicatingDescriptor;
|
||||||
this.contextToResolveToDeclaration = contextToResolveToDeclaration;
|
this.contextToResolveToDeclaration = contextToResolveToDeclaration;
|
||||||
|
this.factory = factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
private PsiElement resolve() {
|
private PsiElement resolve() {
|
||||||
@@ -60,19 +62,19 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public DiagnosticFactory getFactory() {
|
public DiagnosticFactory getFactory() {
|
||||||
return Errors.REDECLARATION;
|
return factory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return "Redeclaration: " + duplicatingDescriptor.getName();
|
return factory.makeMessage(duplicatingDescriptor.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Severity getSeverity() {
|
public Severity getSeverity() {
|
||||||
return ERROR;
|
return factory.severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+20
-5
@@ -11,17 +11,28 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
|
public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
final Severity severity;
|
||||||
|
private final String messagePrefix;
|
||||||
|
|
||||||
public static final RedeclarationDiagnosticFactory INSTANCE = new RedeclarationDiagnosticFactory();
|
public static final RedeclarationDiagnosticFactory REDECLARATION = new RedeclarationDiagnosticFactory(
|
||||||
|
"REDECLARATION", Severity.ERROR, "Redeclaration: ");
|
||||||
|
public static final RedeclarationDiagnosticFactory NAME_SHADOWING = new RedeclarationDiagnosticFactory(
|
||||||
|
"NAME_SHADOWING", Severity.WARNING, "Name shadowed: ");
|
||||||
|
|
||||||
public RedeclarationDiagnosticFactory() {}
|
public RedeclarationDiagnosticFactory(String name, Severity severity, String messagePrefix) {
|
||||||
|
this.name = name;
|
||||||
|
this.severity = severity;
|
||||||
|
this.messagePrefix = messagePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
public RedeclarationDiagnostic on(@NotNull PsiElement duplicatingElement, @NotNull String name) {
|
public RedeclarationDiagnostic on(@NotNull PsiElement duplicatingElement, @NotNull String name) {
|
||||||
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement, name);
|
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement, name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Diagnostic on(DeclarationDescriptor duplicatingDescriptor, BindingContext contextToResolveToDeclaration) {
|
public Diagnostic on(DeclarationDescriptor duplicatingDescriptor, BindingContext contextToResolveToDeclaration) {
|
||||||
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration);
|
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -40,7 +51,11 @@ public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "REDECLARATION";
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String makeMessage(String identifier) {
|
||||||
|
return messagePrefix + identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -123,4 +123,35 @@ public class DescriptorUtils {
|
|||||||
}
|
}
|
||||||
return NO_RECEIVER;
|
return NO_RECEIVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The primary case for local extensions is the following:
|
||||||
|
*
|
||||||
|
* I had a locally declared extension function or a local variable of function type called foo
|
||||||
|
* And I called it on my x
|
||||||
|
* Now, someone added function foo() to the class of x
|
||||||
|
* My code should not change
|
||||||
|
*
|
||||||
|
* thus
|
||||||
|
*
|
||||||
|
* local extension prevail over members (and members prevail over all non-local extensions)
|
||||||
|
*/
|
||||||
|
public static boolean isLocal(DeclarationDescriptor containerOfTheCurrentLocality, DeclarationDescriptor candidate) {
|
||||||
|
if (candidate instanceof ValueParameterDescriptor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
DeclarationDescriptor parent = candidate.getContainingDeclaration();
|
||||||
|
if (!(parent instanceof FunctionDescriptor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
FunctionDescriptor functionDescriptor = (FunctionDescriptor) parent;
|
||||||
|
DeclarationDescriptor current = containerOfTheCurrentLocality;
|
||||||
|
while (current != null) {
|
||||||
|
if (current == functionDescriptor) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
current = current.getContainingDeclaration();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.Call;
|
import org.jetbrains.jet.lang.psi.Call;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetSuperExpression;
|
import org.jetbrains.jet.lang.psi.JetSuperExpression;
|
||||||
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.calls.autocasts.AutoCastService;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastService;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastServiceImpl;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastServiceImpl;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
@@ -36,7 +35,7 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
Collection<ResolvedCallImpl<D>> allDescriptors, DeclarationDescriptor containerOfTheCurrentLocality, Collection<ResolvedCallImpl<D>> local, Collection<ResolvedCallImpl<D>> nonlocal) {
|
Collection<ResolvedCallImpl<D>> allDescriptors, DeclarationDescriptor containerOfTheCurrentLocality, Collection<ResolvedCallImpl<D>> local, Collection<ResolvedCallImpl<D>> nonlocal) {
|
||||||
|
|
||||||
for (ResolvedCallImpl<D> resolvedCall : allDescriptors) {
|
for (ResolvedCallImpl<D> resolvedCall : allDescriptors) {
|
||||||
if (isLocal(containerOfTheCurrentLocality, resolvedCall.getCandidateDescriptor())) {
|
if (DescriptorUtils.isLocal(containerOfTheCurrentLocality, resolvedCall.getCandidateDescriptor())) {
|
||||||
local.add(resolvedCall);
|
local.add(resolvedCall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -45,37 +44,6 @@ import static org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The primary case for local extensions is the following:
|
|
||||||
*
|
|
||||||
* I had a locally declared extension function or a local variable of function type called foo
|
|
||||||
* And I called it on my x
|
|
||||||
* Now, someone added function foo() to the class of x
|
|
||||||
* My code should not change
|
|
||||||
*
|
|
||||||
* thus
|
|
||||||
*
|
|
||||||
* local extension prevail over members (and members prevail over all non-local extensions)
|
|
||||||
*/
|
|
||||||
private static boolean isLocal(DeclarationDescriptor containerOfTheCurrentLocality, DeclarationDescriptor candidate) {
|
|
||||||
if (candidate instanceof ValueParameterDescriptor) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
DeclarationDescriptor parent = candidate.getContainingDeclaration();
|
|
||||||
if (!(parent instanceof FunctionDescriptor)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) parent;
|
|
||||||
DeclarationDescriptor current = containerOfTheCurrentLocality;
|
|
||||||
while (current != null) {
|
|
||||||
if (current == functionDescriptor) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
current = current.getContainingDeclaration();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
/*package*/ static JetSuperExpression getReceiverSuper(@NotNull ReceiverDescriptor receiver) {
|
/*package*/ static JetSuperExpression getReceiverSuper(@NotNull ReceiverDescriptor receiver) {
|
||||||
if (receiver instanceof ExpressionReceiver) {
|
if (receiver instanceof ExpressionReceiver) {
|
||||||
|
|||||||
+15
-1
@@ -6,9 +6,12 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.TaskPrioritizers;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
@@ -211,12 +214,23 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
variableDescriptor = context.getDescriptorResolver().resolveLocalVariableDescriptor(context.scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// http://youtrack.jetbrains.net/issue/KT-527
|
||||||
|
|
||||||
|
VariableDescriptor olderVariable = context.scope.getVariable(variableDescriptor.getName());
|
||||||
|
if (olderVariable != null && DescriptorUtils.isLocal(context.scope.getContainingDeclaration(), olderVariable)) {
|
||||||
|
context.trace.report(Errors.NAME_SHADOWING.on(variableDescriptor, context.trace.getBindingContext()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loopScope.addVariableDescriptor(variableDescriptor);
|
loopScope.addVariableDescriptor(variableDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
JetExpression body = expression.getBody();
|
JetExpression body = expression.getBody();
|
||||||
if (body != null) {
|
if (body != null) {
|
||||||
facade.getType(body, context.replaceScope(loopScope));
|
ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(loopScope);
|
||||||
|
blockLevelVisitor.getType(body, context.replaceScope(loopScope));
|
||||||
}
|
}
|
||||||
|
|
||||||
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType);
|
return DataFlowUtils.checkType(JetStandardClasses.getUnitType(), expression, contextWithExpectedType);
|
||||||
|
|||||||
+8
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
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.TemporaryBindingTrace;
|
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||||
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||||
@@ -89,6 +90,13 @@ public class ExpressionTypingVisitorForStatements extends BasicExpressionTypingV
|
|||||||
JetType outType = propertyDescriptor.getOutType();
|
JetType outType = propertyDescriptor.getOutType();
|
||||||
JetType initializerType = facade.getType(initializer, context.replaceExpectedType(outType).replaceScope(scope));
|
JetType initializerType = facade.getType(initializer, context.replaceExpectedType(outType).replaceScope(scope));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
VariableDescriptor olderVariable = scope.getVariable(propertyDescriptor.getName());
|
||||||
|
if (olderVariable != null && DescriptorUtils.isLocal(propertyDescriptor.getContainingDeclaration(), olderVariable)) {
|
||||||
|
context.trace.report(Errors.NAME_SHADOWING.on(propertyDescriptor, context.trace.getBindingContext()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scope.addVariableDescriptor(propertyDescriptor);
|
scope.addVariableDescriptor(propertyDescriptor);
|
||||||
return checkExpectedType(property, context);
|
return checkExpectedType(property, context);
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// http://youtrack.jetbrains.net/issue/KT-552
|
||||||
|
// KT-552 For variable unresolved if loop body is not block
|
||||||
|
|
||||||
|
fun ff() {
|
||||||
|
var i = 1
|
||||||
|
for (j in 1..10)
|
||||||
|
i += j
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
fun f(p: Int): Int {
|
||||||
|
val <!NAME_SHADOWING!>p<!> = 2
|
||||||
|
return p
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun f(i: Int) {
|
||||||
|
for (j in 1..100) {
|
||||||
|
{
|
||||||
|
var <!NAME_SHADOWING!>i<!> = 12
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val i = 17
|
||||||
|
|
||||||
|
val f = { (): Int => var i = 17; i }
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class RedefinePropertyInFor() {
|
||||||
|
|
||||||
|
var i = 1
|
||||||
|
|
||||||
|
fun ff() {
|
||||||
|
for (i in 0..10) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class RedefinePropertyInFunction() {
|
||||||
|
|
||||||
|
var i = 17
|
||||||
|
|
||||||
|
fun f(): Int {
|
||||||
|
var i = 18
|
||||||
|
return i
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun ff(): Int {
|
||||||
|
var i = 1
|
||||||
|
for (<!NAME_SHADOWING!>i<!> in 0..10) {
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
fun ff(): Int {
|
||||||
|
var i = 1
|
||||||
|
{
|
||||||
|
val <!NAME_SHADOWING!>i<!> = 2
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun f(): Int {
|
||||||
|
var i = 17
|
||||||
|
{ (): Unit => var <!NAME_SHADOWING!>i<!> = 18 }
|
||||||
|
return i
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
fun ff(): Int {
|
||||||
|
var i = 1
|
||||||
|
{ (i: Int) => i }
|
||||||
|
return i
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
namespace demo
|
||||||
|
|
||||||
|
public open class Identifier<T>(myName : T?, myHasDollar : Boolean) {
|
||||||
|
{
|
||||||
|
$myName = myName
|
||||||
|
$myHasDollar = myHasDollar
|
||||||
|
}
|
||||||
|
|
||||||
|
private val myName : T?
|
||||||
|
private var myHasDollar : Boolean
|
||||||
|
private var myNullable : Boolean = true
|
||||||
|
|
||||||
|
open public fun getName() : T? {
|
||||||
|
return myName
|
||||||
|
}
|
||||||
|
|
||||||
|
class object {
|
||||||
|
open public fun init<T>(name : T?) : Identifier<T> {
|
||||||
|
val __ = Identifier<T>(name, false)
|
||||||
|
return __
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
var i3 : Identifier<*>? = Identifier.init<String?>("name")
|
||||||
|
System.out?.println("Hello, " + i3?.getName())
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
namespace Smoke
|
namespace Smoke
|
||||||
|
|
||||||
|
import std.io.*
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
print(args)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<orderEntry type="module" module-name="frontend" />
|
<orderEntry type="module" module-name="frontend" />
|
||||||
<orderEntry type="module" module-name="frontend.java" />
|
<orderEntry type="module" module-name="frontend.java" />
|
||||||
<orderEntry type="module" module-name="stdlib" />
|
<orderEntry type="module" module-name="stdlib" />
|
||||||
|
<orderEntry type="module" module-name="cli" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -9,6 +13,8 @@ import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
|||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|||||||
@@ -25,4 +25,8 @@ public class ObjectGenTest extends CodegenTestCase {
|
|||||||
public void testKt560() throws Exception {
|
public void testKt560() throws Exception {
|
||||||
blackBoxFile("regressions/kt560.jet");
|
blackBoxFile("regressions/kt560.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt640() throws Exception {
|
||||||
|
blackBoxFile("regressions/kt640.jet");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import com.intellij.openapi.vfs.CharsetToolkit;
|
|||||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
|
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||||
import org.jetbrains.jet.compiler.CompileSession;
|
import org.jetbrains.jet.compiler.CompileSession;
|
||||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
@@ -30,8 +31,8 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
|
|
||||||
session.addSources(myFile.getVirtualFile());
|
session.addSources(myFile.getVirtualFile());
|
||||||
try {
|
try {
|
||||||
session.addSources(addStdLib());
|
session.addStdLibSources();
|
||||||
} catch (IOException e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,9 +46,9 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
protected ClassFileFactory generateClassesInFile() {
|
protected ClassFileFactory generateClassesInFile() {
|
||||||
try {
|
try {
|
||||||
CompileSession session = new CompileSession(myEnvironment);
|
CompileSession session = new CompileSession(myEnvironment);
|
||||||
|
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||||
session.addSources(myFile.getVirtualFile());
|
session.addSources(myFile.getVirtualFile());
|
||||||
session.addSources(addStdLib());
|
session.addStdLibSources();
|
||||||
|
|
||||||
if (!session.analyze(System.out)) {
|
if (!session.analyze(System.out)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -57,18 +58,11 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
throw e;
|
throw e;
|
||||||
} catch (IOException e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VirtualFile addStdLib() throws IOException {
|
|
||||||
String text = FileUtil.loadFile(new File(JetParsingTest.getTestDataDir() + "/../../stdlib/ktSrc/StandardLibrary.kt"), CharsetToolkit.UTF8).trim();
|
|
||||||
text = StringUtil.convertLineSeparators(text);
|
|
||||||
PsiFile stdLibFile = createFile("StandardLibrary.kt", text);
|
|
||||||
return stdLibFile.getVirtualFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInputStreamIterator () {
|
public void testInputStreamIterator () {
|
||||||
blackBoxFile("inputStreamIterator.jet");
|
blackBoxFile("inputStreamIterator.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
@@ -85,4 +79,16 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
public void testKt528 () {
|
public void testKt528 () {
|
||||||
blackBoxFile("regressions/kt528.kt");
|
blackBoxFile("regressions/kt528.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCollectionSize () throws Exception {
|
||||||
|
loadText("import std.util.*; fun box() = if(java.util.Arrays.asList(0, 1, 2)?.size == 3) \"OK\" else \"fail\"");
|
||||||
|
// System.out.println(generateToText());
|
||||||
|
blackBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testCollectionEmpty () throws Exception {
|
||||||
|
loadText("import std.util.*; fun box() = if(java.util.Arrays.asList(0, 1, 2)?.empty ?: false) \"OK\" else \"fail\"");
|
||||||
|
// System.out.println(generateToText());
|
||||||
|
blackBox();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,20 @@ package org.jetbrains.jet.compiler;
|
|||||||
import jet.modules.IModuleBuilder;
|
import jet.modules.IModuleBuilder;
|
||||||
import jet.modules.IModuleSetBuilder;
|
import jet.modules.IModuleSetBuilder;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yole
|
* @author yole
|
||||||
|
* @author alex.tkachman
|
||||||
*/
|
*/
|
||||||
public class CompileEnvironmentTest extends TestCase {
|
public class CompileEnvironmentTest extends TestCase {
|
||||||
private CompileEnvironment environment;
|
private CompileEnvironment environment;
|
||||||
@@ -51,7 +51,58 @@ public class CompileEnvironmentTest extends TestCase {
|
|||||||
assertTrue(entries.contains("Smoke/namespace.class"));
|
assertTrue(entries.contains("Smoke/namespace.class"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> listEntries(JarInputStream is) throws IOException {
|
public void testSmokeWithCompilerJar() throws IOException {
|
||||||
|
File tempFile = File.createTempFile("compilerTest", "compilerTest");
|
||||||
|
try {
|
||||||
|
KotlinCompiler.main(Arrays.asList("-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts", "-jar", tempFile.getAbsolutePath()).toArray(new String[0]));
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(tempFile);
|
||||||
|
try {
|
||||||
|
JarInputStream is = new JarInputStream(fileInputStream);
|
||||||
|
try {
|
||||||
|
final List<String> entries = listEntries(is);
|
||||||
|
assertTrue(entries.contains("Smoke/namespace.class"));
|
||||||
|
assertEquals(1, entries.size());
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fileInputStream.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
tempFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean delete(File file) {
|
||||||
|
boolean success = true;
|
||||||
|
if(file.isDirectory()) {
|
||||||
|
for (File child : file.listFiles()) {
|
||||||
|
success = success && delete(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return file.delete() && success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testSmokeWithCompilerOutput() throws IOException {
|
||||||
|
File tempFile = File.createTempFile("compilerTest", "compilerTest");
|
||||||
|
tempFile.delete();
|
||||||
|
tempFile = new File(tempFile.getAbsolutePath());
|
||||||
|
tempFile.mkdir();
|
||||||
|
try {
|
||||||
|
KotlinCompiler.main(Arrays.asList("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt", "-output", tempFile.getAbsolutePath()).toArray(new String[0]));
|
||||||
|
assertEquals(1, tempFile.listFiles().length);
|
||||||
|
assertEquals(1, tempFile.listFiles()[0].listFiles().length);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
delete(tempFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> listEntries(JarInputStream is) throws IOException {
|
||||||
List<String> entries = new ArrayList<String>();
|
List<String> entries = new ArrayList<String>();
|
||||||
while (true) {
|
while (true) {
|
||||||
final JarEntry jarEntry = is.getNextJarEntry();
|
final JarEntry jarEntry = is.getNextJarEntry();
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace std
|
||||||
|
|
||||||
|
namespace util {
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
|
val Collection<*>.size : Int
|
||||||
|
get() = size()
|
||||||
|
|
||||||
|
val Collection<*>.empty : Boolean
|
||||||
|
get() = isEmpty()
|
||||||
|
}
|
||||||
@@ -1,15 +1,5 @@
|
|||||||
namespace std
|
namespace std
|
||||||
|
|
||||||
namespace util {
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
val <T> Collection<T>.size : Int
|
|
||||||
get() = size()
|
|
||||||
|
|
||||||
val <T> Collection<T>.empty : Boolean
|
|
||||||
get() = isEmpty()
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace io {
|
namespace io {
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.nio.charset.*
|
import java.nio.charset.*
|
||||||
|
|||||||
Reference in New Issue
Block a user