js.annotations -> js

path independent jslib
This commit is contained in:
Pavel Talanov
2012-02-07 22:15:09 +04:00
parent e4ea0c02cf
commit de0aa82127
14 changed files with 59 additions and 27 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.6" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
+7
View File
@@ -0,0 +1,7 @@
package core;
/**
* @author Pavel Talanov
*/
public final class Dummy {
}
+2 -2
View File
@@ -1,4 +1,4 @@
package js.annotations;
package js;
annotation class native(name : String = "")
annotation class native(name : String = "") {}
annotation class library(name : String = "") {}
+2 -3
View File
@@ -1,8 +1,7 @@
package js;
import js.annotations.library
import js.annotations.library
import js.annotations.native
import js.library
import js.native
import java.util.*;
library("println")
+1 -1
View File
@@ -1,7 +1,7 @@
package java.lang
import java.util.Iterator;
import js.annotations.library
import js.library
library
trait Iterable<T> {
+1 -1
View File
@@ -1,6 +1,6 @@
package java.util
import js.annotations.*;
import js.*;
library("collectionsMax")
+1 -1
View File
@@ -1,7 +1,7 @@
package js
import java.util.*;
import js.annotations.library
import js.library
class Json() {
+1 -1
View File
@@ -1,6 +1,6 @@
package js;
import js.annotations.native
import js.native
native
val Math = object {
+1 -1
View File
@@ -1,6 +1,6 @@
package html5
import js.annotations.native
import js.native
import js.DomElement
native
+1 -1
View File
@@ -1,6 +1,6 @@
package jquery;
import js.annotations.*;
import js.*;
import js.DomElement
native
+1 -1
View File
@@ -1,6 +1,6 @@
package raphael
import js.annotations.*;
import js.*;
import js.*;
native
@@ -3,12 +3,13 @@ package org.jetbrains.k2js.config;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
import com.intellij.openapi.project.Project;
import core.Dummy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.k2js.utils.JetFileUtils;
import java.io.File;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -26,15 +27,15 @@ public abstract class Config {
//TODO: provide some generic way to get the files of the project
@NotNull
private static final List<String> LIB_FILE_NAMES = Arrays.asList(
PATH_TO_JS_LIB_SRC + "\\core\\annotations.kt",
PATH_TO_JS_LIB_SRC + "\\jquery\\common.kt",
PATH_TO_JS_LIB_SRC + "\\core\\javautil.kt",
PATH_TO_JS_LIB_SRC + "\\core\\javalang.kt",
PATH_TO_JS_LIB_SRC + "\\core\\core.kt",
PATH_TO_JS_LIB_SRC + "\\core\\math.kt",
PATH_TO_JS_LIB_SRC + "\\core\\json.kt",
PATH_TO_JS_LIB_SRC + "\\raphael\\raphael.kt",
PATH_TO_JS_LIB_SRC + "\\html5\\core.kt"
"/core/annotations.kt",
"/jquery/common.kt",
"/core/javautil.kt",
"/core/javalang.kt",
"/core/core.kt",
"/core/math.kt",
"/core/json.kt",
"/raphael/raphael.kt",
"/html5/core.kt"
);
@@ -45,7 +46,7 @@ public abstract class Config {
List<String> lines = Files.readLines(file, Charsets.UTF_8);
return lines.get(0);
} catch (Exception ex) {
return "jslib\\src";
return "jslib/src";
}
}
@@ -53,7 +54,16 @@ public abstract class Config {
private static List<JetFile> initLibFiles(@NotNull Project project) {
List<JetFile> libFiles = new ArrayList<JetFile>();
for (String libFileName : LIB_FILE_NAMES) {
libFiles.add(JetFileUtils.loadPsiFile(libFileName, project));
InputStream stream = Dummy.class.getResourceAsStream(libFileName);
//noinspection IOResourceOpenedButNotSafelyClosed
JetFile file = null;
try {
String text = readString(stream);
file = JetFileUtils.createPsiFile(libFileName, text, project);
} catch (IOException e) {
e.printStackTrace();
}
libFiles.add(file);
}
return libFiles;
}
@@ -73,4 +83,19 @@ public abstract class Config {
return jsLibFiles;
}
static String readString(InputStream is) throws IOException {
char[] buf = new char[2048];
Reader r = new InputStreamReader(is, "UTF-8");
StringBuilder s = new StringBuilder();
while (true) {
int n = r.read(buf);
if (n < 0)
break;
s.append(buf, 0, n);
}
return s.toString();
}
}
@@ -16,9 +16,9 @@ import static org.jetbrains.k2js.translate.utils.DescriptorUtils.getContainingCl
public final class AnnotationsUtils {
@NotNull
public static final String NATIVE_ANNOTATION_FQNAME = "js.annotations.native";
public static final String NATIVE_ANNOTATION_FQNAME = "js.native";
@NotNull
public static final String LIBRARY_ANNOTATION_FQNAME = "js.annotations.library";
public static final String LIBRARY_ANNOTATION_FQNAME = "js.library";
private AnnotationsUtils() {
}
+1
View File
@@ -27,6 +27,7 @@
<orderEntry type="library" name="idea-full" level="application" />
<orderEntry type="module" module-name="js" />
<orderEntry type="module" module-name="compiler-tests" />
<orderEntry type="module" module-name="jslib" />
</component>
</module>