コード例 #1
0
 private static boolean isBrace(@NotNull PsiElement candidate) {
   final ASTNode node = candidate.getNode();
   if (node != null && node.getFirstChildNode() == null) {
     final PairedBraceMatcher braceMatcher =
         LanguageBraceMatching.INSTANCE.forLanguage(candidate.getLanguage());
     if (braceMatcher != null) {
       final IElementType elementType = node.getElementType();
       for (BracePair pair : braceMatcher.getPairs()) {
         if (elementType == pair.getLeftBraceType() || elementType == pair.getRightBraceType()) {
           return true;
         }
       }
     }
   }
   return false;
 }
コード例 #2
0
 @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;
 }