1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 00:36:16 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-03-27 05:15:15 +00:00
parent 56cae6fd61
commit 56690dafd4
2 changed files with 46 additions and 65 deletions

View file

@ -6,9 +6,9 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
@ -18,41 +18,34 @@ import java.util.Map;
/** /**
* Implementation of the {@link IScannerInfo} interface. Allows to configure the preprocessor. * Implementation of the {@link IScannerInfo} interface. Allows to configure the preprocessor.
*/ */
public class ScannerInfo implements IScannerInfo public class ScannerInfo implements IScannerInfo {
{ private final Map<String, String> definedSymbols;
private Map<String, String> definedSymbols = Collections.emptyMap(); private final String[] includePaths;
private String [] includePaths = {};
public ScannerInfo() public ScannerInfo() {
{ this(null, null);
} }
public ScannerInfo(Map<String, String> macroDefinitions, String[] includeSearchPath)
{
if (macroDefinitions != null) {
definedSymbols = macroDefinitions;
}
if (includeSearchPath != null) {
includePaths = includeSearchPath;
}
}
public ScannerInfo(Map<String, String> macroDefinitions) { public ScannerInfo(Map<String, String> macroDefinitions) {
this(macroDefinitions, null); this(macroDefinitions, null);
} }
public ScannerInfo(Map<String, String> macroDefinitions, String[] includeSearchPath) {
definedSymbols = macroDefinitions != null ? macroDefinitions : Collections.<String, String>emptyMap();
includePaths = includeSearchPath != null ? includeSearchPath : new String[] {};
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols() * @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols()
*/ */
public Map<String, String> getDefinedSymbols() public Map<String, String> getDefinedSymbols() {
{
return definedSymbols; return definedSymbols;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.parser.IScannerInfo#getIncludePaths() * @see org.eclipse.cdt.core.parser.IScannerInfo#getIncludePaths()
*/ */
public String[] getIncludePaths() public String[] getIncludePaths() {
{
return includePaths; return includePaths;
} }
} }

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM Rational Software - Initial API and implementation * IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.parser; package org.eclipse.cdt.core.parser;
@ -33,31 +33,25 @@ import org.eclipse.core.runtime.Path;
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients. * @noinstantiate This class is not intended to be instantiated by clients.
*/ */
public class ParserUtil public class ParserUtil {
{ private static IParserLogService parserLogService = new ParserLogService(DebugLogConstants.PARSER);
private static IParserLogService scannerLogService = new ParserLogService(DebugLogConstants.SCANNER);
public static IParserLogService getParserLogService()
{ public static IParserLogService getParserLogService() {
return parserLogService; return parserLogService;
} }
private static IParserLogService parserLogService = new ParserLogService(DebugLogConstants.PARSER );
private static IParserLogService scannerLogService = new ParserLogService(DebugLogConstants.SCANNER );
public static IParserLogService getScannerLogService() { public static IParserLogService getScannerLogService() {
return scannerLogService; return scannerLogService;
} }
public static char [] findWorkingCopyBuffer( String path, Iterator<IWorkingCopy> workingCopies ) public static char[] findWorkingCopyBuffer(String path, Iterator<IWorkingCopy> workingCopies) {
{
IResource resultingResource = getResourceForFilename(path); IResource resultingResource = getResourceForFilename(path);
if( resultingResource != null && resultingResource.getType() == IResource.FILE ) if (resultingResource != null && resultingResource.getType() == IResource.FILE) {
{ // This is the file for sure. Check the working copy.
// this is the file for sure if (workingCopies.hasNext())
// check the working copy return findWorkingCopy(resultingResource, workingCopies);
if( workingCopies.hasNext() )
return findWorkingCopy( resultingResource, workingCopies );
} }
return null; return null;
} }
@ -85,26 +79,24 @@ public class ParserUtil
return null; return null;
} }
public static IResource getResourceForFilename(String finalPath) { public static IResource getResourceForFilename(String finalPath) {
IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspace workspace = ResourcesPlugin.getWorkspace();
if( workspace == null ) if (workspace == null)
return null; return null;
IPath path = new Path( finalPath ); IPath path = new Path(finalPath);
IPath initialPath = new Path( finalPath ); IPath initialPath = new Path(finalPath);
IWorkspaceRoot root = workspace.getRoot(); IWorkspaceRoot root = workspace.getRoot();
if( root.getLocation().isPrefixOf( path ) ) if (root.getLocation().isPrefixOf(path))
path = path.removeFirstSegments(root.getLocation().segmentCount() ); path = path.removeFirstSegments(root.getLocation().segmentCount());
try try {
{
IFile file = root.getFile(path); IFile file = root.getFile(path);
if( file != null && file.exists() ) if (file != null && file.exists())
return file; return file;
file = root.getFileForLocation( path ); file = root.getFileForLocation(path);
if( file != null && file.exists() ) if (file != null && file.exists())
return file; return file;
// check for linked resources // check for linked resources
@ -113,28 +105,24 @@ public class ParserUtil
return file; return file;
return null; return null;
} } catch (IllegalArgumentException e) { // thrown on invalid paths
catch( IllegalArgumentException iae ) //thrown on invalid paths
{
return null; return null;
} }
} }
protected static char[] findWorkingCopy(IResource resultingResource, Iterator<IWorkingCopy> workingCopies) { protected static char[] findWorkingCopy(IResource resultingResource, Iterator<IWorkingCopy> workingCopies) {
if( parserLogService.isTracing() ) if (parserLogService.isTracing())
parserLogService.traceLog( "Attempting to find the working copy for " + resultingResource.getName() ); //$NON-NLS-1$ parserLogService.traceLog("Attempting to find the working copy for " + resultingResource.getName()); //$NON-NLS-1$
while( workingCopies.hasNext() ) while (workingCopies.hasNext()) {
{
IWorkingCopy copy = workingCopies.next(); IWorkingCopy copy = workingCopies.next();
if (resultingResource.equals(copy.getResource())) if (resultingResource.equals(copy.getResource())) {
{ if (parserLogService.isTracing())
if( parserLogService.isTracing() ) parserLogService.traceLog("Working copy found!!"); //$NON-NLS-1$
parserLogService.traceLog( "Working copy found!!" ); //$NON-NLS-1$
return copy.getContents(); return copy.getContents();
} }
} }
if( parserLogService.isTracing() ) if (parserLogService.isTracing())
parserLogService.traceLog( "Working copy not found." ); //$NON-NLS-1$ parserLogService.traceLog("Working copy not found."); //$NON-NLS-1$
return null; return null;
} }