Corrected signatures, pass indicator as constructor parameter

This commit is contained in:
Yaroslav Lepenkin
2016-05-30 21:08:37 +03:00
parent 92d635790c
commit c648f5a53d
7 changed files with 30 additions and 17 deletions
@@ -63,7 +63,7 @@ public abstract class AbstractNewLineBlocksIteratorTest extends LightPlatformCod
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(myFile);
Assert.assertNotNull(document);
return new NewLineBlocksIterator(root, document, null);
return new NewLineBlocksIterator(root, document);
}
}
@@ -78,6 +78,6 @@ public class NewLineBlocksIteratorTest extends AbstractNewLineBlocksIteratorTest
TestFormattingModel model = new TestFormattingModel(text);
Document document = model.getDocument();
TestBlock block = new FormattingModelXmlReader(model).readTestBlock(getTestDataPath(), getFileName() + ".xml");
return new NewLineBlocksIterator(block, document, null);
return new NewLineBlocksIterator(block, document);
}
}
@@ -15,7 +15,6 @@
*/
package com.intellij.psi.codeStyle.autodetect;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -23,9 +22,9 @@ import org.jetbrains.annotations.Nullable;
public interface IndentOptionsDetector {
@Nullable
IndentOptionsAdjuster getIndentOptionsAdjuster(@Nullable ProgressIndicator indicator);
IndentOptionsAdjuster getIndentOptionsAdjuster();
@NotNull
CommonCodeStyleSettings.IndentOptions getIndentOptions(@Nullable ProgressIndicator indicator);
CommonCodeStyleSettings.IndentOptions getIndentOptions();
}
@@ -70,8 +70,8 @@ class DetectAndAdjustIndentOptionsTask extends ReadTask {
PsiFile file = getFile();
if (file == null) return;
IndentOptionsDetectorImpl detector = new IndentOptionsDetectorImpl(file);
IndentOptionsAdjuster adjuster = detector.getIndentOptionsAdjuster(indicator);
IndentOptionsDetectorImpl detector = new IndentOptionsDetectorImpl(file, indicator);
IndentOptionsAdjuster adjuster = detector.getIndentOptionsAdjuster();
if (adjuster != null) {
adjustOptions(adjuster);
}
@@ -30,6 +30,7 @@ import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.util.List;
@@ -39,17 +40,27 @@ public class IndentOptionsDetectorImpl implements IndentOptionsDetector {
private final PsiFile myFile;
private final Project myProject;
private final Document myDocument;
private final ProgressIndicator myProgressIndicator;
public IndentOptionsDetectorImpl(@NotNull PsiFile file, @NotNull ProgressIndicator indicator) {
myFile = file;
myProject = file.getProject();
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myFile);
myProgressIndicator = indicator;
}
@TestOnly
public IndentOptionsDetectorImpl(@NotNull PsiFile file) {
myFile = file;
myProject = file.getProject();
myDocument = PsiDocumentManager.getInstance(myProject).getDocument(myFile);
myProgressIndicator = null;
}
@Override
@Nullable
public IndentOptionsAdjuster getIndentOptionsAdjuster(@Nullable ProgressIndicator indicator) {
List<LineIndentInfo> linesInfo = calcLineIndentInfo(indicator);
public IndentOptionsAdjuster getIndentOptionsAdjuster() {
List<LineIndentInfo> linesInfo = calcLineIndentInfo(myProgressIndicator);
if (linesInfo != null) {
IndentUsageStatistics stats = new IndentUsageStatisticsImpl(linesInfo);
return new IndentOptionsAdjusterImpl(stats);
@@ -59,14 +70,12 @@ public class IndentOptionsDetectorImpl implements IndentOptionsDetector {
@Override
@NotNull
public IndentOptions getIndentOptions(@Nullable ProgressIndicator indicator) {
public IndentOptions getIndentOptions() {
IndentOptions indentOptions =
(IndentOptions)CodeStyleSettingsManager.getSettings(myProject).getIndentOptions(myFile.getFileType()).clone();
List<LineIndentInfo> linesInfo = calcLineIndentInfo(indicator);
if (linesInfo != null) {
IndentUsageStatistics stats = new IndentUsageStatisticsImpl(linesInfo);
IndentOptionsAdjuster adjuster = new IndentOptionsAdjusterImpl(stats);
IndentOptionsAdjuster adjuster = getIndentOptionsAdjuster();
if (adjuster != null) {
adjuster.adjust(indentOptions);
}
@@ -20,7 +20,7 @@ import com.intellij.openapi.editor.Document;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.util.TextRange;
import com.intellij.util.text.CharArrayUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import java.util.Iterator;
import java.util.List;
@@ -36,7 +36,12 @@ public class NewLineBlocksIterator implements Iterator<Block> {
private int myCurrentDocumentLine;
private Stack<Block> myStack = new Stack<>();
public NewLineBlocksIterator(Block root, Document document, @Nullable ProgressIndicator indicator) {
@TestOnly
public NewLineBlocksIterator(Block root, Document document) {
this(root, document, null);
}
public NewLineBlocksIterator(Block root, Document document, ProgressIndicator indicator) {
myStack.add(root);
myDocument = document;
myTotalLines = myDocument.getLineCount();
@@ -106,6 +106,6 @@ public abstract class AbstractIndentAutoDetectionTest extends LightPlatformCodeI
@NotNull
public static CommonCodeStyleSettings.IndentOptions detectIndentOptions() {
IndentOptionsDetector detector = new IndentOptionsDetectorImpl(myFile);
return detector.getIndentOptions(null);
return detector.getIndentOptions();
}
}