Minor: code clean, remove obsolete functions

This commit is contained in:
Yan Zhulanow
2015-04-14 19:52:18 +03:00
parent 3645dfc5af
commit bf707ec3f7
5 changed files with 10 additions and 185 deletions
@@ -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
@@ -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<Module> 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<MyAdditionalModuleData> modules = new ArrayList<MyAdditionalModuleData>();
final List<MyAdditionalModuleData> modules = new ArrayList<MyAdditionalModuleData>();
configureAdditionalModules(projectBuilder, modules);
myFixture.setUp();
@@ -172,18 +171,6 @@ public abstract class KotlinAndroidTestCase extends KotlinAndroidTestCaseBase {
@NotNull List<MyAdditionalModuleData> modules) {
}
protected void addModuleWithAndroidFacet(@NotNull TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder,
@NotNull List<MyAdditionalModuleData> 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;
@@ -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');
}
}