Skip to content
Snippets Groups Projects

Resolve "Structure View Support"

Merged Johannes Mey requested to merge feature/structure-view-support into develop
1 file
+ 152
8
Compare changes
  • Side-by-side
  • Inline
package org.jastadd.tooling.aspect;
import com.intellij.icons.AllIcons;
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.openapi.util.NlsSafe;
import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import org.jastadd.tooling.aspect.psi.AspectFile;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectBodyDeclaration;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectDeclaration;
import org.jastadd.tooling.aspect.psi.JastAddAspectTypeDeclaration;
import org.jastadd.tooling.aspect.psi.impl.JastAddAspectAspectDeclarationImpl;
import org.jastadd.tooling.aspect.psi.impl.JastAddAspectAspectInhAttributeDeclarationImpl;
import org.jastadd.tooling.aspect.psi.impl.JastAddAspectAspectSynAttributeDeclarationImpl;
import org.jastadd.tooling.aspect.psi.impl.JastAddAspectCollectionAttributeImpl;
import org.jastadd.tooling.aspect.psi.*;
import org.jastadd.tooling.aspect.psi.impl.*;
import org.jastadd.tooling.util.JastAddIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Objects;
import java.util.stream.Collectors;
public class AspectStructureViewElement implements StructureViewTreeElement, SortableTreeElement {
@@ -58,9 +59,133 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor
@Override
public ItemPresentation getPresentation() {
ItemPresentation presentation = myElement.getPresentation();
if (presentation == null) {
if (myElement instanceof JastAddAspectAspectMethodDeclaration) {
presentation = new ItemPresentation() {
@Override
public String getPresentableText() {
return AspectStructureViewElement.getPresentableText((JastAddAspectAspectMethodDeclaration) myElement);
}
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.Method;
}
};
} else if (myElement instanceof JastAddAspectAspectClassDeclaration) {
presentation = new ItemPresentation() {
@Override
public String getPresentableText() {
return AspectStructureViewElement.getPresentableText((JastAddAspectAspectClassDeclaration) myElement);
}
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.Class;
}
};
} else if (myElement instanceof JastAddAspectAspectEnumDeclaration) {
presentation = new ItemPresentation() {
@Override
public String getPresentableText() {
return AspectStructureViewElement.getPresentableText((JastAddAspectAspectEnumDeclaration) myElement);
}
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.Enum;
}
};
} else if (myElement instanceof JastAddAspectAspectInterfaceDeclaration) {
presentation = new ItemPresentation() {
@Override
public String getPresentableText() {
return AspectStructureViewElement.getPresentableText((JastAddAspectAspectInterfaceDeclaration) myElement);
}
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.Interface;
}
};
} else if (myElement instanceof JastAddAspectAspectFieldDeclaration) {
presentation = new ItemPresentation() {
@Override
public String getPresentableText() {
return AspectStructureViewElement.getPresentableText((JastAddAspectAspectFieldDeclaration) myElement);
}
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.Field;
}
};
} else if (myElement instanceof JastAddAspectAspectConstructorDeclaration) {
presentation = new ItemPresentation() {
@Override
public String getPresentableText() {
return AspectStructureViewElement.getPresentableText((JastAddAspectAspectConstructorDeclaration) myElement);
}
@Override
public Icon getIcon(boolean unused) {
return AllIcons.Nodes.Method;
}
};
}
}
return presentation != null ? presentation : new PresentationData();
}
private static String getPresentableText(JastAddAspectAspectClassDeclaration decl) {
return decl.getModifiers().getText()
+ " class " + decl.getClassDeclaration().getSimpleTypeName().getText();
}
private static String getPresentableText(JastAddAspectAspectEnumDeclaration decl) {
return decl.getModifiers().getText()
+ " class " + decl.getSimpleTypeName().getText();
}
private static String getPresentableText(JastAddAspectAspectInterfaceDeclaration decl) {
return decl.getModifiers().getText()
+ " class " + decl.getSimpleTypeName().getText();
}
private static String getPresentableText(JastAddAspectAspectFieldDeclaration decl) {
return decl.getModifiers().getText()
+ " " + decl.getAstTypeName().getText()
+ " : " + decl.getAspectType().getText();
}
private static String getPresentableText(JastAddAspectAspectConstructorDeclaration decl) {
return decl.getModifiers().getText()
+ " " + decl.getAstTypeNameList().get(0).getText()
+ "." + decl.getAstTypeNameList().get(1).getText()
+ decl.getFormalParameters().getFormalParameterList().stream()
.map(JastAddAspectFormalParameter::getType)
.map(PsiElement::getText).collect(Collectors.joining(", ", "(", ")"));
}
private static String getPresentableText(JastAddAspectAspectMethodDeclaration decl) {
return decl.getModifiers().getText()
+ " " + decl.getAstTypeName().getText()
+ "." + AspectStructureViewElement.getPresentableText(decl.getMethodDeclarator()) + " : "
+ decl.getAspectResultType().getText();
}
private static String getPresentableText(JastAddAspectMethodDeclarator declarator) {
return declarator.getJavaIdentifier().getText()
+ declarator.getFormalParameters().getFormalParameterList().stream()
.map(JastAddAspectFormalParameter::getType)
.map(PsiElement::getText).collect(Collectors.joining(", ", "(", ")"));
}
@Override
public TreeElement @NotNull [] getChildren() {
if (myElement instanceof AspectFile) {
@@ -80,6 +205,18 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor
return new AspectStructureViewElement((JastAddAspectAspectInhAttributeDeclarationImpl) decl.getAspectInhAttributeDeclaration());
} else if (decl.getCollectionAttribute() != null) {
return new AspectStructureViewElement((JastAddAspectCollectionAttributeImpl) decl.getCollectionAttribute());
} else if (decl.getAspectMethodDeclaration() != null) {
return new AspectStructureViewElement((JastAddAspectAspectMethodDeclarationImpl) decl.getAspectMethodDeclaration());
} else if (decl.getAspectClassDeclaration() != null) {
return new AspectStructureViewElement((JastAddAspectAspectClassDeclarationImpl) decl.getAspectClassDeclaration());
} else if (decl.getAspectEnumDeclaration() != null) {
return new AspectStructureViewElement((JastAddAspectAspectEnumDeclarationImpl) decl.getAspectEnumDeclaration());
} else if (decl.getAspectInterfaceDeclaration() != null) {
return new AspectStructureViewElement((JastAddAspectAspectInterfaceDeclarationImpl) decl.getAspectInterfaceDeclaration());
} else if (decl.getAspectFieldDeclaration() != null) {
return new AspectStructureViewElement((JastAddAspectAspectFieldDeclarationImpl) decl.getAspectFieldDeclaration());
} else if (decl.getAspectConstructorDeclaration()!= null) {
return new AspectStructureViewElement((JastAddAspectAspectConstructorDeclarationImpl) decl.getAspectConstructorDeclaration());
}
return null;
})
@@ -87,6 +224,13 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor
.toArray(TreeElement[]::new);
}
// aspect_refine_method_declaration
// aspect_refine_constructor_declaration
// aspect_rewrite
// aspect_add_interface
// aspect_extend_interface
return EMPTY_ARRAY;
}
Loading