From 89239c9431673bd876940604ab26ee41ac2bfedc Mon Sep 17 00:00:00 2001 From: Victor Turansky Date: Thu, 6 Feb 2025 17:45:34 +0200 Subject: [PATCH] WEB-68929 `XmlEntityContextType` moded on top (previously `XmlEntityDecl.EntityContextType`) GitOrigin-RevId: c3f1fcb38868a17e71170968fc3844a301898346 --- .../src/com/intellij/dtd/DtdParsingTest.java | 8 ++++---- .../intellij/psi/xml/XmlEntityContextType.kt | 14 +++++++++++++ .../com/intellij/psi/xml/XmlEntityDecl.java | 7 +------ .../intellij/lang/dtd/DTDParserDefinition.kt | 4 ++-- .../impl/source/parsing/xml/DtdParsing.java | 12 +++++------ .../impl/source/xml/XmlEntityDeclImpl.java | 4 ++-- .../src/com/intellij/xml/util/XmlPsiUtil.java | 20 +++++++++---------- 7 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 xml/xml-parser/src/com/intellij/psi/xml/XmlEntityContextType.kt diff --git a/xml/tests/src/com/intellij/dtd/DtdParsingTest.java b/xml/tests/src/com/intellij/dtd/DtdParsingTest.java index 4596e00ba3e1..ff29bb7873c0 100644 --- a/xml/tests/src/com/intellij/dtd/DtdParsingTest.java +++ b/xml/tests/src/com/intellij/dtd/DtdParsingTest.java @@ -14,7 +14,7 @@ import com.intellij.psi.impl.source.tree.CompositeElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.xml.StartTagEndTokenProvider; import com.intellij.psi.xml.XmlElementType; -import com.intellij.psi.xml.XmlEntityDecl; +import com.intellij.psi.xml.XmlEntityContextType; import com.intellij.testFramework.ParsingTestCase; import com.intellij.testFramework.PlatformTestUtil; import org.jetbrains.annotations.NonNls; @@ -67,13 +67,13 @@ public class DtdParsingTest extends ParsingTestCase { public void testManualEmptyAttributeParsing() { String value = " "; - final CompositeElement element = parseManually(value, XmlElementType.XML_ELEMENT_DECL, XmlEntityDecl.EntityContextType.GENERIC_XML); + final CompositeElement element = parseManually(value, XmlElementType.XML_ELEMENT_DECL, XmlEntityContextType.GENERIC_XML); checkResult("testManualEmptyAttributeParsing.txt", DebugUtil.treeToString(element, true)); } private static CompositeElement parseManually(final String value, final IElementType xmlElementDecl, - XmlEntityDecl.EntityContextType parseType) { + XmlEntityContextType parseType) { return (CompositeElement)new DtdParsing(value, xmlElementDecl, parseType, null).parse(); } @@ -177,7 +177,7 @@ public class DtdParsingTest extends ParsingTestCase { public void testEntityDeclaration2() { String s = "| %pre.qname; | %blockquote.qname; | %address.qname;"; CompositeElement element = - parseManually(s, XmlElementType.XML_ELEMENT_CONTENT_SPEC, XmlEntityDecl.EntityContextType.ELEMENT_CONTENT_SPEC); + parseManually(s, XmlElementType.XML_ELEMENT_CONTENT_SPEC, XmlEntityContextType.ELEMENT_CONTENT_SPEC); checkResult("testEntityDeclaration2.txt", DebugUtil.treeToString(element, true)); } diff --git a/xml/xml-parser/src/com/intellij/psi/xml/XmlEntityContextType.kt b/xml/xml-parser/src/com/intellij/psi/xml/XmlEntityContextType.kt new file mode 100644 index 000000000000..1167af9ea2b4 --- /dev/null +++ b/xml/xml-parser/src/com/intellij/psi/xml/XmlEntityContextType.kt @@ -0,0 +1,14 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.psi.xml + +enum class XmlEntityContextType { + ELEMENT_CONTENT_SPEC, + ATTRIBUTE_SPEC, + ATTLIST_SPEC, + ENTITY_DECL_CONTENT, + GENERIC_XML, + ENUMERATED_TYPE, + ATTR_VALUE, + + ; +} diff --git a/xml/xml-psi-api/src/com/intellij/psi/xml/XmlEntityDecl.java b/xml/xml-psi-api/src/com/intellij/psi/xml/XmlEntityDecl.java index 5bf66c1e6673..e0c1b4c94c98 100644 --- a/xml/xml-psi-api/src/com/intellij/psi/xml/XmlEntityDecl.java +++ b/xml/xml-psi-api/src/com/intellij/psi/xml/XmlEntityDecl.java @@ -6,15 +6,10 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.PsiNamedElement; public interface XmlEntityDecl extends XmlElement, PsiNamedElement { - enum EntityContextType { - ELEMENT_CONTENT_SPEC, ATTRIBUTE_SPEC, ATTLIST_SPEC, ENTITY_DECL_CONTENT, GENERIC_XML, - ENUMERATED_TYPE, ATTR_VALUE - } - @Override String getName(); PsiElement getNameElement(); XmlAttributeValue getValueElement(); - PsiElement parse(PsiFile baseFile, EntityContextType context, XmlEntityRef originalElement); + PsiElement parse(PsiFile baseFile, XmlEntityContextType context, XmlEntityRef originalElement); boolean isInternalReference(); } diff --git a/xml/xml-psi-impl/src/com/intellij/lang/dtd/DTDParserDefinition.kt b/xml/xml-psi-impl/src/com/intellij/lang/dtd/DTDParserDefinition.kt index 35d560e38063..b56ccd45a8dc 100644 --- a/xml/xml-psi-impl/src/com/intellij/lang/dtd/DTDParserDefinition.kt +++ b/xml/xml-psi-impl/src/com/intellij/lang/dtd/DTDParserDefinition.kt @@ -15,7 +15,7 @@ import com.intellij.psi.impl.source.parsing.xml.DtdParsing import com.intellij.psi.impl.source.xml.XmlFileImpl import com.intellij.psi.tree.IFileElementType import com.intellij.psi.xml.XmlElementType -import com.intellij.psi.xml.XmlEntityDecl +import com.intellij.psi.xml.XmlEntityContextType class DTDParserDefinition : XMLParserDefinition() { @@ -28,7 +28,7 @@ class DTDParserDefinition : override fun createParser(project: Project?): PsiParser = PsiParser { root, builder -> - DtdParsing(root, XmlEntityDecl.EntityContextType.GENERIC_XML, builder).parse() + DtdParsing(root, XmlEntityContextType.GENERIC_XML, builder).parse() } override fun getFileNodeType(): IFileElementType = diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java index aec91b100f29..252bbad5b79b 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/parsing/xml/DtdParsing.java @@ -17,7 +17,7 @@ import com.intellij.psi.impl.source.tree.FileElement; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; -import com.intellij.psi.xml.XmlEntityDecl; +import com.intellij.psi.xml.XmlEntityContextType; import com.intellij.xml.parsing.XmlParserBundle; import org.jetbrains.annotations.NotNull; @@ -28,10 +28,10 @@ public class DtdParsing extends XmlParsing { private static final Logger LOG = Logger.getInstance(XmlParser.class); private final IElementType myRootType; - public static final XmlEntityDecl.EntityContextType TYPE_FOR_MARKUP_DECL = XmlEntityDecl.EntityContextType.ELEMENT_CONTENT_SPEC; - private final XmlEntityDecl.EntityContextType myContextType; + public static final XmlEntityContextType TYPE_FOR_MARKUP_DECL = XmlEntityContextType.ELEMENT_CONTENT_SPEC; + private final XmlEntityContextType myContextType; - public DtdParsing(IElementType root, XmlEntityDecl.EntityContextType contextType, PsiBuilder builder) { + public DtdParsing(IElementType root, XmlEntityContextType contextType, PsiBuilder builder) { super(builder); myRootType = root; myContextType = contextType; @@ -40,7 +40,7 @@ public class DtdParsing extends XmlParsing { public DtdParsing(CharSequence chars, final IElementType type, - final XmlEntityDecl.EntityContextType contextType, + final XmlEntityContextType contextType, PsiFile contextFile ) { this( @@ -116,7 +116,7 @@ public class DtdParsing extends XmlParsing { return astNode; } - private static int getLexerInitialState(IElementType rootNodeType, XmlEntityDecl.EntityContextType context) { + private static int getLexerInitialState(IElementType rootNodeType, XmlEntityContextType context) { short state = 0; switch (context) { diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlEntityDeclImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlEntityDeclImpl.java index 55fac0f808a3..b64967125f7e 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlEntityDeclImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlEntityDeclImpl.java @@ -78,7 +78,7 @@ public class XmlEntityDeclImpl extends XmlElementImpl implements XmlEntityDecl { } @Override - public PsiElement parse(PsiFile baseFile, EntityContextType contextType, final XmlEntityRef originalElement) { + public PsiElement parse(PsiFile baseFile, XmlEntityContextType contextType, final XmlEntityRef originalElement) { PsiElement dep = DEPENDING_ELEMENT.get(getParent()); PsiElement dependsOnElement = getValueElement(dep instanceof PsiFile ? (PsiFile)dep : baseFile); String value = null; @@ -93,7 +93,7 @@ public class XmlEntityDeclImpl extends XmlElementImpl implements XmlEntityDecl { DtdParsing dtdParsing = new DtdParsing(value, XML_ELEMENT_DECL, contextType, baseFile); PsiElement generated = dtdParsing.parse().getPsi().getFirstChild(); - if (contextType == EntityContextType.ELEMENT_CONTENT_SPEC && generated instanceof XmlElementContentSpec) { + if (contextType == XmlEntityContextType.ELEMENT_CONTENT_SPEC && generated instanceof XmlElementContentSpec) { generated = generated.getFirstChild(); } setDependsOnElement(generated, dependsOnElement); diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlPsiUtil.java b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlPsiUtil.java index edc69d795b1c..33944a196c65 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/XmlPsiUtil.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/XmlPsiUtil.java @@ -162,7 +162,7 @@ public final class XmlPsiUtil { } private static PsiElement parseEntityRef(PsiFile targetFile, XmlEntityRef ref) { - XmlEntityDecl.EntityContextType type = getContextType(ref); + XmlEntityContextType type = getContextType(ref); { final XmlEntityDecl entityDecl = ref.resolve(targetFile); @@ -199,27 +199,27 @@ public final class XmlPsiUtil { return null; } - private static XmlEntityDecl.EntityContextType getContextType(XmlEntityRef ref) { - XmlEntityDecl.EntityContextType type = XmlEntityDecl.EntityContextType.GENERIC_XML; + private static XmlEntityContextType getContextType(XmlEntityRef ref) { + XmlEntityContextType type = XmlEntityContextType.GENERIC_XML; PsiElement temp = ref; while (temp != null) { if (temp instanceof XmlAttributeDecl) { - type = XmlEntityDecl.EntityContextType.ATTRIBUTE_SPEC; + type = XmlEntityContextType.ATTRIBUTE_SPEC; } else if (temp instanceof XmlElementDecl) { - type = XmlEntityDecl.EntityContextType.ELEMENT_CONTENT_SPEC; + type = XmlEntityContextType.ELEMENT_CONTENT_SPEC; } else if (temp instanceof XmlAttlistDecl) { - type = XmlEntityDecl.EntityContextType.ATTLIST_SPEC; + type = XmlEntityContextType.ATTLIST_SPEC; } else if (temp instanceof XmlEntityDecl) { - type = XmlEntityDecl.EntityContextType.ENTITY_DECL_CONTENT; + type = XmlEntityContextType.ENTITY_DECL_CONTENT; } else if (temp instanceof XmlEnumeratedType) { - type = XmlEntityDecl.EntityContextType.ENUMERATED_TYPE; + type = XmlEntityContextType.ENUMERATED_TYPE; } else if (temp instanceof XmlAttributeValue) { - type = XmlEntityDecl.EntityContextType.ATTR_VALUE; + type = XmlEntityContextType.ATTR_VALUE; } else { temp = temp.getContext(); @@ -232,7 +232,7 @@ public final class XmlPsiUtil { private static PsiElement parseEntityDecl(final XmlEntityDecl entityDecl, final PsiFile targetFile, - final XmlEntityDecl.EntityContextType type, + final XmlEntityContextType type, final XmlEntityRef entityRef) { CachedValue value = ConcurrencyUtil.computeIfAbsent(entityRef, PARSED_DECL_KEY, () -> CachedValuesManager.getManager(entityDecl.getProject()).createCachedValue(() -> {