diff --git a/java/java-impl/src/com/intellij/psi/codeStyle/arrangement/JavaRearranger.java b/java/java-impl/src/com/intellij/psi/codeStyle/arrangement/JavaRearranger.java index d565926465de..040cf525f9f3 100644 --- a/java/java-impl/src/com/intellij/psi/codeStyle/arrangement/JavaRearranger.java +++ b/java/java-impl/src/com/intellij/psi/codeStyle/arrangement/JavaRearranger.java @@ -351,6 +351,10 @@ public class JavaRearranger implements Rearranger, n.invite(this); } } + + @Override + public void visit(@NotNull ArrangementNameMatchCondition condition) { + } }); Object key = typeRef.get() == null ? NO_TYPE : typeRef.get(); Set modifiers = MODIFIERS_BY_TYPE.get(key); diff --git a/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerByNameTest.groovy b/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerByNameTest.groovy new file mode 100644 index 000000000000..a16ef3024c7d --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/psi/codeStyle/arrangement/JavaRearrangerByNameTest.groovy @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.codeStyle.arrangement + +import com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier +import org.junit.Before + +import static com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier.PROTECTED +import static com.intellij.psi.codeStyle.arrangement.match.ArrangementModifier.PUBLIC + +/** + * @author Denis Zhdanov + * @since 11/14/12 1:29 PM + */ +class JavaRearrangerByNameTest extends AbstractJavaRearrangerTest { + + @Before + void setUp() { + super.setUp() + commonSettings.BLANK_LINES_AROUND_METHOD = 0 + commonSettings.BLANK_LINES_AROUND_CLASS = 0 + } + + void "test only name condition"() { + doTest( + initial: '''\ +class Test { + public void setI() {} + public void getI() {} + public void test() {} +}''', + expected: '''\ +class Test { + public void getI() {} + public void setI() {} + public void test() {} +}''', + rules: [rule("get.*")] + ) + } + + void "test name condition and others"() { + doTest( + initial: '''\ +class Test { + private void getInner() {} + public void getOuter() {} + protected void test() {} +}''', + expected: '''\ +class Test { + public void getOuter() {} + protected void test() {} + private void getInner() {} +}''', + rules: [rule("get.*", PUBLIC), rule(PROTECTED)] + ) + } +} diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementConditionInfo.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementConditionInfo.java index 7825b47a5f96..c1d99426e213 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementConditionInfo.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementConditionInfo.java @@ -18,6 +18,7 @@ package com.intellij.psi.codeStyle.arrangement; 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.ArrangementNameMatchCondition; import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,13 +33,19 @@ import java.util.Set; public class ArrangementConditionInfo { @NotNull private final Set myAtomConditions = ContainerUtilRt.newHashSet(); - @NotNull private final Set myConditions = ContainerUtilRt.newHashSet(); + @NotNull private final Set myConditions = ContainerUtilRt.newHashSet(); + + @Nullable private ArrangementNameMatchCondition myNameCondition; + public void setNameCondition(@Nullable ArrangementNameMatchCondition condition) { + myNameCondition = condition; + } + public void addAtomCondition(@NotNull ArrangementAtomMatchCondition condition) { myAtomConditions.add(condition); myConditions.add(condition.getValue()); } - + public boolean hasCondition(@NotNull Object condition) { return myConditions.contains(condition); } @@ -59,13 +66,17 @@ public class ArrangementConditionInfo { @Nullable public ArrangementMatchCondition buildCondition() { if (myAtomConditions.isEmpty()) { - return null; + return myNameCondition == null ? null : myNameCondition; } - if (myAtomConditions.size() == 1) { + else if (myAtomConditions.size() == 1 && myNameCondition == null) { return myAtomConditions.iterator().next(); } else { - return new ArrangementCompositeMatchCondition(myAtomConditions); + ArrangementCompositeMatchCondition result = new ArrangementCompositeMatchCondition(myAtomConditions); + if (myNameCondition != null) { + result.addOperand(myNameCondition); + } + return result; } } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementUtil.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementUtil.java index 6815eeb2ff48..f6b265e6d85c 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementUtil.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/ArrangementUtil.java @@ -75,6 +75,11 @@ public class ArrangementUtil { operand.invite(this); } } + + @Override + public void visit(@NotNull ArrangementNameMatchCondition condition) { + result.addOperand(condition); + } }; for (ArrangementMatchCondition node : nodes) { node.invite(visitor); @@ -175,6 +180,11 @@ public class ArrangementUtil { operand.invite(this); } } + + @Override + public void visit(@NotNull ArrangementNameMatchCondition condition) { + result.setNameCondition(condition); + } }); return result; } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializer.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializer.java index e0de01da9ec3..4f1123958cde 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializer.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializer.java @@ -16,6 +16,7 @@ package com.intellij.psi.codeStyle.arrangement.match; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.codeStyle.arrangement.model.*; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashSet; @@ -74,7 +75,8 @@ public class DefaultArrangementEntryMatcherSerializer { private static final Logger LOG = Logger.getInstance("#" + DefaultArrangementEntryMatcherSerializer.class.getName()); @NotNull private static final String COMPOSITE_CONDITION_NAME = "AND"; - + @NotNull private static final String PATTERN_CONDITION_NAME = "NAME"; + private static final Set ATOM_SETTINGS_TYPES = new HashSet(); static { @@ -113,7 +115,10 @@ public class DefaultArrangementEntryMatcherSerializer { @Nullable private static ArrangementMatchCondition deserializeCondition(@NotNull Element matcherElement) { String name = matcherElement.getName(); - if (!COMPOSITE_CONDITION_NAME.equals(name)) { + if (PATTERN_CONDITION_NAME.equals(name)) { + return new ArrangementNameMatchCondition(StringUtil.unescapeStringCharacters(matcherElement.getText())); + } + else if (!COMPOSITE_CONDITION_NAME.equals(name)) { if (ATOM_SETTINGS_TYPES.contains(name)) { return deserializeAtomCondition(matcherElement); } @@ -163,23 +168,13 @@ public class DefaultArrangementEntryMatcherSerializer { @Override public void visit(@NotNull ArrangementAtomMatchCondition condition) { Element element = new Element(condition.getType().toString()).setText(condition.getValue().toString()); - if (result == null) { - result = element; - } - if (parent != null) { - parent.addContent(element); - } + register(element); } @Override public void visit(@NotNull ArrangementCompositeMatchCondition condition) { Element composite = new Element(COMPOSITE_CONDITION_NAME); - if (result == null) { - result = composite; - } - if (parent != null) { - parent.addContent(composite); - } + register(composite); parent = composite; List operands = new ArrayList(condition.getOperands()); ContainerUtil.sort(operands, CONDITION_COMPARATOR); @@ -187,5 +182,20 @@ public class DefaultArrangementEntryMatcherSerializer { c.invite(this); } } + + @Override + public void visit(@NotNull ArrangementNameMatchCondition condition) { + Element element = new Element(PATTERN_CONDITION_NAME).setText(StringUtil.escapeStringCharacters(condition.getPattern())); + register(element); + } + + private void register(@NotNull Element element) { + if (result == null) { + result = element; + } + if (parent != null) { + parent.addContent(element); + } + } } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/StdArrangementEntryMatcher.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/StdArrangementEntryMatcher.java index 8dddc51d3378..373c267c84c0 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/StdArrangementEntryMatcher.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/match/StdArrangementEntryMatcher.java @@ -16,13 +16,10 @@ package com.intellij.psi.codeStyle.arrangement.match; import com.intellij.psi.codeStyle.arrangement.ArrangementEntry; -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.ArrangementMatchConditionVisitor; +import com.intellij.psi.codeStyle.arrangement.model.*; +import com.intellij.util.containers.ContainerUtilRt; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; import java.util.EnumSet; import java.util.List; import java.util.Set; @@ -88,11 +85,12 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher { private static class MyVisitor implements ArrangementMatchConditionVisitor { - @NotNull private final List myMatchers = new ArrayList(); - @NotNull private final Set myTypes = EnumSet.noneOf(ArrangementEntryType.class); - @NotNull private final Set myModifiers = EnumSet.noneOf(ArrangementModifier.class); + @NotNull private final List myMatchers = ContainerUtilRt.newArrayList(); + @NotNull private final Set myTypes = EnumSet.noneOf(ArrangementEntryType.class); + @NotNull private final Set myModifiers = EnumSet.noneOf(ArrangementModifier.class); + @NotNull private final List myNamePatterns = ContainerUtilRt.newArrayList(); - private boolean nestedComposite; + private boolean nestedComposite; @Override public void visit(@NotNull ArrangementAtomMatchCondition condition) { @@ -118,16 +116,31 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher { } } + @Override + public void visit(@NotNull ArrangementNameMatchCondition condition) { + myNamePatterns.add(condition.getPattern()); + } + @SuppressWarnings("ConstantConditions") @NotNull public ArrangementEntryMatcher getMatcher() { ByTypeArrangementEntryMatcher byType = myTypes.isEmpty() ? null : new ByTypeArrangementEntryMatcher(myTypes); ByModifierArrangementEntryMatcher byModifiers = myModifiers.isEmpty() ? null : new ByModifierArrangementEntryMatcher(myModifiers); - if (byType == null && byModifiers == null && myMatchers.isEmpty()) { + ByNameArrangementEntryMatcher byName = myNamePatterns.size() != 1 ? null : new ByNameArrangementEntryMatcher(myNamePatterns.get(0)); + int i = countNonNulls(byType, byModifiers, byName); + if (i == 0 && myMatchers.isEmpty()) { return ArrangementEntryMatcher.EMPTY; } - if (myMatchers.isEmpty() && (byType == null ^ byModifiers == null)) { - return byModifiers == null ? byType : byModifiers; + if (myMatchers.isEmpty() && i == 1) { + if (byType != null) { + return byType; + } + else if (byModifiers != null) { + return byModifiers; + } + else { + return byName; + } } else if (myMatchers.size() == 1) { return myMatchers.get(0); @@ -143,8 +156,21 @@ public class StdArrangementEntryMatcher implements ArrangementEntryMatcher { if (byModifiers != null) { result.addMatcher(byModifiers); } + if (byName != null) { + result.addMatcher(byName); + } return result; } } + + private static int countNonNulls(Object... data) { + int result = 0; + for (Object o : data) { + if (o != null) { + result++; + } + } + return result; + } } } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementAtomMatchCondition.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementAtomMatchCondition.java index e7abc5d5f806..7e4d5936896c 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementAtomMatchCondition.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementAtomMatchCondition.java @@ -52,10 +52,6 @@ public class ArrangementAtomMatchCondition implements ArrangementMatchCondition visitor.visit(this); } - public boolean isInverted() { - return myInverted; - } - public void setInverted(boolean inverted) { myInverted = inverted; } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementMatchConditionVisitor.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementMatchConditionVisitor.java index 38b188ed8ff8..9106c81f5e70 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementMatchConditionVisitor.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementMatchConditionVisitor.java @@ -26,4 +26,6 @@ public interface ArrangementMatchConditionVisitor { void visit(@NotNull ArrangementAtomMatchCondition condition); void visit(@NotNull ArrangementCompositeMatchCondition condition); + + void visit(@NotNull ArrangementNameMatchCondition condition); } diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementNameMatchCondition.java b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementNameMatchCondition.java new file mode 100644 index 000000000000..892b69e51242 --- /dev/null +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/arrangement/model/ArrangementNameMatchCondition.java @@ -0,0 +1,70 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.psi.codeStyle.arrangement.model; + +import com.intellij.openapi.util.text.StringUtil; +import com.intellij.psi.codeStyle.arrangement.NameAwareArrangementEntry; +import org.jetbrains.annotations.NotNull; + +/** + * Condition which works on {@link NameAwareArrangementEntry} + * + * @author Denis Zhdanov + * @since 11/14/12 12:18 PM + */ +public class ArrangementNameMatchCondition implements ArrangementMatchCondition { + + @NotNull private final String myPattern; + + public ArrangementNameMatchCondition(@NotNull String pattern) { + myPattern = pattern; + } + + @NotNull + public String getPattern() { + return myPattern; + } + + @Override + public void invite(@NotNull ArrangementMatchConditionVisitor visitor) { + visitor.visit(this); + } + + @NotNull + @Override + public ArrangementMatchCondition clone() { + return new ArrangementNameMatchCondition(myPattern); + } + + @Override + public int hashCode() { + return myPattern.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ArrangementNameMatchCondition condition = (ArrangementNameMatchCondition)o; + return myPattern.equals(condition.myPattern); + } + + @Override + public String toString() { + return String.format("name like '%s'", StringUtil.escapeStringCharacters(myPattern)); + } +} diff --git a/platform/lang-api/testSources/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializerTest.java b/platform/lang-api/testSources/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializerTest.java index 9b7bcac2bbf0..eddbd4eaf1dd 100644 --- a/platform/lang-api/testSources/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializerTest.java +++ b/platform/lang-api/testSources/com/intellij/psi/codeStyle/arrangement/match/DefaultArrangementEntryMatcherSerializerTest.java @@ -19,6 +19,7 @@ import com.intellij.openapi.util.Comparing; 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.ArrangementNameMatchCondition; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -106,6 +107,21 @@ public class DefaultArrangementEntryMatcherSerializerTest { checkElements(element, actual); } + @Test + public void nameConditionOnly() { + ArrangementNameMatchCondition condition = new ArrangementNameMatchCondition("get*"); + doTest(condition); + } + + @Test + public void compositeConditionWithName() { + ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition(); + condition.addOperand(new ArrangementAtomMatchCondition(TYPE, METHOD)); + condition.addOperand(new ArrangementAtomMatchCondition(MODIFIER, SYNCHRONIZED)); + condition.addOperand(new ArrangementNameMatchCondition("get*")); + doTest(condition); + } + private static void checkElements(@NotNull Element expected, @NotNull Element actual) { assertTrue( String.format("Tag name mismatch - expected: '%s', actual: '%s'", expected.getName(), actual.getName()), diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementAndMatchConditionComponent.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementAndMatchConditionComponent.java index 9eb3bc766d80..5a29993af850 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementAndMatchConditionComponent.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementAndMatchConditionComponent.java @@ -20,10 +20,7 @@ import com.intellij.application.options.codeStyle.arrangement.ArrangementConstan import com.intellij.application.options.codeStyle.arrangement.ArrangementNodeDisplayManager; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule; -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.ArrangementMatchConditionVisitor; +import com.intellij.psi.codeStyle.arrangement.model.*; import com.intellij.util.ui.GridBag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,16 +58,11 @@ public class ArrangementAndMatchConditionComponent extends JPanel implements Arr setOpaque(false); setLayout(new GridBagLayout()); final Map operands = new HashMap(); + final List nameConditions = new ArrayList(); ArrangementMatchConditionVisitor visitor = new ArrangementMatchConditionVisitor() { - @Override - public void visit(@NotNull ArrangementAtomMatchCondition condition) { - operands.put(condition.getValue(), condition); - } - - @Override - public void visit(@NotNull ArrangementCompositeMatchCondition condition) { - operands.put(condition, condition); - } + @Override public void visit(@NotNull ArrangementAtomMatchCondition condition) { operands.put(condition.getValue(), condition); } + @Override public void visit(@NotNull ArrangementCompositeMatchCondition condition) { operands.put(condition, condition); } + @Override public void visit(@NotNull ArrangementNameMatchCondition condition) { nameConditions.add(condition); } }; for (ArrangementMatchCondition operand : setting.getOperands()) { operand.invite(visitor); @@ -86,6 +78,12 @@ public class ArrangementAndMatchConditionComponent extends JPanel implements Arr JComponent uiComponent = component.getUiComponent(); add(uiComponent, constraints); } + for (ArrangementNameMatchCondition condition : nameConditions) { + ArrangementMatchConditionComponent component = factory.getComponent(condition, rule, true); + myComponents.add(component); + JComponent uiComponent = component.getUiComponent(); + add(uiComponent, constraints); + } } @NotNull diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java index dfbbf5b9181d..061f330cb0b7 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementMatchNodeComponentFactory.java @@ -24,10 +24,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.Ref; import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher; import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule; -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.ArrangementMatchConditionVisitor; +import com.intellij.psi.codeStyle.arrangement.model.*; import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; @@ -83,6 +80,11 @@ public class ArrangementMatchNodeComponentFactory { public void visit(@NotNull ArrangementCompositeMatchCondition condition) { ref.set(new ArrangementAndMatchConditionComponent(rule, condition, ArrangementMatchNodeComponentFactory.this, myDisplayManager)); } + + @Override + public void visit(@NotNull ArrangementNameMatchCondition condition) { + ref.set(new ArrangementNameConditionComponent(condition)); + } }); return ref.get(); } diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementNameConditionComponent.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementNameConditionComponent.java new file mode 100644 index 000000000000..a3b7a4bc6810 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/arrangement/match/ArrangementNameConditionComponent.java @@ -0,0 +1,89 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.application.options.codeStyle.arrangement.match; + +import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition; +import com.intellij.psi.codeStyle.arrangement.model.ArrangementNameMatchCondition; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.awt.*; +import java.awt.event.MouseEvent; + +/** + * @author Denis Zhdanov + * @since 11/14/12 12:24 PM + */ +public class ArrangementNameConditionComponent implements ArrangementMatchConditionComponent { + + @NotNull private final ArrangementNameMatchCondition myCondition; + + public ArrangementNameConditionComponent(@NotNull ArrangementNameMatchCondition condition) { + myCondition = condition; + } + + @NotNull + @Override + public ArrangementMatchCondition getMatchCondition() { + return myCondition; + } + + @NotNull + @Override + public JComponent getUiComponent() { + // TODO den implement + return null; + } + + @Nullable + @Override + public Rectangle getScreenBounds() { + // TODO den implement + return null; + } + + @Override + public void setSelected(boolean selected) { + // TODO den implement + } + + @Nullable + @Override + public Rectangle onMouseMove(@NotNull MouseEvent event) { + // TODO den implement + return null; + } + + @Override + public void onMouseRelease(@NotNull MouseEvent event) { + // TODO den implement + } + + @Nullable + @Override + public Rectangle onMouseExited() { + // TODO den implement + return null; + } + + @Nullable + @Override + public Rectangle onMouseEntered(@NotNull MouseEvent e) { + // TODO den implement + return null; + } +} diff --git a/platform/lang-impl/src/com/intellij/psi/codeStyle/arrangement/engine/ArrangementEngine.java b/platform/lang-impl/src/com/intellij/psi/codeStyle/arrangement/engine/ArrangementEngine.java index 4ae7318b5a72..c678fcc8a800 100644 --- a/platform/lang-impl/src/com/intellij/psi/codeStyle/arrangement/engine/ArrangementEngine.java +++ b/platform/lang-impl/src/com/intellij/psi/codeStyle/arrangement/engine/ArrangementEngine.java @@ -217,7 +217,7 @@ public class ArrangementEngine { } else { if (dependencies.size() == 1 && dependencies.get(0) == entry.getParent()) { - // Handle a situation when the entry is condifured to be at the first parent's children. + // Handle a situation when the entry is configured to be at the first parent's children. arranged.add(entry); } else { diff --git a/platform/testFramework/testSrc/com/intellij/psi/codeStyle/arrangement/AbstractRearrangerTest.groovy b/platform/testFramework/testSrc/com/intellij/psi/codeStyle/arrangement/AbstractRearrangerTest.groovy index 33e4f360281a..744bfc6485bc 100644 --- a/platform/testFramework/testSrc/com/intellij/psi/codeStyle/arrangement/AbstractRearrangerTest.groovy +++ b/platform/testFramework/testSrc/com/intellij/psi/codeStyle/arrangement/AbstractRearrangerTest.groovy @@ -29,6 +29,7 @@ import com.intellij.psi.codeStyle.arrangement.match.StdArrangementEntryMatcher import com.intellij.psi.codeStyle.arrangement.match.StdArrangementMatchRule import com.intellij.psi.codeStyle.arrangement.model.ArrangementAtomMatchCondition import com.intellij.psi.codeStyle.arrangement.model.ArrangementMatchCondition +import com.intellij.psi.codeStyle.arrangement.model.ArrangementNameMatchCondition import com.intellij.psi.codeStyle.arrangement.order.ArrangementEntryOrderType import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase import org.jetbrains.annotations.NotNull @@ -59,17 +60,29 @@ abstract class AbstractRearrangerTest extends LightPlatformCodeInsightFixtureTes } @NotNull - protected ArrangementGroupingRule group(@NotNull ArrangementGroupingType type) { + protected static ArrangementGroupingRule group(@NotNull ArrangementGroupingType type) { group(type, ArrangementEntryOrderType.KEEP) } @NotNull - protected ArrangementGroupingRule group(@NotNull ArrangementGroupingType type, @NotNull ArrangementEntryOrderType order) { + protected static ArrangementGroupingRule group(@NotNull ArrangementGroupingType type, @NotNull ArrangementEntryOrderType order) { new ArrangementGroupingRule(type, order) } - + @NotNull - protected StdArrangementMatchRule rule(@NotNull Object ... conditions) { + protected static StdArrangementMatchRule rule(@NotNull String name) { + new StdArrangementMatchRule(new StdArrangementEntryMatcher(new ArrangementNameMatchCondition(name))) + } + + @NotNull + protected static StdArrangementMatchRule rule(@NotNull String name, Object ... conditions) { + def c = conditions.collect { atom(it) } + c << new ArrangementNameMatchCondition(name) + new StdArrangementMatchRule(new StdArrangementEntryMatcher(ArrangementUtil.combine(c as ArrangementMatchCondition[]))) + } + + @NotNull + protected static StdArrangementMatchRule rule(@NotNull Object ... conditions) { def condition if (conditions.length == 1) { condition = atom(conditions[0]) @@ -82,7 +95,7 @@ abstract class AbstractRearrangerTest extends LightPlatformCodeInsightFixtureTes } @NotNull - protected ArrangementAtomMatchCondition atom(@NotNull Object condition) { + protected static ArrangementAtomMatchCondition atom(@NotNull Object condition) { new ArrangementAtomMatchCondition(ArrangementUtil.parseType(condition), condition) }