From bf707ec3f70513a1691e57f4a76e6340fd685f7e Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Tue, 14 Apr 2015 19:52:18 +0300 Subject: [PATCH] Minor: code clean, remove obsolete functions --- .../AndroidXml2KConversionTestGenerated.java | 6 + .../android/AbstractAndroidCompletionTest.kt | 2 - .../kotlin/android/KotlinAndroidTestCase.java | 43 +----- .../android/KotlinAndroidTestCaseBase.java | 141 ------------------ .../android/AbstractAndroidJpsTestCase.kt | 3 +- 5 files changed, 10 insertions(+), 185 deletions(-) diff --git a/plugins/android-compiler-plugin/tests/org/jetbrains/kotlin/lang/resolve/android/test/AndroidXml2KConversionTestGenerated.java b/plugins/android-compiler-plugin/tests/org/jetbrains/kotlin/lang/resolve/android/test/AndroidXml2KConversionTestGenerated.java index 5bf08793495..1afd481b24d 100644 --- a/plugins/android-compiler-plugin/tests/org/jetbrains/kotlin/lang/resolve/android/test/AndroidXml2KConversionTestGenerated.java +++ b/plugins/android-compiler-plugin/tests/org/jetbrains/kotlin/lang/resolve/android/test/AndroidXml2KConversionTestGenerated.java @@ -79,6 +79,12 @@ public class AndroidXml2KConversionTestGenerated extends AbstractAndroidXml2KCon doTest(fileName); } + @TestMetadata("severalResDirs") + public void testSeveralResDirs() throws Exception { + String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/android/converter/simple/severalResDirs/"); + doTest(fileName); + } + @TestMetadata("singleFile") public void testSingleFile() throws Exception { String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/android/converter/simple/singleFile/"); diff --git a/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/AbstractAndroidCompletionTest.kt b/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/AbstractAndroidCompletionTest.kt index 9e7a0ed2e88..5ac0dba4912 100644 --- a/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/AbstractAndroidCompletionTest.kt +++ b/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/AbstractAndroidCompletionTest.kt @@ -24,8 +24,6 @@ import org.jetbrains.kotlin.idea.project.TargetPlatform import java.io.File public abstract class AbstractAndroidCompletionTest : KotlinAndroidTestCase() { - private var kotlinInternalModeOriginalValue: Boolean = false - private var codeCompletionOldValue: Boolean = false private var smartTypeCompletionOldValue: Boolean = false diff --git a/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCase.java b/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCase.java index 7173c386381..42a9c6c5007 100644 --- a/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCase.java +++ b/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCase.java @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.android; import com.android.SdkConstants; import com.android.ide.common.rendering.RenderSecurityManager; import com.intellij.analysis.AnalysisScope; -import com.intellij.codeInspection.GlobalInspectionTool; import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.ex.GlobalInspectionToolWrapper; import com.intellij.codeInspection.ex.InspectionManagerEx; @@ -64,7 +63,7 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase { protected Module myModule; protected List myAdditionalModules; - private boolean myCreateManifest; + private final boolean myCreateManifest; protected AndroidFacet myFacet; private boolean kotlinInternalModeOriginalValue; @@ -109,7 +108,7 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase { } tuneModule(moduleFixtureBuilder, dirPath); - final ArrayList modules = new ArrayList(); + final List modules = new ArrayList(); configureAdditionalModules(projectBuilder, modules); myFixture.setUp(); @@ -172,18 +171,6 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase { @NotNull List modules) { } - protected void addModuleWithAndroidFacet(@NotNull TestFixtureBuilder projectBuilder, - @NotNull List modules, - @NotNull String dirName, - boolean library) { - final JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class); - final String moduleDirPath = myFixture.getTempDirPath() + getContentRootPath(dirName); - //noinspection ResultOfMethodCallIgnored - new File(moduleDirPath).mkdirs(); - tuneModule(moduleFixtureBuilder, moduleDirPath); - modules.add(new MyAdditionalModuleData(moduleFixtureBuilder, dirName, library)); - } - protected static String getContentRootPath(@NotNull String moduleName) { return "/additionalModules/" + moduleName; } @@ -202,11 +189,6 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase { protected void createManifest() throws IOException { myFixture.copyFileToProject("plugins/android-idea-plugin/testData/android/AndroidManifest.xml", SdkConstants.FN_ANDROID_MANIFEST_XML); - // myFixture.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML, SdkConstants.FN_ANDROID_MANIFEST_XML); - } - - protected void createProjectProperties() throws IOException { - myFixture.copyFileToProject(SdkConstants.FN_PROJECT_PROPERTIES, SdkConstants.FN_PROJECT_PROPERTIES); } protected void deleteManifest() throws IOException { @@ -282,27 +264,6 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase { return facet; } - protected void doGlobalInspectionTest(@NotNull GlobalInspectionTool inspection, - @NotNull String globalTestDir, - @NotNull AnalysisScope scope) { - doGlobalInspectionTest(new GlobalInspectionToolWrapper(inspection), globalTestDir, scope); - } - - protected void doGlobalInspectionTest(@NotNull GlobalInspectionToolWrapper wrapper, - @NotNull String globalTestDir, - @NotNull AnalysisScope scope) { - myFixture.enableInspections(wrapper.getTool()); - - scope.invalidate(); - - final InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject()); - final GlobalInspectionContextForTests globalContext = - CodeInsightTestFixtureImpl.createGlobalContextForTool(scope, getProject(), inspectionManager, wrapper); - - InspectionTestUtil.runTool(wrapper, scope, globalContext); - InspectionTestUtil.compareToolResults(globalContext, wrapper, false, getTestDataPath() + globalTestDir); - } - protected static class MyAdditionalModuleData { final JavaModuleFixtureBuilder myModuleFixtureBuilder; final String myDirName; diff --git a/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCaseBase.java b/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCaseBase.java index 7c0b2e73221..61b5775f26c 100644 --- a/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCaseBase.java +++ b/plugins/android-idea-plugin/tests/org/jetbrains/kotlin/android/KotlinAndroidTestCaseBase.java @@ -64,21 +64,6 @@ public abstract class KotlinAndroidTestCaseBase extends UsefulTestCase { IdeaTestCase.initPlatformPrefix(); } - public String getAbsoluteTestDataPath() { - // The following code doesn't work right now that the Android - // plugin lives in a separate place: - //String androidHomePath = System.getProperty("android.home.path"); - //if (androidHomePath == null) { - // androidHomePath = new File(PathManager.getHomePath(), "android/android").getPath(); - //} - //return PathUtil.getCanonicalPath(androidHomePath + "/testData"); - - // getTestDataPath already gives the absolute path anyway: - String path = getTestDataPath(); - assertTrue(new File(path).isAbsolute()); - return path; - } - public static String getPluginTestDataPathBase() { return JetTestUtils.getHomeDirectory() + TEST_DATA_PROJECT_RELATIVE; } @@ -87,16 +72,6 @@ public abstract class KotlinAndroidTestCaseBase extends UsefulTestCase { return getPluginTestDataPathBase(); } - public static String getAndroidPluginHome() { - // Now that the Android plugin is kept in a separate place, we need to look in - // a relative position instead - String adtPath = PathManager.getHomePath() + "/../adt/idea/android"; - if (new File(adtPath).exists()) { - return adtPath; - } - return new File(PathManager.getHomePath(), "android/android").getPath(); - } - public String getDefaultTestSdkPath() { return getTestDataPath() + "/sdk1.5"; } @@ -200,121 +175,5 @@ public abstract class KotlinAndroidTestCaseBase extends UsefulTestCase { protected Project getProject() { return myFixture.getProject(); } - - protected void ensureSdkManagerAvailable() { - AndroidSdkData sdkData = AndroidSdkUtils.tryToChooseAndroidSdk(); - if (sdkData == null) { - sdkData = createTestSdkManager(); - if (sdkData != null) { - AndroidSdkUtils.setSdkData(sdkData); - } - } - assertNotNull(sdkData); - } - - @Nullable - protected AndroidSdkData createTestSdkManager() { - Sdk androidSdk = createAndroidSdk(getTestSdkPath(), getPlatformDir()); - AndroidSdkAdditionalData data = (AndroidSdkAdditionalData)androidSdk.getSdkAdditionalData(); - if (data != null) { - AndroidPlatform androidPlatform = data.getAndroidPlatform(); - if (androidPlatform != null) { - // Put default platforms in the list before non-default ones so they'll be looked at first. - return androidPlatform.getSdkData(); - } else { - fail("No getAndroidPlatform() associated with the AndroidSdkAdditionalData: " + data); - } - } else { - fail("Could not find data associated with the SDK: " + androidSdk.getName()); - } - return null; - } - - /** Returns a description of the given elements, suitable as unit test golden file output */ - public static String describeElements(@Nullable PsiElement[] elements) { - if (elements == null) { - return "Empty"; - } - StringBuilder sb = new StringBuilder(); - for (PsiElement target : elements) { - appendElementDescription(sb, target); - } - return sb.toString(); - } - - /** Appends a description of the given element, suitable as unit test golden file output */ - public static void appendElementDescription(@NotNull StringBuilder sb, @NotNull PsiElement element) { - if (element instanceof LazyValueResourceElementWrapper) { - LazyValueResourceElementWrapper wrapper = (LazyValueResourceElementWrapper)element; - XmlAttributeValue value = wrapper.computeElement(); - if (value != null) { - element = value; - } - } - PsiFile file = element.getContainingFile(); - int offset = element.getTextOffset(); - TextRange segment = element.getTextRange(); - appendSourceDescription(sb, file, offset, segment); - } - - /** Appends a description of the given elements, suitable as unit test golden file output */ - public static void appendSourceDescription(@NotNull StringBuilder sb, @Nullable PsiFile file, int offset, @Nullable Segment segment) { - if (file != null && segment != null) { - if (ResourceHelper.getFolderType(file) != null) { - assertNotNull(file.getParent()); - sb.append(file.getParent().getName()); - sb.append("/"); - } - sb.append(file.getName()); - sb.append(':'); - String text = file.getText(); - int lineNumber = 1; - for (int i = 0; i < offset; i++) { - if (text.charAt(i) == '\n') { - lineNumber++; - } - } - sb.append(lineNumber); - sb.append(":"); - sb.append('\n'); - int startOffset = segment.getStartOffset(); - int endOffset = segment.getEndOffset(); - assertTrue(offset == -1 || offset >= startOffset); - assertTrue(offset == -1 || offset <= endOffset); - - int lineStart = startOffset; - while (lineStart > 0 && text.charAt(lineStart - 1) != '\n') { - lineStart--; - } - - // Skip over leading whitespace - while (lineStart < startOffset && Character.isWhitespace(text.charAt(lineStart))) { - lineStart++; - } - - int lineEnd = startOffset; - while (lineEnd < text.length() && text.charAt(lineEnd) != '\n') { - lineEnd++; - } - String indent = " "; - sb.append(indent); - sb.append(text.substring(lineStart, lineEnd)); - sb.append('\n'); - sb.append(indent); - for (int i = lineStart; i < lineEnd; i++) { - if (i == offset) { - sb.append('|'); - } else if (i >= startOffset && i <= endOffset) { - sb.append('~'); - } else { - sb.append(' '); - } - } - } else { - sb.append(offset); - sb.append(":?"); - } - sb.append('\n'); - } } diff --git a/plugins/android-jps-plugin/tests/org/jetbrains/kotlin/jps/build/android/AbstractAndroidJpsTestCase.kt b/plugins/android-jps-plugin/tests/org/jetbrains/kotlin/jps/build/android/AbstractAndroidJpsTestCase.kt index adab5e1a021..1319e7a45a6 100644 --- a/plugins/android-jps-plugin/tests/org/jetbrains/kotlin/jps/build/android/AbstractAndroidJpsTestCase.kt +++ b/plugins/android-jps-plugin/tests/org/jetbrains/kotlin/jps/build/android/AbstractAndroidJpsTestCase.kt @@ -62,7 +62,8 @@ public abstract class AbstractAndroidJpsTestCase : JpsBuildTestCase() { addJdk(jdkName) val properties = JpsAndroidSdkProperties("android-21", jdkName) val sdkPath = getHomePath() + "/../dependencies/androidSDK" - val library = myModel!!.getGlobal().addSdk>(SDK_NAME, sdkPath, "", JpsAndroidSdkType.INSTANCE, JpsSimpleElementImpl(properties)) + val library = myModel!!.getGlobal().addSdk>(SDK_NAME, sdkPath, "", + JpsAndroidSdkType.INSTANCE, JpsSimpleElementImpl(properties)) library!!.addRoot(File(sdkPath + "/platforms/android-21/android.jar"), JpsOrderRootType.COMPILED) return library.getProperties() }