Package org.intellij.grammar.java

Examples of org.intellij.grammar.java.JavaHelper


  }

  public static void checkClassAvailability(@NotNull Project project, @Nullable String className, @Nullable String description) {
    if (StringUtil.isEmpty(className)) return;

    JavaHelper javaHelper = JavaHelper.getJavaHelper(project);
    if (javaHelper.findClass(className) == null) {
      String tail = StringUtil.isEmpty(description) ? "" : " (" + description + ")";
      addWarning(project, "class not found: " + className + tail);
    }
  }
View Full Code Here


    Set<String> imports = ContainerUtil.newLinkedHashSet();
    imports.addAll(Arrays.asList("java.util.List",
                                 "org.jetbrains.annotations.*",
                                 BnfConstants.PSI_ELEMENT_CLASS));
    imports.addAll(psiSupers);
    JavaHelper javaHelper = JavaHelper.getJavaHelper(myFile.getProject());
    imports.addAll(getRuleMethodTypesToImport(rule, psiClass, psiImplUtilClass, javaHelper));

    generateClassHeader(psiClass, imports, "", true, ArrayUtil.toStringArray(psiSupers));
    generatePsiClassMethods(rule, psiClass, psiImplUtilClass, javaHelper, true);
    out("}");
View Full Code Here

    imports.add(BnfConstants.PSI_TREE_UTIL_CLASS);
    imports.add("static " + typeHolderClass + ".*");
    if (StringUtil.isNotEmpty(implSuper)) imports.add(implSuper);
    imports.add(StringUtil.getPackageName(superInterface) + ".*");
    if (StringUtil.isNotEmpty(psiImplUtilClass)) imports.add(psiImplUtilClass);
    JavaHelper javaHelper = JavaHelper.getJavaHelper(myFile.getProject());
    imports.addAll(getRuleMethodTypesToImport(rule, superInterface, psiImplUtilClass, javaHelper));

    String stubName = StringUtil.isNotEmpty(stubClass)? stubClass :
                      implSuper.indexOf("<") < implSuper.indexOf(">") &&
                      !javaHelper.findClassMethods(implSuper.substring(0, implSuper.indexOf("<")), false, "StubBasedPsiElementBase", 2).isEmpty()
                      ? implSuper.substring(implSuper.indexOf("<") + 1, implSuper.indexOf(">")) : null;
    if (stubName != null) imports.add(BnfConstants.ISTUBELEMENTTYPE_CLASS);

    generateClassHeader(psiClass, imports, "", false, implSuper, superInterface);
    String shortName = StringUtil.getShortName(psiClass);
View Full Code Here

      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

    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);
    List<NavigatablePsiElement> methods = helper.findClassMethods(parserClass, true, GrammarUtil.getMethodName(rule, element), -1);
    return ContainerUtil.getFirstItem(methods);
  }
View Full Code Here

    if (attr == null || !Comparing.equal(KnownAttribute.METHODS.getName(), attr.getName())) return PsiReference.EMPTY_ARRAY;
    PsiElement id = o.getId();
    BnfLiteralExpression value = o.getLiteralExpression();
    if (id == null || value != null) return PsiReference.EMPTY_ARRAY;
    final String psiImplUtilClass = getRootAttribute(attr, KnownAttribute.PSI_IMPL_UTIL_CLASS);
    final JavaHelper javaHelper = JavaHelper.getJavaHelper(o.getProject());

    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);
        }

        @NotNull
        @Override
View Full Code Here

        KnownAttribute attribute = KnownAttribute.getCompatibleAttribute(attrName);
        if (attribute != null) {
          String value = (String)ParserGeneratorUtil.getAttributeValue((BnfExpression)psiElement);
          Object resolve;
          String refType = "";
          JavaHelper javaHelper = JavaHelper.getJavaHelper(psiElement.getProject());
          if (attribute.getName().endsWith("Class") || attribute == KnownAttribute.MIXIN) {
            resolve = checkJavaResolve(value, javaHelper);
            refType = "class ";
          }
          else if (attribute.getName().endsWith("Package")) {
            resolve = javaHelper.findPackage(value);
            refType = "package ";
          }
          else if (attribute.getName().endsWith("Factory")) {
            resolve = Boolean.TRUE; // todo
          }
View Full Code Here

      int paramCount = parent instanceof BnfSequence ? ((BnfSequence)parent).getExpressionList().size() - 1 :
        parent instanceof BnfExternalExpression? ((BnfExternalExpression)parent).getExpressionList().size() - 1 : 0;
      BnfRule rule = PsiTreeUtil.getParentOfType(myElement, BnfRule.class);
      String parserClass = ParserGeneratorUtil.getAttribute(rule, KnownAttribute.PARSER_UTIL_CLASS);
      // paramCount + 2 (builder and level)
      JavaHelper helper = JavaHelper.getJavaHelper(myElement.getProject());
      List<NavigatablePsiElement> methods = helper.findClassMethods(parserClass, true, myElement.getText(), paramCount + 2);
      result = ContainerUtil.getFirstItem(methods);
    }
    return result;
  }
View Full Code Here

    }
    if (GrammarUtil.isExternalReference(myElement)) {
      BnfRule rule = PsiTreeUtil.getParentOfType(myElement, BnfRule.class);
      String parserClass = ParserGeneratorUtil.getAttribute(rule, KnownAttribute.PARSER_UTIL_CLASS);
      if (StringUtil.isNotEmpty(parserClass)) {
        JavaHelper javaHelper = JavaHelper.getJavaHelper(myElement.getProject());
        for (NavigatablePsiElement element : javaHelper.findClassMethods(parserClass, true, "*", -1, "*", "*")) {
          List<String> methodTypes = javaHelper.getMethodTypes(element);
          if (methodTypes.size() > 3 &&
              methodTypes.get(0).equals("boolean") &&
              methodTypes.get(1).equals("com.intellij.lang.PsiBuilder") &&
              methodTypes.get(3).equals("int")) {
            list.add(LookupElementBuilder.createWithIcon((PsiNamedElement)element));
View Full Code Here

TOP

Related Classes of org.intellij.grammar.java.JavaHelper

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.