当前位置: 首页>>代码示例>>Java>>正文


Java ParserDefinition类代码示例

本文整理汇总了Java中com.intellij.lang.ParserDefinition的典型用法代码示例。如果您正苦于以下问题:Java ParserDefinition类的具体用法?Java ParserDefinition怎么用?Java ParserDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParserDefinition类属于com.intellij.lang包,在下文中一共展示了ParserDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFile

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
@Override
protected PsiFile createFile(@NotNull Language lang) {
  ParserDefinition parserDefinition = getDefinition(lang);
  if (parserDefinition == null) {
    return null;
  }

  if (lang.is(templateDataLanguage)) {
    PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
    file.setContentElementType(templateDataLanguageType);
    return file;
  } else if (lang.isKindOf(baseLanguage)) {
    return parserDefinition.createFile(this);
  } else {
    return null;
  }
}
 
开发者ID:google,项目名称:bamboo-soy,代码行数:18,代码来源:SoyFileViewProvider.java

示例2: createFile

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
@Override
protected PsiFile createFile(@NotNull Language lang) {
    ParserDefinition parserDefinition = getDefinition(lang);
    if (parserDefinition == null) {
        return null;
    }
    if (lang.is(getTemplateDataLanguage())) {
        PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
        file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
        return file;
    } else if (lang.isKindOf(getBaseLanguage())) {
        return parserDefinition.createFile(this);
    } else {
        return null;
    }
}
 
开发者ID:scireum-incubator,项目名称:rythm_plugin,代码行数:17,代码来源:RythmFileViewProvider.java

