Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/.classpath7
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/.project28
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/ChangeLog171
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/META-INF/MANIFEST.MF21
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/build.properties9
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/plugin.properties14
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/plugin.xml12
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/schema/org.eclipse.linuxtools.cdt.libhover.library.exsd216
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/ClassInfo.java123
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/FunctionInfo.java134
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/HelpBook.java37
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibHoverInfo.java24
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibhoverPlugin.java79
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/MemberInfo.java133
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/TypedefInfo.java118
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/utils/BuildFunctionInfos.java213
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java641
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverLibrary.java216
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.java41
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.properties16
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/CheckboxFieldEditor.java394
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/LibHoverPreferencePage.java79
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceConstants.java20
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceInitializer.java37
-rw-r--r--libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/properties/LibHoverPropertyPage.java465
26 files changed, 3255 insertions, 0 deletions
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/.classpath b/libhover/org.eclipse.linuxtools.cdt.libhover/.classpath
new file mode 100644
index 0000000000..64c5e31b7a
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/.project b/libhover/org.eclipse.linuxtools.cdt.libhover/.project
new file mode 100644
index 0000000000..5207979d38
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.linuxtools.cdt.libhover</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/.settings/org.eclipse.jdt.core.prefs b/libhover/org.eclipse.linuxtools.cdt.libhover/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000000..bbc86d093a
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Fri Sep 19 14:24:23 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/ChangeLog b/libhover/org.eclipse.linuxtools.cdt.libhover/ChangeLog
new file mode 100644
index 0000000000..db4823d93d
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/ChangeLog
@@ -0,0 +1,171 @@
+2009-12-17 Andrew Overholt <overholt@redhat.com>
+
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java (getMemberSummary):
+ Remove unnecessary catch block.
+
+2009-09-23 Jeff Johnston <jjohnstn@redhat.com>
+
+ * META-INF/MANIFEST.MF: Load plugin if any of its classes are used.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibhoverPlugin.java (LibhoverPlugin): Set
+ plugin in constructor.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java (resolveArgs): Change
+ to resolve template parms to actual types where known.
+ (isParmMatch): Resolve the member prototype using template types so we are comparing
+ apples to apples.
+ (getMemberSummary): Change calls to isParmMatch and resolveArgs.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverLibrary.java (getHoverInfo): Add
+ code to try accessing a path locally within the plugin, then try the file system.
+
+2009-08-06 Jeff Johnston <jjohnstn@redhat.com>
+
+ Resolves #285867
+ * plugin.properties: Change Provider to Eclipse instead of Eclipse.org.
+
+2009-07-30 Jeff Johnston <jjohnstn@redhat.com>
+
+ * META-INF/MANIFEST.MF: Bump release to 1.0.3.
+
+2009-07-30 Jeff Johnston <jjohnstn@redhat.com>
+
+ Refactor to hide internal classes in new packages.
+
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverLibrary.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverMessages.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverMessages.properties: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/CheckboxFieldEditor.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/LibHoverPreferencePage.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/PreferenceConstants.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/PreferenceInitializer.java: Removed.
+ * src/org/eclipse/linuxtools/cdt/libhover/properties/LibHoverPropertyPage.java: Removed.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverLibrary.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.properties: New file.
+ * plugin.xml: Changed to match new packages.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/CheckboxFieldEditor.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/LibHoverPreferencePage.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceConstants.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceInitializer.java: New file.
+ * src/org/eclipse/linuxtools/internal/cdt/libhover/properties/LibHoverPropertyPage.java: New file.
+
+
+2009-05-29 Jeff Johnston <jjohnstn@redhat.com>
+
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java (getMemberSummary): Fix compiler warnings.
+ (getFunctionInfo): Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/CheckboxFieldEditor.java (doLoad): Ditto.
+ (doLoadDefault): Ditto.
+ (adjustForNumColumns): Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/properties/LibHoverPropertyPage.java (updateCheckboxData): Ditto.
+
+2009-05-08 Jeff Johnston <jjohnstn@redhat.com>
+
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java (getFunctionInfo): Add logic
+ to find the qualified name of the class, even when namespaces are being used.
+
+2009-05-08 Jeff Johnston <jjohnstn@redhat.com>
+
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java (resolveArgs): New method.
+ (isParmMatch): Ditto.
+ (getMemberSummary): Add parameter matching support and template resolution.
+ (getFunctionInfo): Add AST logic to resolve member name for C++.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverLibrary.java (resolveTemplateTypes):
+ New method.
+ (getClassInfo): Add additional parameter of template types and fill in.
+ * src/org/eclipse/linuxtools/cdt/libhover/MemberInfo.java (getReturnType): New method.
+ (setParamTypes): Ditto.
+ (getParamTypes): Ditto.
+
+2009-02-06 Jeff Johnston <jjohnstn@redhat.com>
+
+ * schema/org.eclipse.linuxtools.cdt.libhover.library.exsd: Change description for
+ location field which now points to a serialized LibHoverInfo instance rather than
+ xml.
+ * src/org/eclipse/linuxtools/cdt/libhover/ClassInfo.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/FunctionInfo.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/HelpBook.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverInfo.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverLibrary.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/MemberInfo.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/TypedefInfo.java: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/utils/BuildFunctionInfos.java: New file to
+ create serialized LibHoverInfo file from an xml file in standard function format
+ used by previous version of LibHover.
+ * META-INF/MANIFEST.MF: Add additional dependencies and bump version to 1.0.2.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java (isCPPCharacter): New method.
+ (EnclosingASTNameJob): New internal class to query the AST for IASTName
+ for a symbol in the document.
+ (ASTDeclarationFinderJob): New internal class to get the declaration of a symbol from
+ the AST.
+ (getMemberSummary): New method to get the summary of a C++ method.
+ (getLibHoverDocs): Modified to no longer parse xml documentation. It now expects
+ documentation to be in LibHoverInfo format, serialized via Java. The method leaves
+ reading of the actual serialized info to LibHoverLibrary.
+ (getFunctionSummary): Rewritten to fetch info from the new LibHoverInfo class and
+ to handle C++.
+ (getMatchingFunctions): Ditto.
+ (FunctionSummary): Added a boolean to mark whether the prototype already has
+ brackets in it.
+ (FunctionSummary.FunctionPrototypeSummary.getPrototypeString): Use new boolean
+ to determine whether to add brackets or not.
+ (getFunctionInfo): Add C++ support.
+
+2009-01-15 Jeff Johnston <jjohnstn@redhat.com>
+
+ * META-INF/MANIFEST.MF: Add .qualifier to version and bump to 1.0.1.
+
+2008-10-31 Andrew Overholt <overholt@redhat.com>
+
+ * META-INF/MANIFEST.MF: Use bundleName and provider from plugin.properties. Add
+ "(Incubation)".
+ * plugin.properties: Initial import.
+
+2008-10-24 Jeff Johnston <jjohnstn@redhat.com>
+
+ * plugin.xml: Remove libhover property and preferences pages which are not needed since
+ C/C++ Documentation properties page does the job.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java:
+ (getMatchingFunctions): Pass document to getFunctionSummaryFromNode.
+ (constructTypes): Add groupsynopsis.
+ (getFunctionInfo): Pass document to getFunctionSummaryFromNode.
+ (getFunctionSummaryFromNode): Add groupsynopsis support.
+
+2008-10-22 Jeff Johnston <jjohnstn@redhat.com>
+
+ * plugin.properties: New file.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/CheckboxFieldEditor.java: New file.
+ * build.properties: Add plugin.properties to list of binary files.
+ * META-INF/MANIFEST.MF: Add Bundle-Localization statement.
+ * plugin.xml: Use translatable names for preference and property pages.
+ * schema/org.eclipse.linuxtools.cdt.libhover.library.exsd: Make id and name required.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java:
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverMessages.java: Fix bundle name.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverMessages.properties: New messages.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibhoverPlugin.java (getID): New method.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/LibHoverPreferencePage.java (createFieldEditors):
+ Rewrite to use new CheckboxFieldEditor.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/PreferenceConstants.java: Add P_LIBHOVER.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/PreferenceInitializer.java (initializeDefaultPreferences):
+ Set up an unused default string.
+ * src/org/eclipse/linuxtools/cdt/libhover/properties/LibHoverPropertyPage.java: Rewritten to use the
+ CheckboxFieldEditor widgets on a property page.
+
+2008-10-15 Jeff Johnston <jjohnstn@redhat.com>
+
+ * build.properties: Specify javacSource and javacTarget to be 1.5.
+
+2008-09-19 Jeff Johnston <jjohnstn@redhat.com>
+
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHover.java: Initial implementation moved
+ org.eclipse.cdt.linuxtools.autotools.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverMessages.java: Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverMessages.properties: Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/LibHoverPlugin.java: New file.
+ * META-INF/MANIFEST.MF: Ditto.
+ * schema/org.eclipse.linuxtools.cdt.libhover.library.exsd: Ditto.
+ * about.html, build.properties, plugin.xml, plugin.properties: Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/LibHoverPreferencesPage.java: Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/PreferenceConstants.java: Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/preferences/PreferenceInitializer.java: Ditto.
+ * src/org/eclipse/linuxtools/cdt/libhover/properties/LibHoverPropertyPage.java: Ditto.
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/META-INF/MANIFEST.MF b/libhover/org.eclipse.linuxtools.cdt.libhover/META-INF/MANIFEST.MF
new file mode 100644
index 0000000000..fc024ea3be
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %bundleName
+Bundle-SymbolicName: org.eclipse.linuxtools.cdt.libhover; singleton:=true
+Bundle-Version: 1.0.3.qualifier
+Bundle-Activator: org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin
+Bundle-Vendor: %provider
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources,
+ org.eclipse.help;bundle-version="3.3.100",
+ org.eclipse.cdt.ui;bundle-version="5.0.0",
+ org.eclipse.core.filesystem;bundle-version="1.2.0",
+ org.eclipse.cdt.core;bundle-version="5.0.0",
+ org.eclipse.cdt;bundle-version="5.0.0",
+ org.eclipse.ui.editors;bundle-version="3.4.0",
+ org.eclipse.jface.text;bundle-version="3.4.1"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Export-Package: org.eclipse.linuxtools.cdt.libhover
+Bundle-ActivationPolicy: lazy
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/build.properties b/libhover/org.eclipse.linuxtools.cdt.libhover/build.properties
new file mode 100644
index 0000000000..50e2a58ba8
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/build.properties
@@ -0,0 +1,9 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ plugin.properties
+
+javacSource=1.5
+javacTarget=1.5
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/plugin.properties b/libhover/org.eclipse.linuxtools.cdt.libhover/plugin.properties
new file mode 100644
index 0000000000..2f48939173
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/plugin.properties
@@ -0,0 +1,14 @@
+#################################################################################
+# Copyright (c) 2008 Red Hat, Inc.
+# 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:
+# Red Hat Incorporated - initial API and implementation
+#################################################################################
+LibhoverPreference.name=Library Hover
+LibhoverProperty.name=Library Hover
+bundleName=C/C++ Libhover Plug-in (Incubation)
+provider=Eclipse \ No newline at end of file
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/plugin.xml b/libhover/org.eclipse.linuxtools.cdt.libhover/plugin.xml
new file mode 100644
index 0000000000..7ece4f49be
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension-point id="org.eclipse.linuxtools.cdt.libhover.library" name="C/C++ Library Hover Specifier" schema="schema/org.eclipse.linuxtools.cdt.libhover.library.exsd"/>
+
+ <extension
+ point="org.eclipse.cdt.ui.CHelpProvider">
+ <provider
+ class="org.eclipse.linuxtools.internal.cdt.libhover.LibHover"
+ id="org.eclipse.linuxtools.cdt.libhover.provider"/>
+ </extension>
+</plugin>
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/schema/org.eclipse.linuxtools.cdt.libhover.library.exsd b/libhover/org.eclipse.linuxtools.cdt.libhover/schema/org.eclipse.linuxtools.cdt.libhover.library.exsd
new file mode 100644
index 0000000000..749ba37b99
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/schema/org.eclipse.linuxtools.cdt.libhover.library.exsd
@@ -0,0 +1,216 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="library" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="library" id="org.eclipse.linuxtools.cdt.libhover.library" name="C/C++ Library Hover Specifier"/>
+ </appinfo>
+ <documentation>
+ This extension allows specification of a library hover file to use when editing C or C++ files under the CDT.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="library" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+ Unique simple id for this extension (e.g. library).
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ Name of this library to hover. This name will be shown in the preference and property dialogs.
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="library">
+ <complexType>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ Name of the library that the hover info is providing
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="location" type="string" use="required">
+ <annotation>
+ <documentation>
+ Location of the binary file containing the serialized LibHoverInfo for the documentation: either an absolute file name or a URL
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="docs" type="string">
+ <annotation>
+ <documentation>
+ URL of help documentation or empty.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="type" use="required">
+ <annotation>
+ <documentation>
+ Type of library that help is for. One of C, C++, or ASM
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="C">
+ </enumeration>
+ <enumeration value="C++">
+ </enumeration>
+ <enumeration value="ASM">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ 1.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ &lt;extension
+ point=&quot;org.eclipse.linuxtools.cdt.libhover.library&quot;&gt;
+ &lt;library
+ name=&quot;GTK&quot;
+ location=&quot;http://mywebsite/libhover/xml/gtk.xml&quot;
+ docs=&quot;http;//gtk.org/docs/gtk.html&quot;/&gt;
+ &lt;/extension&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ XML files referenced must adhere to the following xml structure:
+&lt;pre&gt;
+
+&lt;!DOCTYPE descriptions [
+
+ &lt;!ELEMENT descriptions (construct)*&gt;
+
+ &lt;!ELEMENT construct (structure|function)*&gt;
+ &lt;!ATTLIST construct
+ id ID #REQUIRED
+ type CDATA #REQUIRED
+ &gt;
+
+ &lt;!ELEMENT structure (synopsis?, elements?)?&gt;
+
+ &lt;!ELEMENT elements (element*)&gt;
+
+ &lt;!ELEMENT element (synopsis*)&gt;
+ &lt;!ATTLIST element
+ content CDATA #REQUIRED
+ &gt;
+
+ &lt;!ELEMENT synopsis (#PCDATA)*&gt;
+
+ &lt;!ELEMENT function (prototype,headers?,synopsis)&gt;
+ &lt;!ATTLIST function
+ returntype CDATA #REQUIRED
+ &gt;
+
+ &lt;!ELEMENT prototype (parameter+)?&gt;
+
+ &lt;!ELEMENT parameter (#PCDATA)*&gt;
+ &lt;!ATTLIST parameter
+ content CDATA #REQUIRED
+ &gt;
+
+ &lt;!ELEMENT headers (header+)?&gt;
+
+ &lt;!ELEMENT header (#PCDATA)*&gt;
+ &lt;!ATTLIST header
+ filename CDATA #REQUIRED
+ &gt;
+
+]&gt;
+&lt;/pre&gt;
+Note that function names need to be prefixed by &quot;function-&quot;. For example:
+&lt;pre&gt;
+&lt;descriptions&gt;
+ &lt;construct id=&quot;function-atexit&quot; type=&quot;function&quot;&gt;
+ &lt;function returntype=&quot;int&quot;&gt;
+ &lt;prototype&gt;
+ &lt;parameter content=&quot;void (*function) (void)&quot;/&gt;
+ &lt;/prototype&gt;
+ &lt;headers&gt;
+ &lt;header filename = &quot;stdlib.h&quot;/&gt;
+ &lt;/headers&gt;
+ &lt;synopsis&gt;
+ The &amp;lt;CODE&amp;gt;atexit&amp;lt;/CODE&amp;gt; function registers the function &amp;lt;VAR&amp;gt;function&amp;lt;/VAR&amp;gt; to be
+ called at normal program termination. The &amp;lt;VAR&amp;gt;function&amp;lt;/VAR&amp;gt; is called with
+ no arguments.
+ &amp;lt;br&amp;gt;&amp;lt;br&amp;gt; The return value from &amp;lt;CODE&amp;gt;atexit&amp;lt;/CODE&amp;gt; is zero on success and nonzero if
+ the function cannot be registered.
+ &lt;/synopsis&gt;
+ &lt;/function&gt;
+ &lt;/construct&gt;
+&lt;/descriptions&gt;
+&lt;/pre&gt;
+
+Also note that the synopsis is output as html. To specify html tags, one needs to use &amp;amp;lt; and &amp;amp;gt; as delimeters in place of &quot;&amp;lt&quot; and &quot;&amp;gt&quot;. In the previous example, VAR tags are used for variable references, CODE tags for the function name, and br tags for forcing paragraph breaks. All of these make the hover look more interesting when displayed.
+ </documentation>
+ </annotation>
+
+
+ <annotation>
+ <appinfo>
+ <meta.section type="copyright"/>
+ </appinfo>
+ <documentation>
+ /*******************************************************************************
+ * Copyright (c) 2008 Red Hat Inc. 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:
+ * Red Hat Inc. - initial API and implementation
+ *******************************************************************************/
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/ClassInfo.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/ClassInfo.java
new file mode 100644
index 0000000000..fe826df00d
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/ClassInfo.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+
+public class ClassInfo implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private String templateParms[] = new String[0];
+ private boolean templateParmsFilled = false;
+ private String className;
+ private String id;
+ private String include;
+ private ArrayList<ClassInfo> baseClasses = new ArrayList<ClassInfo>();
+ private HashMap<String, MemberInfo> members = new HashMap<String, MemberInfo>();
+ private transient Document document;
+ public transient Node classNode;
+ private ArrayList<ClassInfo> children = null;
+ public ClassInfo(String className, String id, Node classNode) {
+ this.className = className;
+ this.id = id;
+ this.classNode = classNode;
+ }
+ public String getClassName() {
+ return className;
+ }
+ public Node getClassNode() {
+ if (classNode == null)
+ classNode = document.getElementById(id);
+ return classNode;
+ }
+ public void setDocument (Document d) {
+ document = d;
+ }
+ public void setClassName(String newName) {
+ className = newName;
+ }
+ public void addTemplate(ClassInfo child) {
+ if (children == null)
+ children = new ArrayList<ClassInfo>();
+ children.add(child);
+ }
+ public boolean areTemplateParmsFilled() {
+ return templateParmsFilled;
+ }
+
+ public String[] getTemplateParms() {
+ return templateParms;
+ }
+
+ public void setTemplateParms(String[] templateParms) {
+ templateParmsFilled = true;
+ this.templateParms = templateParms;
+ }
+
+ public String getInclude() {
+ return include;
+ }
+
+ public void setInclude(String include) {
+ this.include = include;
+ }
+
+ public ArrayList<ClassInfo> getChildren() {
+ return children;
+ }
+
+ public MemberInfo getMember(String name) {
+ return members.get(name);
+ }
+
+ public void addMember(MemberInfo info) {
+ String name = info.getName();
+ MemberInfo member = members.get(name);
+ if (member != null)
+ member.addChild(info);
+ else
+ members.put(name, info);
+ }
+
+ public MemberInfo[] getMembers(String nameStart) {
+ ArrayList<MemberInfo> matchList = new ArrayList<MemberInfo>();
+ Collection<MemberInfo> values = members.values();
+ for (Iterator<MemberInfo> i = values.iterator(); i.hasNext();) {
+ MemberInfo k = i.next();
+ if (k.getName().startsWith(nameStart)) {
+ matchList.add(k);
+ ArrayList<MemberInfo> children = k.getChildren();
+ if (children != null) {
+ for (Iterator<MemberInfo> j = children.iterator(); j.hasNext();) {
+ MemberInfo child = (MemberInfo)i.next();
+ matchList.add(child);
+ }
+ }
+ }
+ }
+ MemberInfo[] matches = new MemberInfo[matchList.size()];
+ return matchList.toArray(matches);
+ }
+
+ public ArrayList<ClassInfo> getBaseClasses() {
+ return baseClasses;
+ }
+
+ public void addBaseClass(ClassInfo info) {
+ baseClasses.add(info);
+ }
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/FunctionInfo.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/FunctionInfo.java
new file mode 100644
index 0000000000..b9fef1bd7d
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/FunctionInfo.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class FunctionInfo implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private String name;
+ private String prototype;
+ private String desc;
+ private String returnType;
+ private ArrayList<String> headers = new ArrayList<String>();
+ private ArrayList<FunctionInfo> children = null;
+
+ /**
+ * Constructor for function.
+ *
+ * @param name
+ */
+ public FunctionInfo(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get function name.
+ *
+ * @return function name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get prototype for function.
+ *
+ * @return prototype string or null
+ */
+ public String getPrototype() {
+ return prototype;
+ }
+
+ /**
+ * Set prototype string.
+ *
+ * @param prototype
+ */
+ public void setPrototype(String prototype) {
+ this.prototype = prototype;
+ }
+
+ /**
+ * Get description for function.
+ *
+ * @return description string or null
+ */
+ public String getDescription() {
+ return desc;
+ }
+
+ /**
+ * Set description string for function.
+ *
+ * @param desc
+ */
+ public void setDescription(String desc) {
+ this.desc = desc;
+ }
+
+ /**
+ * Get return type for function.
+ *
+ * @return return type as string or null
+ */
+ public String getReturnType() {
+ return returnType;
+ }
+
+ /**
+ * Set return type for function.
+ *
+ * @param returnType
+ */
+ public void setReturnType(String returnType) {
+ this.returnType = returnType;
+ }
+
+ /**
+ * Get the headers that need including for this function.
+ *
+ * @return list of header strings
+ */
+ public ArrayList<String> getHeaders() {
+ return headers;
+ }
+
+ /**
+ * Add a header to the list of headers needed for this function.
+ *
+ * @param header the name of the header file to add
+ */
+ public void addHeader(String header) {
+ headers.add(header);
+ }
+
+ /**
+ * Add a function with the same name as a child of this function (C++-only).
+ *
+ * @param info a function with same name as this function.
+ */
+ public void addChild(FunctionInfo info) {
+ if (children == null)
+ children = new ArrayList<FunctionInfo>();
+ children.add(info);
+ }
+
+ /**
+ * Get the children functions with same name as this function.
+ *
+ * @return an ArrayList of functions with same name or null.
+ */
+ public ArrayList<FunctionInfo> getChildren() {
+ return children;
+ }
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/HelpBook.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/HelpBook.java
new file mode 100644
index 0000000000..efdb2dbc42
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/HelpBook.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+
+import org.eclipse.cdt.ui.ICHelpBook;
+
+public class HelpBook implements ICHelpBook {
+
+ private String title;
+ private int type;
+
+ public HelpBook (String title, String typeName) {
+ this.title = title;
+ if (typeName.equals("C")) // $NON-NLS-1$
+ type = HELP_TYPE_C;
+ else if (typeName.equals("C++")) // $NON-NLS-1$
+ type = HELP_TYPE_CPP;
+ else
+ type = HELP_TYPE_ASM;
+ }
+ public String getTitle () {
+ return title;
+ }
+
+ public int getCHelpType () {
+ return type;
+ }
+
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibHoverInfo.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibHoverInfo.java
new file mode 100644
index 0000000000..09536d302a
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibHoverInfo.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.TreeMap;
+
+public class LibHoverInfo implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+ public HashMap<String, ClassInfo> classes = new HashMap<String, ClassInfo>();
+ public HashMap<String, TypedefInfo> typedefs = new HashMap<String, TypedefInfo>();
+ public TreeMap<String, FunctionInfo> functions = new TreeMap<String, FunctionInfo>();
+
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibhoverPlugin.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibhoverPlugin.java
new file mode 100644
index 0000000000..39e2b2b0c5
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/LibhoverPlugin.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class LibhoverPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.linuxtools.cdt.libhover";
+
+ // The shared instance
+ private static LibhoverPlugin plugin;
+
+ /**
+ * The constructor
+ */
+ public LibhoverPlugin() {
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static LibhoverPlugin getDefault() {
+ return plugin;
+ }
+
+ /*
+ * Returns the id of the plugin
+ */
+ public static String getID() {
+ return PLUGIN_ID;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/MemberInfo.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/MemberInfo.java
new file mode 100644
index 0000000000..ac92c65375
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/MemberInfo.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class MemberInfo implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private String name;
+ private String prototype;
+ private String desc;
+ private String returnType;
+ private String[] paramTypes = new String[0];
+ private ArrayList<MemberInfo> children = null;
+
+ /**
+ * Constructor for member.
+ *
+ * @param name
+ */
+ public MemberInfo(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Get member name.
+ *
+ * @return member name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get prototype for member.
+ *
+ * @return prototype string or null
+ */
+ public String getPrototype() {
+ return prototype;
+ }
+
+ /**
+ * Set prototype string.
+ *
+ * @param prototype
+ */
+ public void setPrototype(String prototype) {
+ this.prototype = prototype;
+ }
+
+ /**
+ * Get description for member.
+ *
+ * @return description string or null
+ */
+ public String getDescription() {
+ return desc;
+ }
+
+ /**
+ * Set description string for member.
+ *
+ * @param desc
+ */
+ public void setDescription(String desc) {
+ this.desc = desc;
+ }
+
+ /**
+ * Get param types for member.
+ *
+ * @return return array of param types
+ */
+ public String[] getParamTypes() {
+ return paramTypes;
+ }
+
+ /**
+ * Set param types for member.
+ *
+ * @param array of param types
+ */
+ public void setParamTypes(String[] paramTypes) {
+ this.paramTypes = paramTypes;
+ }
+ /**
+ * Get return type for member.
+ *
+ * @return return type as string or null
+ */
+ public String getReturnType() {
+ return returnType;
+ }
+
+ /**
+ * Set return type for member.
+ *
+ * @param returnType
+ */
+ public void setReturnType(String returnType) {
+ this.returnType = returnType;
+ }
+
+ /**
+ * Add a member with the same name as a child of this member.
+ *
+ * @param info a member with same name as this member.
+ */
+ public void addChild(MemberInfo info) {
+ if (children == null)
+ children = new ArrayList<MemberInfo>();
+ children.add(info);
+ }
+
+ /**
+ * Get the children members with same name as this member.
+ *
+ * @return an ArrayList of members with same name or null.
+ */
+ public ArrayList<MemberInfo> getChildren() {
+ return children;
+ }
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/TypedefInfo.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/TypedefInfo.java
new file mode 100644
index 0000000000..d861558e94
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/TypedefInfo.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+public class TypedefInfo implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private String[] templates = new String[0];
+ private String typedefName;
+ private String transformedType;
+ private ArrayList<TypedefInfo> children = null;
+ public TypedefInfo(String typedefName, String transformedType) {
+ this.typedefName = typedefName;
+ this.transformedType = transformedType;
+ }
+ public String getTypedefName() {
+ return typedefName;
+ }
+ public void setTypedefName(String name) {
+ typedefName = name;
+ }
+
+ private String[] getTemplateArgs(String str) {
+ ArrayList<String> list = new ArrayList<String>();
+ int index = 0;
+ int lastIndex = 0;
+ int templateCounter = 0;
+ while (index < str.length()) {
+ char ch = str.charAt(index);
+ if (ch == '<') {
+ if (templateCounter == 0)
+ lastIndex = index + 1;
+ templateCounter++;
+ } else if (ch == '>') {
+ templateCounter--;
+ } else if (ch == ',' && templateCounter == 1) {
+ // FIXME: do we have to strip out all blanks here?
+ list.add(str.substring(lastIndex, index).trim());
+ lastIndex = index + 1;
+ }
+ ++index;
+ }
+ String[] args = new String[list.size()];
+ return list.toArray(args);
+ }
+
+ public String getTransformedType(String className) {
+ int index = className.indexOf('<');
+ if (index > 0) {
+ TypedefInfo e = this;
+ // Search the children list in case the given class name
+ // matches a specific template case.
+ ArrayList<TypedefInfo> children = getChildren();
+ for (int x = 0; x < children.size(); ++x) {
+ TypedefInfo child = children.get(x);
+ if (className.matches(child.getTypedefName())) {
+ e = child;
+ break;
+ }
+ }
+ String[] templates = e.getTemplates();
+ String transformedName = e.transformedType;
+ // Check if there are any template arguments to replace. If not,
+ // we can just return the transformed type we have.
+ if (templates.length <= 0)
+ return transformedName;
+ String[] args = getTemplateArgs(className);
+ String[] templateArgs = getTemplateArgs(e.getTypedefName());
+ int j = 0;
+ // For every argument that doesn't match up, it must be a template
+ // parameter so we'll replace the template parameter name with the
+ // supplied parameter. We have to query the template parameter list
+ // for the names to replace because for partial specific templates
+ // those names will have been replaced with regex sequences designed to
+ // help us identify when the specific template has matched. For example,
+ // <char, _Tp> will be stored as <char,[a-zA-Z0-9_]*> and if we have
+ // <char,char> we will replace _Tp with char in the transformed type.
+ for (int i = 0; i < args.length; ++i) {
+ if (!args[i].equals(templateArgs[i])) {
+ transformedName.replaceAll(templates[j], args[i]);
+ ++j;
+ }
+ }
+ return transformedName;
+ } else {
+ // There is no template specified.
+ return transformedType;
+ }
+ }
+
+ public void addTypedef(TypedefInfo typedef) {
+ if (children == null)
+ children = new ArrayList<TypedefInfo>();
+ children.add(typedef);
+ }
+ public ArrayList<TypedefInfo> getChildren() {
+ return children;
+ }
+ public void copyTemplates(String[] newTemplates) {
+ templates = new String[newTemplates.length];
+ for (int i = 0; i < templates.length; ++i)
+ templates[i] = newTemplates[i];
+ }
+ public String[] getTemplates() {
+ return templates;
+ }
+}
+
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/utils/BuildFunctionInfos.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/utils/BuildFunctionInfos.java
new file mode 100644
index 0000000000..e0daac3512
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/cdt/libhover/utils/BuildFunctionInfos.java
@@ -0,0 +1,213 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.cdt.libhover.utils;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectOutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.filesystem.URIUtil;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo;
+import org.eclipse.linuxtools.cdt.libhover.FunctionInfo;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class BuildFunctionInfos {
+
+ private Document document;
+ private LibHoverInfo hoverInfo = new LibHoverInfo();
+
+ public BuildFunctionInfos(Document document) {
+ this.document = document;
+ }
+
+ public Document getDocument() {
+ return document;
+ }
+
+ protected FunctionInfo getFunctionInfoFromNode(String name, Node function_node, Document document) {
+ FunctionInfo f = new FunctionInfo(name);
+ NamedNodeMap function_node_map = function_node.getAttributes();
+ Node function_node_returntype_node = function_node_map.item(0);
+ String function_node_rt_name = function_node_returntype_node.getNodeName();
+
+ if (function_node_rt_name.equals("returntype")) { // $NON-NLS-1$
+
+ // return type
+
+ String function_node_rt_value = function_node_returntype_node.getNodeValue();
+ f.setReturnType(function_node_rt_value);
+ } // returntype
+
+ NodeList function_node_kids = function_node.getChildNodes();
+ for (int fnk = 0; fnk < function_node_kids.getLength(); fnk++) {
+ Node function_node_kid = function_node_kids.item(fnk);
+ String function_node_kid_name = function_node_kid.getNodeName();
+ if (function_node_kid_name.equals("prototype")) { // $NON-NLS-1$
+
+ // prototype
+
+ String prototype = null;
+
+ NodeList function_node_parms = function_node_kid.getChildNodes();
+ for (int fnp = 0; fnp < function_node_parms.getLength(); fnp++) {
+ Node function_node_parm = function_node_parms.item(fnp);
+ String function_node_parm_name = function_node_parm.getNodeName();
+ if (function_node_parm_name.equals("parameter")) { // $NON-NLS-1$
+ NamedNodeMap function_node_parm_map = function_node_parm.getAttributes();
+ Node function_node_parm_node = function_node_parm_map.item(0);
+ String parameter = function_node_parm_node.getNodeValue();
+ prototype = (null == prototype)
+ ? parameter
+ : prototype + ", " + parameter;
+ }
+ }
+ f.setPrototype(prototype);
+ } // prototype
+
+ else if (function_node_kid_name.equals("headers")) { // $NON-NLS-1$
+
+ // headers
+
+ NodeList function_node_headers = function_node_kid.getChildNodes();
+ for (int fnh = 0; fnh < function_node_headers.getLength(); fnh++) {
+ Node function_node_header = function_node_headers.item(fnh);
+ String function_node_header_name = function_node_header.getNodeName();
+ if (function_node_header_name.equals("header")) { // $NON-NLS-1$
+ NamedNodeMap function_node_header_map = function_node_header.getAttributes();
+ Node function_node_header_node = function_node_header_map.item(0);
+ f.addHeader(function_node_header_node.getNodeValue());
+ }
+ }
+ } // headers
+
+
+ else if (function_node_kid_name.equals("groupsynopsis")) { // $NON-NLS-1$
+
+ // group synopsis
+
+ NamedNodeMap attr = function_node_kid.getAttributes();
+ Node idnode = attr.getNamedItem("id"); // $NON-NLS-1$
+ String id = idnode.getNodeValue();
+ if (id != null) {
+ Element elem2 = document.getElementById(id);
+ if (null != elem2) {
+ NodeList synopsisNode = elem2.getElementsByTagName("synopsis"); // $NON-NLS-1$
+ if (null != synopsisNode && synopsisNode.getLength() > 0) {
+ Node synopsis = synopsisNode.item(0);
+ Node textNode = synopsis.getLastChild();
+ f.setDescription(textNode.getNodeValue());
+ }
+ }
+ }
+ }
+
+ else if (function_node_kid_name.equals("synopsis")) { // $NON-NLS-1$
+
+ // synopsis
+
+ Node textNode = function_node_kid.getLastChild();
+ f.setDescription(textNode.getNodeValue());
+ }
+ }
+ return f;
+ }
+
+ public void buildCPPInfo(String fileName) {
+ Document document = getDocument();
+ NodeList nl = document.getElementsByTagName("construct"); // $NON-NLS-1$
+ for (int i = 0; i < nl.getLength(); ++i) {
+ Node n = nl.item(i);
+ NamedNodeMap m = n.getAttributes();
+ Node id = m.getNamedItem("id"); // $NON-NLS-1$
+ if (id != null && id.getNodeValue().startsWith("function-")) { // $NON-NLS-1$
+ String name = id.getNodeValue().substring(9);
+ NodeList nl2 = n.getChildNodes();
+ for (int j = 0; j < nl2.getLength(); ++j) {
+ Node n2 = nl2.item(j);
+ if (n2.getNodeName().equals("function")) { // $NON-NLS-1$
+ FunctionInfo f = getFunctionInfoFromNode(name, n2, document);
+ hoverInfo.functions.put(name, f);
+ }
+ }
+ }
+ }
+ try {
+ // Now, output the LibHoverInfo for caching later
+ FileOutputStream f = new FileOutputStream(fileName);
+ ObjectOutputStream out = new ObjectOutputStream(f);
+ out.writeObject(hoverInfo);
+ out.close();
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @param args[0] - URL or file name of xml document to parse
+ * args[1] - file name to place resultant serialized LibHoverInfo
+ */
+ public static void main(String[] args) {
+ URI acDoc;
+ try {
+ acDoc = new URI(args[0]);
+ IPath p = URIUtil.toPath(acDoc);
+ InputStream docStream = null;
+ if (p == null) {
+ URL url = acDoc.toURL();
+ docStream = url.openStream();
+ } else {
+ docStream = new FileInputStream(p.toFile());
+ }
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(false);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(docStream);
+ if (doc != null) {
+ BuildFunctionInfos d = new BuildFunctionInfos(doc);
+ d.buildCPPInfo(args[1]);
+ }
+ System.out.println("Built " + args[1] + " from " + args[0]);
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java
new file mode 100644
index 0000000000..c04e403d99
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHover.java
@@ -0,0 +1,641 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2006, 2007, 2008 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+/*
+ * Initially created on Jul 8, 2004
+ */
+
+/**
+ * @author Chris Moller, Red Hat, Inc.
+ * @author Jeff Johnston, Red Hat, Inc. (rewrite to use ICHelpProvider)
+ * Modified to be org.eclipse.linuxtools.cdt.libhover package.
+ */
+
+package org.eclipse.linuxtools.internal.cdt.libhover;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.Map.Entry;
+
+import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTNamedTypeSpecifier;
+import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
+import org.eclipse.cdt.core.dom.ast.IType;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
+import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
+import org.eclipse.cdt.core.model.ILanguage;
+import org.eclipse.cdt.core.model.ITranslationUnit;
+import org.eclipse.cdt.ui.ICHelpBook;
+import org.eclipse.cdt.ui.ICHelpProvider;
+import org.eclipse.cdt.ui.ICHelpResourceDescriptor;
+import org.eclipse.cdt.ui.IFunctionSummary;
+import org.eclipse.cdt.ui.IRequiredInclude;
+import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
+import org.eclipse.cdt.ui.text.IHoverHelpInvocationContext;
+import org.eclipse.cdt.ui.text.SharedASTJob;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.RegistryFactory;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.help.IHelpResource;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.linuxtools.cdt.libhover.ClassInfo;
+import org.eclipse.linuxtools.cdt.libhover.FunctionInfo;
+import org.eclipse.linuxtools.cdt.libhover.HelpBook;
+import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo;
+import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin;
+import org.eclipse.linuxtools.cdt.libhover.MemberInfo;
+
+
+public class LibHover implements ICHelpProvider {
+
+ public static String LIBHOVER_DOC_EXTENSION = LibhoverPlugin.PLUGIN_ID + ".library"; //$NON-NLS-1$
+
+ // see comment in initialize()
+ // private static String defaultSearchPath = null;
+
+ private static HashMap<ICHelpBook, LibHoverLibrary> libraries = new HashMap<ICHelpBook, LibHoverLibrary>();
+
+ static final String constructTypes[] ={
+ "dtype", // $NON-NLS-1$
+ "enum", // $NON-NLS-1$
+ "function", // $NON-NLS-1$
+ "groupsynopsis", // $NON-NLS-1$
+ "struct", // $NON-NLS-1$
+ "type", // $NON-NLS-1$
+ "union" // $NON-NLS-1$
+ };
+
+ static final int dtypeIndex = 0;
+ static final int enumIndex = 1;
+ static final int functionIndex = 2;
+ static final int groupsynopsisIndex = 3;
+ static final int structIndex = 4;
+ static final int typeIndex = 5;
+ static final int unionIndex = 6;
+
+ private static ArrayList<ICHelpBook> helpBooks = new ArrayList<ICHelpBook>();
+ public static boolean docsFetched = false;
+
+ public static synchronized void getLibHoverDocs() {
+ if (docsFetched)
+ return;
+// System.out.println("getlibhoverdocs");
+ libraries.clear();
+ helpBooks.clear();
+ IExtensionRegistry x = RegistryFactory.getRegistry();
+ IConfigurationElement[] ces = x.getConfigurationElementsFor(LIBHOVER_DOC_EXTENSION);
+ for (int i = 0; i < ces.length; ++i) {
+ IConfigurationElement ce = ces[i];
+ if (ce.getName().equals("library")) { //$NON-NLS-1$
+ // see comment in initialize()
+ // Use the FileLocator class to open the magic hover doc file
+ // in the plugin's jar.
+ // Either open the html file or file system file depending
+ // on what has been specified.
+ String location = ce.getAttribute("location"); //$NON-NLS-1$
+ String name = ce.getAttribute("name"); //$NON-NLS-1$
+ String helpdocs = ce.getAttribute("docs"); //$NON-NLS-1$
+ String type = ce.getAttribute("type"); //$NON-NLS-1$
+ HelpBook h = new HelpBook(name, type);
+ helpBooks.add(h);
+ LibHoverLibrary l = new LibHoverLibrary(name, location, helpdocs,
+ true);
+ libraries.put(h, l);
+ docsFetched = true;
+ }
+ }
+ }
+
+ public void initialize() {
+ getLibHoverDocs();
+ }
+
+ public ICHelpBook[] getCHelpBooks () {
+ ICHelpBook[] chelpbooks = new ICHelpBook[helpBooks.size()];
+ return helpBooks.toArray(chelpbooks);
+ }
+
+ private class FunctionSummary implements IFunctionSummary, Comparable<FunctionSummary> {
+
+ private String Name;
+ private String NameSpace;
+ private String ReturnType;
+ private String Prototype;
+ private String Summary;
+ private boolean prototypeHasBrackets;
+
+// private String Synopsis;
+ private class RequiredInclude implements IRequiredInclude {
+ private String include;
+
+ public RequiredInclude (String file) {
+ include = file;
+ }
+
+ public String getIncludeName() {
+ return include;
+ }
+
+ public boolean isStandard() {
+ return true;
+ }
+ }
+
+ public int compareTo (FunctionSummary x) {
+ FunctionSummary y = (FunctionSummary)x;
+ return getName().compareTo(y.getName());
+ }
+
+// private RequiredInclude Includes[];
+ private ArrayList<RequiredInclude> Includes = new ArrayList<RequiredInclude>();
+
+ private void setIncludeName (String iname) {
+ RequiredInclude nri = new RequiredInclude(iname);
+ Includes.add(nri);
+ }
+
+ public class FunctionPrototypeSummary implements IFunctionPrototypeSummary {
+ public String getName() { return Name; }
+ public String getReturnType() { return ReturnType; }
+ public String getArguments() { return Prototype; }
+ public String getPrototypeString(boolean namefirst) {
+ if (true == namefirst) {
+ if (prototypeHasBrackets())
+ return Name + " " + Prototype + " " + ReturnType; // $NON-NLS-1$ // $NON-NLS-2$
+ return Name + " (" + Prototype + ") " + ReturnType; // $NON-NLS-1$ // $NON-NLS-2$
+ }
+ else {
+ if (prototypeHasBrackets())
+ return ReturnType + " " + Name + " " + Prototype; // $NON-NLS-1$ // $NON-NLS-2$
+ return ReturnType + " " + Name + " (" + Prototype + ")"; // $NON-NLS-1$ // $NON-NLS-2$ // $NON-NLS-3$
+ }
+ }
+ }
+
+ public String getName() { return Name; }
+ public String getNamespace() { return NameSpace; }
+ public String getDescription() { return Summary; }
+ public boolean prototypeHasBrackets() { return prototypeHasBrackets; }
+ public void setPrototypeHasBrackets(boolean value) { prototypeHasBrackets = value; }
+ public IFunctionPrototypeSummary getPrototype() { return new FunctionPrototypeSummary(); }
+
+ public IRequiredInclude[] getIncludes() {
+ IRequiredInclude[] includes = new IRequiredInclude[Includes.size()];
+ for (int i = 0; i < Includes.size(); ++i) {
+ includes[i] = (IRequiredInclude)Includes.get(i);
+ }
+ return includes;
+ }
+
+ }
+
+ public boolean isCPPCharacter(int ch) {
+ return Character.isLetterOrDigit(ch) || ch == '_' || ch == ':';
+ }
+
+ private class EnclosingASTNameJob extends SharedASTJob {
+ private int tlength;
+ private int toffset;
+ private IASTName result = null;
+ public EnclosingASTNameJob (ITranslationUnit t,
+ int toffset, int tlength) {
+ super("EnclosingASTNameJob", t); // $NON-NLS-1$
+ this.toffset = toffset;
+ this.tlength = tlength;
+ }
+ public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
+ if (ast != null) {
+ result = ast.getNodeSelector(null).findEnclosingName(toffset, tlength);
+ }
+ return Status.OK_STATUS;
+ }
+ public IASTName getASTName() {
+ return result;
+ }
+ }
+
+ public class ASTDeclarationFinderJob extends SharedASTJob {
+ private IBinding binding;
+ private IASTName[] decls = null;
+ public ASTDeclarationFinderJob (ITranslationUnit t, IBinding binding) {
+ super("ASTDeclarationFinderJob", t); // $NON-NLS-1$
+ this.binding = binding;
+ }
+ public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast) {
+ if (ast != null) {
+ decls = ast.getDeclarationsInAST(binding);
+ }
+ return Status.OK_STATUS;
+ }
+ public IASTName[] getDeclarations() {
+ return decls;
+ }
+ }
+
+ public IFunctionSummary getFunctionInfo(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) {
+ IFunctionSummary f;
+
+ f = null;
+ boolean isPTR = false;
+ boolean isREF = false;
+ int offset = -1;
+ int length = 0;
+
+ ITranslationUnit t = context.getTranslationUnit();
+
+ String className = null;
+ ICPPFunctionType methodType = null;
+
+ if (t.isCXXLanguage()) {
+ try {
+ if (context instanceof IHoverHelpInvocationContext) {
+ // We know the file offset of the member reference.
+ IRegion region = (IRegion)((IHoverHelpInvocationContext)context).getHoverRegion();
+ char[] contents = t.getCodeReader().buffer;
+ int i = region.getOffset();
+ // Let's figure out if it is a pointer reference or a direct reference in which case we can
+ // find the variable and hence it's class.
+ if (i > 2 && contents[i-1] == '>' && contents[i-2] == '-') {
+ // Pointer reference
+ int j = i - 3;
+ int pointer = 0;
+ while (j > 0 && isCPPCharacter(contents[j])) {
+ pointer = j;
+ --j;
+ }
+ if (pointer != 0) {
+ offset = pointer;
+ length = region.getOffset() - pointer - 2;
+ isPTR = true;
+ // String pointerName = new String(contents, pointer, region.getOffset() - pointer - 2);
+ // System.out.println("pointer reference to " + pointerName);
+ }
+ } else if (i > 1 && contents[i-1] == '.') {
+ int j = i - 2;
+ int ref = 0;
+ while (j > 0 && isCPPCharacter(contents[j])) {
+ ref = j;
+ --j;
+ }
+ if (ref != 0) {
+ offset = ref;
+ length = region.getOffset() - ref - 1;
+ isREF = true;
+ // String refName = new String(contents, ref, region.getOffset() - ref - 1);
+ // System.out.println("regular reference to " + refName);
+ }
+ }
+ final IASTName[] result= {null};
+ final int toffset = offset;
+ final int tlength = length;
+
+ // If we have a pointer or reference variable, get its ASTName.
+ if (isPTR || isREF) {
+ EnclosingASTNameJob job = new EnclosingASTNameJob(t, toffset, tlength);
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (job.getResult() == Status.OK_STATUS)
+ result[0] = job.getASTName();
+ }
+
+ // If we get the ASTName for the variable, let's find its declaration which will give us its class.
+ final IASTName[][] decl = {null};
+ if (result[0] != null) {
+ final IBinding binding = result[0].resolveBinding();
+ ASTDeclarationFinderJob job = new ASTDeclarationFinderJob(t, binding);
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (job.getResult() == Status.OK_STATUS) {
+ decl[0] = job.getDeclarations();
+ }
+ }
+
+ // Look for a simple declaration.
+ IASTNode n = null;
+ if (decl[0] != null && decl[0].length > 0) {
+ n = decl[0][0];
+ while (n != null && !(n instanceof IASTSimpleDeclaration)) {
+ n = n.getParent();
+ }
+ }
+
+ // If we have the simple declaration, get its declaration specifier which hopefully will
+ // be a named type.
+ if (n != null) {
+ IASTSimpleDeclaration d = (IASTSimpleDeclaration)n;
+ IASTDeclSpecifier s = d.getDeclSpecifier();
+ if (s instanceof IASTNamedTypeSpecifier) {
+ // From the named type, we can get the binding of the type name and from that,
+ // its qualified name. We need a qualified name (i.e. with namespace) because our
+ // repository of classes and typedefs are hashed by fully qualified names.
+ IASTName astName = ((IASTNamedTypeSpecifier)s).getName();
+ if (astName != null) {
+ IBinding nameBinding = astName.resolveBinding();
+ if (nameBinding instanceof ICPPBinding) {
+ String[] qualified = ((ICPPBinding)nameBinding).getQualifiedName();
+ className = qualified[0];
+ for (int k = 1; k < qualified.length; ++k)
+ className += "::" + qualified[k];
+ } else {
+ className = nameBinding.getName();
+ }
+ }
+ }
+ }
+// System.out.println("classname is " + className);
+
+ // Now, let's find the declaration of the method. We need to do this because we want the specific
+ // member prototype to go searching for. There could be many members called "x" which have different
+ // documentation.
+ if (className != null) {
+ EnclosingASTNameJob job = new EnclosingASTNameJob(t, region.getOffset(), region.getLength());
+ job.schedule();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (job.getResult() == Status.OK_STATUS)
+ result[0] = job.getASTName();
+ }
+ if (result[0] != null) {
+ final IBinding binding = result[0].getBinding();
+ if (binding instanceof ICPPFunction) {
+ methodType = ((ICPPFunction)binding).getType();
+ }
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (DOMException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ // Loop through all the documents we have and report first match.
+ for (int i = 0; i < helpBooks.length; ++i) {
+ LibHoverLibrary l = libraries.get(helpBooks[i]);
+ if (name != null) {
+ if (className != null) {
+ if (l.isCPP())
+ f = getMemberSummary(l, className, name, methodType);
+ } else {
+ f = getFunctionSummary(l, name);
+ }
+ if (f != null)
+ return f;
+ }
+ }
+
+ return null;
+ }
+
+ private IFunctionSummary getFunctionSummary(LibHoverLibrary l, String name) {
+ FunctionInfo x = l.getFunctionInfo(name);
+ if (x != null) {
+ FunctionSummary f = new FunctionSummary();
+ f.ReturnType = x.getReturnType();
+ f.Prototype = x.getPrototype();
+ f.Summary = x.getDescription();
+ f.Name = x.getName();
+ ArrayList<String> headers = x.getHeaders();
+ for (int i = 0; i < headers.size(); ++i)
+ f.setIncludeName(headers.get(i));
+ return f;
+ }
+ return null;
+ }
+
+ private IFunctionSummary getMemberSummary(LibHoverLibrary l, String className,
+ String memberName, ICPPFunctionType methodType) {
+
+ ArrayList<String> templateTypes = new ArrayList<String>();
+ ClassInfo info = l.getClassInfo(className, templateTypes);
+ String[] args = new String[0];
+ @SuppressWarnings("unused")
+ IType returnType = null;
+ if (info == null)
+ return null;
+ if (methodType != null) {
+ args = resolveArgs(info, methodType.getParameterTypes(), templateTypes);
+ returnType = methodType.getReturnType();
+
+ }
+ MemberInfo member = info.getMember(memberName);
+ if (member != null) {
+ MemberInfo m = null;
+ if (!isParmMatch(member, args, templateTypes, info)) {
+ ArrayList<MemberInfo> members = member.getChildren();
+ for (int i = 0; i < members.size(); ++i) {
+ MemberInfo k = members.get(i);
+ if (isParmMatch(k, args, templateTypes, info)) {
+ m = k;
+ break;
+ }
+ }
+ } else {
+ m = member;
+ }
+
+ if (m != null) {
+ // FIXME: do some work to determine parameters and return type.
+ FunctionSummary f = new FunctionSummary();
+ f.ReturnType = m.getReturnType();
+ f.Prototype = m.getPrototype();
+ f.Summary = m.getDescription();
+ String actualClassName = className.substring(className.indexOf("::")+2); // $NON-NLS-1$
+ f.Name = actualClassName + "::" + memberName; // $NON-NLS-1$
+ String[] templateParms = info.getTemplateParms();
+ for (int i = 0; i < templateTypes.size(); ++i) {
+ f.ReturnType = f.ReturnType.replaceAll(templateParms[i], templateTypes.get(i));
+ f.Prototype = f.Prototype.replaceAll(templateParms[i], templateTypes.get(i));
+ f.Name = f.Name.replaceAll(templateParms[i], templateTypes.get(i));
+ }
+ if (f.ReturnType.indexOf('<') >= 0) {
+ f.ReturnType = f.ReturnType.replaceAll("<", "&lt;");
+ f.ReturnType = f.ReturnType.replaceAll(">", "&gt;");
+ }
+ if (f.Prototype.indexOf('<') >= 0) {
+ f.Prototype = f.Prototype.replaceAll("<", "&lt;");
+ f.Prototype = f.Prototype.replaceAll(">", "&gt;");
+ }
+ if (f.Name.indexOf('<') >= 0) {
+ f.Name = f.Name.replaceAll("<", "&lt;");
+ f.Name = f.Name.replaceAll(">", "&gt;");
+ }
+ f.setPrototypeHasBrackets(true);
+ f.setIncludeName(info.getInclude());
+ return f;
+ }
+ }
+ return null;
+ }
+
+
+ private boolean isParmMatch(MemberInfo m, String[] args, ArrayList<String> templateTypes, ClassInfo info) {
+ String[] memberParms = m.getParamTypes();
+ for (int i = 0; i < memberParms.length; ++i) {
+ String[] templateParms = info.getTemplateParms();
+ for (int j = 0; j < templateTypes.size(); ++j) {
+ memberParms[i] = memberParms[i].replaceAll(templateParms[j], templateTypes.get(j));
+ }
+ }
+ return Arrays.equals(memberParms, args);
+ }
+
+ private String[] resolveArgs(ClassInfo info, IType[] parameterTypes, ArrayList<String> templateTypes) {
+ String[] templateParms = info.getTemplateParms();
+ String[] result = new String[parameterTypes.length];
+ for (int i = 0; i < parameterTypes.length; ++i) {
+ String param = parameterTypes[i].toString();
+ param = param.replaceAll("\\{.*\\}", "");
+ param = param.trim();
+ int index = param.indexOf("#");
+ while (index >= 0) {
+ // We assume no class has more than 9 template parms.
+ int digit = param.charAt(index + 1) - '0';
+ // where possible, replace template parms with real values
+ if (digit < templateTypes.size())
+ param = param.replaceFirst(param.substring(index, index + 2), templateTypes.get(digit));
+ else
+ param = param.replaceFirst(param.substring(index, index + 2), templateParms[digit]);
+ index = param.indexOf("#");
+ }
+ result[i] = param;
+ }
+ return result;
+ }
+
+ public IFunctionSummary[] getMatchingFunctions(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String prefix) {
+ ArrayList<IFunctionSummary> fList = new ArrayList<IFunctionSummary>();
+
+ for (int di = 0; di < helpBooks.length; ++di) {
+ LibHoverLibrary l = libraries.get(helpBooks[di]);
+ LibHoverInfo cppInfo = l.getHoverInfo();
+ SortedMap<String, FunctionInfo> map = cppInfo.functions.tailMap(prefix);
+ Set<Map.Entry<String, FunctionInfo>> c = map.entrySet();
+ for (Iterator<Entry<String, FunctionInfo>> i = c.iterator(); i.hasNext();) {
+ Map.Entry<String, FunctionInfo> e = (Map.Entry<String, FunctionInfo>)i.next();
+ FunctionInfo x = e.getValue();
+ if (x.getName().startsWith(prefix)) {
+ FunctionSummary f = new FunctionSummary();
+ f.ReturnType = x.getReturnType();
+ f.Prototype = x.getPrototype();
+ f.Summary = x.getDescription();
+ f.Name = x.getName();
+ ArrayList<String> headers = x.getHeaders();
+ for (int i1 = 0; i1 < headers.size(); ++i1)
+ f.setIncludeName(headers.get(i1));
+ fList.add(f);
+ }
+ }
+
+// Document document = l != null ? l.getDocument() : null;
+// if ((null != document) && (null != prefix)) {
+// NodeList elems = document.getElementsByTagName("construct"); // $NON-NLS-1$
+// for (int i = 0; i < elems.getLength(); ++i) {
+// Element elem = (Element)elems.item(i);
+// NamedNodeMap attrs = elem.getAttributes();
+// Node id_node = attrs.item(0);
+// String elemName = id_node.getNodeValue();
+// if (elemName != null && elemName.startsWith("function-")) { // $NON-NLS-1$
+// String funcName = elemName.substring(9);
+// if (funcName != null && funcName.startsWith(prefix)) {
+// NodeList functionNodes = elem.getElementsByTagName("function"); // $NON-NLS-1$
+// for (int j = 0; j < functionNodes.getLength(); ++j) {
+// Node function_node = functionNodes.item(j);
+// FunctionSummary f = getFunctionSummaryFromNode(funcName, function_node, document);
+// fList.add(f);
+// }
+// }
+// }
+// }
+// }
+ }
+ IFunctionSummary[] summaries = new IFunctionSummary[fList.size()];
+ for (int k = 0; k < summaries.length; k++) {
+ summaries[k] = (IFunctionSummary)fList.get(k);
+ }
+ return summaries;
+ }
+
+ private class HelpResource implements IHelpResource {
+ private String href;
+ private String label;
+ public HelpResource(String href, String label) {
+ this.href = href;
+ this.label = label;
+ }
+ public String getHref() {
+ return href;
+ }
+ public String getLabel() {
+ return label;
+ }
+ }
+
+ private class HelpResourceDescriptor implements ICHelpResourceDescriptor {
+ private ICHelpBook helpbook;
+
+ public HelpResourceDescriptor(ICHelpBook helpbook) {
+ this.helpbook = helpbook;
+ }
+
+ public ICHelpBook getCHelpBook() {
+ return helpbook;
+ }
+
+ public IHelpResource[] getHelpResources() {
+ LibHoverLibrary l = libraries.get(helpbook);
+ if (l != null) {
+ IHelpResource[] hr = new IHelpResource[1];
+ hr[0] = new HelpResource(l.getLocation(), l.getName());
+ return hr;
+ }
+ return null;
+ }
+ }
+
+ public ICHelpResourceDescriptor[] getHelpResources(ICHelpInvocationContext context, ICHelpBook[] helpBooks, String name) {
+ for (int i = 0; i < helpBooks.length; ++i) {
+ IFunctionSummary fs = getFunctionInfo(context, new ICHelpBook[]{helpBooks[i]}, name);
+ if (fs != null) {
+ return new HelpResourceDescriptor[]{new HelpResourceDescriptor(helpBooks[i])};
+ }
+ }
+ return null;
+ }
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverLibrary.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverLibrary.java
new file mode 100644
index 0000000000..8019cf0b1f
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverLibrary.java
@@ -0,0 +1,216 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+
+import org.eclipse.core.filesystem.URIUtil;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.linuxtools.cdt.libhover.ClassInfo;
+import org.eclipse.linuxtools.cdt.libhover.FunctionInfo;
+import org.eclipse.linuxtools.cdt.libhover.LibHoverInfo;
+import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin;
+import org.eclipse.linuxtools.cdt.libhover.TypedefInfo;
+
+public class LibHoverLibrary {
+ private String name;
+ private String location;
+ private String docs;
+ private boolean isCPP;
+ private LibHoverInfo hoverInfo = new LibHoverInfo();
+ private boolean haveReadHoverInfo = false;
+
+ public LibHoverLibrary(String name, String location, String docs,
+ boolean isCPP) {
+ this.name = name;
+ this.location = location;
+ this.docs = docs;
+ this.isCPP = isCPP;
+ }
+
+ /**
+ * Get the name of the library
+ *
+ * @return the name of the library
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the location of the library hover info (URL or file name)
+ *
+ * @return the URL or file name string for the library hover info location
+ */
+ public String getLocation() {
+ return location;
+ }
+
+ /**
+ * Get the browser help documentation URL for this library
+ *
+ * @return the name of the help documentation URL
+ */
+ public String getDocs() {
+ return docs;
+ }
+
+ /**
+ * Is this library a C++ library?
+ *
+ * @return true if C++ library, false otherwise
+ */
+ public boolean isCPP() {
+ return isCPP;
+ }
+
+ /**
+ * Get the library hover info for this library
+ *
+ * @return the library hover info for this library
+ */
+ public LibHoverInfo getHoverInfo() {
+ // We lazily get the hover info for this library since it is possible
+ // the user will never access or ultimately need it if another library
+ // supplies the information first.
+ if (!haveReadHoverInfo) {
+ URI acDoc;
+ try {
+ acDoc = new URI(location);
+ IPath p = URIUtil.toPath(acDoc);
+ InputStream docStream = null;
+ if (p == null) {
+ URL url = acDoc.toURL();
+ docStream = url.openStream();
+ } else {
+ try {
+ // Try to open the file as local to this plug-in.
+ docStream = FileLocator.openStream(LibhoverPlugin.getDefault().getBundle(), p, false);
+ } catch (IOException e) {
+ // File is not local to plug-in, try file system.
+ docStream = new FileInputStream(p.toFile());
+ }
+ }
+ ObjectInputStream input = new ObjectInputStream(docStream);
+ hoverInfo = (LibHoverInfo)input.readObject();
+ haveReadHoverInfo = true;
+ input.close();
+ docStream.close();
+ } catch (URISyntaxException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (MalformedURLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ return hoverInfo;
+ }
+
+ /**
+ * Set the library hover info.
+ *
+ * @param hoverInfo the library hover info to set
+ */
+ public void setHoverinfo(LibHoverInfo hoverInfo) {
+ this.hoverInfo = hoverInfo;
+ }
+
+ /**
+ * Fetch the class info for a given class.
+ *
+ * @param className the name of the class to fetch info for
+ * @return ClassInfo or null if no class info can be found
+ */
+ public ClassInfo getClassInfo(String className, ArrayList<String> templateTypes) {
+ String typedefName = className.replaceAll("<.*>", "<>"); // $NON-NLS-1$ // $NON-NLS-2$
+ TypedefInfo typedef = getHoverInfo().typedefs.get(typedefName);
+ if (typedef != null) {
+ className = typedef.getTransformedType(className); // Reset class name to typedef transformation
+ }
+ int index = className.indexOf('<');
+ // Check if it is a template reference.
+ if (index != -1) {
+ resolveTemplateTypes(className, templateTypes, index);
+ // It is. We want to see if there are partial specific templates
+ // and we choose the first match. If nothing matches our particular
+ // case, we fall back on the initial generic template.
+ ClassInfo info = getHoverInfo().classes.get(className.substring(0, index));
+ ArrayList<ClassInfo> children = info.getChildren();
+ if (children != null && children.size() > 0) {
+ for (int x = 0; x < children.size(); ++x) {
+ ClassInfo child = children.get(x);
+ if (className.matches(child.getClassName())) {
+ info = child;
+ break;
+ }
+ }
+ }
+ return info;
+ }
+ // Otherwise no template, just fetch the class info directly.
+ return getHoverInfo().classes.get(className);
+ }
+
+ private void resolveTemplateTypes(String className,
+ ArrayList<String> templateTypes, int index) {
+ int startIndex = index + 1;
+ int i = startIndex;
+ int count = 1;
+ while (count > 0 && i < className.length()) {
+ char x = className.charAt(i);
+ switch (x) {
+ case ('<'):
+ ++count;
+ break;
+ case ('>'):
+ --count;
+ if (count == 0)
+ templateTypes.add(className.substring(startIndex, i).trim());
+ break;
+ case (','): {
+ if (count == 1) {
+ templateTypes.add(className.substring(startIndex, i).trim());
+ startIndex = i + 1;
+ }
+ }
+ break;
+ }
+ ++i;
+ }
+ }
+
+ /**
+ * Fetch the function info for a given function.
+ *
+ * @param name of function to find info for
+ * @return FunctionInfo or null if no function info exists
+ */
+ public FunctionInfo getFunctionInfo(String name) {
+ return getHoverInfo().functions.get(name);
+ }
+}
+
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.java
new file mode 100644
index 0000000000..8a4724727b
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2002, 2006, 2007 QNX Software Systems 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:
+ * QNX Software Systems - Initial API and implementation
+ * Red Hat Inc. - Modification to use with LibHover
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.cdt.libhover;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * MakefilePreferencesMessages
+ */
+public class LibHoverMessages {
+
+ /**
+ *
+ */
+ private LibHoverMessages() {
+ }
+
+ private static final String BUNDLE_NAME = "org.eclipse.linuxtools.cdt.libhover.LibHoverMessages"; //$NON-NLS-1$
+
+ public static String getString(String key) {
+ try {
+ return ResourceBundle.getBundle(BUNDLE_NAME).getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ } catch (NullPointerException e) {
+ return '#' + key + '#';
+ }
+ }
+
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.properties b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.properties
new file mode 100644
index 0000000000..c187c96126
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/LibHoverMessages.properties
@@ -0,0 +1,16 @@
+#################################################################################
+# Copyright (c) 2007 Red Hat, Inc.
+# 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:
+# Red Hat Incorporated - initial API and implementation
+#################################################################################
+LibcHelpResource.label=C Library Help
+LibcHelpBook.title=C Library Functions
+FileListControl.moveup=Move Up
+FileListControl.movedown=Move Down
+LibhoverPreferences.title=C/C++ Library Hover Enablement
+Libhover.projectSpecific.msg=Use project specific settings \ No newline at end of file
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/CheckboxFieldEditor.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/CheckboxFieldEditor.java
new file mode 100644
index 0000000000..546b4f5f90
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/CheckboxFieldEditor.java
@@ -0,0 +1,394 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.preferences;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.cdt.ui.newui.UIMessages;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.preference.FieldEditor;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.internal.cdt.libhover.LibHoverMessages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Table;
+
+public class CheckboxFieldEditor extends FieldEditor {
+
+ private String extensionID;
+ private String preferenceName;
+ private HashMap<String, String> mapItems = new HashMap<String, String>();
+ private Table table;
+ private CheckboxTableViewer tv;
+ private Button[] buttons;
+ private Composite usercomp; // space where user can create widgets
+ private Composite buttoncomp; // space for buttons on the right
+
+
+ public static final String EMPTY_STR = ""; //$NON-NLS-1$
+ public static final String MOVEUP_STR = LibHoverMessages.getString("FileListControl.moveup"); //$NON-NLS-1$
+ public static final String MOVEDOWN_STR = LibHoverMessages.getString("FileListControl.movedown"); //$NON-NLS-1$
+
+ public CheckboxFieldEditor(String extensionID, String preferenceName, String label, Composite parent) {
+ this.extensionID = extensionID;
+ this.preferenceName = preferenceName;
+ init(preferenceName, label);
+ createControl(parent);
+ }
+
+
+ @Override
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditor#adjustForNumColumns(int)
+ */
+ protected void adjustForNumColumns(int numColumns) {
+ if (numColumns > 1) {
+ Control control = getLabelControl();
+ if (control != null) {
+ ((GridData)control.getLayoutData()).horizontalSpan = numColumns;
+ }
+ ((GridData)table.getLayoutData()).horizontalSpan = numColumns - 1;
+ ((GridData)buttoncomp.getLayoutData()).horizontalSpan = 1;
+ } else {
+ Control control = getLabelControl();
+ if (control != null) {
+ ((GridData)control.getLayoutData()).horizontalSpan = 1;
+ }
+ ((GridData)usercomp.getLayoutData()).horizontalSpan = 1;
+ ((GridData)buttoncomp.getLayoutData()).horizontalSpan = 1;
+ }
+ }
+
+
+ @Override
+ // TODO Auto-generated method stub
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.FieldEditor#doFillIntoGrid(org.eclipse.swt.widgets.Composite, int)
+ */
+ protected void doFillIntoGrid(Composite parent, int numColumns) {
+ int checkC = 1;
+ if (numColumns > 1) {
+ checkC = numColumns - 1;
+ }
+ Control control = getLabelControl(parent);
+ GridData gd = new GridData();
+ gd.horizontalSpan = numColumns;
+ control.setLayoutData(gd);
+ control = getCheckboxControl(parent);
+ gd = new GridData();
+ gd.horizontalSpan = checkC;
+ gd.horizontalAlignment = GridData.FILL;
+ gd.verticalAlignment = GridData.FILL;
+ gd.grabExcessHorizontalSpace = true;
+ gd.grabExcessVerticalSpace = true;
+ control.setLayoutData(gd);
+ control.setFont(parent.getFont());
+ control = getButtonControl(parent);
+ gd = new GridData();
+ gd.horizontalSpan = 1;
+ gd.horizontalAlignment = GridData.FILL;
+ control.setLayoutData(gd);
+ control.setFont(parent.getFont());
+ }
+
+ private void getExtensions() {
+ mapItems.clear();
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(
+ extensionID);
+ if (point != null) {
+ IExtension[] exts = point.getExtensions();
+ for (IExtension ext : exts) {
+ if (ext.getConfigurationElements().length > 0) {
+ mapItems.put(ext.getUniqueIdentifier(), ext.getLabel());
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void doLoad() {
+ // Combine user preference string with existing libhover extensions.
+ getExtensions();
+ HashMap<String,String> copyMap = (HashMap<String,String>)mapItems.clone();
+ ArrayList<TableData> data = new ArrayList<TableData>();
+ ArrayList<TableData> checkedData = new ArrayList<TableData>();
+ // See what the user has set in preferences and make sure that
+ // any libhover referred to is a valid current extension.
+ // Drop any preference for a non-existent extension.
+ String pref = getPreferenceStore().getString(preferenceName);
+ String[] tokens = pref.split(":");
+ if (tokens.length > 1) {
+ for (int i = 0; i < tokens.length; i+=2) {
+ String id = tokens[i];
+ Boolean checked = Boolean.valueOf(tokens[i+1]);
+ String value = copyMap.get(id);
+ if (value != null) {
+ TableData d = new TableData(id, value);
+ data.add(d);
+ if (checked)
+ checkedData.add(d);
+ copyMap.remove(id);
+ }
+ }
+ }
+ // Add remaining libhover extensions to end of list as checked by default
+ String[] leftovers = new String[copyMap.size()];
+ leftovers = copyMap.keySet().toArray(leftovers);
+ for (int i = 0; i < leftovers.length; ++i) {
+ TableData d = new TableData(leftovers[i], copyMap.get(leftovers[i]));
+ data.add(d);
+ checkedData.add(d);
+ }
+ tv.setInput(data.toArray());
+ tv.setCheckedElements(checkedData.toArray());
+ updateButtons();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void doLoadDefault() {
+ // Default is to find all current extensions and turn them on by default.
+ getExtensions();
+ HashMap<String,String> copyMap = (HashMap<String,String>)mapItems.clone();
+ ArrayList<TableData> data = new ArrayList<TableData>();
+ ArrayList<TableData> checkedData = new ArrayList<TableData>();
+ String[] ids = new String[copyMap.size()];
+ ids = copyMap.keySet().toArray(ids);
+ for (int i = 0; i < ids.length; ++i) {
+ TableData d = new TableData(ids[i], copyMap.get(ids[i]));
+ data.add(d);
+ checkedData.add(d);
+ }
+ tv.setInput(data.toArray());
+ tv.setCheckedElements(checkedData.toArray());
+ updateButtons();
+ }
+
+ @Override
+ protected void doStore() {
+ save();
+ }
+
+ @Override
+ public int getNumberOfControls() {
+ return 3;
+ }
+
+ public Control getButtonControl(Composite parent) {
+ if (buttoncomp == null) {
+ buttoncomp = new Composite(parent, SWT.NONE);
+ GridData d = new GridData(GridData.END);
+ d.widthHint = 1;
+ buttoncomp.setLayoutData(d);
+ buttoncomp.setFont(parent.getFont());
+ initButtons(buttoncomp, new String[] {
+ MOVEUP_STR, MOVEDOWN_STR, null,
+ UIMessages.getString("ErrorParsTab.0"), //$NON-NLS-1$
+ UIMessages.getString("ErrorParsTab.1") //$NON-NLS-1$
+ });
+ }
+ return buttoncomp;
+ }
+
+ public Control getCheckboxControl(Composite parent) {
+ if (table == null) {
+// parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ table = new Table(parent, SWT.BORDER | SWT.CHECK | SWT.SINGLE);
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ table.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateButtons();
+ }});
+ tv = new CheckboxTableViewer(table);
+ tv.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return (Object[])inputElement;
+ }
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ });
+
+ tv.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent e) {
+ }
+ });
+
+ }
+ return table;
+ }
+ /**
+ * Ability to create standard button on any composite.
+ * @param c
+ * @param names
+ */
+ protected void initButtons(Composite c, String[] names) {
+ initButtons(c, names, 80);
+ }
+ protected void initButtons(Composite c, String[] names, int width) {
+ if (names == null || names.length == 0) return;
+ c.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ c.setLayout(new GridLayout(1, false));
+ buttons = new Button[names.length];
+ for (int i=0; i<names.length; i++) {
+ buttons[i] = new Button(c, SWT.PUSH);
+ buttons[i].setFont(c.getFont());
+ GridData gdb = new GridData(GridData.VERTICAL_ALIGN_CENTER);
+ gdb.grabExcessHorizontalSpace = false;
+ gdb.horizontalAlignment = SWT.FILL;
+ gdb.minimumWidth = width;
+
+ if (names[i] != null)
+ buttons[i].setText(names[i]);
+ else { // no button, but placeholder !
+ buttons[i].setVisible(false);
+ buttons[i].setEnabled(false);
+ gdb.heightHint = 10;
+ }
+
+ buttons[i].setLayoutData(gdb);
+ buttons[i].addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ buttonPressed(event);
+ }});
+ }
+ }
+
+ /**
+ *
+ * @param e - event to be handled
+ */
+ private void buttonPressed(SelectionEvent e) {
+ for (int i=0; i<buttons.length; i++) {
+ if (buttons[i].equals(e.widget)) {
+ buttonPressed(i);
+ return;
+ }
+ }
+ }
+
+ public void buttonPressed (int n) {
+ switch (n) {
+ case 0: // up
+ moveItem(true);
+ break;
+ case 1: // down
+ moveItem(false);
+ break;
+ case 2: // do nothing - it's not a button
+ break;
+
+ case 3: // check all
+ tv.setAllChecked(true);
+ break;
+ case 4: // uncheck all
+ tv.setAllChecked(false);
+ break;
+ default:
+ break;
+ }
+ }
+
+ // Move item up / down
+ private void moveItem(boolean up) {
+ int n = table.getSelectionIndex();
+ if (n < 0 ||
+ (up && n == 0) ||
+ (!up && n+1 == table.getItemCount()))
+ return;
+ TableData d = (TableData)tv.getElementAt(n);
+ boolean checked = tv.getChecked(d);
+ tv.remove(d);
+ n = up ? n - 1 : n + 1;
+ tv.insert(d, n);
+ tv.setChecked(d, checked);
+ table.setSelection(n);
+ }
+ /**
+ * Changes state of existing button.
+ * Does nothing if index is invalid
+ *
+ * @param i - button index
+ * @param state - required state
+ */
+ protected void buttonSetEnabled(int i, boolean state) {
+ if (buttons == null || buttons.length <= i ) return;
+ buttons[i].setEnabled(state);
+ }
+
+ public void updateButtons() {
+ int cnt = table.getItemCount();
+ int pos = table.getSelectionIndex();
+ buttonSetEnabled(0, pos > 0);
+ buttonSetEnabled(1, pos != -1 && pos < (cnt - 1));
+ buttonSetEnabled(3, cnt > 0);
+ buttonSetEnabled(4, cnt > 0);
+ }
+
+ class TableData {
+ String key;
+ String value;
+ public TableData (String _key, String _value) {
+ key = _key;
+ value = _value;
+ }
+ @Override
+ public String toString() { return value; }
+ }
+
+ private void save() {
+ boolean inRange = true;
+ int i = 0;
+ String outString = new String();
+ String del = "";
+ while (inRange) {
+ TableData t;
+ Object obj = tv.getElementAt(i);
+ if (obj == null)
+ inRange = false;
+ else {
+ ++i;
+ t = (TableData)obj;
+ outString += del + t.key + ":" + tv.getChecked(obj);
+ del = ":";
+ }
+ }
+ if (outString.length() > 1)
+ getPreferenceStore().setValue(preferenceName, outString);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.jface.preference.FieldEditor#setEnabled(boolean,
+ * org.eclipse.swt.widgets.Composite)
+ */
+ public void setEnabled(boolean enabled, Composite parent) {
+ super.setEnabled(enabled, parent);
+ getCheckboxControl(parent).setEnabled(enabled);
+ getButtonControl(parent).setEnabled(enabled);
+ }
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/LibHoverPreferencePage.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/LibHoverPreferencePage.java
new file mode 100644
index 0000000000..c86aff4faf
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/LibHoverPreferencePage.java
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.preferences;
+
+import org.eclipse.jface.preference.*;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin;
+import org.eclipse.linuxtools.internal.cdt.libhover.LibHover;
+import org.eclipse.linuxtools.internal.cdt.libhover.LibHoverMessages;
+
+/**
+ * This class represents a preference page that
+ * is contributed to the Preferences dialog. By
+ * subclassing <samp>FieldEditorPreferencePage</samp>, we
+ * can use the field support built into JFace that allows
+ * us to create a page that is small and knows how to
+ * save, restore and apply itself.
+ * <p>
+ * This page is used to modify preferences only. They
+ * are stored in the preference store that belongs to
+ * the main plug-in class. That way, preferences can
+ * be accessed directly via the preference store.
+ */
+
+public class LibHoverPreferencePage
+ extends FieldEditorPreferencePage
+ implements IWorkbenchPreferencePage {
+
+ public LibHoverPreferencePage() {
+ super(GRID);
+ setPreferenceStore(LibhoverPlugin.getDefault().getPreferenceStore());
+ }
+
+ /**
+ * Creates the field editors. Field editors are abstractions of
+ * the common GUI blocks needed to manipulate various types
+ * of preferences. Each field editor knows how to save and
+ * restore itself.
+ */
+ public void createFieldEditors() {
+ addField(new CheckboxFieldEditor(LibHover.LIBHOVER_DOC_EXTENSION,
+ PreferenceConstants.P_LIBHOVER,
+ LibHoverMessages.getString("LibhoverPreferences.title"),
+ getFieldEditorParent()));
+// addField(new DirectoryFieldEditor(PreferenceConstants.P_PATH,
+// "&Directory preference:", getFieldEditorParent()));
+// addField(
+// new BooleanFieldEditor(
+// PreferenceConstants.P_BOOLEAN,
+// "&An example of a boolean preference",
+// getFieldEditorParent()));
+//
+// addField(new RadioGroupFieldEditor(
+// PreferenceConstants.P_CHOICE,
+// "An example of a multiple-choice preference",
+// 1,
+// new String[][] { { "&Choice 1", "choice1" }, {
+// "C&hoice 2", "choice2" }
+// }, getFieldEditorParent()));
+// addField(
+// new StringFieldEditor(PreferenceConstants.P_STRING, "A &text preference:", getFieldEditorParent()));
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
+ */
+ public void init(IWorkbench workbench) {
+ }
+
+} \ No newline at end of file
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceConstants.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceConstants.java
new file mode 100644
index 0000000000..709d6ca657
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceConstants.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.preferences;
+
+/**
+ * Constant definitions for plug-in preferences
+ */
+public class PreferenceConstants {
+
+ public static String P_LIBHOVER = "libhoverPreference"; //$NON-NLS-1$
+
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceInitializer.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceInitializer.java
new file mode 100644
index 0000000000..4fd11a6c40
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/preferences/PreferenceInitializer.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin;
+
+/**
+ * Class used to initialize default preference values.
+ */
+public class PreferenceInitializer extends AbstractPreferenceInitializer {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
+ */
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = LibhoverPlugin.getDefault().getPreferenceStore();
+ store.setDefault(PreferenceConstants.P_LIBHOVER, "");
+// store.setDefault(PreferenceConstants.P_BOOLEAN, true);
+// store.setDefault(PreferenceConstants.P_CHOICE, "choice2");
+// store.setDefault(PreferenceConstants.P_STRING,
+// "Default value");
+ }
+
+}
diff --git a/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/properties/LibHoverPropertyPage.java b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/properties/LibHoverPropertyPage.java
new file mode 100644
index 0000000000..aca9cf05d4
--- /dev/null
+++ b/libhover/org.eclipse.linuxtools.cdt.libhover/src/org/eclipse/linuxtools/internal/cdt/libhover/properties/LibHoverPropertyPage.java
@@ -0,0 +1,465 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * 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:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.cdt.libhover.properties;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.eclipse.cdt.ui.newui.UIMessages;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.cdt.libhover.LibhoverPlugin;
+import org.eclipse.linuxtools.internal.cdt.libhover.LibHover;
+import org.eclipse.linuxtools.internal.cdt.libhover.LibHoverMessages;
+import org.eclipse.linuxtools.internal.cdt.libhover.preferences.PreferenceConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.ui.dialogs.PropertyPage;
+
+public class LibHoverPropertyPage extends PropertyPage {
+
+ private static final String PROJECT_SPECIFIC_MSG = "Libhover.projectSpecific.msg"; //$NON-NLS-1$
+ private static final String LIBHOVER_PROPERTY = "LIBHOVER"; //$NON-NLS-1$
+
+ private QualifiedName libhoverProperty = new QualifiedName(LibhoverPlugin.getID(), LIBHOVER_PROPERTY);
+
+ private Button projectSpecific;
+
+ private HashMap<String, String> mapItems = new HashMap<String, String>();
+
+ private Table table;
+ private CheckboxTableViewer tv;
+ private Button[] buttons;
+ private Composite buttoncomp; // space for buttons on the right
+
+ public static final String EMPTY_STR = ""; //$NON-NLS-1$
+ public static final String MOVEUP_STR = LibHoverMessages.getString("FileListControl.moveup"); //$NON-NLS-1$
+ public static final String MOVEDOWN_STR = LibHoverMessages.getString("FileListControl.movedown"); //$NON-NLS-1$
+
+ /**
+ * Constructor for LibhoverPropertyPage.
+ */
+ public LibHoverPropertyPage() {
+ super();
+ setPreferenceStore(LibhoverPlugin.getDefault().getPreferenceStore());
+ }
+
+ private IProject getProject() {
+ IResource r = (IResource)getElement().getAdapter(IResource.class);
+ return r.getProject();
+ }
+
+ private String getPropertyString() {
+ String p;
+ try {
+ p = getProject().getPersistentProperty(libhoverProperty);
+ } catch (CoreException c) {
+ p = null;
+ }
+ return p;
+ }
+
+ private void addFirstSection(Composite parent) {
+ Composite composite = createDefaultComposite(parent);
+
+ projectSpecific = new Button(composite, SWT.CHECK);
+ projectSpecific.setText(LibHoverMessages.getString(PROJECT_SPECIFIC_MSG));
+ String p = getPropertyString();
+ projectSpecific.setSelection(p != null);
+ projectSpecific.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ projectSpecificPressed(event);
+ }});
+ }
+
+ private void projectSpecificPressed(SelectionEvent event) {
+ if (projectSpecific.getSelection()) {
+ buttoncomp.setEnabled(true);
+ table.setEnabled(true);
+ updateCheckboxData(true);
+ } else {
+ buttoncomp.setEnabled(false);
+ table.setEnabled(false);
+ updateCheckboxData(false);
+ }
+ }
+
+ private void addSeparator(Composite parent) {
+ Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ separator.setLayoutData(gridData);
+ }
+
+ private void addLabel(Composite parent) {
+ Label label = new Label(parent, SWT.HORIZONTAL);
+ label.setText(LibHoverMessages.getString("LibhoverPreferences.title")); //$NON-NLS-1$
+ GridData gridData = new GridData();
+ gridData.horizontalAlignment = GridData.FILL;
+ gridData.grabExcessHorizontalSpace = true;
+ label.setLayoutData(gridData);
+ }
+
+ private Control getCheckboxControl(Composite parent) {
+ if (table == null) {
+// parent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ table = new Table(parent, SWT.BORDER | SWT.CHECK | SWT.SINGLE);
+ GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ gridData.horizontalSpan = 2;
+ table.setLayoutData(gridData);
+ table.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateButtons();
+ }});
+ tv = new CheckboxTableViewer(table);
+ tv.setContentProvider(new IStructuredContentProvider() {
+ public Object[] getElements(Object inputElement) {
+ return (Object[])inputElement;
+ }
+ public void dispose() {}
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
+ });
+
+ tv.addCheckStateListener(new ICheckStateListener() {
+ public void checkStateChanged(CheckStateChangedEvent e) {
+ }
+ });
+
+ }
+ return table;
+ }
+
+ private Control getButtonControl(Composite parent) {
+ if (buttoncomp == null) {
+ buttoncomp = new Composite(parent, SWT.NONE);
+ GridData d = new GridData(GridData.END);
+ d.widthHint = 1;
+ d.horizontalSpan = 1;
+ buttoncomp.setLayoutData(d);
+ buttoncomp.setFont(parent.getFont());
+ initButtons(buttoncomp, new String[] {
+ MOVEUP_STR, MOVEDOWN_STR, null,
+ UIMessages.getString("ErrorParsTab.0"), //$NON-NLS-1$
+ UIMessages.getString("ErrorParsTab.1") //$NON-NLS-1$
+ });
+ }
+ return buttoncomp;
+ }
+
+ private void addSecondSection(Composite parent) {
+ Composite composite = createDefaultComposite(parent);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 3;
+ composite.setLayout(layout);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(data);
+
+ getCheckboxControl(composite);
+ getButtonControl(composite);
+ }
+
+ /**
+ * @see PreferencePage#createContents(Composite)
+ */
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ composite.setLayout(layout);
+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
+ composite.setLayoutData(data);
+
+ addFirstSection(composite);
+ addSeparator(composite);
+ addLabel(composite);
+ addSecondSection(composite);
+ String p = getPropertyString();
+ updateCheckboxData(p != null);
+ buttoncomp.setEnabled(p != null);
+ table.setEnabled(p != null);
+
+ return composite;
+ }
+
+ private Composite createDefaultComposite(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NULL);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+
+ GridData data = new GridData();
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalAlignment = GridData.FILL;
+ composite.setLayoutData(data);
+
+ return composite;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+ */
+ protected void performDefaults() {
+ updateCheckboxData(projectSpecific.getSelection());
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performOk()
+ */
+ public boolean performOk() {
+ try {
+ save();
+ } catch (CoreException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Ability to create standard button on any composite.
+ * @param c
+ * @param names
+ */
+ private void initButtons(Composite c, String[] names) {
+ initButtons(c, names, 80);
+ }
+
+ private void initButtons(Composite c, String[] names, int width) {
+ if (names == null || names.length == 0) return;
+ c.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ c.setLayout(new GridLayout(1, false));
+ buttons = new Button[names.length];
+ for (int i=0; i<names.length; i++) {
+ buttons[i] = new Button(c, SWT.PUSH);
+ buttons[i].setFont(c.getFont());
+ GridData gdb = new GridData(GridData.VERTICAL_ALIGN_CENTER);
+ gdb.grabExcessHorizontalSpace = false;
+ gdb.horizontalAlignment = SWT.FILL;
+ gdb.minimumWidth = width;
+
+ if (names[i] != null)
+ buttons[i].setText(names[i]);
+ else { // no button, but placeholder !
+ buttons[i].setVisible(false);
+ buttons[i].setEnabled(false);
+ gdb.heightHint = 10;
+ }
+
+ buttons[i].setLayoutData(gdb);
+ buttons[i].addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ buttonPressed(event);
+ }});
+ }
+ }
+
+ /**
+ *
+ * @param e - event to be handled
+ */
+ private void buttonPressed(SelectionEvent e) {
+ for (int i=0; i<buttons.length; i++) {
+ if (buttons[i].equals(e.widget)) {
+ buttonPressed(i);
+ return;
+ }
+ }
+ }
+
+ private void buttonPressed (int n) {
+ switch (n) {
+ case 0: // up
+ moveItem(true);
+ break;
+ case 1: // down
+ moveItem(false);
+ break;
+ case 2: // do nothing - it's not a button
+ break;
+
+ case 3: // check all
+ tv.setAllChecked(true);
+ break;
+ case 4: // uncheck all
+ tv.setAllChecked(false);
+ break;
+ default:
+ break;
+ }
+ }
+
+ // Move item up / down
+ private void moveItem(boolean up) {
+ int n = table.getSelectionIndex();
+ if (n < 0 ||
+ (up && n == 0) ||
+ (!up && n+1 == table.getItemCount()))
+ return;
+ TableData d = (TableData)tv.getElementAt(n);
+ boolean checked = tv.getChecked(d);
+ tv.remove(d);
+ n = up ? n - 1 : n + 1;
+ tv.insert(d, n);
+ tv.setChecked(d, checked);
+ table.setSelection(n);
+ }
+ /**
+ * Changes state of existing button.
+ * Does nothing if index is invalid
+ *
+ * @param i - button index
+ * @param state - required state
+ */
+ private void buttonSetEnabled(int i, boolean state) {
+ if (buttons == null || buttons.length <= i ) return;
+ buttons[i].setEnabled(state);
+ }
+
+ private void updateButtons() {
+ int cnt = table.getItemCount();
+ int pos = table.getSelectionIndex();
+ buttonSetEnabled(0, pos > 0);
+ buttonSetEnabled(1, pos != -1 && pos < (cnt - 1));
+ buttonSetEnabled(3, cnt > 0);
+ buttonSetEnabled(4, cnt > 0);
+ }
+
+ private class TableData {
+ String key;
+ String value;
+ public TableData (String _key, String _value) {
+ key = _key;
+ value = _value;
+ }
+ @Override
+ public String toString() { return value; }
+ }
+
+ private void getExtensions() {
+ mapItems.clear();
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(
+ LibHover.LIBHOVER_DOC_EXTENSION);
+ if (point != null) {
+ IExtension[] exts = point.getExtensions();
+ for (IExtension ext : exts) {
+ if (ext.getConfigurationElements().length > 0) {
+ mapItems.put(ext.getUniqueIdentifier(), ext.getLabel());
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void updateCheckboxData(boolean useProject) {
+ // Combine user preference string with existing libhover extensions.
+ getExtensions();
+ HashMap<String,String> copyMap = (HashMap<String,String>)mapItems.clone();
+ ArrayList<TableData> data = new ArrayList<TableData>();
+ ArrayList<TableData> checkedData = new ArrayList<TableData>();
+ // See what the user has set in preferences/properties and make sure that
+ // any libhover referred to is a valid current extension.
+ // Drop any preference for a non-existent extension.
+ String prop = null;
+ String pref = null;
+ // User wants to use project settings. If they already exist, honor them.
+ if (useProject)
+ prop = getPropertyString();
+ // If no property settings exist or the user has not asked for project
+ // specific settings, then use the preferences as default.
+ if (prop == null)
+ pref = getPreferenceStore().getString(PreferenceConstants.P_LIBHOVER);
+ else // otherwise use the property settings
+ pref = prop;
+ // The property string has the same format as the preference string which is
+ // id1:boolean1:id2:boolean2:id3:boolean3 (where booleanx is checked or not)
+ String[] tokens = pref.split(":");
+ if (tokens.length > 1) {
+ for (int i = 0; i < tokens.length; i+=2) {
+ String id = tokens[i];
+ Boolean checked = Boolean.valueOf(tokens[i+1]);
+ String value = copyMap.get(id);
+ if (value != null) {
+ TableData d = new TableData(id, value);
+ data.add(d);
+ if (checked)
+ checkedData.add(d);
+ copyMap.remove(id);
+ }
+ }
+ }
+ // Add any remaining libhover extensions to end of list. If there is an
+ // existing property string, we treat them as unchecked. If we are
+ // defaulting to the preferences, then we treat them as checked.
+ String[] leftovers = new String[copyMap.size()];
+ leftovers = copyMap.keySet().toArray(leftovers);
+ for (int i = 0; i < leftovers.length; ++i) {
+ TableData d = new TableData(leftovers[i], copyMap.get(leftovers[i]));
+ data.add(d);
+ if (!useProject || prop == null)
+ checkedData.add(d);
+ }
+ tv.setInput(data.toArray());
+ tv.setCheckedElements(checkedData.toArray());
+ updateButtons();
+ }
+
+ private void save() throws CoreException {
+ // if we are not using project-specific property, then we
+ // set it to be null
+ if (!projectSpecific.getSelection())
+ getProject().setPersistentProperty(libhoverProperty, null);
+
+ // Otherwise form a string which has all of the libhovers in order
+ // with their boolean checked value. Use ":" to separate all entries
+ boolean inRange = true;
+ int i = 0;
+ String outString = new String();
+ String del = "";
+ while (inRange) {
+ TableData t;
+ Object obj = tv.getElementAt(i);
+ if (obj == null)
+ inRange = false;
+ else {
+ ++i;
+ t = (TableData)obj;
+ outString += del + t.key + ":" + tv.getChecked(obj);
+ del = ":";
+ }
+ }
+ // Save formatted string to project.
+ if (outString.length() > 1)
+ getProject().setPersistentProperty(libhoverProperty, outString);
+ }
+} \ No newline at end of file

Back to the top