1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 17:25:38 +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.IASTTypeIdExpression;
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.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
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.c.ICASTTypeIdInitializerExpression;
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 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_MINOR__", Integer.toString(GPPLanguage.GNU_LATEST_VERSION_MINOR));
map.put("__SIZEOF_SHORT__", "2");
@ -125,7 +125,7 @@ public class AST2TestBase extends BaseTestCase {
}
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_INT__", "4");
map.put("__SIZEOF_LONG__", "8");
@ -173,7 +173,7 @@ public class AST2TestBase extends BaseTestCase {
} else {
config = new ANSICPPParserExtensionConfiguration();
}
parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG,config, null);
parser = new GNUCPPSourceParser(scanner, ParserMode.COMPLETE_PARSE, NULL_LOG, config, null);
} else {
ICParserExtensionConfiguration config = null;
@ -312,7 +312,7 @@ public class AST2TestBase extends BaseTestCase {
this.shouldVisitImplicitNames = shouldVisitImplicitNames;
}
public List<IASTName> nameList = new ArrayList<IASTName>();
public List<IASTName> nameList = new ArrayList<>();
@Override
public int visit(IASTName name) {
@ -408,7 +408,7 @@ public class AST2TestBase extends BaseTestCase {
}
public int numProblemBindings;
public int numNullBindings;
public List<IASTName> nameList = new ArrayList<IASTName>();
public List<IASTName> nameList = new ArrayList<>();
@Override
public int visit(IASTName name) {
@ -438,7 +438,7 @@ public class AST2TestBase extends BaseTestCase {
}
public int numProblemBindings;
public int numNullBindings;
public List<IASTName> nameList = new ArrayList<IASTName>();
public List<IASTName> nameList = new ArrayList<>();
@Override
public int visit(IASTName name) {

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.parser.tests.scanner;
@ -37,7 +37,6 @@ import org.eclipse.cdt.internal.core.parser.scanner.CPreprocessor;
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
public abstract class PreprocessorTestsBase extends BaseTestCase {
private static final IParserLogService NULL_LOG = new NullLogService();
protected CPreprocessor fScanner;
protected ILocationResolver fLocationResolver;
@ -78,11 +77,10 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
IncludeFileContentProvider readerFactory= FileCodeReaderFactory.getInstance();
//IScannerExtensionConfiguration scannerConfig;
if(scannerConfig == null) {
if (scannerConfig == null) {
if (lang == ParserLanguage.C) {
scannerConfig= GCCScannerExtensionConfiguration.getInstance();
}
else {
} else {
scannerConfig= GPPScannerExtensionConfiguration.getInstance(scannerInfo);
}
}
@ -106,10 +104,10 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
protected void fullyTokenize() throws Exception {
try {
for(;;) {
for (;;) {
IToken t= fScanner.nextToken();
}
} catch ( EndOfFileException e){
} catch (EndOfFileException e) {
}
}
@ -176,8 +174,7 @@ public abstract class PreprocessorTestsBase extends BaseTestCase {
try {
IToken t= fScanner.nextToken();
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]);
}
}
}

View file

@ -18,8 +18,6 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.zip.ZipFile;
import junit.framework.Assert;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
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.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
import org.junit.Assert;
import org.osgi.framework.Bundle;
/**
* Helper methods to set up a ICProject.
*/
@ -357,7 +357,7 @@ public class CProjectHelper {
* @throws InterruptedException
*/
public static ITranslationUnit findTranslationUnit(ICProject testProject, String name) throws CModelException, InterruptedException {
for (int j=0; j<20; j++) {
for (int j = 0; j < 20; j++) {
ICElement[] sourceRoots = testProject.getChildren();
for (int i = 0; i < sourceRoots.length; i++) {
ISourceRoot root = (ISourceRoot) sourceRoots[i];

View file

@ -8,7 +8,6 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.testplugin;
// copied from startup.jar. planned to be removed soon
@ -73,51 +72,51 @@ public class Main {
/**
* Indicates whether this instance is running in debug mode.
*/
protected boolean debug = false;
protected boolean debug;
/**
* The location of the launcher to run.
*/
protected String bootLocation = null;
protected String bootLocation;
/**
* The identifier of the application to run.
*/
protected String application;
/**
* The path for finding find plugins.
*/
protected URL pluginPathLocation;
/**
* The boot path location.
*/
protected String location;
/**
* Indicates whether items for UNinstallation should be looked for.
*/
protected boolean uninstall = false;
protected boolean uninstall;
/**
* The item to be uninstalled.
*/
protected String uninstallCookie;
/**
* The class path entries.
*/
protected String devClassPath = null;
protected String devClassPath;
/**
* 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
private static String endSplash = null;
private static String endSplash;
// constants
private static final String APPLICATION = "-application";
private static final String BOOT = "-boot";
@ -152,390 +151,398 @@ public class Main {
}
}
/**
* Executes the launch.
*
* @return the result of performing the launch
* @param args command-line arguments
* @exception Exception thrown if a problem occurs during the launch
*/
protected Object basicRun(String[] args) throws Exception {
Class clazz = getBootLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, URL.class, String.class, String[].class });
try {
return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args });
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Error)
throw (Error) e.getTargetException();
else
throw e;
/**
* Executes the launch.
*
* @return the result of performing the launch
* @param args command-line arguments
* @exception Exception thrown if a problem occurs during the launch
*/
protected Object basicRun(String[] args) throws Exception {
Class clazz = getBootLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, URL.class, String.class, String[].class });
try {
return method.invoke(clazz, new Object[] { application, pluginPathLocation, location, args });
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Error)
throw (Error) e.getTargetException();
else
throw e;
}
}
}
/**
* Returns the result of converting a list of comma-separated tokens into an array
*
* @return the array of string tokens
* @param prop the initial comma-separated string
*/
private String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().equals(""))
return new String[0];
List<String> list = new ArrayList<String>();
StringTokenizer tokens = new StringTokenizer(prop, ",");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (!token.equals(""))
list.add(token);
/**
* Returns the result of converting a list of comma-separated tokens into an array
*
* @return the array of string tokens
* @param prop the initial comma-separated string
*/
private String[] getArrayFromList(String prop) {
if (prop == null || prop.trim().equals(""))
return new String[0];
List<String> list = new ArrayList<>();
StringTokenizer tokens = new StringTokenizer(prop, ",");
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken().trim();
if (!token.equals(""))
list.add(token);
}
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
* up and run the platform. The given base, if not <code>null</code>,
* is the location of the boot loader code. If the value is <code>null</code>
* then the boot loader is located relative to this class.
*
* @return the new boot loader
* @param base the location of the boot loader
*/
public Class getBootLoader(String base) throws Exception {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null);
return loader.loadClass(BOOTLOADER);
}
/**
* Returns the <code>URL</code>-based class path describing where the boot classes
* are located when running in development mode.
*
* @return the url-based class path
* @param base the base location
* @exception MalformedURLException if a problem occurs computing the class path
*/
protected URL[] getDevPath(URL base) throws MalformedURLException {
URL url;
String devBase = base.toExternalForm();
if (!inDevelopmentMode) {
/**
* 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>,
* is the location of the boot loader code. If the value is <code>null</code>
* then the boot loader is located relative to this class.
*
* @return the new boot loader
* @param base the location of the boot loader
*/
public Class getBootLoader(String base) throws Exception {
try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
return loader.loadClass(BOOTLOADER);
}
}
/**
* Returns the <code>URL</code>-based class path describing where the boot classes
* are located when running in development mode.
*
* @return the url-based class path
* @param base the base location
* @exception MalformedURLException if a problem occurs computing the class path
*/
protected URL[] getDevPath(URL base) throws MalformedURLException {
URL url;
String devBase = base.toExternalForm();
if (!inDevelopmentMode) {
url = new URL(devBase + "boot.jar");
return new URL[] {url};
}
String[] locations = getArrayFromList(devClassPath);
ArrayList result = new ArrayList(locations.length);
for (int i = 0; i < locations.length; i++) {
String spec = devBase + locations[i];
char lastChar = spec.charAt(spec.length() - 1);
if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\')))
url = new URL (spec);
else
url = new URL(spec + "/");
//make sure URL exists before adding to path
if (new java.io.File(url.getFile()).exists())
result.add(url);
}
url = new URL(devBase + "boot.jar");
return new URL[] {url};
}
String[] locations = getArrayFromList(devClassPath);
ArrayList result = new ArrayList(locations.length);
for (int i = 0; i < locations.length; i++) {
String spec = devBase + locations[i];
char lastChar = spec.charAt(spec.length() - 1);
if ((spec.endsWith(".jar") || (lastChar == '/' || lastChar == '\\')))
url = new URL (spec);
else
url = new URL(spec + "/");
//make sure URL exists before adding to path
if (new java.io.File(url.getFile()).exists())
result.add(url);
return (URL[])result.toArray(new URL[result.size()]);
}
url = new URL(devBase + "boot.jar");
if (new java.io.File(url.getFile()).exists())
result.add(url);
return (URL[])result.toArray(new URL[result.size()]);
}
/**
* Returns the <code>URL</code>-based class path describing where the boot classes are located.
*
* @return the url-based class path
* @param base the base location
* @exception MalformedURLException if a problem occurs computing the class path
*/
protected URL[] getBootPath(String base) throws MalformedURLException {
URL url = null;
// if the given location is not null, assume it is correct and use it.
if (base != null) {
url = new URL(base);
if (debug)
System.out.println("Boot URL: " + url.toExternalForm());
return new URL[] {url};
}
// Create a URL based on the location of this class' code.
// strip off jar file and/or last directory to get
// to the directory containing projects.
URL[] result = null;
url = getClass().getProtectionDomain().getCodeSource().getLocation();
String path = url.getFile();
if (path.endsWith(".jar"))
path = path.substring(0, path.lastIndexOf("/"));
else
if (path.endsWith("/"))
path = path.substring(0, path.length() - 1);
if (inVAJ || inVAME) {
int ix = path.lastIndexOf("/");
path = path.substring(0, ix + 1);
path = path + PROJECT_NAME + "/";
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = new URL[] {url};
} else {
path = searchForPlugins(path);
path = searchForBoot(path);
// add on any dev path elements
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = getDevPath(url);
}
if (debug) {
System.out.println("Boot URL:");
for (int i = 0; i < result.length; i++)
System.out.println(" " + result[i].toExternalForm());
}
return result;
}
/**
* Searches for a plugins root starting at a given location. If one is
* found then this location is returned; otherwise an empty string is
* returned.
*
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at
*/
protected String searchForPlugins(String start) {
File path = new File(start);
while (path != null) {
File test = new File(path, "plugins");
if (test.exists())
return test.toString();
path = path.getParentFile();
path = (path == null || path.length() == 1) ? null : path;
}
return "";
}
/**
* Searches for a boot directory starting at a given location. If one
* is found then this location is returned; otherwise an empty string
* is returned.
*
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at
*/
protected String searchForBoot(String start) {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File candidate) {
return candidate.getName().startsWith(PI_BOOT);
/**
* Returns the <code>URL</code>-based class path describing where the boot classes are located.
*
* @return the url-based class path
* @param base the base location
* @exception MalformedURLException if a problem occurs computing the class path
*/
protected URL[] getBootPath(String base) throws MalformedURLException {
URL url = null;
// if the given location is not null, assume it is correct and use it.
if (base != null) {
url = new URL(base);
if (debug)
System.out.println("Boot URL: " + url.toExternalForm());
return new URL[] {url};
}
};
File[] boots = new File(start).listFiles(filter);
String result = null;
String maxVersion = null;
for (int i = 0; i < boots.length; i++) {
String name = boots[i].getName();
int index = name.lastIndexOf('_');
if (index == -1) {
result = boots[i].getAbsolutePath();
i = boots.length;
// Create a URL based on the location of this class' code.
// strip off jar file and/or last directory to get
// to the directory containing projects.
URL[] result = null;
url = getClass().getProtectionDomain().getCodeSource().getLocation();
String path = url.getFile();
if (path.endsWith(".jar"))
path = path.substring(0, path.lastIndexOf("/"));
else
if (path.endsWith("/"))
path = path.substring(0, path.length() - 1);
if (inVAJ || inVAME) {
int ix = path.lastIndexOf("/");
path = path.substring(0, ix + 1);
path = path + PROJECT_NAME + "/";
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = new URL[] {url};
} else {
if (index > 0) {
String version = name.substring(index + 1);
if (maxVersion == null) {
result = boots[i].getAbsolutePath();
maxVersion = version;
} else
if (maxVersion.compareTo(version) == -1) {
path = searchForPlugins(path);
path = searchForBoot(path);
// add on any dev path elements
url = new URL(url.getProtocol(), url.getHost(), url.getPort(), path);
result = getDevPath(url);
}
if (debug) {
System.out.println("Boot URL:");
for (int i = 0; i < result.length; i++)
System.out.println(" " + result[i].toExternalForm());
}
return result;
}
/**
* Searches for a plugins root starting at a given location. If one is
* found then this location is returned; otherwise an empty string is
* returned.
*
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at
*/
protected String searchForPlugins(String start) {
File path = new File(start);
while (path != null) {
File test = new File(path, "plugins");
if (test.exists())
return test.toString();
path = path.getParentFile();
path = (path == null || path.length() == 1) ? null : path;
}
return "";
}
/**
* Searches for a boot directory starting at a given location. If one
* is found then this location is returned; otherwise an empty string
* is returned.
*
* @return the location where plugins were found, or an empty string
* @param start the location to begin searching at
*/
protected String searchForBoot(String start) {
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File candidate) {
return candidate.getName().startsWith(PI_BOOT);
}
};
File[] boots = new File(start).listFiles(filter);
String result = null;
String maxVersion = null;
for (int i = 0; i < boots.length; i++) {
String name = boots[i].getName();
int index = name.lastIndexOf('_');
if (index == -1) {
result = boots[i].getAbsolutePath();
i = boots.length;
} else {
if (index > 0) {
String version = name.substring(index + 1);
if (maxVersion == null) {
result = boots[i].getAbsolutePath();
maxVersion = version;
}
} else
if (maxVersion.compareTo(version) == -1) {
result = boots[i].getAbsolutePath();
maxVersion = version;
}
}
}
}
if (result == null)
throw new RuntimeException("Could not find bootstrap code. Check location of boot plug-in or specify -boot.");
return result.replace(File.separatorChar, '/') + "/";
}
if (result == null)
throw new RuntimeException("Could not find bootstrap code. Check location of boot plug-in or specify -boot.");
return result.replace(File.separatorChar, '/') + "/";
}
/**
* Returns the update loader for the given boot path.
*
* @return the update loader
* @param base the boot path base
* @exception Exception thrown is a problem occurs determining this loader
*/
public Class getUpdateLoader(String base) throws Exception {
URLClassLoader loader = new URLClassLoader(getBootPath(base), null);
return loader.loadClass(UPDATELOADER);
}
/**
* Runs the platform with the given arguments. The arguments must identify
* an application to run (e.g., <code>-application com.example.application</code>).
* After running the application <code>System.exit(N)</code> is executed.
* The value of N is derived from the value returned from running the application.
* If the application's return value is an <code>Integer</code>, N is this value.
* In all other cases, N = 0.
* <p>
* Clients wishing to run the platform without a following <code>System.exit</code>
* call should use <code>run()</code>.
*
* @see #run
*
* @param args the command line arguments
*/
public static void main(String[] args) {
Object result = null;
try {
result = new Main().run(args);
} catch (Throwable e) {
// try and take down the splash screen.
endSplash();
System.out.println("Exception launching the Eclipse Platform:");
e.printStackTrace();
}
int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
System.exit(exitCode);
}
/**
* Tears down the currently-displayed splash screen.
*/
public static void endSplash() {
if (endSplash == null)
return;
try {
Runtime.getRuntime().exec(endSplash);
} catch (Exception e) {
}
}
/**
* Runs this launcher with the arguments specified in the given string.
*
* @param argString the arguments string
* @exception Exception thrown if a problem occurs during launching
*/
public static void main(String argString) throws Exception {
List<String> list = new ArrayList<String>(5);
for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();)
list.add((String) tokens.nextElement());
main(list.toArray(new String[list.size()]));
}
/**
* Processes the command line arguments
*
* @return the arguments to pass through to the launched application
* @param args the command line arguments
*/
protected String[] processCommandLine(String[] args) throws Exception {
int[] configArgs = new int[100];
configArgs[0] = -1; // need to initialize the first element to something that could not be an index.
int configArgIndex = 0;
for (int i = 0; i < args.length; i++) {
boolean found = false;
// check for args without parameters (i.e., a flag arg)
// check if debug should be enabled for the entire platform
if (args[i].equalsIgnoreCase(DEBUG)) {
debug = true;
// passed thru this arg (i.e., do not set found = true
continue;
}
// check if development mode should be enabled for the entire platform
// If this is the last arg or there is a following arg (i.e., arg+1 has a leading -),
// simply enable development mode. Otherwise, assume that that the following arg is
// actually some additional development time class path entries. This will be processed below.
if (args[i].equalsIgnoreCase(DEV) && ((i + 1 == args.length) || ((i + 1 < args.length) && (args[i + 1].startsWith("-"))))) {
inDevelopmentMode = true;
// do not mark the arg as found so it will be passed through
continue;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i;
continue;
}
// check for args with parameters. If we are at the last argument or if the next one
// has a '-' as the first character, then we can't have an arg with a parm so continue.
if (i == args.length - 1 || args[i + 1].startsWith("-"))
continue;
String arg = args[++i];
// look for the laucher to run
if (args[i - 1].equalsIgnoreCase(BOOT)) {
bootLocation = arg;
found = true;
}
// look for the development mode and class path entries.
if (args[i - 1].equalsIgnoreCase(DEV)) {
inDevelopmentMode = true;
devClassPath = arg;
continue;
}
// look for the application to run
if (args[i - 1].equalsIgnoreCase(APPLICATION)) {
application = arg;
found = true;
}
// look for token to use to end the splash screen
if (args[i - 1].equalsIgnoreCase(ENDSPLASH)) {
endSplash = arg;
continue;
}
// look for items to uninstall
if (args[i - 1].equalsIgnoreCase(UNINSTALL)) {
uninstall = true;
uninstallCookie = arg;
found = true;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i - 1;
configArgs[configArgIndex++] = i;
/**
* Returns the update loader for the given boot path.
*
* @return the update loader
* @param base the boot path base
* @exception Exception thrown is a problem occurs determining this loader
*/
public Class getUpdateLoader(String base) throws Exception {
try (URLClassLoader loader = new URLClassLoader(getBootPath(base), null)) {
return loader.loadClass(UPDATELOADER);
}
}
// remove all the arguments consumed by this argument parsing
if (configArgIndex == 0)
return args;
String[] passThruArgs = new String[args.length - configArgIndex];
configArgIndex = 0;
int j = 0;
for (int i = 0; i < args.length; i++) {
if (i == configArgs[configArgIndex])
configArgIndex++;
/**
* Runs the platform with the given arguments. The arguments must identify
* an application to run (e.g., <code>-application com.example.application</code>).
* After running the application <code>System.exit(N)</code> is executed.
* The value of N is derived from the value returned from running the application.
* If the application's return value is an <code>Integer</code>, N is this value.
* In all other cases, N = 0.
* <p>
* Clients wishing to run the platform without a following <code>System.exit</code>
* call should use <code>run()</code>.
*
* @see #run
*
* @param args the command line arguments
*/
public static void main(String[] args) {
Object result = null;
try {
result = new Main().run(args);
} catch (Throwable e) {
// try and take down the splash screen.
endSplash();
System.out.println("Exception launching the Eclipse Platform:");
e.printStackTrace();
}
int exitCode = result instanceof Integer ? ((Integer) result).intValue() : 0;
System.exit(exitCode);
}
/**
* Tears down the currently-displayed splash screen.
*/
public static void endSplash() {
if (endSplash == null)
return;
try {
Runtime.getRuntime().exec(endSplash);
} catch (Exception e) {
}
}
/**
* Runs this launcher with the arguments specified in the given string.
*
* @param argString the arguments string
* @exception Exception thrown if a problem occurs during launching
*/
public static void main(String argString) throws Exception {
List<String> list = new ArrayList<String>(5);
for (StringTokenizer tokens = new StringTokenizer(argString, " "); tokens.hasMoreElements();)
list.add((String) tokens.nextElement());
main(list.toArray(new String[list.size()]));
}
/**
* Processes the command line arguments
*
* @return the arguments to pass through to the launched application
* @param args the command line arguments
*/
protected String[] processCommandLine(String[] args) throws Exception {
int[] configArgs = new int[100];
configArgs[0] = -1; // need to initialize the first element to something that could not be an index.
int configArgIndex = 0;
for (int i = 0; i < args.length; i++) {
boolean found = false;
// check for args without parameters (i.e., a flag arg)
// check if debug should be enabled for the entire platform
if (args[i].equalsIgnoreCase(DEBUG)) {
debug = true;
// passed thru this arg (i.e., do not set found = true
continue;
}
// check if development mode should be enabled for the entire platform
// If this is the last arg or there is a following arg (i.e., arg+1 has a leading -),
// simply enable development mode. Otherwise, assume that that the following arg is
// actually some additional development time class path entries. This will be processed below.
if (args[i].equalsIgnoreCase(DEV) && ((i + 1 == args.length) || ((i + 1 < args.length) && (args[i + 1].startsWith("-"))))) {
inDevelopmentMode = true;
// do not mark the arg as found so it will be passed through
continue;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i;
continue;
}
// check for args with parameters. If we are at the last argument or if the next one
// has a '-' as the first character, then we can't have an arg with a parm so continue.
if (i == args.length - 1 || args[i + 1].startsWith("-"))
continue;
String arg = args[++i];
// look for the laucher to run
if (args[i - 1].equalsIgnoreCase(BOOT)) {
bootLocation = arg;
found = true;
}
// look for the development mode and class path entries.
if (args[i - 1].equalsIgnoreCase(DEV)) {
inDevelopmentMode = true;
devClassPath = arg;
continue;
}
// look for the application to run
if (args[i - 1].equalsIgnoreCase(APPLICATION)) {
application = arg;
found = true;
}
// look for token to use to end the splash screen
if (args[i - 1].equalsIgnoreCase(ENDSPLASH)) {
endSplash = arg;
continue;
}
// look for items to uninstall
if (args[i - 1].equalsIgnoreCase(UNINSTALL)) {
uninstall = true;
uninstallCookie = arg;
found = true;
}
// done checking for args. Remember where an arg was found
if (found) {
configArgs[configArgIndex++] = i - 1;
configArgs[configArgIndex++] = i;
}
}
// remove all the arguments consumed by this argument parsing
if (configArgIndex == 0)
return args;
String[] passThruArgs = new String[args.length - configArgIndex];
configArgIndex = 0;
int j = 0;
for (int i = 0; i < args.length; i++) {
if (i == configArgs[configArgIndex])
configArgIndex++;
else
passThruArgs[j++] = args[i];
}
return passThruArgs;
}
/**
* Runs the application to be launched.
*
* @return the return value from the launched application
* @param args the arguments to pass to the application
* @exception thrown if a problem occurs during launching
*/
public Object run(String[] args) throws Exception {
String[] passThruArgs = processCommandLine(args);
if (uninstall)
return updateRun(UNINSTALL, uninstallCookie, passThruArgs);
else
passThruArgs[j++] = args[i];
return basicRun(passThruArgs);
}
return passThruArgs;
}
/**
* Runs the application to be launched.
*
* @return the return value from the launched application
* @param args the arguments to pass to the application
* @exception thrown if a problem occurs during launching
*/
public Object run(String[] args) throws Exception {
String[] passThruArgs = processCommandLine(args);
if (uninstall)
return updateRun(UNINSTALL, uninstallCookie, passThruArgs);
else
return basicRun(passThruArgs);
}
/**
* Performs an update run.
*
* @return the return value from the update loader
* @param flag flag to give to the update loader
* @param value value to give to the update loader
* @param args arguments to give to the update loader.
* @exception Exception thrown if a problem occurs during execution
*/
protected Object updateRun(String flag, String value, String[] args) throws Exception {
Class clazz = getUpdateLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, String.class, String.class, String[].class });
try {
return method.invoke(clazz, new Object[] { flag, value, location, args });
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Error)
throw (Error) e.getTargetException();
else
throw e;
/**
* Performs an update run.
*
* @return the return value from the update loader
* @param flag flag to give to the update loader
* @param value value to give to the update loader
* @param args arguments to give to the update loader.
* @exception Exception thrown if a problem occurs during execution
*/
protected Object updateRun(String flag, String value, String[] args) throws Exception {
Class clazz = getUpdateLoader(bootLocation);
Method method = clazz.getDeclaredMethod("run", new Class[] { String.class, String.class, String.class, String[].class });
try {
return method.invoke(clazz, new Object[] { flag, value, location, args });
} catch (InvocationTargetException e) {
if (e.getTargetException() instanceof Error)
throw (Error) e.getTargetException();
else
throw e;
}
}
}
}

