From a07c6e6db71d7d6a3deaa7f6d792805ebc9fb1dc Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Thu, 17 May 2012 16:54:45 +0400 Subject: [PATCH 1/2] IDEA-19061 Integrate the Rearranger-plugin into core-IDEA GDSL for the Rearranger tests is introduced --- .../atomicAttributes/FinalAttribute.java | 4 +- .../com/wrq/rearranger/RearrangerTest.groovy | 176 ++++++------------ .../util/AbstractRuleBuilder.groovy | 139 ++++++++++++++ .../rearranger/util/CommentRuleBuilder.groovy | 38 ++++ .../rearranger/util/RearrangerTestDsl.java | 45 +++++ .../util/java/AbstractJavaRuleBuilder.groovy | 51 +++++ .../rearranger/util/java/InitializerType.java | 9 + .../util/java/JavaClassRuleBuilder.groovy | 22 +++ .../util/java/JavaFieldRuleBuilder.groovy | 28 +++ .../util/java/JavaMethodRuleBuilder.groovy | 32 ++++ .../wrq/rearranger/util/java/MethodType.java | 9 + .../wrq/rearranger/util/java/SortType.java | 9 + 12 files changed, 444 insertions(+), 118 deletions(-) create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/AbstractJavaRuleBuilder.groovy create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/InitializerType.java create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaClassRuleBuilder.groovy create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaFieldRuleBuilder.groovy create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaMethodRuleBuilder.groovy create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/MethodType.java create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/SortType.java diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java index acf75802d0de..87ec094d411b 100644 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/atomicAttributes/FinalAttribute.java @@ -26,9 +26,7 @@ import org.jdom.Element; import java.lang.reflect.Modifier; /** Routines to handle the 'final' modifier. */ -public final class FinalAttribute - extends AndNotAttribute -{ +public final class FinalAttribute extends AndNotAttribute { // -------------------------- STATIC METHODS -------------------------- diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy index 082abe39e019..cc06490a4cb3 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy @@ -23,19 +23,23 @@ package com.wrq.rearranger; import com.intellij.openapi.application.ApplicationManager +import com.intellij.psi.PsiModifier import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import com.wrq.rearranger.settings.CommentRule import com.wrq.rearranger.settings.RearrangerSettings -import com.wrq.rearranger.settings.attributeGroups.ClassAttributes -import com.wrq.rearranger.settings.attributeGroups.FieldAttributes -import com.wrq.rearranger.settings.attributeGroups.MethodAttributes +import com.wrq.rearranger.util.CommentRuleBuilder import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable -import com.wrq.rearranger.settings.CommentRule +import com.wrq.rearranger.util.java.* /** JUnit tests for the rearranger plugin. */ class RearrangerTest extends LightCodeInsightFixtureTestCase { - - private RearrangerSettings mySettings; + + private RearrangerSettings mySettings + private JavaClassRuleBuilder classRule + private JavaFieldRuleBuilder fieldRule + private JavaMethodRuleBuilder methodRule + private CommentRuleBuilder commentRule @Override protected String getBasePath() { @@ -44,6 +48,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { protected final void setUp() throws Exception { super.setUp(); + mySettings = new RearrangerSettings(); // rs.setAskBeforeRearranging(true); // uncomment for debugging file structure popup mySettings.showFields = true @@ -51,6 +56,11 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { mySettings.showParameterTypes = true mySettings.showRules = true mySettings.rearrangeInnerClasses = true + + classRule = new JavaClassRuleBuilder(settings: mySettings) + fieldRule = new JavaFieldRuleBuilder(settings: mySettings) + methodRule = new JavaMethodRuleBuilder(settings: mySettings) + commentRule = new CommentRuleBuilder(settings: mySettings) } public final void testNoRearrangement() throws Exception { @@ -59,102 +69,66 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testPublicFieldRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult2') { - def attributes = new FieldAttributes() - attributes.protectionLevelAttributes.plPublic = true - mySettings.addItem(attributes) - } - } + fieldRule.create { + modifier( PsiModifier.PUBLIC ) + } } } public final void testNotPublicFieldRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult3') { - def attributes = new FieldAttributes() - attributes.protectionLevelAttributes.plPublic = true - attributes.protectionLevelAttributes.invertProtectionLevel = true - mySettings.addItem(attributes) - } - } + fieldRule.create { + modifier( PsiModifier.PUBLIC, invert: true ) + } } } public final void testConstructorRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult4') { - def attributes = new MethodAttributes() - attributes.protectionLevelAttributes.plPackage = true - attributes.protectionLevelAttributes.plPublic = true - attributes.constructorMethodType = true - mySettings.addItem(attributes) - } - } + methodRule.create { + modifier([ PsiModifier.PUBLIC, PsiModifier.PACKAGE_LOCAL ]) + target( MethodType.CONSTRUCTOR ) + } } } public final void testClassRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult5') { - def attributes = new ClassAttributes() - attributes.protectionLevelAttributes.plPackage = true - mySettings.addClass(attributes) - } - } + classRule.create { + modifier( PsiModifier.PACKAGE_LOCAL ) + } } } public final void testPSFRearrangement() throws Exception { doTest('RearrangementTest2', 'RearrangementResult6') { - def attributes = new FieldAttributes() - attributes.finalAttribute.value = true - attributes.staticAttribute.value = true - mySettings.addItem(attributes) - } - } + fieldRule.create { + modifier([ PsiModifier.FINAL, PsiModifier.STATIC ]) + } } } public final void testAnonClassInit() throws Exception { doTest('RearrangementTest7', 'RearrangementResult7') { - def attributes = new FieldAttributes() - attributes.initialisedByAnonymousClassAttr.value = true - mySettings.addItem(attributes) - } - } + fieldRule.create { + initializer( InitializerType.ANONYMOUS_CLASS ) + } } } public final void testNameMatch() throws Exception { doTest('RearrangementTest', 'RearrangementResult8') { - def fieldAttributes = new FieldAttributes() - fieldAttributes.nameAttribute.match = true - fieldAttributes.nameAttribute.expression = '.*5' - mySettings.addItem(fieldAttributes) - - def methodAttributes = new MethodAttributes() - methodAttributes.nameAttribute.match = true - methodAttributes.nameAttribute.expression = '.*2' - mySettings.addItem(methodAttributes) - } - } + fieldRule.create { name('.*5') } + methodRule.create { name('.*2') } + } } public final void testStaticInitializer() throws Exception { doTest('RearrangementTest8', 'RearrangementResult8A') { - def methodAttributes = new MethodAttributes() - methodAttributes.staticAttribute.value = true - mySettings.addItem(methodAttributes) - } - } + methodRule.create { modifier( PsiModifier.STATIC ) } + } } public final void testAlphabetizingGSMethods() throws Exception { + mySettings.keepGettersSettersTogether = false doTest('RearrangementTest', 'RearrangementResult9') { - def attributes = new MethodAttributes() - attributes.getterSetterMethodType = true - attributes.otherMethodType = true - attributes.constructorMethodType = false - attributes.sortOptions.byName = true - mySettings.addItem(attributes) - mySettings.keepGettersSettersTogether = false - } - } + methodRule.create { + target([ MethodType.GETTER_OR_SETTER, MethodType.OTHER ]) + sort(SortType.BY_NAME) + } } } public final void testSimpleComment() throws Exception { doTest('RearrangementTest', 'RearrangementResult10') { - def attributes = new FieldAttributes() - attributes.protectionLevelAttributes.plPublic = true - mySettings.addItem(attributes) - - def comment = new CommentRule() - comment.commentText = '// simple comment **********' - comment.emitCondition = CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE - mySettings.addItem(comment) - } - } + fieldRule.create { modifier( PsiModifier.PUBLIC) } + commentRule.create { + comment( '// simple comment **********', condition: CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE ) + } } } /** * Delete old comment and insert (identical) new one. This tests proper identification and deletion of old @@ -164,49 +138,21 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { */ public final void testReplayComment() throws Exception { doTest('RearrangementResult10', 'RearrangementResult10') { - def attributes = new FieldAttributes() - attributes.protectionLevelAttributes.plPublic = true - mySettings.addItem(attributes) - - def comment = new CommentRule() - comment.commentText = '// simple comment **********' - comment.emitCondition = CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE - mySettings.addItem(comment) - } - } + fieldRule.create { modifier( PsiModifier.PUBLIC) } + commentRule.create { + comment( '// simple comment **********', condition: CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE ) + } } } public final void testMultipleRuleCommentMatch() throws Exception { doTest('RearrangementTest11', 'RearrangementResult11') { - def allFieldsComment = new CommentRule() - allFieldsComment.commentText = '// FIELDS:' - allFieldsComment.emitCondition = CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE - allFieldsComment.allSubsequentRules = false - mySettings.addItem(allFieldsComment) - - def finalFieldsComment = new CommentRule() - finalFieldsComment.commentText = '// FINAL FIELDS:' - finalFieldsComment.emitCondition = CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE - finalFieldsComment.allSubsequentRules = true - finalFieldsComment.NSubsequentRulesToMatch = 1 - mySettings.addItem(finalFieldsComment) - - def finalFields = new FieldAttributes() - finalFields.finalAttribute.value = true - mySettings.addItem(finalFields) - - def nonFinalFieldsComment = new CommentRule() - nonFinalFieldsComment.commentText = '// NON-FINAL FIELDS:' - nonFinalFieldsComment.emitCondition = CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE - nonFinalFieldsComment.allSubsequentRules = true - nonFinalFieldsComment.NSubsequentRulesToMatch = 1 - mySettings.addItem(nonFinalFieldsComment) - - def nonFinalFields = new FieldAttributes() - nonFinalFields.finalAttribute.value = true - nonFinalFields.finalAttribute.invert = true - mySettings.addItem(nonFinalFields) - } - } + commentRule.create { comment('// FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false) } + commentRule.create { comment('// FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, + subsequentRulesToMatch: 1) } + fieldRule.create { modifier(PsiModifier.FINAL) } + commentRule.create { comment('// NON-FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, + subsequentRulesToMatch: 1) } + fieldRule.create { modifier(PsiModifier.FINAL, invert: true) } + } } // public final void testOpsBlockingQueueExample() throws Exception { // testOpsBlockingQueueExampleWorker(false, "/com/wrq/rearranger/OpsBlockingQueue.java", diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy new file mode 100644 index 000000000000..218c11c9f1bc --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy @@ -0,0 +1,139 @@ +package com.wrq.rearranger.util; + + +import com.wrq.rearranger.settings.RearrangerSettings +import com.wrq.rearranger.settings.atomicAttributes.AndNotAttribute +import com.wrq.rearranger.settings.attributeGroups.Rule +import org.jetbrains.annotations.NotNull +import org.junit.Assert + +/** + * Defines common infrastructure for the {@link Rule} builders. + * + * @author Denis Zhdanov + * @since 5/17/12 10:43 AM + * @param rule class + */ +public abstract class AbstractRuleBuilder extends BuilderSupport { + + @NotNull def RearrangerSettings settings + + /** + * Holds rule customization handlers in the form {@code 'property id -> closure'} where 'property id' + * is expected to be one of the {@link RearrangerTestDsl#getValue()} predefined constants}. + *

+ * Corresponding value is a closure that receives three arguments - target attribute value, attribute customization map + * and target rule instance . + */ + @NotNull private def myHandlers = [:].withDefault { + { key -> Assert.fail("No handler for the rule attribute '${key}'") } + } + + @Override + protected void nodeCompleted(Object parent, Object node) { + if (!parent) { + registerRule(settings, node as T) + } + } + + @Override + protected void setParent(Object parent, Object child) { + } + + @Override + protected Object createNode(Object name) { + if (name == 'create') { + return createRule() + } + createNode(name, [:], []) + } + + @Override + protected Object createNode(Object name, Object value) { + createNode(name, [:], value) + } + + @Override + protected Object createNode(Object name, Map attributes) { + createNode(name, attributes, []) + } + + @Override + protected Object createNode(Object name, Map attributes, Object value) { + for (i in [value].flatten()) { + myHandlers[name](i, attributes, current) + } + getCurrent() + } + + @NotNull + protected abstract T createRule() + + protected abstract void registerRule(@NotNull RearrangerSettings settings, @NotNull T rule) + + /** + * Registers given handler for the rule customization within the given data. + *

+ * Example: + *

+   *   register('modifier', PsiModifier.FINAL, { rule, value, attributes ->
+   *       rule.finalAttribute.value = value
+   *       if (attributes.invert) rule.finalAttribute.invert = true
+   *   })
+   * 
+ * + * @param specifier target rule attribute specifier used at the test DSL + * @param handler closure to apply target information to the rule instance. Accepts two values - target rule instance + * and additional rule attribute information map + */ + protected void registerHandler(@NotNull RearrangerTestDsl specifier, @NotNull Closure handler) { + myHandlers[specifier.value] = handler + true + } + + /** + * Allows to get a closure with the following properties: + *
+   * 
    + *
  • receives two arguments - target attribute data and target rule;
  • + *
  • + * assumes that target attribute (identified by the 'propertyName' method argument) IS-A {@link AndNotAttribute} + * and updates its value at the given rule object in accordance with the given attribute data; + *
  • + *
+ *
+ * I.e. returned closure looks like { attributes, rule -> ...}, it configure 'rule.propertyName' + * according to the 'attributes' argument. + * + * @param propertyName name of the target attribute property at the target rule class + * @return closure to use for updating target attribute + */ + @NotNull + protected static Closure createBooleanAttributeHandler(@NotNull final String propertyName) { + { attributes, T rule -> + rule."$propertyName".value = true + if (attributes[RearrangerTestDsl.INVERT.value]) { + rule."$propertyName".invert = true + } + } + } + + /** + * Very similar to the {@link #createBooleanAttributeHandler(java.lang.String)} but targets boolean property with the given name + * at the given rule argument. + * + * @param propertyName name of the target attribute property at the target rule class + * @return closure to use for updating target attribute + */ + @NotNull + protected static Closure createRawBooleanAttributeHandler(@NotNull final String propertyName) { + { attributes, T rule -> rule."$propertyName" = true } + } + + protected static Closure createStringAttributeHandler(@NotNull final String propertyName) { + { value, attributes, T rule -> + rule."$propertyName".match = true + rule."$propertyName".expression = value + } + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy new file mode 100644 index 000000000000..ae23f6a59ab7 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy @@ -0,0 +1,38 @@ +package com.wrq.rearranger.util; + +import com.wrq.rearranger.settings.CommentRule; +import com.wrq.rearranger.settings.RearrangerSettings; +import org.jetbrains.annotations.NotNull; + +/** + * @author Denis Zhdanov + * @since 5/17/12 4:08 PM + */ +class CommentRuleBuilder extends AbstractRuleBuilder { + + { + def helper = { RearrangerTestDsl dslProperty, map, rulePropertyName, rule -> + if (map[dslProperty.value]) { + rule."$rulePropertyName" = map[dslProperty.value] + } + } + + registerHandler(RearrangerTestDsl.COMMENT, { data, attributes, rule -> + rule.commentText = data + helper(RearrangerTestDsl.CONDITION, attributes, 'emitCondition', rule) + helper(RearrangerTestDsl.ALL_SUBSEQUENT, attributes, 'allSubsequentRules', rule) + helper(RearrangerTestDsl.SUBSEQUENT_RULES_TO_MATCH, attributes, 'NSubsequentRulesToMatch', rule) + }) + } + + @NotNull + @Override + protected CommentRule createRule() { + new CommentRule() + } + + @Override + protected void registerRule(@NotNull RearrangerSettings settings, @NotNull CommentRule rule) { + settings.addItem(rule) + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java new file mode 100644 index 000000000000..857634ad2fe3 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java @@ -0,0 +1,45 @@ +package com.wrq.rearranger.util; + +import org.jetbrains.annotations.NotNull; + +/** + * Enumerates constants used at the Rearranger DSL. + * + * @author Denis Zhdanov + * @since 5/17/12 12:57 PM + */ +public enum RearrangerTestDsl { + + NAME, + MODIFIER, + /** Field initializer type. */ + INITIALIZER, + /** Method target type (e.g. constructor). */ + TARGET, + SORT, + COMMENT, + + // Attributes + INVERT, + CONDITION, + ALL_SUBSEQUENT("allSubsequent"), + SUBSEQUENT_RULES_TO_MATCH("subsequentRulesToMatch"); + + @NotNull private final String myValue; + + RearrangerTestDsl() { + myValue = toString().toLowerCase(); + } + + RearrangerTestDsl(@NotNull String value) { + myValue = value; + } + + /** + * @return string value used at the Rearranger DSL + */ + @NotNull + public String getValue() { + return myValue; + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/AbstractJavaRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/AbstractJavaRuleBuilder.groovy new file mode 100644 index 000000000000..a7e53e599332 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/AbstractJavaRuleBuilder.groovy @@ -0,0 +1,51 @@ +package com.wrq.rearranger.util.java + +import com.intellij.openapi.util.text.StringUtil +import com.intellij.psi.PsiModifier +import com.wrq.rearranger.util.AbstractRuleBuilder +import com.wrq.rearranger.util.RearrangerTestDsl + +/** + * @author Denis Zhdanov + * @since 5/17/12 10:47 AM + */ +abstract class AbstractJavaRuleBuilder extends AbstractRuleBuilder {{ + + // Name + registerHandler(RearrangerTestDsl.NAME, { value, attributes, rule -> + rule.nameAttribute.match = true + rule.nameAttribute.expression = value + }) + + // Sort + def sortOptions = [ (SortType.BY_NAME) : "byName"] + registerHandler(RearrangerTestDsl.SORT, { data, attributes, rule -> + rule.sortOptions."${sortOptions[data]}" = true + }) + + // Modifiers + // Visibility + def visibilityHandler = { propertyName, attributes, rule -> + rule.protectionLevelAttributes."$propertyName" = true + if (attributes.invert) { + rule.protectionLevelAttributes.invertProtectionLevel = true + } + } + + // Final, static. + def genericHandlers = [:] + for (i in [PsiModifier.FINAL, PsiModifier.STATIC]) { + genericHandlers[i] = createBooleanAttributeHandler("${i}Attribute") + } + + def visibilityModifiers = [PsiModifier.PUBLIC, PsiModifier.PROTECTED, PsiModifier.PRIVATE, PsiModifier.PACKAGE_LOCAL].toSet() + registerHandler(RearrangerTestDsl.MODIFIER, { value, attributes, rule -> + if (visibilityModifiers.contains(value)) { + def propertyName = value == PsiModifier.PACKAGE_LOCAL ? 'plPackage' : "pl${StringUtil.capitalize(value)}" + visibilityHandler(propertyName, attributes, rule) + } + else { + genericHandlers[value](attributes, rule) + } + }) +}} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/InitializerType.java b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/InitializerType.java new file mode 100644 index 000000000000..19d89bec1b7a --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/InitializerType.java @@ -0,0 +1,9 @@ +package com.wrq.rearranger.util.java; + +/** + * @author Denis Zhdanov + * @since 5/17/12 11:51 AM + */ +public enum InitializerType { + ANONYMOUS_CLASS +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaClassRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaClassRuleBuilder.groovy new file mode 100644 index 000000000000..76d59c76c281 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaClassRuleBuilder.groovy @@ -0,0 +1,22 @@ +package com.wrq.rearranger.util.java + +import com.wrq.rearranger.settings.RearrangerSettings +import com.wrq.rearranger.settings.attributeGroups.ClassAttributes +import org.jetbrains.annotations.NotNull + +/** + * @author Denis Zhdanov + * @since 5/17/12 11:13 AM + */ +class JavaClassRuleBuilder extends AbstractJavaRuleBuilder { + + @Override + protected ClassAttributes createRule() { + new ClassAttributes() + } + + @Override + protected void registerRule(@NotNull RearrangerSettings settings, @NotNull ClassAttributes rule) { + settings.addClass(rule) + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaFieldRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaFieldRuleBuilder.groovy new file mode 100644 index 000000000000..d093c65bb0d9 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaFieldRuleBuilder.groovy @@ -0,0 +1,28 @@ +package com.wrq.rearranger.util.java + +import com.wrq.rearranger.settings.RearrangerSettings +import org.jetbrains.annotations.NotNull +import com.wrq.rearranger.settings.attributeGroups.FieldAttributes +import com.wrq.rearranger.util.RearrangerTestDsl + +/** + * @author Denis Zhdanov + * @since 5/17/12 10:49 AM + */ +class JavaFieldRuleBuilder extends AbstractJavaRuleBuilder { + + { + def handlers = [(InitializerType.ANONYMOUS_CLASS) : createBooleanAttributeHandler('initialisedByAnonymousClassAttr')] + registerHandler(RearrangerTestDsl.INITIALIZER, { data, attributes, rule -> handlers[data](attributes, rule) }) + } + + @Override + protected FieldAttributes createRule() { + new FieldAttributes() + } + + @Override + protected void registerRule(@NotNull RearrangerSettings settings, @NotNull FieldAttributes rule) { + settings.addItem(rule) + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaMethodRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaMethodRuleBuilder.groovy new file mode 100644 index 000000000000..68fdece9d412 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaMethodRuleBuilder.groovy @@ -0,0 +1,32 @@ +package com.wrq.rearranger.util.java + +import com.wrq.rearranger.settings.RearrangerSettings +import com.wrq.rearranger.settings.attributeGroups.MethodAttributes +import org.jetbrains.annotations.NotNull +import com.wrq.rearranger.util.RearrangerTestDsl + +/** + * @author Denis Zhdanov + * @since 5/17/12 11:01 AM + */ +class JavaMethodRuleBuilder extends AbstractJavaRuleBuilder { + + { + def handlers = [ + (MethodType.CONSTRUCTOR) : createRawBooleanAttributeHandler('constructorMethodType'), + (MethodType.GETTER_OR_SETTER) : createRawBooleanAttributeHandler('getterSetterMethodType'), + (MethodType.OTHER) : createRawBooleanAttributeHandler('otherMethodType') + ] + registerHandler(RearrangerTestDsl.TARGET, { data, attributes, rule -> handlers[data](attributes, rule) }) + } + + @Override + protected MethodAttributes createRule() { + new MethodAttributes() + } + + @Override + protected void registerRule(@NotNull RearrangerSettings settings, @NotNull MethodAttributes rule) { + settings.addItem(rule) + } +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/MethodType.java b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/MethodType.java new file mode 100644 index 000000000000..f31690cb7248 --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/MethodType.java @@ -0,0 +1,9 @@ +package com.wrq.rearranger.util.java; + +/** + * @author Denis Zhdanov + * @since 5/17/12 11:05 AM + */ +public enum MethodType { + CONSTRUCTOR, GETTER_OR_SETTER, OTHER +} diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/SortType.java b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/SortType.java new file mode 100644 index 000000000000..ab035a85809e --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/SortType.java @@ -0,0 +1,9 @@ +package com.wrq.rearranger.util.java; + +/** + * @author Denis Zhdanov + * @since 5/17/12 3:57 PM + */ +public enum SortType { + BY_NAME +} From f61c9593671839247819740e49293189de6fe6a9 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Fri, 18 May 2012 10:28:59 +0400 Subject: [PATCH 2/2] IDEA-19061 Integrate the Rearranger-plugin into core-IDEA *) more tests have been refactored and enabled; *) test data has been corrected to remove unnecessary comment rule-related blank lines. Checked that that behavior is consistent with the Rearranger processing at v.11.1.2; --- .../rearrangement/GenericRearranger.java | 2 +- .../com/wrq/rearranger/RearrangerTest.groovy | 322 ++++++++---------- .../rearranger/util/CommentRuleBuilder.groovy | 4 +- .../rearranger/util/RearrangerTestDsl.java | 4 +- .../java/JavaInnerClassRuleBuilder.groovy | 21 ++ .../com/wrq/rearranger/OpsBlockingQueue.java | 11 +- 6 files changed, 168 insertions(+), 196 deletions(-) create mode 100644 plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInnerClassRuleBuilder.groovy diff --git a/plugins/rearranger/src/com/wrq/rearranger/rearrangement/GenericRearranger.java b/plugins/rearranger/src/com/wrq/rearranger/rearrangement/GenericRearranger.java index 0fe9f582a692..ca751455130e 100644 --- a/plugins/rearranger/src/com/wrq/rearranger/rearrangement/GenericRearranger.java +++ b/plugins/rearranger/src/com/wrq/rearranger/rearrangement/GenericRearranger.java @@ -66,7 +66,7 @@ public abstract class GenericRearranger { * @return rearranged list of RangeEntry and CommentRuleInstance objects. */ public final List rearrangeEntries() { - final List prioritizedRuleInstances = new ArrayList(); + final List prioritizedRuleInstances = new ArrayList(); buildRuleInstanceLists(prioritizedRuleInstances); // Recursively reorder contents of every nested ClassEntry diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy index cc06490a4cb3..07f2c8ff1fda 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy @@ -35,11 +35,12 @@ import com.wrq.rearranger.util.java.* /** JUnit tests for the rearranger plugin. */ class RearrangerTest extends LightCodeInsightFixtureTestCase { - private RearrangerSettings mySettings - private JavaClassRuleBuilder classRule - private JavaFieldRuleBuilder fieldRule - private JavaMethodRuleBuilder methodRule - private CommentRuleBuilder commentRule + private RearrangerSettings mySettings + private JavaClassRuleBuilder classRule + private JavaInnerClassRuleBuilder innerClassRule + private JavaFieldRuleBuilder fieldRule + private JavaMethodRuleBuilder methodRule + private CommentRuleBuilder commentRule @Override protected String getBasePath() { @@ -58,6 +59,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { mySettings.rearrangeInnerClasses = true classRule = new JavaClassRuleBuilder(settings: mySettings) + innerClassRule = new JavaInnerClassRuleBuilder(settings: mySettings) fieldRule = new JavaFieldRuleBuilder(settings: mySettings) methodRule = new JavaMethodRuleBuilder(settings: mySettings) commentRule = new CommentRuleBuilder(settings: mySettings) @@ -154,11 +156,10 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { fieldRule.create { modifier(PsiModifier.FINAL, invert: true) } } } -// public final void testOpsBlockingQueueExample() throws Exception { -// testOpsBlockingQueueExampleWorker(false, "/com/wrq/rearranger/OpsBlockingQueue.java", -// false, "/com/wrq/rearranger/OpsBlockingQueue.java"); -// } -// + public final void testOpsBlockingQueueExample() throws Exception { + testOpsBlockingQueueExampleWorker(false, "OpsBlockingQueue", false, "OpsBlockingQueue"); + } + // public final void testOpsBlockingQueueExampleWithGlobalPattern() throws Exception { // testOpsBlockingQueueExampleWorker(true, "/com/wrq/rearranger/OpsBlockingQueue.java", // false, "/com/wrq/rearranger/OpsBlockingQueue.java"); @@ -168,182 +169,131 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { // testOpsBlockingQueueExampleWorker(false, "/com/wrq/rearranger/OpsBlockingQueueIndented.java", // true, "/com/wrq/rearranger/OpsBlockingQueueIndentedResult.java"); // } -// -// private void testOpsBlockingQueueExampleWorker(boolean doGlobalPattern, -// String srcFilename, -// boolean doublePublicMethods, -// String compareFilename) -// throws Exception -// { -// // submitted by Joe Martinez. -// configureByFile(srcFilename); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// CommentRule c; -// FieldAttributes fa; -// c = new CommentRule(); -// c.setCommentText("//************************************** PUBLIC STATIC FIELDS *************************************"); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(2); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(false); -// rs.addItem(c, 0); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlPublic(true); -// fa.getStAttr().setValue(true); -// fa.getfAttr().setValue(true); -// rs.addItem(fa, 1); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlPublic(true); -// fa.getStAttr().setValue(true); -// rs.addItem(fa, 2); -// c = new CommentRule(); -// c.setCommentText("//************************************** PUBLIC FIELDS *****************************************"); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(1); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(true); -// rs.addItem(c, 3); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlPublic(true); -// rs.addItem(fa, 4); -// c = new CommentRule(); -// c.setCommentText("//*********************************** PROTECTED/PACKAGE FIELDS **************************************"); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(3); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(false); -// rs.addItem(c, 5); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlProtected(true); -// fa.getPlAttr().setPlPackage(true); -// fa.getStAttr().setValue(true); -// fa.getfAttr().setValue(true); -// rs.addItem(fa, 6); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlProtected(true); -// fa.getPlAttr().setPlPackage(true); -// fa.getStAttr().setValue(true); -// rs.addItem(fa, 7); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlProtected(true); -// fa.getPlAttr().setPlPackage(true); -// rs.addItem(fa, 8); -// c = new CommentRule(); -// c.setCommentText("//************************************** PRIVATE FIELDS *****************************************"); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(1); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(false); -// rs.addItem(c, 9); -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(true); -// fa.getPlAttr().setPlPrivate(true); -// rs.addItem(fa, 10); -// c = new CommentRule(); -// c.setCommentText("//************************************** CONSTRUCTORS ************************************* "); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(2); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(false); -// rs.addItem(c, 11); -// MethodAttributes ma = new MethodAttributes(); -// ma.getPlAttr().setPlPublic(true); -// ma.setConstructorMethodType(true); -// rs.addItem(ma, 12); -// ma = new MethodAttributes(); -// ma.setConstructorMethodType(true); -// rs.addItem(ma, 13); -// c = new CommentRule(); -// c.setCommentText("//*********************************** GETTERS AND SETTERS ********************************** "); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(2); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(false); -// rs.addItem(c, 14); -// ma = new MethodAttributes(); -// ma.getSortAttr().setByName(true); -// ma.getPlAttr().setPlPublic(true); -// ma.setGetterSetterMethodType(true); -// rs.addItem(ma, 15); -// ma = new MethodAttributes(); -// ma.getSortAttr().setByName(true); -// ma.setGetterSetterMethodType(true); -// rs.addItem(ma, 16); -// c = new CommentRule(); -// String commentText = -// "//************************************** PUBLIC METHODS ************************************* "; -// if (doublePublicMethods) { -// commentText += "\n// PUBLIC METHODS LINE 2"; -// } -// c.setCommentText(commentText); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(1); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(true); -// rs.addItem(c, 17); -// ma = new MethodAttributes(); -// ma.getSortAttr().setByName(true); -// ma.getPlAttr().setPlPublic(true); -// rs.addItem(ma, 18); -// c = new CommentRule(); -// c.setCommentText("//********************************* PACKAGE/PROTECTED METHODS ******************************** "); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(1); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(true); -// rs.addItem(c, 19); -// ma = new MethodAttributes(); -// ma.getSortAttr().setByName(true); -// ma.getPlAttr().setPlProtected(true); -// ma.getPlAttr().setPlPackage(true); -// rs.addItem(ma, 20); -// c = new CommentRule(); -// c.setCommentText("//************************************** PRIVATE METHODS *************************************"); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(1); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(true); -// rs.addItem(c, 21); -// ma = new MethodAttributes(); -// ma.getSortAttr().setByName(true); -// ma.getPlAttr().setPlPrivate(true); -// rs.addItem(ma, 22); -// c = new CommentRule(); -// c.setCommentText("//************************************** INNER CLASSES ************************************* "); -// c.setEmitCondition(2); -// c.setnPrecedingRulesToMatch(1); -// c.setnSubsequentRulesToMatch(1); -// c.setAllPrecedingRules(true); -// c.setAllSubsequentRules(true); -// rs.addItem(c, 23); -// InnerClassAttributes ic = new InnerClassAttributes(); -// ic.getSortAttr().setByName(true); -// rs.addItem(ic, 24); -// rs.getExtractedMethodsSettings().setMoveExtractedMethods(false); -// if (doGlobalPattern) { -// rs.setGlobalCommentPattern("//\\*{20,45}[A-Z /]*\\*{20,45}\n"); -// } -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile(compareFilename); -// } -// + + private void testOpsBlockingQueueExampleWorker(boolean doGlobalPattern, + String srcFilename, + boolean doublePublicMethods, + String compareFilename) + throws Exception + { + // submitted by Joe Martinez. + doTest(srcFilename, compareFilename) { + commentRule.create { + comment('//************************************** PUBLIC STATIC FIELDS *************************************', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, + subsequentRulesToMatch: 2, precedingRulesToMatch: 1) + } + fieldRule.create { + modifier([ PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL ]) + sort( SortType.BY_NAME ) + } + fieldRule.create { + modifier([ PsiModifier.PUBLIC, PsiModifier.STATIC ]) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//************************************** PUBLIC FIELDS *****************************************', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, + subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + } + fieldRule.create { + modifier( PsiModifier.PUBLIC ) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//*********************************** PROTECTED/PACKAGE FIELDS **************************************', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, + subsequentRulesToMatch: 3, precedingRulesToMatch: 1) + } + fieldRule.create { + modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL, PsiModifier.STATIC, PsiModifier.FINAL ]) + sort( SortType.BY_NAME ) + } + fieldRule.create { + modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL, PsiModifier.STATIC ]) + sort( SortType.BY_NAME ) + } + fieldRule.create { + modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL ]) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//************************************** PRIVATE FIELDS *****************************************', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, + subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + } + fieldRule.create { + modifier( PsiModifier.PRIVATE ) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//************************************** CONSTRUCTORS ************************************* ', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, + subsequentRulesToMatch: 2, precedingRulesToMatch: 1) + } + methodRule.create { + modifier( PsiModifier.PUBLIC ) + target( MethodType.CONSTRUCTOR ) + } + methodRule.create { target( MethodType.CONSTRUCTOR ) } + commentRule.create { + comment('//*********************************** GETTERS AND SETTERS ********************************** ', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, + subsequentRulesToMatch: 2, precedingRulesToMatch: 1) + } + methodRule.create { + modifier( PsiModifier.PUBLIC ) + target( MethodType.GETTER_OR_SETTER ) + sort( SortType.BY_NAME ) + } + methodRule.create { + target( MethodType.GETTER_OR_SETTER ) + sort( SortType.BY_NAME ) + } + def text = '//************************************** PUBLIC METHODS ************************************* ' + if (doublePublicMethods) { + text += "\n// PUBLIC METHODS LINE 2"; + } + commentRule.create { + comment(text, condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, + subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + } + methodRule.create { + modifier( PsiModifier.PUBLIC ) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//********************************* PACKAGE/PROTECTED METHODS ******************************** ', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, + subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + } + methodRule.create { + modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL ]) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//************************************** PRIVATE METHODS *************************************', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, + subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + } + methodRule.create { + modifier( PsiModifier.PRIVATE ) + sort( SortType.BY_NAME ) + } + commentRule.create { + comment('//************************************** INNER CLASSES ************************************* ', + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, + subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + } + innerClassRule.create { sort(SortType.BY_NAME ) } + + mySettings.extractedMethodsSettings.moveExtractedMethods = false + if (doGlobalPattern) { + mySettings.globalCommentPattern = "//\\*{20,45}[A-Z /]*\\*{20,45}\n" + } + } + } + // public final void testReturnTypeMatch() throws Exception { // configureByFile("/com/wrq/rearranger/RearrangementTest12.java"); // final PsiFile file = getFile(); diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy index ae23f6a59ab7..8b133c2f4432 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy @@ -12,7 +12,7 @@ class CommentRuleBuilder extends AbstractRuleBuilder { { def helper = { RearrangerTestDsl dslProperty, map, rulePropertyName, rule -> - if (map[dslProperty.value]) { + if (map.containsKey(dslProperty.value)) { rule."$rulePropertyName" = map[dslProperty.value] } } @@ -21,7 +21,9 @@ class CommentRuleBuilder extends AbstractRuleBuilder { rule.commentText = data helper(RearrangerTestDsl.CONDITION, attributes, 'emitCondition', rule) helper(RearrangerTestDsl.ALL_SUBSEQUENT, attributes, 'allSubsequentRules', rule) + helper(RearrangerTestDsl.ALL_PRECEDING, attributes, 'allPrecedingRules', rule) helper(RearrangerTestDsl.SUBSEQUENT_RULES_TO_MATCH, attributes, 'NSubsequentRulesToMatch', rule) + helper(RearrangerTestDsl.PRECEDING_RULES_TO_MATCH, attributes, 'NPrecedingRulesToMatch', rule) }) } diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java index 857634ad2fe3..58a58b7ac408 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java @@ -23,7 +23,9 @@ public enum RearrangerTestDsl { INVERT, CONDITION, ALL_SUBSEQUENT("allSubsequent"), - SUBSEQUENT_RULES_TO_MATCH("subsequentRulesToMatch"); + ALL_PRECEDING("allPreceding"), + SUBSEQUENT_RULES_TO_MATCH("subsequentRulesToMatch"), + PRECEDING_RULES_TO_MATCH("precedingRulesToMatch"); @NotNull private final String myValue; diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInnerClassRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInnerClassRuleBuilder.groovy new file mode 100644 index 000000000000..22b3422a5eba --- /dev/null +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInnerClassRuleBuilder.groovy @@ -0,0 +1,21 @@ +package com.wrq.rearranger.util.java + +import com.wrq.rearranger.settings.attributeGroups.InnerClassAttributes +import com.wrq.rearranger.settings.RearrangerSettings + +/** + * @author Denis Zhdanov + * @since 5/18/12 8:51 AM + */ +class JavaInnerClassRuleBuilder extends AbstractJavaRuleBuilder { + + @Override + protected InnerClassAttributes createRule() { + new InnerClassAttributes() + } + + @Override + protected void registerRule(RearrangerSettings settings, InnerClassAttributes rule) { + settings.addItem(rule) + } +} diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueue.java b/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueue.java index fedb5e2587e5..818ec3c04ea7 100644 --- a/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueue.java +++ b/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueue.java @@ -10,22 +10,20 @@ import opsx.server.email.OpsEmailGenerator; /** @author dchan */ public class OpsBlockingQueue extends OpsNonBlockingQueue { - //*********************************** PROTECTED/PACKAGE FIELDS ************************************** +//*********************************** PROTECTED/PACKAGE FIELDS ************************************** protected final Object putLock; protected final Object takeLock; protected volatile int waitCount; - //************************************** PRIVATE FIELDS ***************************************** +//************************************** PRIVATE FIELDS ***************************************** private static final OpsLogCategory logCat = (OpsLogCategory)OpsLogCategory.getInstance(OpsEmailGenerator.class); //************************************** CONSTRUCTORS ************************************* - /** Creates new OpsBlockingQueue */ public OpsBlockingQueue() { takeLock = new Object(); putLock = new Object(); waitCount = 0; } - - //************************************** PUBLIC METHODS ************************************* +//************************************** PUBLIC METHODS ************************************* public void put(Object obj) { synchronized (putLock) { insert(obj); @@ -60,8 +58,7 @@ public class OpsBlockingQueue extends OpsNonBlockingQueue { } } } - - //********************************* PACKAGE/PROTECTED METHODS ******************************** +//********************************* PACKAGE/PROTECTED METHODS ******************************** protected Object takeNext() { synchronized (takeLock) { return super.takeNext();