IDEA-19061 Integrate the Rearranger-plugin into core-IDEA

Arrangement settings are linked with the arrangement rules editing UI
This commit is contained in:
Denis.Zhdanov
2012-08-27 19:21:45 +04:00
parent 9d9b347a37
commit 1a58b28535
22 changed files with 235 additions and 129 deletions
@@ -15,14 +15,11 @@
*/
package com.intellij.application.options;
import com.intellij.application.options.codeStyle.arrangement.ArrangementNodeDisplayManager;
import com.intellij.application.options.codeStyle.arrangement.ArrangementSettingsPanel;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.arrangement.Rearranger;
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsAware;
import org.jetbrains.annotations.NotNull;
/**
@@ -32,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
public class JavaArrangementPanel extends ArrangementSettingsPanel {
public JavaArrangementPanel(@NotNull CodeStyleSettings settings) {
super(settings, (ArrangementStandardSettingsAware)Rearranger.EXTENSION.forLanguage(JavaLanguage.INSTANCE));
super(settings, JavaLanguage.INSTANCE);
}
@Override
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.*;
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementStandardSettingsAware;
@@ -169,4 +170,11 @@ public class JavaRearranger implements Rearranger<JavaElementArrangementEntry>,
});
return result.get();
}
@Nullable
@Override
public List<ArrangementRule<StdArrangementEntryMatcher>> getDefaultRules() {
// TODO den implement
return null;
}
}
@@ -16,9 +16,11 @@
package com.intellij.application.options.codeStyle.arrangement;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.JavaRearranger;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementSettingType;
@@ -57,7 +59,9 @@ public abstract class AbstractArrangementRuleEditingModelTest {
}
protected void configure(@NotNull ArrangementMatchCondition matchCondition) {
Pair<ArrangementRuleEditingModelImpl,TIntIntHashMap> pair = myBuilder.build(matchCondition, myTree, myRoot, null, myGrouper);
Pair<ArrangementRuleEditingModelImpl,TIntIntHashMap> pair = myBuilder.build(
new ArrangementRule<StdArrangementEntryMatcher>(new StdArrangementEntryMatcher(matchCondition)), myTree, myRoot, null, myGrouper
);
myRowMappings.put(pair.first.getRow(), pair.first);
}
@@ -42,7 +42,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
assertNotNull(child);
ArrangementMatchCondition expectedMatchCondition = and(atom(PUBLIC), atom(STATIC));
assertEquals(expectedMatchCondition, child.getBackingCondition());
assertEquals(expectedMatchCondition, model.getMatchCondition());
assertEquals(expectedMatchCondition, model.getCondition());
}
@Test
@@ -55,7 +55,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
model.addAndCondition(atom(FIELD));
assertEquals(2, model.getRow());
assertEquals(and(atom(FIELD), atom(PUBLIC)), model.getMatchCondition());
assertEquals(and(atom(FIELD), atom(PUBLIC)), model.getCondition());
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
assertNotNull(fieldNode);
@@ -77,7 +77,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
assertEquals(1, myRowMappings.size());
assertSame(model, myRowMappings.get(2));
assertEquals(and(atom(FIELD), atom(PUBLIC), atom(STATIC)), model.getMatchCondition());
assertEquals(and(atom(FIELD), atom(PUBLIC), atom(STATIC)), model.getCondition());
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
assertNotNull(fieldNode);
@@ -99,7 +99,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
assertEquals(1, myRowMappings.size());
assertSame(model, myRowMappings.get(2));
assertEquals(and(atom(FIELD), atom(STATIC)), model.getMatchCondition());
assertEquals(and(atom(FIELD), atom(STATIC)), model.getCondition());
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
assertNotNull(fieldNode);
@@ -122,7 +122,7 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
model.removeAndCondition(atom(PUBLIC));
assertEquals(1, model.getRow());
assertEquals(atom(FIELD), model.getMatchCondition());
assertEquals(atom(FIELD), model.getCondition());
ArrangementTreeNode fieldNode = myRoot.getFirstChild();
assertNotNull(fieldNode);
@@ -146,10 +146,10 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
modelToChange.removeAndCondition(atom(PUBLIC));
assertSame(1, modelToChange.getRow());
assertEquals(atom(FIELD), modelToChange.getMatchCondition());
assertEquals(atom(FIELD), modelToChange.getCondition());
assertSame(3, siblingModel.getRow());
assertEquals(and(atom(FIELD), atom(STATIC)), siblingModel.getMatchCondition());
assertEquals(and(atom(FIELD), atom(STATIC)), siblingModel.getCondition());
ArrangementTreeNode atomFieldNode = myRoot.getFirstChild();
assertNotNull(atomFieldNode);
@@ -180,10 +180,10 @@ public class ArrangementRuleEditingModelImplTest extends AbstractArrangementRule
assertEquals(2, myRowMappings.size());
assertSame(siblingModel, myRowMappings.get(2));
assertEquals(and(atom(FIELD), atom(PUBLIC)), siblingModel.getMatchCondition());
assertEquals(and(atom(FIELD), atom(PUBLIC)), siblingModel.getCondition());
assertSame(modelToChange, myRowMappings.get(3));
assertEquals(atom(FIELD), modelToChange.getMatchCondition());
assertEquals(atom(FIELD), modelToChange.getCondition());
ArrangementTreeNode compositeFieldNode = myRoot.getFirstChild();
assertNotNull(compositeFieldNode);
@@ -54,7 +54,7 @@ class Test2 {
public void test() {
}
}''',
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
[rule(atom(ArrangementEntryType.FIELD))]
)
}
@@ -98,7 +98,7 @@ class Test {
return null;
}
}''',
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
[rule(atom(ArrangementEntryType.FIELD))]
)
}
@@ -136,7 +136,7 @@ class Test {
});
}
}''',
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
[rule(atom(ArrangementEntryType.FIELD))]
)
}
@@ -174,7 +174,7 @@ class Test {
});
}
}''',
[new ArrangementRule(atom(ArrangementEntryType.FIELD))]
[rule(atom(ArrangementEntryType.FIELD))]
)
}
}
@@ -21,6 +21,7 @@ import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.util.*;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.ArrangementUtil;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
import com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters;
import com.intellij.util.xmlb.XmlSerializer;
import org.intellij.lang.annotations.MagicConstant;
@@ -45,7 +46,7 @@ public class CommonCodeStyleSettings {
@NonNls private static final String ARRANGEMENT_ELEMENT_NAME = "arrangementRules";
private final List<ArrangementRule> myArrangementRules = new ArrayList<ArrangementRule>();
private final List<ArrangementRule<?>> myArrangementRules = new ArrayList<ArrangementRule<?>>();
private final Language myLanguage;
private CodeStyleSettings myRootSettings;
private IndentOptions myIndentOptions;
@@ -122,11 +123,11 @@ public class CommonCodeStyleSettings {
}
@NotNull
public List<ArrangementRule> getArrangementRules() {
public List<ArrangementRule<?>> getArrangementRules() {
return myArrangementRules;
}
public void setArrangementRules(@NotNull List<ArrangementRule> rules) {
public <T extends ArrangementEntryMatcher> void setArrangementRules(@NotNull List<ArrangementRule<T>> rules) {
myArrangementRules.clear();
myArrangementRules.addAll(rules);
}
@@ -16,8 +16,6 @@
package com.intellij.psi.codeStyle.arrangement;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
import com.intellij.psi.codeStyle.arrangement.order.ArrangementEntryOrderType;
import org.jetbrains.annotations.NotNull;
@@ -30,32 +28,29 @@ import org.jetbrains.annotations.NotNull;
*
* @author Denis Zhdanov
* @since 7/17/12 11:07 AM
* @param <M> {@link ArrangementEntryMatcher matcher} type
*/
public class ArrangementRule {
public class ArrangementRule<M extends ArrangementEntryMatcher> {
@NotNull private final ArrangementEntryMatcher myMatcher;
@NotNull private final M myMatcher;
@NotNull private final ArrangementEntryOrderType mySortType;
public ArrangementRule(@NotNull ArrangementMatchCondition condition) {
this(new StdArrangementEntryMatcher(condition));
}
public ArrangementRule(@NotNull ArrangementEntryMatcher matcher) {
public ArrangementRule(@NotNull M matcher) {
this(matcher, ArrangementEntryOrderType.KEEP);
}
public ArrangementRule(@NotNull ArrangementEntryMatcher matcher, @NotNull ArrangementEntryOrderType type) {
public ArrangementRule(@NotNull M matcher, @NotNull ArrangementEntryOrderType type) {
myMatcher = matcher;
mySortType = type;
}
@NotNull
public ArrangementEntryMatcher getMatcher() {
public M getMatcher() {
return myMatcher;
}
@NotNull
public ArrangementEntryOrderType getSorter() {
public ArrangementEntryOrderType getOrderType() {
return mySortType;
}
@@ -42,8 +42,8 @@ public class ArrangementUtil {
//region Serialization
@NotNull
public static List<ArrangementRule> readExternal(@NotNull Element element, @NotNull Language language) {
final List<ArrangementRule> result = new ArrayList<ArrangementRule>();
public static List<ArrangementRule<?>> readExternal(@NotNull Element element, @NotNull Language language) {
final List<ArrangementRule<?>> result = new ArrayList<ArrangementRule<?>>();
ArrangementRuleSerializer serializer = getSerializer(language);
for (Object child : element.getChildren()) {
ArrangementRule rule = serializer.deserialize((Element)child);
@@ -54,7 +54,7 @@ public class ArrangementUtil {
return result;
}
public static void writeExternal(@NotNull Element element, @NotNull List<ArrangementRule> rules, @NotNull Language language) {
public static void writeExternal(@NotNull Element element, @NotNull List<ArrangementRule<?>> rules, @NotNull Language language) {
if (rules.isEmpty()) {
return;
}
@@ -76,7 +76,7 @@ public class DefaultArrangementRuleSerializer implements ArrangementRuleSerializ
Element result = new Element(RULE_ELEMENT_NAME);
result.addContent(new Element(MATCHER_ELEMENT_NAME).addContent(matcherElement));
result.addContent(new Element(SORT_TYPE_ELEMENT_NAME).setText(rule.getSorter().toString()));
result.addContent(new Element(SORT_TYPE_ELEMENT_NAME).setText(rule.getOrderType().toString()));
return result;
}
}
@@ -32,6 +32,14 @@ import org.jetbrains.annotations.NotNull;
*/
public interface ArrangementEntryMatcher {
@NotNull
ArrangementEntryMatcher EMPTY = new ArrangementEntryMatcher() {
@Override
public boolean isMatched(@NotNull ArrangementEntry entry) {
return false;
}
};
/**
* Allows to check if given entry is matched by the current rule.
* <p/>
@@ -103,7 +103,9 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher {
public ArrangementEntryMatcher getMatcher() {
ByTypeArrangementEntryMatcher byType = myTypes.isEmpty() ? null : new ByTypeArrangementEntryMatcher(myTypes);
ByModifierArrangementEntryMatcher byModifiers = myModifiers.isEmpty() ? null : new ByModifierArrangementEntryMatcher(myModifiers);
assert byType != null || byModifiers != null || (myOperator != null && !myMatchers.isEmpty());
if (byType == null && byModifiers == null && (myOperator == null || myMatchers.isEmpty())) {
return ArrangementEntryMatcher.EMPTY;
}
if (myMatchers.isEmpty() && (byType == null ^ byModifiers == null)) {
return byModifiers == null ? byType : byModifiers;
}
@@ -15,13 +15,16 @@
*/
package com.intellij.psi.codeStyle.arrangement.settings;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
@@ -32,6 +35,13 @@ import java.util.Set;
* @since 8/6/12 2:26 PM
*/
public interface ArrangementStandardSettingsAware {
/**
* @return list of rules to use by default, i.e. when a user hasn't been explicitly modified arrangement settings;
* <code>null</code> as an indication that no default rules are available
*/
@Nullable
List<ArrangementRule<StdArrangementEntryMatcher>> getDefaultRules();
/**
* Allows to answer if given entry type can be applied for the rule specified by the given settings node.
@@ -56,8 +56,8 @@ public class ArrangementConfigUtil {
* @return map which contains information on what new new settings are available at the current situation
*/
@NotNull
public static Map<ArrangementSettingType, Collection<?>> buildAvailableOptions(@NotNull ArrangementStandardSettingsAware filter,
@Nullable ArrangementMatchCondition condition)
public static Map<ArrangementSettingType, Collection<?>> buildAvailableConditions(@NotNull ArrangementStandardSettingsAware filter,
@Nullable ArrangementMatchCondition condition)
{
Map<ArrangementSettingType, Collection<?>> result = new EnumMap<ArrangementSettingType, Collection<?>>(ArrangementSettingType.class);
processData(filter, condition, result, ArrangementSettingType.TYPE, ArrangementEntryType.values());
@@ -49,7 +49,7 @@ public class ArrangementNodeDisplayManager {
@NotNull ArrangementStandardSettingsRepresentationAware representationManager)
{
myRepresentationManager = representationManager;
Map<ArrangementSettingType, Collection<?>> map = ArrangementConfigUtil.buildAvailableOptions(filter, null);
Map<ArrangementSettingType, Collection<?>> map = ArrangementConfigUtil.buildAvailableConditions(filter, null);
for (Map.Entry<ArrangementSettingType, Collection<?>> entry : map.entrySet()) {
myMaxWidths.put(entry.getKey(), maxWidth(entry.getValue()));
}
@@ -15,9 +15,13 @@
*/
package com.intellij.application.options.codeStyle.arrangement;
import com.intellij.psi.codeStyle.arrangement.ArrangementOperator;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
import org.jetbrains.annotations.NotNull;
@@ -31,9 +35,17 @@ import org.jetbrains.annotations.NotNull;
* @since 8/15/12 1:04 PM
*/
public interface ArrangementRuleEditingModel {
@NotNull
ArrangementRule<StdArrangementEntryMatcher> EMPTY_RULE = new ArrangementRule<StdArrangementEntryMatcher>(new StdArrangementEntryMatcher(
new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
));
@NotNull
ArrangementMatchCondition getMatchCondition();
ArrangementMatchCondition getCondition();
@NotNull
ArrangementRule<StdArrangementEntryMatcher> getRule();
/**
* Asks current model to destroy itself.
@@ -41,17 +53,17 @@ public interface ArrangementRuleEditingModel {
* The key concern here is to perform necessary tree modification.
*/
void destroy();
/**
* Allows to answer if current model has a registered condition for the given key. A key is expected to be one of the standard
* keys, e.g. {@link ArrangementEntryType type}, {@link ArrangementModifier modifier} etc.
*
*
* @param key target key
* @return <code>true</code> if current model has a registered mapping for the given key;
* <code>false</code> otherwise
*/
boolean hasCondition(@NotNull Object key);
void addAndCondition(@NotNull ArrangementAtomMatchCondition condition);
void removeAndCondition(@NotNull ArrangementMatchCondition condition);
@@ -60,12 +72,12 @@ public interface ArrangementRuleEditingModel {
* We need to be able to replace one condition by another. Most of the time it can be simulated by
* {@link #removeAndCondition(ArrangementMatchCondition) 'remove old'} and
* {@link #addAndCondition(ArrangementAtomMatchCondition) 'add new'} actions sequence but that doesn't work when
* {@link #getMatchCondition() underlying condition} has the only atom condition. Removing it eliminates the condition at all.
*
* {@link #getRule() underlying condition} has the only atom condition. Removing it eliminates the condition at all.
*
* @param from condition which should be replaced
* @param to replacement condition
* @throws IllegalArgumentException when given 'from' condition is not a part of the
* {@link #getMatchCondition() underlying match condition}
* {@link #getRule() underlying match condition}
*/
void replaceCondition(@NotNull ArrangementAtomMatchCondition from, @NotNull ArrangementAtomMatchCondition to)
throws IllegalArgumentException;
@@ -16,7 +16,9 @@
package com.intellij.application.options.codeStyle.arrangement;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.HierarchicalArrangementConditionNode;
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
@@ -58,7 +60,7 @@ public class ArrangementRuleEditingModelBuilder {
* </ol>
* </pre>
*
* @param matchCondition target settings to process
* @param rule target rule to process
* @param tree UI tree which shows arrangement matcher rules
* @param root UI tree settings root to use (may be not the same as the tree root)
* @param anchor node after which should be previous sibling for the root node of the inserted condition;
@@ -70,13 +72,13 @@ public class ArrangementRuleEditingModelBuilder {
*/
@SuppressWarnings("MethodMayBeStatic")
public Pair<ArrangementRuleEditingModelImpl, TIntIntHashMap> build(
@NotNull ArrangementMatchCondition matchCondition,
@NotNull ArrangementRule<StdArrangementEntryMatcher> rule,
@NotNull JTree tree,
@NotNull ArrangementTreeNode root,
@Nullable ArrangementTreeNode anchor,
@NotNull ArrangementConditionsGrouper grouper)
{
HierarchicalArrangementConditionNode grouped = grouper.group(matchCondition);
HierarchicalArrangementConditionNode grouped = grouper.group(rule.getMatcher().getCondition());
DefaultTreeModel treeModel = (DefaultTreeModel)tree.getModel();
Pair<ArrangementTreeNode, Integer> pair = ArrangementConfigUtil.map(null, grouped, null);
ArrangementTreeNode topMostNode = ArrangementConfigUtil.getRoot(pair.first);
@@ -95,7 +97,7 @@ public class ArrangementRuleEditingModelBuilder {
int row = ArrangementConfigUtil.getRow(pair.first, tree.isRootVisible());
ArrangementRuleEditingModelImpl model = new ArrangementRuleEditingModelImpl(
treeModel,
matchCondition,
rule,
topMostNode,
pair.first,
grouper,
@@ -17,7 +17,9 @@ package com.intellij.application.options.codeStyle.arrangement;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.ArrangementUtil;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.*;
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
import com.intellij.util.containers.hash.HashSet;
@@ -46,17 +48,17 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
@NotNull private final ArrangementConditionsGrouper myGrouper;
private final boolean myRootVisible;
@NotNull private ArrangementTreeNode myTopMost;
@NotNull private ArrangementTreeNode myBottomMost;
@NotNull private ArrangementMatchCondition myMatchCondition;
private int myRow;
@NotNull private ArrangementTreeNode myTopMost;
@NotNull private ArrangementTreeNode myBottomMost;
@NotNull private ArrangementRule<StdArrangementEntryMatcher> myRule;
private int myRow;
/**
* Creates new <code>ArrangementRuleEditingModelImpl</code> object.
*
* @param model tree model which holds target ui nodes. Basically, we need to perform ui nodes modification via it in order
* to generate corresponding events automatically
* @param node backing settings node
* @param rule backing arrangement rule
* @param topMost there is a possible case that a single settings node is shown in more than one visual line
* ({@link HierarchicalArrangementConditionNode}). This argument is the top-most UI node used for the
* settings node representation
@@ -66,7 +68,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
* @param rootVisible determines if the root should be count during rows calculations
*/
public ArrangementRuleEditingModelImpl(@NotNull DefaultTreeModel model,
@NotNull ArrangementMatchCondition node,
@NotNull ArrangementRule<StdArrangementEntryMatcher> rule,
@NotNull ArrangementTreeNode topMost,
@NotNull ArrangementTreeNode bottomMost,
@NotNull ArrangementConditionsGrouper grouper,
@@ -74,7 +76,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
boolean rootVisible)
{
myTreeModel = model;
myMatchCondition = node;
myRule = rule;
myTopMost = topMost;
myBottomMost = bottomMost;
myGrouper = grouper;
@@ -87,7 +89,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
myConditions.clear();
CONDITIONS_BUILDER.conditions = myConditions;
try {
myMatchCondition.invite(CONDITIONS_BUILDER);
getCondition().invite(CONDITIONS_BUILDER);
}
finally {
CONDITIONS_BUILDER.conditions = null;
@@ -96,8 +98,14 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
@NotNull
@Override
public ArrangementMatchCondition getMatchCondition() {
return myMatchCondition;
public ArrangementMatchCondition getCondition() {
return myRule.getMatcher().getCondition();
}
@NotNull
@Override
public ArrangementRule<StdArrangementEntryMatcher> getRule() {
return myRule;
}
public int getRow() {
@@ -143,10 +151,10 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
public void addAndCondition(@NotNull ArrangementAtomMatchCondition condition) {
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
LOG.info(String.format(
"Arrangement rule modification - adding a condition '%s'. Model: '%s', row: %d", condition, myMatchCondition, myRow
"Arrangement rule modification - adding a condition '%s'. Model: '%s', row: %d", condition, myRule, myRow
));
}
ArrangementMatchCondition newCondition = ArrangementUtil.and(myMatchCondition.clone(), condition);
ArrangementMatchCondition newCondition = ArrangementUtil.and(getCondition().clone(), condition);
applyNewCondition(newCondition);
}
@@ -154,16 +162,17 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
public void removeAndCondition(@NotNull ArrangementMatchCondition condition) {
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
LOG.info(String.format(
"Arrangement rule modification - removing a condition '%s'. Model: '%s', row: %d", condition, myMatchCondition, myRow
"Arrangement rule modification - removing a condition '%s'. Model: '%s', row: %d", condition, myRule, myRow
));
}
if (myMatchCondition.equals(condition)) {
ArrangementMatchCondition matchCondition = getCondition();
if (matchCondition.equals(condition)) {
destroy();
return;
}
assert myMatchCondition instanceof ArrangementCompositeMatchCondition;
ArrangementMatchCondition newCondition = myMatchCondition.clone();
assert matchCondition instanceof ArrangementCompositeMatchCondition;
ArrangementMatchCondition newCondition = matchCondition.clone();
ArrangementCompositeMatchCondition composite = (ArrangementCompositeMatchCondition)newCondition;
composite.getOperands().remove(condition);
if (composite.getOperands().size() == 1) {
@@ -172,9 +181,9 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
applyNewCondition(newCondition);
}
private void applyNewCondition(@NotNull ArrangementMatchCondition newNode) {
myMatchCondition = newNode;
HierarchicalArrangementConditionNode grouped = myGrouper.group(newNode);
private void applyNewCondition(@NotNull ArrangementMatchCondition newCondition) {
myRule = new ArrangementRule<StdArrangementEntryMatcher>(new StdArrangementEntryMatcher(newCondition));
HierarchicalArrangementConditionNode grouped = myGrouper.group(newCondition);
Pair<ArrangementTreeNode, Integer> replacement = ArrangementConfigUtil.map(null, grouped, null);
ArrangementTreeNode newBottom = replacement.first;
ArrangementTreeNode newTop = ArrangementConfigUtil.getRoot(newBottom);
@@ -193,7 +202,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
}
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
LOG.info(String.format("Arrangement rule is modified: '%s', row: %d", myMatchCondition, myRow));
LOG.info(String.format("Arrangement rule is modified: '%s', row: %d", myRule, myRow));
}
}
@@ -201,16 +210,17 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
public void replaceCondition(@NotNull ArrangementAtomMatchCondition from, @NotNull ArrangementAtomMatchCondition to) {
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
LOG.info(String.format(
"Arrangement rule modification - replacing condition '%s' by '%s'. Model: '%s', row: %d", from, to, myMatchCondition, myRow
"Arrangement rule modification - replacing condition '%s' by '%s'. Model: '%s', row: %d", from, to, myRule, myRow
));
}
ArrangementMatchCondition newCondition;
if (myMatchCondition.equals(from)) {
ArrangementMatchCondition matchCondition = getCondition();
if (matchCondition.equals(from)) {
newCondition = to;
}
else {
assert myMatchCondition instanceof ArrangementCompositeMatchCondition;
ArrangementCompositeMatchCondition composite = (ArrangementCompositeMatchCondition)myMatchCondition;
assert matchCondition instanceof ArrangementCompositeMatchCondition;
ArrangementCompositeMatchCondition composite = (ArrangementCompositeMatchCondition)matchCondition;
ArrangementCompositeMatchCondition newComposite = composite.clone();
newComposite.getOperands().remove(from);
newComposite.getOperands().add(to);
@@ -222,7 +232,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
@Override
public void destroy() {
if (ArrangementConstants.LOG_RULE_MODIFICATION) {
LOG.info(String.format("Arrangement rule modification - destroy. Model: '%s', row: %d", myMatchCondition, myRow));
LOG.info(String.format("Arrangement rule modification - destroy. Model: '%s', row: %d", myRule, myRow));
}
for (Listener listener : myListeners) {
listener.beforeModelDestroy(this);
@@ -239,7 +249,7 @@ public class ArrangementRuleEditingModelImpl implements ArrangementRuleEditingMo
@Override
public String toString() {
return "model for " + myMatchCondition;
return "model for " + myRule;
}
private static class MyConditionsBuilder implements ArrangementMatchConditionVisitor {
@@ -63,7 +63,7 @@ public class ArrangementRuleEditor extends JPanel {
private void init(@NotNull ArrangementNodeDisplayManager displayManager) {
setLayout(new GridBagLayout());
Map<ArrangementSettingType, Collection<?>> supportedSettings = ArrangementConfigUtil.buildAvailableOptions(myFilter, null);
Map<ArrangementSettingType, Collection<?>> supportedSettings = ArrangementConfigUtil.buildAvailableConditions(myFilter, null);
addRowIfPossible(ArrangementSettingType.TYPE, supportedSettings, displayManager);
addRowIfPossible(ArrangementSettingType.MODIFIER, supportedSettings, displayManager);
}
@@ -109,7 +109,7 @@ public class ArrangementRuleEditor extends JPanel {
return;
}
Map<ArrangementSettingType, Collection<?>> available = ArrangementConfigUtil.buildAvailableOptions(myFilter, model.getMatchCondition());
Map<ArrangementSettingType, Collection<?>> available = ArrangementConfigUtil.buildAvailableConditions(myFilter, model.getRule().getMatcher().getCondition());
for (Collection<?> ids : available.values()) {
for (Object id : ids) {
ArrangementAtomNodeComponent component = myComponents.get(id);
@@ -157,7 +157,7 @@ public class ArrangementRuleEditor extends JPanel {
myModel.replaceCondition(componentToDeselect.getMatchCondition(), chosenCondition);
for (ArrangementAtomNodeComponent componentToCheck : myComponents.values()) {
Object value = componentToCheck.getMatchCondition().getValue();
if (myModel.hasCondition(value) && !ArrangementConfigUtil.isEnabled(value, myFilter, myModel.getMatchCondition())) {
if (myModel.hasCondition(value) && !ArrangementConfigUtil.isEnabled(value, myFilter, myModel.getCondition())) {
myModel.removeAndCondition(componentToCheck.getMatchCondition());
}
}
@@ -18,13 +18,11 @@ package com.intellij.application.options.codeStyle.arrangement;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Pair;
import com.intellij.psi.codeStyle.arrangement.ArrangementOperator;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType;
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementCompositeMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition;
import com.intellij.psi.codeStyle.arrangement.model.ArrangementSettingType;
import com.intellij.psi.codeStyle.arrangement.settings.ArrangementConditionsGrouper;
import com.intellij.ui.treeStructure.Tree;
import com.intellij.util.Alarm;
@@ -42,6 +40,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
@@ -79,7 +78,10 @@ public class ArrangementRuleTree {
private boolean myExplicitSelectionChange;
private boolean mySkipSelectionChange;
public ArrangementRuleTree(@NotNull ArrangementConditionsGrouper grouper, @NotNull ArrangementNodeDisplayManager displayManager) {
public ArrangementRuleTree(@NotNull List<ArrangementRule<StdArrangementEntryMatcher>> rules,
@NotNull ArrangementConditionsGrouper grouper,
@NotNull ArrangementNodeDisplayManager displayManager)
{
myGrouper = grouper;
myFactory = new ArrangementNodeComponentFactory(displayManager, new Consumer<ArrangementAtomMatchCondition>() {
@Override
@@ -179,21 +181,6 @@ public class ArrangementRuleTree {
}
});
List<ArrangementMatchCondition> rules = new ArrayList<ArrangementMatchCondition>();
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.FIELD))
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PUBLIC))
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.STATIC))
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.FINAL)));
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.FIELD))
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PRIVATE)));
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.METHOD))
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PUBLIC)));
rules.add(new ArrangementCompositeMatchCondition(ArrangementOperator.AND)
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.TYPE, ArrangementEntryType.METHOD))
.addOperand(new ArrangementAtomMatchCondition(ArrangementSettingType.MODIFIER, ArrangementModifier.PRIVATE)));
map(rules);
expandAll(myTree, new TreePath(myRoot));
@@ -205,7 +192,7 @@ public class ArrangementRuleTree {
myModels.forEachValue(new TObjectProcedure<ArrangementRuleEditingModelImpl>() {
@Override
public boolean execute(ArrangementRuleEditingModelImpl model) {
LOG.info(String.format(" row %d, model '%s'", model.getRow(), model.getMatchCondition()));
LOG.info(String.format(" row %d, model '%s'", model.getRow(), model.getRule()));
return true;
}
});
@@ -335,9 +322,9 @@ public class ArrangementRuleTree {
tree.expandPath(parent);
}
private void map(@NotNull List<ArrangementMatchCondition> matchConditions) {
for (ArrangementMatchCondition matchCondition : matchConditions) {
Pair<ArrangementRuleEditingModelImpl, TIntIntHashMap> pair = myModelBuilder.build(matchCondition, myTree, myRoot, null, myGrouper);
private void map(@NotNull List<ArrangementRule<StdArrangementEntryMatcher>> rules) {
for (ArrangementRule<StdArrangementEntryMatcher> rule : rules) {
Pair<ArrangementRuleEditingModelImpl, TIntIntHashMap> pair = myModelBuilder.build(rule, myTree, myRoot, null, myGrouper);
myModels.put(pair.first.getRow(), pair.first);
pair.first.addListener(myModelChangeListener);
}
@@ -377,6 +364,20 @@ public class ArrangementRuleTree {
return myTree;
}
/**
* @return rules configured at the current tree at the moment
*/
@NotNull
public List<ArrangementRule<StdArrangementEntryMatcher>> getRules() {
int[] rows = myModels.keys();
Arrays.sort(rows);
List<ArrangementRule<StdArrangementEntryMatcher>> result = new ArrayList<ArrangementRule<StdArrangementEntryMatcher>>();
for (int row : rows) {
result.add(myModels.get(row).getRule());
}
return result;
}
@NotNull
private ArrangementNodeComponent getNodeComponentAt(int row, @NotNull ArrangementMatchCondition condition) {
ArrangementNodeComponent result = myRenderers.get(row);
@@ -547,7 +548,7 @@ public class ArrangementRuleTree {
final ArrangementTreeNode anchor = activeModel == null ? null : activeModel.getBottomMost();
doClearSelection();
Pair<ArrangementRuleEditingModelImpl,TIntIntHashMap> pair = myModelBuilder.build(
new ArrangementCompositeMatchCondition(ArrangementOperator.AND), myTree, myRoot, anchor, myGrouper
ArrangementRuleEditingModel.EMPTY_RULE, myTree, myRoot, anchor, myGrouper
);
processRowChanges(pair.second);
myModels.put(pair.first.getRow(), pair.first);
@@ -690,7 +691,7 @@ public class ArrangementRuleTree {
boolean emptyRuleRemoved = false;
for (Object value : values) {
ArrangementRuleEditingModelImpl model = (ArrangementRuleEditingModelImpl)value;
if (model != null && model != activeModel && isEmptyCondition(model.getMatchCondition())) {
if (model != null && model != activeModel && model.getRule() == ArrangementRuleEditingModel.EMPTY_RULE) {
model.destroy();
emptyRuleRemoved = true;
}
@@ -702,7 +703,7 @@ public class ArrangementRuleTree {
for (Object value : myModels.getValues()) {
ArrangementRuleEditingModelImpl model = (ArrangementRuleEditingModelImpl)value;
if (activeModel.getMatchCondition().equals(model.getMatchCondition())) {
if (activeModel.getRule().equals(model.getRule())) {
mySelectionModel.setSelectionPath(new TreePath(activeModel.getBottomMost().getPath()));
}
}
@@ -20,12 +20,16 @@ import com.intellij.application.options.codeStyle.arrangement.action.AddArrangem
import com.intellij.application.options.codeStyle.arrangement.action.RemoveArrangementRuleAction;
import com.intellij.ide.DataManager;
import com.intellij.ide.ui.customization.CustomizationUtil;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.arrangement.ArrangementRule;
import com.intellij.psi.codeStyle.arrangement.Rearranger;
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher;
import com.intellij.psi.codeStyle.arrangement.settings.*;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.SideBorder;
@@ -42,6 +46,7 @@ import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@@ -54,16 +59,24 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
@NotNull private final JPanel myContent = new JPanel(new GridBagLayout());
public ArrangementSettingsPanel(@NotNull CodeStyleSettings settings, @NotNull final ArrangementStandardSettingsAware filter) {
@NotNull private final Language myLanguage;
@NotNull private final ArrangementStandardSettingsAware mySettingsAware;
@NotNull private final ArrangementRuleTree myRuleTree;
public ArrangementSettingsPanel(@NotNull CodeStyleSettings settings, @NotNull Language language) {
super(settings);
myLanguage = language;
Rearranger<?> rearranger = Rearranger.EXTENSION.forLanguage(language);
assert rearranger instanceof ArrangementStandardSettingsAware;
mySettingsAware = (ArrangementStandardSettingsAware)rearranger;
ArrangementStandardSettingsRepresentationAware representationManager = DefaultArrangementSettingsRepresentationManager.INSTANCE;
if (filter instanceof ArrangementStandardSettingsRepresentationAware) {
representationManager = (ArrangementStandardSettingsRepresentationAware)filter;
if (mySettingsAware instanceof ArrangementStandardSettingsRepresentationAware) {
representationManager = (ArrangementStandardSettingsRepresentationAware)mySettingsAware;
}
final ArrangementNodeDisplayManager displayManager = new ArrangementNodeDisplayManager(filter, representationManager);
final ArrangementNodeDisplayManager displayManager = new ArrangementNodeDisplayManager(mySettingsAware, representationManager);
ArrangementConditionsGrouper grouper = DefaultArrangementSettingsGrouper.INSTANCE;
if (filter instanceof ArrangementConditionsGrouper) {
grouper = (ArrangementConditionsGrouper)filter;
if (mySettingsAware instanceof ArrangementConditionsGrouper) {
grouper = (ArrangementConditionsGrouper)mySettingsAware;
}
final ActionManager actionManager = ActionManager.getInstance();
@@ -73,9 +86,9 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
toolbarControl.add(actionToolbar.getComponent(), new GridBag().anchor(GridBagConstraints.WEST).weightx(1).fillCellHorizontally());
toolbarControl.setBorder(IdeBorderFactory.createBorder(SideBorder.LEFT | SideBorder.TOP | SideBorder.RIGHT));
myContent.add(toolbarControl, new GridBag().weightx(1).fillCellHorizontally().coverLine());
final ArrangementRuleTree ruleTree = new ArrangementRuleTree(grouper, displayManager);
final Tree treeComponent = ruleTree.getTreeComponent();
myRuleTree = new ArrangementRuleTree(getRules(settings), grouper, displayManager);
final Tree treeComponent = myRuleTree.getTreeComponent();
actionToolbar.setTargetComponent(treeComponent);
myContent.add(new JBScrollPane(treeComponent), new GridBag().weightx(1).weighty(1).fillCell().coverLine());
CustomizationUtil.installPopupHandler(
@@ -83,13 +96,22 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
);
final JXTaskPane editorPane = new JXTaskPane(ApplicationBundle.message("arrangement.title.editor"));
final ArrangementRuleEditor ruleEditor = new ArrangementRuleEditor(filter, displayManager);
final ArrangementRuleEditor ruleEditor = new ArrangementRuleEditor(mySettingsAware, displayManager);
ruleEditor.applyBackground(treeComponent.getBackground());
editorPane.getContentPane().setBackground(treeComponent.getBackground());
editorPane.add(ruleEditor);
editorPane.setCollapsed(true);
final Ref<Boolean> resetEditor = new Ref<Boolean>(Boolean.TRUE);
myContent.add(editorPane, new GridBag().weightx(1).fillCellHorizontally().coverLine());
final Ref<Boolean> resetEditor = new Ref<Boolean>(Boolean.TRUE);
linkTreeAndEditor(editorPane, ruleEditor, resetEditor);
setupRuleManagementActions(treeComponent, editorPane, ruleEditor, resetEditor);
setupKeyboardActions(actionManager, treeComponent);
}
private void linkTreeAndEditor(@NotNull final JXTaskPane editorPane,
@NotNull final ArrangementRuleEditor ruleEditor,
@NotNull final Ref<Boolean> resetEditor)
{
editorPane.addPropertyChangeListener("collapsed", new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
@@ -98,7 +120,7 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
}
}
});
ruleTree.addEditingListener(new ArrangementRuleSelectionListener() {
myRuleTree.addEditingListener(new ArrangementRuleSelectionListener() {
@Override
public void onSelected(@NotNull ArrangementRuleEditingModel model) {
ruleEditor.updateState(model);
@@ -116,11 +138,18 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
editorPane.setCollapsed(true);
}
});
}
private void setupRuleManagementActions(@NotNull final Tree treeComponent,
@NotNull final JXTaskPane editorPane,
@NotNull final ArrangementRuleEditor ruleEditor,
@NotNull final Ref<Boolean> resetEditor)
{
final Runnable newRuleFunction = new Runnable() {
@Override
public void run() {
treeComponent.requestFocus();
ArrangementRuleEditingModel model = ruleTree.newModel();
ArrangementRuleEditingModel model = myRuleTree.newModel();
ruleEditor.updateState(model);
resetEditor.set(Boolean.FALSE);
try {
@@ -135,7 +164,7 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
@Override
public void run() {
treeComponent.requestFocus();
ArrangementRuleEditingModelImpl model = ruleTree.getActiveModel();
ArrangementRuleEditingModelImpl model = myRuleTree.getActiveModel();
if (model != null) {
model.destroy();
}
@@ -154,7 +183,29 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
return null;
}
});
setupKeyboardActions(actionManager, treeComponent);
}
@SuppressWarnings("unchecked")
@NotNull
private List<ArrangementRule<StdArrangementEntryMatcher>> getRules(@NotNull CodeStyleSettings settings) {
List<ArrangementRule<StdArrangementEntryMatcher>> result = Collections.emptyList();
List<ArrangementRule<?>> storedRules = settings.getCommonSettings(myLanguage).getArrangementRules();
if (storedRules.isEmpty()) {
List<ArrangementRule<StdArrangementEntryMatcher>> defaultRules = mySettingsAware.getDefaultRules();
if (defaultRules != null) {
result = defaultRules;
}
}
else {
// We use unchecked cast here in assumption that current rearranger is based on standard settings if it uses standard
// settings-based rule editor.
// Note: unchecked cast for the whole collection doesn't work here (compiler error).
for (ArrangementRule<?> rule : storedRules) {
result.add((ArrangementRule<StdArrangementEntryMatcher>)rule);
}
}
return result;
}
private static void setupKeyboardActions(@NotNull ActionManager actionManager, @NotNull Tree treeComponent) {
@@ -181,13 +232,12 @@ public abstract class ArrangementSettingsPanel extends CodeStyleAbstractPanel {
@Override
public boolean isModified(CodeStyleSettings settings) {
// TODO den implement
return false;
return getRules(settings).equals(myRuleTree.getRules());
}
@Override
public void apply(CodeStyleSettings settings) {
// TODO den implement
settings.getCommonSettings(myLanguage).setArrangementRules(myRuleTree.getRules());
}
@Override
@@ -51,7 +51,7 @@ public class ArrangementEngine {
}
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(file.getProject()).getCurrentSettings();
final List<ArrangementRule> arrangementRules = settings.getCommonSettings(file.getLanguage()).getArrangementRules();
final List<ArrangementRule<?>> arrangementRules = settings.getCommonSettings(file.getLanguage()).getArrangementRules();
if (arrangementRules.isEmpty()) {
return;
}
@@ -89,7 +89,7 @@ public class ArrangementEngine {
}
private static void doArrange(@NotNull final Document document,
@NotNull List<ArrangementRule> arrangementRules,
@NotNull List<ArrangementRule<?>> arrangementRules,
@NotNull Collection<? extends ArrangementEntry> entriesToProcess)
{
// The general idea is to process entries bottom-up where every processed group belongs to the same parent. We may not bother
@@ -174,7 +174,7 @@ public class ArrangementEngine {
}
}
private static void doArrange(@NotNull List<ArrangementRule> rules,
private static void doArrange(@NotNull List<ArrangementRule<?>> rules,
@NotNull List<ArrangementEntry> entries,
@NotNull Document document)
{
@@ -24,7 +24,9 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine
import com.intellij.psi.codeStyle.arrangement.match.ArrangementEntryType
import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier
import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher
import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition
import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition
import com.intellij.psi.codeStyle.arrangement.model.ArrangementSettingType
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase
import org.jetbrains.annotations.NotNull
@@ -48,6 +50,10 @@ abstract class AbstractRearrangerTest extends LightPlatformCodeInsightFixtureTes
CodeStyleSettingsManager.getInstance(myFixture.project).dropTemporarySettings()
super.tearDown()
}
protected ArrangementRule<StdArrangementEntryMatcher> rule(@NotNull ArrangementMatchCondition condition) {
new ArrangementRule<StdArrangementEntryMatcher>(new StdArrangementEntryMatcher(condition))
}
@NotNull
protected ArrangementAtomMatchCondition atom(@NotNull Object condition) {