Java Code Examples for com.intellij.psi.tree.IElementType#getLanguage()

The following examples show how to use com.intellij.psi.tree.IElementType#getLanguage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
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);
}
 
Example 2
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);
}
 
Example 3
Source Project: consulo   File: CacheUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean isInComments(final IElementType tokenType, LanguageVersion languageVersion) {
  final Language language = tokenType.getLanguage();

  //for (CommentTokenSetProvider provider : CommentTokenSetProvider.EXTENSION.allForLanguage(language)) {
  //  if (provider.isInComments(tokenType)) {
  //    return true;
  //  }
  //}

  boolean inComments = false;
  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);

  if (parserDefinition != null) {
    final TokenSet commentTokens = parserDefinition.getCommentTokens(languageVersion);

    if (commentTokens.contains(tokenType)) {
      inComments = true;
    }
  }
  return inComments;
}
 
Example 4
Source Project: consulo   File: CommentUtilCore.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean isCommentToken(@Nonnull IElementType tokenType, @Nonnull LanguageVersion languageVersion) {
  final Language language = tokenType.getLanguage();
  if(language != languageVersion.getLanguage()) {
    return false;
  }

  final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);

  if (parserDefinition != null) {
    final TokenSet commentTokens = parserDefinition.getCommentTokens(languageVersion);

    if (commentTokens.contains(tokenType)) {
      return true;
    }
  }
  return false;
}
 
Example 5
Source Project: consulo   File: IndentsPass.java    License: Apache License 2.0 6 votes vote down vote up
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(LanguageVersionUtil.findLanguageVersion(language, myFile));
    }
    if (comments == null) {
      return false;
    }
    else {
      myComments.put(language, comments);
    }
  }
  return comments.contains(tokenType);
}
 
Example 6
Source Project: intellij-latte   File: GeneratedParserUtilBase.java    License: MIT License 5 votes vote down vote up
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
	state.extendsSets = extendsSets;
	PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
	state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
	Language language = file == null? root.getLanguage() : file.getLanguage();
	state.caseSensitive = language.isCaseSensitive();
	PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
	state.braces = matcher == null ? null : matcher.getPairs();
	if (state.braces != null && state.braces.length == 0) state.braces = null;
}
 
Example 7
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
    state.extendsSets = extendsSets;
    PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
    state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
    Language language = file == null? root.getLanguage() : file.getLanguage();
    state.caseSensitive = language.isCaseSensitive();
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
    state.braces = matcher == null ? null : matcher.getPairs();
    if (state.braces != null && state.braces.length == 0) state.braces = null;
}
 
Example 8
Source Project: consulo   File: PlatformIdTableBuilding.java    License: Apache License 2.0 5 votes vote down vote up
private boolean isCommentToken(Map<Language, LanguageVersion> cache, IElementType token) {
  Language language = token.getLanguage();
  LanguageVersion languageVersion = cache.get(language);
  if (languageVersion == null) {
    cache.put(language, languageVersion = LanguageVersionUtil.findLanguageVersion(language, myProject, myFile));
  }
  return CommentUtilCore.isCommentToken(token, languageVersion);
}
 
Example 9
Source Project: consulo   File: LineLayout.java    License: Apache License 2.0 5 votes vote down vote up
private static boolean distinctTokens(@Nullable IElementType token1, @Nullable IElementType token2) {
  if (token1 == token2) return false;
  if (token1 == null || token2 == null) return true;
  if (StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(token1) || StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(token2)) return false;
  if (token1 != TokenType.WHITE_SPACE && token2 != TokenType.WHITE_SPACE && !token1.getLanguage().is(token2.getLanguage())) return true;
  Language language = token1.getLanguage();
  if (language == Language.ANY) language = token2.getLanguage();
  BidiRegionsSeparator separator = LanguageBidiRegionsSeparator.INSTANCE.forLanguage(language);
  return separator.createBorderBetweenTokens(token1, token2);
}
 
Example 10
Source Project: consulo   File: GeneratedParserUtilBase.java    License: Apache License 2.0 5 votes vote down vote up
public static void initState(ErrorState state, PsiBuilder builder, IElementType root, TokenSet[] extendsSets) {
  state.extendsSets = extendsSets;
  PsiFile file = builder.getUserData(FileContextUtil.CONTAINING_FILE_KEY);
  state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
  Language language = file == null? root.getLanguage() : file.getLanguage();
  state.caseSensitive = language.isCaseSensitive();
  PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
  state.braces = matcher == null ? null : matcher.getPairs();
  if (state.braces != null && state.braces.length == 0) state.braces = null;
}
 
Example 11
Source Project: Intellij-Dust   File: GeneratedParserUtilBase.java    License: MIT License 5 votes vote down vote up
private static void initState(IElementType root, PsiBuilder builder, ErrorState state) {
    PsiFile file = builder.getUserDataUnprotected(FileContextUtil.CONTAINING_FILE_KEY);
    state.completionState = file == null? null: file.getUserData(COMPLETION_STATE_KEY);
    Language language = file == null? root.getLanguage() : file.getLanguage();
    state.caseSensitive = language.isCaseSensitive();
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (parserDefinition != null) {
        state.commentTokens = parserDefinition.getCommentTokens();
        state.whitespaceTokens = parserDefinition.getWhitespaceTokens();
    }
    PairedBraceMatcher matcher = LanguageBraceMatching.INSTANCE.forLanguage(language);
    state.braces = matcher == null ? null : matcher.getPairs();
    if (state.braces != null && state.braces.length == 0) state.braces = null;
}
 
Example 12
Source Project: consulo   File: TokenWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public TokenWrapper(IElementType delegate, CharSequence value) {
  super("Wrapper", delegate.getLanguage(), false);
  myDelegate = delegate;
  myValue = value;
}
 
Example 13
Source Project: consulo   File: CodeBlockUtil.java    License: Apache License 2.0 4 votes vote down vote up
private static Language getBraceType(HighlighterIterator iterator) {
  final IElementType type = iterator.getTokenType();
  return type.getLanguage();
}