Skip to content

Commit

Permalink
WEB-67476 Separate XmlParserBundle
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 1fc5b1306140d145eadaa9dd2d5037fae4d814be
  • Loading branch information
Victor Turansky authored and intellij-monorepo-bot committed Dec 2, 2024
1 parent cdc7f54 commit 8eea40a
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import com.intellij.structuralsearch.plugin.replace.impl.ReplacerUtil;
import com.intellij.structuralsearch.plugin.ui.Configuration;
import com.intellij.util.LocalTimeCounter;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlUtil;
import org.jetbrains.annotations.NonNls;
Expand Down Expand Up @@ -146,11 +146,11 @@ public void visitErrorElement(@NotNull PsiErrorElement element) {
super.visitErrorElement(element);
final String errorDescription = element.getErrorDescription();
final PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute && XmlPsiBundle.message("xml.parsing.expected.attribute.eq.sign").equals(errorDescription)) {
if (parent instanceof XmlAttribute && XmlParserBundle.message("xml.parsing.expected.attribute.eq.sign").equals(errorDescription)) {
return;
}
else if (parent instanceof XmlTag &&
XmlPsiBundle.message("xml.parsing.named.element.is.not.closed", ((XmlTag)parent).getName()).equals(errorDescription)) {
XmlParserBundle.message("xml.parsing.named.element.is.not.closed", ((XmlTag)parent).getName()).equals(errorDescription)) {
return;
}
throw new MalformedPatternException(errorDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.intellij.psi.templateLanguages.OuterLanguageElement;
import com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider;
import com.intellij.util.text.TextRangeUtil;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -30,8 +30,8 @@ public final class TemplateFormatUtil {
private static final List<PsiElement> EMPTY_PSI_ELEMENT_LIST = new ArrayList<>();

private static final String[] IGNORABLE_ERROR_MESSAGES = {
XmlPsiBundle.message("xml.parsing.closing.tag.matches.nothing"),
XmlPsiBundle.message("xml.parsing.closing.tag.name.missing")
XmlParserBundle.message("xml.parsing.closing.tag.matches.nothing"),
XmlParserBundle.message("xml.parsing.closing.tag.name.missing")
};

private TemplateFormatUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import com.intellij.lang.PsiBuilder;
import com.intellij.psi.tree.IElementType;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import org.intellij.plugins.relaxNG.RelaxngBundle;
import org.intellij.plugins.relaxNG.compact.RncElementTypes;

Expand Down Expand Up @@ -77,7 +77,7 @@ private void parseGrammarContent(boolean allowInclude) {
} else if (IDENTIFIERS.contains(t)) {
parseDefine();
} else {
error(XmlPsiBundle.message("xml.parsing.unexpected.token"));
error(XmlParserBundle.message("xml.parsing.unexpected.token"));
advance();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.PsiParser;
import com.intellij.psi.tree.IElementType;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import org.intellij.plugins.relaxNG.compact.RncElementTypes;
import org.jetbrains.annotations.NotNull;

Expand All @@ -34,7 +34,7 @@ public class RncParser implements PsiParser {
new PatternParsing(builder).parse();

while (!builder.eof()) {
builder.error(XmlPsiBundle.message("xml.parsing.unexpected.token"));
builder.error(XmlParserBundle.message("xml.parsing.unexpected.token"));
builder.advanceLexer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlTag;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import org.jetbrains.annotations.NotNull;

public class XmlErrorQuickFixProvider implements ErrorQuickFixProvider {
Expand All @@ -17,7 +17,7 @@ public void registerErrorQuickFix(@NotNull final PsiErrorElement element, @NotNu
return;
}
final String text = element.getErrorDescription();
if (text.equals(XmlPsiBundle.message("xml.parsing.unescaped.ampersand.or.nonterminated.character.entity.reference"))) {
if (text.equals(XmlParserBundle.message("xml.parsing.unescaped.ampersand.or.nonterminated.character.entity.reference"))) {
highlightInfo.registerFix(
new EscapeCharacterIntentionFix(element, new TextRange(0, 1), "&", "&amp;"),
null, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlToken;
import com.intellij.psi.xml.XmlTokenType;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import org.jetbrains.annotations.NotNull;

final class HtmlClosingTagErrorFilter extends HighlightErrorFilter {
Expand All @@ -24,7 +24,7 @@ public static boolean skip(@NotNull PsiErrorElement element) {
final PsiElement[] children = element.getChildren();
if (children.length > 0) {
if (children[0] instanceof XmlToken && XmlTokenType.XML_END_TAG_START == ((XmlToken)children[0]).getTokenType()) {
if (XmlPsiBundle.message("xml.parsing.closing.tag.matches.nothing").equals(element.getErrorDescription())) {
if (XmlParserBundle.message("xml.parsing.closing.tag.matches.nothing").equals(element.getErrorDescription())) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.intellij.psi.xml.XmlToken;
import com.intellij.psi.xml.XmlTokenType;
import com.intellij.xml.analysis.XmlAnalysisBundle;
import com.intellij.xml.psi.XmlPsiBundle;
import com.intellij.xml.parsing.XmlParserBundle;
import com.intellij.xml.util.HtmlUtil;
import com.intellij.xml.util.XmlTagUtil;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -59,7 +59,7 @@ else if (psiElement instanceof PsiErrorElement) {
PsiFile psiFile = holder.getCurrentAnnotationSession().getFile();

if (HTMLLanguage.INSTANCE == psiFile.getViewProvider().getBaseLanguage() || HTMLLanguage.INSTANCE == psiElement.getLanguage()) {
String message = XmlPsiBundle.message("xml.parsing.closing.tag.matches.nothing");
String message = XmlParserBundle.message("xml.parsing.closing.tag.matches.nothing");

if (message.equals(((PsiErrorElement)psiElement).getErrorDescription()) && psiFile.getContext() == null) {
holder.newAnnotation(HighlightSeverity.WARNING, message).range(psiElement).withFix(new RemoveExtraClosingTagIntentionAction()).create();
Expand Down
28 changes: 28 additions & 0 deletions xml/xml-psi-api/resources/messages/XmlParserBundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
dtd.parser.message.left.paren.or.entityref.or.empty.or.any.expected=( or entity ref or EMPTY or ANY expected
dtd.parser.message.literal.public.system.expected=Literal, PUBLIC or SYSTEM expected
dtd.parser.message.name.expected=XML name expected
dtd.parser.message.name.or.entity.ref.expected=XML name or entity ref expected
dtd.parser.message.rparen.expected=) expected
dtd.parser.message.whitespace.expected=Whitespace expected
dtd.parser.message.expected.prologue.tag.termination.expected='?>' expected

xml.parsing.absent.root.tag=Valid XML document must have a root tag
xml.parsing.attribute.value.expected=Attribute value expected
xml.parsing.bad.character=Bad character
xml.parsing.closing.tag.is.not.done=Closing tag is not valid
xml.parsing.closing.tag.matches.nothing=Closing tag matches nothing
xml.parsing.closing.tag.name.missing=Closing tag name is missing
xml.parsing.expected.attribute.eq.sign== expected
xml.parsing.named.element.is.not.closed=Element {0} is not closed
xml.parsing.multiple.root.tags=Multiple root tags
xml.parsing.processing.instruction.name.expected=Processing instruction name expected
xml.parsing.tag.name.expected=Tag name expected
xml.parsing.tag.start.is.not.closed=Tag start is not closed
xml.parsing.top.level.element.is.not.completed=Top level element is not completed
xml.parsing.unclosed.attribute.value=Attribute value is not closed
xml.parsing.unescaped.ampersand.or.nonterminated.character.entity.reference=Unescaped \\& or nonterminated character/entity reference
xml.parsing.unexpected.end.of.file=Unexpected end of file
xml.parsing.unexpected.token=Unexpected token
xml.parsing.unexpected.tokens=Unexpected tokens
xml.parsing.unterminated.processing.instruction=Processing instruction not terminated
xml.parsing.way.too.unbalanced=Way too unbalanced. Stopping attempt to balance tags properly at this point
29 changes: 0 additions & 29 deletions xml/xml-psi-api/resources/messages/XmlPsiBundle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
dtd.parser.message.left.paren.or.entityref.or.empty.or.any.expected=( or entity ref or EMPTY or ANY expected
dtd.parser.message.literal.public.system.expected=Literal, PUBLIC or SYSTEM expected
dtd.parser.message.name.expected=XML name expected
dtd.parser.message.name.or.entity.ref.expected=XML name or entity ref expected
dtd.parser.message.rparen.expected=) expected
dtd.parser.message.whitespace.expected=Whitespace expected
dtd.parser.message.expected.prologue.tag.termination.expected='?>' expected

filetype.dtd.description=XML Document Type Definition
filetype.html.description=HTML
filetype.xhtml.description=XHTML
Expand All @@ -23,27 +15,6 @@ xml.inspections.validate.external.resource.is.not.registered=External resource {

xml.namespace.prefix=XML Namespace Prefix

xml.parsing.absent.root.tag=Valid XML document must have a root tag
xml.parsing.attribute.value.expected=Attribute value expected
xml.parsing.bad.character=Bad character
xml.parsing.closing.tag.is.not.done=Closing tag is not valid
xml.parsing.closing.tag.matches.nothing=Closing tag matches nothing
xml.parsing.closing.tag.name.missing=Closing tag name is missing
xml.parsing.expected.attribute.eq.sign== expected
xml.parsing.named.element.is.not.closed=Element {0} is not closed
xml.parsing.multiple.root.tags=Multiple root tags
xml.parsing.processing.instruction.name.expected=Processing instruction name expected
xml.parsing.tag.name.expected=Tag name expected
xml.parsing.tag.start.is.not.closed=Tag start is not closed
xml.parsing.top.level.element.is.not.completed=Top level element is not completed
xml.parsing.unclosed.attribute.value=Attribute value is not closed
xml.parsing.unescaped.ampersand.or.nonterminated.character.entity.reference=Unescaped \\& or nonterminated character/entity reference
xml.parsing.unexpected.end.of.file=Unexpected end of file
xml.parsing.unexpected.token=Unexpected token
xml.parsing.unexpected.tokens=Unexpected tokens
xml.parsing.unterminated.processing.instruction=Processing instruction not terminated
xml.parsing.way.too.unbalanced=Way too unbalanced. Stopping attempt to balance tags properly at this point

xml.schema.validation.attr.not.allowed.with.ref=Attribute {0} is not allowed here when element reference is used
xml.schema.validation.default.or.fixed.should.be.specified.but.not.both='default' and 'fixed' attributes should not be present in the same time
xml.schema.validation.max.occurs.should.be.not.less.than.min.occurs=maxOccurs value should be greater than minOccurs value
Expand Down
30 changes: 30 additions & 0 deletions xml/xml-psi-api/src/com/intellij/xml/parsing/XmlParserBundle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.intellij.xml.parsing

import com.intellij.DynamicBundle
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import java.util.function.Supplier

object XmlParserBundle {
const val BUNDLE: @NonNls String = "messages.XmlParserBundle"
private val INSTANCE = DynamicBundle(XmlParserBundle::class.java, BUNDLE)

@JvmStatic
fun message(
@PropertyKey(resourceBundle = BUNDLE)
key: String,
vararg params: Any?,
): @Nls String {
return INSTANCE.getMessage(key = key, params = params)
}

@JvmStatic
fun messagePointer(
@PropertyKey(resourceBundle = BUNDLE)
key: String,
vararg params: Any?,
): Supplier<String> {
return INSTANCE.getLazyMessage(key = key, params = params)
}
}
Loading

0 comments on commit 8eea40a

Please sign in to comment.