@Override
 protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) {
   Project project = psi.getProject();
   Language languageForParser = getLanguageForParser(psi);
   PsiBuilder builder =
       PsiBuilderFactory.getInstance()
           .createBuilder(project, chameleon, null, languageForParser, chameleon.getChars());
   return JetParser.parseExpressionCodeFragment(builder).getFirstChildNode();
 }
Ejemplo n.º 2
0
  private void doSingleTest(String suffix, String path) throws Throwable {
    final String text = FileUtil.loadFile(new File(path, suffix), true);
    final StringBuilder result = new StringBuilder();
    for (String line : StringUtil.splitByLines(text)) {
      if (result.length() > 0) result.append("------\n");
      final AngularJSParserDefinition definition = new AngularJSParserDefinition();
      final PsiBuilder builder =
          PsiBuilderFactory.getInstance().createBuilder(definition, new AngularJSLexer(), line);
      final ASTNode root =
          definition.createParser(getProject()).parse(JSStubElementTypes.FILE, builder);
      result.append(DebugUtil.psiToString(root.getPsi(), false, false));
    }

    assertEquals(
        FileUtil.loadFile(new File(path, suffix.replace("js", "txt")), true), result.toString());
  }
 @NotNull
 @Override
 public PsiElement createDummyHolder(
     @NotNull final String text,
     @NotNull final IElementType type,
     @Nullable final PsiElement context) {
   final DummyHolder result = DummyHolderFactory.createHolder(myManager, context);
   final FileElement holder = result.getTreeElement();
   final Language language = type.getLanguage();
   final ParserDefinition parserDefinition =
       LanguageParserDefinitions.INSTANCE.forLanguage(language);
   assert parserDefinition != null : "No parser definition for language " + language;
   final Project project = myManager.getProject();
   final Lexer lexer = parserDefinition.createLexer(project);
   final PsiBuilder builder =
       PsiBuilderFactory.getInstance().createBuilder(project, holder, lexer, language, text);
   final ASTNode node = parserDefinition.createParser(project).parse(type, builder);
   holder.rawAddChildren((TreeElement) node);
   final PsiElement psi = node.getPsi();
   assert psi != null : text;
   return psi;
 }