1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-12-15 14:48:58 -08:00
parent 77c0f78b4f
commit 5cd381dfe8
13 changed files with 3757 additions and 3760 deletions

View file

@ -24,18 +24,13 @@ import java.net.URI;
*/ */
public interface IIndexFileLocation { public interface IIndexFileLocation {
/** /**
* The URI of the indexed file. * Returns the URI of the indexed file (non-{@code null}).
*
* @return the URI of the indexed file (non-{@code null})
*/ */
public URI getURI(); public URI getURI();
/** /**
* Returns the workspace relative path of the indexed file or {@code null} if the file * Returns the workspace relative path of the file in the index or {@code null} if the file
* is not in the workspace. * is not in the workspace.
*
* @return the workspace relative path of the file in the index, or null if the
* file is not in the workspace
*/ */
public String getFullPath(); public String getFullPath();
} }

View file

@ -1,13 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2005, 2008 Wind River Systems, Inc. * Copyright (c) 2005, 2008 Wind River Systems, Inc.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
******************************************************************************/ ******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename; package org.eclipse.cdt.ui.tests.refactoring.rename;
import java.io.StringWriter; import java.io.StringWriter;
@ -63,15 +63,15 @@ public class RefactoringTests extends BaseTestFramework {
assertTotalChanges(numChanges, 0, 0, changes); assertTotalChanges(numChanges, 0, 0, changes);
} }
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]);
assertEquals("comment changes: ", commentCh, count[2]); //$NON-NLS-1$ assertEquals("comment changes: ", commentCh, count[2]);
} }
private void countChanges(Change change, int[] count) { private void countChanges(Change change, int[] count) {
@ -92,9 +92,9 @@ public class RefactoringTests extends BaseTestFramework {
private void countChanges(TextEditChangeGroup edit, int[] count) { private void countChanges(TextEditChangeGroup edit, int[] count) {
String name= edit.getName(); String name= edit.getName();
if (name.indexOf("potential") != -1) { //$NON-NLS-1$ if (name.indexOf("potential") != -1) {
count[1]++; count[1]++;
} else if (name.indexOf("comment") != -1) { //$NON-NLS-1$ } else if (name.indexOf("comment") != -1) {
count[2]++; count[2]++;
} else { } else {
count[0]++; count[0]++;
@ -110,9 +110,9 @@ public class RefactoringTests extends BaseTestFramework {
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.");
assertFalse(true); assertFalse(true);
} }
} }
@ -139,7 +139,7 @@ public class RefactoringTests extends BaseTestFramework {
TextEditChangeGroup[] groups= change.getTextEditChangeGroups(); TextEditChangeGroup[] groups= change.getTextEditChangeGroups();
for (int i = 0; i < groups.length; i++) { for (int i = 0; i < groups.length; i++) {
TextEditGroup group = groups[i].getTextEditGroup(); TextEditGroup group = groups[i].getTextEditGroup();
if ((group.getName().indexOf("potential") != -1) == potential) { //$NON-NLS-1$ if ((group.getName().indexOf("potential") != -1) == potential) {
TextEdit[] edits= group.getTextEdits(); TextEdit[] edits= group.getTextEdits();
if (checkTextEdits(edits, startOffset, numChars, newText)) { if (checkTextEdits(edits, startOffset, numChars, newText)) {
return true; return true;
@ -151,7 +151,7 @@ public class RefactoringTests extends BaseTestFramework {
private boolean checkTextEdit(TextEdit edit, int startOffset, int numChars, String newText) { private boolean checkTextEdit(TextEdit edit, int startOffset, int numChars, String newText) {
if (edit instanceof MultiTextEdit) { if (edit instanceof MultiTextEdit) {
if (checkTextEdits(((MultiTextEdit) edit).getChildren(), if (checkTextEdits(((MultiTextEdit) edit).getChildren(),
startOffset, numChars, newText)) { startOffset, numChars, newText)) {
return true; return true;
} }
@ -176,94 +176,94 @@ 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");
writer.write("struct struct_fwd; \n"); //$NON-NLS-1$ writer.write("struct struct_fwd; \n");
writer.write("union union_fwd; \n"); //$NON-NLS-1$ writer.write("union union_fwd; \n");
writer.write("int func_proto(); \n"); //$NON-NLS-1$ writer.write("int func_proto(); \n");
writer.write("int func_proto_ov(); \n"); //$NON-NLS-1$ writer.write("int func_proto_ov(); \n");
writer.write("int func_proto_ov(int); \n"); //$NON-NLS-1$ writer.write("int func_proto_ov(int); \n");
writer.write("int func_proto_ov(int*); \n"); //$NON-NLS-1$ writer.write("int func_proto_ov(int*); \n");
writer.write("extern int extern_var; \n"); //$NON-NLS-1$ writer.write("extern int extern_var; \n");
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");
writer.write("union union_fwd; \n"); //$NON-NLS-1$ writer.write("union union_fwd; \n");
writer.write("int func_proto(); \n"); //$NON-NLS-1$ writer.write("int func_proto(); \n");
writer.write("extern int extern_var; \n"); //$NON-NLS-1$ writer.write("extern int extern_var; \n");
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");
writer.write("public: \n"); //$NON-NLS-1$ writer.write("public: \n");
writer.write(" int member; \n"); //$NON-NLS-1$ writer.write(" int member; \n");
writer.write(" static int static_member; \n"); //$NON-NLS-1$ writer.write(" static int static_member; \n");
writer.write(" void method(int par); \n"); //$NON-NLS-1$ writer.write(" void method(int par); \n");
writer.write(" void static_method(int par); \n"); //$NON-NLS-1$ writer.write(" void static_method(int par); \n");
writer.write(" int method_ov(); \n"); //$NON-NLS-1$ writer.write(" int method_ov(); \n");
writer.write(" int method_ov(int); \n"); //$NON-NLS-1$ writer.write(" int method_ov(int); \n");
writer.write(" int method_ov(int*); \n"); //$NON-NLS-1$ writer.write(" int method_ov(int*); \n");
writer.write("}; \n"); //$NON-NLS-1$ writer.write("}; \n");
writer.write("struct struct_def { \n"); //$NON-NLS-1$ writer.write("struct struct_def { \n");
writer.write(" int st_member; \n"); //$NON-NLS-1$ writer.write(" int st_member; \n");
writer.write("}; \n"); //$NON-NLS-1$ writer.write("}; \n");
writer.write("union union_def { \n"); //$NON-NLS-1$ writer.write("union union_def { \n");
writer.write(" int un_member; \n"); //$NON-NLS-1$ writer.write(" int un_member; \n");
writer.write("}; \n"); //$NON-NLS-1$ writer.write("}; \n");
writer.write("typedef int typedef_def; \n"); //$NON-NLS-1$ writer.write("typedef int typedef_def; \n");
writer.write("namespace namespace_def{}; \n"); //$NON-NLS-1$ writer.write("namespace namespace_def{}; \n");
writer.write("enum enum_def { \n"); //$NON-NLS-1$ writer.write("enum enum_def { \n");
writer.write(" enum_item }; \n"); //$NON-NLS-1$ writer.write(" enum_item }; \n");
writer.write("int func_def() {} \n"); //$NON-NLS-1$ writer.write("int func_def() {} \n");
writer.write("int func_def_ov() {} \n"); //$NON-NLS-1$ writer.write("int func_def_ov() {} \n");
writer.write("int func_def_ov(int){} \n"); //$NON-NLS-1$ writer.write("int func_def_ov(int){} \n");
writer.write("int func_def_ov(int*){} \n"); //$NON-NLS-1$ writer.write("int func_def_ov(int*){} \n");
writer.write("int var_def; \n"); //$NON-NLS-1$ writer.write("int var_def; \n");
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");
writer.write(" int st_member; \n"); //$NON-NLS-1$ writer.write(" int st_member; \n");
writer.write("}; \n"); //$NON-NLS-1$ writer.write("}; \n");
writer.write("union union_def { \n"); //$NON-NLS-1$ writer.write("union union_def { \n");
writer.write(" int un_member; \n"); //$NON-NLS-1$ writer.write(" int un_member; \n");
writer.write("}; \n"); //$NON-NLS-1$ writer.write("}; \n");
writer.write("typedef int typedef_def; \n"); //$NON-NLS-1$ writer.write("typedef int typedef_def; \n");
writer.write("enum enum_def { \n"); //$NON-NLS-1$ writer.write("enum enum_def { \n");
writer.write(" enum_item }; \n"); //$NON-NLS-1$ writer.write(" enum_item }; \n");
writer.write("int func_def() {} \n"); //$NON-NLS-1$ writer.write("int func_def() {} \n");
writer.write("int var_def; \n"); //$NON-NLS-1$ writer.write("int var_def; \n");
String contents = writer.toString(); String contents = writer.toString();
return importFile(fileName, contents ); return importFile(fileName, contents );
} }
protected void assertRefactoringError(RefactoringStatus status, String msg) { protected void assertRefactoringError(RefactoringStatus status, String msg) {
RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.ERROR); RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.ERROR);
assertNotNull("Expected refactoring error!", e); //$NON-NLS-1$ assertNotNull("Expected refactoring error!", e);
assertEquals(msg, e.getMessage()); assertEquals(msg, e.getMessage());
} }
protected void assertRefactoringWarning(RefactoringStatus status, String msg) { protected void assertRefactoringWarning(RefactoringStatus status, String msg) {
RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.WARNING); RefactoringStatusEntry e= status.getEntryMatchingSeverity(RefactoringStatus.WARNING);
assertNotNull("Expected refactoring warning!", e); //$NON-NLS-1$ assertNotNull("Expected refactoring warning!", e);
assertEquals(msg, e.getMessage()); assertEquals(msg, e.getMessage());
} }
protected void assertRefactoringOk(RefactoringStatus status) { protected void assertRefactoringOk(RefactoringStatus status) {
assertTrue("Expected refactoring status ok: " + //$NON-NLS-1$ assertTrue("Expected refactoring status ok: " +
status.getMessageMatchingSeverity(status.getSeverity()), status.getMessageMatchingSeverity(status.getSeverity()),
status.getSeverity()==RefactoringStatus.OK); status.getSeverity() == RefactoringStatus.OK);
} }
} }

View file

@ -7,7 +7,7 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename; package org.eclipse.cdt.ui.tests.refactoring.rename;
@ -29,211 +29,211 @@ public class RenameMacroTests extends RenameTestBase {
} }
public static Test suite(boolean cleanup) { public static Test suite(boolean cleanup) {
TestSuite suite = new TestSuite(RenameMacroTests.class); TestSuite suite = new TestSuite(RenameMacroTests.class);
if (cleanup) { if (cleanup) {
suite.addTest(new RefactoringTests("cleanupProject")); //$NON-NLS-1$ suite.addTest(new RefactoringTests("cleanupProject"));
} }
return suite; return suite;
} }
public void testMacroRename() throws Exception { public void testMacroRename() throws Exception {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("#define HALLO x \n"); //$NON-NLS-1$ buf.append("#define HALLO x \n");
buf.append("class v1 { \n"); //$NON-NLS-1$ buf.append("class v1 { \n");
buf.append(" int HALLO; \n"); //$NON-NLS-1$ buf.append(" int HALLO; \n");
buf.append("}; \n"); //$NON-NLS-1$ buf.append("}; \n");
buf.append("class HALLO { \n"); //$NON-NLS-1$ buf.append("class HALLO { \n");
buf.append(" int v; \n"); //$NON-NLS-1$ buf.append(" int v; \n");
buf.append("}; \n"); //$NON-NLS-1$ buf.append("}; \n");
buf.append("class v3 { \n"); //$NON-NLS-1$ buf.append("class v3 { \n");
buf.append(" int v; \n"); //$NON-NLS-1$ buf.append(" int v; \n");
buf.append("}; \n"); //$NON-NLS-1$ buf.append("}; \n");
buf.append("class v4 { \n"); //$NON-NLS-1$ buf.append("class v4 { \n");
buf.append(" int HALLO(); \n"); //$NON-NLS-1$ buf.append(" int HALLO(); \n");
buf.append("}; \n"); //$NON-NLS-1$ buf.append("}; \n");
buf.append("int v4::HALLO(){} \n"); //$NON-NLS-1$ buf.append("int v4::HALLO(){} \n");
buf.append("void f(int par1){ \n"); //$NON-NLS-1$ buf.append("void f(int par1){ \n");
buf.append(" { \n"); //$NON-NLS-1$ buf.append(" { \n");
buf.append(" int HALLO; v1::v++; \n"); //$NON-NLS-1$ buf.append(" int HALLO; v1::v++; \n");
buf.append(" } \n"); //$NON-NLS-1$ buf.append(" } \n");
buf.append("} \n"); //$NON-NLS-1$ buf.append("} \n");
String contents = buf.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents);
int offset1= contents.indexOf("HALLO"); //$NON-NLS-1$ int offset1= contents.indexOf("HALLO");
int offset2= contents.indexOf("HALLO", offset1 + 1); //$NON-NLS-1$ int offset2= contents.indexOf("HALLO", offset1 + 1);
Change ch= getRefactorChanges(cpp, offset1, "WELT"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "WELT");
assertTotalChanges(6, ch); assertTotalChanges(6, ch);
int off= offset1; int off= offset1;
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$ ch= getRefactorChanges(cpp, offset2, "WELT");
assertTotalChanges(6, ch); assertTotalChanges(6, ch);
off= offset1; off= offset1;
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT");
off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ off= contents.indexOf("HALLO", off + 1);
} }
public void testMacroNameConflicts() throws Exception { public void testMacroNameConflicts() throws Exception {
createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$ createCppFwdDecls("cpp_fwd.hh");
createCppDefs("cpp_def.hh"); //$NON-NLS-1$ createCppDefs("cpp_def.hh");
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$ buf.append("#include \"cpp_fwd.hh\" \n");
buf.append("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$ buf.append("#include \"cpp_def.hh\" \n");
buf.append("#define MACRO 1 \n"); //$NON-NLS-1$ buf.append("#define MACRO 1 \n");
buf.append("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$ buf.append("int v1(); int v2(); int v3(); \n");
buf.append("static int s1(); \n"); //$NON-NLS-1$ buf.append("static int s1(); \n");
buf.append("static int s2(); \n"); //$NON-NLS-1$ buf.append("static int s2(); \n");
buf.append("void f(int par1){ \n"); //$NON-NLS-1$ buf.append("void f(int par1){ \n");
buf.append(" int w1; v1(); \n"); //$NON-NLS-1$ buf.append(" int w1; v1(); \n");
buf.append(" extern_var; \n"); //$NON-NLS-1$ buf.append(" extern_var; \n");
buf.append(" var_def; \n"); //$NON-NLS-1$ buf.append(" var_def; \n");
buf.append(" enum_item; \n"); //$NON-NLS-1$ buf.append(" enum_item; \n");
buf.append("} \n"); //$NON-NLS-1$ buf.append("} \n");
String contents = buf.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents);
buf = new StringBuilder(); buf = new StringBuilder();
buf.append("static int static_other_file(); \n"); //$NON-NLS-1$ buf.append("static int static_other_file(); \n");
importFile("other.cpp", buf.toString()); //$NON-NLS-1$ importFile("other.cpp", buf.toString());
waitForIndexer(); waitForIndexer();
int offset1= contents.indexOf("MACRO"); //$NON-NLS-1$ int offset1= contents.indexOf("MACRO");
// conflicts after renaming // conflicts after renaming
RefactoringStatus status= checkConditions(cpp, offset1, "w1"); //$NON-NLS-1$ RefactoringStatus status= checkConditions(cpp, offset1, "w1");
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" + assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
"Type of problem: Name conflict \n" + "Type of problem: Name conflict \n" +
"New element: w1 \n" + "New element: w1 \n" +
"Conflicting element type: Local variable"); //$NON-NLS-1$ "Conflicting element type: Local variable");
status= checkConditions(cpp, contents.indexOf("par1"), "MACRO"); //$NON-NLS-1$ //$NON-NLS-2$ status= checkConditions(cpp, contents.indexOf("par1"), "MACRO");
assertRefactoringError(status, "'MACRO' conflicts with the name of an existing macro."); //$NON-NLS-1$ assertRefactoringError(status, "'MACRO' conflicts with the name of an existing macro.");
status= checkConditions(cpp, offset1, "par1"); //$NON-NLS-1$ status= checkConditions(cpp, offset1, "par1");
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" + assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
"Type of problem: Name conflict \n" + "Type of problem: Name conflict \n" +
"New element: par1 \n" + "New element: par1 \n" +
"Conflicting element type: Parameter"); //$NON-NLS-1$ "Conflicting element type: Parameter");
status= checkConditions(cpp, offset1, "extern_var"); //$NON-NLS-1$ status= checkConditions(cpp, offset1, "extern_var");
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" + assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
"Type of problem: Name conflict \n" + "Type of problem: Name conflict \n" +
"New element: extern_var \n" + "New element: extern_var \n" +
"Conflicting element type: Global variable"); //$NON-NLS-1$ "Conflicting element type: Global variable");
status= checkConditions(cpp, offset1, "var_def"); //$NON-NLS-1$ status= checkConditions(cpp, offset1, "var_def");
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" + assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
"Type of problem: Name conflict \n" + "Type of problem: Name conflict \n" +
"New element: var_def \n" + "New element: var_def \n" +
"Conflicting element type: Global variable"); //$NON-NLS-1$ "Conflicting element type: Global variable");
status= checkConditions(cpp, offset1, "enum_item"); //$NON-NLS-1$ status= checkConditions(cpp, offset1, "enum_item");
assertRefactoringError(status, "A conflict was encountered during refactoring. \n" + assertRefactoringError(status, "A conflict was encountered during refactoring. \n" +
"Type of problem: Name conflict \n" + "Type of problem: Name conflict \n" +
"New element: enum_item \n" + "New element: enum_item \n" +
"Conflicting element type: Enumerator"); //$NON-NLS-1$ "Conflicting element type: Enumerator");
} }
public void testClassMacroClash() throws Exception { public void testClassMacroClash() throws Exception {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("class CC {int a;}; \n"); //$NON-NLS-1$ buf.append("class CC {int a;}; \n");
String contents = buf.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents);
buf = new StringBuilder(); buf = new StringBuilder();
buf.append("#define CC mm \n"); //$NON-NLS-1$ buf.append("#define CC mm \n");
buf.append("int CC; \n"); //$NON-NLS-1$ buf.append("int CC; \n");
String contents2 = buf.toString(); String contents2 = buf.toString();
IFile cpp2= importFile("test2.cpp", contents2); //$NON-NLS-1$ IFile cpp2= importFile("test2.cpp", contents2);
int offset1= contents.indexOf("CC"); //$NON-NLS-1$ int offset1= contents.indexOf("CC");
Change ch= getRefactorChanges(cpp, offset1, "CCC"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "CCC");
assertTotalChanges(1, ch); assertTotalChanges(1, ch);
int offset2= contents2.indexOf("CC"); //$NON-NLS-1$ int offset2= contents2.indexOf("CC");
ch= getRefactorChanges(cpp2, offset2, "CCC"); //$NON-NLS-1$ ch= getRefactorChanges(cpp2, offset2, "CCC");
assertTotalChanges(2, ch); assertTotalChanges(2, ch);
} }
public void testMacroRename_434917() throws Exception { public void testMacroRename_434917() throws Exception {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("#define CC mm\n"); //$NON-NLS-1$ buf.append("#define CC mm\n");
String contents = buf.toString(); String contents = buf.toString();
IFile header= importFile("test.h", contents); //$NON-NLS-1$ IFile header= importFile("test.h", contents);
buf = new StringBuilder(); buf = new StringBuilder();
buf.append("#include \"test.h\"\n"); buf.append("#include \"test.h\"\n");
buf.append("int CC;\n"); //$NON-NLS-1$ buf.append("int CC;\n");
String contents2 = buf.toString(); String contents2 = buf.toString();
IFile source= importFile("test.cpp", contents2); //$NON-NLS-1$ IFile source= importFile("test.cpp", contents2);
int offset= contents.indexOf("CC"); //$NON-NLS-1$ int offset= contents.indexOf("CC");
Change ch= getRefactorChanges(header, offset, "CCC"); //$NON-NLS-1$ Change ch= getRefactorChanges(header, offset, "CCC");
assertTotalChanges(2, ch); assertTotalChanges(2, ch);
} }
public void testIncludeGuard() throws Exception { public void testIncludeGuard() throws Exception {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("#ifndef _guard \n"); //$NON-NLS-1$ buf.append("#ifndef _guard \n");
buf.append("#define _guard \n"); //$NON-NLS-1$ buf.append("#define _guard \n");
buf.append(" int HALLO \n"); //$NON-NLS-1$ buf.append(" int HALLO \n");
buf.append("#endif /* _guard */ \n"); //$NON-NLS-1$ buf.append("#endif /* _guard */ \n");
String contents = buf.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents);
int offset1= contents.indexOf("_guard"); //$NON-NLS-1$ int offset1= contents.indexOf("_guard");
int offset2= contents.indexOf("_guard", offset1 + 1); //$NON-NLS-1$ int offset2= contents.indexOf("_guard", offset1 + 1);
Change ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset2, "WELT");
assertTotalChanges(2, 0, 1, ch); assertTotalChanges(2, 0, 1, ch);
int off= offset1; int off= offset1;
assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 6, "WELT");
off= contents.indexOf("_guard", off + 1); //$NON-NLS-1$ off= contents.indexOf("_guard", off + 1);
assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$ assertChange(ch, cpp, off, 6, "WELT");
} }
public void testMacroParameters() throws Exception { public void testMacroParameters() throws Exception {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("int var; \n"); //$NON-NLS-1$ buf.append("int var; \n");
buf.append("#define M1(var) var \n"); //$NON-NLS-1$ buf.append("#define M1(var) var \n");
buf.append("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$ buf.append("#define M2(var, x) (var+x)*var \n");
buf.append("#define M3 var \n"); //$NON-NLS-1$ buf.append("#define M3 var \n");
String contents = buf.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents);
int offset1= contents.indexOf("var"); //$NON-NLS-1$ int offset1= contents.indexOf("var");
Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "xxx");
assertTotalChanges(1, 1, 0, ch); assertTotalChanges(1, 1, 0, ch);
} }
public void testRenameMacroAsMacroArgument() throws Exception { public void testRenameMacroAsMacroArgument() throws Exception {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("#define M1(var) var \n"); //$NON-NLS-1$ buf.append("#define M1(var) var \n");
buf.append("#define M2 1 \n"); //$NON-NLS-1$ buf.append("#define M2 1 \n");
buf.append("int b= M2; \n"); //$NON-NLS-1$ buf.append("int b= M2; \n");
buf.append("int a= M1(M2); \n"); //$NON-NLS-1$ buf.append("int a= M1(M2); \n");
String contents = buf.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents);
int offset1= contents.indexOf("M2"); //$NON-NLS-1$ int offset1= contents.indexOf("M2");
Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "xxx");
assertTotalChanges(countOccurrences(contents, "M2"), ch); //$NON-NLS-1$ assertTotalChanges(countOccurrences(contents, "M2"), ch);
} }
} }

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename; package org.eclipse.cdt.ui.tests.refactoring.rename;

