From 004a2f86d807ed9675f70cffc4b247841e3cda69 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Fri, 29 Jul 2011 13:42:10 -0700 Subject: [PATCH] Cosmetics. --- .../cdt/core/model/LanguageManager.java | 58 +++++++++---------- .../core/index/provider/PDOMCache.java | 15 +++-- .../cdt/internal/ui/viewsupport/IndexUI.java | 21 ++++--- 3 files changed, 44 insertions(+), 50 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java index 603a57a21e9..c6acb69f186 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java @@ -8,10 +8,8 @@ * Contributors: * Doug Schaefer (QNX) - Initial API and implementation * Markus Schorn (Wind River Systems) - * IBM Corporation - * - Language managment feature (see Bugzilla 151850) + * IBM Corporation - Language management feature (see Bugzilla 151850) *******************************************************************************/ - package org.eclipse.cdt.core.model; import java.util.ArrayList; @@ -84,19 +82,19 @@ public class LanguageManager { return map.get(id); } - private HashMap getDescriptorCache(){ - if(fIdToLanguageDescriptorCache == null){ + private HashMap getDescriptorCache() { + if (fIdToLanguageDescriptorCache == null) { fIdToLanguageDescriptorCache = createDescriptorCache(); } return fIdToLanguageDescriptorCache; } - public ILanguageDescriptor[] getLanguageDescriptors(){ + public ILanguageDescriptor[] getLanguageDescriptors() { HashMap map = getDescriptorCache(); return map.values().toArray(new ILanguageDescriptor[map.size()]); } - private HashMap createDescriptorCache(){ + private HashMap createDescriptorCache() { HashMap map = new HashMap(); IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID); for (int j = 0; j < configs.length; ++j) { @@ -109,21 +107,21 @@ public class LanguageManager { return map; } - private HashMap> getContentTypeToDescriptorCache(){ - if(fContentTypeToDescriptorListCache == null){ + private HashMap> getContentTypeToDescriptorCache() { + if (fContentTypeToDescriptorListCache == null) { fContentTypeToDescriptorListCache = createContentTypeToDescriptorCache(); } return fContentTypeToDescriptorListCache; } - public Map getContentTypeIdToLanguageDescriptionsMap(){ + public Map getContentTypeIdToLanguageDescriptionsMap() { HashMap map = new HashMap(); Map> cache = getContentTypeToDescriptorCache(); - for(Iterator>> iter = cache.entrySet().iterator(); iter.hasNext();){ + for (Iterator>> iter = cache.entrySet().iterator(); iter.hasNext();) { Entry> entry = iter.next(); List list = entry.getValue(); - if(list.size() > 0){ + if (list.size() > 0) { ILanguageDescriptor[] dess = list.toArray(new ILanguageDescriptor[list.size()]); map.put(entry.getKey(), dess); } @@ -133,21 +131,21 @@ public class LanguageManager { } - private HashMap> createContentTypeToDescriptorCache(){ + private HashMap> createContentTypeToDescriptorCache() { HashMap> map = new HashMap>(); Map dc = getDescriptorCache(); List list; IContentType type; String id; - for(Iterator iter = dc.values().iterator(); iter.hasNext();){ + for (Iterator iter = dc.values().iterator(); iter.hasNext();) { ILanguageDescriptor des = iter.next(); IContentType types[] = des.getContentTypes(); - for(int i = 0; i < types.length; i++){ + for (int i = 0; i < types.length; i++) { type = types[i]; id = type.getId(); list = map.get(id); - if(list == null){ + if (list == null) { list = new ArrayList(); map.put(id, list); } @@ -169,7 +167,7 @@ public class LanguageManager { String langId = getLanguageID(languageElem); if (langId.equals(id)) { final ILanguage[] result= new ILanguage[]{null}; - SafeRunner.run(new ISafeRunnable(){ + SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { CCorePlugin.log(exception); } @@ -227,8 +225,8 @@ public class LanguageManager { * @deprecated use getRegisteredContentTypes() instead. */ @Deprecated - public ArrayList/**/ getAllContentTypes() { - ArrayList/**/ allTypes = new ArrayList(); + public ArrayList getAllContentTypes() { + ArrayList allTypes = new ArrayList(); allTypes.add(CCorePlugin.CONTENT_TYPE_ASMSOURCE); allTypes.add(CCorePlugin.CONTENT_TYPE_CHEADER); allTypes.add(CCorePlugin.CONTENT_TYPE_CSOURCE); @@ -261,7 +259,7 @@ public class LanguageManager { } private Set collectContentTypeIds() { - HashSet/**/ allTypes = new HashSet(); + HashSet allTypes = new HashSet(); allTypes.add(CCorePlugin.CONTENT_TYPE_ASMSOURCE); allTypes.add(CCorePlugin.CONTENT_TYPE_CHEADER); allTypes.add(CCorePlugin.CONTENT_TYPE_CSOURCE); @@ -331,7 +329,7 @@ public class LanguageManager { for (int i = 0; i < configs.length; i++) { final IConfigurationElement element = configs[i]; if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) { - SafeRunner.run(new ISafeRunnable(){ + SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { CCorePlugin.log(exception); } @@ -369,14 +367,14 @@ public class LanguageManager { final IConfigurationElement languageElem = configs[j]; if (ELEMENT_LANGUAGE.equals(languageElem.getName())) { String langId = getLanguageID(languageElem); - final ILanguage[] result= new ILanguage[]{null}; - SafeRunner.run(new ISafeRunnable(){ + final ILanguage[] result= new ILanguage[] { null }; + SafeRunner.run(new ISafeRunnable() { public void handleException(Throwable exception) { CCorePlugin.log(exception); } public void run() throws Exception { - result[0]= (ILanguage)languageElem.createExecutableExtension(ATTRIBUTE_CLASS); + result[0]= (ILanguage) languageElem.createExecutableExtension(ATTRIBUTE_CLASS); } }); if (result[0] != null) { @@ -490,8 +488,7 @@ public class LanguageManager { IContentType contentType = CContentTypes.getContentType(project, fullPathToFile); - if(contentType == null) - { + if (contentType == null) { return null; } @@ -560,8 +557,7 @@ public class LanguageManager { public ILanguage getLanguageForFile(IFile file, ICConfigurationDescription configuration) throws CoreException { return getLanguageForFile(file, configuration, null); } - - + /** * Returns an ILanguage representing the language to be used for the given file. * @return an ILanguage representing the language to be used for the given file @@ -572,12 +568,12 @@ public class LanguageManager { * @throws CoreException * @since 4.0 */ - public ILanguage getLanguageForFile(IFile file, ICConfigurationDescription configuration, String contentTypeId) throws CoreException { + public ILanguage getLanguageForFile(IFile file, ICConfigurationDescription configuration, + String contentTypeId) throws CoreException { IProject project = file.getProject(); if (contentTypeId == null) { - IContentType contentType= - CContentTypes.getContentType(project, file.getLocation().toString()); + IContentType contentType= CContentTypes.getContentType(project, file.getLocation().toString()); if (contentType == null) { return null; } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/PDOMCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/PDOMCache.java index d9552a30e54..29214feaf31 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/PDOMCache.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/index/provider/PDOMCache.java @@ -39,8 +39,8 @@ class PDOMCache { * Returns the instance of the cache */ public static PDOMCache getInstance() { - synchronized(singletonMutex) { - if(singleton == null) { + synchronized (singletonMutex) { + if (singleton == null) { singleton = new PDOMCache(); } return singleton; @@ -55,23 +55,22 @@ class PDOMCache { * @return a PDOM instance or null if the PDOM version was too old */ public PDOM getPDOM(IPath path, IIndexLocationConverter converter) { - - if (path==null){ + if (path == null){ return null; } PDOM result= null; File file = path.toFile(); - synchronized(path2pdom) { - if(path2pdom.containsKey(file)) { + synchronized (path2pdom) { + if (path2pdom.containsKey(file)) { result= path2pdom.get(file); } - if(result==null) { + if (result == null) { try { result= new PDOM(file, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings()); path2pdom.put(file, result); - } catch(CoreException ce) { + } catch (CoreException ce) { CCorePlugin.log(ce); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java index 3b515b96a55..c11a424b741 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/viewsupport/IndexUI.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Markus Schorn - initial API and implementation - * Ed Swartz (Nokia) + * Markus Schorn - initial API and implementation + * Ed Swartz (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.ui.viewsupport; @@ -108,8 +108,7 @@ public class IndexUI { if (name != null) { return index.findBinding(name); } - } - else { + } else { String name= element.getElementName(); name= name.substring(name.lastIndexOf(':')+1); IIndexBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.ALL, new NullProgressMonitor()); @@ -190,9 +189,9 @@ public class IndexUI { for (IIndexFile file : files) { if (linkageID == -1 || file.getLinkageID() == linkageID) { String elementName= element.getElementName(); - int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$ + int idx= elementName.lastIndexOf(":") + 1; //$NON-NLS-1$ ISourceRange pos= sf.getSourceRange(); - IRegion region = getConvertedRegion(tu, file, pos.getIdStartPos()+idx, pos.getIdLength()-idx); + IRegion region = getConvertedRegion(tu, file, pos.getIdStartPos() + idx, pos.getIdLength() - idx); IIndexName[] names= file.findNames(region.getOffset(), region.getLength()); for (IIndexName name2 : names) { IIndexName name = name2; @@ -223,9 +222,11 @@ public class IndexUI { return false; } - private static IRegion getConvertedRegion(ITranslationUnit tu, IIndexFile file, int pos, int length) throws CoreException { + private static IRegion getConvertedRegion(ITranslationUnit tu, IIndexFile file, int pos, + int length) throws CoreException { IRegion region= new Region(pos, length); - IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu, file.getTimestamp()); + IPositionConverter converter= + CCorePlugin.getPositionTrackerManager().findPositionConverter(tu, file.getTimestamp()); if (converter != null) { region= converter.actualToHistoric(region); } @@ -248,7 +249,7 @@ public class IndexUI { int bestDiff= Integer.MAX_VALUE; IIndexInclude best= null; for (IIndexInclude candidate : includes) { - int diff= Math.abs(candidate.getNameOffset()- region.getOffset()); + int diff= Math.abs(candidate.getNameOffset() - region.getOffset()); if (diff > bestDiff) { break; } @@ -288,7 +289,6 @@ public class IndexUI { if (definition != null) { result.add(definition); } - } return result.toArray(new ICElementHandle[result.size()]); } @@ -513,7 +513,6 @@ public class IndexUI { if (result == null) result= new ArrayList(instances.size()); - for (ICPPTemplateInstance inst : instances) { if (!ASTInternal.hasDeclaration(inst)) { result.add(inst);