use of com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions in project intellij-community by JetBrains.
the class IndentOptionsDetectorImpl method getIndentOptions.
@Override
@NotNull
public IndentOptions getIndentOptions() {
IndentOptions indentOptions = (IndentOptions) CodeStyleSettingsManager.getSettings(myProject).getIndentOptions(myFile.getFileType()).clone();
IndentOptionsAdjuster adjuster = getIndentOptionsAdjuster();
if (adjuster != null) {
adjuster.adjust(indentOptions);
}
return indentOptions;
}
use of com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions in project intellij-community by JetBrains.
the class DetectAndAdjustIndentOptionsTask method adjustOptions.
private void adjustOptions(IndentOptionsAdjuster adjuster) {
final PsiFile file = getFile();
if (file == null)
return;
final IndentOptions currentDefault = getDefaultIndentOptions(file, myDocument);
myOptionsToAdjust.copyFrom(currentDefault);
adjuster.adjust(myOptionsToAdjust);
if (myOptionsToAdjust instanceof TimeStampedIndentOptions) {
TimeStampedIndentOptions cachedInDocument = (TimeStampedIndentOptions) myOptionsToAdjust;
cachedInDocument.setTimeStamp(myDocument.getModificationStamp());
cachedInDocument.setOriginalIndentOptionsHash(currentDefault.hashCode());
}
}
use of com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions in project intellij-community by JetBrains.
the class DetectableIndentOptionsProvider method getValidCachedIndentOptions.
public IndentOptions getValidCachedIndentOptions(PsiFile file, Document document) {
IndentOptions options = IndentOptions.retrieveFromAssociatedDocument(file);
if (options instanceof TimeStampedIndentOptions) {
final IndentOptions defaultIndentOptions = getDefaultIndentOptions(file, document);
final TimeStampedIndentOptions cachedInDocument = (TimeStampedIndentOptions) options;
if (!cachedInDocument.isOutdated(document, defaultIndentOptions)) {
return cachedInDocument;
}
}
return null;
}
use of com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions in project intellij by bazelbuild.
the class BuildEnterHandler method preprocessEnter.
@Override
public Result preprocessEnter(PsiFile file, Editor editor, Ref<Integer> caretOffset, Ref<Integer> caretAdvance, DataContext dataContext, EditorActionHandler originalHandler) {
int offset = caretOffset.get();
if (editor instanceof EditorWindow) {
file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file);
editor = InjectedLanguageUtil.getTopLevelEditor(editor);
offset = editor.getCaretModel().getOffset();
}
if (!isApplicable(file, dataContext)) {
return Result.Continue;
}
// Previous enter handler's (e.g. EnterBetweenBracesHandler) can introduce a mismatch
// between the editor's caret model and the offset we've been provided with.
editor.getCaretModel().moveToOffset(offset);
Document doc = editor.getDocument();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(doc);
CodeStyleSettings currentSettings = CodeStyleSettingsManager.getSettings(file.getProject());
IndentOptions indentOptions = currentSettings.getIndentOptions(file.getFileType());
Integer indent = determineIndent(file, editor, offset, indentOptions);
if (indent == null) {
return Result.Continue;
}
removeTrailingWhitespace(doc, file, offset);
originalHandler.execute(editor, editor.getCaretModel().getCurrentCaret(), dataContext);
LogicalPosition position = editor.getCaretModel().getLogicalPosition();
if (position.column == indent) {
return Result.Stop;
}
if (position.column > indent) {
// default enter handler has added too many spaces -- remove them
int excess = position.column - indent;
doc.deleteString(editor.getCaretModel().getOffset() - excess, editor.getCaretModel().getOffset());
} else if (position.column < indent) {
String spaces = StringUtil.repeatSymbol(' ', indent - position.column);
doc.insertString(editor.getCaretModel().getOffset(), spaces);
}
editor.getCaretModel().moveToLogicalPosition(new LogicalPosition(position.line, indent));
return Result.Stop;
}
use of com.intellij.psi.codeStyle.CommonCodeStyleSettings.IndentOptions in project intellij-community by JetBrains.
the class DetectableIndentOptionsProvider method getIndentOptions.
@Nullable
@Override
public IndentOptions getIndentOptions(@NotNull CodeStyleSettings settings, @NotNull PsiFile file) {
if (!isEnabled(settings, file)) {
return null;
}
Project project = file.getProject();
PsiDocumentManager psiManager = PsiDocumentManager.getInstance(project);
Document document = psiManager.getDocument(file);
if (document == null) {
return null;
}
IndentOptions options = getValidCachedIndentOptions(file, document);
if (options != null) {
return options;
}
TimeStampedIndentOptions indentOptions = getDefaultIndentOptions(file, document);
indentOptions.associateWithDocument(document);
DetectAndAdjustIndentOptionsTask task = new DetectAndAdjustIndentOptionsTask(project, document, indentOptions, BOUNDED_EXECUTOR);
task.scheduleInBackgroundForCommittedDocument();
return indentOptions;
}
Aggregations