From 56690dafd4ead43620c147c8356824d5ca182b62 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Sun, 27 Mar 2011 05:15:15 +0000 Subject: [PATCH] Cosmetics. --- .../eclipse/cdt/core/parser/ScannerInfo.java | 39 +++++----- .../eclipse/cdt/core/parser/ParserUtil.java | 72 ++++++++----------- 2 files changed, 46 insertions(+), 65 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerInfo.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerInfo.java index 4d1a7411918..fe4e415a9ec 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerInfo.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/parser/ScannerInfo.java @@ -6,9 +6,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Anton Leherbauer (Wind River Systems) - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Anton Leherbauer (Wind River Systems) + * Markus Schorn (Wind River Systems) *******************************************************************************/ 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. */ -public class ScannerInfo implements IScannerInfo -{ - private Map definedSymbols = Collections.emptyMap(); - private String [] includePaths = {}; +public class ScannerInfo implements IScannerInfo { + private final Map definedSymbols; + private final String[] includePaths; - public ScannerInfo() - { + public ScannerInfo() { + this(null, null); } - public ScannerInfo(Map macroDefinitions, String[] includeSearchPath) - { - if (macroDefinitions != null) { - definedSymbols = macroDefinitions; - } - if (includeSearchPath != null) { - includePaths = includeSearchPath; - } - } - public ScannerInfo(Map macroDefinitions) { this(macroDefinitions, null); } + public ScannerInfo(Map macroDefinitions, String[] includeSearchPath) { + definedSymbols = macroDefinitions != null ? macroDefinitions : Collections.emptyMap(); + includePaths = includeSearchPath != null ? includeSearchPath : new String[] {}; + } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IScannerInfo#getDefinedSymbols() */ - public Map getDefinedSymbols() - { + public Map getDefinedSymbols() { return definedSymbols; } + /* (non-Javadoc) * @see org.eclipse.cdt.core.parser.IScannerInfo#getIncludePaths() */ - public String[] getIncludePaths() - { + public String[] getIncludePaths() { return includePaths; } } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java index 57d7c80f3e3..83b0d90a368 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/parser/ParserUtil.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * IBM Rational Software - Initial API and implementation - * Markus Schorn (Wind River Systems) + * IBM Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ 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. * @noinstantiate This class is not intended to be instantiated by clients. */ -public class ParserUtil -{ - - public static IParserLogService getParserLogService() - { +public class ParserUtil { + private static IParserLogService parserLogService = new ParserLogService(DebugLogConstants.PARSER); + private static IParserLogService scannerLogService = new ParserLogService(DebugLogConstants.SCANNER); + + public static IParserLogService getParserLogService() { return parserLogService; } - private static IParserLogService parserLogService = new ParserLogService(DebugLogConstants.PARSER ); - private static IParserLogService scannerLogService = new ParserLogService(DebugLogConstants.SCANNER ); - public static IParserLogService getScannerLogService() { return scannerLogService; } - public static char [] findWorkingCopyBuffer( String path, Iterator workingCopies ) - { + public static char[] findWorkingCopyBuffer(String path, Iterator workingCopies) { IResource resultingResource = getResourceForFilename(path); - if( resultingResource != null && resultingResource.getType() == IResource.FILE ) - { - // this is the file for sure - // check the working copy - if( workingCopies.hasNext() ) - return findWorkingCopy( resultingResource, workingCopies ); + if (resultingResource != null && resultingResource.getType() == IResource.FILE) { + // This is the file for sure. Check the working copy. + if (workingCopies.hasNext()) + return findWorkingCopy(resultingResource, workingCopies); } return null; } @@ -85,26 +79,24 @@ public class ParserUtil return null; } - public static IResource getResourceForFilename(String finalPath) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); - if( workspace == null ) + if (workspace == null) return null; - IPath path = new Path( finalPath ); - IPath initialPath = new Path( finalPath ); + IPath path = new Path(finalPath); + IPath initialPath = new Path(finalPath); IWorkspaceRoot root = workspace.getRoot(); - if( root.getLocation().isPrefixOf( path ) ) - path = path.removeFirstSegments(root.getLocation().segmentCount() ); + if (root.getLocation().isPrefixOf(path)) + path = path.removeFirstSegments(root.getLocation().segmentCount()); - try - { + try { IFile file = root.getFile(path); - if( file != null && file.exists() ) + if (file != null && file.exists()) return file; - file = root.getFileForLocation( path ); - if( file != null && file.exists() ) + file = root.getFileForLocation(path); + if (file != null && file.exists()) return file; // check for linked resources @@ -113,28 +105,24 @@ public class ParserUtil return file; return null; - } - catch( IllegalArgumentException iae ) //thrown on invalid paths - { + } catch (IllegalArgumentException e) { // thrown on invalid paths return null; } } protected static char[] findWorkingCopy(IResource resultingResource, Iterator workingCopies) { - if( parserLogService.isTracing() ) - parserLogService.traceLog( "Attempting to find the working copy for " + resultingResource.getName() ); //$NON-NLS-1$ - while( workingCopies.hasNext() ) - { + if (parserLogService.isTracing()) + parserLogService.traceLog("Attempting to find the working copy for " + resultingResource.getName()); //$NON-NLS-1$ + while (workingCopies.hasNext()) { IWorkingCopy copy = workingCopies.next(); - if (resultingResource.equals(copy.getResource())) - { - if( parserLogService.isTracing() ) - parserLogService.traceLog( "Working copy found!!" ); //$NON-NLS-1$ + if (resultingResource.equals(copy.getResource())) { + if (parserLogService.isTracing()) + parserLogService.traceLog("Working copy found!!"); //$NON-NLS-1$ return copy.getContents(); } } - if( parserLogService.isTracing() ) - parserLogService.traceLog( "Working copy not found." ); //$NON-NLS-1$ + if (parserLogService.isTracing()) + parserLogService.traceLog("Working copy not found."); //$NON-NLS-1$ return null; }