Skip to content
Snippets Groups Projects

Resolve "Structure View Support"

Merged Johannes Mey requested to merge feature/structure-view-support into develop
14 files
+ 509
30
Compare changes
  • Side-by-side
  • Inline
Files
14
package org.jastadd.tooling.aspect.psi.impl;
import com.intellij.lang.ASTNode;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.psi.PsiElement;
import org.jastadd.tooling.aspect.psi.AspectElementFactory;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectDeclaration;
import org.jastadd.tooling.aspect.psi.JastAddAspectAspectName;
import org.jastadd.tooling.grammar.psi.GrammarNamedElement;
import org.jastadd.tooling.grammar.psi.impl.GrammarNamedElementImpl;
import org.jastadd.tooling.util.JastAddIcons;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
public class JastAddAspectAspectDeclarationImplExtension extends GrammarNamedElementImpl implements GrammarNamedElement {
public JastAddAspectAspectDeclarationImplExtension(@NotNull ASTNode node) {
super(node);
}
public String getName() {
return getNameIdentifier().getText();
}
public PsiElement setName(@NotNull String newName) {
ASTNode identifierNode = getNameIdentifier().getNode().getFirstChildNode();
if (identifierNode != null) {
JastAddAspectAspectDeclaration name = AspectElementFactory.createAspectDeclaration(getProject(), newName);
assert name != null; // we know the name is not null because we always create the same one
ASTNode newNameIdentifierNode = name.getAspectName().getNode().getFirstChildNode();
getNameIdentifier().getNode().replaceChild(identifierNode, newNameIdentifierNode);
}
return this;
}
@Override
@NotNull
public JastAddAspectAspectName getNameIdentifier() {
return ((JastAddAspectAspectDeclaration) getNode().getPsi()).getAspectName();
}
@Override
public ItemPresentation getPresentation() {
return new ItemPresentation() {
@Nullable
@Override
public String getPresentableText() {
return "aspect " + getName();
}
@Override
public String getLocationString() {
Document document = FileDocumentManager.getInstance().getDocument(getNode().getPsi().getContainingFile().getVirtualFile());
return document != null ? "l." + document.getLineNumber(getTextRange().getStartOffset() + 1) : "";
}
@Override
public Icon getIcon(boolean unused) {
return JastAddIcons.FILE;
}
};
}
}
Loading