From b75e994cb1cffa942693b42ba6569e9362e0f569 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 13 May 2014 14:01:18 -0700 Subject: [PATCH] Cosmetics. --- .../core/parser/scanner/CPreprocessor.java | 12 +- .../parser/scanner/MacroDefinitionParser.java | 16 +- .../internal/core/pdom/dom/PDOMLinkage.java | 14 +- .../core/pdom/dom/PDOMMacroContainer.java | 3 +- .../refactoring/rename/RenameMacroTests.java | 172 +++++++++--------- .../tests/refactoring/rename/RenameTests.java | 18 +- .../refactoring/rename/CRefactoringMatch.java | 15 +- .../rename/CRenameMacroProcessor.java | 3 +- .../rename/CRenameProcessorDelegate.java | 12 +- 9 files changed, 133 insertions(+), 132 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java index b4fd64f5d54..0805ab15b3d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/CPreprocessor.java @@ -246,7 +246,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { private boolean fSplitShiftRightOperator= false; // State information - private final CharArrayMap fMacroDictionary = new CharArrayMap(512); + private final CharArrayMap fMacroDictionary = new CharArrayMap<>(512); private final IMacroDictionary fMacroDictionaryFacade = new MacroDictionary(); private final LocationMap fLocationMap; private CharArraySet fPreventInclusion; @@ -340,7 +340,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { if (ctx != fRootContext) { if (fLog.isTracing(TRACE_NO_GUARD)) { if (fTracedGuards == null) - fTracedGuards= new HashSet(); + fTracedGuards= new HashSet<>(); if (fTracedGuards.add(filePath)) fLog.traceLog(TRACE_NO_GUARD, "No include guard in " + filePath); //$NON-NLS-1$ } @@ -420,7 +420,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { */ public static IncludeSearchPath configureIncludeSearchPath(File directory, IScannerInfo info) { boolean inhibitUseOfCurrentFileDirectory= false; - List elements = new ArrayList(); + List elements = new ArrayList<>(); if (info != null) { // Quote includes first @@ -584,7 +584,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { @Override public Map getMacroDefinitions() { - Map hashMap = new HashMap(fMacroDictionary.size()); + Map hashMap = new HashMap<>(fMacroDictionary.size()); for (char[] key : fMacroDictionary.keys()) { hashMap.put(String.valueOf(key), fMacroDictionary.get(key)); } @@ -799,8 +799,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable { endOffset= t1.getEndOffset(); t1.setType(IToken.tGT_in_SHIFTR); - t1.setOffset(offset, offset+1); - t2= new Token(IToken.tGT_in_SHIFTR, t1.fSource, offset+1, endOffset); + t1.setOffset(offset, offset + 1); + t2= new Token(IToken.tGT_in_SHIFTR, t1.fSource, offset + 1, endOffset); pushbackToken(t2); } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java index 5eaf6696381..029d0dc4bca 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/scanner/MacroDefinitionParser.java @@ -6,10 +6,12 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation + * Markus Schorn - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.internal.core.parser.scanner; +import static org.eclipse.cdt.core.parser.OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE; + import java.util.ArrayList; import org.eclipse.cdt.core.parser.IProblem; @@ -24,8 +26,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions; * @since 5.0 */ public class MacroDefinitionParser { - private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE; - /** * Exception for reporting problems while parsing a macro definition. */ @@ -159,17 +159,17 @@ public class MacroDefinitionParser { if (CharArrayUtils.equals(lastParam, Keywords.cpELLIPSIS)) { hasVarargs= FunctionStyleMacro.VAARGS; char[][] copy= new char[length][]; - System.arraycopy(paramList, 0, copy, 0, length-1); + System.arraycopy(paramList, 0, copy, 0, length - 1); copy[length-1]= Keywords.cVA_ARGS; paramList= copy; } break; default: - if (CharArrayUtils.equals(lastParam, lpl-3, 3, Keywords.cpELLIPSIS)) { + if (CharArrayUtils.equals(lastParam, lpl - 3, 3, Keywords.cpELLIPSIS)) { hasVarargs= FunctionStyleMacro.NAMED_VAARGS; char[][] copy= new char[length][]; - System.arraycopy(paramList, 0, copy, 0, length-1); - copy[length-1]= CharArrayUtils.subarray(lastParam, 0, lpl-3); + System.arraycopy(paramList, 0, copy, 0, length - 1); + copy[length - 1]= CharArrayUtils.subarray(lastParam, 0, lpl - 3); paramList= copy; } break; @@ -202,7 +202,7 @@ public class MacroDefinitionParser { if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) { return null; } - ArrayList paramList= new ArrayList(); + ArrayList paramList= new ArrayList<>(); IToken next= null; do { final Token param= lex.nextToken(); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java index eec74275148..14316d562b0 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMLinkage.java @@ -57,11 +57,9 @@ import org.eclipse.core.runtime.IProgressMonitor; /** * The top-level node in the PDOM storage format. A linkage is a collection of nodes - * that can be linked with references. Several linkages can be created for an input - * AST. + * that can be linked with references. Several linkages can be created for an input AST. * - * TODO Move this to a public interface and discuss the extension point (that already - * exists). + * TODO Move this to a public interface and discuss the extension point (that already exists). */ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage, IIndexBindingConstants { // Record offsets. @@ -73,7 +71,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage @SuppressWarnings("hiding") protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 20; - protected static final long[] FILE_LOCAL_REC_DUMMY = new long[]{0}; + protected static final long[] FILE_LOCAL_REC_DUMMY = new long[] { 0 }; private BTree fMacroIndex= null; // No need for volatile, all fields of BTree are final. private final PDOM fPDOM; @@ -377,7 +375,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage return result; } - public void removeMacroContainer (PDOMMacroContainer container) throws CoreException { + public void removeMacroContainer(PDOMMacroContainer container) throws CoreException { String key= fPDOM.createKeyForCache(record, container.getNameCharArray()); fPDOM.putCachedResult(key, null); getMacroIndex().delete(container.getRecord()); @@ -643,10 +641,10 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage return new TypeMarshalBuffer(this, data).unmarshalTemplateArgument(); } - public void storeValue(long offset, IValue type) throws CoreException { + public void storeValue(long offset, IValue value) throws CoreException { final Database db= getDB(); deleteValue(db, offset); - storeValue(db, offset, type); + storeValue(db, offset, value); } private void storeValue(Database db, long offset, IValue value) throws CoreException { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java index 97a9727dd84..6e09b9ec82e 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMMacroContainer.java @@ -98,9 +98,8 @@ public class PDOMMacroContainer extends PDOMNamedNode implements IIndexMacroCont } public IIndexMacro[] getDefinitions() throws CoreException { - PDOMMacro macro; List macros= new ArrayList<>(); - for (macro= getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) { + for (PDOMMacro macro= getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) { macros.add(macro); } return macros.toArray(new IIndexMacro[macros.size()]); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java index 8c2478c4e8b..09c245b01c6 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameMacroTests.java @@ -10,8 +10,6 @@ *******************************************************************************/ package org.eclipse.cdt.ui.tests.refactoring.rename; -import java.io.StringWriter; - import junit.framework.Test; import junit.framework.TestSuite; @@ -29,37 +27,37 @@ public class RenameMacroTests extends RenameTests { return suite(true); } - public static Test suite( boolean cleanup ) { + public static Test suite(boolean cleanup) { TestSuite suite = new TestSuite(RenameMacroTests.class); if (cleanup) { - suite.addTest( new RefactoringTests("cleanupProject") ); //$NON-NLS-1$ + suite.addTest(new RefactoringTests("cleanupProject")); //$NON-NLS-1$ } return suite; } public void testMacroRename() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("#define HALLO x \n"); //$NON-NLS-1$ - writer.write("class v1 { \n"); //$NON-NLS-1$ - writer.write(" int HALLO; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("class HALLO { \n"); //$NON-NLS-1$ - writer.write(" int v; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("class v3 { \n"); //$NON-NLS-1$ - writer.write(" int v; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("class v4 { \n"); //$NON-NLS-1$ - writer.write(" int HALLO(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("int v4::HALLO(){} \n"); //$NON-NLS-1$ - writer.write("void f(int par1){ \n"); //$NON-NLS-1$ - writer.write(" { \n"); //$NON-NLS-1$ - writer.write(" int HALLO; v1::v++; \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String contents = writer.toString(); - IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ + StringBuilder buf = new StringBuilder(); + buf.append("#define HALLO x \n"); //$NON-NLS-1$ + buf.append("class v1 { \n"); //$NON-NLS-1$ + buf.append(" int HALLO; \n"); //$NON-NLS-1$ + buf.append("}; \n"); //$NON-NLS-1$ + buf.append("class HALLO { \n"); //$NON-NLS-1$ + buf.append(" int v; \n"); //$NON-NLS-1$ + buf.append("}; \n"); //$NON-NLS-1$ + buf.append("class v3 { \n"); //$NON-NLS-1$ + buf.append(" int v; \n"); //$NON-NLS-1$ + buf.append("}; \n"); //$NON-NLS-1$ + buf.append("class v4 { \n"); //$NON-NLS-1$ + buf.append(" int HALLO(); \n"); //$NON-NLS-1$ + buf.append("}; \n"); //$NON-NLS-1$ + buf.append("int v4::HALLO(){} \n"); //$NON-NLS-1$ + buf.append("void f(int par1){ \n"); //$NON-NLS-1$ + buf.append(" { \n"); //$NON-NLS-1$ + buf.append(" int HALLO; v1::v++; \n"); //$NON-NLS-1$ + buf.append(" } \n"); //$NON-NLS-1$ + buf.append("} \n"); //$NON-NLS-1$ + String contents = buf.toString(); + IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ int offset1= contents.indexOf("HALLO"); //$NON-NLS-1$ int offset2= contents.indexOf("HALLO", offset1+1); //$NON-NLS-1$ @@ -68,57 +66,57 @@ public class RenameMacroTests extends RenameTests { assertTotalChanges(6, ch); int off= offset1; assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$ assertTotalChanges(6, ch); off= offset1; assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 5, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("HALLO", off+1); //$NON-NLS-1$ + off= contents.indexOf("HALLO", off + 1); //$NON-NLS-1$ } public void testMacroNameConflicts() throws Exception { createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$ createCppDefs("cpp_def.hh"); //$NON-NLS-1$ - StringWriter writer = new StringWriter(); - writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$ - writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$ - writer.write("#define MACRO 1 \n"); //$NON-NLS-1$ - writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$ - writer.write("static int s1(); \n"); //$NON-NLS-1$ - writer.write("static int s2(); \n"); //$NON-NLS-1$ - writer.write("void f(int par1){ \n"); //$NON-NLS-1$ - writer.write(" int w1; v1(); \n"); //$NON-NLS-1$ - writer.write(" extern_var; \n"); //$NON-NLS-1$ - writer.write(" var_def; \n"); //$NON-NLS-1$ - writer.write(" enum_item; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String contents = writer.toString(); - IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ + StringBuilder buf = new StringBuilder(); + buf.append("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$ + buf.append("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$ + buf.append("#define MACRO 1 \n"); //$NON-NLS-1$ + buf.append("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$ + buf.append("static int s1(); \n"); //$NON-NLS-1$ + buf.append("static int s2(); \n"); //$NON-NLS-1$ + buf.append("void f(int par1){ \n"); //$NON-NLS-1$ + buf.append(" int w1; v1(); \n"); //$NON-NLS-1$ + buf.append(" extern_var; \n"); //$NON-NLS-1$ + buf.append(" var_def; \n"); //$NON-NLS-1$ + buf.append(" enum_item; \n"); //$NON-NLS-1$ + buf.append("} \n"); //$NON-NLS-1$ + String contents = buf.toString(); + IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$ - importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$ + buf = new StringBuilder(); + buf.append("static int static_other_file(); \n"); //$NON-NLS-1$ + importFile("other.cpp", buf.toString()); //$NON-NLS-1$ waitForIndexer(); @@ -155,16 +153,16 @@ public class RenameMacroTests extends RenameTests { } public void testClassMacroClash() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class CC {int a;}; \n"); //$NON-NLS-1$ - String contents = writer.toString(); - IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ + StringBuilder buf = new StringBuilder(); + buf.append("class CC {int a;}; \n"); //$NON-NLS-1$ + String contents = buf.toString(); + IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write("#define CC mm \n"); //$NON-NLS-1$ - writer.write("int CC; \n"); //$NON-NLS-1$ - String contents2 = writer.toString(); - IFile cpp2= importFile("test2.cpp", contents2 ); //$NON-NLS-1$ + buf = new StringBuilder(); + buf.append("#define CC mm \n"); //$NON-NLS-1$ + buf.append("int CC; \n"); //$NON-NLS-1$ + String contents2 = buf.toString(); + IFile cpp2= importFile("test2.cpp", contents2); //$NON-NLS-1$ int offset1= contents.indexOf("CC"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "CCC"); //$NON-NLS-1$ @@ -176,13 +174,13 @@ public class RenameMacroTests extends RenameTests { } public void testIncludeGuard() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("#ifndef _guard \n"); //$NON-NLS-1$ - writer.write("#define _guard \n"); //$NON-NLS-1$ - writer.write(" int HALLO \n"); //$NON-NLS-1$ - writer.write("#endif /* _guard */ \n"); //$NON-NLS-1$ - String contents = writer.toString(); - IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ + StringBuilder buf = new StringBuilder(); + buf.append("#ifndef _guard \n"); //$NON-NLS-1$ + buf.append("#define _guard \n"); //$NON-NLS-1$ + buf.append(" int HALLO \n"); //$NON-NLS-1$ + buf.append("#endif /* _guard */ \n"); //$NON-NLS-1$ + String contents = buf.toString(); + IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ int offset1= contents.indexOf("_guard"); //$NON-NLS-1$ int offset2= contents.indexOf("_guard", offset1+1); //$NON-NLS-1$ @@ -190,18 +188,18 @@ public class RenameMacroTests extends RenameTests { assertTotalChanges(2, 0, 1, ch); int off= offset1; assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$ - off= contents.indexOf("_guard", off+1); //$NON-NLS-1$ + off= contents.indexOf("_guard", off + 1); //$NON-NLS-1$ assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$ } public void testMacroParameters() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int var; \n"); //$NON-NLS-1$ - writer.write("#define M1(var) var \n"); //$NON-NLS-1$ - writer.write("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$ - writer.write("#define M3 var \n"); //$NON-NLS-1$ - String contents = writer.toString(); - IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ + StringBuilder buf = new StringBuilder(); + buf.append("int var; \n"); //$NON-NLS-1$ + buf.append("#define M1(var) var \n"); //$NON-NLS-1$ + buf.append("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$ + buf.append("#define M3 var \n"); //$NON-NLS-1$ + String contents = buf.toString(); + IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ int offset1= contents.indexOf("var"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$ @@ -209,13 +207,13 @@ public class RenameMacroTests extends RenameTests { } public void testRenameMacroAsMacroArgument() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("#define M1(var) var \n"); //$NON-NLS-1$ - writer.write("#define M2 1 \n"); //$NON-NLS-1$ - writer.write("int b= M2; \n"); //$NON-NLS-1$ - writer.write("int a= M1(M2); \n"); //$NON-NLS-1$ - String contents = writer.toString(); - IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ + StringBuilder buf = new StringBuilder(); + buf.append("#define M1(var) var \n"); //$NON-NLS-1$ + buf.append("#define M2 1 \n"); //$NON-NLS-1$ + buf.append("int b= M2; \n"); //$NON-NLS-1$ + buf.append("int a= M1(M2); \n"); //$NON-NLS-1$ + String contents = buf.toString(); + IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$ int offset1= contents.indexOf("M2"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java index 4292c598f10..72c1b429bd9 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/rename/RenameTests.java @@ -50,11 +50,11 @@ public class RenameTests extends RefactoringTests { try { RefactoringStatus rs = checkConditions(proc); if (!rs.hasError()) { - Change change = proc.createChange( new NullProgressMonitor() ); + Change change = proc.createChange(new NullProgressMonitor()); return change; } - fail ("Input check on " + newName + " failed. "+rs.getEntryMatchingSeverity(RefactoringStatus.ERROR) ); //$NON-NLS-1$ //$NON-NLS-2$ + fail ("Input check on " + newName + " failed. "+rs.getEntryMatchingSeverity(RefactoringStatus.ERROR)); //$NON-NLS-1$ //$NON-NLS-2$ //rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in //the UI for renaming a method to a constructor, the first message which is only //a warning is shown in the UI. If you click preview, then the error and the warning @@ -68,7 +68,7 @@ public class RenameTests extends RefactoringTests { private CRenameRefactoring createRefactoring(IFile file, int offset, String newName) { CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0); CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg); - proc.setReplacementText( newName ); + proc.setReplacementText(newName); proc.setSelectedOptions(-1); proc.setExhaustiveSearchScope(TextSearchWrapper.SCOPE_WORKSPACE); return new CRenameRefactoring(proc); @@ -80,15 +80,15 @@ public class RenameTests extends RefactoringTests { ((CRenameProcessor) proc.getProcessor()).lockIndex(); try { RefactoringStatus rs = checkConditions(proc); - if (!rs.hasWarning()){ - fail ("Input check on "+ newName + " passed. There should have been warnings or errors. ") ; //$NON-NLS-1$ //$NON-NLS-2$ + if (!rs.hasWarning()) { + fail ("Input check on "+ newName + " passed. There should have been warnings or errors.") ; //$NON-NLS-1$ //$NON-NLS-2$ return null; } RefactoringStatusEntry[] rse = rs.getEntries(); result = new String[rse.length]; - for (int i=0; i< rse.length; i++){ + for (int i= 0; i < rse.length; i++) { RefactoringStatusEntry entry = rse[i]; - result[i]=entry.getMessage(); + result[i]= entry.getMessage(); } return result; @@ -108,8 +108,8 @@ public class RenameTests extends RefactoringTests { } private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException { - RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor() ); - if (!rs.hasError()){ + RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor()); + if (!rs.hasError()) { rs= proc.checkFinalConditions(new NullProgressMonitor()); } return rs; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringMatch.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringMatch.java index 96690fba923..0d80f66fe8c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringMatch.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRefactoringMatch.java @@ -23,45 +23,51 @@ public class CRefactoringMatch { public static final int AST_REFERENCE_OTHER= 2; public static final int AST_REFEREENCE_CONFLICTING= 3; public static final int IN_COMMENT = 4; - + private static String[] LABELS= { RenameMessages.CRefactoringMatch_label_potentialOccurrence, RenameMessages.CRefactoringMatch_label_occurrence, "", //$NON-NLS-1$ RenameMessages.CRefactoringMatch_label_potentialOccurrence, RenameMessages.CRefactoringMatch_label_comment }; - + private IFile fFile; private int fOffset; private int fLength; private int fLocation; - private int fAstInformation= 0; + private int fAstInformation; public int getAstInformation() { return fAstInformation; } - + public CRefactoringMatch(IFile file, int offset, int length, int location) { fFile= file; fOffset= offset; fLength= length; fLocation= location; } + public int getOffset() { return fOffset; } + public void setLocation(int location) { fLocation= location; } + public int getLocation() { return fLocation; } + public int getLength() { return fLength; } + public IFile getFile() { return fFile; } + public void setASTInformation(int val) { switch (fAstInformation) { case AST_REFERENCE: @@ -76,6 +82,7 @@ public class CRefactoringMatch { break; } } + public String getLabel() { if (fAstInformation == AST_REFERENCE) { return LABELS[AST_REFERENCE]; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMacroProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMacroProcessor.java index c71e7e15a88..0d985f7a810 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMacroProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameMacroProcessor.java @@ -18,7 +18,6 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus; import org.eclipse.cdt.core.dom.ast.IBinding; - /** * Rename processor that sets up the input page for renaming a global entity. */ @@ -28,7 +27,7 @@ public class CRenameMacroProcessor extends CRenameGlobalProcessor { super(processor, name); setAvailableOptions( CRefactory.OPTION_IN_CODE_REFERENCES | - CRefactory.OPTION_IN_COMMENT | + CRefactory.OPTION_IN_COMMENT | CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE | CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessorDelegate.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessorDelegate.java index 2b22bf24ecf..05b583f4cc9 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessorDelegate.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/rename/CRenameProcessorDelegate.java @@ -166,12 +166,12 @@ public abstract class CRenameProcessorDelegate { * @return A set of files containing references to the bindings. */ private Collection getReferringFiles(IBinding[] bindings) { - ArrayList files = new ArrayList(); + ArrayList files = new ArrayList<>(); IIndex index = getIndex(); if (index == null) { return files; } - Set locations = new HashSet(); + Set locations = new HashSet<>(); try { index.acquireReadLock(); for (IBinding binding : bindings) { @@ -213,12 +213,12 @@ public abstract class CRenameProcessorDelegate { RefactoringStatus result= new RefactoringStatus(); monitor.beginTask(RenameMessages.CRenameProcessorDelegate_task_checkFinalCondition, 2); IFile file= getArgument().getSourceFile(); - //assert file!=null; + //assert file != null; IBinding[] renameBindings= getBindingsToBeRenamed(result); - // perform text-search - fMatches= new ArrayList(); + // Perform text search. + fMatches= new ArrayList<>(); TextSearchWrapper txtSearch= getManager().getTextSearch(); Collection filesToSearch = getReferringFiles(renameBindings); if (!filesToSearch.contains(file)) { @@ -240,7 +240,7 @@ public abstract class CRenameProcessorDelegate { return result; } - HashSet fileset= new HashSet(); + HashSet fileset= new HashSet<>(); int potentialMatchCount= 0; int commentCount= 0; for (Iterator iter = fMatches.iterator(); iter.hasNext();) {