Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.intellij.grammar.config;

import consulo.util.lang.ObjectUtil;
Expand All @@ -33,14 +32,15 @@ abstract class Option<T> implements Supplier<T> {
this.defValue = defValue;
}

@Override
public abstract T get();

String innerValue() {
return System.getProperty(id);
}

static Option<Integer> intOption(String id, int def) {
return new Option<Integer>(id, def) {
return new Option<>(id, def) {
@Override
public Integer get() {
return StringUtil.parseInt(innerValue(), defValue);
Expand All @@ -49,7 +49,7 @@ public Integer get() {
}

static Option<String> strOption(String id, String def) {
return new Option<String>(id, def) {
return new Option<>(id, def) {
@Override
public String get() {
return ObjectUtil.chooseNotNull(innerValue(), defValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
* Copyright 2011-2021 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;

import consulo.util.collection.ContainerUtil;
Expand Down Expand Up @@ -191,6 +190,7 @@ String getClassName() {
}

@Nonnull
@Override
public String render(@Nonnull Names names) {
if (renderClass) {
return String.format("%s.%s(%s, %s + 1)", className, methodName, names.builder, names.level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
*/
package org.intellij.grammar.psi;

import consulo.annotation.access.RequiredReadAction;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiNameIdentifierOwner;
import jakarta.annotation.Nonnull;

/**
* User: gregory
* Date: 13.07.11
* Time: 19:02
* @author gregory
* @since 2011-07-13
*/
public interface BnfNamedElement extends BnfComposite, PsiNameIdentifierOwner {
@Nonnull
@Override
@RequiredReadAction
String getName();

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
import java.util.regex.Pattern;

/**
* User: gregory
* Date: 13.07.11
* Time: 23:55
* @author gregory
* @since 2011-07-13
*/
public class BnfFileImpl extends PsiFileBase implements BnfFile {
private final CachedValue<Map<String, BnfRule>> myRules;
Expand Down Expand Up @@ -98,6 +97,7 @@ public BnfAttr findAttribute(
return PsiTreeUtil.getParentOfType(findElementAt(result.attrOffset), BnfAttr.class);
}

@Override
@RequiredReadAction
public <T> T findAttributeValue(
@Nullable String version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.intellij.grammar.psi.impl;

import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.access.RequiredWriteAction;
import consulo.document.util.TextRange;
import consulo.language.ast.ASTNode;
import consulo.language.psi.PsiElement;
Expand All @@ -28,28 +30,29 @@
import jakarta.annotation.Nullable;

/**
* Created by IntelliJ IDEA.
* User: gregory
* Date: 14.07.11
* Time: 19:17
* @author gregory
* @since 2011-07-14
*/
public abstract class BnfRefOrTokenImpl extends BnfExpressionImpl implements BnfReferenceOrToken {
public BnfRefOrTokenImpl(ASTNode node) {
super(node);
}

@Nullable
@Override
public BnfRule resolveRule() {
PsiFile file = getContainingFile();
return file instanceof BnfFile bnfFile ? bnfFile.getRule(GrammarUtil.getIdText(getId())) : null;
}

@Override
@RequiredReadAction
public PsiReference getReference() {
int delta = GrammarUtil.isIdQuoted(getId().getText()) ? 1 : 0;
TextRange range = TextRange.create(delta, getTextLength() - delta);
return new BnfReferenceImpl<BnfReferenceOrToken>(this, range) {
@Override
@RequiredWriteAction
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
myElement.getId().replace(BnfElementFactory.createLeafFromText(getElement().getProject(), newElementName));
return myElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.intellij.grammar.psi.impl;

import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.access.RequiredWriteAction;
import consulo.document.util.TextRange;
import consulo.language.ast.ASTNode;
import consulo.language.impl.psi.FakePsiElement;
Expand Down Expand Up @@ -90,6 +92,7 @@ public PsiElement getNumber() {
}

@Nonnull
@Override
public PsiReference[] getReferences() {
// performance: do not run injectors
// return PsiReferenceService.getService().getContributedReferences(this);
Expand All @@ -114,8 +117,9 @@ public boolean isValidHost() {
}

@Override
public BnfStringImpl updateText(@Nonnull final String text) {
final BnfExpression expression = BnfElementFactory.createExpressionFromText(getProject(), text);
@RequiredWriteAction
public BnfStringImpl updateText(@Nonnull String text) {
BnfExpression expression = BnfElementFactory.createExpressionFromText(getProject(), text);
assert expression instanceof BnfStringImpl : text + "-->" + expression;
return (BnfStringImpl)this.replace(expression);
}
Expand All @@ -127,6 +131,7 @@ public LiteralTextEscaper<? extends PsiLanguageInjectionHost> createLiteralTextE
}

@Nullable
@RequiredReadAction
private static Pattern getPattern(BnfLiteralExpression expression) {
return ParserGeneratorUtil.compilePattern(StringUtil.stripQuotesAroundValue(expression.getText()));
}
Expand All @@ -142,6 +147,7 @@ public TextRange getRangeInElement() {
}

@Override
@RequiredWriteAction
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
BnfStringImpl element = getElement();
PsiElement string = element.getString();
Expand Down Expand Up @@ -176,17 +182,19 @@ public boolean isReferenceTo(PsiElement element) {

@Nonnull
@Override
@RequiredReadAction
public ResolveResult[] multiResolve(boolean b) {
return ResolveCache.getInstance(getElement().getProject()).resolveWithCaching(this, RESOLVER, false, b);
}

@Nonnull
@RequiredReadAction
public ResolveResult[] multiResolveInner() {
final Pattern pattern = getPattern(getElement());
Pattern pattern = getPattern(getElement());
if (pattern == null) {
return ResolveResult.EMPTY_ARRAY;
}
final List<PsiElement> result = ContainerUtil.newArrayList();
List<PsiElement> result = new ArrayList<>();

BnfAttr thisAttr = ObjectUtil.assertNotNull(PsiTreeUtil.getParentOfType(getElement(), BnfAttr.class));
BnfAttrs thisAttrs = ObjectUtil.assertNotNull(PsiTreeUtil.getParentOfType(thisAttr, BnfAttrs.class));
Expand Down Expand Up @@ -249,18 +257,21 @@ public ResolveResult[] multiResolveInner() {
}

@Override
@RequiredWriteAction
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
// do not rename pattern
return myElement;
}

@Nonnull
@Override
@RequiredReadAction
public Object[] getVariants() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
}

@RequiredReadAction
public static boolean matchesElement(@Nullable BnfLiteralExpression e1, @Nonnull PsiElement e2) {
if (e1 == null) {
return false;
Expand All @@ -285,6 +296,7 @@ private static class MyFakePsiElement extends FakePsiElement implements BnfCompo
}

@Override
@RequiredReadAction
public String getName() {
return myFuncName;
}
Expand All @@ -296,6 +308,7 @@ public PsiElement getNavigationElement() {
}

@Override
@RequiredReadAction
public TextRange getTextRange() {
return myExpression.getTextRange();
}
Expand All @@ -311,7 +324,8 @@ public <R> R accept(@Nonnull BnfVisitor<R> visitor) {
}
}

public static TextRange getStringTokenRange(final BnfStringImpl element) {
@RequiredReadAction
public static TextRange getStringTokenRange(BnfStringImpl element) {
return TextRange.from(1, element.getTextLength() - 2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.intellij.grammar.impl.editor;

import consulo.annotation.component.ExtensionImpl;
Expand Down Expand Up @@ -61,21 +60,25 @@ public class BnfColorSettingsPage implements ColorSettingsPage {
}

@Nonnull
@Override
public LocalizeValue getDisplayName() {
return LocalizeValue.localizeTODO("IntelliJ Grammar");
}

@Nonnull
@Override
public AttributesDescriptor[] getAttributeDescriptors() {
return ATTRS;
}

@Nonnull
@Override
public SyntaxHighlighter getHighlighter() {
return new BnfSyntaxHighlighter();
}

@Nonnull
@Override
public String getDemoText() {
return "/*\n" +
" * Sample grammar\n" +
Expand All @@ -102,8 +105,9 @@ public String getDemoText() {
"\n";
}

@Override
public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMap() {
final Map<String, TextAttributesKey> map = new HashMap<>();
Map<String, TextAttributesKey> map = new HashMap<>();
map.put("r", RULE);
map.put("mr", META_RULE);
map.put("a", ATTRIBUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.intellij.grammar.impl.livePreview;

import consulo.annotation.access.RequiredReadAction;
import consulo.language.ast.ASTNode;
import consulo.language.parser.ParserDefinition;
import consulo.language.lexer.Lexer;
Expand Down Expand Up @@ -54,6 +54,7 @@ public LivePreviewParserDefinition(LivePreviewLanguage language) {
myFileElementType = new IFileElementType(myLanguage); // todo do not register
}

@Override
public LivePreviewLanguage getLanguage() {
return myLanguage;
}
Expand All @@ -65,6 +66,7 @@ public Lexer createLexer(LanguageVersion languageVersion) {
}

@Override
@RequiredReadAction
public PsiParser createParser(LanguageVersion languageVersion) {
return new LivePreviewParser(null, myLanguage);
}
Expand Down Expand Up @@ -94,6 +96,7 @@ public TokenSet getStringLiteralElements(LanguageVersion languageVersion) {

@Nonnull
@Override
@RequiredReadAction
public PsiElement createElement(ASTNode node) {
return new ASTWrapperPsiElement(node);
}
Expand Down
Loading
Loading