Search in sources :

Example 81 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class TemplateLanguageStructureViewBuilder method updateAfterPsiChange.

private void updateAfterPsiChange() {
    if (myProject.isDisposed())
        return;
    if (myBaseStructureViewDescriptor != null && ((StructureViewComponent) myBaseStructureViewDescriptor.structureView).getTree() == null)
        return;
    ApplicationManager.getApplication().runReadAction(() -> {
        if (!myVirtualFile.isValid() || getViewProvider() == null)
            return;
        StructureViewWrapper structureViewWrapper = StructureViewFactoryEx.getInstanceEx(myProject).getStructureViewWrapper();
        if (structureViewWrapper == null)
            return;
        Language baseLanguage = getTemplateDataLanguage();
        if (baseLanguage == myTemplateDataLanguage && (myBaseStructureViewDescriptor == null || isPsiValid(myBaseStructureViewDescriptor))) {
            updateBaseLanguageView();
        } else {
            myTemplateDataLanguage = baseLanguage;
            ((StructureViewWrapperImpl) structureViewWrapper).rebuild();
        }
    });
}
Also used : Language(com.intellij.lang.Language) StructureViewComponent(com.intellij.ide.structureView.newStructureView.StructureViewComponent) StructureViewWrapperImpl(com.intellij.ide.impl.StructureViewWrapperImpl)

Example 82 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class ExtractCodeStyleAction method reportResult.

public void reportResult(final ValuesExtractionResult forSelection, final Project project, final CodeStyleSettings cloneSettings, final PsiFile file, final Map<Value, Object> backup) {
    final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Formatting Options were extracted<br/><a href=\"apply\">Apply</a> <a href=\"details\">Details...</a>", MessageType.INFO, new HyperlinkListener() {

        @Override
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                boolean apply = "apply".equals(e.getDescription());
                ExtractedSettingsDialog myDialog = null;
                if (!apply) {
                    final List<Value> values = forSelection.getValues();
                    final LanguageCodeStyleSettingsProvider[] providers = Extensions.getExtensions(LanguageCodeStyleSettingsProvider.EP_NAME);
                    Language language = file.getLanguage();
                    CodeStyleSettingsNameProvider nameProvider = new CodeStyleSettingsNameProvider();
                    for (final LanguageCodeStyleSettingsProvider provider : providers) {
                        Language target = provider.getLanguage();
                        if (target.equals(language)) {
                            //this is our language
                            nameProvider.addSettings(provider);
                            myDialog = new ExtractedSettingsDialog(project, nameProvider, values);
                            apply = myDialog.showAndGet();
                            break;
                        }
                    }
                }
                if (apply && myDialog != null) {
                    //create new settings named after the file
                    final ExtractedSettingsDialog finalMyDialog = myDialog;
                    forSelection.applyConditioned(value -> finalMyDialog.valueIsSelectedInTree(value), backup);
                    CodeStyleScheme derivedScheme = CodeStyleSchemes.getInstance().createNewScheme("Derived from " + file.getName(), null);
                    derivedScheme.getCodeStyleSettings().copyFrom(cloneSettings);
                    CodeStyleSchemes.getInstance().addScheme(derivedScheme);
                    CodeStyleSchemesImpl.getSchemeManager().setCurrent(derivedScheme);
                    CodeStyleSettingsManager.getInstance(project).PREFERRED_PROJECT_CODE_STYLE = derivedScheme.getName();
                }
            }
        }
    }).setDisposable(ApplicationManager.getApplication()).setShowCallout(false).setFadeoutTime(0).setShowCallout(false).setAnimationCycle(0).setHideOnClickOutside(false).setHideOnKeyOutside(false).setCloseButtonEnabled(true).setHideOnLinkClick(true).createBalloon();
    ApplicationManager.getApplication().invokeLater(() -> {
        Window window = WindowManager.getInstance().getFrame(project);
        if (window == null) {
            window = JOptionPane.getRootFrame();
        }
        if (window instanceof IdeFrame) {
            BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
            if (layout != null) {
                layout.add(balloon);
            }
        }
    });
}
Also used : Language(com.intellij.lang.Language) IdeFrame(com.intellij.openapi.wm.IdeFrame) MessageType(com.intellij.openapi.ui.MessageType) HyperlinkEvent(javax.swing.event.HyperlinkEvent) com.intellij.psi.codeStyle(com.intellij.psi.codeStyle) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleDeriveProcessor(com.intellij.psi.codeStyle.extractor.processor.CodeStyleDeriveProcessor) LangCodeStyleExtractor(com.intellij.psi.codeStyle.extractor.differ.LangCodeStyleExtractor) Value(com.intellij.psi.codeStyle.extractor.values.Value) PsiManager(com.intellij.psi.PsiManager) Balloon(com.intellij.openapi.ui.popup.Balloon) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Task(com.intellij.openapi.progress.Task) BalloonLayout(com.intellij.ui.BalloonLayout) Map(java.util.Map) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DumbAware(com.intellij.openapi.project.DumbAware) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) ExtractedSettingsDialog(com.intellij.psi.codeStyle.extractor.ui.ExtractedSettingsDialog) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) HyperlinkListener(javax.swing.event.HyperlinkListener) WindowManager(com.intellij.openapi.wm.WindowManager) Editor(com.intellij.openapi.editor.Editor) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) GenProcessor(com.intellij.psi.codeStyle.extractor.processor.GenProcessor) CodeStyleSchemesImpl(com.intellij.psi.impl.source.codeStyle.CodeStyleSchemesImpl) LanguageFormatting(com.intellij.lang.LanguageFormatting) ApplicationManager(com.intellij.openapi.application.ApplicationManager) CodeStyleSettingsNameProvider(com.intellij.psi.codeStyle.extractor.ui.CodeStyleSettingsNameProvider) ValuesExtractionResult(com.intellij.psi.codeStyle.extractor.values.ValuesExtractionResult) NotNull(org.jetbrains.annotations.NotNull) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) HyperlinkEvent(javax.swing.event.HyperlinkEvent) ExtractedSettingsDialog(com.intellij.psi.codeStyle.extractor.ui.ExtractedSettingsDialog) Balloon(com.intellij.openapi.ui.popup.Balloon) CodeStyleSettingsNameProvider(com.intellij.psi.codeStyle.extractor.ui.CodeStyleSettingsNameProvider) IdeFrame(com.intellij.openapi.wm.IdeFrame) BalloonLayout(com.intellij.ui.BalloonLayout) Language(com.intellij.lang.Language) HyperlinkListener(javax.swing.event.HyperlinkListener) List(java.util.List)

