Java Code Examples for com.intellij.lang.Language#ANY

The following examples show how to use com.intellij.lang.Language#ANY . These examples are extracted from open source projects. 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
Source Project: consulo   File: IElementType.java    License: Apache License 2.0 6 votes vote down vote up
protected IElementType(@Nonnull @NonNls String debugName, @Nullable Language language, boolean register) {
  myDebugName = debugName;
  myLanguage = language == null ? Language.ANY : language;
  if (register) {
    synchronized (lock) {
      myIndex = size++;
      LOG.assertTrue(myIndex < MAX_INDEXED_TYPES, "Too many element types registered. Out of (short) range.");
      IElementType[] newRegistry = myIndex >= ourRegistry.length ? ArrayUtil.realloc(ourRegistry, ourRegistry.length * 3 / 2 + 1, ARRAY_FACTORY) : ourRegistry;
      newRegistry[myIndex] = this;
      ourRegistry = newRegistry;
    }
  }
  else {
    myIndex = -1;
  }
}
 
Example 2
Source Project: nosql4idea   File: QueryPanel.java    License: Apache License 2.0 5 votes vote down vote up
private EditorHighlighter createHighlighter(EditorColorsScheme settings) {
    Language language = Language.findLanguageByID("JSON");
    if (language == null) {
        language = Language.ANY;
    }
    return new LexerEditorHighlighter(PlainTextSyntaxHighlighterFactory.getSyntaxHighlighter(language, null, null), settings);
}
 
Example 3
Source Project: consulo   File: TokenSetTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
  T1 = new IElementType("T1", Language.ANY);
  T2 = new IElementType("T2", Language.ANY);
  fakeElements(1, 128);
  T3 = new IElementType("T3", Language.ANY);
  T4 = new IElementType("T4", Language.ANY);
  fakeElements(201, 204);
  T5 = new IElementType("T5", Language.ANY);
  T6 = new IElementType("T6", Language.ANY);
}
 
Example 4
@Nonnull
@Override
protected Collection<Language> getAllFilterValues() {
  final Collection<Language> registeredLanguages = Language.getRegisteredLanguages();
  List<Language> accepted = new ArrayList<Language>();
  for (Language language : registeredLanguages) {
    if (language != Language.ANY && !(language instanceof DependentLanguage)) {
      accepted.add(language);
    }
  }
  Collections.sort(accepted, LanguageUtil.LANGUAGE_COMPARATOR);
  return accepted;
}
 
Example 5
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 6
/**
 * Get common code style settings by language name. {@code getCommonSettings(Language)} is a preferred method but
 * sometimes (for example, in plug-ins which do not depend on a specific language support) language settings can be
 * obtained by name.
 *
 * @param langName The display name of the language whose settings must be returned.
 * @return Common code style settings for the given language or a new instance with default values if not found.
 */
@Nonnull
public CommonCodeStyleSettings getCommonSettings(@Nonnull String langName) {
  Map<Language, CommonCodeStyleSettings> map = getCommonSettingsMap();
  for (Map.Entry<Language, CommonCodeStyleSettings> entry : map.entrySet()) {
    if (langName.equals(entry.getKey().getDisplayName())) {
      return entry.getValue();
    }
  }
  return new CommonCodeStyleSettings(Language.ANY);
}
 
Example 7
private static Language calcBaseLanguage(@Nonnull VirtualFile file, @Nonnull Project project, @Nonnull final FileType fileType) {
  if (fileType.isBinary()) return Language.ANY;
  if (isTooLargeForIntelligence(file)) return PlainTextLanguage.INSTANCE;

  Language language = LanguageUtil.getLanguageForPsi(project, file);

  return language != null ? language : PlainTextLanguage.INSTANCE;
}
 
Example 8
Source Project: consulo   File: ScratchFileServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable
public static Language substituteLanguage(@Nonnull Project project, @Nonnull VirtualFile file) {
  RootType rootType = ScratchFileService.getInstance().getRootType(file);
  if (rootType == null) return null;
  Language language = rootType.substituteLanguage(project, file);
  Language adjusted = language != null ? language : getLanguageByFileName(file);
  Language result = adjusted != null && adjusted != PlainTextLanguage.INSTANCE ? LanguageSubstitutors.INSTANCE.substituteLanguage(adjusted, file, project) : adjusted;
  return result == Language.ANY ? null : result;
}
 
Example 9
Source Project: consulo   File: PomTargetPsiElementImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Language getLanguage() {
  if (myTarget instanceof PsiTarget) {
    return ((PsiTarget)myTarget).getNavigationElement().getLanguage();
  }
  return Language.ANY;
}
 
