From 706f8fe3ef1f15e23db63333d56b833ea4175d9d Mon Sep 17 00:00:00 2001 From: Oleg Krasilnikov Date: Wed, 20 Feb 2008 15:31:27 +0000 Subject: [PATCH] Warnings elimination. --- .../internal/ui/help/CFunctionSummary.java | 15 +++- .../cdt/internal/ui/help/CHelpBook.java | 42 ++++++---- .../cdt/internal/ui/help/CHelpEntry.java | 18 +++- .../cdt/internal/ui/help/CHelpProvider.java | 84 ++++++++++++------- .../cdt/internal/ui/help/CHelpTopic.java | 10 +++ 5 files changed, 117 insertions(+), 52 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CFunctionSummary.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CFunctionSummary.java index 0ef08cea3f0..6a995749ae6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CFunctionSummary.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CFunctionSummary.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 Intel Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.ui.help; import java.util.ArrayList; @@ -32,7 +42,7 @@ public class CFunctionSummary implements IFunctionSummary { String args = null; String type = null; NodeList list = e.getChildNodes(); - ArrayList incList = new ArrayList(); + ArrayList incList = new ArrayList(); for(int j = 0; j < list.getLength(); j++){ Node node = list.item(j); if(node.getNodeType() != Node.ELEMENT_NODE) @@ -58,8 +68,7 @@ public class CFunctionSummary implements IFunctionSummary { } } if (incList.size() > 0) - incs = (IRequiredInclude[])incList.toArray( - new IRequiredInclude[incList.size()]); + incs = incList.toArray(new IRequiredInclude[incList.size()]); fps = new FunctionPrototypeSummary(type + SP + name + LB + args + RB); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpBook.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpBook.java index b7c22218fa8..922c62d0d54 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpBook.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpBook.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 Intel Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.ui.help; import java.util.ArrayList; @@ -27,10 +37,10 @@ public class CHelpBook implements ICHelpBook { private int type; private String title; - private TreeMap entries; + private TreeMap entries; public CHelpBook(Element e) { - entries = new TreeMap(); + entries = new TreeMap(); if (e.hasAttribute(ATTR_TITLE)) title = e.getAttribute(ATTR_TITLE).trim(); @@ -59,7 +69,7 @@ public class CHelpBook implements ICHelpBook { if(NODE_ENTRY.equals(node.getNodeName())) { CHelpEntry he = new CHelpEntry((Element)node); if (he.isValid()) - add(he.getKeyword(), he); + entries.put(he.getKeyword(), he); } } } @@ -72,16 +82,12 @@ public class CHelpBook implements ICHelpBook { return title; } - private void add(String keyword, Object entry) { - entries.put(keyword, entry); - } - public IFunctionSummary getFunctionInfo( ICHelpInvocationContext context, String name) { if (entries.containsKey(name)) { - CHelpEntry he = (CHelpEntry)entries.get(name); + CHelpEntry he = entries.get(name); IFunctionSummary[] fs = he.getFunctionSummary(); if (fs != null && fs.length > 0) return fs[0]; @@ -95,11 +101,11 @@ public class CHelpBook implements ICHelpBook { * @param prefix * @return matching functions */ - public List getMatchingFunctions( + public List getMatchingFunctions( ICHelpInvocationContext context, String prefix) { - Collection col = null; + Collection col = null; if (prefix == null || prefix.trim().length() == 0) { // return whole data col = entries.values(); @@ -115,22 +121,26 @@ public class CHelpBook implements ICHelpBook { } else i--; } - SortedMap sm = (i>-1) ? + SortedMap sm = (i>-1) ? entries.subMap(pr1, new String(bs)) : entries.tailMap(pr1); col = sm.values(); } - - if (col.size() > 0) - return new ArrayList(col); - else + + if (col.size() > 0) { + ArrayList out = new ArrayList(col.size()); + for (CHelpEntry he: col) + for (IFunctionSummary fs : he.getFunctionSummary()) + out.add(fs); + return out; + } else return null; } public ICHelpResourceDescriptor getHelpResources( ICHelpInvocationContext context, String name) { if (entries.containsKey(name)) { - CHelpEntry he = (CHelpEntry)entries.get(name); + CHelpEntry he = entries.get(name); IHelpResource[] hr = he.getHelpResource(); if (hr != null && hr.length > 0) return new HRDescriptor(this, hr); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpEntry.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpEntry.java index bd0df39e2ac..2d3700d347b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpEntry.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpEntry.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 Intel Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.ui.help; import java.util.ArrayList; @@ -21,8 +31,8 @@ public class CHelpEntry { public CHelpEntry(Element e) { keyword = e.getAttribute(ATTR_KEYWD).trim(); - ArrayList obs1 = new ArrayList(); - ArrayList obs2 = new ArrayList(); + ArrayList obs1 = new ArrayList(); + ArrayList obs2 = new ArrayList(); NodeList list = e.getChildNodes(); for(int i = 0; i < list.getLength(); i++){ Node node = list.item(i); @@ -34,8 +44,8 @@ public class CHelpEntry { obs2.add(new CHelpTopic((Element)node, keyword)); } } - fss = (CFunctionSummary[])obs1.toArray(new CFunctionSummary[obs1.size()]); - hts = (CHelpTopic[])obs2.toArray(new CHelpTopic[obs2.size()]); + fss = obs1.toArray(new CFunctionSummary[obs1.size()]); + hts = obs2.toArray(new CHelpTopic[obs2.size()]); if (fss.length == 0 && hts.length == 0) isValid = false; // nothing to display diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpProvider.java index 7971c51aba7..0e969528d3f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpProvider.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 Intel Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.ui.help; import java.io.BufferedReader; @@ -39,10 +49,13 @@ public class CHelpProvider implements ICHelpProvider { private static final String ATTRIB_FILE = "file"; //$NON-NLS-1$ private static final String NODE_HEAD = "documentation"; //$NON-NLS-1$ private static final String NODE_BOOK = "helpBook"; //$NON-NLS-1$ + + private boolean Done = false; ICHelpBook[] hbs = null; public ICHelpBook[] getCHelpBooks() { + waitForDone(); return hbs; } @@ -63,18 +76,17 @@ public class CHelpProvider implements ICHelpProvider { public ICHelpResourceDescriptor[] getHelpResources( ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) { - ArrayList lst = new ArrayList(); - for (int i=0; i lst = new ArrayList(); + for (ICHelpBook h : helpBooks) { + if (h instanceof CHelpBook) { ICHelpResourceDescriptor hrd = - ((CHelpBook)helpBooks[i]).getHelpResources(context, name); + ((CHelpBook)h).getHelpResources(context, name); if (hrd != null) lst.add(hrd); } } if (lst.size() > 0) - return (ICHelpResourceDescriptor[])lst.toArray( - new ICHelpResourceDescriptor[lst.size()]); + return lst.toArray(new ICHelpResourceDescriptor[lst.size()]); else return null; } @@ -82,50 +94,64 @@ public class CHelpProvider implements ICHelpProvider { public IFunctionSummary[] getMatchingFunctions( ICHelpInvocationContext context, ICHelpBook[] helpBooks, String prefix) { - ArrayList lst = new ArrayList(); + ArrayList lst = new ArrayList(); for (int i=0; i fs = ((CHelpBook)helpBooks[i]).getMatchingFunctions(context, prefix); if (fs != null) // if null, try with another book lst.addAll(fs); } } if (lst.size() > 0) - return (IFunctionSummary[])lst.toArray(new IFunctionSummary[lst.size()]); + return lst.toArray(new IFunctionSummary[lst.size()]); else return null; } public void initialize() { - loadExtensions(); - System.out.println(); +// (new Thread() { +// public void run() { + loadExtensions(); +// } +// }).run(); } + private void waitForDone() { + if (hbs != null) + return; + try { + while (! Done ) Thread.sleep(10); + } catch (InterruptedException e) {} + } + private void loadExtensions() { - IExtensionPoint extensionPoint = Platform.getExtensionRegistry() - .getExtensionPoint(EXTENSION_POINT_ID); - if (extensionPoint == null) return; - IExtension[] extensions = extensionPoint.getExtensions(); - if (extensions == null) return; - - ArrayList chbl = new ArrayList(); - - for (int i = 0; i < extensions.length; ++i) { - String pluginId = extensions[i].getNamespaceIdentifier(); - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); - for (int k = 0; k < elements.length; k++) { - if (elements[k].getName().equals(ELEMENT_NAME)) { - loadFile(elements[k], chbl, pluginId); + try { + IExtensionPoint extensionPoint = Platform.getExtensionRegistry() + .getExtensionPoint(EXTENSION_POINT_ID); + if (extensionPoint != null) { + IExtension[] extensions = extensionPoint.getExtensions(); + if (extensions != null) { + ArrayList chbl = new ArrayList(); + for (IExtension ex: extensions) { + String pluginId = ex.getNamespaceIdentifier(); + for (IConfigurationElement el : ex.getConfigurationElements()) { + if (el.getName().equals(ELEMENT_NAME)) { + loadFile(el, chbl, pluginId); + } + } + } + if (chbl.size() > 0) { + hbs = chbl.toArray(new ICHelpBook[chbl.size()]); + } } } - } - if (chbl.size() > 0) { - hbs = (ICHelpBook[])chbl.toArray(new ICHelpBook[chbl.size()]); + } finally { + Done = true; } } - private void loadFile(IConfigurationElement el, ArrayList chbl, String pluginId) { + private void loadFile(IConfigurationElement el, ArrayList chbl, String pluginId) { String fname = el.getAttribute(ATTRIB_FILE); if (fname == null || fname.trim().length() == 0) return; URL x = FileLocator.find(Platform.getBundle(pluginId), new Path(fname), null); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpTopic.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpTopic.java index 30e5da73a93..8787c006e47 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpTopic.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/help/CHelpTopic.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 Intel Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Intel Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.internal.ui.help; import org.eclipse.help.IHelpResource;