1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 03:45:35 +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;
// 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 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<String>();
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<IncludeSearchPathElement> elements = new ArrayList<IncludeSearchPathElement>();
List<IncludeSearchPathElement> elements = new ArrayList<>();
if (info != null) {
// Quote includes first
@ -584,7 +584,7 @@ public class CPreprocessor implements ILexerLog, IScanner, IAdaptable {
@Override
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()) {
hashMap.put(String.valueOf(key), fMacroDictionary.get(key));
}

View file

@ -10,6 +10,8 @@
*******************************************************************************/
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.
*/
@ -202,7 +202,7 @@ public class MacroDefinitionParser {
if (lparen.getType() != IToken.tLPAREN || name.getEndOffset() != lparen.getOffset()) {
return null;
}
ArrayList<char[]> paramList= new ArrayList<char[]>();
ArrayList<char[]> paramList= new ArrayList<>();
IToken next= null;
do {
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
* 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.
@ -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 {

View file

@ -98,9 +98,8 @@ public class PDOMMacroContainer extends PDOMNamedNode implements IIndexMacroCont
}
public IIndexMacro[] getDefinitions() throws CoreException {
PDOMMacro macro;
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);
}
return macros.toArray(new IIndexMacro[macros.size()]);

View file

@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.ui.tests.refactoring.rename;
import java.io.StringWriter;
import junit.framework.Test;
import junit.framework.TestSuite;
@ -38,27 +36,27 @@ public class RenameMacroTests extends RenameTests {
}
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();
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$
@ -100,25 +98,25 @@ public class RenameMacroTests extends RenameTests {
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();
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,15 +153,15 @@ 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();
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();
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$
@ -176,12 +174,12 @@ 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();
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$
@ -195,12 +193,12 @@ public class RenameMacroTests extends RenameTests {
}
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();
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$
@ -209,12 +207,12 @@ 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();
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$

View file

@ -35,7 +35,7 @@ public class CRefactoringMatch {
private int fOffset;
private int fLength;
private int fLocation;
private int fAstInformation= 0;
private int fAstInformation;
public int getAstInformation() {
return fAstInformation;
@ -47,21 +47,27 @@ public class CRefactoringMatch {
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];

View file

@ -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.
*/

View file

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