Skip to content

Commit fdf5daf

Browse files
committed
PSI-class prefixes aren't getting added consistently #123
1 parent 73c1600 commit fdf5daf

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

support/org/intellij/grammar/generator/ParserGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public ParserGenerator(BnfFile tree, String sourcePath, String outputPath) {
123123
String tmpVisitorClass = getRootAttribute(myFile, KnownAttribute.PSI_VISITOR_NAME);
124124
visitorClassName = !G.generateVisitor || StringUtil.isEmpty(tmpVisitorClass) ? null :
125125
!tmpVisitorClass.equals(myPsiClassFormat.strip(tmpVisitorClass)) ? tmpVisitorClass :
126-
myPsiClassFormat.enforce("") + tmpVisitorClass;
126+
myPsiClassFormat.apply("") + tmpVisitorClass;
127127
mySimpleTokens = ContainerUtil.newLinkedHashMap(RuleGraphHelper.getTokenMap(myFile));
128128
myUnknownRootAttributes = collectUnknownAttributes(myFile);
129129
myGraphHelper = RuleGraphHelper.getCached(myFile);

support/org/intellij/grammar/generator/ParserGeneratorUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public static String toIdentifier(@NotNull String text, @Nullable NameFormat for
269269
if (cas == Case.CAMEL && i < len - 1 && !strings[i+1].startsWith("_") && Case.UPPER.apply(s).equals(s)) sb.append(s);
270270
else sb.append(cas.apply(s));
271271
}
272-
return format == null ? sb.toString() : format.enforce(sb.toString());
272+
return format == null ? sb.toString() : format.apply(sb.toString());
273273
}
274274

275275
public static String getPsiPackage(BnfFile file) {
@@ -797,9 +797,9 @@ private NameFormat(@Nullable String format) {
797797
suffix = StringUtil.join(parts.skip(1), "");
798798
}
799799

800-
public String enforce(String s) {
801-
if (prefix != null && !s.startsWith(prefix)) s = prefix + s;
802-
if (suffix != null && !s.endsWith(suffix)) s += suffix;
800+
public String apply(String s) {
801+
if (prefix != null) s = prefix + s;
802+
if (suffix != null) s += suffix;
803803
return s;
804804
}
805805

tests/org/intellij/grammar/BnfUtilTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public class BnfUtilTest extends UsefulTestCase {
2929
public void testIdentifiers() {
3030
assertEquals("AbcEdf", toIdentifier("abc-edf", Case.CAMEL));
3131
assertEquals("SampleAbcEdfElement", toIdentifier("abc-edf", "Sample/Element", Case.CAMEL));
32+
33+
// w/ a single-letter psiClass-prefix coincidentally matching the 1st letter of name being transformed
34+
assertEquals("CContinueStatementElement", toIdentifier("continue-statement", "C/Element", Case.CAMEL));
35+
// w/ a psiClass-suffix that matches the rule name suffix but has a different meaning & context and should be preserved
36+
assertEquals("HtmlBodyElementElement", toIdentifier("body-element", "Html/Element", Case.CAMEL));
37+
3238
assertEquals("getAbcEdf", getGetterName("abc-edf"));
3339
assertEquals("getMySomething", getGetterName("MY_SOMETHING"));
3440
assertEquals("getWithSpace", getGetterName("with space"));

0 commit comments

Comments
 (0)