1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 02:05:39 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2014-05-02 10:24:38 -07:00
parent ddb8ab8708
commit 355027f0c9
25 changed files with 751 additions and 761 deletions

View file

@ -51,13 +51,13 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId; import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression; import org.eclipse.cdt.core.dom.ast.IASTTypeIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType; import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField; import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunctionType; import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.IBasicType.Kind;
import org.eclipse.cdt.core.dom.ast.IVariable; import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression; import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification; import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTLinkageSpecification;
@ -114,7 +114,7 @@ public class AST2TestBase extends BaseTestCase {
private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap()); private static final ScannerInfo SCANNER_INFO = new ScannerInfo(getStdMap());
private static Map<String, String> getGnuMap() { private static Map<String, String> getGnuMap() {
Map<String, String> map= new HashMap<String, String>(); Map<String, String> map= new HashMap<>();
map.put("__GNUC__", Integer.toString(GPPLanguage.GNU_LATEST_VERSION_MAJOR)); map.put("__GNUC__", Integer.toString(GPPLanguage.GNU_LATEST_VERSION_MAJOR));
map.put("__GNUC_MINOR__", Integer.toString(GPPLanguage.GNU_LATEST_VERSION_MINOR)); map.put("__GNUC_MINOR__", Integer.toString(GPPLanguage.GNU_LATEST_VERSION_MINOR));
map.put("__SIZEOF_SHORT__", "2"); map.put("__SIZEOF_SHORT__", "2");
@ -125,7 +125,7 @@ public class AST2TestBase extends BaseTestCase {
} }
private static Map<String, String> getStdMap() { private static Map<String, String> getStdMap() {
Map<String, String> map= new HashMap<String, String>(); Map<String, String> map= new HashMap<>();
map.put("__SIZEOF_SHORT__", "2"); map.put("__SIZEOF_SHORT__", "2");
map.put("__SIZEOF_INT__", "4"); map.put("__SIZEOF_INT__", "4");
map.put("__SIZEOF_LONG__", "8"); map.put("__SIZEOF_LONG__", "8");
@ -312,7 +312,7 @@ public class AST2TestBase extends BaseTestCase {
this.shouldVisitImplicitNames = shouldVisitImplicitNames; this.shouldVisitImplicitNames = shouldVisitImplicitNames;
} }
public List<IASTName> nameList = new ArrayList<IASTName>(); public List<IASTName> nameList = new ArrayList<>();
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
@ -408,7 +408,7 @@ public class AST2TestBase extends BaseTestCase {
} }
public int numProblemBindings; public int numProblemBindings;
public int numNullBindings; public int numNullBindings;
public List<IASTName> nameList = new ArrayList<IASTName>(); public List<IASTName> nameList = new ArrayList<>();
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
@ -438,7 +438,7 @@ public class AST2TestBase extends BaseTestCase {
} }
public int numProblemBindings; public int numProblemBindings;
public int numNullBindings; public int numNullBindings;
public List<IASTName> nameList = new ArrayList<IASTName>(); public List<IASTName> nameList = new ArrayList<>();
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {

View file

@ -37,7 +37,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver; import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
public abstract class PreprocessorTestsBase extends BaseTestCase { public abstract class PreprocessorTestsBase extends BaseTestCase {
private static final IParserLogService NULL_LOG = new NullLogService(); private static final IParserLogService NULL_LOG = new NullLogService();
protected CPreprocessor fScanner; protected CPreprocessor fScanner;
protected ILocationResolver fLocationResolver; protected ILocationResolver fLocationResolver;
@ -81,8 +80,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
if (scannerConfig == null) { if (scannerConfig == null) {
if (lang == ParserLanguage.C) { if (lang == ParserLanguage.C) {
scannerConfig= GCCScannerExtensionConfiguration.getInstance(); scannerConfig= GCCScannerExtensionConfiguration.getInstance();
} } else {
else {
scannerConfig= GPPScannerExtensionConfiguration.getInstance(scannerInfo); scannerConfig= GPPScannerExtensionConfiguration.getInstance(scannerInfo);
} }
} }
@ -176,8 +174,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
try { try {
IToken t= fScanner.nextToken(); IToken t= fScanner.nextToken();
fail("superfluous token " + t); fail("superfluous token " + t);
} } catch(EndOfFileException e) {
catch(EndOfFileException e) {
} }
} }
@ -211,5 +208,4 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
assertEquals(detail, problem.getArguments()[0]); assertEquals(detail, problem.getArguments()[0]);
} }
} }
} }

View file

@ -18,8 +18,6 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import junit.framework.Assert;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature; import org.eclipse.cdt.core.CProjectNature;
@ -61,7 +59,9 @@ import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider; import org.eclipse.ui.wizards.datatransfer.FileSystemStructureProvider;
import org.eclipse.ui.wizards.datatransfer.ImportOperation; import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.junit.Assert;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
/** /**
* Helper methods to set up a ICProject. * Helper methods to set up a ICProject.
*/ */

View file

