use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class CommonCodeStyleSettingsManager method readExternal.
public void readExternal(@NotNull Element element) throws InvalidDataException {
synchronized (this) {
initCommonSettingsMap();
for (Element commonSettingsElement : element.getChildren(COMMON_SETTINGS_TAG)) {
final String languageId = commonSettingsElement.getAttributeValue(LANGUAGE_ATTR);
if (!StringUtil.isEmpty(languageId)) {
Language target = Language.findLanguageByID(languageId);
boolean isKnownLanguage = target != null;
if (isKnownLanguage) {
final LanguageCodeStyleSettingsProvider provider = LanguageCodeStyleSettingsProvider.forLanguage(target);
if (provider != null) {
CommonCodeStyleSettings settings = provider.getDefaultCommonSettings();
if (settings != null) {
settings.readExternal(commonSettingsElement);
init(settings, target);
}
} else {
isKnownLanguage = false;
}
}
if (!isKnownLanguage) {
myUnknownSettingsMap.put(languageId, commonSettingsElement.clone());
}
}
}
initNonReadSettings();
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class PsiUtilBase method getPsiFileInEditor.
@Nullable
public static PsiFile getPsiFileInEditor(@NotNull Caret caret, @NotNull final Project project) {
Editor editor = caret.getEditor();
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null)
return null;
PsiUtilCore.ensureValid(file);
final Language language = getLanguageInEditor(caret, project);
if (language == null)
return file;
if (language == file.getLanguage())
return file;
int caretOffset = caret.getOffset();
int mostProbablyCorrectLanguageOffset = caretOffset == caret.getSelectionEnd() ? caret.getSelectionStart() : caretOffset;
return getPsiFileAtOffset(file, mostProbablyCorrectLanguageOffset);
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class ChameleonSyntaxHighlightingPass method collectHighlights.
private void collectHighlights(@NotNull PsiElement element, @NotNull List<HighlightInfo> inside, @NotNull List<HighlightInfo> outside, @NotNull ProperTextRange priorityRange) {
EditorColorsScheme scheme = ObjectUtils.notNull(getColorsScheme(), EditorColorsManager.getInstance().getGlobalScheme());
TextAttributes defaultAttrs = scheme.getAttributes(HighlighterColors.TEXT);
Language language = ILazyParseableElementType.LANGUAGE_KEY.get(element.getNode());
if (language == null)
return;
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, myProject, myFile.getVirtualFile());
for (PsiElement token : psiTraverser(element).traverse(TreeTraversal.LEAVES_DFS)) {
TextRange tr = token.getTextRange();
if (tr.isEmpty())
continue;
IElementType type = PsiUtilCore.getElementType(token);
TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(type);
// force attribute colors to override host' ones
TextAttributes attributes = null;
for (TextAttributesKey key : keys) {
TextAttributes attrs2 = scheme.getAttributes(key);
if (attrs2 != null) {
attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
}
}
TextAttributes forcedAttributes;
if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
forcedAttributes = TextAttributes.ERASE_MARKER;
} else {
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
(priorityRange.contains(tr) ? inside : outside).add(info);
forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
}
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(tr).textAttributes(forcedAttributes).createUnconditionally();
(priorityRange.contains(tr) ? inside : outside).add(info);
}
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class HectorComponent method isModified.
private boolean isModified() {
final FileViewProvider viewProvider = myFile.getViewProvider();
for (Language language : mySliders.keySet()) {
JSlider slider = mySliders.get(language);
final PsiFile root = viewProvider.getPsi(language);
HighlightingLevelManager highlightingLevelManager = HighlightingLevelManager.getInstance(myFile.getProject());
if (root != null && getValue(highlightingLevelManager.shouldHighlight(root), highlightingLevelManager.shouldInspect(root)) != slider.getValue()) {
return true;
}
}
for (HectorComponentPanel panel : myAdditionalPanels) {
if (panel.isModified()) {
return true;
}
}
return false;
}
use of com.intellij.lang.Language in project intellij-community by JetBrains.
the class HectorComponent method layoutVertical.
private void layoutVertical(final JPanel panel) {
for (Language language : mySliders.keySet()) {
JSlider slider = mySliders.get(language);
JPanel borderPanel = new JPanel(new BorderLayout());
slider.setPreferredSize(JBUI.size(100));
borderPanel.add(new JLabel(language.getID()), BorderLayout.NORTH);
borderPanel.add(slider, BorderLayout.CENTER);
panel.add(borderPanel, new GridBagConstraints(GridBagConstraints.RELATIVE, 1, 1, 1, 0, 1, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 5, 0, 5), 0, 0));
}
}
Aggregations