1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-05-13 14:01:18 -07:00
parent 2664b7c6f7
commit b75e994cb1
9 changed files with 133 additions and 132 deletions

View file

@ -246,7 +246,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
private boolean fSplitShiftRightOperator= false; private boolean fSplitShiftRightOperator= false;
// State information // State information
private final CharArrayMap<PreprocessorMacro> fMacroDictionary = new CharArrayMap<PreprocessorMacro>(512); private final CharArrayMap<PreprocessorMacro> fMacroDictionary = new CharArrayMap<>(512);
private final IMacroDictionary fMacroDictionaryFacade = new MacroDictionary(); private final IMacroDictionary fMacroDictionaryFacade = new MacroDictionary();
private final LocationMap fLocationMap; private final LocationMap fLocationMap;
private CharArraySet fPreventInclusion; private CharArraySet fPreventInclusion;
@ -340,7 +340,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
if (ctx != fRootContext) { if (ctx != fRootContext) {
if (fLog.isTracing(TRACE_NO_GUARD)) { if (fLog.isTracing(TRACE_NO_GUARD)) {
if (fTracedGuards == null) if (fTracedGuards == null)
fTracedGuards= new HashSet<String>(); fTracedGuards= new HashSet<>();
if (fTracedGuards.add(filePath)) if (fTracedGuards.add(filePath))
fLog.traceLog(TRACE_NO_GUARD, "No include guard in " + filePath); //$NON-NLS-1$ 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) { public static IncludeSearchPath configureIncludeSearchPath(File directory, IScannerInfo info) {
boolean inhibitUseOfCurrentFileDirectory= false; boolean inhibitUseOfCurrentFileDirectory= false;
List<IncludeSearchPathElement> elements = new ArrayList<IncludeSearchPathElement>(); List<IncludeSearchPathElement> elements = new ArrayList<>();
if (info != null) { if (info != null) {
// Quote includes first // Quote includes first
@ -584,7 +584,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
@Override @Override
public Map<String, IMacroBinding> getMacroDefinitions() { public Map<String, IMacroBinding> getMacroDefinitions() {
Map<String, IMacroBinding> hashMap = new HashMap<String, IMacroBinding>(fMacroDictionary.size()); Map<String, IMacroBinding> hashMap = new HashMap<>(fMacroDictionary.size());
for (char[] key : fMacroDictionary.keys()) { for (char[] key : fMacroDictionary.keys()) {
hashMap.put(String.valueOf(key), fMacroDictionary.get(key)); hashMap.put(String.valueOf(key), fMacroDictionary.get(key));
} }
@ -799,8 +799,8 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
endOffset= t1.getEndOffset(); endOffset= t1.getEndOffset();
t1.setType(IToken.tGT_in_SHIFTR); t1.setType(IToken.tGT_in_SHIFTR);
t1.setOffset(offset, offset+1); t1.setOffset(offset, offset + 1);
t2= new Token(IToken.tGT_in_SHIFTR, t1.fSource, offset+1, endOffset); t2= new Token(IToken.tGT_in_SHIFTR, t1.fSource, offset + 1, endOffset);
pushbackToken(t2); pushbackToken(t2);
} }
} }

View file

@ -6,10 +6,12 @@
* 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.internal.core.parser.scanner; package org.eclipse.cdt.internal.core.parser.scanner;
import static org.eclipse.cdt.core.parser.OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.parser.IProblem; import org.eclipse.cdt.core.parser.IProblem;
@ -24,8 +26,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.Lexer.LexerOptions;
* @since 5.0 * @since 5.0
*/ */
public class MacroDefinitionParser { public class MacroDefinitionParser {
private static final int ORIGIN_PREPROCESSOR_DIRECTIVE = OffsetLimitReachedException.ORIGIN_PREPROCESSOR_DIRECTIVE;
/** /**
* Exception for reporting problems while parsing a macro definition. * Exception for reporting problems while parsing a macro definition.
*/ */
@ -159,17 +159,17 @@ public class MacroDefinitionParser {
if (CharArrayUtils.equals(lastParam, Keywords.cpELLIPSIS)) { if (CharArrayUtils.equals(lastParam, Keywords.cpELLIPSIS)) {
hasVarargs= FunctionStyleMacro.VAARGS; hasVarargs= FunctionStyleMacro.VAARGS;
char[][] copy= new char[length][]; 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; copy[length-1]= Keywords.cVA_ARGS;
paramList= copy; paramList= copy;
} }
break; break;
default: default:
if (CharArrayUtils.equals(lastParam, lpl-3, 3, Keywords.cpELLIPSIS)) { if (CharArrayUtils.equals(lastParam, lpl - 3, 3, Keywords.cpELLIPSIS)) {
hasVarargs= FunctionStyleMacro.NAMED_VAARGS; hasVarargs= FunctionStyleMacro.NAMED_VAARGS;
char[][] copy= new char[length][]; char[][] copy= new char[length][];
System.arraycopy(paramList, 0, copy, 0, length-1); System.arraycopy(paramList, 0, copy, 0, length - 1);
copy[length-1]= CharArrayUtils.subarray(lastParam, 0, lpl-3); copy[length - 1]= CharArrayUtils.subarray(lastParam, 0, lpl - 3);
paramList= copy; paramList= copy;
} }
break; break;
@ -202,7 +202,7 @@ public class MacroDefinitionParser {
if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) { if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) {
return null; return null;
} }
ArrayList<char[]> paramList= new ArrayList<char[]>(); ArrayList<char[]> paramList= new ArrayList<>();
IToken next= null; IToken next= null;
do { do {
final Token param= lex.nextToken(); final Token param= lex.nextToken();

View file

@ -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 * 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 * that can be linked with references. Several linkages can be created for an input AST.
* AST.
* *
* TODO Move this to a public interface and discuss the extension point (that already * TODO Move this to a public interface and discuss the extension point (that already exists).
* exists).
*/ */
public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage, IIndexBindingConstants { public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage, IIndexBindingConstants {
// Record offsets. // Record offsets.
@ -73,7 +71,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
protected static final int RECORD_SIZE = PDOMNamedNode.RECORD_SIZE + 20; 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 BTree fMacroIndex= null; // No need for volatile, all fields of BTree are final.
private final PDOM fPDOM; private final PDOM fPDOM;
@ -377,7 +375,7 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return result; return result;
} }
public void removeMacroContainer (PDOMMacroContainer container) throws CoreException { public void removeMacroContainer(PDOMMacroContainer container) throws CoreException {
String key= fPDOM.createKeyForCache(record, container.getNameCharArray()); String key= fPDOM.createKeyForCache(record, container.getNameCharArray());
fPDOM.putCachedResult(key, null); fPDOM.putCachedResult(key, null);
getMacroIndex().delete(container.getRecord()); getMacroIndex().delete(container.getRecord());
@ -643,10 +641,10 @@ public abstract class PDOMLinkage extends PDOMNamedNode implements IIndexLinkage
return new TypeMarshalBuffer(this, data).unmarshalTemplateArgument(); 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(); final Database db= getDB();
deleteValue(db, offset); deleteValue(db, offset);
storeValue(db, offset, type); storeValue(db, offset, value);
} }
private void storeValue(Database db, long offset, IValue value) throws CoreException { private void storeValue(Database db, long offset, IValue value) throws CoreException {

View file

@ -98,9 +98,8 @@ public class PDOMMacroContainer extends PDOMNamedNode implements IIndexMacroCont
} }
public IIndexMacro[] getDefinitions() throws CoreException { public IIndexMacro[] getDefinitions() throws CoreException {
PDOMMacro macro;
List<PDOMMacro> macros= new ArrayList<>(); List<PDOMMacro> macros= new ArrayList<>();
for (macro= getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) { for (PDOMMacro macro= getFirstDefinition(); macro != null; macro= macro.getNextInContainer()) {
macros.add(macro); macros.add(macro);
} }
return macros.toArray(new IIndexMacro[macros.size()]); return macros.toArray(new IIndexMacro[macros.size()]);

View file

@ -10,8 +10,6 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename; package org.eclipse.cdt.ui.tests.refactoring.rename;
import java.io.StringWriter;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestSuite; import junit.framework.TestSuite;
@ -29,37 +27,37 @@ public class RenameMacroTests extends RenameTests {
return suite(true); return suite(true);
} }
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")); //$NON-NLS-1$
} }
return suite; return suite;
} }
public void testMacroRename() throws Exception { public void testMacroRename() throws Exception {
StringWriter writer = new StringWriter(); StringBuilder buf = new StringBuilder();
writer.write("#define HALLO x \n"); //$NON-NLS-1$ buf.append("#define HALLO x \n"); //$NON-NLS-1$
writer.write("class v1 { \n"); //$NON-NLS-1$ buf.append("class v1 { \n"); //$NON-NLS-1$
writer.write(" int HALLO; \n"); //$NON-NLS-1$ buf.append(" int HALLO; \n"); //$NON-NLS-1$
writer.write("}; \n"); //$NON-NLS-1$ buf.append("}; \n"); //$NON-NLS-1$
writer.write("class HALLO { \n"); //$NON-NLS-1$ buf.append("class HALLO { \n"); //$NON-NLS-1$
writer.write(" int v; \n"); //$NON-NLS-1$ buf.append(" int v; \n"); //$NON-NLS-1$
writer.write("}; \n"); //$NON-NLS-1$ buf.append("}; \n"); //$NON-NLS-1$
writer.write("class v3 { \n"); //$NON-NLS-1$ buf.append("class v3 { \n"); //$NON-NLS-1$
writer.write(" int v; \n"); //$NON-NLS-1$ buf.append(" int v; \n"); //$NON-NLS-1$
writer.write("}; \n"); //$NON-NLS-1$ buf.append("}; \n"); //$NON-NLS-1$
writer.write("class v4 { \n"); //$NON-NLS-1$ buf.append("class v4 { \n"); //$NON-NLS-1$
writer.write(" int HALLO(); \n"); //$NON-NLS-1$ buf.append(" int HALLO(); \n"); //$NON-NLS-1$
writer.write("}; \n"); //$NON-NLS-1$ buf.append("}; \n"); //$NON-NLS-1$
writer.write("int v4::HALLO(){} \n"); //$NON-NLS-1$ buf.append("int v4::HALLO(){} \n"); //$NON-NLS-1$
writer.write("void f(int par1){ \n"); //$NON-NLS-1$ buf.append("void f(int par1){ \n"); //$NON-NLS-1$
writer.write(" { \n"); //$NON-NLS-1$ buf.append(" { \n"); //$NON-NLS-1$
writer.write(" int HALLO; v1::v++; \n"); //$NON-NLS-1$ buf.append(" int HALLO; v1::v++; \n"); //$NON-NLS-1$
writer.write(" } \n"); //$NON-NLS-1$ buf.append(" } \n"); //$NON-NLS-1$
writer.write("} \n"); //$NON-NLS-1$ buf.append("} \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
int offset1= contents.indexOf("HALLO"); //$NON-NLS-1$ int offset1= contents.indexOf("HALLO"); //$NON-NLS-1$
int offset2= contents.indexOf("HALLO", offset1+1); //$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); assertTotalChanges(6, ch);
int off= offset1; int off= offset1;
assertChange(ch, cpp, off, 5, "WELT"); //$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$ 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$ 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$ 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$ 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$ 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$ ch= getRefactorChanges(cpp, offset2, "WELT"); //$NON-NLS-1$
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"); //$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$ 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$ 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$ 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$ 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$ 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 { public void testMacroNameConflicts() throws Exception {
createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$ createCppFwdDecls("cpp_fwd.hh"); //$NON-NLS-1$
createCppDefs("cpp_def.hh"); //$NON-NLS-1$ createCppDefs("cpp_def.hh"); //$NON-NLS-1$
StringWriter writer = new StringWriter(); StringBuilder buf = new StringBuilder();
writer.write("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$ buf.append("#include \"cpp_fwd.hh\" \n"); //$NON-NLS-1$
writer.write("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$ buf.append("#include \"cpp_def.hh\" \n"); //$NON-NLS-1$
writer.write("#define MACRO 1 \n"); //$NON-NLS-1$ buf.append("#define MACRO 1 \n"); //$NON-NLS-1$
writer.write("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$ buf.append("int v1(); int v2(); int v3(); \n"); //$NON-NLS-1$
writer.write("static int s1(); \n"); //$NON-NLS-1$ buf.append("static int s1(); \n"); //$NON-NLS-1$
writer.write("static int s2(); \n"); //$NON-NLS-1$ buf.append("static int s2(); \n"); //$NON-NLS-1$
writer.write("void f(int par1){ \n"); //$NON-NLS-1$ buf.append("void f(int par1){ \n"); //$NON-NLS-1$
writer.write(" int w1; v1(); \n"); //$NON-NLS-1$ buf.append(" int w1; v1(); \n"); //$NON-NLS-1$
writer.write(" extern_var; \n"); //$NON-NLS-1$ buf.append(" extern_var; \n"); //$NON-NLS-1$
writer.write(" var_def; \n"); //$NON-NLS-1$ buf.append(" var_def; \n"); //$NON-NLS-1$
writer.write(" enum_item; \n"); //$NON-NLS-1$ buf.append(" enum_item; \n"); //$NON-NLS-1$
writer.write("} \n"); //$NON-NLS-1$ buf.append("} \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
writer = new StringWriter(); buf = new StringBuilder();
writer.write( "static int static_other_file(); \n" ); //$NON-NLS-1$ buf.append("static int static_other_file(); \n"); //$NON-NLS-1$
importFile( "other.cpp", writer.toString() ); //$NON-NLS-1$ importFile("other.cpp", buf.toString()); //$NON-NLS-1$
waitForIndexer(); waitForIndexer();
@ -155,16 +153,16 @@ public class RenameMacroTests extends RenameTests {
} }
public void testClassMacroClash() throws Exception { public void testClassMacroClash() throws Exception {
StringWriter writer = new StringWriter(); StringBuilder buf = new StringBuilder();
writer.write("class CC {int a;}; \n"); //$NON-NLS-1$ buf.append("class CC {int a;}; \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
writer = new StringWriter(); buf = new StringBuilder();
writer.write("#define CC mm \n"); //$NON-NLS-1$ buf.append("#define CC mm \n"); //$NON-NLS-1$
writer.write("int CC; \n"); //$NON-NLS-1$ buf.append("int CC; \n"); //$NON-NLS-1$
String contents2 = writer.toString(); String contents2 = buf.toString();
IFile cpp2= importFile("test2.cpp", contents2 ); //$NON-NLS-1$ IFile cpp2= importFile("test2.cpp", contents2); //$NON-NLS-1$
int offset1= contents.indexOf("CC"); //$NON-NLS-1$ int offset1= contents.indexOf("CC"); //$NON-NLS-1$
Change ch= getRefactorChanges(cpp, offset1, "CCC"); //$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 { public void testIncludeGuard() throws Exception {
StringWriter writer = new StringWriter(); StringBuilder buf = new StringBuilder();
writer.write("#ifndef _guard \n"); //$NON-NLS-1$ buf.append("#ifndef _guard \n"); //$NON-NLS-1$
writer.write("#define _guard \n"); //$NON-NLS-1$ buf.append("#define _guard \n"); //$NON-NLS-1$
writer.write(" int HALLO \n"); //$NON-NLS-1$ buf.append(" int HALLO \n"); //$NON-NLS-1$
writer.write("#endif /* _guard */ \n"); //$NON-NLS-1$ buf.append("#endif /* _guard */ \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
int offset1= contents.indexOf("_guard"); //$NON-NLS-1$ int offset1= contents.indexOf("_guard"); //$NON-NLS-1$
int offset2= contents.indexOf("_guard", offset1+1); //$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); 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"); //$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$ assertChange(ch, cpp, off, 6, "WELT"); //$NON-NLS-1$
} }
public void testMacroParameters() throws Exception { public void testMacroParameters() throws Exception {
StringWriter writer = new StringWriter(); StringBuilder buf = new StringBuilder();
writer.write("int var; \n"); //$NON-NLS-1$ buf.append("int var; \n"); //$NON-NLS-1$
writer.write("#define M1(var) var \n"); //$NON-NLS-1$ buf.append("#define M1(var) var \n"); //$NON-NLS-1$
writer.write("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$ buf.append("#define M2(var, x) (var+x)*var \n"); //$NON-NLS-1$
writer.write("#define M3 var \n"); //$NON-NLS-1$ buf.append("#define M3 var \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
int offset1= contents.indexOf("var"); //$NON-NLS-1$ int offset1= contents.indexOf("var"); //$NON-NLS-1$
Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$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 { public void testRenameMacroAsMacroArgument() throws Exception {
StringWriter writer = new StringWriter(); StringBuilder buf = new StringBuilder();
writer.write("#define M1(var) var \n"); //$NON-NLS-1$ buf.append("#define M1(var) var \n"); //$NON-NLS-1$
writer.write("#define M2 1 \n"); //$NON-NLS-1$ buf.append("#define M2 1 \n"); //$NON-NLS-1$
writer.write("int b= M2; \n"); //$NON-NLS-1$ buf.append("int b= M2; \n"); //$NON-NLS-1$
writer.write("int a= M1(M2); \n"); //$NON-NLS-1$ buf.append("int a= M1(M2); \n"); //$NON-NLS-1$
String contents = writer.toString(); String contents = buf.toString();
IFile cpp= importFile("test.cpp", contents ); //$NON-NLS-1$ IFile cpp= importFile("test.cpp", contents); //$NON-NLS-1$
int offset1= contents.indexOf("M2"); //$NON-NLS-1$ int offset1= contents.indexOf("M2"); //$NON-NLS-1$
Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$ Change ch= getRefactorChanges(cpp, offset1, "xxx"); //$NON-NLS-1$

View file

@ -50,11 +50,11 @@ public class RenameTests extends RefactoringTests {
try { try {
RefactoringStatus rs = checkConditions(proc); RefactoringStatus rs = checkConditions(proc);
if (!rs.hasError()) { if (!rs.hasError()) {
Change change = proc.createChange( new NullProgressMonitor() ); Change change = proc.createChange(new NullProgressMonitor());
return change; 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 //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 //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 //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) { private CRenameRefactoring createRefactoring(IFile file, int offset, String newName) {
CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0); CRefactoringArgument arg= new CRefactoringArgument(file, offset, 0);
CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg); CRenameProcessor proc= new CRenameProcessor(CRefactory.getInstance(), arg);
proc.setReplacementText( newName ); proc.setReplacementText(newName);
proc.setSelectedOptions(-1); proc.setSelectedOptions(-1);
proc.setExhaustiveSearchScope(TextSearchWrapper.SCOPE_WORKSPACE); proc.setExhaustiveSearchScope(TextSearchWrapper.SCOPE_WORKSPACE);
return new CRenameRefactoring(proc); return new CRenameRefactoring(proc);
@ -80,15 +80,15 @@ public class RenameTests extends RefactoringTests {
((CRenameProcessor) proc.getProcessor()).lockIndex(); ((CRenameProcessor) proc.getProcessor()).lockIndex();
try { try {
RefactoringStatus rs = checkConditions(proc); RefactoringStatus rs = checkConditions(proc);
if (!rs.hasWarning()){ if (!rs.hasWarning()) {
fail ("Input check on "+ newName + " passed. There should have been warnings or errors. ") ; //$NON-NLS-1$ //$NON-NLS-2$ fail ("Input check on "+ newName + " passed. There should have been warnings or errors.") ; //$NON-NLS-1$ //$NON-NLS-2$
return null; return null;
} }
RefactoringStatusEntry[] rse = rs.getEntries(); RefactoringStatusEntry[] rse = rs.getEntries();
result = new String[rse.length]; 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]; RefactoringStatusEntry entry = rse[i];
result[i]=entry.getMessage(); result[i]= entry.getMessage();
} }
return result; return result;
@ -108,8 +108,8 @@ public class RenameTests extends RefactoringTests {
} }
private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException { private RefactoringStatus checkConditions(CRenameRefactoring proc) throws CoreException {
RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor() ); RefactoringStatus rs =proc.checkInitialConditions(new NullProgressMonitor());
if (!rs.hasError()){ if (!rs.hasError()) {
rs= proc.checkFinalConditions(new NullProgressMonitor()); rs= proc.checkFinalConditions(new NullProgressMonitor());
} }
return rs; return rs;

View file

@ -23,45 +23,51 @@ public class CRefactoringMatch {
public static final int AST_REFERENCE_OTHER= 2; public static final int AST_REFERENCE_OTHER= 2;
public static final int AST_REFEREENCE_CONFLICTING= 3; public static final int AST_REFEREENCE_CONFLICTING= 3;
public static final int IN_COMMENT = 4; public static final int IN_COMMENT = 4;
private static String[] LABELS= { private static String[] LABELS= {
RenameMessages.CRefactoringMatch_label_potentialOccurrence, RenameMessages.CRefactoringMatch_label_potentialOccurrence,
RenameMessages.CRefactoringMatch_label_occurrence, RenameMessages.CRefactoringMatch_label_occurrence,
"", //$NON-NLS-1$ "", //$NON-NLS-1$
RenameMessages.CRefactoringMatch_label_potentialOccurrence, RenameMessages.CRefactoringMatch_label_potentialOccurrence,
RenameMessages.CRefactoringMatch_label_comment }; RenameMessages.CRefactoringMatch_label_comment };
private IFile fFile; private IFile fFile;
private int fOffset; private int fOffset;
private int fLength; private int fLength;
private int fLocation; private int fLocation;
private int fAstInformation= 0; private int fAstInformation;
public int getAstInformation() { public int getAstInformation() {
return fAstInformation; return fAstInformation;
} }
public CRefactoringMatch(IFile file, int offset, int length, int location) { public CRefactoringMatch(IFile file, int offset, int length, int location) {
fFile= file; fFile= file;
fOffset= offset; fOffset= offset;
fLength= length; fLength= length;
fLocation= location; fLocation= location;
} }
public int getOffset() { public int getOffset() {
return fOffset; return fOffset;
} }
public void setLocation(int location) { public void setLocation(int location) {
fLocation= location; fLocation= location;
} }
public int getLocation() { public int getLocation() {
return fLocation; return fLocation;
} }
public int getLength() { public int getLength() {
return fLength; return fLength;
} }
public IFile getFile() { public IFile getFile() {
return fFile; return fFile;
} }
public void setASTInformation(int val) { public void setASTInformation(int val) {
switch (fAstInformation) { switch (fAstInformation) {
case AST_REFERENCE: case AST_REFERENCE:
@ -76,6 +82,7 @@ public class CRefactoringMatch {
break; break;
} }
} }
public String getLabel() { public String getLabel() {
if (fAstInformation == AST_REFERENCE) { if (fAstInformation == AST_REFERENCE) {
return LABELS[AST_REFERENCE]; return LABELS[AST_REFERENCE];

View file

@ -18,7 +18,6 @@ import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
/** /**
* Rename processor that sets up the input page for renaming a global entity. * 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); super(processor, name);
setAvailableOptions( setAvailableOptions(
CRefactory.OPTION_IN_CODE_REFERENCES | CRefactory.OPTION_IN_CODE_REFERENCES |
CRefactory.OPTION_IN_COMMENT | CRefactory.OPTION_IN_COMMENT |
CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE | CRefactory.OPTION_IN_PREPROCESSOR_DIRECTIVE |
CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH); CRefactory.OPTION_EXHAUSTIVE_FILE_SEARCH);
} }

View file

@ -166,12 +166,12 @@ public abstract class CRenameProcessorDelegate {
* @return A set of files containing references to the bindings. * @return A set of files containing references to the bindings.
*/ */
private Collection<IFile> getReferringFiles(IBinding[] bindings) { private Collection<IFile> getReferringFiles(IBinding[] bindings) {
ArrayList<IFile> files = new ArrayList<IFile>(); ArrayList<IFile> files = new ArrayList<>();
IIndex index = getIndex(); IIndex index = getIndex();
if (index == null) { if (index == null) {
return files; return files;
} }
Set<IIndexFileLocation> locations = new HashSet<IIndexFileLocation>(); Set<IIndexFileLocation> locations = new HashSet<>();
try { try {
index.acquireReadLock(); index.acquireReadLock();
for (IBinding binding : bindings) { for (IBinding binding : bindings) {
@ -213,12 +213,12 @@ public abstract class CRenameProcessorDelegate {
RefactoringStatus result= new RefactoringStatus(); RefactoringStatus result= new RefactoringStatus();
monitor.beginTask(RenameMessages.CRenameProcessorDelegate_task_checkFinalCondition, 2); monitor.beginTask(RenameMessages.CRenameProcessorDelegate_task_checkFinalCondition, 2);
IFile file= getArgument().getSourceFile(); IFile file= getArgument().getSourceFile();
//assert file!=null; //assert file != null;
IBinding[] renameBindings= getBindingsToBeRenamed(result); IBinding[] renameBindings= getBindingsToBeRenamed(result);
// perform text-search // Perform text search.
fMatches= new ArrayList<CRefactoringMatch>(); fMatches= new ArrayList<>();
TextSearchWrapper txtSearch= getManager().getTextSearch(); TextSearchWrapper txtSearch= getManager().getTextSearch();
Collection<IFile> filesToSearch = getReferringFiles(renameBindings); Collection<IFile> filesToSearch = getReferringFiles(renameBindings);
if (!filesToSearch.contains(file)) { if (!filesToSearch.contains(file)) {
@ -240,7 +240,7 @@ public abstract class CRenameProcessorDelegate {
return result; return result;
} }
HashSet<IFile> fileset= new HashSet<IFile>(); HashSet<IFile> fileset= new HashSet<>();
int potentialMatchCount= 0; int potentialMatchCount= 0;
int commentCount= 0; int commentCount= 0;
for (Iterator<CRefactoringMatch> iter = fMatches.iterator(); iter.hasNext();) { for (Iterator<CRefactoringMatch> iter = fMatches.iterator(); iter.hasNext();) {