View file

@ -24,7 +24,7 @@ public class TestScannerProvider extends AbstractCExtension implements IScannerI
public static String[] sIncludes;
public static String[] sIncludeFiles;
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 static void clear() {

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.settings.model;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - Initial API and implementation
* Intel Corporation - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.core.settings.model;
@ -15,7 +15,6 @@ import org.eclipse.core.runtime.IPath;
/**
* Helper interface capturing 'path' characteristic for {@link ICSettingEntry}
* and {@link ICLanguageSettingEntry} interfaces.
*
*/
public interface ICPathEntry extends ICSettingEntry {
IPath getFullPath();
@ -23,5 +22,4 @@ public interface ICPathEntry extends ICSettingEntry {
IPath getLocation();
boolean isValueWorkspacePath();
}

View file

@ -33,8 +33,7 @@ public interface IPDOMIndexer {
public ICProject getProject();
/**
* Return the unique ID of type of this indexer
* @return the unique ID of type of this indexer
* Returns the unique ID of type of this indexer
*/
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.
*/
public interface IASTComment extends IASTNode {
/**
* @since 5.4
*/
/** @since 5.4 */
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);
/**
* Return a char array representation of the comment.
*
* @return char array representation of the comment
* Returns a char array representation of the comment.
*/
public char[] getComment();
/**
* Return true if this is a blockcomment.
*
* @return true if this is a blockcomment
* Returns true if this is a block comment.
*/
public boolean isBlockComment();
}

View file

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

View file

@ -104,7 +104,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindings(patterns, isFullyQualified, filter, monitor);
} else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) {
@ -134,7 +134,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findMacroContainers(pattern, filter, monitor);
} else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) {
@ -160,14 +160,14 @@ public class CIndex implements IIndex {
@Override
public IIndexName[] findNames(IBinding binding, int flags) throws CoreException {
ArrayList<IIndexFragmentName> result= new ArrayList<IIndexFragmentName>();
ArrayList<IIndexFragmentName> result= new ArrayList<>();
if (binding instanceof ICPPUsingDeclaration) {
IBinding[] bindings= ((ICPPUsingDeclaration) binding).getDelegates();
if (bindings == null || bindings.length == 0) {
return new IIndexName[0];
return IIndexName.EMPTY_ARRAY;
}
if (bindings.length > 1) {
ArrayList<IIndexName> multi= new ArrayList<IIndexName>();
ArrayList<IIndexName> multi= new ArrayList<>();
for (IBinding b : bindings) {
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
// a writable fragment. Therefore names from a read-only fragment are
// 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) {
if (fragment instanceof IWritableIndexFragment) {
final IIndexFragmentName[] names = fragment.findNames(binding, flags);
@ -250,8 +250,8 @@ public class CIndex implements IIndex {
if (location == null) {
return IIndexFile.EMPTY_FILE_ARRAY;
}
Set<ISignificantMacros> handled = new HashSet<ISignificantMacros>();
ArrayList<IIndexFragmentFile> result= new ArrayList<IIndexFragmentFile>();
Set<ISignificantMacros> handled = new HashSet<>();
ArrayList<IIndexFragmentFile> result= new ArrayList<>();
for (IIndexFragment fragment : fFragments) {
IIndexFragmentFile[] candidates= fragment.getFiles(linkageID, location);
for (IIndexFragmentFile candidate : candidates) {
@ -274,8 +274,8 @@ public class CIndex implements IIndex {
if (location == null) {
return IIndexFile.EMPTY_FILE_ARRAY;
}
Set<FileContentKey> keys = new HashSet<FileContentKey>();
ArrayList<IIndexFragmentFile> result= new ArrayList<IIndexFragmentFile>();
Set<FileContentKey> keys = new HashSet<>();
ArrayList<IIndexFragmentFile> result= new ArrayList<>();
for (IIndexFragment fragment : fFragments) {
IIndexFragmentFile[] candidates= fragment.getFiles(location);
for (IIndexFragmentFile candidate : candidates) {
@ -313,7 +313,7 @@ public class CIndex implements IIndex {
@Override
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,
new HashSet<FileContentKey>());
return result.toArray(new IIndexInclude[result.size()]);
@ -354,8 +354,8 @@ public class CIndex implements IIndex {
@Override
public IIndexInclude[] findIncludes(IIndexFile file, int depth) throws CoreException {
List<IIndexInclude> result= new ArrayList<IIndexInclude>();
findIncludes(Collections.singletonList(file), result, depth, new HashSet<Object>());
List<IIndexInclude> result= new ArrayList<>();
findIncludes(Collections.singletonList(file), result, depth, new HashSet<>());
return result.toArray(new IIndexInclude[result.size()]);
}
@ -454,7 +454,7 @@ public class CIndex implements IIndex {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length * linkages.length);
for (ILinkage linkage : linkages) {
@ -529,7 +529,7 @@ public class CIndex implements IIndex {
}
public IIndexFragmentBinding[] findEquivalentBindings(IBinding binding) throws CoreException {
List<IIndexFragmentBinding> result = new ArrayList<IIndexFragmentBinding>();
List<IIndexFragmentBinding> result = new ArrayList<>();
for (IIndexFragment fragment : fFragments) {
IIndexFragmentBinding adapted = fragment.adaptBinding(binding);
if (adapted != null) {
@ -583,7 +583,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindingsForPrefix(prefix, filescope, filter, monitor);
} else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) {
@ -613,7 +613,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindingsForContentAssist(prefix, filescope, filter, monitor);
} else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) {
@ -643,7 +643,7 @@ public class CIndex implements IIndex {
if (SPECIALCASE_SINGLES && fFragments.length == 1) {
return fFragments[0].findBindings(name, filescope, filter, monitor);
} else {
List<IIndexBinding[]> result = new ArrayList<IIndexBinding[]>();
List<IIndexBinding[]> result = new ArrayList<>();
ILinkage[] linkages = Linkage.getIndexerLinkages();
for (ILinkage linkage : linkages) {
if (filter.acceptLinkage(linkage)) {
@ -685,11 +685,11 @@ public class CIndex implements IIndex {
if (monitor == null) {
monitor= new NullProgressMonitor();
}
List<IIndexMacro> result = new ArrayList<IIndexMacro>();
HashSet<IIndexFileLocation> handledIFLs= new HashSet<IIndexFileLocation>();
List<IIndexMacro> result = new ArrayList<>();
HashSet<IIndexFileLocation> handledIFLs= new HashSet<>();
monitor.beginTask(Messages.CIndex_FindBindingsTask_label, fFragments.length);
for (IIndexFragment fragment : fFragments) {
HashSet<IIndexFile> allowedFiles= new HashSet<IIndexFile>();
HashSet<IIndexFile> allowedFiles= new HashSet<>();
try {
IIndexMacro[] macros= fragment.findMacros(name, isPrefix, caseSensitive, filter,
new SubProgressMonitor(monitor, 1));
@ -747,7 +747,7 @@ public class CIndex implements IIndex {
@Override
public IIndexFile[] getAllFiles() throws CoreException {
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<IIndexFileLocation, IIndexFile>();
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<>();
for (IIndexFragment fragment : fFragments) {
for (IIndexFragmentFile file : fragment.getAllFiles()) {
if (file.hasContent()) {
@ -760,7 +760,7 @@ public class CIndex implements IIndex {
@Override
public IIndexFile[] getDefectiveFiles() throws CoreException {
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<IIndexFileLocation, IIndexFile>();
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<>();
for (IIndexFragment fragment : fFragments) {
for (IIndexFragmentFile file : fragment.getDefectiveFiles()) {
if (file.hasContent()) {
@ -773,7 +773,7 @@ public class CIndex implements IIndex {
@Override
public IIndexFile[] getFilesWithUnresolvedIncludes() throws CoreException {
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<IIndexFileLocation, IIndexFile>();
HashMap<IIndexFileLocation, IIndexFile> result= new HashMap<>();
for (IIndexFragment fragment : fFragments) {
for (IIndexFragmentFile file : fragment.getFilesWithUnresolvedIncludes()) {
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.
* @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;
/**
* 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;
/**
* Sets the flag that determines whether the file is a header with #pragma once statement
* or an include guard, or it is a source file and parsed only once because of that.
* Sets the flag that determines whether the file is a header with {@code #pragma once}
* statement or an include guard, or it is a source file and parsed only once because of that.
*/
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.
*/
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);
resultCacheCleared = true; // The cache was cleared while writing to the index.
}
} catch (CoreException e) {
th= e;
} catch (RuntimeException e) {
final Throwable cause = e.getCause();
if (cause instanceof DependsOnOutdatedFileException)
return (DependsOnOutdatedFileException) cause;
th= e;
} catch (StackOverflowError e) {
th= e;
} catch (AssertionError e) {
} catch (StackOverflowError | CoreException | AssertionError e) {
th= e;
} catch (OutOfMemoryError e) {
if (--fSwallowOutOfMemoryError < 0)
@ -1247,16 +1243,10 @@ public abstract class AbstractIndexerTask extends PDOMWriter {
if (storageLinkageID != ILinkage.NO_LINKAGE_ID)
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.
withdrawRequests(linkageID, fileKeys);
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:
* Sergey Prigogin (Google) - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom;
import org.eclipse.cdt.core.dom.ast.IASTComment;

View file

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

View file

@ -40,7 +40,7 @@ public class ShortString implements IString {
final int n = chars.length;
this.db = db;
this.record = db.malloc(CHARS + (useBytes ? n : 2*n));
this.record = db.malloc(CHARS + (useBytes ? n : 2 * n));
Chunk chunk = db.getChunk(record);
chunk.putInt(record + LENGTH, useBytes ? -n : n);
long p = record + CHARS;
@ -134,7 +134,7 @@ public class ShortString implements IString {
chars = getChars();
final int len = chars.length;
for (int i = 0; i < len; i++) {
h = 31*h + chars[i];
h = 31 * h + chars[i];
}
} catch (CoreException e) {
}
@ -145,7 +145,7 @@ public class ShortString implements IString {
public static int compare(final char[] chars, char[] other, boolean caseSensitive) {
final int n = Math.min(chars.length, other.length);
for (int i=0; i<n; i++) {
for (int i = 0; i < n; i++) {
int cmp= compareChars(chars[i], other[i], caseSensitive);
if (cmp != 0)
return cmp;
@ -182,7 +182,7 @@ public class ShortString implements IString {
final int n = Math.min(chars.length, other.length);
int sensitiveCmp= 0;
for (int i=0; i<n; i++) {
for (int i = 0; i < n; i++) {
final char c1= chars[i];
final char c2= other[i];
if (c1 != c2) {
@ -214,7 +214,7 @@ public class ShortString implements IString {
public static int comparePrefix(final char[] chars, char[] other, boolean caseSensitive) {
final int n = Math.min(chars.length, other.length);
for (int i=0; i<n; i++) {
for (int i = 0; i < n; i++) {
int cmp= compareChars(chars[i], other[i], caseSensitive);
if (cmp != 0)
return cmp;

View file

@ -48,14 +48,15 @@ import com.ibm.icu.text.NumberFormat;
* Configures the abstract indexer task suitable for indexing projects.
*/
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 boolean fWriteInfoToLog;
protected PDOMIndexerTask(ITranslationUnit[] forceFiles, ITranslationUnit[] updateFiles,
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;
setShowActivity(checkDebugOption(TRACE_ACTIVITY, 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) {
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(changed));
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) {
String prefSetting = getIndexer().getProperty(key);
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();
@ -249,7 +250,7 @@ public abstract class PDOMIndexerTask extends AbstractIndexerTask implements IPD
// tracing
if (checkDebugOption(IPDOMIndexerTask.TRACE_STATISTICS, TRUE)) {
String ident= " "; //$NON-NLS-1$
String indent= " "; //$NON-NLS-1$
final long totalTime = System.currentTimeMillis() - start;
final IndexerProgress info= getProgressInformation();
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 skipTypeRefs= skipRefs || checkProperty(IndexerPreferences.KEY_SKIP_TYPE_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$
+ "', parseAllFiles=" + indexFilesWithoutConfiguration() //$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$
+ ", skipMacroReferences=" + skipMacroRefs //$NON-NLS-1$
+ "."); //$NON-NLS-1$
System.out.println(ident + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(ident + " Timings: " //$NON-NLS-1$
System.out.println(indent + " Database: " + dbSize + " bytes"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(indent + " Timings: " //$NON-NLS-1$
+ totalTime + " total, " //$NON-NLS-1$
+ fStatistics.fParsingTime + " parser, " //$NON-NLS-1$
+ fStatistics.fResolutionTime + " resolution, " //$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.fUnresolvedIncludesCount + " include, " //$NON-NLS-1$
+ fStatistics.fPreprocessorProblemCount + " scanner, " //$NON-NLS-1$
+ fStatistics.fSyntaxProblemsCount + " syntax errors."); //$NON-NLS-1$
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$
NumberFormat nfPercent= NumberFormat.getPercentInstance();
nfPercent.setMaximumFractionDigits(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.fReferenceCount + " references, " //$NON-NLS-1$
+ 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 tries= misses + hits;
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$
+ hits + " hits, " //$NON-NLS-1$
+ 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 {
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 IndexerProgress fProgress;
@ -78,7 +78,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
createDelegate(cproject, monitor);
}
}
// remove task-tags.
// Remove task-tags.
TodoTaskUpdater.removeTasksFor(project);
} catch (CoreException e) {
CCorePlugin.log(NLS.bind(Messages.PDOMRebuildTask_0, cproject.getElementName() ), e);
@ -112,7 +112,7 @@ public class PDOMRebuildTask implements IPDOMIndexerTask {
boolean allFiles =
TRUE.equals(fIndexer.getProperty(IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_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;
TranslationUnitCollector collector= new TranslationUnitCollector(sources, headers, monitor);
project.accept(collector);

View file

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

View file

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

View file

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

View file

@ -107,7 +107,7 @@ public class HeaderSubstitutor {
IncludeInfo includeInfo = fContext.getIncludeForHeaderFile(path);
if (includeInfo == null)
return path;
List<IncludeInfo> candidates = new ArrayList<IncludeInfo>();
List<IncludeInfo> candidates = new ArrayList<>();
candidates.add(includeInfo);
IncludeMap[] maps = fIncludeMaps;
for (IncludeMap map : maps) {
@ -150,8 +150,8 @@ public class HeaderSubstitutor {
public IPath getPreferredRepresentativeHeaderByHeuristic(InclusionRequest request) {
Set<IIndexFile> indexFiles = request.getDeclaringFiles().keySet();
String symbolName = request.getBinding().getName();
ArrayDeque<IIndexFile> front = new ArrayDeque<IIndexFile>();
HashSet<IIndexFile> processed = new HashSet<IIndexFile>();
ArrayDeque<IIndexFile> front = new ArrayDeque<>();
HashSet<IIndexFile> processed = new HashSet<>();
try {
// 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) {
super(tu);
fIndex = index;
fHeadersToInclude = new HashSet<IPath>();
fHeadersAlreadyIncluded = new HashSet<IPath>();
fHeadersIncludedPreviously = new HashSet<IPath>();
fHeadersToInclude = new HashSet<>();
fHeadersAlreadyIncluded = new HashSet<>();
fHeadersIncludedPreviously = new HashSet<>();
}
public String getSourceContents() {
@ -67,7 +67,7 @@ public class IncludeCreationContext extends InclusionContext {
*/
public void removeExportedHeaders() throws CoreException {
// 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()) {
IPath path = getPath(file);
filesByPath.put(path, file);
@ -79,12 +79,12 @@ public class IncludeCreationContext extends InclusionContext {
private void removeExportedHeaders(Set<IPath> exportingHeaders,
Map<IPath, IIndexFile> filesByPath) throws CoreException {
Set<IPath> exportedHeaders = new HashSet<IPath>();
Set<IPath> exportedHeaders = new HashSet<>();
for (IPath path : exportingHeaders) {
if (!exportedHeaders.contains(path)) {
IIndexFile file = filesByPath.get(path);
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);
while ((file = queue.pollFirst()) != null) {
for (IIndexInclude include : file.getIncludes()) {

View file

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