1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-02-15 20:34:58 -08:00
parent 183fe7ba62
commit aab2dfc32b

View file

@ -31,7 +31,6 @@ import org.eclipse.cdt.core.tests.BaseTestFramework;
import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory; import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory;
/** /**
* @author markus.schorn@windriver.com * @author markus.schorn@windriver.com
*/ */
@ -67,21 +66,21 @@ public class RefactoringTests extends BaseTestFramework {
protected void assertTotalChanges(int numChanges, int potChanges, int commentCh, protected void assertTotalChanges(int numChanges, int potChanges, int commentCh,
Change changes) throws Exception { Change changes) throws Exception {
int count[]= {0,0,0}; int count[]= {0,0,0};
if( changes != null ) { if (changes != null) {
countChanges( changes, count); countChanges(changes, count);
} }
assertEquals( numChanges, count[0] ); assertEquals(numChanges, count[0]);
assertEquals("potential changes: ", potChanges, count[1]); //$NON-NLS-1$ assertEquals("potential changes: ", potChanges, count[1]); //$NON-NLS-1$
assertEquals("comment changes: ", commentCh, count[2]); //$NON-NLS-1$ assertEquals("comment changes: ", commentCh, count[2]); //$NON-NLS-1$
} }
private void countChanges(Change change, int[] count) { private void countChanges(Change change, int[] count) {
if( change instanceof CompositeChange ){ if (change instanceof CompositeChange) {
Change [] children = ((CompositeChange) change).getChildren(); Change[] children = ((CompositeChange) change).getChildren();
for( int i = 0; i < children.length; i++ ){ for (int i = 0; i < children.length; i++) {
countChanges( children[i], count); countChanges(children[i], count);
} }
} else if( change instanceof TextFileChange ){ } else if (change instanceof TextFileChange) {
TextFileChange tfc= (TextFileChange) change; TextFileChange tfc= (TextFileChange) change;
TextEditChangeGroup[] tecgs= tfc.getTextEditChangeGroups(); TextEditChangeGroup[] tecgs= tfc.getTextEditChangeGroups();
for (int i = 0; i < tecgs.length; i++) { for (int i = 0; i < tecgs.length; i++) {
@ -95,11 +94,9 @@ public class RefactoringTests extends BaseTestFramework {
String name= edit.getName(); String name= edit.getName();
if (name.indexOf("potential") != -1) { //$NON-NLS-1$ if (name.indexOf("potential") != -1) { //$NON-NLS-1$
count[1]++; count[1]++;
} } else if (name.indexOf("comment") != -1) { //$NON-NLS-1$
else if (name.indexOf("comment") != -1) { //$NON-NLS-1$
count[2]++; count[2]++;
} } else {
else {
count[0]++; count[0]++;
} }
} }
@ -110,29 +107,29 @@ public class RefactoringTests extends BaseTestFramework {
protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText, boolean potential) throws Exception { protected void assertChange(Change changes, IFile file, int startOffset, int numChars, String newText, boolean potential) throws Exception {
boolean found = false; boolean found = false;
if( changes != null && changes instanceof CompositeChange ){ if (changes != null && changes instanceof CompositeChange) {
found = checkCompositeChange( (CompositeChange) changes, file, startOffset, numChars, newText, potential); found = checkCompositeChange((CompositeChange) changes, file, startOffset, numChars, newText, potential);
} }
if( !found ) { if (!found) {
fail ("Rename at offset " + startOffset + " in \"" + file.getLocation() + "\" not found."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ fail ("Rename at offset " + startOffset + " in \"" + file.getLocation() + "\" not found."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
assertFalse( true ); assertFalse(true);
} }
} }
private boolean checkCompositeChange(CompositeChange composite, IFile file, int startOffset, int numChars, String newText, boolean potential) { private boolean checkCompositeChange(CompositeChange composite, IFile file, int startOffset, int numChars, String newText, boolean potential) {
boolean found = false; boolean found = false;
Change [] children = composite.getChildren(); Change[] children = composite.getChildren();
for( int i = 0; i < children.length; i++ ){ for (int i = 0; i < children.length; i++) {
if( children[i] instanceof CompositeChange ) if (children[i] instanceof CompositeChange) {
found = checkCompositeChange( (CompositeChange) children[i], file, startOffset, numChars, newText, potential); found = checkCompositeChange((CompositeChange) children[i], file, startOffset, numChars, newText, potential);
else if( children[i] instanceof TextFileChange ){ } else if (children[i] instanceof TextFileChange) {
TextFileChange tuChange = (TextFileChange) children[i]; TextFileChange tuChange = (TextFileChange) children[i];
if( tuChange.getFile().toString().equals( file.toString() ) ){ if (tuChange.getFile().toString().equals(file.toString())) {
found = checkTranslationUnitChange( tuChange, startOffset, numChars, newText, potential ); found = checkTranslationUnitChange(tuChange, startOffset, numChars, newText, potential);
} }
} }
if( found ) if (found)
return found; return found;
} }
return found; return found;
@ -158,9 +155,8 @@ public class RefactoringTests extends BaseTestFramework {
startOffset, numChars, newText)) { startOffset, numChars, newText)) {
return true; return true;
} }
} } else if (edit instanceof ReplaceEdit) {
else if (edit instanceof ReplaceEdit) { if (checkReplaceEdit((ReplaceEdit) edit, startOffset, numChars, newText)) {
if (checkReplaceEdit((ReplaceEdit) edit, startOffset, numChars, newText ) ) {
return true; return true;
} }
} }
@ -178,77 +174,77 @@ public class RefactoringTests extends BaseTestFramework {
} }
private boolean checkReplaceEdit(ReplaceEdit edit, int startOffset, int numChars, String newText) { private boolean checkReplaceEdit(ReplaceEdit edit, int startOffset, int numChars, String newText) {
return ( edit.getOffset() == startOffset && edit.getLength() == numChars && edit.getText().equals( newText ) ); return (edit.getOffset() == startOffset && edit.getLength() == numChars && edit.getText().equals(newText ) );
} }
protected IFile createCppFwdDecls(String fileName) throws Exception { protected IFile createCppFwdDecls(String fileName) throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "class class_fwd; \n"); //$NON-NLS-1$ writer.write("class class_fwd; \n"); //$NON-NLS-1$
writer.write( "struct struct_fwd; \n"); //$NON-NLS-1$ writer.write("struct struct_fwd; \n"); //$NON-NLS-1$
writer.write( "union union_fwd; \n"); //$NON-NLS-1$ writer.write("union union_fwd; \n"); //$NON-NLS-1$
writer.write( "int func_proto(); \n"); //$NON-NLS-1$ writer.write("int func_proto(); \n"); //$NON-NLS-1$
writer.write( "int func_proto_ov(); \n"); //$NON-NLS-1$ writer.write("int func_proto_ov(); \n"); //$NON-NLS-1$
writer.write( "int func_proto_ov(int); \n"); //$NON-NLS-1$ writer.write("int func_proto_ov(int); \n"); //$NON-NLS-1$
writer.write( "int func_proto_ov(int*); \n"); //$NON-NLS-1$ writer.write("int func_proto_ov(int*); \n"); //$NON-NLS-1$
writer.write( "extern int extern_var; \n"); //$NON-NLS-1$ writer.write("extern int extern_var; \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = writer.toString();
return importFile(fileName, contents ); return importFile(fileName, contents );
} }
protected IFile createCFwdDecls(String fileName) throws Exception { protected IFile createCFwdDecls(String fileName) throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "struct struct_fwd; \n"); //$NON-NLS-1$ writer.write("struct struct_fwd; \n"); //$NON-NLS-1$
writer.write( "union union_fwd; \n"); //$NON-NLS-1$ writer.write("union union_fwd; \n"); //$NON-NLS-1$
writer.write( "int func_proto(); \n"); //$NON-NLS-1$ writer.write("int func_proto(); \n"); //$NON-NLS-1$
writer.write( "extern int extern_var; \n"); //$NON-NLS-1$ writer.write("extern int extern_var; \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = writer.toString();
return importFile(fileName, contents ); return importFile(fileName, contents );
} }
protected IFile createCppDefs(String fileName) throws Exception { protected IFile createCppDefs(String fileName) throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "class class_def { \n"); //$NON-NLS-1$ writer.write("class class_def { \n"); //$NON-NLS-1$
writer.write( "public: \n"); //$NON-NLS-1$ writer.write("public: \n"); //$NON-NLS-1$
writer.write( " int member; \n"); //$NON-NLS-1$ writer.write(" int member; \n"); //$NON-NLS-1$
writer.write( " static int static_member; \n"); //$NON-NLS-1$ writer.write(" static int static_member; \n"); //$NON-NLS-1$
writer.write( " void method(int par); \n"); //$NON-NLS-1$ writer.write(" void method(int par); \n"); //$NON-NLS-1$
writer.write( " void static_method(int par); \n"); //$NON-NLS-1$ writer.write(" void static_method(int par); \n"); //$NON-NLS-1$
writer.write( " int method_ov(); \n"); //$NON-NLS-1$ writer.write(" int method_ov(); \n"); //$NON-NLS-1$
writer.write( " int method_ov(int); \n"); //$NON-NLS-1$ writer.write(" int method_ov(int); \n"); //$NON-NLS-1$
writer.write( " int method_ov(int*); \n"); //$NON-NLS-1$ writer.write(" int method_ov(int*); \n"); //$NON-NLS-1$
writer.write( "}; \n"); //$NON-NLS-1$ writer.write("}; \n"); //$NON-NLS-1$
writer.write( "struct struct_def { \n"); //$NON-NLS-1$ writer.write("struct struct_def { \n"); //$NON-NLS-1$
writer.write( " int st_member; \n"); //$NON-NLS-1$ writer.write(" int st_member; \n"); //$NON-NLS-1$
writer.write( "}; \n"); //$NON-NLS-1$ writer.write("}; \n"); //$NON-NLS-1$
writer.write( "union union_def { \n"); //$NON-NLS-1$ writer.write("union union_def { \n"); //$NON-NLS-1$
writer.write( " int un_member; \n"); //$NON-NLS-1$ writer.write(" int un_member; \n"); //$NON-NLS-1$
writer.write( "}; \n"); //$NON-NLS-1$ writer.write("}; \n"); //$NON-NLS-1$
writer.write( "typedef int typedef_def; \n"); //$NON-NLS-1$ writer.write("typedef int typedef_def; \n"); //$NON-NLS-1$
writer.write( "namespace namespace_def{}; \n"); //$NON-NLS-1$ writer.write("namespace namespace_def{}; \n"); //$NON-NLS-1$
writer.write( "enum enum_def { \n"); //$NON-NLS-1$ writer.write("enum enum_def { \n"); //$NON-NLS-1$
writer.write( " enum_item }; \n"); //$NON-NLS-1$ writer.write(" enum_item }; \n"); //$NON-NLS-1$
writer.write( "int func_def() {} \n"); //$NON-NLS-1$ writer.write("int func_def() {} \n"); //$NON-NLS-1$
writer.write( "int func_def_ov() {} \n"); //$NON-NLS-1$ writer.write("int func_def_ov() {} \n"); //$NON-NLS-1$
writer.write( "int func_def_ov(int){} \n"); //$NON-NLS-1$ writer.write("int func_def_ov(int){} \n"); //$NON-NLS-1$
writer.write( "int func_def_ov(int*){} \n"); //$NON-NLS-1$ writer.write("int func_def_ov(int*){} \n"); //$NON-NLS-1$
writer.write( "int var_def; \n"); //$NON-NLS-1$ writer.write("int var_def; \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = writer.toString();
return importFile(fileName, contents ); return importFile(fileName, contents );
} }
protected IFile createCDefs(String fileName) throws Exception { protected IFile createCDefs(String fileName) throws Exception {
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
writer.write( "struct struct_def { \n"); //$NON-NLS-1$ writer.write("struct struct_def { \n"); //$NON-NLS-1$
writer.write( " int st_member; \n"); //$NON-NLS-1$ writer.write(" int st_member; \n"); //$NON-NLS-1$
writer.write( "}; \n"); //$NON-NLS-1$ writer.write("}; \n"); //$NON-NLS-1$
writer.write( "union union_def { \n"); //$NON-NLS-1$ writer.write("union union_def { \n"); //$NON-NLS-1$
writer.write( " int un_member; \n"); //$NON-NLS-1$ writer.write(" int un_member; \n"); //$NON-NLS-1$
writer.write( "}; \n"); //$NON-NLS-1$ writer.write("}; \n"); //$NON-NLS-1$
writer.write( "typedef int typedef_def; \n"); //$NON-NLS-1$ writer.write("typedef int typedef_def; \n"); //$NON-NLS-1$
writer.write( "enum enum_def { \n"); //$NON-NLS-1$ writer.write("enum enum_def { \n"); //$NON-NLS-1$
writer.write( " enum_item }; \n"); //$NON-NLS-1$ writer.write(" enum_item }; \n"); //$NON-NLS-1$
writer.write( "int func_def() {} \n"); //$NON-NLS-1$ writer.write("int func_def() {} \n"); //$NON-NLS-1$
writer.write( "int var_def; \n"); //$NON-NLS-1$ writer.write("int var_def; \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = writer.toString();
return importFile(fileName, contents ); return importFile(fileName, contents );
} }
@ -270,5 +266,4 @@ public class RefactoringTests extends BaseTestFramework {
status.getMessageMatchingSeverity(status.getSeverity()), status.getMessageMatchingSeverity(status.getSeverity()),
status.getSeverity()==RefactoringStatus.OK); status.getSeverity()==RefactoringStatus.OK);
} }
} }