mirror of
https://github.com/revanced/smali.git
synced 2025-05-20 16:07:05 +02:00
Add support for renaming methods
This commit is contained in:
parent
923cc91ea2
commit
48aacd2c01
@ -225,8 +225,12 @@ public class SmaliMethod extends SmaliStubBasedPsiElement<SmaliMethodStub>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
@Override public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
|
||||||
// TODO: implement this
|
SmaliMemberName smaliMemberName = getNameIdentifier();
|
||||||
throw new IncorrectOperationException();
|
if (smaliMemberName == null) {
|
||||||
|
throw new IncorrectOperationException();
|
||||||
|
}
|
||||||
|
smaliMemberName.setName(name);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull @Override public HierarchicalMethodSignature getHierarchicalMethodSignature() {
|
@NotNull @Override public HierarchicalMethodSignature getHierarchicalMethodSignature() {
|
||||||
@ -253,7 +257,11 @@ public class SmaliMethod extends SmaliStubBasedPsiElement<SmaliMethodStub>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable @Override public SmaliClass getContainingClass() {
|
@Nullable @Override public SmaliClass getContainingClass() {
|
||||||
return (SmaliClass)getStubOrPsiParent();
|
PsiElement parent = getStubOrPsiParent();
|
||||||
|
if (parent instanceof SmaliClass) {
|
||||||
|
return (SmaliClass) parent;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean hasModifierProperty(@ModifierConstant @NonNls @NotNull String name) {
|
@Override public boolean hasModifierProperty(@ModifierConstant @NonNls @NotNull String name) {
|
||||||
|
@ -177,8 +177,12 @@ public class SmaliMethodReference extends SmaliCompositeElement implements PsiRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
@Override public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
|
||||||
//TODO: implement this
|
SmaliMemberName memberName = getMemberName();
|
||||||
throw new IncorrectOperationException();
|
if (memberName == null) {
|
||||||
|
throw new IncorrectOperationException();
|
||||||
|
}
|
||||||
|
memberName.setName(newElementName);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
@Override public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||||
|
50
smalidea/src/test/java/org/jf/smalidea/MethodRenameTest.java
Normal file
50
smalidea/src/test/java/org/jf/smalidea/MethodRenameTest.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package org.jf.smalidea;
|
||||||
|
|
||||||
|
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
|
import com.intellij.psi.PsiClass;
|
||||||
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
|
import com.intellij.psi.PsiMethod;
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
|
import com.intellij.refactoring.MultiFileTestCase;
|
||||||
|
import com.intellij.refactoring.rename.RenameProcessor;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class MethodRenameTest extends MultiFileTestCase {
|
||||||
|
@Override
|
||||||
|
protected String getTestDataPath() {
|
||||||
|
return "testData";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected String getTestRoot() {
|
||||||
|
return "/methodRename/";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMethodRename() {
|
||||||
|
doTest("blah", "blah", "blort");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTest(@NotNull final String containingClass, @NotNull final String oldMethodName,
|
||||||
|
@NotNull final String newMethodName) {
|
||||||
|
doTest(new PerformAction() {
|
||||||
|
@Override
|
||||||
|
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||||
|
doRename(containingClass, oldMethodName, newMethodName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doRename(String containingClass, String oldMethodName, String newMethodName) throws Exception {
|
||||||
|
PsiClass testClass = myJavaFacade.findClass(containingClass, GlobalSearchScope.allScope(getProject()));
|
||||||
|
|
||||||
|
PsiMethod method = testClass.findMethodsByName(oldMethodName, false)[0];
|
||||||
|
|
||||||
|
RenameProcessor processor = new RenameProcessor(getProject(), method, newMethodName, false, false);
|
||||||
|
processor.run();
|
||||||
|
|
||||||
|
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||||
|
FileDocumentManager.getInstance().saveAllDocuments();
|
||||||
|
}
|
||||||
|
}
|
27
smalidea/testData/methodRename/methodRename/after/blah.smali
Normal file
27
smalidea/testData/methodRename/methodRename/after/blah.smali
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
.class public Lblah;
|
||||||
|
.super Ljava/lang/Object;
|
||||||
|
|
||||||
|
.annotation runtime Lblah;
|
||||||
|
element = Lblah;->blort()V;
|
||||||
|
.end annotation
|
||||||
|
|
||||||
|
.method public blort()V
|
||||||
|
.registers 2
|
||||||
|
|
||||||
|
invoke-direct {v0}, Lblah;->blort()V
|
||||||
|
invoke-direct/empty {v0}, Lblah;->blort()V
|
||||||
|
invoke-direct/range {v0}, Lblah;->blort()V
|
||||||
|
invoke-interface {v0}, Lblah;->blort()V
|
||||||
|
invoke-interface/range {v0}, Lblah;->blort()V
|
||||||
|
invoke-object-init/range {v0}, Lblah;->blort()V
|
||||||
|
invoke-static {v0}, Lblah;->blort()V
|
||||||
|
invoke-static/range {v0}, Lblah;->blort()V
|
||||||
|
invoke-super {v0}, Lblah;->blort()V
|
||||||
|
invoke-super/range {v0}, Lblah;->blort()V
|
||||||
|
invoke-virtual {v0}, Lblah;->blort()V
|
||||||
|
invoke-virtual/range {v0}, Lblah;->blort()V
|
||||||
|
|
||||||
|
throw-verification-error generic-error, Lblah;->blort()V
|
||||||
|
|
||||||
|
return-void
|
||||||
|
.end method
|
@ -0,0 +1,27 @@
|
|||||||
|
.class public Lblah;
|
||||||
|
.super Ljava/lang/Object;
|
||||||
|
|
||||||
|
.annotation runtime Lblah;
|
||||||
|
element = Lblah;->blah()V;
|
||||||
|
.end annotation
|
||||||
|
|
||||||
|
.method public blah()V
|
||||||
|
.registers 2
|
||||||
|
|
||||||
|
invoke-direct {v0}, Lblah;->blah()V
|
||||||
|
invoke-direct/empty {v0}, Lblah;->blah()V
|
||||||
|
invoke-direct/range {v0}, Lblah;->blah()V
|
||||||
|
invoke-interface {v0}, Lblah;->blah()V
|
||||||
|
invoke-interface/range {v0}, Lblah;->blah()V
|
||||||
|
invoke-object-init/range {v0}, Lblah;->blah()V
|
||||||
|
invoke-static {v0}, Lblah;->blah()V
|
||||||
|
invoke-static/range {v0}, Lblah;->blah()V
|
||||||
|
invoke-super {v0}, Lblah;->blah()V
|
||||||
|
invoke-super/range {v0}, Lblah;->blah()V
|
||||||
|
invoke-virtual {v0}, Lblah;->blah()V
|
||||||
|
invoke-virtual/range {v0}, Lblah;->blah()V
|
||||||
|
|
||||||
|
throw-verification-error generic-error, Lblah;->blah()V
|
||||||
|
|
||||||
|
return-void
|
||||||
|
.end method
|
Loading…
x
Reference in New Issue
Block a user