Move built-in files out of source directory
This commit is contained in:
Generated
+3
@@ -17,6 +17,9 @@
|
||||
<element id="module-output" name="cli-common" />
|
||||
<element id="module-output" name="ide-compiler-runner" />
|
||||
<element id="module-output" name="preloader" />
|
||||
<element id="directory" name="jet">
|
||||
<element id="dir-copy" path="$PROJECT_DIR$/compiler/frontend/builtins/jet" />
|
||||
</element>
|
||||
</element>
|
||||
<element id="library" level="project" name="js-libs" />
|
||||
<element id="library" level="project" name="javax.inject" />
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
<classpath refid="classpath"/>
|
||||
</javac>
|
||||
<copy todir="${output}/classes/generators">
|
||||
<fileset dir="compiler/frontend/src" includes="**/*.jet"/>
|
||||
<fileset dir="compiler/frontend/builtins" includes="**/*.jet"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
@@ -267,7 +267,7 @@
|
||||
<sequential>
|
||||
<jar jarfile="@{jarfile}" compress="@{compress}">
|
||||
<fileset dir="${output}/classes/compiler"/>
|
||||
<fileset dir="${basedir}/compiler/frontend/src" includes="jet/**"/>
|
||||
<fileset dir="${basedir}/compiler/frontend/builtins" includes="jet/**"/>
|
||||
|
||||
<zipgroupfileset dir="${basedir}/lib" includes="*.jar"/>
|
||||
<zipgroupfileset dir="${basedir}/ideaSDK/core" includes="*.jar" excludes="util.jar"/>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
* Copyright 2010-2013 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.
|
||||
@@ -20,14 +20,17 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.StandardFileSystems;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.util.LocalTimeCounter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
@@ -48,10 +51,14 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.types.lang.PrimitiveType.*;
|
||||
@@ -247,16 +254,11 @@ public class KotlinBuiltIns {
|
||||
{
|
||||
List<JetFile> files = new LinkedList<JetFile>();
|
||||
for(String path : libraryFiles) {
|
||||
InputStream stream = KotlinBuiltIns.class.getClassLoader().getResourceAsStream(path);
|
||||
String text = loadBuiltInFileText(path);
|
||||
|
||||
if (stream == null) {
|
||||
throw new IllegalStateException("Resource not found in classpath: " + path);
|
||||
}
|
||||
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText(
|
||||
path, JetFileType.INSTANCE, StringUtil.convertLineSeparators(text), LocalTimeCounter.currentTime(), true, false);
|
||||
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
String text = FileUtil.loadTextAndClose(new InputStreamReader(stream));
|
||||
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText(path,
|
||||
JetFileType.INSTANCE, StringUtil.convertLineSeparators(text), LocalTimeCounter.currentTime(), true, false);
|
||||
files.add(file);
|
||||
}
|
||||
return files;
|
||||
@@ -277,7 +279,57 @@ public class KotlinBuiltIns {
|
||||
jetArrayTypeToPrimitiveJetType.put(arrayType, type);
|
||||
}
|
||||
|
||||
private static String loadBuiltInFileText(String path) throws IOException {
|
||||
InputStream stream = KotlinBuiltIns.class.getClassLoader().getResourceAsStream(path);
|
||||
if (stream == null) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
//noinspection TestOnlyProblems
|
||||
return FileUtil.loadFile(getInTestBuiltInPath(path));
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Resource not found in classpath: " + path);
|
||||
}
|
||||
|
||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
||||
return FileUtil.loadTextAndClose(new InputStreamReader(stream));
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
private static File getInTestBuiltInPath(String path) {
|
||||
return new File("compiler/frontend/builtins", path);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@NotNull
|
||||
public static URL getBuiltInsDirUrl() {
|
||||
String builtInFilePath = "/" + LIBRARY_FILES.get(0);
|
||||
String dirPath = "/" + BUILT_INS_DIR;
|
||||
|
||||
URL url = KotlinBuiltIns.class.getResource(builtInFilePath);
|
||||
URL dirUrl = KotlinBuiltIns.class.getResource(dirPath);
|
||||
|
||||
if (url == null || dirUrl == null) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
// HACK: Temp code. Get built-in files from the sources when running from test.
|
||||
try {
|
||||
@SuppressWarnings("TestOnlyProblems") File builtInDir = getInTestBuiltInPath(BUILT_INS_DIR);
|
||||
return new URL(StandardFileSystems.FILE_PROTOCOL, "", FileUtil.toSystemIndependentName(builtInDir.getAbsolutePath()));
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
throw ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
throw new IllegalStateException("Built-ins file wasn't found at url: " + builtInFilePath);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Built-ins directory wasn't found at url: " + dirPath);
|
||||
}
|
||||
}
|
||||
|
||||
return dirUrl;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ModuleDescriptorImpl getBuiltInsModule() {
|
||||
|
||||
+2
-1
@@ -48,6 +48,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -234,7 +235,7 @@ public class KotlinJavaFileStubProvider implements CachedValueProvider<PsiJavaFi
|
||||
String path = virtualFile == null ? "<null>" : virtualFile.getPath();
|
||||
LOG.error(
|
||||
"Could not generate LightClass for " + fqName + " declared in " + path + "\n" +
|
||||
"built-ins dir URL is " + LightClassUtil.getBuiltInsDirResourceUrl() + "\n" +
|
||||
"built-ins dir URL is " + KotlinBuiltIns.getBuiltInsDirUrl() + "\n" +
|
||||
"System: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + " Java Runtime: " + SystemInfo.JAVA_RUNTIME_VERSION,
|
||||
cause);
|
||||
}
|
||||
|
||||
@@ -43,56 +43,46 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.utils.KotlinVfsUtil;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.*;
|
||||
|
||||
public class LightClassUtil {
|
||||
private static final Logger LOG = Logger.getInstance(LightClassUtil.class);
|
||||
private static final String DEFINITION_OF_ANY = "Any.jet";
|
||||
|
||||
/**
|
||||
* Checks whether the given file is loaded from the location where Kotlin's built-in classes are defined.
|
||||
* As of today, this is compiler/frontend/src/jet directory and files such as Any.jet, Nothing.jet etc.
|
||||
* As of today, this is compiler/frontend/builtins/jet directory and files such as Any.jet, Nothing.jet etc.
|
||||
*
|
||||
* Used to skip JetLightClass creation for built-ins, because built-in classes have no Java counterparts
|
||||
*/
|
||||
public static boolean belongsToKotlinBuiltIns(@NotNull JetFile file) {
|
||||
try {
|
||||
String jetVfsPathUrl = KotlinVfsUtil.convertFromUrl(getBuiltInsDirResourceUrl());
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
VirtualFile parent = virtualFile.getParent();
|
||||
if (parent != null) {
|
||||
String fileDirVfsUrl = parent.getUrl() + "/" + DEFINITION_OF_ANY;
|
||||
VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
VirtualFile parent = virtualFile.getParent();
|
||||
if (parent != null) {
|
||||
try {
|
||||
String jetVfsPathUrl = KotlinVfsUtil.convertFromUrl(KotlinBuiltIns.getBuiltInsDirUrl());
|
||||
|
||||
String fileDirVfsUrl = parent.getUrl();
|
||||
if (jetVfsPathUrl.equals(fileDirVfsUrl)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MalformedURLException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
// We deliberately return false on error: who knows what weird URLs we might come across out there
|
||||
// it would be a pity if no light classes would be created in such cases
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static URL getBuiltInsDirResourceUrl() {
|
||||
String pathToAny = "/" + KotlinBuiltIns.BUILT_INS_DIR + "/" + DEFINITION_OF_ANY;
|
||||
URL url = KotlinBuiltIns.class.getResource(pathToAny);
|
||||
if (url == null) {
|
||||
throw new IllegalStateException("Built-ins not found in the classpath: " + pathToAny);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
/*package*/ static void logErrorWithOSInfo(@Nullable Throwable cause, @NotNull FqName fqName, @Nullable VirtualFile virtualFile) {
|
||||
String path = virtualFile == null ? "<null>" : virtualFile.getPath();
|
||||
LOG.error(
|
||||
"Could not generate LightClass for " + fqName + " declared in " + path + "\n" +
|
||||
"built-ins dir URL is " + getBuiltInsDirResourceUrl() + "\n" +
|
||||
"built-ins dir URL is " + KotlinBuiltIns.getBuiltInsDirUrl() + "\n" +
|
||||
"System: " + SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION + " Java Runtime: " + SystemInfo.JAVA_RUNTIME_VERSION,
|
||||
cause);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.io.PrintWriter;
|
||||
|
||||
public class GenerateFunctions {
|
||||
public static final int MAX_PARAM_COUNT = 22;
|
||||
public static final File JET_SRC_DIR = new File("compiler/frontend/src/jet/");
|
||||
public static final File JET_SRC_DIR = new File("compiler/frontend/builtins/jet/");
|
||||
public static final File RUNTIME_SRC_DIR = new File("runtime/src/jet/");
|
||||
|
||||
private final PrintWriter out;
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.references;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.components.AbstractProjectComponent;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
@@ -91,15 +89,15 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
||||
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
|
||||
jetNamespace.setMemberScope(scope);
|
||||
|
||||
List<JetFile> jetBuiltInsFiles = getJetFiles("jet", Predicates.<JetFile>alwaysTrue());
|
||||
List<JetFile> jetBuiltInsFiles = getJetBuiltinsFiles();
|
||||
TopDownAnalyzer.processStandardLibraryNamespace(myProject, context, scope, jetNamespace, jetBuiltInsFiles);
|
||||
|
||||
builtInsSources = Sets.newHashSet(jetBuiltInsFiles);
|
||||
bindingContext = context.getBindingContext();
|
||||
}
|
||||
|
||||
private List<JetFile> getJetFiles(String dir, final Predicate<JetFile> filter) {
|
||||
URL url = BuiltInsReferenceResolver.class.getResource("/" + dir + "/");
|
||||
private List<JetFile> getJetBuiltinsFiles() {
|
||||
URL url = KotlinBuiltIns.getBuiltInsDirUrl();
|
||||
VirtualFile vf = VfsUtil.findFileByURL(url);
|
||||
assert vf != null : "Virtual file not found by URL: " + url;
|
||||
|
||||
@@ -116,11 +114,7 @@ public class BuiltInsReferenceResolver extends AbstractProjectComponent {
|
||||
return ContainerUtil.mapNotNull(psiDirectory.getFiles(), new Function<PsiFile, JetFile>() {
|
||||
@Override
|
||||
public JetFile fun(PsiFile file) {
|
||||
if (file instanceof JetFile) {
|
||||
JetFile jetFile = (JetFile) file;
|
||||
return filter.apply(jetFile) ? jetFile : null;
|
||||
}
|
||||
return null;
|
||||
return file instanceof JetFile ? (JetFile) file : null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user