Skip to content
Snippets Groups Projects
Commit e598ce02 authored by Johannes Mey's avatar Johannes Mey
Browse files

add inter-type declarations and attributes to structure view

parent adde402f
No related branches found
No related tags found
1 merge request!5Resolve "Structure View Support"
Pipeline #12041 passed
package org.jastadd.tooling.aspect; package org.jastadd.tooling.aspect;
import com.intellij.icons.AllIcons;
import com.intellij.ide.projectView.PresentationData; import com.intellij.ide.projectView.PresentationData;
import com.intellij.ide.structureView.StructureViewTreeElement; import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.SortableTreeElement; import com.intellij.ide.util.treeView.smartTree.SortableTreeElement;
import com.intellij.ide.util.treeView.smartTree.TreeElement; import com.intellij.ide.util.treeView.smartTree.TreeElement;
import com.intellij.navigation.ItemPresentation; import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.psi.NavigatablePsiElement; import com.intellij.psi.NavigatablePsiElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.util.PsiTreeUtil;
import org.jastadd.tooling.aspect.psi.AspectFile; import org.jastadd.tooling.aspect.psi.*;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectBodyDeclaration; import org.jastadd.tooling.aspect.psi.impl.*;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectDeclaration; import org.jastadd.tooling.util.JastAddIcons;
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.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
public class AspectStructureViewElement implements StructureViewTreeElement, SortableTreeElement { public class AspectStructureViewElement implements StructureViewTreeElement, SortableTreeElement {
...@@ -58,9 +59,133 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor ...@@ -58,9 +59,133 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor
@Override @Override
public ItemPresentation getPresentation() { public ItemPresentation getPresentation() {
ItemPresentation presentation = myElement.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(); 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 @Override
public TreeElement @NotNull [] getChildren() { public TreeElement @NotNull [] getChildren() {
if (myElement instanceof AspectFile) { if (myElement instanceof AspectFile) {
...@@ -80,6 +205,18 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor ...@@ -80,6 +205,18 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor
return new AspectStructureViewElement((JastAddAspectAspectInhAttributeDeclarationImpl) decl.getAspectInhAttributeDeclaration()); return new AspectStructureViewElement((JastAddAspectAspectInhAttributeDeclarationImpl) decl.getAspectInhAttributeDeclaration());
} else if (decl.getCollectionAttribute() != null) { } else if (decl.getCollectionAttribute() != null) {
return new AspectStructureViewElement((JastAddAspectCollectionAttributeImpl) decl.getCollectionAttribute()); 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; return null;
}) })
...@@ -87,6 +224,13 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor ...@@ -87,6 +224,13 @@ public class AspectStructureViewElement implements StructureViewTreeElement, Sor
.toArray(TreeElement[]::new); .toArray(TreeElement[]::new);
} }
// aspect_refine_method_declaration
// aspect_refine_constructor_declaration
// aspect_rewrite
// aspect_add_interface
// aspect_extend_interface
return EMPTY_ARRAY; return EMPTY_ARRAY;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment