mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
android dom: fix rename/bind references from view[class]
This commit is contained in:
@@ -16,86 +16,13 @@
|
||||
|
||||
package org.jetbrains.android.dom.converters;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassOwner;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.xml.ConvertContext;
|
||||
import com.intellij.util.xml.ResolvingConverter;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.facet.SimpleClassMapConstructor;
|
||||
import org.jetbrains.android.util.AndroidUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Eugene.Kudelevsky
|
||||
* Date: 23.06.2009
|
||||
* Time: 18:48:18
|
||||
* To change this template use File | Settings | File Templates.
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class ViewClassConverter extends ResolvingConverter<PsiClass> {
|
||||
@Nullable
|
||||
private static Map<String, PsiClass> getViewClassMap(ConvertContext context) {
|
||||
AndroidFacet facet = AndroidFacet.getInstance(context);
|
||||
if (facet != null) {
|
||||
return facet.getClassMap(AndroidUtils.VIEW_CLASS_NAME, SimpleClassMapConstructor.getInstance());
|
||||
}
|
||||
return null;
|
||||
public class ViewClassConverter extends PackageClassConverter {
|
||||
public ViewClassConverter() {
|
||||
super(AndroidUtils.VIEW_CLASS_NAME);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<? extends PsiClass> getVariants(ConvertContext context) {
|
||||
Map<String, PsiClass> viewClassMap = getViewClassMap(context);
|
||||
if (viewClassMap != null) {
|
||||
return new HashSet<PsiClass>(viewClassMap.values());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public PsiClass fromString(@Nullable @NonNls String s, ConvertContext context) {
|
||||
if (s == null) return null;
|
||||
final AndroidFacet facet = AndroidFacet.getInstance(context);
|
||||
if (facet != null) {
|
||||
s = s.replace('$', '.');
|
||||
|
||||
final String className = s;
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(facet.getModule().getProject());
|
||||
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
|
||||
@Nullable
|
||||
public PsiClass compute() {
|
||||
return facade.findClass(className, facet.getModule().getModuleWithDependenciesAndLibrariesScope(true));
|
||||
}
|
||||
});
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getClassName(@NotNull PsiClass c) {
|
||||
PsiElement parent = c.getParent();
|
||||
if (parent instanceof PsiClassOwner) {
|
||||
PsiClassOwner owner = (PsiClassOwner)parent;
|
||||
String packageName = owner.getPackageName();
|
||||
return packageName + '.' + c.getName();
|
||||
}
|
||||
else if (parent instanceof PsiClass) {
|
||||
return getClassName((PsiClass)parent) + '$' + c.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString(@Nullable PsiClass psiClass, ConvertContext context) {
|
||||
return psiClass != null ? getClassName(psiClass) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.p2.MyW<caret>idget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<p1.p2.MyW<caret>idget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
<view class="p1.p2.MyWidget"/>
|
||||
</LinearLayout>
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.p<caret>2.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<p1.p<caret>2.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
<view class="p1.p2.MyWidget"/>
|
||||
</LinearLayout>
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.newPackage.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.newPackage.MyWidget>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<p1.newPackage.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.newPackage.MyWidget>
|
||||
<view class="p1.newPackage.MyWidget"/>
|
||||
</LinearLayout>
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.p<caret>2.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<p1.p<caret>2.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
<view class="p1.p2.MyWidget"/>
|
||||
</LinearLayout>
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.newp.p2.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.newp.p2.MyWidget>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<p1.newp.p2.MyWidget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.newp.p2.MyWidget>
|
||||
<view class="p1.newp.p2.MyWidget"/>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.p2.MyW<caret>idget xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.p2.MyWidget1 xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget1>
|
||||
@@ -1,4 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<p1.p2.MyWidget1 xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget1>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<p1.p2.MyWidget1 xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListView/>
|
||||
</p1.p2.MyWidget1>
|
||||
<view class="p1.p2.MyWidget1"/>
|
||||
</LinearLayout>
|
||||
@@ -339,6 +339,15 @@ public class AndroidRenameTest extends AndroidTestCase {
|
||||
myFixture.checkResultByFile(BASE_PATH + "layout_widget_after.xml");
|
||||
}
|
||||
|
||||
public void testRenameWidget1() throws Throwable {
|
||||
createManifest();
|
||||
myFixture.copyFileToProject(BASE_PATH + "MyWidget.java", "src/p1/p2/MyWidget.java");
|
||||
VirtualFile file = myFixture.copyFileToProject(BASE_PATH + "layout_widget.xml", "res/layout/layout_widget.xml");
|
||||
myFixture.configureFromExistingVirtualFile(file);
|
||||
checkAndRename("MyWidget1");
|
||||
myFixture.checkResultByFile(BASE_PATH + "layout_widget_after.xml");
|
||||
}
|
||||
|
||||
public void testRenameWidgetPackage1() throws Throwable {
|
||||
createManifest();
|
||||
myFixture.copyFileToProject(BASE_PATH + "MyWidget.java", "src/p1/p2/MyWidget.java");
|
||||
|
||||
Reference in New Issue
Block a user