use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class CodeStyleSettings method writeExternal.
@Override
public void writeExternal(Element element) throws WriteExternalException {
CodeStyleSettings parentSettings = new CodeStyleSettings();
DefaultJDOMExternalizer.writeExternal(this, element, new DifferenceFilter<>(this, parentSettings));
myUnknownElementWriter.write(element, getCustomSettingsValues(), CustomCodeStyleSettings::getTagName, settings -> {
CustomCodeStyleSettings parentCustomSettings = parentSettings.getCustomSettings(settings.getClass());
if (parentCustomSettings == null) {
throw new WriteExternalException("Custom settings are null for " + settings.getClass());
}
settings.writeExternal(element, parentCustomSettings);
});
if (!myAdditionalIndentOptions.isEmpty()) {
FileType[] fileTypes = myAdditionalIndentOptions.keySet().toArray(new FileType[myAdditionalIndentOptions.keySet().size()]);
Arrays.sort(fileTypes, Comparator.comparing(FileType::getDefaultExtension));
for (FileType fileType : fileTypes) {
Element additionalIndentOptions = new Element(ADDITIONAL_INDENT_OPTIONS);
myAdditionalIndentOptions.get(fileType).serialize(additionalIndentOptions, getDefaultIndentOptions(fileType));
additionalIndentOptions.setAttribute(FILETYPE, fileType.getDefaultExtension());
if (!additionalIndentOptions.getChildren().isEmpty()) {
element.addContent(additionalIndentOptions);
}
}
}
myCommonSettingsManager.writeExternal(element);
if (!myRepeatAnnotations.isEmpty()) {
Element annos = new Element(REPEAT_ANNOTATIONS);
for (String annotation : myRepeatAnnotations) {
annos.addContent(new Element("ANNO").setAttribute("name", annotation));
}
element.addContent(annos);
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class CodeStyleSettings method readExternal.
@Override
public void readExternal(Element element) throws InvalidDataException {
DefaultJDOMExternalizer.readExternal(this, element);
if (LAYOUT_STATIC_IMPORTS_SEPARATELY) {
// add <all other static imports> entry if there is none
boolean found = false;
for (PackageEntry entry : IMPORT_LAYOUT_TABLE.getEntries()) {
if (entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) {
found = true;
break;
}
}
if (!found) {
PackageEntry last = IMPORT_LAYOUT_TABLE.getEntryCount() == 0 ? null : IMPORT_LAYOUT_TABLE.getEntryAt(IMPORT_LAYOUT_TABLE.getEntryCount() - 1);
if (last != PackageEntry.BLANK_LINE_ENTRY) {
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.BLANK_LINE_ENTRY);
}
IMPORT_LAYOUT_TABLE.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
}
}
myRepeatAnnotations.clear();
Element annotations = element.getChild(REPEAT_ANNOTATIONS);
if (annotations != null) {
for (Element anno : annotations.getChildren("ANNO")) {
myRepeatAnnotations.add(anno.getAttributeValue("name"));
}
}
UnknownElementCollector unknownElementCollector = new UnknownElementCollector();
for (CustomCodeStyleSettings settings : getCustomSettingsValues()) {
settings.getKnownTagNames().forEach(unknownElementCollector::addKnownName);
settings.readExternal(element);
}
unknownElementCollector.addKnownName(ADDITIONAL_INDENT_OPTIONS);
List<Element> list = element.getChildren(ADDITIONAL_INDENT_OPTIONS);
for (Element additionalIndentElement : list) {
String fileTypeId = additionalIndentElement.getAttributeValue(FILETYPE);
if (!StringUtil.isEmpty(fileTypeId)) {
FileType target = FileTypeManager.getInstance().getFileTypeByExtension(fileTypeId);
if (FileTypes.UNKNOWN == target || FileTypes.PLAIN_TEXT == target || target.getDefaultExtension().isEmpty()) {
target = new TempFileType(fileTypeId);
}
IndentOptions options = getDefaultIndentOptions(target);
options.readExternal(additionalIndentElement);
registerAdditionalIndentOptions(target, options);
}
}
unknownElementCollector.addKnownName(CommonCodeStyleSettingsManager.COMMON_SETTINGS_TAG);
myCommonSettingsManager.readExternal(element);
myUnknownElementWriter = unknownElementCollector.createWriter(element);
if (USE_SAME_INDENTS) {
IGNORE_SAME_INDENTS_FOR_LANGUAGES = true;
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class TrafficLightRenderer method getDaemonCodeAnalyzerStatus.
@NotNull
protected DaemonCodeAnalyzerStatus getDaemonCodeAnalyzerStatus(@NotNull SeverityRegistrar severityRegistrar) {
DaemonCodeAnalyzerStatus status = new DaemonCodeAnalyzerStatus();
if (myFile == null) {
status.reasonWhyDisabled = "No file";
status.errorAnalyzingFinished = true;
return status;
}
if (myProject != null && myProject.isDisposed()) {
status.reasonWhyDisabled = "Project is disposed";
status.errorAnalyzingFinished = true;
return status;
}
if (!myDaemonCodeAnalyzer.isHighlightingAvailable(myFile)) {
if (!myFile.isPhysical()) {
status.reasonWhyDisabled = "File is generated";
status.errorAnalyzingFinished = true;
return status;
} else if (myFile instanceof PsiCompiledElement) {
status.reasonWhyDisabled = "File is decompiled";
status.errorAnalyzingFinished = true;
return status;
}
final FileType fileType = myFile.getFileType();
if (fileType.isBinary()) {
status.reasonWhyDisabled = "File is binary";
status.errorAnalyzingFinished = true;
return status;
}
status.reasonWhyDisabled = "Highlighting is disabled for this file";
status.errorAnalyzingFinished = true;
return status;
}
FileViewProvider provider = myFile.getViewProvider();
Set<Language> languages = provider.getLanguages();
HighlightingSettingsPerFile levelSettings = HighlightingSettingsPerFile.getInstance(myProject);
boolean shouldHighlight = languages.isEmpty();
for (Language language : languages) {
PsiFile root = provider.getPsi(language);
FileHighlightingSetting level = levelSettings.getHighlightingSettingForRoot(root);
shouldHighlight |= level != FileHighlightingSetting.SKIP_HIGHLIGHTING;
}
if (!shouldHighlight) {
status.reasonWhyDisabled = "Highlighting level is None";
status.errorAnalyzingFinished = true;
return status;
}
if (HeavyProcessLatch.INSTANCE.isRunning()) {
status.reasonWhySuspended = StringUtil.defaultIfEmpty(HeavyProcessLatch.INSTANCE.getRunningOperationName(), "Heavy operation is running");
status.errorAnalyzingFinished = true;
return status;
}
status.errorCount = errorCount.clone();
List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(myDocument);
status.passStati = passes.isEmpty() ? Collections.emptyList() : new ArrayList<>(passes.size());
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < passes.size(); i++) {
TextEditorHighlightingPass tepass = passes.get(i);
if (!(tepass instanceof ProgressableTextEditorHighlightingPass))
continue;
ProgressableTextEditorHighlightingPass pass = (ProgressableTextEditorHighlightingPass) tepass;
if (pass.getProgress() < 0)
continue;
status.passStati.add(pass);
}
status.errorAnalyzingFinished = myDaemonCodeAnalyzer.isAllAnalysisFinished(myFile);
status.reasonWhySuspended = myDaemonCodeAnalyzer.isUpdateByTimerEnabled() ? null : "Highlighting is paused temporarily";
fillDaemonCodeAnalyzerErrorsStatus(status, severityRegistrar);
return status;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class TypedHandler method indentBrace.
private static void indentBrace(@NotNull final Project project, @NotNull final Editor editor, final char braceChar) {
final int offset = editor.getCaretModel().getOffset() - 1;
final Document document = editor.getDocument();
CharSequence chars = document.getCharsSequence();
if (offset < 0 || chars.charAt(offset) != braceChar)
return;
int spaceStart = CharArrayUtil.shiftBackward(chars, offset - 1, " \t");
if (spaceStart < 0 || chars.charAt(spaceStart) == '\n' || chars.charAt(spaceStart) == '\r') {
PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitDocument(document);
final PsiFile file = documentManager.getPsiFile(document);
if (file == null || !file.isWritable())
return;
PsiElement element = file.findElementAt(offset);
if (element == null)
return;
EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
HighlighterIterator iterator = highlighter.createIterator(offset);
final FileType fileType = file.getFileType();
BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
boolean rBraceToken = braceMatcher.isRBraceToken(iterator, chars, fileType);
final boolean isBrace = braceMatcher.isLBraceToken(iterator, chars, fileType) || rBraceToken;
int lBraceOffset = -1;
if (CodeInsightSettings.getInstance().REFORMAT_BLOCK_ON_RBRACE && rBraceToken && braceMatcher.isStructuralBrace(iterator, chars, fileType) && offset > 0) {
lBraceOffset = BraceMatchingUtil.findLeftLParen(highlighter.createIterator(offset - 1), braceMatcher.getOppositeBraceTokenType(iterator.getTokenType()), editor.getDocument().getCharsSequence(), fileType);
}
if (element.getNode() != null && isBrace) {
final int finalLBraceOffset = lBraceOffset;
ApplicationManager.getApplication().runWriteAction(() -> {
try {
int newOffset;
if (finalLBraceOffset != -1) {
RangeMarker marker = document.createRangeMarker(offset, offset + 1);
CodeStyleManager.getInstance(project).reformatRange(file, finalLBraceOffset, offset, true);
newOffset = marker.getStartOffset();
marker.dispose();
} else {
newOffset = CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
}
editor.getCaretModel().moveToOffset(newOffset + 1);
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
editor.getSelectionModel().removeSelection();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
});
}
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class TypedHandler method execute.
@Override
public void execute(@NotNull final Editor originalEditor, final char charTyped, @NotNull final DataContext dataContext) {
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final PsiFile originalFile;
if (project == null || (originalFile = PsiUtilBase.getPsiFileInEditor(originalEditor, project)) == null) {
if (myOriginalHandler != null) {
myOriginalHandler.execute(originalEditor, charTyped, dataContext);
}
return;
}
if (!EditorModificationUtil.checkModificationAllowed(originalEditor))
return;
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
final Document originalDocument = originalEditor.getDocument();
originalEditor.getCaretModel().runForEachCaret(new CaretAction() {
@Override
public void perform(Caret caret) {
if (psiDocumentManager.isDocumentBlockedByPsi(originalDocument)) {
// to clean up after previous caret processing
psiDocumentManager.doPostponedOperationsAndUnblockDocument(originalDocument);
}
Editor editor = injectedEditorIfCharTypedIsSignificant(charTyped, originalEditor, originalFile);
PsiFile file = editor == originalEditor ? originalFile : psiDocumentManager.getPsiFile(editor.getDocument());
final TypedHandlerDelegate[] delegates = Extensions.getExtensions(TypedHandlerDelegate.EP_NAME);
if (caret == originalEditor.getCaretModel().getPrimaryCaret()) {
boolean handled = false;
for (TypedHandlerDelegate delegate : delegates) {
final TypedHandlerDelegate.Result result = delegate.checkAutoPopup(charTyped, project, editor, file);
handled = result == TypedHandlerDelegate.Result.STOP;
if (result != TypedHandlerDelegate.Result.CONTINUE) {
break;
}
}
if (!handled) {
autoPopupCompletion(editor, charTyped, project, file);
autoPopupParameterInfo(editor, charTyped, project, file);
}
}
if (!editor.isInsertMode()) {
type(originalEditor, charTyped);
return;
}
for (TypedHandlerDelegate delegate : delegates) {
final TypedHandlerDelegate.Result result = delegate.beforeSelectionRemoved(charTyped, project, editor, file);
if (result == TypedHandlerDelegate.Result.STOP) {
return;
}
if (result == TypedHandlerDelegate.Result.DEFAULT) {
break;
}
}
EditorModificationUtil.deleteSelectedText(editor);
FileType fileType = getFileType(file, editor);
for (TypedHandlerDelegate delegate : delegates) {
final TypedHandlerDelegate.Result result = delegate.beforeCharTyped(charTyped, project, editor, file, fileType);
if (result == TypedHandlerDelegate.Result.STOP) {
return;
}
if (result == TypedHandlerDelegate.Result.DEFAULT) {
break;
}
}
if (')' == charTyped || ']' == charTyped || '}' == charTyped) {
if (FileTypes.PLAIN_TEXT != fileType) {
if (handleRParen(editor, fileType, charTyped))
return;
}
} else if ('"' == charTyped || '\'' == charTyped || '`' == charTyped) /* || '/' == charTyped*/
{
if (handleQuote(editor, charTyped, file))
return;
}
long modificationStampBeforeTyping = editor.getDocument().getModificationStamp();
type(originalEditor, charTyped);
AutoHardWrapHandler.getInstance().wrapLineIfNecessary(originalEditor, dataContext, modificationStampBeforeTyping);
if (('(' == charTyped || '[' == charTyped || '{' == charTyped) && CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET && fileType != FileTypes.PLAIN_TEXT) {
handleAfterLParen(editor, fileType, charTyped);
} else if ('}' == charTyped) {
indentClosingBrace(project, editor);
} else if (')' == charTyped) {
indentClosingParenth(project, editor);
}
for (TypedHandlerDelegate delegate : delegates) {
final TypedHandlerDelegate.Result result = delegate.charTyped(charTyped, project, editor, file);
if (result == TypedHandlerDelegate.Result.STOP) {
return;
}
if (result == TypedHandlerDelegate.Result.DEFAULT) {
break;
}
}
if ('{' == charTyped) {
indentOpenedBrace(project, editor);
} else if ('(' == charTyped) {
indentOpenedParenth(project, editor);
}
}
});
}
Aggregations