diff --git a/plugins/rearranger/src/com/wrq/rearranger/defaultConfiguration.xml b/plugins/rearranger/src/com/wrq/rearranger/defaultConfiguration.xml index ff91276bbcac..f153990a0491 100644 --- a/plugins/rearranger/src/com/wrq/rearranger/defaultConfiguration.xml +++ b/plugins/rearranger/src/com/wrq/rearranger/defaultConfiguration.xml @@ -27,9 +27,7 @@ ShowMatchedRules="false" ShowComments="false" RemoveBlanksInsideCodeBlocks="true"> \n//\ ------------------------------\ FIELDS\ - ------------------------------\n - + fillString="" useProjectWidthForFill="true" fillWidth="0">\n// ------------------------------ FIELDS ------------------------------\n @@ -247,9 +245,7 @@ \n//\ --------------------------\ OTHER\ METHODS\ - --------------------------\n - + fillString="" useProjectWidthForFill="true" fillWidth="0">\n// -------------------------- OTHER METHODS --------------------------\n @@ -285,9 +281,7 @@ \n//\ --------------------------\ INNER\ CLASSES\ - --------------------------\n - + fillString="" useProjectWidthForFill="true" fillWidth="0">\n// -------------------------- INNER CLASSES --------------------------\n diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java b/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java index 09beffce623b..78865f5de646 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java +++ b/plugins/rearranger/test/src/com/wrq/rearranger/InteractiveTest.java @@ -30,11 +30,8 @@ import com.wrq.rearranger.settings.RearrangerSettings; * Date: Mar 30, 2004 */ @SkipInHeadlessEnvironment -public class InteractiveTest - extends LightCodeInsightFixtureTestCase -{ - public static final String DEFAULT_CONFIGURATION_ROOT = ".."; // up one level from test - public static final String DEFAULT_CONFIGURATION = DEFAULT_CONFIGURATION_ROOT + "/src/com/wrq/rearranger/defaultConfiguration.xml"; +public class InteractiveTest extends LightCodeInsightFixtureTestCase { + public static final String DEFAULT_CONFIGURATION = "/src/com/wrq/rearranger/defaultConfiguration.xml"; private RearrangerSettings mySettings; @Override diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy index 47f437e26fda..7487b73ca465 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy @@ -29,21 +29,27 @@ import com.wrq.rearranger.settings.CommentRule import com.wrq.rearranger.settings.RearrangerSettings import com.wrq.rearranger.settings.RelatedMethodsSettings import com.wrq.rearranger.settings.attributeGroups.GetterSetterDefinition +import com.wrq.rearranger.settings.attributeGroups.InterfaceAttributes +import com.wrq.rearranger.settings.attributeGroups.RegexUtil import com.wrq.rearranger.util.CommentRuleBuilder +import com.wrq.rearranger.util.SettingsConfigurationBuilder import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.Nullable import com.wrq.rearranger.util.java.* +import com.intellij.testFramework.PlatformTestUtil /** JUnit tests for the rearranger plugin. */ class RearrangerTest extends LightCodeInsightFixtureTestCase { - private RearrangerSettings mySettings - private JavaClassRuleBuilder classRule - private JavaInnerClassRuleBuilder innerClassRule - private JavaFieldRuleBuilder fieldRule - private JavaMethodRuleBuilder methodRule - private CommentRuleBuilder commentRule - private JavaSpacingRule spacingRule + private RearrangerSettings mySettings + private SettingsConfigurationBuilder settings + private JavaClassRuleBuilder classRule + private JavaInterfaceRuleBuilder interfaceRule + private JavaInnerClassRuleBuilder innerClassRule + private JavaFieldRuleBuilder fieldRule + private JavaMethodRuleBuilder methodRule + private CommentRuleBuilder commentRule + private JavaSpacingRule spacingRule @Override protected String getBasePath() { @@ -61,7 +67,13 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { mySettings.showRules = true mySettings.rearrangeInnerClasses = true + prepareBuilders(mySettings) + } + + private void prepareBuilders(RearrangerSettings mySettings) { + settings = new SettingsConfigurationBuilder(settings: mySettings) classRule = new JavaClassRuleBuilder(settings: mySettings) + interfaceRule = new JavaInterfaceRuleBuilder(settings: mySettings) innerClassRule = new JavaInnerClassRuleBuilder(settings: mySettings) fieldRule = new JavaFieldRuleBuilder(settings: mySettings) methodRule = new JavaMethodRuleBuilder(settings: mySettings) @@ -75,15 +87,13 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testPublicFieldRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult2') { - fieldRule.create { - modifier( PsiModifier.PUBLIC ) - } } } + fieldRule.modifier PsiModifier.PUBLIC + } } public final void testNotPublicFieldRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult3') { - fieldRule.create { - modifier( PsiModifier.PUBLIC, invert: true ) - } } } + fieldRule.modifier PsiModifier.PUBLIC, invert: true + } } public final void testConstructorRearrangement() throws Exception { doTest('RearrangementTest', 'RearrangementResult4') { @@ -151,12 +161,12 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testMultipleRuleCommentMatch() throws Exception { doTest('RearrangementTest11', 'RearrangementResult11') { - 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) } + commentRule.create { comment('// FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false) } + commentRule.create { comment('// FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, + 'subsequent rules to match': 1) } fieldRule.create { modifier(PsiModifier.FINAL) } - commentRule.create { comment('// NON-FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, - subsequentRulesToMatch: 1) } + commentRule.create { comment('// NON-FINAL FIELDS:', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, + 'subsequent rules to match': 1) } fieldRule.create { modifier(PsiModifier.FINAL, invert: true) } } } @@ -182,8 +192,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { 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) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, + 'subsequent rules to match': 2, 'preceding rules to match': 1) } fieldRule.create { modifier([ PsiModifier.PUBLIC, PsiModifier.STATIC, PsiModifier.FINAL ]) @@ -195,8 +205,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//************************************** PUBLIC FIELDS *****************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, - subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, + 'subsequent rules to match': 1, 'preceding rules to match': 1) } fieldRule.create { modifier( PsiModifier.PUBLIC ) @@ -204,8 +214,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//*********************************** PROTECTED/PACKAGE FIELDS **************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, - subsequentRulesToMatch: 3, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, + 'subsequent rules to match': 3, 'preceding rules to match': 1) } fieldRule.create { modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL, PsiModifier.STATIC, PsiModifier.FINAL ]) @@ -221,8 +231,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//************************************** PRIVATE FIELDS *****************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, - subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, + 'subsequent rules to match': 1, 'preceding rules to match': 1) } fieldRule.create { modifier( PsiModifier.PRIVATE ) @@ -230,8 +240,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//************************************** CONSTRUCTORS ************************************* ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: false, allPreceding: true, - subsequentRulesToMatch: 2, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, + 'subsequent rules to match': 2, 'preceding rules to match': 1) } methodRule.create { modifier( PsiModifier.PUBLIC ) @@ -240,8 +250,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { 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) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': false, 'all preceding': true, + 'subsequent rules to match': 2, 'preceding rules to match': 1) } methodRule.create { modifier( PsiModifier.PUBLIC ) @@ -257,8 +267,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { 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) + comment(text, condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, + 'subsequent rules to match': 1, 'preceding rules to match': 1) } methodRule.create { modifier( PsiModifier.PUBLIC ) @@ -266,8 +276,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//********************************* PACKAGE/PROTECTED METHODS ******************************** ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, - subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, + 'subsequent rules to match': 1, 'preceding rules to match': 1) } methodRule.create { modifier([ PsiModifier.PROTECTED, PsiModifier.PACKAGE_LOCAL ]) @@ -275,8 +285,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//************************************** PRIVATE METHODS *************************************', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, - subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, + 'subsequent rules to match': 1, 'preceding rules to match': 1) } methodRule.create { modifier( PsiModifier.PRIVATE ) @@ -284,8 +294,8 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } commentRule.create { comment('//************************************** INNER CLASSES ************************************* ', - condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, allSubsequent: true, allPreceding: true, - subsequentRulesToMatch: 1, precedingRulesToMatch: 1) + condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, 'all preceding': true, + 'subsequent rules to match': 1, 'preceding rules to match': 1) } innerClassRule.create { sort(SortType.BY_NAME ) } @@ -298,61 +308,46 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testReturnTypeMatch() throws Exception { doTest('RearrangementTest12', 'RearrangementResult12') { - methodRule.create { returnType( 'void' ) } - fieldRule.create { type( 'int' ) } - methodRule.create { returnType( '.*je.*' ) } - methodRule.create { returnType( /Integer\[\]/) } - methodRule.create { returnType( 'int' ) } + methodRule.create { 'return type'( 'void' ) } + fieldRule.create { type( 'int' ) } + methodRule.create { 'return type'( '.*je.*' ) } + methodRule.create { 'return type'( /Integer\[\]/) } + methodRule.create { 'return type'( 'int' ) } } } public final void testRelatedMethodsDepthOriginal() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13DO') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER + settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER ) } } public final void testRelatedMethodsDepthAlphabetical() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13DA') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.ALPHABETICAL_ORDER + settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.ALPHABETICAL_ORDER ) } } public final void testRelatedMethodsDepthInvocation() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13DI') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.INVOCATION_ORDER + settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.INVOCATION_ORDER ) } } public final void testRelatedMethodsBreadthOriginal() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13BO') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = false - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER + settings.'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER ) } } public final void testRelatedMethodsBreadthAlphabetical() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13BA') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = false - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.ALPHABETICAL_ORDER + settings.'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.ALPHABETICAL_ORDER) } } public final void testRelatedMethodsBreadthInvocation() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13BI') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = false - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.INVOCATION_ORDER + settings.'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.INVOCATION_ORDER) } } private void doTestEmitComments(args) { doTest(args.initial?: 'RearrangementTest13', args.expected) { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = args.depthFirst - mySettings.extractedMethodsSettings.ordering = args.orderType - mySettings.extractedMethodsSettings.commentType = args.commentType + settings.'extracted methods'( 'depth-first order': args.depthFirst, order: args.orderType, commentType: args.commentType ) def precedingCommentRule = new CommentRule() precedingCommentRule.commentText = '''\ @@ -373,98 +368,97 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testEmitTLCommentsRelatedMethodsBreadthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13BITLC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL + expected: 'RearrangementResult13BITLC', + depthFirst: false, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL ) } public final void testEmitEMCommentsRelatedMethodsBreadthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13BIEMC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD + expected: 'RearrangementResult13BIEMC', + depthFirst: false, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD ) } public final void testEmitELCommentsRelatedMethodsBreadthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13BIELC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL + expected: 'RearrangementResult13BIELC', + depthFirst: false, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL ) } public final void testEmitNFCommentsRelatedMethodsBreadthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13BINFC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY + expected: 'RearrangementResult13BINFC', + depthFirst: false, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY ) } public final void testEmitTLCommentsRelatedMethodsDepthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13DITLC', - depthFirst: true, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL + expected: 'RearrangementResult13DITLC', + depthFirst: true, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_TOP_LEVEL ) } public final void testEmitEMCommentsRelatedMethodsDepthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13DIEMC', - depthFirst: true, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD + expected: 'RearrangementResult13DIEMC', + depthFirst: true, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_METHOD ) } public final void testEmitELCommentsRelatedMethodsDepthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13BIELC', - depthFirst: false, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL + expected: 'RearrangementResult13BIELC', + depthFirst: false, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL ) } public final void testEmitNFCommentsRelatedMethodsDepthInvocation() throws Exception { doTestEmitComments( - expected: 'RearrangementResult13DINFC', - depthFirst: true, - orderType: RelatedMethodsSettings.INVOCATION_ORDER, - commentType: RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY + expected: 'RearrangementResult13DINFC', + depthFirst: true, + orderType: RelatedMethodsSettings.INVOCATION_ORDER, + commentType: RelatedMethodsSettings.COMMENT_TYPE_NEW_FAMILY ) } public final void testRelatedMethodsException() throws Exception { doTest('RearrangementTest13', 'RearrangementResult13Ex') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER + settings.'extracted methods'( 'depth-first order': true, order: RelatedMethodsSettings.RETAIN_ORIGINAL_ORDER ) methodRule.create { name('GF') } } } public final void testKeepOverloadedMethodsTogether() throws Exception { doTest('RearrangementTest14', 'RearrangementResult14') { - mySettings.extractedMethodsSettings.moveExtractedMethods = true - mySettings.extractedMethodsSettings.depthFirstOrdering = false - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.INVOCATION_ORDER - mySettings.keepOverloadedMethodsTogether = true - } } + settings.configure { + 'extracted methods'( 'depth-first order': false, order: RelatedMethodsSettings.INVOCATION_ORDER ) + 'keep together'( 'overloaded' ) + } } } public final void testXML() throws Exception { doTest('RearrangementTest17', 'RearrangementTest17', 'xml') } public final void testKeepGSTogether() throws Exception { doTest('RearrangementTest18', 'RearrangementResult18') { - mySettings.keepGettersSettersTogether = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.ALPHABETICAL_ORDER + settings.configure { + 'extracted methods'( order: RelatedMethodsSettings.INVOCATION_ORDER ) + 'keep together'( 'getters and setters' ) + } fieldRule.create {} methodRule.create { target( MethodType.CONSTRUCTOR ) } methodRule.create { @@ -474,9 +468,10 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testKeepGSWithProperty() throws Exception { doTest('RearrangementTest18', 'RearrangementResult18A') { - mySettings.keepGettersSettersTogether = true - mySettings.keepGettersSettersWithProperty = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.ALPHABETICAL_ORDER + settings.configure { + 'extracted methods'( order: RelatedMethodsSettings.ALPHABETICAL_ORDER ) + 'keep together'([ 'getters and setters', 'getters and setters with property' ]) + } fieldRule.create { } methodRule.create { target(MethodType.CONSTRUCTOR) } methodRule.create { @@ -486,16 +481,17 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testKeepGSWithPropertyElseTogether() throws Exception { doTest('RearrangementTest18B', 'RearrangementResult18B') { - mySettings.keepGettersSettersTogether = true - mySettings.keepGettersSettersWithProperty = true - mySettings.extractedMethodsSettings.ordering = RelatedMethodsSettings.ALPHABETICAL_ORDER + settings.configure { + 'extracted methods'( order: RelatedMethodsSettings.ALPHABETICAL_ORDER ) + 'keep together'([ 'getters and setters', 'getters and setters with property' ]) + } fieldRule.create { } commentRule.create { comment('// Getters/Setters', condition: CommentRule.EMIT_ALWAYS) } methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, body: GetterSetterDefinition.GETTER_BODY_IMMATERIAL ) @@ -511,23 +507,17 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { public final void testKeepOverloadsTogetherOriginalOrder() throws Exception { doTest('RearrangementTest19', 'RearrangementResult19A') { - mySettings.extractedMethodsSettings.moveExtractedMethods = false - mySettings.keepOverloadedMethodsTogether = true - mySettings.overloadedOrder = RearrangerSettings.OVERLOADED_ORDER_RETAIN_ORIGINAL + settings.'overloaded methods'( 'keep together': true, order: RearrangerSettings.OVERLOADED_ORDER_RETAIN_ORIGINAL ) } } public final void testKeepOverloadsTogetherAscendingOrder() throws Exception { doTest('RearrangementTest19', 'RearrangementResult19B') { - mySettings.extractedMethodsSettings.moveExtractedMethods = false - mySettings.keepOverloadedMethodsTogether = true - mySettings.overloadedOrder = RearrangerSettings.OVERLOADED_ORDER_ASCENDING_PARAMETERS + settings.'overloaded methods'( 'keep together': true, order: RearrangerSettings.OVERLOADED_ORDER_ASCENDING_PARAMETERS ) } } public final void testKeepOverloadsTogetherDescendingOrder() throws Exception { doTest('RearrangementTest19', 'RearrangementResult19C') { - mySettings.extractedMethodsSettings.moveExtractedMethods = false - mySettings.keepOverloadedMethodsTogether = true - mySettings.overloadedOrder = RearrangerSettings.OVERLOADED_ORDER_DESCENDING_PARAMETERS + settings.'overloaded methods'( 'keep together': true, order: RearrangerSettings.OVERLOADED_ORDER_DESCENDING_PARAMETERS ) } } public final void testInnerClassReferenceToChild() throws Exception { @@ -602,7 +592,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { doTest('GetterDefinitionTest', 'GetPrefixImmaterialResult') { methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, body: GetterSetterDefinition.GETTER_BODY_IMMATERIAL ) } } } @@ -611,7 +601,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { doTest('GetterDefinitionTest', 'GetPrefixReturnsResult') { methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, body: GetterSetterDefinition.GETTER_BODY_RETURNS ) } } } @@ -620,7 +610,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { doTest('GetterDefinitionTest', 'GetPrefixReturnsFieldResult') { methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, body: GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD ) } } } @@ -629,7 +619,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { doTest('GetterDefinitionTest', 'GetFieldReturnsResult') { methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD, body: GetterSetterDefinition.GETTER_BODY_RETURNS ) } } } @@ -638,7 +628,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { doTest('GetterDefinitionTest', 'GetFieldReturnsFieldResult') { methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_MATCHES_FIELD, body: GetterSetterDefinition.GETTER_BODY_RETURNS_FIELD ) } } } @@ -647,7 +637,7 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { doTest('RearrangementTest22', 'RearrangementResult22') { methodRule.create { target( MethodType.GETTER_OR_SETTER ) - getterCriteria( + 'getter criteria'( name: GetterSetterDefinition.GETTER_NAME_CORRECT_PREFIX, body: GetterSetterDefinition.GETTER_BODY_RETURNS ) @@ -658,500 +648,227 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { mySettings.keepGettersSettersTogether = true } } -// public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodAlphabetical() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(false); -// InterfaceAttributes ia = new InterfaceAttributes(); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Header ****/"); -// ia.setPrecedingComment(cr); -// cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Trailer ***/"); -// ia.setTrailingComment(cr); -// ia.setNoExtractedMethods(true); -// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ALPHABETICAL); -// ia.setAlphabetizeInterfaces(false); -// rs.addItem(ia, 0); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNNANXMA.java"); -// } -// -// public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(false); -// InterfaceAttributes ia = new InterfaceAttributes(); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Header ****/"); -// ia.setPrecedingComment(cr); -// cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Trailer ***/"); -// ia.setTrailingComment(cr); -// ia.setNoExtractedMethods(true); -// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); -// ia.setAlphabetizeInterfaces(false); -// rs.addItem(ia, 0); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNNANXME.java"); -// } -// -// public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodInterfaceOrder() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(false); -// InterfaceAttributes ia = new InterfaceAttributes(); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Header ****/"); -// ia.setPrecedingComment(cr); -// cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Trailer ***/"); -// ia.setTrailingComment(cr); -// ia.setNoExtractedMethods(true); -// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_INTERFACE_ORDER); -// ia.setAlphabetizeInterfaces(false); -// rs.addItem(ia, 0); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNNANXMI.java"); -// } -// -// public void testInterfaceByNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(false); -// InterfaceAttributes ia = new InterfaceAttributes(); -// ia.getNameAttr().setMatch(true); -// ia.getNameAttr().setExpression("IFace1"); -// ia.setNoExtractedMethods(true); -// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); -// ia.setAlphabetizeInterfaces(false); -// rs.addItem(ia, 0); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23BNNANXME.java"); -// } -// -// public void testInterfaceIsAlphabeticalNoExcludeMethodEncountered() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest23.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(false); -// InterfaceAttributes ia = new InterfaceAttributes(); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Header ****/"); -// ia.setPrecedingComment(cr); -// cr = new CommentRule(); -// cr.setCommentText("/**** Interface %IF% Trailer ***/"); -// ia.setTrailingComment(cr); -// ia.setNoExtractedMethods(true); -// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); -// ia.setAlphabetizeInterfaces(true); -// rs.addItem(ia, 0); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult23NNIANXME.java"); -// } -// -// public void testNPE24() throws Exception { -// // submitted by Nathan Brown. Caused NPE in Rearranger plugin version 1.7. -// int itemIndex = 0; -// configureByFile("/com/wrq/rearranger/RearrangementTest24.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(true); -// rs.setKeepOverloadedMethodsTogether(true); -//// rs.setAskBeforeRearranging(false); -// rs.setOverloadedOrder(1); -// rs.setGlobalCommentPattern(""); -// rs.setRemoveBlanksInsideCodeBlocks(false); -// FieldAttributes fa; -// fa = new FieldAttributes(); -// fa.getSortAttr().setByName(false); -// fa.getPlAttr().setPlPublic(true); -// fa.getPlAttr().setPlPrivate(true); -// fa.getPlAttr().setPlProtected(true); -// fa.getPlAttr().setPlPackage(true); -// fa.getPlAttr().setInvertProtectionLevel(false); -// fa.getStAttr().setValue(true); -// fa.getStAttr().setInvert(false); -// rs.addItem(fa, itemIndex++); -// fa = new FieldAttributes(); -// fa.getStAttr().setValue(true); -// fa.getStAttr().setInvert(true); -// fa.getInitToAnonClassAttr().setValue(true); -// fa.getInitToAnonClassAttr().setInvert(true); -// rs.addItem(fa, itemIndex++); -// fa = new FieldAttributes(); -// fa.getInitToAnonClassAttr().setValue(true); -// rs.addItem(fa, itemIndex++); -// MethodAttributes ma; -// ma = new MethodAttributes(); -// ma.getStaticInitAttr().setValue(true); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.setConstructorMethodType(true); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.getNameAttr().setMatch(true); -// ma.getNameAttr().setExpression("clone"); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.getNameAttr().setMatch(true); -// ma.getNameAttr().setExpression("dispose"); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.getNameAttr().setMatch(true); -// ma.getNameAttr().setExpression("_dispose"); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.getNameAttr().setMatch(true); -// ma.getNameAttr().setExpression("build"); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.getAbstractAttr().setValue(true); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.getStAttr().setValue(true); -// ma.getStAttr().setInvert(true); -// ma.getAbstractAttr().setValue(true); -// ma.getAbstractAttr().setInvert(true); -// ma.setOtherMethodType(true); -// rs.addItem(ma, itemIndex++); -// ma = new MethodAttributes(); -// ma.setGetterSetterMethodType(true); -// rs.addItem(ma, itemIndex++); -// InnerClassAttributes ica = new InnerClassAttributes(); -// rs.addItem(ica, itemIndex++); -// ma = new MethodAttributes(); -// ma.getStAttr().setValue(true); -// rs.addItem(ma, itemIndex); -// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); -// rs.getExtractedMethodsSettings().setBelowFirstCaller(false); -// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); -// rs.getExtractedMethodsSettings().setOrdering(0); -// rs.getExtractedMethodsSettings().setNonPrivateTreatment(2); -// rs.getExtractedMethodsSettings().setCommentType(0); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// } -// -// public void testSpacingOptions() throws Exception { -// /** -// * From Thomas Singer: -// * I've enabled -// * - Force 0 blank lines before class close brace "}" -// * - Force 0 blank lines before method close brace "}" -// * - Remove initial and final blank lines inside code block -// * but in the code below the blank lines don't get removed when invoking -// * Rearrager from editor's context menu: -// */ -// configureByFile("/com/wrq/rearranger/RearrangementTest25.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.getBeforeClassRBrace().setForce(true); -// rs.getBeforeClassRBrace().setnBlankLines(0); -// rs.getBeforeMethodRBrace().setForce(true); -// rs.getBeforeMethodRBrace().setnBlankLines(0); -// rs.setRemoveBlanksInsideCodeBlocks(true); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult25.java"); -// } -// -// public void testPriority() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// MethodAttributes ma; -// ma = new MethodAttributes(); -// ma.setPriority(1); -// rs.addItem(ma, 0); -// ma = new MethodAttributes(); -// ma.setPriority(2); -// ma.getNameAttr().setMatch(true); -// ma.getNameAttr().setExpression("method.*"); -// rs.addItem(ma, 1); -// ma = new MethodAttributes(); -// ma.setPriority(2); -// ma.getNameAttr().setMatch(true); -// ma.getNameAttr().setExpression(".*Method"); -// rs.addItem(ma, 2); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult1A.java"); -// } -// -// public void testGSRuleWithClassInitializer() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest26.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// MethodAttributes ma; -// ma = new MethodAttributes(); -// ma.setGetterSetterMethodType(true); -// rs.addItem(ma, 0); -// rs.setKeepGettersSettersTogether(true); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult26.java"); -// } -// -// public void testKeepGSTogetherAndExtractedMethods() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest27.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(true); -// rs.setKeepOverloadedMethodsTogether(true); -// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult27.java"); -// } -// -// public void testRegexEscape() throws Exception { -// String s = "// ********* start of fields *********"; -// String result = RegexUtil.escape(s); -// assertEquals("sequence reduction failed", "// \\*{9} start of fields \\*{9}", result); -// s = "// \\ backslash \n \t \\d [...] (^...$)"; -// result = RegexUtil.escape(s); -// assertEquals("special character escape failed", "// \\\\ backslash \\n \\t \\\\d \\[\\.\\.\\.\\]" + -// " \\(\\^\\.\\.\\.\\$\\)", result); -// } -// -// public void testRegexCombine() throws Exception { -// String p1 = RegexUtil.escape("// ********* start of fields *********"); -// String p2 = RegexUtil.escape("// ********* start of methods *********"); -// List list = new ArrayList(); -// list.add(p1); -// list.add(p2); -// String result = RegexUtil.combineExpressions(list); -// assertEquals("combination failed", "// \\*{9} start of (fiel|metho)ds \\*{9}", result); -// String p3 = RegexUtil.escape("// ***** start of interfaces *******"); -// list.add(p3); -// result = RegexUtil.combineExpressions(list); -// assertEquals("combination failed", "// (\\*{9} start of (fiel|metho)ds \\*{9}|" + -// "\\*{5} start of interfaces \\*{7})", result); -// } -// -// public void testVariousComments() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest28.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.setKeepGettersSettersTogether(true); -// rs.setKeepOverloadedMethodsTogether(true); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("// start of fields"); -// cr.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE); -// cr.setAllSubsequentRules(true); -// cr.setnSubsequentRulesToMatch(1); -// rs.addItem(cr, 0); -// FieldAttributes fa = new FieldAttributes(); -// rs.addItem(fa, 1); -// cr = new CommentRule(); -// cr.setCommentText("// end of fields"); -// cr.setEmitCondition(CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE); -// cr.setAllPrecedingRules(true); -// cr.setnPrecedingRulesToMatch(1); -// rs.addItem(cr, 2); -// InterfaceAttributes ia = new InterfaceAttributes(); -// ia.setMethodOrder(InterfaceAttributes.METHOD_ORDER_ENCOUNTERED); -// ia.setAlphabetizeInterfaces(false); -// ia.setNoExtractedMethods(false); -// cr = new CommentRule(); -// cr.setCommentText("// start of interface %IF%"); -// ia.setPrecedingComment(cr); -// cr = new CommentRule(); -// cr.setCommentText("// end of interface %IF%"); -// ia.setTrailingComment(cr); -// rs.addItem(ia, 3); -// rs.getExtractedMethodsSettings().setBelowFirstCaller(false); -// rs.getExtractedMethodsSettings().setMoveExtractedMethods(true); -// rs.getExtractedMethodsSettings().setCommentType(RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL); -// rs.getExtractedMethodsSettings().setNonPrivateTreatment(RelatedMethodsSettings.NON_PRIVATE_EXTRACTED_ANY_CALLERS); -// rs.getExtractedMethodsSettings().setDepthFirstOrdering(true); -// cr = new CommentRule(); -// cr.setCommentText("// Level %LV% methods"); -// rs.getExtractedMethodsSettings().setPrecedingComment(cr); -// cr = new CommentRule(); -// cr.setCommentText("// end Level %LV% methods"); -// rs.getExtractedMethodsSettings().setTrailingComment(cr); -// // should work with or without the global comment pattern -//// rs.setGlobalCommentPattern("// (((start|end) of (fields|interface [A-Za-z_0-9]+))|(end|)Level [0-9]+ methods)"); -// rah.rearrangeDocument(getProject(), file, rs, doc); // note - blank lines end up "reversed" -// // where a blank line, generated comment, and method occur in order; the generated comment is removed -// // and the blank line precedes the method; when the new comment is generated, it is inserted before -// // the blank line. -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult28.java"); -// } -// -// public void testParseBugInfiniteLoop() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest29.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementTest29.java"); -// } -// -// public void testSpacingBug() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest30.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.getAfterClassLBrace().setForce(true); -// rs.getAfterClassLBrace().setnBlankLines(0); -// rs.getAfterClassRBrace().setForce(true); -// rs.getAfterClassRBrace().setnBlankLines(1); -// rs.getAfterMethodLBrace().setForce(true); -// rs.getAfterMethodLBrace().setnBlankLines(0); -// rs.getAfterMethodRBrace().setForce(true); -// rs.getAfterMethodRBrace().setnBlankLines(1); -// rs.getBeforeClassRBrace().setForce(true); -// rs.getBeforeClassRBrace().setnBlankLines(0); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// rs.setRemoveBlanksInsideCodeBlocks(true); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult30.java"); -// } -// -// public void testSpacingBug2() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest31.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.getAfterClassLBrace().setForce(true); -// rs.getAfterClassLBrace().setnBlankLines(0); -// rs.getAfterClassRBrace().setForce(true); -// rs.getAfterClassRBrace().setnBlankLines(1); -// rs.getAfterMethodLBrace().setForce(true); -// rs.getAfterMethodLBrace().setnBlankLines(0); -// rs.getAfterMethodRBrace().setForce(true); -// rs.getAfterMethodRBrace().setnBlankLines(1); -// rs.getBeforeClassRBrace().setForce(true); -// rs.getBeforeClassRBrace().setnBlankLines(0); -// rs.getBeforeMethodRBrace().setForce(true); -// rs.getBeforeMethodRBrace().setnBlankLines(0); -// rs.setRemoveBlanksInsideCodeBlocks(true); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult31.java"); -// } -// -// public void testSpacingBug3() throws Exception { -// configureByFile("/com/wrq/rearranger/DomainExpanderTest.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rs.getAfterClassLBrace().setForce(true); -// rs.getAfterClassLBrace().setnBlankLines(0); -// rs.getAfterClassRBrace().setForce(true); -// rs.getAfterClassRBrace().setnBlankLines(1); -// rs.getAfterMethodLBrace().setForce(true); -// rs.getAfterMethodLBrace().setnBlankLines(0); -// rs.getAfterMethodRBrace().setForce(true); -// rs.getAfterMethodRBrace().setnBlankLines(0); -// rs.getBeforeClassRBrace().setForce(true); -// rs.getBeforeClassRBrace().setnBlankLines(0); -// rs.getBeforeMethodRBrace().setForce(true); -// rs.getBeforeMethodRBrace().setnBlankLines(0); -// rs.setRemoveBlanksInsideCodeBlocks(true); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/DomainExpanderResult.java"); -// } -// -// /** -// * Bug occurs when one or more blank lines precede a generated comment. -// * When comment is removed, blank lines now precede the item. Comment is inserted -// * at the beginning (i.e. before the blank lines) and a newline character is -// * prefixed to the comment. Net effect is that new blank line(s) appear after the comment. -// * -// * @throws Exception test exception -// */ -// public void testGeneratedCommentSpacingBug() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest32.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// rs = RearrangerSettings.getSettingsFromFile(new File(InteractiveTest.DEFAULT_CONFIGURATION)); -// rs.setAskBeforeRearranging(false); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult32.java"); -// } -// -// public void testGeneratedCommentSpacing() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest32.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// rs = RearrangerSettings.getSettingsFromFile(new File(InteractiveTest.DEFAULT_CONFIGURATION)); -// rs.setAskBeforeRearranging(false); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult32.java"); -// } -// -// public void testInnerClassComments() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest34.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// rs = RearrangerSettings.getSettingsFromFile(new File(InteractiveTest.DEFAULT_CONFIGURATION)); -// rs.setAskBeforeRearranging(false); -// rs.setRearrangeInnerClasses(true); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("// ----- OUTER CLASS -----\n"); -// rs.getClassOrderAttributeList().add(0, cr); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult34.java"); -// } -// -// public void testInnerClassCommentsNoRearrangement() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest34.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// rs = RearrangerSettings.getSettingsFromFile(new File(InteractiveTest.DEFAULT_CONFIGURATION)); -// rs.setAskBeforeRearranging(false); -// rs.setRearrangeInnerClasses(false); -// rs.getNewlinesAtEOF().setForce(true); -// rs.getNewlinesAtEOF().setnBlankLines(1); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("// ----- OUTER CLASS -----\n"); -// rs.getClassOrderAttributeList().add(0, cr); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult34B.java"); -// } -// -// public void testFirstInsertionOfComment() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest35.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// CommentRule cr = new CommentRule(); -// cr.setCommentText("// ----- FIELDS -----\n"); -// FieldAttributes fa = new FieldAttributes(); -// rs.addItem(cr, 0); -// rs.addItem(fa, 1); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult35.java"); -// } -// + public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodAlphabetical() throws Exception { + doTest('RearrangementTest23', 'RearrangementResult23NNNANXMA') { + mySettings.keepGettersSettersTogether = false + interfaceRule.create { + 'preceding comment'( '/**** Interface %IF% Header ****/' ) + 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) + setup( "don't group extracted methods": false, order: InterfaceAttributes.METHOD_ORDER_ALPHABETICAL, alphabetize: false ) + } } } + + public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { + doTest('RearrangementTest23', 'RearrangementResult23NNNANXME') { + mySettings.keepGettersSettersTogether = false + interfaceRule.create { + 'preceding comment'( '/**** Interface %IF% Header ****/' ) + 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) + setup( "don't group extracted methods": false, order: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, alphabetize: false ) + } } } + + public void testInterfaceNoNameNotAlphabeticalNoExcludeMethodInterfaceOrder() throws Exception { + doTest('RearrangementTest23', 'RearrangementResult23NNNANXMI') { + mySettings.keepGettersSettersTogether = false + interfaceRule.create { + 'preceding comment'( '/**** Interface %IF% Header ****/' ) + 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) + setup( "don't group extracted methods": false, order: InterfaceAttributes.METHOD_ORDER_INTERFACE_ORDER, alphabetize: false ) + } } } + + public void testInterfaceByNameNotAlphabeticalNoExcludeMethodEncountered() throws Exception { + doTest('RearrangementTest23', 'RearrangementResult23BNNANXME') { + mySettings.keepGettersSettersTogether = false + interfaceRule.setup( "don't group extracted methods": true, order: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, + alphabetize: false, name : 'IFace1' + ) } } + + public void testInterfaceIsAlphabeticalNoExcludeMethodEncountered() throws Exception { + doTest('RearrangementTest23', 'RearrangementResult23NNIANXME') { + interfaceRule.create { + 'preceding comment'( '/**** Interface %IF% Header ****/' ) + 'trailing comment'( '/**** Interface %IF% Trailer ***/' ) + setup( "don't group extracted methods": true, order: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, alphabetize: true ) + } } } + + public void testSpacingOptions() throws Exception { + /** + * From Thomas Singer: + * I've enabled + * - Force 0 blank lines before class close brace "}" + * - Force 0 blank lines before method close brace "}" + * - Remove initial and final blank lines inside code block + * but in the code below the blank lines don't get removed when invoking + * Rearranger from editor's context menu: + */ + doTest('RearrangementTest25', 'RearrangementResult25') { + spacingRule.spacing(anchor: [ SpacingAnchor.BEFORE_CLASS_RBRACE, SpacingAnchor.BEFORE_METHOD_RBRACE ], + lines: 0, 'remove blank lines': true + ) } } + + public void testPriority() throws Exception { + doTest('RearrangementTest', 'RearrangementResult1A') { + methodRule.create { priority( 1 ) } + methodRule.create { + priority( 2 ) + name( 'method.*' ) + } + methodRule.create { + priority( 2 ) + name( '.*Method' ) + } } } + + public void testGSRuleWithClassInitializer() throws Exception { + doTest('RearrangementTest26', 'RearrangementResult26') { + mySettings.keepOverloadedMethodsTogether = true + methodRule.create { + target( MethodType.GETTER_OR_SETTER ) + } } } + + public void testKeepGSTogetherAndExtractedMethods() throws Exception { + doTest('RearrangementTest27', 'RearrangementResult27') { + settings.configure { + 'keep together'([ 'getters and setters', 'overloaded' ]) + 'extracted methods' move: true + } } } + + public void testRegexEscape() throws Exception { + String s = "// ********* start of fields *********"; + String result = RegexUtil.escape(s); + assertEquals("sequence reduction failed", "// \\*{9} start of fields \\*{9}", result); + s = "// \\ backslash \n \t \\d [...] (^...\$)"; + result = RegexUtil.escape(s); + assertEquals("special character escape failed", "// \\\\ backslash \\n \\t \\\\d \\[\\.\\.\\.\\]" + + " \\(\\^\\.\\.\\.\\\$\\)", result); + } + + public void testRegexCombine() throws Exception { + String p1 = RegexUtil.escape("// ********* start of fields *********"); + String p2 = RegexUtil.escape("// ********* start of methods *********"); + List list = new ArrayList(); + list.add(p1); + list.add(p2); + String result = RegexUtil.combineExpressions(list); + assertEquals("combination failed", "// \\*{9} start of (fiel|metho)ds \\*{9}", result); + String p3 = RegexUtil.escape("// ***** start of interfaces *******"); + list.add(p3); + result = RegexUtil.combineExpressions(list); + assertEquals("combination failed", "// (\\*{9} start of (fiel|metho)ds \\*{9}|" + + "\\*{5} start of interfaces \\*{7})", result); + } + + public void testVariousComments() throws Exception { + doTest('RearrangementTest28', 'RearrangementResult28') { + settings.configure{ + 'keep together'([ 'getters and setters', 'overloaded' ]) + 'extracted methods'( 'depth-first order': true, commentType: RelatedMethodsSettings.COMMENT_TYPE_EACH_LEVEL, + 'below first caller': false, + 'non-private treatment': RelatedMethodsSettings.NON_PRIVATE_EXTRACTED_ANY_CALLERS, + 'preceding comment': '// Level %LV% methods', 'trailing comment': '// end Level %LV% methods' ) + } + commentRule.create { + comment('// start of fields', condition: CommentRule.EMIT_IF_ITEMS_MATCH_SUBSEQUENT_RULE, 'all subsequent': true, + 'subsequent rules to match': 1) + } + fieldRule.create { } + commentRule.create { + comment('// end of fields', condition: CommentRule.EMIT_IF_ITEMS_MATCH_PRECEDING_RULE, 'all preceding': true, + 'preceding rules to match': 1) + } + interfaceRule.configure { + 'preceding comment'( '// start of interface %IF%' ) + 'trailing comment'( '// end of interface %IF%' ) + setup( methodOrder: InterfaceAttributes.METHOD_ORDER_ENCOUNTERED, alphabetize: false, 'group extracted methods': false ) + } } + // where a blank line, generated comment, and method occur in order; the generated comment is removed + // and the blank line precedes the method; when the new comment is generated, it is inserted before + // the blank line. + } + + public void testParseBugInfiniteLoop() throws Exception { doTest('RearrangementTest29', 'RearrangementTest29') } + + public void testSpacingBug() throws Exception { + doTest('RearrangementTest30', 'RearrangementResult30') { + spacingRule.create { + spacing( anchor: [ SpacingAnchor.AFTER_CLASS_LBRACE, SpacingAnchor.AFTER_METHOD_LBRACE, SpacingAnchor.BEFORE_CLASS_RBRACE ], + lines: 0 ) + spacing( anchor: [ SpacingAnchor.AFTER_CLASS_RBRACE, SpacingAnchor.AFTER_METHOD_RBRACE, SpacingAnchor.EOF ], + lines: 1 ) + spacing ( 'remove blank lines': true ) + } } } + + public void testSpacingBug2() throws Exception { + doTest('RearrangementTest31', 'RearrangementResult31') { + spacingRule.create { + spacing( anchor: [ SpacingAnchor.AFTER_CLASS_LBRACE, SpacingAnchor.AFTER_METHOD_LBRACE, SpacingAnchor.BEFORE_CLASS_RBRACE, + SpacingAnchor.BEFORE_METHOD_RBRACE ], + lines: 0 ) + spacing( anchor: [ SpacingAnchor.AFTER_CLASS_RBRACE, SpacingAnchor.AFTER_METHOD_RBRACE, SpacingAnchor.EOF ], + lines: 1 ) + spacing ( 'remove blank lines': true ) + } } } + + public void testSpacingBug3() throws Exception { + doTest('DomainExpanderTest', 'DomainExpanderResult') { + spacingRule.create { + spacing( anchor: [ SpacingAnchor.AFTER_CLASS_LBRACE, SpacingAnchor.AFTER_METHOD_LBRACE, + SpacingAnchor.BEFORE_CLASS_RBRACE, SpacingAnchor.BEFORE_METHOD_RBRACE], + lines: 0 ) + spacing( anchor: [ SpacingAnchor.AFTER_CLASS_RBRACE, SpacingAnchor.EOF, SpacingAnchor.AFTER_METHOD_RBRACE ], + lines: 1 ) + spacing ( 'remove blank lines': true ) + } } } + + private void setupSettings(@NotNull String relativePath) { + // Using concat() because simple '+' here produces weird groovy.lang.MissingMethodException: No signature of method: + // java.lang.String.positive() is applicable for argument types: () values: [] + def path = PlatformTestUtil.getCommunityPath().replace(File.separator, '/').concat("/plugins/rearranger") + .concat(relativePath) + mySettings = RearrangerSettings.getSettingsFromFile(new File(path)); + mySettings.askBeforeRearranging = false + + prepareBuilders(mySettings) + } + + /** + * Bug occurs when one or more blank lines precede a generated comment. + * When comment is removed, blank lines now precede the item. Comment is inserted + * at the beginning (i.e. before the blank lines) and a newline character is + * prefixed to the comment. Net effect is that new blank line(s) appear after the comment. + * + * @throws Exception test exception + */ + public void testGeneratedCommentSpacingBug() throws Exception { + doTest('RearrangementTest32', 'RearrangementResult32') { + setupSettings(InteractiveTest.DEFAULT_CONFIGURATION) + spacingRule.spacing(anchor: SpacingAnchor.EOF, lines: 1) + } } + + public void testGeneratedCommentSpacing() throws Exception { + doTest('RearrangementTest32', 'RearrangementResult32') { + setupSettings(InteractiveTest.DEFAULT_CONFIGURATION) + spacingRule.spacing(anchor: SpacingAnchor.EOF, lines: 1) + } } + + public void testInnerClassComments() throws Exception { + doTest('RearrangementTest34', 'RearrangementResult34') { + setupSettings(InteractiveTest.DEFAULT_CONFIGURATION) + spacingRule.spacing(anchor: SpacingAnchor.EOF, lines: 1) + settings.configure( 'rearranger inner classes': true, 'class comment': '// ----- OUTER CLASS -----\n' ) + } } + + public void testInnerClassCommentsNoRearrangement() throws Exception { + doTest('RearrangementTest34', 'RearrangementResult34B') { + setupSettings(InteractiveTest.DEFAULT_CONFIGURATION) + spacingRule.spacing(anchor: SpacingAnchor.EOF, lines: 1) + settings.configure( 'rearranger inner classes': false, 'class comment': '// ----- OUTER CLASS -----\n' ) + } } + + public void testFirstInsertionOfComment() throws Exception { + doTest('RearrangementTest35', 'RearrangementResult35') { + commentRule.comment('// ----- FIELDS -----\n') + fieldRule.create { } + } } + // public void testExcludeFromExtraction() throws Exception { // configureByFile("/com/wrq/rearranger/RearrangementTest36.java"); // final PsiFile file = getFile(); diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy index 2b3452f0fe91..a9051a28862f 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/AbstractRuleBuilder.groovy @@ -18,6 +18,7 @@ import org.junit.Assert public abstract class AbstractRuleBuilder extends BuilderSupport { @NotNull def RearrangerSettings settings + private int depth /** * Holds rule customization handlers in the form {@code 'property id -> closure'} where 'property id' @@ -30,25 +31,33 @@ public abstract class AbstractRuleBuilder extends BuilderSupport { { key -> Assert.fail("No handler for the rule attribute '${key}'") } } + @Override + protected Object getCurrent() { + if (!super.current) { + current = createRule() + } + super.current + } + @Override protected void nodeCompleted(Object parent, Object node) { - if (!parent && node) { + if (--depth <= 0) { + // Top level call on the build object has been reached. registerRule(settings, node as T) + current = null } } @Override protected void setParent(Object parent, Object child) { + depth++ } @Override protected Object createNode(Object name) { - if (name == 'create') { - return createRule() - } createNode(name, [:], []) } - + @Override protected Object createNode(Object name, Object value) { createNode(name, [:], value) @@ -61,6 +70,9 @@ public abstract class AbstractRuleBuilder extends BuilderSupport { @Override protected Object createNode(Object name, Map attributes, Object value) { + if (!myHandlers.containsKey(name)) { + return current + } if (value) { for (i in [value].flatten()) { myHandlers[name](i, attributes, current) @@ -70,7 +82,7 @@ public abstract class AbstractRuleBuilder extends BuilderSupport { myHandlers[name](null, attributes, current) } - getCurrent() + current } @Nullable @@ -83,7 +95,7 @@ public abstract class AbstractRuleBuilder extends BuilderSupport { *