Example 10
Source Project: consulo-unity3d   File: UnitySceneFile.java    License: Apache License 2.0 4 votes vote down vote up
public UnitySceneFile(Project project, VirtualFile virtualFile)
{
	super(PsiManager.getInstance(project), Language.ANY);
	myVirtualFile = virtualFile;
}
 
Example 11
Source Project: consulo   File: TokenSetTest.java    License: Apache License 2.0 4 votes vote down vote up
private static void fakeElements(int from, int to) {
  for (int i = from; i <= to; i++) {
    new IElementType("Test element #" + i, Language.ANY);
  }
}
 
Example 12
Source Project: consulo   File: MockLanguageFileType.java    License: Apache License 2.0 4 votes vote down vote up
private MockLanguageFileType() {
  super(Language.ANY);
}
 
Example 13
Source Project: consulo   File: PsiWhiteSpaceImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public Language getLanguage() {
  final PsiElement master = getParent();
  return master != null ?  master.getLanguage() : Language.ANY;
}
 
Example 14
Source Project: consulo   File: FakePsiElement.java    License: Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
@Nonnull
public Language getLanguage() {
  return Language.ANY;
}
 
Example 15
Source Project: consulo   File: PsiBinaryFileImpl.java    License: Apache License 2.0 4 votes vote down vote up
@RequiredReadAction
@Override
@Nonnull
public Language getLanguage() {
  return Language.ANY;
}
 
Example 16
Source Project: consulo   File: PsiDirectoryImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public Language getLanguage() {
  return Language.ANY;
}
 
Example 17
Source Project: consulo   File: SyntheticFileSystemItem.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public Language getLanguage() {
  return Language.ANY;
}
 
Example 18
Source Project: consulo   File: ScopeTokenType.java    License: Apache License 2.0 4 votes vote down vote up
public ScopeTokenType(@Nonnull @NonNls final String debugName) {
  super(debugName, Language.ANY);
}
 
Example 19
private int getStatementStartOffset(@Nonnull SemanticEditorPosition position, boolean ignoreLabels) {
  Language currLanguage = position.getLanguage();
  while (!position.isAtEnd()) {
    if (currLanguage == Language.ANY || currLanguage == null) currLanguage = position.getLanguage();
    if (!ignoreLabels && isColonAfterLabelOrCase(position)) {
      SemanticEditorPosition afterColon = getPosition(position.getEditor(), position.getStartOffset()).afterOptionalMix(Whitespace, BlockComment).after().afterOptionalMix(Whitespace, LineComment);
      return afterColon.getStartOffset();
    }
    else if (position.isAt(RightParenthesis)) {
      position.moveBeforeParentheses(LeftParenthesis, RightParenthesis);
      continue;
    }
    else if (position.isAt(BlockClosingBrace)) {
      position.moveBeforeParentheses(BlockOpeningBrace, BlockClosingBrace);
      continue;
    }
    else if (position.isAt(ArrayClosingBracket)) {
      position.moveBeforeParentheses(ArrayOpeningBracket, ArrayClosingBracket);
      continue;
    }
    else if (isStartOfStatementWithOptionalBlock(position)) {
      return position.getStartOffset();
    }
    else if (position.isAtAnyOf(Semicolon, BlockOpeningBrace, BlockComment, DocBlockEnd, LeftParenthesis, LanguageStartDelimiter) ||
             (position.getLanguage() != Language.ANY) && !position.isAtLanguage(currLanguage)) {
      SemanticEditorPosition statementStart = position.copy();
      statementStart = statementStart.after().afterOptionalMix(Whitespace, LineComment);
      if (!isIndentProvider(statementStart, ignoreLabels)) {
        final SemanticEditorPosition maybeColon = statementStart.afterOptionalMix(Whitespace, BlockComment).after();
        final SemanticEditorPosition afterColonStatement = maybeColon.after().after();
        if (atColonWithNewLineAfterColonStatement(maybeColon, afterColonStatement)) {
          return afterColonStatement.getStartOffset();
        }
        if (atBlockStartAndNeedBlockIndent(position)) {
          return position.getStartOffset();
        }
      }
      else if (!statementStart.isAtEnd()) {
        return statementStart.getStartOffset();
      }
    }
    position.moveBefore();
  }
  return 0;
}
 
Example 20
Source Project: consulo   File: SemanticEditorPosition.java    License: Apache License 2.0 4 votes vote down vote up
public boolean isAtLanguage(@Nullable Language language) {
  if (language != null && !myIterator.atEnd()) {
    return language == Language.ANY || myIterator.getTokenType().getLanguage().is(language);
  }
  return false;
}