Package org.intellij.grammar.psi

Examples of org.intellij.grammar.psi.BnfRule


*/
public class BnfPinMarkerAnnotator implements Annotator, DumbAware {
  @Override
  public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (!(psiElement instanceof BnfRule)) return;
    BnfRule rule = (BnfRule) psiElement;
    final BnfFile bnfFile = (BnfFile)rule.getContainingFile();
    final ArrayList<Pair<BnfExpression, BnfAttr>> pinned = new ArrayList<Pair<BnfExpression, BnfAttr>>();
    GrammarUtil.processPinnedExpressions(rule, new PairProcessor<BnfExpression, ParserGeneratorUtil.PinMatcher>() {
      @Override
      public boolean process(BnfExpression bnfExpression, ParserGeneratorUtil.PinMatcher pinMatcher) {
        BnfAttr attr = bnfFile.findAttribute(pinMatcher.rule, KnownAttribute.PIN, pinMatcher.funcName);
View Full Code Here


  @Override
  public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement element : elements) {
      if (!(element instanceof BnfRule)) continue;
      BnfRule rule = (BnfRule)element;

      ProgressManager.checkCanceled();

      RuleGraphHelper helper = RuleGraphHelper.getCached((BnfFile)rule.getContainingFile());
      Map<PsiElement, RuleGraphHelper.Cardinality> map = helper.getFor(rule);
      if (map.containsKey(rule)) {
        result.add(new MyMarkerInfo(rule));
      }
    }
View Full Code Here

    for (PsiElement element : cardMap.keySet()) {
      RuleGraphHelper.Cardinality c = myExpressionHelper.fixCardinality(rule, element, cardMap.get(element));
      String pathName = getRuleOrTokenNameForPsi(element, c);
      if (pathName == null) continue;
      if (element instanceof BnfRule) {
        BnfRule resultType = (BnfRule)element;
        if (!ParserGeneratorUtil.Rule.isPrivate(rule)) {
          result.add(new MethodInfo(1, pathName, pathName, resultType, c)); // public rule
        }
      }
      else {
View Full Code Here

      else {
        result = null;
      }
    }
    else {
      BnfRule asRule = (BnfRule)tree;
      result = asRule.getName();
      if (StringUtil.isEmpty(getElementType(asRule))) return null;
    }
    return result;
  }
View Full Code Here

  @Override
  public void applyFix(final @NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final AccessToken token = WriteAction.start();
    try {
      final PsiElement element = descriptor.getPsiElement();
      final BnfRule rule = PsiTreeUtil.getParentOfType(element, BnfRule.class);
      if (rule == null) return;

      final BnfRule addedRule = BnfIntroduceRuleHandler.addNextRule(project, rule, "private " + myName + " ::= ");
      final FileEditor selectedEditor = FileEditorManager.getInstance(project).getSelectedEditor(rule.getContainingFile().getVirtualFile());
      if (selectedEditor instanceof TextEditor) {
        final Editor editor = ((TextEditor)selectedEditor).getEditor();
        editor.getCaretModel().moveToOffset(addedRule.getTextRange().getEndOffset() - (BnfIntroduceRuleHandler.endsWithSemicolon(addedRule)? 1 : 0));
        editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
      }
    }
    finally {
      token.finish();
View Full Code Here

      if (method != null && (!forNavigation || visited.add(method))) {
        items.add(method);
      }
      boolean hasPSI = false;
      if (isRuleId) {
        BnfRule rule = RuleGraphHelper.getSynonymTargetOrSelf((BnfRule)parent);
        if (RuleGraphHelper.shouldGeneratePsi(rule, true)) {
          hasPSI = true;
          JavaHelper javaHelper = JavaHelper.getJavaHelper(rule.getProject());
          for (String className : new String[]{ParserGeneratorUtil.getQualifiedRuleClassName(rule, false),
            ParserGeneratorUtil.getQualifiedRuleClassName(rule, true)}) {
            NavigatablePsiElement aClass = javaHelper.findClass(className);
            if (aClass != null && (!forNavigation || visited.add(aClass))) {
              items.add(aClass);
View Full Code Here

    }
  }

  @Nullable
  private static NavigatablePsiElement getMethod(PsiElement element) {
    BnfRule rule = PsiTreeUtil.getParentOfType(element, BnfRule.class);
    if (rule == null) return null;
    Project project = element.getProject();
    String parserClass = ParserGeneratorUtil.getAttribute(rule, KnownAttribute.PARSER_CLASS);
    if (StringUtil.isEmpty(parserClass)) return null;
    JavaHelper helper = JavaHelper.getJavaHelper(project);
View Full Code Here

  public void testComplexExternalMetaRule() throws Exception { doTest("meta inline ::= <<p>> (x <<p>>) *; external rule ::= inline <<inline y>>", "rule ::= y (x y) * (x y (x y) *) *"); }


  private void doTest(/*@Language("BNF")*/ String text, /*@Language("BNF")*/ String expected) {
    PsiFile file = myFixture.configureByText("a.bnf", text);
    BnfRule rule = PsiTreeUtil.getChildOfType(file, BnfRule.class);
    assertNotNull(rule);
    new BnfInlineRuleProcessor(rule, getProject(), null, false).run();
    assertSameLines(expected, file.getText());
  }
View Full Code Here

*/
public class BnfExpressionMarkerAnnotator implements Annotator {
  @Override
  public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (!(psiElement instanceof BnfRule)) return;
    BnfRule rule = (BnfRule) psiElement;
    // todo
    //boolean expression = ExpressionGeneratorHelper.getInfoForExpressionParsing(ExpressionHelper.getCached((BnfFile)rule.getContainingFile()), rule) != null;
    //if (expression) {
    //  annotationHolder.createInfoAnnotation(rule.getNameIdentifier(), null).setTextAttributes(key);
    //}
View Full Code Here

    return new PsiReference[] {
      new PsiPolyVariantReferenceBase<BnfListEntry>(o, TextRange.from(id.getStartOffsetInParent(), id.getTextLength())) {

        private List<NavigatablePsiElement> getTargetMethods(String methodName) {
          BnfRule rule = PsiTreeUtil.getParentOfType(getElement(), BnfRule.class);
          String mixinClass = ParserGeneratorUtil.getAttribute(rule, KnownAttribute.MIXIN);
          String ruleClass = rule == null ? null : ParserGeneratorUtil.getQualifiedRuleClassName(rule, false);
          List<NavigatablePsiElement> implMethods = javaHelper.findClassMethods(psiImplUtilClass, true, methodName, -1, ruleClass);
          List<NavigatablePsiElement> mixinMethods = javaHelper.findClassMethods(mixinClass, false, methodName, -1);
          return ContainerUtil.concat(mixinMethods, implMethods);
View Full Code Here

TOP

Related Classes of org.intellij.grammar.psi.BnfRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.