* Example: *

-   *   register('modifier', PsiModifier.FINAL, { rule, value, attributes ->
+   *   register('modifier', PsiModifier.FINAL, { value, attributes, rule ->
    *       rule.finalAttribute.value = value
    *       if (attributes.invert) rule.finalAttribute.invert = true
    *   })
@@ -143,10 +155,4 @@ public abstract class AbstractRuleBuilder extends BuilderSupport {
       rule."$propertyName".expression = value
     }
   }
-  
-  protected static void setIf(@NotNull RearrangerTestDsl dslProperty, map, rulePropertyName, rule) {
-    if (map.containsKey(dslProperty.value)) {
-      rule."$rulePropertyName" = map[dslProperty.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
index 80f06617fc57..868238943cc7 100644
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/CommentRuleBuilder.groovy
@@ -13,11 +13,11 @@ class CommentRuleBuilder extends AbstractRuleBuilder {
   {
     registerHandler(RearrangerTestDsl.COMMENT, { data, attributes, rule ->
       rule.commentText = data
-      setIf(RearrangerTestDsl.CONDITION, attributes, 'emitCondition', rule)
-      setIf(RearrangerTestDsl.ALL_SUBSEQUENT, attributes, 'allSubsequentRules', rule)
-      setIf(RearrangerTestDsl.ALL_PRECEDING, attributes, 'allPrecedingRules', rule)
-      setIf(RearrangerTestDsl.SUBSEQUENT_RULES_TO_MATCH, attributes, 'NSubsequentRulesToMatch', rule)
-      setIf(RearrangerTestDsl.PRECEDING_RULES_TO_MATCH, attributes, 'NPrecedingRulesToMatch', rule)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.CONDITION, attributes, 'emitCondition', rule)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.ALL_SUBSEQUENT, attributes, 'allSubsequentRules', rule)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.ALL_PRECEDING, attributes, 'allPrecedingRules', rule)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.SUBSEQUENT_RULES_TO_MATCH, attributes, 'NSubsequentRulesToMatch', rule)
+      RearrangerTestUtil.setIf(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 c6a46cbeb636..07bdde6296db 100644
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java
@@ -9,7 +9,19 @@ import org.jetbrains.annotations.NotNull;
  * @since 5/17/12 12:57 PM
  */
 public enum RearrangerTestDsl {
+
+  // Settings
+  EXTRACTED_METHODS("extracted methods"),
+  OVERLOADED_METHODS("overloaded methods"),
+  DEPTH_FIRST_ORDER("depth-first order"),
+  ORDER,
+  COMMENT_TYPE("commentType"),
+  KEEP_TOGETHER("keep together"),
+  OVERLOADED,
+  GETTERS_SETTERS("getters and setters"),
+  GETTERS_SETTERS_WITH_PROPERTY("getters and setters with property"),
   
+  // Rules
   NAME,
   MODIFIER,
   /** Field initializer type. */
@@ -17,23 +29,34 @@ public enum RearrangerTestDsl {
   /** Method target type (e.g. constructor). */
   TARGET,
   TYPE,
-  RETURN_TYPE("returnType"),
+  RETURN_TYPE("return type"),
   SORT,
   COMMENT,
-  GETTER_CRITERIA("getterCriteria"),
+  GETTER_CRITERIA("getter criteria"),
   SETTER_CRITERIA("setterCriteria"),
   SPACING,
+  PRECEDING_COMMENT("preceding comment"),
+  TRAILING_COMMENT("trailing comment"),
+  SETUP,
+  GROUP_EXTRACTED_METHODS("group extracted methods"),
+  ALPHABETIZE,
+  PRIORITY,
   
   // Attributes
   INVERT,
   CONDITION,
-  ALL_SUBSEQUENT("allSubsequent"),
-  ALL_PRECEDING("allPreceding"),
-  SUBSEQUENT_RULES_TO_MATCH("subsequentRulesToMatch"),
-  PRECEDING_RULES_TO_MATCH("precedingRulesToMatch"),
+  ALL_SUBSEQUENT("all subsequent"),
+  ALL_PRECEDING("all preceding"),
+  SUBSEQUENT_RULES_TO_MATCH("subsequent rules to match"),
+  PRECEDING_RULES_TO_MATCH("preceding rules to match"),
   BODY,
   ANCHOR,
-  BLANK_LINES("lines");
+  BLANK_LINES("lines"),
+  REMOVE_BLANK_LINES("remove blank lines"),
+  BELOW_FIRST_CALLER("below first caller"),
+  NON_PRIVATE_TREATMENT("non-private treatment"),
+  REARRANGE_INNER_CLASSES("rearranger inner classes"),
+  CLASS_COMMENT("class comment");
 
   @NotNull private final String myValue;
   
diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestUtil.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestUtil.groovy
new file mode 100644
index 000000000000..64e0dc28f6e3
--- /dev/null
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestUtil.groovy
@@ -0,0 +1,19 @@
+package com.wrq.rearranger.util
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Denis Zhdanov
+ * @since 5/22/12 11:11 AM
+ */
+public class RearrangerTestUtil {
+
+  private RearrangerTestUtil() {
+  }
+
+  public static void setIf(@NotNull RearrangerTestDsl dslProperty, map, rulePropertyName, rule) {
+    if (map.containsKey(dslProperty.value)) {
+      rule."$rulePropertyName" = map[dslProperty.value]
+    }
+  }
+}
diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/SettingsConfigurationBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/SettingsConfigurationBuilder.groovy
new file mode 100644
index 000000000000..fe06eb05731d
--- /dev/null
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/SettingsConfigurationBuilder.groovy
@@ -0,0 +1,81 @@
+package com.wrq.rearranger.util
+
+import com.wrq.rearranger.settings.CommentRule
+import com.wrq.rearranger.settings.RearrangerSettings
+
+import static com.wrq.rearranger.util.RearrangerTestUtil.setIf
+
+/**
+ * @author Denis Zhdanov
+ * @since 5/22/12 11:07 AM
+ */
+class SettingsConfigurationBuilder extends BuilderSupport {
+  
+  def RearrangerSettings settings
+  
+  @Override
+  protected void setParent(Object parent, Object child) {
+  }
+
+  @Override
+  protected Object createNode(Object name) {
+    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) {
+    def commentHandler = { RearrangerTestDsl dslName, propertyName ->
+      if (attributes.containsKey(dslName.value)) {
+        def comment = new CommentRule()
+        comment.commentText = attributes[dslName.value]
+        settings.extractedMethodsSettings."$propertyName" = comment
+      }
+    }
+    
+    switch (name) {
+      case RearrangerTestDsl.EXTRACTED_METHODS.value:
+        settings.extractedMethodsSettings.moveExtractedMethods = true
+        setIf(RearrangerTestDsl.DEPTH_FIRST_ORDER,     attributes, 'depthFirstOrdering',  settings.extractedMethodsSettings)
+        setIf(RearrangerTestDsl.ORDER,                 attributes, 'ordering',            settings.extractedMethodsSettings)
+        setIf(RearrangerTestDsl.COMMENT_TYPE,          attributes, 'commentType',         settings.extractedMethodsSettings)
+        setIf(RearrangerTestDsl.BELOW_FIRST_CALLER,    attributes, 'belowFirstCaller',    settings.extractedMethodsSettings)
+        setIf(RearrangerTestDsl.NON_PRIVATE_TREATMENT, attributes, 'nonPrivateTreatment', settings.extractedMethodsSettings)
+        
+        commentHandler(RearrangerTestDsl.PRECEDING_COMMENT, 'precedingComment')
+        commentHandler(RearrangerTestDsl.TRAILING_COMMENT,  'trailingComment')
+        break
+      case RearrangerTestDsl.KEEP_TOGETHER.value:
+        def m = [
+          (RearrangerTestDsl.OVERLOADED.value)                    : 'keepOverloadedMethodsTogether',
+          (RearrangerTestDsl.GETTERS_SETTERS.value)               : 'keepGettersSettersTogether',
+          (RearrangerTestDsl.GETTERS_SETTERS_WITH_PROPERTY.value) : 'keepGettersSettersWithProperty'
+        ]
+        for (i in [value].flatten()) {
+          settings."${m[i]}" = true
+        }
+        break
+      case RearrangerTestDsl.OVERLOADED_METHODS.value:
+        setIf(RearrangerTestDsl.ORDER,         attributes, 'overloadedOrder',               settings)
+        setIf(RearrangerTestDsl.KEEP_TOGETHER, attributes, 'keepOverloadedMethodsTogether', settings)
+        break
+      default:
+        setIf(RearrangerTestDsl.REARRANGE_INNER_CLASSES, attributes, 'rearrangeInnerClasses', settings)
+        if (attributes[RearrangerTestDsl.CLASS_COMMENT.value]) {
+          def comment = new CommentRule()
+          comment.commentText = attributes[RearrangerTestDsl.CLASS_COMMENT.value]
+          settings.classOrderAttributeList.add(0, comment)
+        }
+    }
+    settings
+  }
+}
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
index a7e53e599332..1ffbe3a767e2 100644
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/AbstractJavaRuleBuilder.groovy
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/AbstractJavaRuleBuilder.groovy
@@ -48,4 +48,9 @@ abstract class AbstractJavaRuleBuilder extends AbstractRuleBuilder {{
       genericHandlers[value](attributes, rule)
     }
   })
+  
+  // Priority.
+  registerHandler(RearrangerTestDsl.PRIORITY, { value, attributes, rule ->
+    rule.priority = value
+  })
 }}
diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInterfaceRuleBuilder.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInterfaceRuleBuilder.groovy
new file mode 100644
index 000000000000..083138816896
--- /dev/null
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaInterfaceRuleBuilder.groovy
@@ -0,0 +1,45 @@
+package com.wrq.rearranger.util.java
+
+import com.wrq.rearranger.settings.attributeGroups.InterfaceAttributes
+import com.wrq.rearranger.settings.RearrangerSettings
+import com.wrq.rearranger.util.RearrangerTestDsl
+import com.wrq.rearranger.settings.CommentRule
+import com.wrq.rearranger.util.RearrangerTestUtil
+
+/** 
+ * @author Denis Zhdanov
+ * @since 5/22/12 11:56 AM
+ */
+class JavaInterfaceRuleBuilder extends AbstractJavaRuleBuilder {
+  
+  {
+    def commentHandler = { rule, commentText, propertyName ->
+      def comment = new CommentRule()
+      comment.commentText = commentText
+      rule."$propertyName" = comment
+    }
+    
+    def nameHandler = createStringAttributeHandler('nameAttr')
+    
+    registerHandler(RearrangerTestDsl.PRECEDING_COMMENT, { value, attributes, rule -> commentHandler(rule, value, 'precedingComment') })
+    registerHandler(RearrangerTestDsl.TRAILING_COMMENT, { value, attributes, rule -> commentHandler(rule, value, 'trailingComment') })
+    registerHandler(RearrangerTestDsl.SETUP, { value, attributes, rule -> 
+      RearrangerTestUtil.setIf(RearrangerTestDsl.GROUP_EXTRACTED_METHODS, attributes, 'noExtractedMethods', rule)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.ORDER, attributes, 'methodOrder', rule)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.ALPHABETIZE, attributes, 'alphabetizeInterfaces', rule)
+      if (attributes[RearrangerTestDsl.NAME.value]) {
+        nameHandler(attributes[RearrangerTestDsl.NAME.value], attributes, rule)
+      }
+    })
+  }
+  
+  @Override
+  protected InterfaceAttributes createRule() {
+    new InterfaceAttributes()
+  }
+
+  @Override
+  protected void registerRule(RearrangerSettings settings, InterfaceAttributes 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
index c83323449342..8b7c40b76d67 100644
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaMethodRuleBuilder.groovy
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaMethodRuleBuilder.groovy
@@ -4,6 +4,7 @@ import com.wrq.rearranger.settings.RearrangerSettings
 import com.wrq.rearranger.settings.attributeGroups.MethodAttributes
 import org.jetbrains.annotations.NotNull
 import com.wrq.rearranger.util.RearrangerTestDsl
+import com.wrq.rearranger.util.RearrangerTestUtil
 
 /** 
  * @author Denis Zhdanov
@@ -20,12 +21,12 @@ class JavaMethodRuleBuilder extends AbstractJavaRuleBuilder {
     registerHandler(RearrangerTestDsl.TARGET, { data, attributes, rule -> handlers[data](attributes, rule) })
     registerHandler(RearrangerTestDsl.RETURN_TYPE, createStringAttributeHandler('returnTypeAttr'))
     registerHandler(RearrangerTestDsl.GETTER_CRITERIA, { data, attributes, rule ->
-      setIf(RearrangerTestDsl.NAME, attributes, 'getterNameCriterion', rule.getterSetterDefinition)
-      setIf(RearrangerTestDsl.BODY, attributes, 'getterBodyCriterion', rule.getterSetterDefinition)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.NAME, attributes, 'getterNameCriterion', rule.getterSetterDefinition)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.BODY, attributes, 'getterBodyCriterion', rule.getterSetterDefinition)
     })
     registerHandler(RearrangerTestDsl.SETTER_CRITERIA, { data, attributes, rule ->
-      setIf(RearrangerTestDsl.NAME, attributes, 'setterNameCriterion', rule.getterSetterDefinition)
-      setIf(RearrangerTestDsl.BODY, attributes, 'setterBodyCriterion', rule.getterSetterDefinition)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.NAME, attributes, 'setterNameCriterion', rule.getterSetterDefinition)
+      RearrangerTestUtil.setIf(RearrangerTestDsl.BODY, attributes, 'setterBodyCriterion', rule.getterSetterDefinition)
     })
   }
   
diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaSpacingRule.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaSpacingRule.groovy
index 559df6d97ae8..bcc99867d94a 100644
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaSpacingRule.groovy
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaSpacingRule.groovy
@@ -27,6 +27,9 @@ class JavaSpacingRule extends AbstractRuleBuilder {
         s.force = true
         s.nBlankLines = attributes[RearrangerTestDsl.BLANK_LINES.value]
       }
+      if (attributes[RearrangerTestDsl.REMOVE_BLANK_LINES.value]) {
+        settings.removeBlanksInsideCodeBlocks = true
+      }
     })
   }
   
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
index f31690cb7248..d02eb8148d04 100644
--- a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/MethodType.java
+++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/MethodType.java
@@ -5,5 +5,5 @@ package com.wrq.rearranger.util.java;
  * @since 5/17/12 11:05 AM
  */
 public enum MethodType {
-  CONSTRUCTOR, GETTER_OR_SETTER, OTHER
+  CONSTRUCTOR, GETTER_OR_SETTER, OVERLOADED, OTHER
 }
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23BNNANXME.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23BNNANXME.java
index 4e7bf76cd622..3bf2004df185 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23BNNANXME.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23BNNANXME.java
@@ -1,6 +1,7 @@
 public class RearrangementTest23
   implements IFace2, IFace1
 {
+
   public int getY() {
     return 6;
   }
@@ -8,7 +9,6 @@ public class RearrangementTest23
   public int getX() {
     return getA() ? 5 : 3;
   }
-
   int method1() {
     return 4;
   }
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNIANXME.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNIANXME.java
index 73e08795186f..ef00945287f0 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNIANXME.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNIANXME.java
@@ -1,7 +1,8 @@
 public class RearrangementTest23
   implements IFace2, IFace1
 {
-  /** * Interface IFace1 Header *** */
+/**** Interface IFace1 Header ****/
+
   public int getY() {
     return 6;
   }
@@ -10,7 +11,8 @@ public class RearrangementTest23
     return getA() ? 5 : 3;
   }
 /**** Interface IFace1 Trailer ***/
-  /** * Interface IFace2 Header *** */
+/**** Interface IFace2 Header ****/
+
   public boolean getB() {
     return false;
   }
@@ -18,8 +20,7 @@ public class RearrangementTest23
   public boolean getA() {
     return true;
   }
-
-  /** * Interface IFace2 Trailer ** */
+/**** Interface IFace2 Trailer ***/
   int method1() {
     return 4;
   }
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMA.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMA.java
index 22a6c10e38e7..4f0b0b8ea0e1 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMA.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMA.java
@@ -1,7 +1,8 @@
 public class RearrangementTest23
   implements IFace2, IFace1
 {
-  /** * Interface IFace2 Header *** */
+/**** Interface IFace2 Header ****/
+
   public boolean getA() {
     return true;
   }
@@ -10,7 +11,8 @@ public class RearrangementTest23
     return false;
   }
 /**** Interface IFace2 Trailer ***/
-  /** * Interface IFace1 Header *** */
+/**** Interface IFace1 Header ****/
+
   public int getX() {
     return getA() ? 5 : 3;
   }
@@ -18,8 +20,7 @@ public class RearrangementTest23
   public int getY() {
     return 6;
   }
-
-  /** * Interface IFace1 Trailer ** */
+/**** Interface IFace1 Trailer ***/
   int method1() {
     return 4;
   }
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXME.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXME.java
index f903e3e5cc05..7e52e4923324 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXME.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXME.java
@@ -1,7 +1,8 @@
 public class RearrangementTest23
   implements IFace2, IFace1
 {
-  /** * Interface IFace2 Header *** */
+/**** Interface IFace2 Header ****/
+
   public boolean getB() {
     return false;
   }
@@ -10,7 +11,8 @@ public class RearrangementTest23
     return true;
   }
 /**** Interface IFace2 Trailer ***/
-  /** * Interface IFace1 Header *** */
+/**** Interface IFace1 Header ****/
+
   public int getY() {
     return 6;
   }
@@ -18,8 +20,7 @@ public class RearrangementTest23
   public int getX() {
     return getA() ? 5 : 3;
   }
-
-  /** * Interface IFace1 Trailer ** */
+/**** Interface IFace1 Trailer ***/
   int method1() {
     return 4;
   }
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMI.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMI.java
index 8088b74fa28a..1ab483ac4f6e 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMI.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult23NNNANXMI.java
@@ -1,7 +1,8 @@
 public class RearrangementTest23
   implements IFace2, IFace1
 {
-  /** * Interface IFace2 Header *** */
+/**** Interface IFace2 Header ****/
+
   public boolean getA() {
     return true;
   }
@@ -10,7 +11,8 @@ public class RearrangementTest23
     return false;
   }
 /**** Interface IFace2 Trailer ***/
-  /** * Interface IFace1 Header *** */
+/**** Interface IFace1 Header ****/
+
   public int getY() {
     return 6;
   }
@@ -18,8 +20,7 @@ public class RearrangementTest23
   public int getX() {
     return getA() ? 5 : 3;
   }
-
-  /** * Interface IFace1 Trailer ** */
+/**** Interface IFace1 Trailer ***/
   int method1() {
     return 4;
   }
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult26.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult26.java
index fd22dd84a491..6145ad5a6868 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult26.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult26.java
@@ -7,7 +7,6 @@ class RearrangementTest26 {
   public void setValue(int i) {
     value = i;
   }
-
   int value;
 
   {
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult28.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult28.java
index f7382377292c..ef4bc4993913 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult28.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult28.java
@@ -1,37 +1,32 @@
 public class RearrangementTest28
   implements InterfaceName, InterfaceName2
 {
-  // start of fields
+// start of fields
   int i;
-
-  // end of fields
+// end of fields
 // start of interface InterfaceName
 // Level 1 methods
   public int getTime() {
     return getAnother();
   }
-
-  // Level 2 methods
+// Level 2 methods
   public int getAnother() {
     return 0;
   }
-
-  // end Level 2 methods
+// end Level 2 methods
 // end Level 1 methods
 // end of interface InterfaceName
 // start of interface InterfaceName2
   public int getDate() {
     return 0;
   }
-
-  // end of interface InterfaceName2
+// end of interface InterfaceName2
 // Level 1 methods
   public void m1() {
     m2();
     m3();
   }
-
-  // Level 2 methods
+// Level 2 methods
   public void m2() {
   }
 
diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementTest32.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementTest32.java
index 58d1b54e6d63..b89ab41d9237 100644
--- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementTest32.java
+++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementTest32.java
@@ -1,5 +1,7 @@
 public class Temp {
-  // ------------------------------ FIELDS ------------------------------
+
+// ------------------------------ FIELDS ------------------------------
+
   int field1;
 
 // -------------------------- OTHER METHODS --------------------------