當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。