diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidConst.java b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidConst.java index ed532431621..5897f408b32 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidConst.java +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidConst.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android; import com.intellij.openapi.util.Key; diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlParser.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlParser.kt index 9071d4a6982..ec24ccda731 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlParser.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlParser.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android import java.util.ArrayList diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUtil.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUtil.kt index d610b885eec..ccb0d15db47 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUtil.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUtil.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android trait AndroidResource diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidXmlHandler.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidXmlHandler.kt index e215f0b4420..0576fe04f5a 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidXmlHandler.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidXmlHandler.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android import org.xml.sax.helpers.DefaultHandler diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/CliAndroidUIXmlParser.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/CliAndroidUIXmlParser.kt index 33180a637a1..646140ee700 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/CliAndroidUIXmlParser.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/CliAndroidUIXmlParser.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android import com.intellij.openapi.vfs.VirtualFileManager diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/Context.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/Context.kt index 401dd5f81c7..502c17b7c07 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/Context.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/Context.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android import java.util.ArrayList diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/KotlinWriter.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/KotlinWriter.kt index fbff51ce990..261eebcca5a 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/KotlinWriter.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/KotlinWriter.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android trait KotlinWriter { diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidXmlTest.java b/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidXmlTest.java index ab3f04a1cd5..7ea03bc1ec3 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidXmlTest.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidXmlTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.lang.resolve.android; import com.intellij.openapi.project.Project; @@ -16,7 +32,6 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.net.URL; -import java.net.URLClassLoader; import java.util.*; public class AndroidXmlTest extends TestCaseWithTmpdir { @@ -28,65 +43,6 @@ public class AndroidXmlTest extends TestCaseWithTmpdir { private final File fakeMyActivitySrc = new File(getTestDataPath() + "/converter/singleFile/MyActivity.kt"); private final String singleFileResPath = getTestDataPath() + "/converter/singleFile/res/layout/"; - public static class ByteClassLoader extends URLClassLoader { - - private Queue q; - private final Map extraClassDefs = new HashMap(); - - @NotNull - @Override - protected Class findClass(String name) throws ClassNotFoundException { - final Class aClass = extraClassDefs.get(name); - if (aClass != null) return aClass; - else return super.findClass(name); - } - - public ByteClassLoader(URL[] urls, ClassLoader parent, List files) { - super(urls, parent); - q = new LinkedList(files); - } - - private void loadBytes(OutputFile f) { - try { - final byte[] b = f.asByteArray(); - final String name = relPathToClassName(f.getRelativePath()); - final Class aClass = defineClass(name, b, 0, b.length); - extraClassDefs.put(name, aClass); - q.remove(f); - } catch (NoClassDefFoundError e) { - OutputFile found = findByClassName(e.getMessage()); - if (found == null) throw e; - else { - loadBytes(found); - loadBytes(f); - } - } - } - - public void loadFiles() { - OutputFile f = q.peek(); - while (f != null) { - loadBytes(f); - f = q.peek(); - } - } - - private OutputFile findByClassName(String name) { - String path = classNameToRelPath(name); - for (OutputFile file: q) - if (file.getRelativePath().equals(path)) return file; - return null; - } - - private String relPathToClassName(String path) { - return path.replace(".class", "").replace("/", "."); - } - - private String classNameToRelPath(String name) { - return name.replace(".", "/").concat(".class"); - } - } - @Override public void setUp() throws Exception { super.setUp(); @@ -139,7 +95,7 @@ public class AndroidXmlTest extends TestCaseWithTmpdir { } private List addDefaultFiles() { - final File fakeRClass = new File(getTestDataPath() + "/converter/singleFile/R.kt"); + File fakeRClass = new File(getTestDataPath() + "/converter/singleFile/R.kt"); List files = new ArrayList(); files.add(fakeActivitySrc); files.add(fakeViewSrc); @@ -165,9 +121,9 @@ public class AndroidXmlTest extends TestCaseWithTmpdir { files.add(fakeMyActivitySrc); GenerationState state = compileManyFilesGetGenerationState(files, resPath); - ByteClassLoader classLoader = new ByteClassLoader(new URL[] {}, getClass().getClassLoader(), state.getFactory().asList()); + ByteArrayClassLoader classLoader = new ByteArrayClassLoader(new URL[] {}, getClass().getClassLoader(), state.getFactory().asList()); classLoader.loadFiles(); - final Class activity = classLoader.findClass("com.myapp.MyActivity"); + Class activity = classLoader.findClass("com.myapp.MyActivity"); String res =(String) activity.getMethod("test").invoke(activity.newInstance()); Disposer.dispose(getTestRootDisposable()); assertEquals("OK", res); diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/android/ByteArrayClassLoader.java b/compiler/tests/org/jetbrains/jet/lang/resolve/android/ByteArrayClassLoader.java new file mode 100644 index 00000000000..188cb47a8d4 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/android/ByteArrayClassLoader.java @@ -0,0 +1,83 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.lang.resolve.android; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.OutputFile; + +import java.net.URL; +import java.net.URLClassLoader; +import java.util.*; + +public class ByteArrayClassLoader extends URLClassLoader { + + private final Queue q; + private final Map extraClassDefs = new HashMap(); + + @NotNull + @Override + protected Class findClass(@NotNull String name) throws ClassNotFoundException { + Class aClass = extraClassDefs.get(name); + if (aClass != null) return aClass; + else return super.findClass(name); + } + + public ByteArrayClassLoader(URL[] urls, ClassLoader parent, List files) { + super(urls, parent); + q = new LinkedList(files); + } + + private void loadBytes(OutputFile f) { + try { + byte[] b = f.asByteArray(); + String name = relPathToClassName(f.getRelativePath()); + Class aClass = defineClass(name, b, 0, b.length); + extraClassDefs.put(name, aClass); + q.remove(f); + } catch (NoClassDefFoundError e) { + OutputFile found = findByClassName(e.getMessage()); + if (found == null) throw e; + else { + loadBytes(found); + loadBytes(f); + } + } + } + + public void loadFiles() { + OutputFile f = q.peek(); + while (f != null) { + loadBytes(f); + f = q.peek(); + } + } + + private OutputFile findByClassName(String name) { + String path = classNameToRelPath(name); + for (OutputFile file: q) + if (file.getRelativePath().equals(path)) return file; + return null; + } + + private static String relPathToClassName(String path) { + return path.replace(".class", "").replace("/", "."); + } + + private static String classNameToRelPath(String name) { + return name.replace(".", "/").concat(".class"); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/android/IDEAndroidUIXmlParser.kt b/idea/src/org/jetbrains/jet/plugin/android/IDEAndroidUIXmlParser.kt index d8820e399fe..50471152e6f 100644 --- a/idea/src/org/jetbrains/jet/plugin/android/IDEAndroidUIXmlParser.kt +++ b/idea/src/org/jetbrains/jet/plugin/android/IDEAndroidUIXmlParser.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.jetbrains.jet.plugin.android import org.jetbrains.jet.lang.resolve.android.AndroidUIXmlParser