示例3: acceptInput

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
@Override
public boolean acceptInput(@NotNull final VirtualFile file) {
  if (!file.isInLocalFileSystem()) {
    return false; // do not index TODOs in library sources
  }

  final FileType fileType = file.getFileType();

  if (fileType instanceof LanguageFileType) {
    final Language lang = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
    final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
    return commentTokens != null;
  }

  return PlatformIdTableBuilding.isTodoIndexerRegistered(fileType) ||
         fileType instanceof CustomSyntaxTableFileType;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TodoIndex.java

示例4: isMinified

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
/**
 * Finds out whether the file minified by using common (not language-specific) heuristics.
 * Can be used for checking of css/less/scss/sass and js files.
 *
 * @param fileContent              target file content
 * @param parserDefinition         Parser definition of target language
 * @param noWSRequireAfterTokenSet TokenSet of types that doesn't require whitespaces after them.
 */
public static boolean isMinified(@NotNull CharSequence fileContent,
                                 @NotNull ParserDefinition parserDefinition,
                                 @NotNull TokenSet noWSRequireAfterTokenSet) {
  Lexer lexer = parserDefinition.createLexer(null);
  lexer.start(fileContent);
  if (!isMinified(lexer, parserDefinition, noWSRequireAfterTokenSet)) {
    return false;
  }
  else if (lexer.getTokenType() == null) {
    // whole file had been considered
    return true;
  }

  int startOffset = fileContent.length() - COUNT_OF_CONSIDERING_CHARACTERS_FROM_END_OF_FILE;
  if (startOffset <= 0) {
    return true;
  }
  lexer.start(fileContent, startOffset, fileContent.length());
  return isMinified(lexer, parserDefinition, noWSRequireAfterTokenSet);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:MinifiedFilesUtil.java

示例5: canHaveStub

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
@Override
public boolean canHaveStub(VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    Language l = ((LanguageFileType)fileType).getLanguage();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) return false;
    final IFileElementType elementType = parserDefinition.getFileNodeType();
    return elementType instanceof IStubFileElementType && ((IStubFileElementType)elementType).shouldBuildStubFor(file);
  }
  else if (fileType.isBinary()) {
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:CoreStubTreeLoader.java

示例6: getCumulativeVersion

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
public static int getCumulativeVersion() {
  int version = VERSION;
  for (final FileType fileType : FileTypeRegistry.getInstance().getRegisteredFileTypes()) {
    if (fileType instanceof LanguageFileType) {
      Language l = ((LanguageFileType)fileType).getLanguage();
      ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
      if (parserDefinition != null) {
        final IFileElementType type = parserDefinition.getFileNodeType();
        if (type instanceof IStubFileElementType) {
          version += ((IStubFileElementType)type).getStubVersion();
        }
      }
    }

    BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
      version += builder.getStubVersion();
    }
  }
  return version;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CumulativeStubVersion.java

示例7: isComment

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
private boolean isComment(int offset) {
  final HighlighterIterator it = myEditor.getHighlighter().createIterator(offset);
  IElementType tokenType = it.getTokenType();
  Language language = tokenType.getLanguage();
  TokenSet comments = myComments.get(language);
  if (comments == null) {
    ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (definition != null) {
      comments = definition.getCommentTokens();
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:IndentsPass.java

示例8: canHaveStub

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
public static boolean canHaveStub(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      if (IndexingStamp.isFileIndexedStateCurrent(file, INDEX_ID)) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:StubUpdatingIndex.java

示例9: processStringLiteralsContainingIdentifier

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
private static boolean processStringLiteralsContainingIdentifier(@NotNull String identifier, @NotNull SearchScope searchScope, PsiSearchHelper helper, final Processor<PsiElement> processor) {
  TextOccurenceProcessor occurenceProcessor = new TextOccurenceProcessor() {
    @Override
    public boolean execute(@NotNull PsiElement element, int offsetInElement) {
      final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
      final ASTNode node = element.getNode();
      if (definition != null && node != null && definition.getStringLiteralElements().contains(node.getElementType())) {
        return processor.process(element);
      }
      return true;
    }
  };

  return helper.processElementsWithWord(occurenceProcessor,
                                 searchScope,
                                 identifier,
                                 UsageSearchContext.IN_STRINGS,
                                 true);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:TextOccurrencesUtil.java

示例10: registerProblemStart

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
private static void registerProblemStart(@NotNull final AnnotationHolder holder,
                                    @NotNull final XmlTag tag,
                                    @NotNull final XmlToken start,
                                    @NotNull final XmlToken end) {
  PsiElement context = tag.getContainingFile().getContext();
  if (context != null) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    if (parserDefinition != null) {
      ASTNode contextNode = context.getNode();
      if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) {
        // TODO: we should check for concatenations here
        return;
      }
    }
  }
  final String tagName = tag.getName();
  final String endTokenText = end.getText();

  final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false);
  final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true);

  final Annotation annotation = holder.createErrorAnnotation(start, XmlErrorMessages.message("tag.has.wrong.closing.tag.name"));
  annotation.registerFix(renameEndAction);
  annotation.registerFix(renameStartAction);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:XmlWrongClosingTagNameInspection.java

示例11: registerProblemEnd

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
private static void registerProblemEnd(@NotNull final AnnotationHolder holder,
                                       @NotNull final XmlTag tag,
                                       @NotNull final XmlToken end) {
  PsiElement context = tag.getContainingFile().getContext();
  if (context != null) {
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    if (parserDefinition != null) {
      ASTNode contextNode = context.getNode();
      if (contextNode != null && contextNode.getChildren(parserDefinition.getStringLiteralElements()) != null) {
        // TODO: we should check for concatenations here
        return;
      }
    }
  }
  final String tagName = tag.getName();
  final String endTokenText = end.getText();

  final RenameTagBeginOrEndIntentionAction renameEndAction = new RenameTagBeginOrEndIntentionAction(tagName, endTokenText, false);
  final RenameTagBeginOrEndIntentionAction renameStartAction = new RenameTagBeginOrEndIntentionAction(endTokenText, tagName, true);

  final Annotation annotation = holder.createErrorAnnotation(end, XmlErrorMessages.message("wrong.closing.tag.name"));
  annotation.registerFix(new RemoveExtraClosingTagIntentionAction());
  annotation.registerFix(renameEndAction);
  annotation.registerFix(renameStartAction);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:XmlWrongClosingTagNameInspection.java

示例12: createAST

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
private ASTNode createAST(String text) {
  ParserDefinition definition = new BuildParserDefinition();
  PsiParser parser = definition.createParser(getProject());
  Lexer lexer = definition.createLexer(getProject());
  PsiBuilderImpl psiBuilder =
      new PsiBuilderImpl(
          getProject(), null, definition, lexer, new CharTableImpl(), text, null, null);
  PsiBuilderAdapter adapter =
      new PsiBuilderAdapter(psiBuilder) {
        @Override
        public void error(String messageText) {
          super.error(messageText);
          errors.add(messageText);
        }
      };
  return parser.parse(definition.getFileNodeType(), adapter);
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:18,代码来源:BuildParserTest.java

示例13: createLanguageBindings

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
/**
 * Creates the IDEA language object associated with the specified language.
 *
 * @param language
 *            The language.
 * @return The created IDEA language.
 */
private LanguageBindings createLanguageBindings(final ILanguage language) {
    final MetaborgIdeaLanguage ideaLanguage = createIdeaLanguage(language);
    final MetaborgLanguageFileType fileType = createFileType(ideaLanguage);
    final SpoofaxTokenTypeManager tokenTypeManager = createTokenTypeManager(ideaLanguage);
    final IFileElementType fileElementType = createFileElementType(ideaLanguage, tokenTypeManager);
    final ParserDefinition parserDefinition = createParserDefinition(fileType, fileElementType);
    final SpoofaxSyntaxHighlighterFactory syntaxHighlighterFactory = createSyntaxHighlighterFactory();

    final InstanceLanguageExtensionPoint<?> parserDefinitionExtension =
        new InstanceLanguageExtensionPoint<>(ExtensionIds.ParserDefinition, ideaLanguage, parserDefinition);
    final InstanceSyntaxHighlighterFactoryExtensionPoint syntaxHighlighterFactoryExtension =
        new InstanceSyntaxHighlighterFactoryExtensionPoint(ideaLanguage, syntaxHighlighterFactory);
    final InstanceLanguageExtensionPoint<?> externalAnnotatorExtension = new InstanceLanguageExtensionPoint<>(
        ExtensionIds.ExternalAnnotator, ideaLanguage, this.metaborgSourceAnnotator);

    return new LanguageBindings(tokenTypeManager, fileType, parserDefinitionExtension,
        syntaxHighlighterFactoryExtension, externalAnnotatorExtension);
}
 
开发者ID:metaborg,项目名称:spoofax-intellij,代码行数:26,代码来源:DefaultIdeaLanguageManager.java

示例14: isInsideStringLiteral

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
private static boolean isInsideStringLiteral(final Editor editor, final PsiFile file) {
  int offset = editor.getCaretModel().getOffset();
  PsiElement element = file.findElementAt(offset);
  if (element == null) return false;
  final ParserDefinition definition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
  if (definition != null) {
    final TokenSet stringLiteralElements = definition.getStringLiteralElements();
    final ASTNode node = element.getNode();
    if (node == null) return false;
    final IElementType elementType = node.getElementType();
    if (stringLiteralElements.contains(elementType)) {
      return true;
    }
    PsiElement parent = element.getParent();
    if (parent != null) {
      ASTNode parentNode = parent.getNode();
      if (parentNode != null && stringLiteralElements.contains(parentNode.getElementType())) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:TypedHandler.java

示例15: canHaveStub

import com.intellij.lang.ParserDefinition; //导入依赖的package包/类
public static boolean canHaveStub(@NotNull VirtualFile file) {
  final FileType fileType = file.getFileType();
  if (fileType instanceof LanguageFileType) {
    final Language l = ((LanguageFileType)fileType).getLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
    if (parserDefinition == null) {
      return false;
    }

    final IFileElementType elementType = parserDefinition.getFileNodeType();
    if (elementType instanceof IStubFileElementType) {
      if (((IStubFileElementType)elementType).shouldBuildStubFor(file)) {
        return true;
      }
      final ID indexId = IndexInfrastructure.getStubId(INDEX_ID, file.getFileType());
      if (IndexingStamp.isFileIndexed(file, indexId, IndexInfrastructure.getIndexCreationStamp(indexId))) {
        return true;
      }
    }
  }
  final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
  return builder != null && builder.acceptsFile(file);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:StubUpdatingIndex.java


注:本文中的com.intellij.lang.ParserDefinition类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。