Search in sources :

Example 41 with Language

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;
}
Also used : Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with Language

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();
}
Also used : Language(com.intellij.lang.Language) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 43 with Language

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;
}
Also used : Language(com.intellij.lang.Language)

Example 44 with Language

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;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) Language(com.intellij.lang.Language) TokenSet(com.intellij.psi.tree.TokenSet)

Example 45 with Language

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;
}
Also used : Language(com.intellij.lang.Language) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) ColumnInfo(com.intellij.util.ui.ColumnInfo) THashSet(gnu.trove.THashSet) TableCellRenderer(javax.swing.table.TableCellRenderer) TObjectHashingStrategy(gnu.trove.TObjectHashingStrategy) Nls(org.jetbrains.annotations.Nls) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper) FileTypes(com.intellij.openapi.fileTypes.FileTypes) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) NullableFactory(com.intellij.openapi.util.NullableFactory) TableView(com.intellij.ui.table.TableView) FileChooserFactory(com.intellij.openapi.fileChooser.FileChooserFactory) Configurable(com.intellij.openapi.options.Configurable) ReferenceInjector(com.intellij.psi.injection.ReferenceInjector) KeyEvent(java.awt.event.KeyEvent) com.intellij.ui(com.intellij.ui) SpeedSearchSupply(com.intellij.ui.speedSearch.SpeedSearchSupply) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SplitterProportionsData(com.intellij.openapi.ui.SplitterProportionsData) InjectionPlace(org.intellij.plugins.intelliLang.inject.config.InjectionPlace) com.intellij.util(com.intellij.util) NotNull(org.jetbrains.annotations.NotNull) Factory(com.intellij.openapi.util.Factory) InputEvent(java.awt.event.InputEvent) java.util(java.util) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) ContainerUtil(com.intellij.util.containers.ContainerUtil) Comparing(com.intellij.openapi.util.Comparing) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection) Project(com.intellij.openapi.project.Project) ListTableModel(com.intellij.util.ui.ListTableModel) DataManager(com.intellij.ide.DataManager) AbstractLanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.AbstractLanguageInjectionSupport) InjectorUtils(org.intellij.plugins.intelliLang.inject.InjectorUtils) SplitterProportionsDataImpl(com.intellij.ide.ui.SplitterProportionsDataImpl) StdFileTypes(com.intellij.openapi.fileTypes.StdFileTypes) StringUtil(com.intellij.openapi.util.text.StringUtil) Convertor(com.intellij.util.containers.Convertor) IOException(java.io.IOException) FileType(com.intellij.openapi.fileTypes.FileType) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) LanguageInjectionSupport(org.intellij.plugins.intelliLang.inject.LanguageInjectionSupport) FileChooser(com.intellij.openapi.fileChooser.FileChooser) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) javax.swing(javax.swing) TableCellRenderer(javax.swing.table.TableCellRenderer) ColumnInfo(com.intellij.util.ui.ColumnInfo)

Aggregations

Language (com.intellij.lang.Language)292 NotNull (org.jetbrains.annotations.NotNull)58 Nullable (org.jetbrains.annotations.Nullable)49 PsiElement (com.intellij.psi.PsiElement)46 PsiFile (com.intellij.psi.PsiFile)45 FileType (com.intellij.openapi.fileTypes.FileType)31 Project (com.intellij.openapi.project.Project)31 TextRange (com.intellij.openapi.util.TextRange)25 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 FileViewProvider (com.intellij.psi.FileViewProvider)21 HbLanguage (com.dmarcotte.handlebars.HbLanguage)20 JavaLanguage (com.intellij.lang.java.JavaLanguage)16 Editor (com.intellij.openapi.editor.Editor)14 XMLLanguage (com.intellij.lang.xml.XMLLanguage)12 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)11 List (java.util.List)11 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)9 JavascriptLanguage (com.intellij.lang.javascript.JavascriptLanguage)9 Document (com.intellij.openapi.editor.Document)9