Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
.idea/shelf/
.idea/workspace.xml
.gradle/
.idea/compiler.xml
.idea/gradle.xml
.idea/misc.xml
.idea/modules.xml
.idea/modules/
.idea/libraries/
.intellijPlatform/
out/
binaries/
build/
Expand Down
18 changes: 0 additions & 18 deletions .idea/compiler.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/libraries/org_jetbrains_annotations_Latest.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<body>
<p>Allows specifying a fallback class to use for an elementType in the constructor of stub elements.</p>

<p>Usually the parser generator looks into the parent class file to detect which class to use.
But in some cases a parent class file may not be available (not yet compiled).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a parent class file

let it be "the parent class"

In this case, it uses `IStubElementType` by default, which may not be the case in the modern code when `IElementType` should be used.
</p>

<p>This is per parser option. It does not allow overriding the default per rule.</p>
</body>
</html>
4 changes: 3 additions & 1 deletion src/org/intellij/grammar/KnownAttribute.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* Copyright 2011-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/

package org.intellij.grammar;
Expand Down Expand Up @@ -52,6 +52,8 @@ public class KnownAttribute<T> {
public static final KnownAttribute<String> EXTENDS = create(false, String.class, "extends", BnfConstants.AST_WRAPPER_PSI_ELEMENT_CLASS);
public static final KnownAttribute<ListValue> IMPLEMENTS = create(false, ListValue.class, "implements", ListValue.singleValue( null, BnfConstants.PSI_ELEMENT_CLASS));
public static final KnownAttribute<String> ELEMENT_TYPE = create(false, String.class, "elementType", null);
public static final KnownAttribute<String> FALLBACK_STUB_ELEMENT_TYPE =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind keeping the formatting in the file? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to shift all the fields, and this does not fit

create(false, String.class, "fallbackStubElementType", BnfConstants.ISTUBELEMENTTYPE_CLASS);
public static final KnownAttribute<String> ELEMENT_TYPE_CLASS = create(false, String.class, "elementTypeClass", BnfConstants.IELEMENTTYPE_CLASS);
public static final KnownAttribute<String> ELEMENT_TYPE_FACTORY = create(false, String.class, "elementTypeFactory", null);
public static final KnownAttribute<Object> PIN = create(false, Object.class, "pin", -1);
Expand Down
6 changes: 5 additions & 1 deletion src/org/intellij/grammar/generator/GenOptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* Copyright 2011-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/

package org.intellij.grammar.generator;
Expand All @@ -11,6 +11,7 @@

import java.util.Map;

import static org.intellij.grammar.KnownAttribute.FALLBACK_STUB_ELEMENT_TYPE;
import static org.intellij.grammar.generator.ParserGeneratorUtil.getGenerateOption;
import static org.intellij.grammar.generator.ParserGeneratorUtil.getRootAttribute;

Expand All @@ -35,6 +36,7 @@ public class GenOptions {
public final Case generateElementCase;
public final boolean generateTokenAccessors;
public final boolean generateTokenAccessorsSet;
public final String fallbackStubElementType;
public final int javaVersion;

public GenOptions(BnfFile myFile) {
Expand All @@ -48,6 +50,8 @@ public GenOptions(BnfFile myFile) {
generateTokenSets = generateTokenTypes && "yes".equals(genOptions.get("token-sets"));
generateElementTypes = !"no".equals(genOptions.get("elements"));
generateExactTypes = StringUtil.notNullize(genOptions.get("exact-types"));
fallbackStubElementType = StringUtil.notNullize(getGenerateOption(myFile, FALLBACK_STUB_ELEMENT_TYPE, genOptions),
FALLBACK_STUB_ELEMENT_TYPE.getDefaultValue());
generateFirstCheck = getGenerateOption(myFile, KnownAttribute.GENERATE_FIRST_CHECK, genOptions, "first-check", "firstCheck");
generateExtendedPin = getGenerateOption(myFile, KnownAttribute.EXTENDED_PIN, genOptions, "extended-pin", "extendedPin");
generateTokenAccessors = getGenerateOption(myFile, KnownAttribute.GENERATE_TOKEN_ACCESSORS, genOptions, "token-accessors", "tokenAccessors");
Expand Down
8 changes: 4 additions & 4 deletions src/org/intellij/grammar/generator/ParserGenerator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
* Copyright 2011-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/

package org.intellij.grammar.generator;
Expand Down Expand Up @@ -31,9 +31,9 @@
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.*;

import static com.intellij.util.containers.ContainerUtil.emptyList;
import static com.intellij.util.containers.ContainerUtil.map;
Expand Down Expand Up @@ -1615,7 +1615,7 @@ private void generatePsiImpl(BnfRule rule, RuleInfo info) {
for (NavigatablePsiElement m : constructors) {
collectMethodTypesToImport(Collections.singletonList(m), false, imports);
}
if (stubName != null && constructors.isEmpty()) imports.add(ISTUBELEMENTTYPE_CLASS);
if (stubName != null && constructors.isEmpty()) imports.add(G.fallbackStubElementType);
if (stubName != null) imports.add(stubName);
}

Expand All @@ -1642,7 +1642,7 @@ private void generatePsiImpl(BnfRule rule, RuleInfo info) {
if (stubName != null) {
out("public " + shortName + "(" +
shorten(stubName) + " stub, " +
shorten(ISTUBELEMENTTYPE_CLASS) + " stubType) {");
shorten(G.fallbackStubElementType) + " stubType) {");
out("super(stub, stubType);");
out("}");
newLine();
Expand Down
Loading
Loading