-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Donlon/structure-view
Implement structure view for Smali files
- Loading branch information
Showing
8 changed files
with
283 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/org/jf/smalidea/structureView/SmaliFileTreeModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jf.smalidea.structureView; | ||
|
||
import com.intellij.ide.structureView.StructureViewModel; | ||
import com.intellij.ide.structureView.StructureViewModelBase; | ||
import com.intellij.ide.structureView.StructureViewTreeElement; | ||
import com.intellij.ide.util.treeView.smartTree.Sorter; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jf.smalidea.psi.impl.SmaliFile; | ||
|
||
public class SmaliFileTreeModel extends StructureViewModelBase implements | ||
StructureViewModel.ElementInfoProvider { | ||
public SmaliFileTreeModel(SmaliFile psiFile) { | ||
super(psiFile, new SmaliStructureViewElement(psiFile)); | ||
} | ||
|
||
@NotNull | ||
public Sorter[] getSorters() { | ||
return new Sorter[] { | ||
Sorter.ALPHA_SORTER}; | ||
} | ||
|
||
@Override | ||
public boolean isAlwaysShowsPlus(StructureViewTreeElement element) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isAlwaysLeaf(StructureViewTreeElement element) { | ||
return false; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/jf/smalidea/structureView/SmaliStructureViewBuilderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.jf.smalidea.structureView; | ||
|
||
import com.intellij.ide.structureView.StructureViewBuilder; | ||
import com.intellij.ide.structureView.StructureViewModel; | ||
import com.intellij.ide.structureView.TreeBasedStructureViewBuilder; | ||
import com.intellij.lang.PsiStructureViewFactory; | ||
import com.intellij.openapi.editor.Editor; | ||
import com.intellij.psi.PsiFile; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.jf.smalidea.psi.impl.SmaliFile; | ||
|
||
public class SmaliStructureViewBuilderFactory implements PsiStructureViewFactory { | ||
@Nullable | ||
@Override | ||
public StructureViewBuilder getStructureViewBuilder(@NotNull final PsiFile psiFile) { | ||
if (!(psiFile instanceof SmaliFile)) { | ||
return null; | ||
} | ||
return new TreeBasedStructureViewBuilder() { | ||
@Override | ||
@NotNull | ||
public StructureViewModel createStructureViewModel(@Nullable Editor editor) { | ||
return new SmaliFileTreeModel((SmaliFile) psiFile); | ||
} | ||
|
||
@Override | ||
public boolean isRootNodeShown() { | ||
return false; | ||
} | ||
}; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
src/main/java/org/jf/smalidea/structureView/SmaliStructureViewElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.jf.smalidea.structureView; | ||
|
||
import com.intellij.ide.projectView.PresentationData; | ||
import com.intellij.ide.structureView.StructureViewTreeElement; | ||
import com.intellij.ide.util.treeView.smartTree.SortableTreeElement; | ||
import com.intellij.ide.util.treeView.smartTree.TreeElement; | ||
import com.intellij.navigation.ItemPresentation; | ||
import com.intellij.psi.NavigatablePsiElement; | ||
import com.intellij.psi.PsiField; | ||
import com.intellij.psi.PsiMethod; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jf.smalidea.psi.impl.SmaliClass; | ||
import org.jf.smalidea.psi.impl.SmaliFile; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class SmaliStructureViewElement implements StructureViewTreeElement, SortableTreeElement { | ||
private final NavigatablePsiElement element; | ||
|
||
public SmaliStructureViewElement(NavigatablePsiElement element) { | ||
this.element = element; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return element; | ||
} | ||
|
||
@Override | ||
public void navigate(boolean requestFocus) { | ||
element.navigate(requestFocus); | ||
} | ||
|
||
@Override | ||
public boolean canNavigate() { | ||
return element.canNavigate(); | ||
} | ||
|
||
@Override | ||
public boolean canNavigateToSource() { | ||
return element.canNavigateToSource(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getAlphaSortKey() { | ||
String name = element.getName(); | ||
return name != null ? name : ""; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ItemPresentation getPresentation() { | ||
ItemPresentation presentation = element.getPresentation(); | ||
return presentation != null ? presentation : new PresentationData(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public TreeElement[] getChildren() { | ||
if (element instanceof SmaliFile) { | ||
SmaliFile smaliFile = (SmaliFile) element; | ||
SmaliClass[] classes = smaliFile.getClasses(); | ||
TreeElement[] treeElements = new TreeElement[classes.length]; | ||
for (int i = 0; i < classes.length; i++) { | ||
treeElements[i] = new SmaliStructureViewElement(classes[i]); | ||
} | ||
return treeElements; | ||
} else if (element instanceof SmaliClass) { | ||
SmaliClass smaliClass = (SmaliClass) element; | ||
PsiField[] fields = smaliClass.getFields(); | ||
PsiMethod[] methods = smaliClass.getMethods(); | ||
|
||
List<TreeElement> treeElements = new ArrayList<>(fields.length + methods.length); | ||
for (PsiField field : fields) { | ||
treeElements.add(new SmaliStructureViewElement(field)); | ||
} | ||
for (PsiMethod method : methods) { | ||
treeElements.add(new SmaliStructureViewElement(method)); | ||
} | ||
return treeElements.toArray(new TreeElement[0]); | ||
} else { | ||
return EMPTY_ARRAY; | ||
} | ||
} | ||
} |
Oops, something went wrong.