Example 83 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class FormattingDocumentModelImpl method containsWhiteSpaceSymbolsOnly.

@Override
public boolean containsWhiteSpaceSymbolsOnly(int startOffset, int endOffset) {
    WhiteSpaceFormattingStrategy strategy = myWhiteSpaceStrategy;
    if (strategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset) {
        return true;
    }
    PsiElement injectedElement = myFile != null ? InjectedLanguageUtil.findElementAtNoCommit(myFile, startOffset) : null;
    if (injectedElement != null) {
        Language injectedLanguage = injectedElement.getLanguage();
        if (!injectedLanguage.equals(myFile.getLanguage())) {
            WhiteSpaceFormattingStrategy localStrategy = WhiteSpaceFormattingStrategyFactory.getStrategy(injectedLanguage);
            if (localStrategy != null) {
                String unescapedText = InjectedLanguageUtil.getUnescapedLeafText(injectedElement, true);
                if (unescapedText != null) {
                    return localStrategy.check(unescapedText, 0, unescapedText.length()) >= unescapedText.length();
                }
                return localStrategy.check(myDocument.getCharsSequence(), startOffset, endOffset) >= endOffset;
            }
        }
    }
    return false;
}
Also used : Language(com.intellij.lang.Language) PsiElement(com.intellij.psi.PsiElement)

Example 84 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class WhiteSpaceFormattingStrategyFactory method getAllStrategies.

/**
   * @return    collection of all registered white space strategies
   */
@NotNull
public static Collection<WhiteSpaceFormattingStrategy> getAllStrategies() {
    final WeakReference<Collection<WhiteSpaceFormattingStrategy>> reference = myCachedStrategies.get();
    final Collection<WhiteSpaceFormattingStrategy> strategies = SoftReference.dereference(reference);
    if (strategies != null) {
        return strategies;
    }
    final Collection<Language> languages = Language.getRegisteredLanguages();
    if (languages == null) {
        final List<WhiteSpaceFormattingStrategy> result = Collections.emptyList();
        myCachedStrategies.set(new PatchedWeakReference<>(result));
        return result;
    }
    Set<WhiteSpaceFormattingStrategy> result = new HashSet<>(SHARED_STRATEGIES);
    final LanguageWhiteSpaceFormattingStrategy languageStrategy = LanguageWhiteSpaceFormattingStrategy.INSTANCE;
    for (Language language : languages) {
        final WhiteSpaceFormattingStrategy strategy = languageStrategy.forLanguage(language);
        if (strategy != null) {
            result.add(strategy);
        }
    }
    myCachedStrategies.set(new PatchedWeakReference<>(result));
    return result;
}
Also used : Language(com.intellij.lang.Language) NotNull(org.jetbrains.annotations.NotNull)

Example 85 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class InjectedLanguageBlockBuilder method addInjectedLanguageBlockWrapper.

public void addInjectedLanguageBlockWrapper(final List<Block> result, final ASTNode injectedNode, final Indent indent, int offset, @Nullable TextRange range) {
    //
    if (range != null) {
        if (range.getLength() == 0)
            return;
        if (StringUtil.isEmptyOrSpaces(range.substring(injectedNode.getText()))) {
            return;
        }
    }
    final PsiElement childPsi = injectedNode.getPsi();
    final Language childLanguage = childPsi.getLanguage();
    final FormattingModelBuilder builder = LanguageFormatting.INSTANCE.forContext(childLanguage, childPsi);
    LOG.assertTrue(builder != null);
    final FormattingModel childModel = builder.createModel(childPsi, getSettings());
    Block original = childModel.getRootBlock();
    if ((original.isLeaf() && !injectedNode.getText().trim().isEmpty()) || !original.getSubBlocks().isEmpty()) {
        result.add(createInjectedBlock(injectedNode, original, indent, offset, range, childLanguage));
    }
}
Also used : Language(com.intellij.lang.Language) PsiElement(com.intellij.psi.PsiElement)

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