From e26b7ebd04509dd6752943a1b2e1c2151c6e57bf Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Fri, 18 May 2012 12:53:44 +0400 Subject: [PATCH] IDEA-19061 Integrate the Rearranger-plugin into core-IDEA *) test DSL for the field type and method return type has been added; *) more tests have been refactored and enabled; --- .../com/wrq/rearranger/entry/MethodEntry.java | 8 +- .../settings/RearrangerSettings.java | 30 +++---- .../com/wrq/rearranger/RearrangerTest.groovy | 82 ++++++++++--------- .../rearranger/util/RearrangerTestDsl.java | 2 + .../util/java/JavaFieldRuleBuilder.groovy | 1 + .../util/java/JavaMethodRuleBuilder.groovy | 1 + .../OpsBlockingQueueIndentedResult.java | 11 +-- .../wrq/rearranger/RearrangementResult12.java | 5 +- 8 files changed, 71 insertions(+), 69 deletions(-) diff --git a/plugins/rearranger/src/com/wrq/rearranger/entry/MethodEntry.java b/plugins/rearranger/src/com/wrq/rearranger/entry/MethodEntry.java index 7826d6946b24..4734ba867a2b 100644 --- a/plugins/rearranger/src/com/wrq/rearranger/entry/MethodEntry.java +++ b/plugins/rearranger/src/com/wrq/rearranger/entry/MethodEntry.java @@ -1050,11 +1050,9 @@ public class MethodEntry extends ClassContentsEntry implements RelatableEntry { return; } createAlternateValueString(); - /** - * we don't want to check for comments in the body of the method. So reduce the alternate value string - * to only that text up to and including the open brace. Temporarily remove the rest of the text; append - * it again after checking for comments. - */ + // We don't want to check for comments in the body of the method. So reduce the alternate value string + // to only that text up to and including the open brace. Temporarily remove the rest of the text; append + // it again after checking for comments. int brace = myAlternateValue.indexOf('{'); String temp = ""; if (brace >= 0) { diff --git a/plugins/rearranger/src/com/wrq/rearranger/settings/RearrangerSettings.java b/plugins/rearranger/src/com/wrq/rearranger/settings/RearrangerSettings.java index 632e3f81788c..786676f8d68b 100644 --- a/plugins/rearranger/src/com/wrq/rearranger/settings/RearrangerSettings.java +++ b/plugins/rearranger/src/com/wrq/rearranger/settings/RearrangerSettings.java @@ -361,7 +361,7 @@ public final class RearrangerSettings { // Level 2 methods public void setGlobalCommentPattern(String globalCommentPattern) { - this.myGlobalCommentPattern = globalCommentPattern; + myGlobalCommentPattern = globalCommentPattern; } // end of Level 2 methods @@ -384,7 +384,7 @@ public final class RearrangerSettings { // Level 2 methods public void setOverloadedOrder(int overloadedOrder) { - this.myOverloadedOrder = overloadedOrder; + myOverloadedOrder = overloadedOrder; } // end of Level 2 methods @@ -403,7 +403,7 @@ public final class RearrangerSettings { // Level 2 methods public void setAskBeforeRearranging(boolean askBeforeRearranging) { - this.myAskBeforeRearranging = askBeforeRearranging; + myAskBeforeRearranging = askBeforeRearranging; } public boolean isKeepGettersSettersTogether() { @@ -413,7 +413,7 @@ public final class RearrangerSettings { // Level 2 methods public void setKeepGettersSettersTogether(boolean keepGettersSettersTogether) { - this.myKeepGettersSettersTogether = keepGettersSettersTogether; + myKeepGettersSettersTogether = keepGettersSettersTogether; } public boolean isKeepGettersSettersWithProperty() { @@ -421,7 +421,7 @@ public final class RearrangerSettings { } public void setKeepGettersSettersWithProperty(boolean keepGettersSettersWithProperty) { - this.myKeepGettersSettersWithProperty = keepGettersSettersWithProperty; + myKeepGettersSettersWithProperty = keepGettersSettersWithProperty; } // end of Level 2 methods // end of Level 1 methods @@ -434,7 +434,7 @@ public final class RearrangerSettings { // Level 2 methods public void setKeepOverloadedMethodsTogether(boolean keepOverloadedMethodsTogether) { - this.myKeepOverloadedMethodsTogether = keepOverloadedMethodsTogether; + myKeepOverloadedMethodsTogether = keepOverloadedMethodsTogether; } // end of Level 2 methods @@ -445,7 +445,7 @@ public final class RearrangerSettings { } public void setRearrangeInnerClasses(boolean rearrangeInnerClasses) { - this.myRearrangeInnerClasses = rearrangeInnerClasses; + myRearrangeInnerClasses = rearrangeInnerClasses; } // end of Level 2 methods @@ -459,7 +459,7 @@ public final class RearrangerSettings { // Level 2 methods public void setRemoveBlanksInsideCodeBlocks(boolean removeBlanksInsideCodeBlocks) { - this.myRemoveBlanksInsideCodeBlocks = removeBlanksInsideCodeBlocks; + myRemoveBlanksInsideCodeBlocks = removeBlanksInsideCodeBlocks; } public boolean isShowComments() { @@ -467,7 +467,7 @@ public final class RearrangerSettings { } public void setShowComments(boolean showComments) { - this.myShowComments = showComments; + myShowComments = showComments; } // end of Level 2 methods @@ -481,7 +481,7 @@ public final class RearrangerSettings { // Level 2 methods public void setShowFields(boolean showFields) { - this.myShowFields = showFields; + myShowFields = showFields; } public boolean isShowMatchedRules() { @@ -489,7 +489,7 @@ public final class RearrangerSettings { } public void setShowMatchedRules(boolean showMatchedRules) { - this.myShowMatchedRules = showMatchedRules; + myShowMatchedRules = showMatchedRules; } public boolean isShowParameterNames() { @@ -499,7 +499,7 @@ public final class RearrangerSettings { // Level 2 methods public void setShowParameterNames(boolean showParameterNames) { - this.myShowParameterNames = showParameterNames; + myShowParameterNames = showParameterNames; } // end of Level 2 methods @@ -513,7 +513,7 @@ public final class RearrangerSettings { // Level 2 methods public void setShowParameterTypes(boolean showParameterTypes) { - this.myShowParameterTypes = showParameterTypes; + myShowParameterTypes = showParameterTypes; } // end of Level 2 methods @@ -524,7 +524,7 @@ public final class RearrangerSettings { } public void setShowRules(boolean showRules) { - this.myShowRules = showRules; + myShowRules = showRules; } // end of Level 2 methods @@ -534,7 +534,7 @@ public final class RearrangerSettings { } public void setShowTypeAfterMethod(boolean showTypeAfterMethod) { - this.myShowTypeAfterMethod = showTypeAfterMethod; + myShowTypeAfterMethod = showTypeAfterMethod; } // ------------------------ CANONICAL METHODS ------------------------ diff --git a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy index 07f2c8ff1fda..7dfdf2233035 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/RearrangerTest.groovy @@ -160,15 +160,13 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { testOpsBlockingQueueExampleWorker(false, "OpsBlockingQueue", false, "OpsBlockingQueue"); } -// public final void testOpsBlockingQueueExampleWithGlobalPattern() throws Exception { -// testOpsBlockingQueueExampleWorker(true, "/com/wrq/rearranger/OpsBlockingQueue.java", -// false, "/com/wrq/rearranger/OpsBlockingQueue.java"); -// } -// -// public final void testOpsBlockingQueueExampleWithIndentedComments() throws Exception { -// testOpsBlockingQueueExampleWorker(false, "/com/wrq/rearranger/OpsBlockingQueueIndented.java", -// true, "/com/wrq/rearranger/OpsBlockingQueueIndentedResult.java"); -// } + public final void testOpsBlockingQueueExampleWithGlobalPattern() throws Exception { + testOpsBlockingQueueExampleWorker(true, "OpsBlockingQueue", false, "OpsBlockingQueue"); + } + + public final void testOpsBlockingQueueExampleWithIndentedComments() throws Exception { + testOpsBlockingQueueExampleWorker(false, "OpsBlockingQueueIndented", true, "OpsBlockingQueueIndentedResult"); + } private void testOpsBlockingQueueExampleWorker(boolean doGlobalPattern, String srcFilename, @@ -294,36 +292,42 @@ class RearrangerTest extends LightCodeInsightFixtureTestCase { } } -// public final void testReturnTypeMatch() throws Exception { -// configureByFile("/com/wrq/rearranger/RearrangementTest12.java"); -// final PsiFile file = getFile(); -// final Document doc = PsiDocumentManager.getInstance(getProject()).getDocument(file); -// MethodAttributes ma; -// ma = new MethodAttributes(); -// ma.getReturnTypeAttr().setMatch(true); -// ma.getReturnTypeAttr().setExpression("void"); -// rs.addItem(ma, 0); -// FieldAttributes fa = new FieldAttributes(); -// fa.getTypeAttr().setMatch(true); -// fa.getTypeAttr().setExpression("int"); -// rs.addItem(fa, 1); -// ma = new MethodAttributes(); -// ma.getReturnTypeAttr().setMatch(true); -// ma.getReturnTypeAttr().setExpression(".*je.*"); -// rs.addItem(ma, 2); -// ma = new MethodAttributes(); -// ma.getReturnTypeAttr().setMatch(true); -// ma.getReturnTypeAttr().setExpression("Integer\\[\\]"); -// rs.addItem(ma, 3); -// ma = new MethodAttributes(); -// ma.getReturnTypeAttr().setMatch(true); -// ma.getReturnTypeAttr().setExpression("int"); -// rs.addItem(ma, 4); -// final RearrangerActionHandler rah = new RearrangerActionHandler(); -// rah.rearrangeDocument(getProject(), file, rs, doc); -// super.checkResultByFile("/com/wrq/rearranger/RearrangementResult12.java"); -// } -// + 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' ) } + } + + + //MethodAttributes ma; + //ma = new MethodAttributes(); + //ma.getReturnTypeAttr().setMatch(true); + //ma.getReturnTypeAttr().setExpression("void"); + //rs.addItem(ma, 0); + //FieldAttributes fa = new FieldAttributes(); + //fa.getTypeAttr().setMatch(true); + //fa.getTypeAttr().setExpression("int"); + //rs.addItem(fa, 1); + //ma = new MethodAttributes(); + //ma.getReturnTypeAttr().setMatch(true); + //ma.getReturnTypeAttr().setExpression(".*je.*"); + //rs.addItem(ma, 2); + //ma = new MethodAttributes(); + //ma.getReturnTypeAttr().setMatch(true); + //ma.getReturnTypeAttr().setExpression("Integer\\[\\]"); + //rs.addItem(ma, 3); + //ma = new MethodAttributes(); + //ma.getReturnTypeAttr().setMatch(true); + //ma.getReturnTypeAttr().setExpression("int"); + //rs.addItem(ma, 4); + //final RearrangerActionHandler rah = new RearrangerActionHandler(); + //rah.rearrangeDocument(getProject(), file, rs, doc); + //super.checkResultByFile("/com/wrq/rearranger/RearrangementResult12.java"); + } + // public final void testRelatedMethodsDepthOriginal() throws Exception { // configureByFile("/com/wrq/rearranger/RearrangementTest13.java"); // final PsiFile file = getFile(); 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 58a58b7ac408..ab7ae00aa5f3 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/RearrangerTestDsl.java @@ -16,6 +16,8 @@ public enum RearrangerTestDsl { INITIALIZER, /** Method target type (e.g. constructor). */ TARGET, + TYPE, + RETURN_TYPE("returnType"), SORT, COMMENT, 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 index d093c65bb0d9..13d5f2865b8c 100644 --- a/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaFieldRuleBuilder.groovy +++ b/plugins/rearranger/test/src/com/wrq/rearranger/util/java/JavaFieldRuleBuilder.groovy @@ -14,6 +14,7 @@ class JavaFieldRuleBuilder extends AbstractJavaRuleBuilder { { def handlers = [(InitializerType.ANONYMOUS_CLASS) : createBooleanAttributeHandler('initialisedByAnonymousClassAttr')] registerHandler(RearrangerTestDsl.INITIALIZER, { data, attributes, rule -> handlers[data](attributes, rule) }) + registerHandler(RearrangerTestDsl.TYPE, createStringAttributeHandler('typeAttr')) } @Override 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 68fdece9d412..a59998417dc6 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 @@ -18,6 +18,7 @@ class JavaMethodRuleBuilder extends AbstractJavaRuleBuilder { (MethodType.OTHER) : createRawBooleanAttributeHandler('otherMethodType') ] registerHandler(RearrangerTestDsl.TARGET, { data, attributes, rule -> handlers[data](attributes, rule) }) + registerHandler(RearrangerTestDsl.RETURN_TYPE, createStringAttributeHandler('returnTypeAttr')) } @Override diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueueIndentedResult.java b/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueueIndentedResult.java index a8ba010d2f51..fcda3831105d 100644 --- a/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueueIndentedResult.java +++ b/plugins/rearranger/test/testData/com/wrq/rearranger/OpsBlockingQueueIndentedResult.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 METHODS LINE 2 public void put(Object obj) { synchronized (putLock) { @@ -61,8 +59,7 @@ public class OpsBlockingQueue extends OpsNonBlockingQueue { } } } - - //********************************* PACKAGE/PROTECTED METHODS ******************************** +//********************************* PACKAGE/PROTECTED METHODS ******************************** protected Object takeNext() { synchronized (takeLock) { return super.takeNext(); diff --git a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult12.java b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult12.java index fdcee3db5fb1..096c4c224c67 100644 --- a/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult12.java +++ b/plugins/rearranger/test/testData/com/wrq/rearranger/RearrangementResult12.java @@ -1,9 +1,9 @@ class RearrangementTest12 { + void method(int y) { x = y; } - - int x; + int x; Object convertX() { return new Integer(x); @@ -16,6 +16,5 @@ class RearrangementTest12 { int getX() { return x; } - String s; } \ No newline at end of file