View file

@ -56,11 +56,12 @@ public class TestRenameParticipant extends RenameParticipant {
@Override @Override
public String getName() { public String getName() {
return "TestRenameParticipant"; //$NON-NLS-1$ return "TestRenameParticipant";
} }
@Override @Override
public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException { public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context)
throws OperationCanceledException {
sConditionCheck++; sConditionCheck++;
sArguments= getArguments(); sArguments= getArguments();
return new RefactoringStatus(); return new RefactoringStatus();

View file

@ -33,7 +33,7 @@ public class CRenameClassProcessor extends CRenameTypeProcessor {
protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) { protected IBinding[] getBindingsToBeRenamed(RefactoringStatus status) {
CRefactoringArgument argument= getArgument(); CRefactoringArgument argument= getArgument();
IBinding binding= argument.getBinding(); IBinding binding= argument.getBinding();
ArrayList<IBinding> bindings= new ArrayList<IBinding>(); ArrayList<IBinding> bindings= new ArrayList<>();
if (binding != null) { if (binding != null) {
bindings.add(binding); bindings.add(binding);
} }

View file

@ -33,6 +33,7 @@ import org.eclipse.cdt.internal.ui.refactoring.RefactoringSaveHelper;
*/ */
public class CRenameLocalProcessor extends CRenameProcessorDelegate { public class CRenameLocalProcessor extends CRenameProcessorDelegate {
private IScope fScope; private IScope fScope;
public CRenameLocalProcessor(CRenameProcessor input, String kind, IScope scope) { public CRenameLocalProcessor(CRenameProcessor input, String kind, IScope scope) {
super(input, kind); super(input, kind);
fScope= scope; fScope= scope;

View file

@ -100,7 +100,7 @@ public class CRenameMethodProcessor extends CRenameGlobalProcessor {
CRefactoringArgument argument= getArgument(); CRefactoringArgument argument= getArgument();
IBinding binding= argument.getBinding(); IBinding binding= argument.getBinding();
ArrayList<IBinding> bindings= new ArrayList<IBinding>(); ArrayList<IBinding> bindings= new ArrayList<>();
if (binding != null) { if (binding != null) {
bindings.add(binding); bindings.add(binding);
} }

View file

@ -1380,7 +1380,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
sourceName = NewSourceFileGenerator.generateSourceFileNameFromClass(className); sourceName = NewSourceFileGenerator.generateSourceFileNameFromClass(className);
testName = NewSourceFileGenerator.generateTestFileNameFromClass(className); testName = NewSourceFileGenerator.generateTestFileNameFromClass(className);
} else { } else {
// make sure the file names are unique // Make sure the file names are unique.
String currName = className; String currName = className;
int count = 0; int count = 0;
String separator = ""; //$NON-NLS-1$ String separator = ""; //$NON-NLS-1$
@ -1399,7 +1399,7 @@ public class NewClassCreationWizardPage extends NewElementWizardPage {
headerName = header; headerName = header;
sourceName = source; sourceName = source;
testName = test; testName = test;
// we're done // We're done.
break; break;
} }
} }