From a56fa7f1927a7a83dd728f31e15f006c583c86e5 Mon Sep 17 00:00:00 2001 From: Mikhail Mutcianko Date: Fri, 22 Aug 2014 18:16:43 +0400 Subject: [PATCH] optimize imports --- .idea/runConfigurations/Android_Studio.xml | 4 +- .../android/AndroidResourceManagerBase.kt | 3 +- .../resolve/android/AndroidUIXmlProcessor.kt | 12 +-- .../jet/lang/resolve/android/AndroidUtil.kt | 2 +- .../noManifest}/layout/layout.xml | 0 .../fqNameInAttr}/AndroidManifest.xml | 0 .../converter/simple/fqNameInAttr/layout.kt | 9 ++ .../simple/fqNameInAttr/layout/layout.xml | 15 ++++ .../simple/fqNameInTag/AndroidManifest.xml | 33 +++++++ .../converter/simple/fqNameInTag/layout.kt | 9 ++ .../simple/fqNameInTag/layout/layout.xml | 14 +++ .../simple/multiFile/AndroidManifest.xml | 33 +++++++ .../converter/simple/multiFile/layout.kt | 30 +++++++ .../simple/multiFile/layout/layout.xml | 29 +++++++ .../simple/multiFile/layout/layout1.xml | 29 +++++++ .../simple/noIds/AndroidManifest.xml | 33 +++++++ .../android/converter/simple/noIds/layout.kt | 6 ++ .../converter/simple/noIds/layout/layout.xml | 25 ++++++ .../simple/singleFile/AndroidManifest.xml | 33 +++++++ .../{ => simple}/singleFile/MyActivity.kt | 0 .../converter/{ => simple}/singleFile/R.kt | 0 .../{ => simple}/singleFile/layout.kt | 0 .../simple/singleFile/layout/layout.xml | 29 +++++++ .../AbstractAndroidXml2KConversionTest.kt | 59 +++++++++++++ .../android/AbstractCrossParserTest.kt | 39 +++++++++ .../AndroidXml2KConversionTestGenerated.java | 87 +++++++++++++++++++ .../lang/resolve/android/AndroidXmlTest.java | 7 +- .../resolve/android/ByteArrayClassLoader.java | 1 + .../kotlin/generators/tests/GenerateTests.kt | 6 ++ idea/idea.iml | 2 +- .../android/IDEAndroidResourceManager.kt | 10 +-- .../android/IDEAndroidUIXmlProcessor.kt | 1 - .../AndroidPropertiesCompletionBasicTest.java | 6 -- 33 files changed, 543 insertions(+), 23 deletions(-) rename compiler/testData/android/converter/{singleFile/res => exceptions/noManifest}/layout/layout.xml (100%) rename compiler/testData/android/converter/{singleFile => simple/fqNameInAttr}/AndroidManifest.xml (100%) create mode 100644 compiler/testData/android/converter/simple/fqNameInAttr/layout.kt create mode 100644 compiler/testData/android/converter/simple/fqNameInAttr/layout/layout.xml create mode 100644 compiler/testData/android/converter/simple/fqNameInTag/AndroidManifest.xml create mode 100644 compiler/testData/android/converter/simple/fqNameInTag/layout.kt create mode 100644 compiler/testData/android/converter/simple/fqNameInTag/layout/layout.xml create mode 100644 compiler/testData/android/converter/simple/multiFile/AndroidManifest.xml create mode 100644 compiler/testData/android/converter/simple/multiFile/layout.kt create mode 100644 compiler/testData/android/converter/simple/multiFile/layout/layout.xml create mode 100644 compiler/testData/android/converter/simple/multiFile/layout/layout1.xml create mode 100644 compiler/testData/android/converter/simple/noIds/AndroidManifest.xml create mode 100644 compiler/testData/android/converter/simple/noIds/layout.kt create mode 100644 compiler/testData/android/converter/simple/noIds/layout/layout.xml create mode 100644 compiler/testData/android/converter/simple/singleFile/AndroidManifest.xml rename compiler/testData/android/converter/{ => simple}/singleFile/MyActivity.kt (100%) rename compiler/testData/android/converter/{ => simple}/singleFile/R.kt (100%) rename compiler/testData/android/converter/{ => simple}/singleFile/layout.kt (100%) create mode 100644 compiler/testData/android/converter/simple/singleFile/layout/layout.xml create mode 100644 compiler/tests/org/jetbrains/jet/lang/resolve/android/AbstractAndroidXml2KConversionTest.kt create mode 100644 compiler/tests/org/jetbrains/jet/lang/resolve/android/AbstractCrossParserTest.kt create mode 100644 compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidXml2KConversionTestGenerated.java diff --git a/.idea/runConfigurations/Android_Studio.xml b/.idea/runConfigurations/Android_Studio.xml index a3c9397272d..1fdc9b2f5d3 100644 --- a/.idea/runConfigurations/Android_Studio.xml +++ b/.idea/runConfigurations/Android_Studio.xml @@ -21,7 +21,9 @@ - \ No newline at end of file diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidResourceManagerBase.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidResourceManagerBase.kt index 3caac163b65..f0171200156 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidResourceManagerBase.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidResourceManagerBase.kt @@ -29,7 +29,8 @@ abstract class AndroidResourceManagerBase(project: Project, searchPath: String?) val fileManager = VirtualFileManager.getInstance() val watchDir = fileManager.findFileByUrl("file://" + searchPath) val psiManager = PsiManager.getInstance(project) - return watchDir?.getChildren()?.toArrayList()?.map { psiManager.findFile(it) }?.mapNotNull { it } ?: ArrayList(0) + val files = watchDir?.getChildren()?.toArrayList()?.map { psiManager.findFile(it) }?.mapNotNull { it } ?: ArrayList(0) + return files.sortBy({it.getName()}) } protected fun vritualFileToPsi(vf: VirtualFile): PsiFile? { diff --git a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlProcessor.kt b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlProcessor.kt index e42e316e94b..3a6dcdcbef0 100644 --- a/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlProcessor.kt +++ b/compiler/frontend.android/src/org/jetbrains/jet/lang/resolve/android/AndroidUIXmlProcessor.kt @@ -47,9 +47,8 @@ import java.util.Queue import com.intellij.psi.PsiFile import com.intellij.openapi.diagnostic.Logger import org.jetbrains.jet.lang.resolve.android.AndroidConst.* -import com.intellij.openapi.application.ApplicationManager -abstract class AndroidUIXmlProcessor(protected val project: Project) { +public abstract class AndroidUIXmlProcessor(protected val project: Project) { class NoAndroidManifestFound : Exception("No android manifest file found in project root") @@ -69,6 +68,8 @@ abstract class AndroidUIXmlProcessor(protected val project: Project) { protected val filesToProcess: Queue = ConcurrentLinkedQueue() + public abstract val resourceManager: AndroidResourceManager + protected val LOG: Logger = Logger.getInstance(this.javaClass) public fun parseToString(): String? { @@ -77,7 +78,6 @@ abstract class AndroidUIXmlProcessor(protected val project: Project) { return renderString() } - public abstract val resourceManager: AndroidResourceManager public fun parseToPsi(project: Project): JetFile? { val cacheState = doParse() @@ -121,7 +121,7 @@ abstract class AndroidUIXmlProcessor(protected val project: Project) { return res } - abstract fun parseSingleFileImpl(file: PsiFile): String + protected abstract fun parseSingleFileImpl(file: PsiFile): String private fun doParse(): CacheAction? { if (searchPath == null || searchPath == "") return null @@ -138,8 +138,8 @@ abstract class AndroidUIXmlProcessor(protected val project: Project) { private fun renderString(): String { val buffer = writeImports(KotlinStringWriter()).output() - for (buf in fileCache.values()) - buffer.append(buf) + for (buf in fileCache.entrySet().sortBy({it.key.getName()})) + buffer.append(buf.value) return buffer.toString() } 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 da38d002334..95b5e4f1648 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 @@ -42,6 +42,6 @@ fun isAndroidSyntheticFile(f: PsiFile?): Boolean { return f?.getUserData(AndroidConst.ANDROID_USER_PACKAGE) != null } -fun isAndroidSyntheticElement(element: PsiElement?): Boolean { +public fun isAndroidSyntheticElement(element: PsiElement?): Boolean { return isAndroidSyntheticFile(element?.getContainingFile()) } \ No newline at end of file diff --git a/compiler/testData/android/converter/singleFile/res/layout/layout.xml b/compiler/testData/android/converter/exceptions/noManifest/layout/layout.xml similarity index 100% rename from compiler/testData/android/converter/singleFile/res/layout/layout.xml rename to compiler/testData/android/converter/exceptions/noManifest/layout/layout.xml diff --git a/compiler/testData/android/converter/singleFile/AndroidManifest.xml b/compiler/testData/android/converter/simple/fqNameInAttr/AndroidManifest.xml similarity index 100% rename from compiler/testData/android/converter/singleFile/AndroidManifest.xml rename to compiler/testData/android/converter/simple/fqNameInAttr/AndroidManifest.xml diff --git a/compiler/testData/android/converter/simple/fqNameInAttr/layout.kt b/compiler/testData/android/converter/simple/fqNameInAttr/layout.kt new file mode 100644 index 00000000000..5ec16eef328 --- /dev/null +++ b/compiler/testData/android/converter/simple/fqNameInAttr/layout.kt @@ -0,0 +1,9 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* + +val Activity.MyButton: org.my.cool.Button + get() = findViewById(0) as org.my.cool.Button + diff --git a/compiler/testData/android/converter/simple/fqNameInAttr/layout/layout.xml b/compiler/testData/android/converter/simple/fqNameInAttr/layout/layout.xml new file mode 100644 index 00000000000..a0ef9f3a1ed --- /dev/null +++ b/compiler/testData/android/converter/simple/fqNameInAttr/layout/layout.xml @@ -0,0 +1,15 @@ + + + + + diff --git a/compiler/testData/android/converter/simple/fqNameInTag/AndroidManifest.xml b/compiler/testData/android/converter/simple/fqNameInTag/AndroidManifest.xml new file mode 100644 index 00000000000..580c474f5de --- /dev/null +++ b/compiler/testData/android/converter/simple/fqNameInTag/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/compiler/testData/android/converter/simple/fqNameInTag/layout.kt b/compiler/testData/android/converter/simple/fqNameInTag/layout.kt new file mode 100644 index 00000000000..5ec16eef328 --- /dev/null +++ b/compiler/testData/android/converter/simple/fqNameInTag/layout.kt @@ -0,0 +1,9 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* + +val Activity.MyButton: org.my.cool.Button + get() = findViewById(0) as org.my.cool.Button + diff --git a/compiler/testData/android/converter/simple/fqNameInTag/layout/layout.xml b/compiler/testData/android/converter/simple/fqNameInTag/layout/layout.xml new file mode 100644 index 00000000000..2ec85364e74 --- /dev/null +++ b/compiler/testData/android/converter/simple/fqNameInTag/layout/layout.xml @@ -0,0 +1,14 @@ + + + + + diff --git a/compiler/testData/android/converter/simple/multiFile/AndroidManifest.xml b/compiler/testData/android/converter/simple/multiFile/AndroidManifest.xml new file mode 100644 index 00000000000..580c474f5de --- /dev/null +++ b/compiler/testData/android/converter/simple/multiFile/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/compiler/testData/android/converter/simple/multiFile/layout.kt b/compiler/testData/android/converter/simple/multiFile/layout.kt new file mode 100644 index 00000000000..313d0b13d16 --- /dev/null +++ b/compiler/testData/android/converter/simple/multiFile/layout.kt @@ -0,0 +1,30 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* + +val Activity.item_detail_container: FrameLayout + get() = findViewById(0) as FrameLayout + +val Activity.textView1: TextView + get() = findViewById(0) as TextView + +val Activity.password: EditText + get() = findViewById(0) as EditText + +val Activity.login: Button + get() = findViewById(0) as Button + +val Activity.frameLayout: FrameLayout + get() = findViewById(0) as FrameLayout + +val Activity.passwordField: TextView + get() = findViewById(0) as TextView + +val Activity.passwordCaption: EditText + get() = findViewById(0) as EditText + +val Activity.loginButton: Button + get() = findViewById(0) as Button + diff --git a/compiler/testData/android/converter/simple/multiFile/layout/layout.xml b/compiler/testData/android/converter/simple/multiFile/layout/layout.xml new file mode 100644 index 00000000000..f4736f6937b --- /dev/null +++ b/compiler/testData/android/converter/simple/multiFile/layout/layout.xml @@ -0,0 +1,29 @@ + + + + + + + +