use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class MultiplePsiFilesPerDocumentFileViewProvider method findReferenceAt.
@Override
@Nullable
public PsiReference findReferenceAt(int offset) {
TextRange minRange = new TextRange(0, getContents().length());
PsiReference ret = null;
for (final Language language : getLanguages()) {
final PsiElement psiRoot = getPsi(language);
final PsiReference reference = SharedPsiElementImplUtil.findReferenceAt(psiRoot, offset, language);
if (reference == null)
continue;
final TextRange textRange = reference.getRangeInElement().shiftRight(reference.getElement().getTextRange().getStartOffset());
if (minRange.contains(textRange) && !textRange.contains(minRange)) {
minRange = textRange;
ret = reference;
}
}
return ret;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class MultiplePsiFilesPerDocumentFileViewProvider method contentsSynchronized.
@Override
public void contentsSynchronized() {
Set<Language> languages = getLanguages();
for (Iterator<Map.Entry<Language, PsiFileImpl>> iterator = myRoots.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<Language, PsiFileImpl> entry = iterator.next();
if (!languages.contains(entry.getKey())) {
PsiFileImpl file = entry.getValue();
iterator.remove();
file.markInvalidated();
}
}
super.contentsSynchronized();
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class FileManagerImpl method areViewProvidersEquivalent.
static boolean areViewProvidersEquivalent(@NotNull FileViewProvider view1, @NotNull FileViewProvider view2) {
if (view1.getClass() != view2.getClass() || view1.getFileType() != view2.getFileType())
return false;
Language baseLanguage = view1.getBaseLanguage();
if (baseLanguage != view2.getBaseLanguage())
return false;
if (!view1.getLanguages().equals(view2.getLanguages()))
return false;
PsiFile psi1 = view1.getPsi(baseLanguage);
PsiFile psi2 = view2.getPsi(baseLanguage);
if (psi1 == null)
return psi2 == null;
if (psi1.getClass() != psi2.getClass())
return false;
return true;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class CacheUtil method isInComments.
public static boolean isInComments(final IElementType tokenType) {
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();
if (commentTokens.contains(tokenType)) {
inComments = true;
}
}
return inComments;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class InjectionsSettingsUI method createInjectionColumnInfos.
private ColumnInfo[] createInjectionColumnInfos() {
final TableCellRenderer booleanCellRenderer = createBooleanCellRenderer();
final TableCellRenderer displayNameCellRenderer = createDisplayNameCellRenderer();
final TableCellRenderer languageCellRenderer = createLanguageCellRenderer();
final Comparator<InjInfo> languageComparator = (o1, o2) -> Comparing.compare(o1.injection.getInjectedLanguageId(), o2.injection.getInjectedLanguageId());
final Comparator<InjInfo> displayNameComparator = (o1, o2) -> {
final int support = Comparing.compare(o1.injection.getSupportId(), o2.injection.getSupportId());
if (support != 0)
return support;
return Comparing.compare(o1.injection.getDisplayName(), o2.injection.getDisplayName());
};
final ColumnInfo[] columnInfos = { new ColumnInfo<InjInfo, Boolean>(" ") {
@Override
public Class getColumnClass() {
return Boolean.class;
}
@Override
public Boolean valueOf(final InjInfo o) {
return o.injection.isEnabled();
}
@Override
public boolean isCellEditable(final InjInfo injection) {
return true;
}
@Override
public void setValue(final InjInfo injection, final Boolean value) {
injection.injection.setPlaceEnabled(null, value.booleanValue());
}
@Override
public TableCellRenderer getRenderer(final InjInfo injection) {
return booleanCellRenderer;
}
}, new ColumnInfo<InjInfo, InjInfo>("Name") {
@Override
public InjInfo valueOf(final InjInfo info) {
return info;
}
@Override
public Comparator<InjInfo> getComparator() {
return displayNameComparator;
}
@Override
public TableCellRenderer getRenderer(final InjInfo injection) {
return displayNameCellRenderer;
}
}, new ColumnInfo<InjInfo, InjInfo>("Language") {
@Override
public InjInfo valueOf(final InjInfo info) {
return info;
}
@Override
public Comparator<InjInfo> getComparator() {
return languageComparator;
}
@Override
public TableCellRenderer getRenderer(final InjInfo info) {
return languageCellRenderer;
}
} };
if (myInfos.length > 1) {
final TableCellRenderer typeRenderer = createTypeRenderer();
return ArrayUtil.append(columnInfos, new ColumnInfo<InjInfo, String>("Scope") {
@Override
public String valueOf(final InjInfo info) {
return info.bundled ? "Built-in" : info.cfgInfo.title;
}
@Override
public TableCellRenderer getRenderer(final InjInfo injInfo) {
return typeRenderer;
}
@Override
public int getWidth(final JTable table) {
return table.getFontMetrics(table.getFont()).stringWidth(StringUtil.repeatSymbol('m', 6));
}
@Override
public Comparator<InjInfo> getComparator() {
return (o1, o2) -> Comparing.compare(valueOf(o1), valueOf(o2));
}
});
}
return columnInfos;
}
Aggregations