@ -8,7 +8,6 @@
* Contributors: * Contributors:
* IBM Corporation - initial API and implementation * IBM Corporation - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.testplugin; package org.eclipse.cdt.core.testplugin;
// copied from startup.jar. planned to be removed soon // copied from startup.jar. planned to be removed soon
@ -73,12 +72,12 @@ public class Main {
/** /**
* Indicates whether this instance is running in debug mode. * Indicates whether this instance is running in debug mode.
*/ */
protected boolean debug = false; protected boolean debug;
/** /**
* The location of the launcher to run. * The location of the launcher to run.
*/ */
protected String bootLocation = null; protected String bootLocation;
/** /**
* The identifier of the application to run. * The identifier of the application to run.
@ -98,7 +97,7 @@ public class Main {
/** /**
* Indicates whether items for UNinstallation should be looked for. * Indicates whether items for UNinstallation should be looked for.
*/ */
protected boolean uninstall = false; protected boolean uninstall;
/** /**
* The item to be uninstalled. * The item to be uninstalled.
@ -108,15 +107,15 @@ public class Main {
/** /**
* The class path entries. * The class path entries.
*/ */
protected String devClassPath = null; protected String devClassPath;
/** /**
* Indicates whether this instance is running in development mode. * Indicates whether this instance is running in development mode.
*/ */
protected boolean inDevelopmentMode = false; protected boolean inDevelopmentMode;
// static token describing how to take down the splash screen // static token describing how to take down the splash screen
private static String endSplash = null; private static String endSplash;
// constants // constants
private static final String APPLICATION = "-application"; private static final String APPLICATION = "-application";
@ -181,7 +180,7 @@ protected Object basicRun(String[] args) throws Exception {
private String[] getArrayFromList(String prop) { private String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().equals("")) if (prop == null || prop.trim().equals(""))
return new String[0]; return new String[0];
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
StringTokenizer tokens = new StringTokenizer(prop, ","); StringTokenizer tokens = new StringTokenizer(prop, ",");
while (tokens.hasMoreTokens()) { while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim(); String token = tokens.nextToken().trim();
@ -190,6 +189,7 @@ private String[] getArrayFromList(String prop) {
} }
return list.toArray(new String[list.size()]); return list.toArray(new String[list.size()]);
} }
/** /**
* Creates and returns a platform <code>BootLoader</code> which can be used to start * Creates and returns a platform <code>BootLoader</code> which can be used to start
* up and run the platform. The given base, if not <code>null</code>, * up and run the platform. The given base, if not <code>null</code>,
@ -200,9 +200,11 @@ private String[] getArrayFromList(String prop) {
* @param base the location of the boot loader * @param base the location of the boot loader
*/ */
public Class getBootLoader(String base) throws Exception { public Class getBootLoader(String base) throws Exception {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null); try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
return loader.loadClass(BOOTLOADER); return loader.loadClass(BOOTLOADER);
} }
}
/** /**
* Returns the <code>URL</code>-based class path describing where the boot classes * Returns the <code>URL</code>-based class path describing where the boot classes
* are located when running in development mode. * are located when running in development mode.
@ -346,6 +348,7 @@ protected String searchForBoot(String start) {
throw new RuntimeException("Could not find bootstrap code. Check location of boot plug-in or specify -boot."); throw new RuntimeException("Could not find bootstrap code. Check location of boot plug-in or specify -boot.");
return result.replace(File.separatorChar, '/') + "/"; return result.replace(File.separatorChar, '/') + "/";
} }
/** /**
* Returns the update loader for the given boot path. * Returns the update loader for the given boot path.
* *
@ -354,9 +357,11 @@ protected String searchForBoot(String start) {
* @exception Exception thrown is a problem occurs determining this loader * @exception Exception thrown is a problem occurs determining this loader
*/ */
public Class getUpdateLoader(String base) throws Exception { public Class getUpdateLoader(String base) throws Exception {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null); try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
return loader.loadClass(UPDATELOADER); return loader.loadClass(UPDATELOADER);
} }
}
/** /**
* Runs the platform with the given arguments. The arguments must identify * Runs the platform with the given arguments. The arguments must identify
* an application to run (e.g., <code>-application com.example.application</code>). * an application to run (e.g., <code>-application com.example.application</code>).
@ -503,6 +508,7 @@ protected String[] processCommandLine(String[] args) throws Exception {
} }
return passThruArgs; return passThruArgs;
} }
/** /**
* Runs the application to be launched. * Runs the application to be launched.
* *
@ -517,6 +523,7 @@ public Object run(String[] args) throws Exception {
else else
return basicRun(passThruArgs); return basicRun(passThruArgs);
} }
/** /**
* Performs an update run. * Performs an update run.
* *

View file

@ -24,7 +24,7 @@ public class TestScannerProvider extends AbstractCExtension implements IScannerI
public static String[] sIncludes; public static String[] sIncludes;
public static String[] sIncludeFiles; public static String[] sIncludeFiles;
public static String[] sMacroFiles; public static String[] sMacroFiles;
public static Map<String, String> sDefinedSymbols = new HashMap<String, String>(); public static Map<String, String> sDefinedSymbols = new HashMap<>();
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner"; public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner";
public static void clear() { public static void clear() {

View file

@ -15,7 +15,6 @@ import org.eclipse.core.runtime.IPath;
/** /**
* Helper interface capturing 'path' characteristic for {@link ICSettingEntry} * Helper interface capturing 'path' characteristic for {@link ICSettingEntry}
* and {@link ICLanguageSettingEntry} interfaces. * and {@link ICLanguageSettingEntry} interfaces.
*
*/ */
public interface ICPathEntry extends ICSettingEntry { public interface ICPathEntry extends ICSettingEntry {
IPath getFullPath(); IPath getFullPath();
@ -23,5 +22,4 @@ public interface ICPathEntry extends ICSettingEntry {
IPath getLocation(); IPath getLocation();
boolean isValueWorkspacePath(); boolean isValueWorkspacePath();
} }

View file

@ -76,14 +76,14 @@ public class CDataUtil {
private static final String DELIM = " "; //$NON-NLS-1$ private static final String DELIM = " "; //$NON-NLS-1$
private static Random randomNumber; private static Random randomNumber;
public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static final String[] EMPTY_STRING_ARRAY = {};
/** /**
* Pool of setting entries implemented as WeakHashSet. That allows to gain memory savings * Pool of setting entries implemented as WeakHashSet. That allows to gain memory savings
* at the expense of CPU time. WeakHashSet handles garbage collection when a list is not * at the expense of CPU time. WeakHashSet handles garbage collection when a list is not
* referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects. * referenced anywhere else. See JavaDoc {@link java.lang.ref.WeakReference} about weak reference objects.
*/ */
private static WeakHashSet<ICSettingEntry> settingEntriesPool = new WeakHashSetSynchronized<ICSettingEntry>(); private static WeakHashSet<ICSettingEntry> settingEntriesPool = new WeakHashSetSynchronized<>();
public static int genRandomNumber() { public static int genRandomNumber() {
if (randomNumber == null) { if (randomNumber == null) {
@ -101,8 +101,8 @@ public class CDataUtil {
public static String genId(String baseId) { public static String genId(String baseId) {
String suffix = new Integer(genRandomNumber()).toString(); String suffix = new Integer(genRandomNumber()).toString();
return baseId != null ? return baseId != null ?
new StringBuffer(baseId).append(".").append(suffix).toString() //$NON-NLS-1$ new StringBuilder(baseId).append(".").append(suffix).toString() : //$NON-NLS-1$
: suffix; suffix;
} }
public static boolean objectsEqual(Object o1, Object o2) { public static boolean objectsEqual(Object o1, Object o2) {
@ -122,7 +122,7 @@ public class CDataUtil {
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
if (array.length == 1) if (array.length == 1)
return array[0].toString(); return array[0].toString();
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
buf.append(array[0]); buf.append(array[0]);
for (int i = 1; i < array.length; i++) { for (int i = 1; i < array.length; i++) {
buf.append(separator).append(array[i]); buf.append(separator).append(array[i]);
@ -137,7 +137,7 @@ public class CDataUtil {
if (string.length() == 0) if (string.length() == 0)
return EMPTY_STRING_ARRAY; return EMPTY_STRING_ARRAY;
StringTokenizer t = new StringTokenizer(string, separator); StringTokenizer t = new StringTokenizer(string, separator);
List<String> list = new ArrayList<String>(t.countTokens()); List<String> list = new ArrayList<>(t.countTokens());
while (t.hasMoreElements()) { while (t.hasMoreElements()) {
list.add(t.nextToken()); list.add(t.nextToken());
} }
@ -148,7 +148,7 @@ public class CDataUtil {
if (entries.length == 0) if (entries.length == 0)
return entries; return entries;
ArrayList<ICSettingEntry> out = new ArrayList<ICSettingEntry>(entries.length); ArrayList<ICSettingEntry> out = new ArrayList<>(entries.length);
ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager(); ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager();
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
@ -466,7 +466,7 @@ public class CDataUtil {
if (type != null) if (type != null)
exts = getContentTypeFileSpecs(project, type); exts = getContentTypeFileSpecs(project, type);
} else { } else {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (int i = 0; i < typeIds.length; i++) { for (int i = 0; i < typeIds.length; i++) {
type = manager.getContentType(typeIds[i]); type = manager.getContentType(typeIds[i]);
if (type != null) { if (type != null) {
@ -558,7 +558,7 @@ public class CDataUtil {
} }
public static Map<IPath, CResourceData> createPathRcDataMap(CConfigurationData data) { public static Map<IPath, CResourceData> createPathRcDataMap(CConfigurationData data) {
Map<IPath, CResourceData> map = new HashMap<IPath, CResourceData>(); Map<IPath, CResourceData> map = new HashMap<>();
CResourceData[] rcDatas = data.getResourceDatas(); CResourceData[] rcDatas = data.getResourceDatas();
CResourceData rcData; CResourceData rcData;
for (int i = 0; i < rcDatas.length; i++) { for (int i = 0; i < rcDatas.length; i++) {
@ -617,7 +617,7 @@ public class CDataUtil {
CResourceData[] rcDatas = cfg.getResourceDatas(); CResourceData[] rcDatas = cfg.getResourceDatas();
for (int i = 0; i < rcDatas.length; i++) { for (int i = 0; i < rcDatas.length; i++) {
if (rcDatas[i].getType() == ICSettingBase.SETTING_FOLDER) { if (rcDatas[i].getType() == ICSettingBase.SETTING_FOLDER) {
adjustFolderData(cfg, (CFolderData)rcDatas[i], factory, dess, new HashMap<String, ILanguageDescriptor[]>(map)); adjustFolderData(cfg, (CFolderData)rcDatas[i], factory, dess, new HashMap<>(map));
} }
} }
@ -626,7 +626,7 @@ public class CDataUtil {
private static void adjustFolderData(CConfigurationData cfgData, CFolderData data, CDataFactory factory, ILanguageDescriptor dess[], HashMap<String, ILanguageDescriptor[]> map) { private static void adjustFolderData(CConfigurationData cfgData, CFolderData data, CDataFactory factory, ILanguageDescriptor dess[], HashMap<String, ILanguageDescriptor[]> map) {
Map<String, ILanguageDescriptor> langMap = new HashMap<String, ILanguageDescriptor>(); Map<String, ILanguageDescriptor> langMap = new HashMap<>();
for (int i = 0; i < dess.length; i++) { for (int i = 0; i < dess.length; i++) {
langMap.put(dess[i].getId(), dess[i]); langMap.put(dess[i].getId(), dess[i]);
} }
@ -664,11 +664,11 @@ public class CDataUtil {
String [] cTypeIds = des.getContentTypeIds(); String [] cTypeIds = des.getContentTypeIds();
String srcIds[] = lData.getSourceContentTypeIds(); String srcIds[] = lData.getSourceContentTypeIds();
Set<String> landTypes = new HashSet<String>(Arrays.asList(cTypeIds)); Set<String> landTypes = new HashSet<>(Arrays.asList(cTypeIds));
landTypes.removeAll(Arrays.asList(srcIds)); landTypes.removeAll(Arrays.asList(srcIds));
if (landTypes.size() != 0) { if (landTypes.size() != 0) {
List<String> srcList = new ArrayList<String>(); List<String> srcList = new ArrayList<>();
srcList.addAll(landTypes); srcList.addAll(landTypes);
lData.setSourceContentTypeIds(srcList.toArray(new String[srcList.size()])); lData.setSourceContentTypeIds(srcList.toArray(new String[srcList.size()]));
} }
@ -680,7 +680,7 @@ public class CDataUtil {
} }
private static void addLangs(CConfigurationData cfgData, CFolderData data, CDataFactory factory, Map<String, ILanguageDescriptor> langMap, Map<String, ILanguageDescriptor[]> cTypeToLangMap) { private static void addLangs(CConfigurationData cfgData, CFolderData data, CDataFactory factory, Map<String, ILanguageDescriptor> langMap, Map<String, ILanguageDescriptor[]> cTypeToLangMap) {
List<ILanguageDescriptor> list = new ArrayList<ILanguageDescriptor>(langMap.values()); List<ILanguageDescriptor> list = new ArrayList<>(langMap.values());
ILanguageDescriptor des; ILanguageDescriptor des;
while(list.size() != 0) { while(list.size() != 0) {
des = list.remove(list.size() - 1); des = list.remove(list.size() - 1);
@ -761,8 +761,10 @@ public class CDataUtil {
* @return - true if they are equal * @return - true if they are equal
*/ */
public static boolean isEqual(ICSourceEntry[] ein, ICSourceEntry[] aus) { public static boolean isEqual(ICSourceEntry[] ein, ICSourceEntry[] aus) {
if (ein == null || aus == null) return (ein == null && aus == null); if (ein == null || aus == null)
if (ein.length != aus.length) return false; return (ein == null && aus == null);
if (ein.length != aus.length)
return false;
for (int i= 0; i < ein.length; i++) { for (int i= 0; i < ein.length; i++) {
boolean found = false; boolean found = false;
for (int j=0; j<aus.length; j++) { for (int j=0; j<aus.length; j++) {
@ -801,8 +803,8 @@ public class CDataUtil {
ICSourceEntry[] newEntries; ICSourceEntry[] newEntries;
if (excluded) { if (excluded) {
List<ICSourceEntry> includeList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> includeList = new ArrayList<>(entries.length);
List<ICSourceEntry> excludeList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> excludeList = new ArrayList<>(entries.length);
sortEntries(path, false, entries, includeList, excludeList); sortEntries(path, false, entries, includeList, excludeList);
@ -817,8 +819,8 @@ public class CDataUtil {
newEntries = excludeList.toArray(new ICSourceEntry[excludeList.size()]); newEntries = excludeList.toArray(new ICSourceEntry[excludeList.size()]);
} else { } else {
List<ICSourceEntry> includeList = new ArrayList<ICSourceEntry>(entries.length + 1); List<ICSourceEntry> includeList = new ArrayList<>(entries.length + 1);
List<ICSourceEntry> excludeList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> excludeList = new ArrayList<>(entries.length);
sortIncludingExcludingEntries(path, entries, includeList, excludeList); sortIncludingExcludingEntries(path, entries, includeList, excludeList);
boolean included = false; boolean included = false;
@ -878,12 +880,13 @@ public class CDataUtil {
private static void sortIncludingExcludingEntries(IPath path, ICSourceEntry[] entries, List<ICSourceEntry> including, List<ICSourceEntry> excluding) { private static void sortIncludingExcludingEntries(IPath path, ICSourceEntry[] entries, List<ICSourceEntry> including, List<ICSourceEntry> excluding) {
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
IPath entryPath = new Path(entries[i].getName()); IPath entryPath = new Path(entries[i].getName());
if(entryPath.isPrefixOf(path)) if (entryPath.isPrefixOf(path)) {
including.add(entries[i]); including.add(entries[i]);
else } else {
excluding.add(entries[i]); excluding.add(entries[i]);
} }
} }
}
public static ICSourceEntry[] adjustEntries(ICSourceEntry entries[]) { public static ICSourceEntry[] adjustEntries(ICSourceEntry entries[]) {
return adjustEntries(entries, false, null); return adjustEntries(entries, false, null);
@ -892,10 +895,11 @@ public class CDataUtil {
private static ICSourceEntry[] getDefaultSourceEntries(boolean absolute, IProject project) { private static ICSourceEntry[] getDefaultSourceEntries(boolean absolute, IProject project) {
ICSourceEntry entry; ICSourceEntry entry;
if (absolute) { if (absolute) {
if(project != null) if (project != null) {
entry = new CSourceEntry(project.getFullPath(), null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); entry = new CSourceEntry(project.getFullPath(), null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
else } else {
entry = new CSourceEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); entry = new CSourceEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
}
} else { } else {
entry = new CSourceEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); entry = new CSourceEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
} }
@ -905,10 +909,11 @@ public class CDataUtil {
private static ICOutputEntry[] getDefaultOutputEntries(boolean absolute, IProject project) { private static ICOutputEntry[] getDefaultOutputEntries(boolean absolute, IProject project) {
ICOutputEntry entry; ICOutputEntry entry;
if (absolute) { if (absolute) {
if(project != null) if (project != null) {
entry = new COutputEntry(project.getFullPath(), null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); entry = new COutputEntry(project.getFullPath(), null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
else } else {
entry = new COutputEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); entry = new COutputEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
}
} else { } else {
entry = new COutputEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED); entry = new COutputEntry(Path.EMPTY, null, ICSettingEntry.VALUE_WORKSPACE_PATH | ICSettingEntry.RESOLVED);
} }
@ -927,7 +932,7 @@ public class CDataUtil {
return getDefaultSourceEntries(makeAbsolute, project); return getDefaultSourceEntries(makeAbsolute, project);
ICSourceEntry ei, ej; ICSourceEntry ei, ej;
LinkedHashMap<ICSourceEntry, List<IPath>> map = new LinkedHashMap<ICSourceEntry, List<IPath>>(); LinkedHashMap<ICSourceEntry, List<IPath>> map = new LinkedHashMap<>();
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
ei = entries[i]; ei = entries[i];
List<IPath> list = null; List<IPath> list = null;
@ -939,20 +944,20 @@ public class CDataUtil {
IPath ejPath = new Path(ej.getName()); IPath ejPath = new Path(ej.getName());
if (!isExcluded(ejPath, ei)) { if (!isExcluded(ejPath, ei)) {
if (list == null) if (list == null)
list = new ArrayList<IPath>(); list = new ArrayList<>();
list.add(ejPath); list.add(ejPath);
} }
} }
map.put(ei, list); map.put(ei, list);
} }
List<ICSourceEntry> resultList = new ArrayList<ICSourceEntry>(entries.length); List<ICSourceEntry> resultList = new ArrayList<>(entries.length);
for (Iterator<Map.Entry<ICSourceEntry, List<IPath>>> iter = map.entrySet().iterator(); iter.hasNext();) { for (Iterator<Map.Entry<ICSourceEntry, List<IPath>>> iter = map.entrySet().iterator(); iter.hasNext();) {
Map.Entry<ICSourceEntry, List<IPath>> entry = iter.next(); Map.Entry<ICSourceEntry, List<IPath>> entry = iter.next();
List<IPath> list = entry.getValue(); List<IPath> list = entry.getValue();
if(list == null) if (list == null) {
resultList.add(entry.getKey()); resultList.add(entry.getKey());
else { } else {
ICSourceEntry se = entry.getKey(); ICSourceEntry se = entry.getKey();
se = addExcludePaths(se, list, true); se = addExcludePaths(se, list, true);
if (se != null) if (se != null)
@ -1030,7 +1035,7 @@ public class CDataUtil {
private static Collection<IPath> removePrefix(IPath prefix, Collection<IPath> paths, Collection<IPath> result) { private static Collection<IPath> removePrefix(IPath prefix, Collection<IPath> paths, Collection<IPath> result) {
if (result == null) if (result == null)
result = new ArrayList<IPath>(paths.size()); result = new ArrayList<>(paths.size());
for (Iterator<IPath> iter = paths.iterator(); iter.hasNext(); ) { for (Iterator<IPath> iter = paths.iterator(); iter.hasNext(); ) {
IPath path = iter.next(); IPath path = iter.next();
if (prefix.isPrefixOf(path)) if (prefix.isPrefixOf(path))
@ -1045,7 +1050,7 @@ public class CDataUtil {
IPath entryPath = new Path(entry.getName()); IPath entryPath = new Path(entry.getName());
IPath[] oldExclusions = entry.getExclusionPatterns(); IPath[] oldExclusions = entry.getExclusionPatterns();
// List newExList = new ArrayList(oldExclusions.length + paths.size()); // List newExList = new ArrayList(oldExclusions.length + paths.size());
LinkedHashSet<IPath> newSet = new LinkedHashSet<IPath>(); LinkedHashSet<IPath> newSet = new LinkedHashSet<>();
if (removePrefix) { if (removePrefix) {
removePrefix(entryPath, paths, newSet); removePrefix(entryPath, paths, newSet);
} else { } else {
@ -1078,7 +1083,7 @@ public class CDataUtil {
public static Map<EntryNameKey, ICSettingEntry> fillEntriesMapByNameKey(Map<EntryNameKey, ICSettingEntry> map, ICSettingEntry[] entries) { public static Map<EntryNameKey, ICSettingEntry> fillEntriesMapByNameKey(Map<EntryNameKey, ICSettingEntry> map, ICSettingEntry[] entries) {
if (map == null) if (map == null)
map = new LinkedHashMap<EntryNameKey, ICSettingEntry>(); map = new LinkedHashMap<>();
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
ICSettingEntry entry = entries[i]; ICSettingEntry entry = entries[i];
@ -1089,7 +1094,7 @@ public class CDataUtil {
public static Map<EntryContentsKey, ICSettingEntry> fillEntriesMapByContentsKey(Map<EntryContentsKey, ICSettingEntry> map, ICSettingEntry[] entries) { public static Map<EntryContentsKey, ICSettingEntry> fillEntriesMapByContentsKey(Map<EntryContentsKey, ICSettingEntry> map, ICSettingEntry[] entries) {
if (map == null) if (map == null)
map = new LinkedHashMap<EntryContentsKey, ICSettingEntry>(); map = new LinkedHashMap<>();
for (int i = 0; i < entries.length; i++) { for (int i = 0; i < entries.length; i++) {
ICSettingEntry entry = entries[i]; ICSettingEntry entry = entries[i];
@ -1140,12 +1145,13 @@ public class CDataUtil {
} }
private static Set<IPath> mergeRemovingDups(IPath[] o1, IPath[] o2, boolean add) { private static Set<IPath> mergeRemovingDups(IPath[] o1, IPath[] o2, boolean add) {
LinkedHashSet<IPath> set = new LinkedHashSet<IPath>(); LinkedHashSet<IPath> set = new LinkedHashSet<>();
set.addAll(Arrays.asList(o1)); set.addAll(Arrays.asList(o1));
if(add) if (add) {
set.addAll(Arrays.asList(o2)); set.addAll(Arrays.asList(o2));
else } else {
set.removeAll(Arrays.asList(o2)); set.removeAll(Arrays.asList(o2));
}
return set; return set;
} }
@ -1157,7 +1163,7 @@ public class CDataUtil {
IPath projPath = project.getFullPath(); IPath projPath = project.getFullPath();
if (!path.isAbsolute() || (force && !projPath.isPrefixOf(path))) { if (!path.isAbsolute() || (force && !projPath.isPrefixOf(path))) {
path = projPath.append(path).makeAbsolute(); path = projPath.append(path).makeAbsolute();
return (ICExclusionPatternPathEntry)CDataUtil.createEntry(entry.getKind(), path.toString(), null, entry.getExclusionPatterns(), entry.getFlags()); return (ICExclusionPatternPathEntry) createEntry(entry.getKind(), path.toString(), null, entry.getExclusionPatterns(), entry.getFlags());
} }
return entry; return entry;
} }
@ -1170,11 +1176,12 @@ public class CDataUtil {
IPath projPath = project.getFullPath(); IPath projPath = project.getFullPath();
if (path.isAbsolute()) { if (path.isAbsolute()) {
if(projPath.isPrefixOf(path)) if (projPath.isPrefixOf(path)) {
path = path.removeFirstSegments(projPath.segmentCount()).makeRelative(); path = path.removeFirstSegments(projPath.segmentCount()).makeRelative();
else if (force) } else if (force) {
path = path.makeRelative(); path = path.makeRelative();
return (ICExclusionPatternPathEntry)CDataUtil.createEntry(entry.getKind(), path.toString(), null, entry.getExclusionPatterns(), entry.getFlags()); }
return (ICExclusionPatternPathEntry) createEntry(entry.getKind(), path.toString(), null, entry.getExclusionPatterns(), entry.getFlags());
} }
return entry; return entry;
} }

View file

@ -33,8 +33,7 @@ public interface IPDOMIndexer {
public ICProject getProject(); public ICProject getProject();
/** /**
* Return the unique ID of type of this indexer * Returns the unique ID of type of this indexer
* @return the unique ID of type of this indexer
*/ */
public String getID(); public String getID();

View file

@ -18,29 +18,23 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTComment extends IASTNode { public interface IASTComment extends IASTNode {
/** /** @since 5.4 */
* @since 5.4
*/
public final IASTComment[] EMPTY_COMMENT_ARRAY = {}; public final IASTComment[] EMPTY_COMMENT_ARRAY = {};
/** /**
* Set the comment. * Sets the comment.
* *
* @param comment * @param comment the text of the comment
*/ */
public void setComment(char[] comment); public void setComment(char[] comment);
/** /**
* Return a char array representation of the comment. * Returns a char array representation of the comment.
*
* @return char array representation of the comment
*/ */
public char[] getComment(); public char[] getComment();
/** /**
* Return true if this is a blockcomment. * Returns true if this is a block comment.
*
* @return true if this is a blockcomment
*/ */
public boolean isBlockComment(); public boolean isBlockComment();
} }

View file

@ -320,7 +320,7 @@ public abstract class ASTTranslationUnit extends ASTNode implements IASTTranslat
if (fLocationResolver != null) { if (fLocationResolver != null) {
return fLocationResolver.getComments(); return fLocationResolver.getComments();
} }
return new IASTComment[0]; return IASTComment.EMPTY_COMMENT_ARRAY;
} }
@Override @Override

View file

@ -104,7 +104,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) { if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor); return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor);
} else { } else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) { for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -134,7 +134,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) { if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findMacroContainers(pattern, filter, monitor); return fFragments[0].findMacroContainers(pattern, filter, monitor);
} else { } else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) { for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -160,14 +160,14 @@ public class CIndex implements IIndex {
@Override @Override
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException { public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
ArrayList<IIndexFragmentName> result= new ArrayList<IIndexFragmentName>(); ArrayList<IIndexFragmentName> result= new ArrayList<>();
if (binding instanceof ICPPUsingDeclaration) { if (binding instanceof ICPPUsingDeclaration) {
IBinding[] bindings= ((ICPPUsingDeclaration) binding).getDelegates(); IBinding[] bindings= ((ICPPUsingDeclaration) binding).getDelegates();
if (bindings == null || bindings.length == 0) { if (bindings == null || bindings.length == 0) {
return new IIndexName[0]; return IIndexName.EMPTY_ARRAY;
} }
if (bindings.length > 1) { if (bindings.length > 1) {
ArrayList<IIndexName> multi= new ArrayList<IIndexName>(); ArrayList<IIndexName> multi= new ArrayList<>();
for (IBinding b : bindings) { for (IBinding b : bindings) {
multi.addAll(Arrays.asList(findNames(b, flags))); multi.addAll(Arrays.asList(findNames(b, flags)));
} }
@ -182,7 +182,7 @@ public class CIndex implements IIndex {
// Read only fragments can be superseded by what the indexer writes into // Read only fragments can be superseded by what the indexer writes into
// a writable fragment. Therefore names from a read-only fragment are // a writable fragment. Therefore names from a read-only fragment are
// ignored if there is a match in a writable fragment. // ignored if there is a match in a writable fragment.
HashSet<NameKey> encounteredNames = new HashSet<NameKey>(); HashSet<NameKey> encounteredNames = new HashSet<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
if (fragment instanceof IWritableIndexFragment) { if (fragment instanceof IWritableIndexFragment) {
final IIndexFragmentName[] names = fragment.findNames(binding, flags); final IIndexFragmentName[] names = fragment.findNames(binding, flags);
@ -250,8 +250,8 @@ public class CIndex implements IIndex {
if (location == null) { if (location == null) {
return IIndexFile.EMPTY_FILE_ARRAY; return IIndexFile.EMPTY_FILE_ARRAY;
} }
Set<ISignificantMacros> handled = new HashSet<ISignificantMacros>(); Set<ISignificantMacros> handled = new HashSet<>();
ArrayList<IIndexFragmentFile> result= new ArrayList<IIndexFragmentFile>(); ArrayList<IIndexFragmentFile> result= new ArrayList<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
IIndexFragmentFile[] candidates= fragment.getFiles(linkageID, location); IIndexFragmentFile[] candidates= fragment.getFiles(linkageID, location);
for (IIndexFragmentFile candidate : candidates) { for (IIndexFragmentFile candidate : candidates) {
@ -274,8 +274,8 @@ public class CIndex implements IIndex {
if (location == null) { if (location == null) {
return IIndexFile.EMPTY_FILE_ARRAY; return IIndexFile.EMPTY_FILE_ARRAY;
} }
Set<FileContentKey> keys = new HashSet<FileContentKey>(); Set<FileContentKey> keys = new HashSet<>();
ArrayList<IIndexFragmentFile> result= new ArrayList<IIndexFragmentFile>(); ArrayList<IIndexFragmentFile> result= new ArrayList<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
IIndexFragmentFile[] candidates= fragment.getFiles(location); IIndexFragmentFile[] candidates= fragment.getFiles(location);
for (IIndexFragmentFile candidate : candidates) { for (IIndexFragmentFile candidate : candidates) {
@ -313,7 +313,7 @@ public class CIndex implements IIndex {
@Override @Override
public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException { public IIndexInclude[] findIncludedBy(IIndexFile file, int depth) throws CoreException {
List<IIndexInclude> result= new ArrayList<IIndexInclude>(); List<IIndexInclude> result= new ArrayList<>();
findIncludedBy(file.getLinkageID(), Collections.singletonList(file), result, depth, findIncludedBy(file.getLinkageID(), Collections.singletonList(file), result, depth,
new HashSet<FileContentKey>()); new HashSet<FileContentKey>());
return result.toArray(new IIndexInclude[result.size()]); return result.toArray(new IIndexInclude[result.size()]);
@ -354,8 +354,8 @@ public class CIndex implements IIndex {
@Override @Override
public IIndexInclude[] findIncludes(IIndexFile file, int depth) throws CoreException { public IIndexInclude[] findIncludes(IIndexFile file, int depth) throws CoreException {
List<IIndexInclude> result= new ArrayList<IIndexInclude>(); List<IIndexInclude> result= new ArrayList<>();
findIncludes(Collections.singletonList(file), result, depth, new HashSet<Object>()); findIncludes(Collections.singletonList(file), result, depth, new HashSet<>());
return result.toArray(new IIndexInclude[result.size()]); return result.toArray(new IIndexInclude[result.size()]);
} }
@ -454,7 +454,7 @@ public class CIndex implements IIndex {
if (monitor == null) { if (monitor == null) {
monitor= new NullProgressMonitor(); monitor= new NullProgressMonitor();
} }
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length); monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length);
for (ILinkage linkage : linkages) { for (ILinkage linkage : linkages) {
@ -529,7 +529,7 @@ public class CIndex implements IIndex {
} }
public IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) throws CoreException { public IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) throws CoreException {
List<IIndexFragmentBinding> result = new ArrayList<IIndexFragmentBinding>(); List<IIndexFragmentBinding> result = new ArrayList<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
IIndexFragmentBinding adapted = fragment.adaptBinding(binding); IIndexFragmentBinding adapted = fragment.adaptBinding(binding);
if (adapted != null) { if (adapted != null) {
@ -583,7 +583,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) { if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindingsForPrefix(prefix, filescope, filter, monitor); return fFragments[0].findBindingsForPrefix(prefix, filescope, filter, monitor);
} else { } else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) { for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -613,7 +613,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) { if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindingsForContentAssist(prefix, filescope, filter, monitor); return fFragments[0].findBindingsForContentAssist(prefix, filescope, filter, monitor);
} else { } else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) { for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -643,7 +643,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) { if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindings(name, filescope, filter, monitor); return fFragments[0].findBindings(name, filescope, filter, monitor);
} else { } else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>(); List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages(); ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) { for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) { if (filter.acceptLinkage(linkage)) {
@ -685,11 +685,11 @@ public class CIndex implements IIndex {
if (monitor == null) { if (monitor == null) {
monitor= new NullProgressMonitor(); monitor= new NullProgressMonitor();
} }
List<IIndexMacro> result = new ArrayList<IIndexMacro>(); List<IIndexMacro> result = new ArrayList<>();
HashSet<IIndexFileLocation> handledIFLs= new HashSet<IIndexFileLocation>(); HashSet<IIndexFileLocation> handledIFLs= new HashSet<>();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length); monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length);
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
HashSet<IIndexFile> allowedFiles= new HashSet<IIndexFile>(); HashSet<IIndexFile> allowedFiles= new HashSet<>();
try { try {
IIndexMacro[] macros= fragment.findMacros(name, isPrefix, caseSensitive, filter, IIndexMacro[] macros= fragment.findMacros(name, isPrefix, caseSensitive, filter,
new SubProgressMonitor(monitor, 1)); new SubProgressMonitor(monitor, 1));
@ -747,7 +747,7 @@ public class CIndex implements IIndex {
@Override @Override
public IIndexFile[] getAllFiles() throws CoreException { public IIndexFile[] getAllFiles() throws CoreException {
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<IIndexFileLocation, IIndexFile>(); HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
for (IIndexFragmentFile file : fragment.getAllFiles()) { for (IIndexFragmentFile file : fragment.getAllFiles()) {
if (file.hasContent()) { if (file.hasContent()) {
@ -760,7 +760,7 @@ public class CIndex implements IIndex {
@Override @Override
public IIndexFile[] getDefectiveFiles() throws CoreException { public IIndexFile[] getDefectiveFiles() throws CoreException {
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<IIndexFileLocation, IIndexFile>(); HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
for (IIndexFragmentFile file : fragment.getDefectiveFiles()) { for (IIndexFragmentFile file : fragment.getDefectiveFiles()) {
if (file.hasContent()) { if (file.hasContent()) {
@ -773,7 +773,7 @@ public class CIndex implements IIndex {
@Override @Override
public IIndexFile[] getFilesWithUnresolvedIncludes() throws CoreException { public IIndexFile[] getFilesWithUnresolvedIncludes() throws CoreException {
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<IIndexFileLocation, IIndexFile>(); HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<>();
for (IIndexFragment fragment : fFragments) { for (IIndexFragment fragment : fFragments) {
for (IIndexFragmentFile file : fragment.getFilesWithUnresolvedIncludes()) { for (IIndexFragmentFile file : fragment.getFilesWithUnresolvedIncludes()) {
if (file.hasContent()) { if (file.hasContent()) {

View file

@ -40,19 +40,19 @@ public interface IIndexFragmentFile extends IIndexFile {
/** /**
* Returns the hash-code computed by combining the file size and the file encoding. * Returns the hash-code computed by combining the file size and the file encoding.
* @return hashcode a hash-code or <code>0</code> if it is unknown. * @return a hash-code or {@code 0} if it is unknown.
*/ */
int getSizeAndEncodingHashcode() throws CoreException; int getSizeAndEncodingHashcode() throws CoreException;
/** /**
* Sets the hash-code computed by combining the file size and the file encoding. * Sets the hash-code computed by combining the file size and the file encoding.
* @param hashcode a hash-code or <code>0</code> if it is unknown. * @param hashcode a hash-code or {@code 0} if it is unknown.
*/ */
void setSizeAndEncodingHashcode(int hashcode) throws CoreException; void setSizeAndEncodingHashcode(int hashcode) throws CoreException;
/** /**
* Sets the flag that determines whether the file is a header with #pragma once statement * Sets the flag that determines whether the file is a header with {@code #pragma once}
* or an include guard, or it is a source file and parsed only once because of that. * statement or an include guard, or it is a source file and parsed only once because of that.
*/ */
void setPragmaOnceSemantics(boolean value) throws CoreException; void setPragmaOnceSemantics(boolean value) throws CoreException;
@ -85,5 +85,4 @@ public interface IIndexFragmentFile extends IIndexFile {
* The file 'source' must belong to the same fragment as this file. * The file 'source' must belong to the same fragment as this file.
*/ */
void transferContext(IIndexFragmentFile source) throws CoreException; void transferContext(IIndexFragmentFile source) throws CoreException;
} }

View file

@ -1057,16 +1057,12 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
writeToIndex(lang.getLinkageID(), ast, codeReader, ctx, pm); writeToIndex(lang.getLinkageID(), ast, codeReader, ctx, pm);
resultCacheCleared = true; // The cache was cleared while writing to the index. resultCacheCleared = true; // The cache was cleared while writing to the index.
} }
} catch (CoreException e) {
th= e;
} catch (RuntimeException e) { } catch (RuntimeException e) {
final Throwable cause = e.getCause(); final Throwable cause = e.getCause();
if (cause instanceof DependsOnOutdatedFileException) if (cause instanceof DependsOnOutdatedFileException)
return (DependsOnOutdatedFileException) cause; return (DependsOnOutdatedFileException) cause;
th= e; th= e;
} catch (StackOverflowError e) { } catch (StackOverflowError | CoreException | AssertionError e) {
th= e;
} catch (AssertionError e) {
th= e; th= e;
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
if (--fSwallowOutOfMemoryError < 0) if (--fSwallowOutOfMemoryError < 0)
@ -1247,16 +1243,10 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (storageLinkageID != ILinkage.NO_LINKAGE_ID) if (storageLinkageID != ILinkage.NO_LINKAGE_ID)
addSymbols(data, storageLinkageID, ctx, fTodoTaskUpdater, pm); addSymbols(data, storageLinkageID, ctx, fTodoTaskUpdater, pm);
} }
} catch (CoreException e) { } catch (CoreException | RuntimeException | Error e) {
// Avoid parsing files again, that caused an exception to be thrown. // Avoid parsing files again, that caused an exception to be thrown.
withdrawRequests(linkageID, fileKeys); withdrawRequests(linkageID, fileKeys);
throw e; throw e;
} catch (RuntimeException e) {
withdrawRequests(linkageID, fileKeys);
throw e;
} catch (Error e) {
withdrawRequests(linkageID, fileKeys);
throw e;
} }
} }

View file

@ -8,7 +8,6 @@
* Contributors: * Contributors:
* Sergey Prigogin (Google) - initial API and implementation * Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom; package org.eclipse.cdt.internal.core.pdom;
import org.eclipse.cdt.core.dom.ast.IASTComment; import org.eclipse.cdt.core.dom.ast.IASTComment;

View file

@ -135,27 +135,28 @@ abstract public class PDOMWriter implements IPDOMASTProcessor {
public static int SKIP_NO_REFERENCES= 0; public static int SKIP_NO_REFERENCES= 0;
private static class Symbols { private static class Symbols {
final ArrayList<IASTName[]> fNames= new ArrayList<IASTName[]>(); final ArrayList<IASTName[]> fNames= new ArrayList<>();
final ArrayList<IASTPreprocessorStatement> fMacros= new ArrayList<IASTPreprocessorStatement>(); final ArrayList<IASTPreprocessorStatement> fMacros= new ArrayList<>();
final ArrayList<IASTPreprocessorIncludeStatement> fIncludes= new ArrayList<IASTPreprocessorIncludeStatement>(); final ArrayList<IASTPreprocessorIncludeStatement> fIncludes= new ArrayList<>();
} }
protected static class Data implements IIndexSymbols { protected static class Data implements IIndexSymbols {
final IASTTranslationUnit fAST; final IASTTranslationUnit fAST;
final FileInAST[] fSelectedFiles; final FileInAST[] fSelectedFiles;
final IWritableIndex fIndex; final IWritableIndex fIndex;
final Map<IASTPreprocessorIncludeStatement, Symbols> fSymbolMap = new HashMap<IASTPreprocessorIncludeStatement, Symbols>(); final Map<IASTPreprocessorIncludeStatement, Symbols> fSymbolMap = new HashMap<>();
final Set<IASTPreprocessorIncludeStatement> fContextIncludes = new HashSet<IASTPreprocessorIncludeStatement>(); final Set<IASTPreprocessorIncludeStatement> fContextIncludes = new HashSet<>();
final List<IStatus> fStati= new ArrayList<IStatus>(); final List<IStatus> fStatuses= new ArrayList<>();
public Data(IASTTranslationUnit ast, FileInAST[] selectedFiles, IWritableIndex index) { public Data(IASTTranslationUnit ast, FileInAST[] selectedFiles, IWritableIndex index) {
fAST= ast; fAST= ast;
fSelectedFiles= selectedFiles; fSelectedFiles= selectedFiles;
fIndex= index; fIndex= index;
for(FileInAST file : selectedFiles) for (FileInAST file : selectedFiles) {
fSymbolMap.put(file.includeStatement, new Symbols()); fSymbolMap.put(file.includeStatement, new Symbols());
} }
}
@Override @Override
public boolean isEmpty() { public boolean isEmpty() {
@ -272,14 +273,14 @@ abstract public class PDOMWriter implements IPDOMASTProcessor {
// Tasks update. // Tasks update.
if (taskUpdater != null) { if (taskUpdater != null) {
Set<IIndexFileLocation> locations= new HashSet<IIndexFileLocation>(); Set<IIndexFileLocation> locations= new HashSet<>();
for (FileInAST file : data.fSelectedFiles) { for (FileInAST file : data.fSelectedFiles) {
locations.add(file.fileContentKey.getLocation()); locations.add(file.fileContentKey.getLocation());
} }
taskUpdater.updateTasks(data.fAST.getComments(), locations.toArray(new IIndexFileLocation[locations.size()])); taskUpdater.updateTasks(data.fAST.getComments(), locations.toArray(new IIndexFileLocation[locations.size()]));
} }
if (!data.fStati.isEmpty()) { if (!data.fStatuses.isEmpty()) {
List<IStatus> stati = data.fStati; List<IStatus> stati = data.fStatuses;
String path= null; String path= null;
if (data.fSelectedFiles.length > 0) { if (data.fSelectedFiles.length > 0) {
path= data.fSelectedFiles[data.fSelectedFiles.length - 1].fileContentKey.getLocation().getURI().getPath(); path= data.fSelectedFiles[data.fSelectedFiles.length - 1].fileContentKey.getLocation().getURI().getPath();
@ -352,7 +353,7 @@ abstract public class PDOMWriter implements IPDOMASTProcessor {
lock.release(); lock.release();
} }
if (th != null) { if (th != null) {
data.fStati.add(createStatus(NLS.bind(Messages.PDOMWriter_errorWhileParsing, data.fStatuses.add(createStatus(NLS.bind(Messages.PDOMWriter_errorWhileParsing,
fileInAST.fileContentKey.getLocation().getURI().getPath()), th)); fileInAST.fileContentKey.getLocation().getURI().getPath()), th));
} }
fStatistics.fAddToIndexTime += lock.getCumulativeLockTime(); fStatistics.fAddToIndexTime += lock.getCumulativeLockTime();
@ -414,7 +415,7 @@ abstract public class PDOMWriter implements IPDOMASTProcessor {
} }
if (th != null) { if (th != null) {
if (!reported) { if (!reported) {
data.fStati.add(CCorePlugin.createStatus(NLS.bind(Messages.PDOMWriter_errorResolvingName, data.fStatuses.add(CCorePlugin.createStatus(NLS.bind(Messages.PDOMWriter_errorResolvingName,
name.toString(), file.fileContentKey.getLocation().getURI().getPath()), th)); name.toString(), file.fileContentKey.getLocation().getURI().getPath()), th));
} }
reported= true; reported= true;
@ -593,7 +594,7 @@ abstract public class PDOMWriter implements IPDOMASTProcessor {
} }
} }
List<IncludeInformation> includeInfos= new ArrayList<IncludeInformation>(); List<IncludeInformation> includeInfos= new ArrayList<>();
for (int i= 0; i < lists.fIncludes.size(); i++) { for (int i= 0; i < lists.fIncludes.size(); i++) {
final IASTPreprocessorIncludeStatement stmt = lists.fIncludes.get(i); final IASTPreprocessorIncludeStatement stmt = lists.fIncludes.get(i);
if (!stmt.isResolved()) { if (!stmt.isResolved()) {

View file

@ -48,14 +48,15 @@ import com.ibm.icu.text.NumberFormat;
* Configures the abstract indexer task suitable for indexing projects. * Configures the abstract indexer task suitable for indexing projects.
*/ */
public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPDOMIndexerTask { public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPDOMIndexerTask {
private static final String TRUE = "true"; //$NON-NLS-1$ private static final String TRUE = Boolean.TRUE.toString();
private AbstractPDOMIndexer fIndexer; private AbstractPDOMIndexer fIndexer;
private boolean fWriteInfoToLog; private boolean fWriteInfoToLog;
protected PDOMIndexerTask(ITranslationUnit[] forceFiles, ITranslationUnit[] updateFiles, protected PDOMIndexerTask(ITranslationUnit[] forceFiles, ITranslationUnit[] updateFiles,
ITranslationUnit[] removeFiles, AbstractPDOMIndexer indexer, boolean isFastIndexer) { ITranslationUnit[] removeFiles, AbstractPDOMIndexer indexer, boolean isFastIndexer) {
super(concat(forceFiles, updateFiles), removeFiles, new ProjectIndexerInputAdapter(indexer.getProject()), isFastIndexer); super(concat(forceFiles, updateFiles), removeFiles, new ProjectIndexerInputAdapter(indexer.getProject()),
isFastIndexer);
fIndexer= indexer; fIndexer= indexer;
setShowActivity(checkDebugOption(TRACE_ACTIVITY, TRUE)); setShowActivity(checkDebugOption(TRACE_ACTIVITY, TRUE));
setShowInclusionProblems(checkDebugOption(TRACE_INCLUSION_PROBLEMS, TRUE)); setShowInclusionProblems(checkDebugOption(TRACE_INCLUSION_PROBLEMS, TRUE));
@ -105,7 +106,7 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
} }
private static ITranslationUnit[] concat(ITranslationUnit[] added, ITranslationUnit[] changed) { private static ITranslationUnit[] concat(ITranslationUnit[] added, ITranslationUnit[] changed) {
HashSet<ITranslationUnit> union = new HashSet<ITranslationUnit>(added.length + changed.length); HashSet<ITranslationUnit> union = new HashSet<>(added.length + changed.length);
union.addAll(Arrays.asList(added)); union.addAll(Arrays.asList(added));
union.addAll(Arrays.asList(changed)); union.addAll(Arrays.asList(changed));
final ITranslationUnit[] result = union.toArray(new ITranslationUnit[union.size()]); final ITranslationUnit[] result = union.toArray(new ITranslationUnit[union.size()]);
@ -166,7 +167,7 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
private Set<String> getStringSet(String key) { private Set<String> getStringSet(String key) {
String prefSetting = getIndexer().getProperty(key); String prefSetting = getIndexer().getProperty(key);
if (prefSetting != null && !prefSetting.isEmpty()) { if (prefSetting != null && !prefSetting.isEmpty()) {
return new HashSet<String>(Arrays.asList(prefSetting.split(","))); //$NON-NLS-1$ return new HashSet<>(Arrays.asList(prefSetting.split(","))); //$NON-NLS-1$
} }
return Collections.emptySet(); return Collections.emptySet();
@ -249,7 +250,7 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
// tracing // tracing
if (checkDebugOption(IPDOMIndexerTask.TRACE_STATISTICS, TRUE)) { if (checkDebugOption(IPDOMIndexerTask.TRACE_STATISTICS, TRUE)) {
String ident= " "; //$NON-NLS-1$ String indent= " "; //$NON-NLS-1$
final long totalTime = System.currentTimeMillis() - start; final long totalTime = System.currentTimeMillis() - start;
final IndexerProgress info= getProgressInformation(); final IndexerProgress info= getProgressInformation();
final int sum= fStatistics.fDeclarationCount + fStatistics.fReferenceCount + fStatistics.fProblemBindingCount; final int sum= fStatistics.fDeclarationCount + fStatistics.fReferenceCount + fStatistics.fProblemBindingCount;
@ -265,7 +266,7 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
boolean skipImplRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_IMPLICIT_REFERENCES); boolean skipImplRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_IMPLICIT_REFERENCES);
boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES); boolean skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_REFERENCES);
boolean skipMacroRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES); boolean skipMacroRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_MACRO_REFERENCES);
System.out.println(ident + " Options: " //$NON-NLS-1$ System.out.println(indent + " Options: " //$NON-NLS-1$
+ "indexer='" + kind //$NON-NLS-1$ + "indexer='" + kind //$NON-NLS-1$
+ "', parseAllFiles=" + indexFilesWithoutConfiguration() //$NON-NLS-1$ + "', parseAllFiles=" + indexFilesWithoutConfiguration() //$NON-NLS-1$
+ ", unusedHeaders=" + getIndexHeadersWithoutContext() //$NON-NLS-1$ + ", unusedHeaders=" + getIndexHeadersWithoutContext() //$NON-NLS-1$
@ -274,25 +275,25 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
+ ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$ + ", skipTypeReferences=" + skipTypeRefs //$NON-NLS-1$
+ ", skipMacroReferences=" + skipMacroRefs //$NON-NLS-1$ + ", skipMacroReferences=" + skipMacroRefs //$NON-NLS-1$
+ "."); //$NON-NLS-1$ + "."); //$NON-NLS-1$
System.out.println(ident + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.println(indent + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(ident + " Timings: " //$NON-NLS-1$ System.out.println(indent + " Timings: " //$NON-NLS-1$
+ totalTime + " total, " //$NON-NLS-1$ + totalTime + " total, " //$NON-NLS-1$
+ fStatistics.fParsingTime + " parser, " //$NON-NLS-1$ + fStatistics.fParsingTime + " parser, " //$NON-NLS-1$
+ fStatistics.fResolutionTime + " resolution, " //$NON-NLS-1$ + fStatistics.fResolutionTime + " resolution, " //$NON-NLS-1$
+ fStatistics.fAddToIndexTime + " index update."); //$NON-NLS-1$ + fStatistics.fAddToIndexTime + " index update."); //$NON-NLS-1$
System.out.println(ident + " Errors: " //$NON-NLS-1$ System.out.println(indent + " Errors: " //$NON-NLS-1$
+ fStatistics.fErrorCount + " internal, " //$NON-NLS-1$ + fStatistics.fErrorCount + " internal, " //$NON-NLS-1$
+ fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$ + fStatistics.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$
+ fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$ + fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$
+ fStatistics.fSyntaxProblemsCount + " syntax errors."); //$NON-NLS-1$ + fStatistics.fSyntaxProblemsCount + " syntax errors."); //$NON-NLS-1$
if (fStatistics.fTooManyTokensCount > 0) if (fStatistics.fTooManyTokensCount > 0)
System.out.println(ident + " Tokens: " //$NON-NLS-1$ System.out.println(indent + " Tokens: " //$NON-NLS-1$
+ fStatistics.fTooManyTokensCount + " TUs with too many tokens."); //$NON-NLS-1$ + fStatistics.fTooManyTokensCount + " TUs with too many tokens."); //$NON-NLS-1$
NumberFormat nfPercent= NumberFormat.getPercentInstance(); NumberFormat nfPercent= NumberFormat.getPercentInstance();
nfPercent.setMaximumFractionDigits(2); nfPercent.setMaximumFractionDigits(2);
nfPercent.setMinimumFractionDigits(2); nfPercent.setMinimumFractionDigits(2);
System.out.println(ident + " Names: " //$NON-NLS-1$ System.out.println(indent + " Names: " //$NON-NLS-1$
+ fStatistics.fDeclarationCount + " declarations, " //$NON-NLS-1$ + fStatistics.fDeclarationCount + " declarations, " //$NON-NLS-1$
+ fStatistics.fReferenceCount + " references, " //$NON-NLS-1$ + fStatistics.fReferenceCount + " references, " //$NON-NLS-1$
+ fStatistics.fProblemBindingCount + "(" + nfPercent.format(problemPct) + ") unresolved."); //$NON-NLS-1$ //$NON-NLS-2$ + fStatistics.fProblemBindingCount + "(" + nfPercent.format(problemPct) + ") unresolved."); //$NON-NLS-1$ //$NON-NLS-2$
@ -301,7 +302,7 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
long hits= index.getCacheHits(); long hits= index.getCacheHits();
long tries= misses + hits; long tries= misses + hits;
double missPct= tries == 0 ? 0.0 : (double) misses / (double) tries; double missPct= tries == 0 ? 0.0 : (double) misses / (double) tries;
System.out.println(ident + " Cache[" //$NON-NLS-1$ System.out.println(indent + " Cache[" //$NON-NLS-1$
+ ChunkCache.getSharedInstance().getMaxSize() / 1024 / 1024 + "MB]: " + //$NON-NLS-1$ + ChunkCache.getSharedInstance().getMaxSize() / 1024 / 1024 + "MB]: " + //$NON-NLS-1$
+ hits + " hits, " //$NON-NLS-1$ + hits + " hits, " //$NON-NLS-1$
+ misses + "(" + nfPercent.format(missPct) + ") misses."); //$NON-NLS-1$ //$NON-NLS-2$ + misses + "(" + nfPercent.format(missPct) + ") misses."); //$NON-NLS-1$ //$NON-NLS-2$

View file

@ -37,7 +37,7 @@ import org.eclipse.osgi.util.NLS;
*/ */
public class PDOMRebuildTask implements IPDOMIndexerTask { public class PDOMRebuildTask implements IPDOMIndexerTask {
protected static final String TRUE= String.valueOf(true); protected static final String TRUE= String.valueOf(true);
protected static final ITranslationUnit[] NO_TUS = new ITranslationUnit[0]; protected static final ITranslationUnit[] NO_TUS = {};
private final IPDOMIndexer fIndexer; private final IPDOMIndexer fIndexer;
private final IndexerProgress fProgress; private final IndexerProgress fProgress;
@ -78,7 +78,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
createDelegate(cproject, monitor); createDelegate(cproject, monitor);
} }
} }
// remove task-tags. // Remove task-tags.
TodoTaskUpdater.removeTasksFor(project); TodoTaskUpdater.removeTasksFor(project);
} catch (CoreException e) { } catch (CoreException e) {
CCorePlugin.log(NLS.bind(Messages.PDOMRebuildTask_0, cproject.getElementName() ), e); CCorePlugin.log(NLS.bind(Messages.PDOMRebuildTask_0, cproject.getElementName() ), e);
@ -112,7 +112,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
boolean allFiles = boolean allFiles =
TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG)) || TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG)) ||
TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_ALTERNATE_LANG)); TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_ALTERNATE_LANG));
List<ITranslationUnit> sources= new ArrayList<ITranslationUnit>(); List<ITranslationUnit> sources= new ArrayList<>();
List<ITranslationUnit> headers= allFiles ? sources : null; List<ITranslationUnit> headers= allFiles ? sources : null;
TranslationUnitCollector collector= new TranslationUnitCollector(sources, headers, monitor); TranslationUnitCollector collector= new TranslationUnitCollector(sources, headers, monitor);
project.accept(collector); project.accept(collector);

View file

@ -75,8 +75,7 @@ public class TodoTaskParser {
return tasks.toArray(new Task[tasks.size()]); return tasks.toArray(new Task[tasks.size()]);
} }
private void parse(char[] comment, String filename, int offset, int lineNumber, private void parse(char[] comment, String filename, int offset, int lineNumber, List<Task> tasks) {
List<Task> tasks) {
int commentLength = comment.length; int commentLength = comment.length;
int foundTaskIndex = tasks.size(); int foundTaskIndex = tasks.size();

View file

@ -9,7 +9,6 @@
* Sergey Prigogin (Google) - initial API and implementation * Sergey Prigogin (Google) - initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.indexer; package org.eclipse.cdt.internal.core.pdom.indexer;
import java.util.ArrayList; import java.util.ArrayList;
@ -100,12 +99,14 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
class TaskList { class TaskList {
IFile fFile; IFile fFile;
List<Task> fTasks; List<Task> fTasks;
public TaskList(IFile file) { public TaskList(IFile file) {
fFile= file; fFile= file;
} }
public void add(Task task) { public void add(Task task) {
if (fTasks == null) { if (fTasks == null) {
fTasks= new ArrayList<Task>(); fTasks= new ArrayList<>();
} }
fTasks.add(task); fTasks.add(task);
} }
@ -113,9 +114,9 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
// first collect all valid file-locations // First collect all valid file-locations.
final Map<IPath, TaskList> pathToTaskList= new HashMap<IPath, TaskList>(); final Map<IPath, TaskList> pathToTaskList= new HashMap<>();
final Set<IProject> projects= new HashSet<IProject>(); final Set<IProject> projects= new HashSet<>();
for (final IIndexFileLocation indexFileLocation : filesToUpdate) { for (final IIndexFileLocation indexFileLocation : filesToUpdate) {
final String filepath = indexFileLocation.getFullPath(); final String filepath = indexFileLocation.getFullPath();
if (filepath != null) { if (filepath != null) {
@ -137,7 +138,7 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
} }
} }
// run this in a job in order not to block the indexer (bug 210730). // Update markers in a job in order not to block the indexer (bug 210730).
if (!pathToTaskList.isEmpty()) { if (!pathToTaskList.isEmpty()) {
WorkspaceJob job= new WorkspaceJob(Messages.TodoTaskUpdater_UpdateJob) { WorkspaceJob job= new WorkspaceJob(Messages.TodoTaskUpdater_UpdateJob) {
@Override @Override
@ -174,8 +175,7 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
private void applyTask(Task task, IResource resource) throws CoreException { private void applyTask(Task task, IResource resource) throws CoreException {
IMarker marker = resource.createMarker(ICModelMarker.TASK_MARKER); IMarker marker = resource.createMarker(ICModelMarker.TASK_MARKER);
String description = NLS.bind(Messages.TodoTaskUpdater_taskFormat, String description = NLS.bind(Messages.TodoTaskUpdater_taskFormat, task.getTag(), task.getMessage());
task.getTag(), task.getMessage());
marker.setAttributes( marker.setAttributes(
TASK_MARKER_ATTRIBUTE_NAMES, TASK_MARKER_ATTRIBUTE_NAMES,
new Object[] { new Object[] {
@ -203,7 +203,7 @@ public class TodoTaskUpdater implements ITodoTaskUpdater {
return; return;
} }
// run this in a job in order not to block the indexer (bug 210730). // Delete markers in a job in order not to block the indexer (bug 210730).
WorkspaceJob job= new WorkspaceJob(Messages.TodoTaskUpdater_DeleteJob) { WorkspaceJob job= new WorkspaceJob(Messages.TodoTaskUpdater_DeleteJob) {
@Override @Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {

View file

@ -64,7 +64,7 @@ public abstract class IncludesTestBase extends BaseTestCase {
protected TestSourceFile selectedFile; protected TestSourceFile selectedFile;
private StringBuilder[] testData; private StringBuilder[] testData;
private boolean cpp = true; private boolean cpp = true;
private final Set<TestSourceFile> testFiles = new LinkedHashSet<TestSourceFile>(); private final Set<TestSourceFile> testFiles = new LinkedHashSet<>();
protected IncludesTestBase() { protected IncludesTestBase() {
super(); super();

View file

@ -107,7 +107,7 @@ public class HeaderSubstitutor {
IncludeInfo includeInfo = fContext.getIncludeForHeaderFile(path); IncludeInfo includeInfo = fContext.getIncludeForHeaderFile(path);
if (includeInfo == null) if (includeInfo == null)
return path; return path;
List<IncludeInfo> candidates = new ArrayList<IncludeInfo>(); List<IncludeInfo> candidates = new ArrayList<>();
candidates.add(includeInfo); candidates.add(includeInfo);
IncludeMap[] maps = fIncludeMaps; IncludeMap[] maps = fIncludeMaps;
for (IncludeMap map : maps) { for (IncludeMap map : maps) {
@ -150,8 +150,8 @@ public class HeaderSubstitutor {
public IPath getPreferredRepresentativeHeaderByHeuristic(InclusionRequest request) { public IPath getPreferredRepresentativeHeaderByHeuristic(InclusionRequest request) {
Set<IIndexFile> indexFiles = request.getDeclaringFiles().keySet(); Set<IIndexFile> indexFiles = request.getDeclaringFiles().keySet();
String symbolName = request.getBinding().getName(); String symbolName = request.getBinding().getName();
ArrayDeque<IIndexFile> front = new ArrayDeque<IIndexFile>(); ArrayDeque<IIndexFile> front = new ArrayDeque<>();
HashSet<IIndexFile> processed = new HashSet<IIndexFile>(); HashSet<IIndexFile> processed = new HashSet<>();
try { try {
// Look for headers without an extension and a matching name. // Look for headers without an extension and a matching name.

View file

@ -42,9 +42,9 @@ public class IncludeCreationContext extends InclusionContext {
public IncludeCreationContext(ITranslationUnit tu, IIndex index) { public IncludeCreationContext(ITranslationUnit tu, IIndex index) {
super(tu); super(tu);
fIndex = index; fIndex = index;
fHeadersToInclude = new HashSet<IPath>(); fHeadersToInclude = new HashSet<>();
fHeadersAlreadyIncluded = new HashSet<IPath>(); fHeadersAlreadyIncluded = new HashSet<>();
fHeadersIncludedPreviously = new HashSet<IPath>(); fHeadersIncludedPreviously = new HashSet<>();
} }
public String getSourceContents() { public String getSourceContents() {
@ -67,7 +67,7 @@ public class IncludeCreationContext extends InclusionContext {
*/ */
public void removeExportedHeaders() throws CoreException { public void removeExportedHeaders() throws CoreException {
// Index files keyed by their absolute paths. // Index files keyed by their absolute paths.
Map<IPath, IIndexFile> filesByPath = new HashMap<IPath, IIndexFile>(); Map<IPath, IIndexFile> filesByPath = new HashMap<>();
for (IIndexFile file : fIndex.getAllFiles()) { for (IIndexFile file : fIndex.getAllFiles()) {
IPath path = getPath(file); IPath path = getPath(file);
filesByPath.put(path, file); filesByPath.put(path, file);
@ -79,12 +79,12 @@ public class IncludeCreationContext extends InclusionContext {
private void removeExportedHeaders(Set<IPath> exportingHeaders, private void removeExportedHeaders(Set<IPath> exportingHeaders,
Map<IPath, IIndexFile> filesByPath) throws CoreException { Map<IPath, IIndexFile> filesByPath) throws CoreException {
Set<IPath> exportedHeaders = new HashSet<IPath>(); Set<IPath> exportedHeaders = new HashSet<>();
for (IPath path : exportingHeaders) { for (IPath path : exportingHeaders) {
if (!exportedHeaders.contains(path)) { if (!exportedHeaders.contains(path)) {
IIndexFile file = filesByPath.get(path); IIndexFile file = filesByPath.get(path);
if (file != null) { // file can be null if the header was not indexed. if (file != null) { // file can be null if the header was not indexed.
ArrayDeque<IIndexFile> queue = new ArrayDeque<IIndexFile>(); ArrayDeque<IIndexFile> queue = new ArrayDeque<>();
queue.add(file); queue.add(file);
while ((file = queue.pollFirst()) != null) { while ((file = queue.pollFirst()) != null) {
for (IIndexInclude include : file.getIncludes()) { for (IIndexInclude include : file.getIncludes()) {

View file

@ -39,7 +39,7 @@ public class IncludeMap {
public IncludeMap(boolean unconditionalSubstitution) { public IncludeMap(boolean unconditionalSubstitution) {
this.unconditionalSubstitution = unconditionalSubstitution; this.unconditionalSubstitution = unconditionalSubstitution;
this.map = new LinkedHashMap<IncludeInfo, List<IncludeInfo>>(); this.map = new LinkedHashMap<>();
} }
/** /**
@ -51,7 +51,7 @@ public class IncludeMap {
if (keysAndValues.length % 2 != 0) if (keysAndValues.length % 2 != 0)
throw new IllegalArgumentException("More keys than values"); //$NON-NLS-1$ throw new IllegalArgumentException("More keys than values"); //$NON-NLS-1$
this.unconditionalSubstitution = unconditionalSubstitution; this.unconditionalSubstitution = unconditionalSubstitution;
this.map = new LinkedHashMap<IncludeInfo, List<IncludeInfo>>(keysAndValues.length / 2); this.map = new LinkedHashMap<>(keysAndValues.length / 2);
for (int i = 0; i < keysAndValues.length;) { for (int i = 0; i < keysAndValues.length;) {
String key = keysAndValues[i++]; String key = keysAndValues[i++];
addMapping(key, keysAndValues[i++]); addMapping(key, keysAndValues[i++]);
@ -60,7 +60,7 @@ public class IncludeMap {
public IncludeMap(IncludeMap other) { public IncludeMap(IncludeMap other) {
this.unconditionalSubstitution = other.unconditionalSubstitution; this.unconditionalSubstitution = other.unconditionalSubstitution;
this.map = new LinkedHashMap<IncludeInfo, List<IncludeInfo>>(other.map.size()); this.map = new LinkedHashMap<>(other.map.size());
addAllMappings(other); addAllMappings(other);
} }
@ -75,7 +75,7 @@ public class IncludeMap {
return; // Don't allow mapping to itself. return; // Don't allow mapping to itself.
List<IncludeInfo> list = map.get(from); List<IncludeInfo> list = map.get(from);
if (list == null) { if (list == null) {
list = new ArrayList<IncludeInfo>(2); list = new ArrayList<>(2);
map.put(from, list); map.put(from, list);
} }
list.add(to); list.add(to);
@ -158,7 +158,7 @@ public class IncludeMap {
* Writes the map to a memento. The {@link #isUnconditionalSubstitution()} flag is not written. * Writes the map to a memento. The {@link #isUnconditionalSubstitution()} flag is not written.
*/ */
public void saveToMemento(IMemento memento) { public void saveToMemento(IMemento memento) {
List<IncludeInfo> keys = new ArrayList<IncludeInfo>(map.keySet()); List<IncludeInfo> keys = new ArrayList<>(map.keySet());
Collections.sort(keys); Collections.sort(keys);
for (IncludeInfo key : keys) { for (IncludeInfo key : keys) {
for (IncludeInfo value : map.get(key)) { for (IncludeInfo value : map.get(key)) {
@ -189,7 +189,7 @@ public class IncludeMap {
List<IncludeInfo> otherTargets = entry.getValue(); List<IncludeInfo> otherTargets = entry.getValue();
List<IncludeInfo> targets = map.get(source); List<IncludeInfo> targets = map.get(source);
if (targets == null) { if (targets == null) {
targets = new ArrayList<IncludeInfo>(otherTargets); targets = new ArrayList<>(otherTargets);
map.put(source, targets); map.put(source, targets);
} else { } else {
targets.addAll(otherTargets); targets.addAll(otherTargets);
@ -201,12 +201,12 @@ public class IncludeMap {
for (Entry<IncludeInfo, List<IncludeInfo>> entry : map.entrySet()) { for (Entry<IncludeInfo, List<IncludeInfo>> entry : map.entrySet()) {
IncludeInfo source = entry.getKey(); IncludeInfo source = entry.getKey();
List<IncludeInfo> targets = entry.getValue(); List<IncludeInfo> targets = entry.getValue();
ArrayDeque<IncludeInfo> queue = new ArrayDeque<IncludeInfo>(targets); ArrayDeque<IncludeInfo> queue = new ArrayDeque<>(targets);
targets.clear(); targets.clear();
HashSet<IncludeInfo> processed = new HashSet<IncludeInfo>(); HashSet<IncludeInfo> processed = new HashSet<>();
if (!unconditionalSubstitution) if (!unconditionalSubstitution)
processed.add(source); // Don't allow mapping to itself. processed.add(source); // Don't allow mapping to itself.
HashSet<IncludeInfo> seenTargets = new HashSet<IncludeInfo>(); HashSet<IncludeInfo> seenTargets = new HashSet<>();
IncludeInfo target; IncludeInfo target;
queueLoop: while ((target = queue.pollFirst()) != null) { queueLoop: while ((target = queue.pollFirst()) != null) {
if (processed.contains(target)) if (processed.contains(target))
@ -263,7 +263,7 @@ public class IncludeMap {
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(); StringBuilder buf = new StringBuilder();
buf.append("upconditionalSubstitution = ").append(unconditionalSubstitution); //$NON-NLS-1$ buf.append("upconditionalSubstitution = ").append(unconditionalSubstitution); //$NON-NLS-1$
ArrayList<IncludeInfo> sources = new ArrayList<IncludeInfo>(map.keySet()); ArrayList<IncludeInfo> sources = new ArrayList<>(map.keySet());
Collections.sort(sources); Collections.sort(sources);
for (IncludeInfo source : sources) { for (IncludeInfo source : sources) {
buf.append('\n'); buf.append('\n');