Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -9,6 +9,11 @@
|
||||
<pathelement path="${output}/classes/runtime"/>
|
||||
</path>
|
||||
|
||||
<path id="classpath.kotlin">
|
||||
<path refid="classpath"/>
|
||||
<pathelement path="${output}/classes/compiler"/>
|
||||
</path>
|
||||
|
||||
<path id="sourcepath">
|
||||
<dirset dir="${basedir}/compiler">
|
||||
<include name="frontend/src"/>
|
||||
@@ -26,9 +31,21 @@
|
||||
</javac>
|
||||
</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">
|
||||
<fileset dir="${output}/classes/runtime"/>
|
||||
<fileset dir="${output}/classes/stdlib"/>
|
||||
<fileset dir="${basedir}/stdlib/ktSrc"/>
|
||||
</jar>
|
||||
</target>
|
||||
@@ -49,7 +66,11 @@
|
||||
</jar>
|
||||
</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">
|
||||
<zipfileset prefix="${output.name}/bin" filemode="755" dir="${basedir}/compiler/cli/bin"/>
|
||||
<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.io.FileUtil;
|
||||
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 com.intellij.util.Function;
|
||||
import com.intellij.util.Processor;
|
||||
import jet.modules.IModuleBuilder;
|
||||
@@ -22,6 +24,8 @@ import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.jar.*;
|
||||
|
||||
@@ -53,14 +57,18 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
public boolean initializeKotlinRuntime() {
|
||||
return initializeKotlinRuntime(myEnvironment);
|
||||
}
|
||||
|
||||
public static boolean initializeKotlinRuntime(JetCoreEnvironment environment) {
|
||||
final File unpackedRuntimePath = getUnpackedRuntimePath();
|
||||
if (unpackedRuntimePath != null) {
|
||||
myEnvironment.addToClasspath(unpackedRuntimePath);
|
||||
environment.addToClasspath(unpackedRuntimePath);
|
||||
}
|
||||
else {
|
||||
final File runtimeJarPath = getRuntimeJarPath();
|
||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||
myEnvironment.addToClasspath(runtimeJarPath);
|
||||
environment.addToClasspath(runtimeJarPath);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
@@ -147,7 +155,7 @@ public class CompileEnvironment {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void compileModuleScript(String moduleFile) {
|
||||
public void compileModuleScript(String moduleFile, String jarPath, boolean jarRuntime) {
|
||||
final IModuleSetBuilder moduleSetBuilder = loadModuleScript(moduleFile);
|
||||
if (moduleSetBuilder == null) {
|
||||
return;
|
||||
@@ -156,9 +164,9 @@ public class CompileEnvironment {
|
||||
final String directory = new File(moduleFile).getParent();
|
||||
for (IModuleBuilder moduleBuilder : moduleSetBuilder.getModules()) {
|
||||
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 {
|
||||
writeToJar(moduleFactory, new FileOutputStream(path), null, true);
|
||||
writeToJar(moduleFactory, new FileOutputStream(path), null, jarRuntime);
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new CompileEnvironmentException("Invalid jar path " + path, e);
|
||||
}
|
||||
@@ -168,25 +176,7 @@ public class CompileEnvironment {
|
||||
public IModuleSetBuilder loadModuleScript(String moduleFile) {
|
||||
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
||||
scriptCompileSession.addSources(moduleFile);
|
||||
|
||||
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()));
|
||||
}
|
||||
scriptCompileSession.addStdLibSources();
|
||||
|
||||
if (!scriptCompileSession.analyze(myErrorStream)) {
|
||||
return null;
|
||||
@@ -223,6 +213,7 @@ public class CompileEnvironment {
|
||||
|
||||
public ClassFileFactory compileModule(IModuleBuilder moduleBuilder, String directory) {
|
||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||
moduleCompileSession.addStdLibSources();
|
||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||
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();
|
||||
}
|
||||
|
||||
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) {
|
||||
try {
|
||||
Manifest manifest = new Manifest();
|
||||
@@ -251,8 +253,10 @@ public class CompileEnvironment {
|
||||
JarOutputStream stream = new JarOutputStream(fos, manifest);
|
||||
try {
|
||||
for (String file : factory.files()) {
|
||||
stream.putNextEntry(new JarEntry(file));
|
||||
stream.write(factory.asBytes(file));
|
||||
if(!skipFile(file)) {
|
||||
stream.putNextEntry(new JarEntry(file));
|
||||
stream.write(factory.asBytes(file));
|
||||
}
|
||||
}
|
||||
if (includeRuntime) {
|
||||
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);
|
||||
session.addSources(sourceFileOrDir);
|
||||
session.addStdLibSources();
|
||||
|
||||
String mainClass = null;
|
||||
for (JetNamespace namespace : session.getSourceFileNamespaces()) {
|
||||
@@ -334,7 +339,7 @@ public class CompileEnvironment {
|
||||
ClassFileFactory factory = session.generate();
|
||||
if (jar != null) {
|
||||
try {
|
||||
writeToJar(factory, new FileOutputStream(jar), mainClass, true);
|
||||
writeToJar(factory, new FileOutputStream(jar), mainClass, includeRuntime);
|
||||
} catch (FileNotFoundException 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) {
|
||||
List<String> files = factory.files();
|
||||
for (String file : files) {
|
||||
File target = new File(outputDir, file);
|
||||
try {
|
||||
FileUtil.writeToFile(target, factory.asBytes(file));
|
||||
} catch (IOException e) {
|
||||
throw new CompileEnvironmentException(e);
|
||||
if(!skipFile(file)) {
|
||||
File target = new File(outputDir, file);
|
||||
try {
|
||||
FileUtil.writeToFile(target, factory.asBytes(file));
|
||||
} 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.plugin.JetFileType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -47,7 +48,22 @@ public class CompileSession {
|
||||
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) {
|
||||
@@ -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() {
|
||||
return mySourceFileNamespaces;
|
||||
}
|
||||
@@ -104,4 +113,22 @@ public class CompileSession {
|
||||
generationState.compileCorrectNamespaces(myBindingContext, mySourceFileNamespaces);
|
||||
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;
|
||||
@Argument(value = "module", description = "module to compile")
|
||||
public String module;
|
||||
@Argument(value = "includeRuntime", description = "include Kotlin runtime in to resulting jar")
|
||||
public boolean includeRuntime;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -32,7 +34,7 @@ public class KotlinCompiler {
|
||||
Args.parse(arguments, args);
|
||||
}
|
||||
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();
|
||||
return;
|
||||
}
|
||||
@@ -47,11 +49,11 @@ public class KotlinCompiler {
|
||||
}
|
||||
|
||||
if (arguments.module != null) {
|
||||
environment.compileModuleScript(arguments.module);
|
||||
environment.compileModuleScript(arguments.module, arguments.jar, arguments.includeRuntime);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir);
|
||||
environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime);
|
||||
}
|
||||
} catch (CompileEnvironmentException e) {
|
||||
System.out.println(e.getMessage());
|
||||
|
||||
@@ -44,7 +44,10 @@ public interface Errors {
|
||||
}
|
||||
};
|
||||
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");
|
||||
ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>> INCOMPATIBLE_MODIFIERS = new ParameterizedDiagnosticFactory1<Collection<JetKeywordToken>>(ERROR, "Incompatible modifiers: ''{0}''") {
|
||||
@Override
|
||||
|
||||
+8
-6
@@ -15,8 +15,8 @@ import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR;
|
||||
public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiElement> {
|
||||
public class SimpleRedeclarationDiagnostic extends DiagnosticWithPsiElementImpl<PsiElement> implements RedeclarationDiagnostic {
|
||||
|
||||
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name) {
|
||||
super(RedeclarationDiagnosticFactory.INSTANCE, ERROR, "Redeclaration: " + name, psiElement);
|
||||
public SimpleRedeclarationDiagnostic(@NotNull PsiElement psiElement, @NotNull String name, RedeclarationDiagnosticFactory factory) {
|
||||
super(factory, factory.severity, factory.makeMessage(name), psiElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,13 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
|
||||
|
||||
private final DeclarationDescriptor duplicatingDescriptor;
|
||||
private final BindingContext contextToResolveToDeclaration;
|
||||
private final RedeclarationDiagnosticFactory factory;
|
||||
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.contextToResolveToDeclaration = contextToResolveToDeclaration;
|
||||
this.factory = factory;
|
||||
}
|
||||
|
||||
private PsiElement resolve() {
|
||||
@@ -60,19 +62,19 @@ public interface RedeclarationDiagnostic extends DiagnosticWithPsiElement<PsiEle
|
||||
@NotNull
|
||||
@Override
|
||||
public DiagnosticFactory getFactory() {
|
||||
return Errors.REDECLARATION;
|
||||
return factory;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Redeclaration: " + duplicatingDescriptor.getName();
|
||||
return factory.makeMessage(duplicatingDescriptor.getName());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Severity getSeverity() {
|
||||
return ERROR;
|
||||
return factory.severity;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+20
-5
@@ -11,17 +11,28 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
* @author abreslav
|
||||
*/
|
||||
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) {
|
||||
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement, name);
|
||||
return new RedeclarationDiagnostic.SimpleRedeclarationDiagnostic(duplicatingElement, name, this);
|
||||
}
|
||||
|
||||
public Diagnostic on(DeclarationDescriptor duplicatingDescriptor, BindingContext contextToResolveToDeclaration) {
|
||||
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration);
|
||||
return new RedeclarationDiagnostic.RedeclarationDiagnosticWithDeferredResolution(duplicatingDescriptor, contextToResolveToDeclaration, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -40,7 +51,11 @@ public class RedeclarationDiagnosticFactory extends AbstractDiagnosticFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "REDECLARATION";
|
||||
return name;
|
||||
}
|
||||
|
||||
public String makeMessage(String identifier) {
|
||||
return messagePrefix + identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -123,4 +123,35 @@ public class DescriptorUtils {
|
||||
}
|
||||
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.jet.lang.descriptors.CallableDescriptor;
|
||||
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.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSuperExpression;
|
||||
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.AutoCastServiceImpl;
|
||||
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) {
|
||||
|
||||
for (ResolvedCallImpl<D> resolvedCall : allDescriptors) {
|
||||
if (isLocal(containerOfTheCurrentLocality, resolvedCall.getCandidateDescriptor())) {
|
||||
if (DescriptorUtils.isLocal(containerOfTheCurrentLocality, resolvedCall.getCandidateDescriptor())) {
|
||||
local.add(resolvedCall);
|
||||
}
|
||||
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
|
||||
/*package*/ static JetSuperExpression getReceiverSuper(@NotNull ReceiverDescriptor receiver) {
|
||||
if (receiver instanceof ExpressionReceiver) {
|
||||
|
||||
+15
-1
@@ -6,9 +6,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
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.resolve.BindingContext;
|
||||
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.OverloadResolutionResults;
|
||||
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);
|
||||
}
|
||||
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
JetExpression body = expression.getBody();
|
||||
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);
|
||||
|
||||
+8
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallMaker;
|
||||
@@ -89,6 +90,13 @@ public class ExpressionTypingVisitorForStatements extends BasicExpressionTypingV
|
||||
JetType outType = propertyDescriptor.getOutType();
|
||||
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);
|
||||
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
|
||||
|
||||
import std.io.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
print(args)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
<orderEntry type="module" module-name="stdlib" />
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
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.jet.JetLiteFixture;
|
||||
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.junit.Assert;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -25,4 +25,8 @@ public class ObjectGenTest extends CodegenTestCase {
|
||||
public void testKt560() throws Exception {
|
||||
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.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
@@ -30,8 +31,8 @@ public class StdlibTest extends CodegenTestCase {
|
||||
|
||||
session.addSources(myFile.getVirtualFile());
|
||||
try {
|
||||
session.addSources(addStdLib());
|
||||
} catch (IOException e) {
|
||||
session.addStdLibSources();
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -45,9 +46,9 @@ public class StdlibTest extends CodegenTestCase {
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
|
||||
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||
session.addSources(myFile.getVirtualFile());
|
||||
session.addSources(addStdLib());
|
||||
session.addStdLibSources();
|
||||
|
||||
if (!session.analyze(System.out)) {
|
||||
return null;
|
||||
@@ -57,18 +58,11 @@ public class StdlibTest extends CodegenTestCase {
|
||||
} catch (RuntimeException e) {
|
||||
System.out.println(generateToText());
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
} catch (Throwable 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 () {
|
||||
blackBoxFile("inputStreamIterator.jet");
|
||||
// System.out.println(generateToText());
|
||||
@@ -85,4 +79,16 @@ public class StdlibTest extends CodegenTestCase {
|
||||
public void testKt528 () {
|
||||
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.IModuleSetBuilder;
|
||||
import junit.framework.TestCase;
|
||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class CompileEnvironmentTest extends TestCase {
|
||||
private CompileEnvironment environment;
|
||||
@@ -51,7 +51,58 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
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>();
|
||||
while (true) {
|
||||
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 util {
|
||||
import java.util.*
|
||||
|
||||
val <T> Collection<T>.size : Int
|
||||
get() = size()
|
||||
|
||||
val <T> Collection<T>.empty : Boolean
|
||||
get() = isEmpty()
|
||||
}
|
||||
|
||||
namespace io {
|
||||
import java.io.*
|
||||
import java.nio.charset.*
|
||||
|
||||
Reference in New Issue
Block a user