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;
This commit is contained in:
Denis.Zhdanov
2012-05-18 12:54:01 +04:00
parent 89be43e504
commit e26b7ebd04
8 changed files with 71 additions and 69 deletions
@@ -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) {
@@ -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 ------------------------
@@ -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();
@@ -16,6 +16,8 @@ public enum RearrangerTestDsl {
INITIALIZER,
/** Method target type (e.g. constructor). */
TARGET,
TYPE,
RETURN_TYPE("returnType"),
SORT,
COMMENT,
@@ -14,6 +14,7 @@ class JavaFieldRuleBuilder extends AbstractJavaRuleBuilder<FieldAttributes> {
{
def handlers = [(InitializerType.ANONYMOUS_CLASS) : createBooleanAttributeHandler('initialisedByAnonymousClassAttr')]
registerHandler(RearrangerTestDsl.INITIALIZER, { data, attributes, rule -> handlers[data](attributes, rule) })
registerHandler(RearrangerTestDsl.TYPE, createStringAttributeHandler('typeAttr'))
}
@Override
@@ -18,6 +18,7 @@ class JavaMethodRuleBuilder extends AbstractJavaRuleBuilder<MethodAttributes> {
(MethodType.OTHER) : createRawBooleanAttributeHandler('otherMethodType')
]
registerHandler(RearrangerTestDsl.TARGET, { data, attributes, rule -> handlers[data](attributes, rule) })
registerHandler(RearrangerTestDsl.RETURN_TYPE, createStringAttributeHandler('returnTypeAttr'))
}
@Override
@@ -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();
@@ -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;
}