Added stubbing and stub index for symbol definitions.

This commit is contained in:
Chris Hodges 2021-07-25 20:13:13 +02:00
parent 83d2ca3304
commit 89ecaeb613
11 changed files with 89 additions and 5 deletions

View File

@ -2,10 +2,12 @@
package de.platon42.intellij.plugins.m68k.psi;
import com.intellij.psi.PsiElement;
import com.intellij.psi.StubBasedPsiElement;
import de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStub;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface M68kSymbolDefinition extends M68kNamedElement {
public interface M68kSymbolDefinition extends M68kNamedElement, StubBasedPsiElement<M68kSymbolDefinitionStub> {
@Nullable
String getName();

View File

@ -66,7 +66,7 @@ public interface M68kTypes {
IElementType SPECIAL_REGISTER = new M68kElementType("SPECIAL_REGISTER");
IElementType SPECIAL_REGISTER_DIRECT_ADDRESSING_MODE = new M68kElementType("SPECIAL_REGISTER_DIRECT_ADDRESSING_MODE");
IElementType STATEMENT = new M68kElementType("STATEMENT");
IElementType SYMBOL_DEFINITION = new M68kElementType("SYMBOL_DEFINITION");
IElementType SYMBOL_DEFINITION = M68kStubElementTypeFactory.stubFactory("SYMBOL_DEFINITION");
IElementType SYMBOL_REFERENCE = new M68kElementType("SYMBOL_REFERENCE");
IElementType UNARY_COMPL_EXPR = new M68kElementType("UNARY_COMPL_EXPR");
IElementType UNARY_MINUS_EXPR = new M68kElementType("UNARY_MINUS_EXPR");

View File

@ -4,10 +4,12 @@ package de.platon42.intellij.plugins.m68k.psi.impl;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.stubs.IStubElementType;
import de.platon42.intellij.plugins.m68k.psi.M68kPsiImplUtil;
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition;
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinitionMixin;
import de.platon42.intellij.plugins.m68k.psi.M68kVisitor;
import de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStub;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -17,6 +19,10 @@ public class M68kSymbolDefinitionImpl extends M68kSymbolDefinitionMixin implemen
super(node);
}
public M68kSymbolDefinitionImpl(@NotNull M68kSymbolDefinitionStub stub, @NotNull IStubElementType<?, ?> nodeType) {
super(stub, nodeType);
}
public void accept(@NotNull M68kVisitor visitor) {
visitor.visitSymbolDefinition(this);
}

View File

@ -130,6 +130,8 @@ private statement_recover ::= !(EOL)
SymbolDefinition ::= SYMBOLDEF {
implements = "de.platon42.intellij.plugins.m68k.psi.M68kNamedElement"
mixin = "de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinitionMixin"
elementTypeFactory = "de.platon42.intellij.plugins.m68k.stubs.M68kStubElementTypeFactory.stubFactory"
stubClass = "de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStub"
methods = [getName setName getNameIdentifier]
}

View File

@ -1,19 +1,29 @@
package de.platon42.intellij.plugins.m68k.psi
import com.intellij.extapi.psi.ASTWrapperPsiElement
import com.intellij.extapi.psi.StubBasedPsiElementBase
import com.intellij.ide.projectView.PresentationData
import com.intellij.lang.ASTNode
import com.intellij.navigation.ItemPresentation
import com.intellij.psi.stubs.IStubElementType
import de.platon42.intellij.plugins.m68k.M68kIcons
import de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStub
import javax.swing.Icon
abstract class M68kSymbolDefinitionMixin(node: ASTNode) : ASTWrapperPsiElement(node), M68kSymbolDefinition {
abstract class M68kSymbolDefinitionMixin : StubBasedPsiElementBase<M68kSymbolDefinitionStub>, M68kSymbolDefinition {
constructor(node: ASTNode) : super(node)
constructor(stub: M68kSymbolDefinitionStub, nodeType: IStubElementType<*, *>) : super(stub, nodeType)
override fun getPresentation(): ItemPresentation? {
return PresentationData(name, containingFile?.name, getIcon(0), null)
return PresentationData(name, containingFile.name, getIcon(0), null)
}
override fun getIcon(flags: Int): Icon? {
return M68kIcons.SYMBOL_DEF
}
override fun toString(): String {
return javaClass.simpleName + "(SYMBOL_DEFINITION)"
}
}

View File

@ -8,9 +8,12 @@ import com.intellij.psi.stubs.*
import com.intellij.psi.tree.ILightStubFileElementType
import de.platon42.intellij.plugins.m68k.MC68000Language.Companion.INSTANCE
import de.platon42.intellij.plugins.m68k.psi.M68kGlobalLabel
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition
import de.platon42.intellij.plugins.m68k.psi.M68kTypes
import de.platon42.intellij.plugins.m68k.psi.impl.M68kGlobalLabelImpl
import de.platon42.intellij.plugins.m68k.psi.impl.M68kSymbolDefinitionImpl
import de.platon42.intellij.plugins.m68k.stubs.impl.M68kGlobalLabelStubImpl
import de.platon42.intellij.plugins.m68k.stubs.impl.M68kSymbolDefinitionStubImpl
import java.io.IOException
interface M68kElementTypes {
@ -40,5 +43,29 @@ interface M68kElementTypes {
override fun indexStub(stub: M68kGlobalLabelStub, sink: IndexSink) = sink.occurrence(M68kGlobalLabelStubIndex.KEY, stub.name!!)
}
@JvmField
val SYMBOL_DEFINITION: IStubElementType<M68kSymbolDefinitionStub, M68kSymbolDefinition> =
object : M68kStubElementType<M68kSymbolDefinitionStub, M68kSymbolDefinition>("SYMBOL_DEFINITION") {
override fun createPsi(stub: M68kSymbolDefinitionStub): M68kSymbolDefinition = M68kSymbolDefinitionImpl(stub, this)
override fun createStub(psi: M68kSymbolDefinition, parentStub: StubElement<out PsiElement>): M68kSymbolDefinitionStub =
M68kSymbolDefinitionStubImpl(parentStub, this, psi.name!!)
override fun createStub(tree: LighterAST, node: LighterASTNode, parentStub: StubElement<*>): M68kSymbolDefinitionStub {
val idNode = LightTreeUtil.requiredChildOfType(tree, node, M68kTypes.SYMBOLDEF)
return M68kSymbolDefinitionStubImpl(parentStub, this, LightTreeUtil.toFilteredString(tree, idNode, null))
}
@Throws(IOException::class)
override fun serialize(stub: M68kSymbolDefinitionStub, dataStream: StubOutputStream) = dataStream.writeName(stub.name)
@Throws(IOException::class)
override fun deserialize(dataStream: StubInputStream, parentStub: StubElement<*>): M68kSymbolDefinitionStub =
M68kSymbolDefinitionStubImpl(parentStub, this, dataStream.readName()!!)
override fun indexStub(stub: M68kSymbolDefinitionStub, sink: IndexSink) = sink.occurrence(M68kSymbolDefinitionStubIndex.KEY, stub.name!!)
}
}
}

View File

@ -9,6 +9,7 @@ object M68kStubElementTypeFactory {
fun stubFactory(name: String): IStubElementType<out StubElement<out M68kPsiElement>, out M68kPsiElement> {
when (name) {
"GLOBAL_LABEL" -> return M68kElementTypes.GLOBAL_LABEL
"SYMBOL_DEFINITION" -> return M68kElementTypes.SYMBOL_DEFINITION
else -> throw RuntimeException("Unknown element type '$name'")
}
}

View File

@ -0,0 +1,6 @@
package de.platon42.intellij.plugins.m68k.stubs
import com.intellij.psi.stubs.NamedStub
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition
interface M68kSymbolDefinitionStub : NamedStub<M68kSymbolDefinition>

View File

@ -0,0 +1,16 @@
package de.platon42.intellij.plugins.m68k.stubs
import com.intellij.psi.stubs.StringStubIndexExtension
import com.intellij.psi.stubs.StubIndexKey
import de.platon42.intellij.plugins.m68k.M68kFileElementType
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition
class M68kSymbolDefinitionStubIndex : StringStubIndexExtension<M68kSymbolDefinition>() {
override fun getKey(): StubIndexKey<String, M68kSymbolDefinition> = KEY
override fun getVersion(): Int = M68kFileElementType.STUB_VERSION
companion object {
val KEY = StubIndexKey.createIndexKey<String, M68kSymbolDefinition>("mc68000.symboldef.index")
}
}

View File

@ -0,0 +1,13 @@
package de.platon42.intellij.plugins.m68k.stubs.impl
import com.intellij.psi.stubs.IStubElementType
import com.intellij.psi.stubs.NamedStubBase
import com.intellij.psi.stubs.StubElement
import com.intellij.util.io.StringRef
import de.platon42.intellij.plugins.m68k.psi.M68kSymbolDefinition
import de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStub
class M68kSymbolDefinitionStubImpl : NamedStubBase<M68kSymbolDefinition>, M68kSymbolDefinitionStub {
constructor(parent: StubElement<*>, elementType: IStubElementType<*, *>, name: StringRef) : super(parent, elementType, name)
constructor(parent: StubElement<*>, elementType: IStubElementType<*, *>, name: String) : super(parent, elementType, name)
}

View File

@ -31,6 +31,7 @@
implementationClass="de.platon42.intellij.plugins.m68k.refs.M68kSymbolReferenceElementManipulator"/>
<stubElementTypeHolder class="de.platon42.intellij.plugins.m68k.stubs.M68kElementTypes"/>
<stubIndex implementation="de.platon42.intellij.plugins.m68k.stubs.M68kGlobalLabelStubIndex"/>
<stubIndex implementation="de.platon42.intellij.plugins.m68k.stubs.M68kSymbolDefinitionStubIndex"/>
<psi.referenceContributor implementation="de.platon42.intellij.plugins.m68k.refs.M68kReferenceContributor"/>
<gotoSymbolContributor implementation="de.platon42.intellij.plugins.m68k.refs.M68kChooseByNameContributor"/>
<renameInputValidator implementation="de.platon42.intellij.plugins.m68k.psi.M68kRenameInputValidator"/>