1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Initial commit of CDT code from QNX

This commit is contained in:
Sebastien Marineau 2002-06-26 20:55:44 +00:00
parent e0fe72f58c
commit 58eca28a21
316 changed files with 37232 additions and 0 deletions

View file

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="utils.ui"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.ui_2.0.0/workbench.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.ui_2.0.0/workbenchsrc.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.ui.win32_2.0.0/workbenchwin32.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_WIN32_SOURCE/org.eclipse.ui.win32_2.0.0/workbenchwin32src.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.swt.win32_2.0.0/ws/win32/swt.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_WIN32_SOURCE/org.eclipse.swt.win32_2.0.0/ws/win32/swtsrc.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.core.resources_2.0.0/resources.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.core.resources_2.0.0/resourcessrc.zip"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.apache.xerces_4.0.3/xmlParserAPIs.jar"/>
<classpathentry kind="var" path="ECLIPSE_HOME/plugins/org.apache.xerces_4.0.3/xercesImpl.jar"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.search_2.0.0/search.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.search_2.0.0/searchsrc.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.compare_2.0.0/compare.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.compare_2.0.0/comparesrc.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.debug.ui_2.0.0/dtui.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.debug.ui_2.0.0/dtuisrc.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.debug.core_2.0.0/dtcore.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.debug.core_2.0.0/dtcoresrc.zip"/>
<classpathentry kind="src" path="/org.eclipse.cdt.core"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.core.runtime_2.0.0/runtime.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.core.runtime_2.0.0/runtimesrc.zip"/>
<classpathentry kind="var"
path="ECLIPSE_HOME/plugins/org.eclipse.core.boot_2.0.0/boot.jar" sourcepath="_ORG_ECLIPSE_PLATFORM_SOURCE/org.eclipse.core.boot_2.0.0/bootsrc.zip"/>
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -0,0 +1 @@
bin

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.ui</name>
<comment></comment>
<projects>
<project>org.eclipse.cdt.core</project>
</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.jdt.core.javanature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
</natures>
</projectDescription>

View file

@ -0,0 +1,8 @@
###############################################
#
# (c) Copyright QNX Software Systems Ltd. 2002.
# All Rights Reserved.
#
###############################################
source.cdtui.jar = src

View file

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="org.eclipse.cdt.ui" default="plugin.zip" basedir=".">
<target name="init">
<initTemplate/>
<property name="plugin" value="org.eclipse.cdt.ui"/>
<property name="version" value="0.5.4"/>
</target>
<target name="plugin.zip" depends="init">
<property name="destroot" value="${basedir}/_temp___"/>
<delete dir="${destroot}"/>
<mkdir dir="${destroot}"/>
<antcall target="jar"/>
<antcall target="bin"/>
<zip zipfile="${plugin}_${version}.zip" basedir="${destroot}"/>
<delete dir="${destroot}"/>
</target>
<target name="cdtui.jar" depends="init">
<property name="out" value="${basedir}/cdtui.jar.bin"/>
<delete dir="${out}"/>
<mkdir dir="${out}"/>
<ant antfile="${template}" target="jar">
<property name="includes" value="src/"/>
<property name="excludes" value=""/>
<property name="compilePath" value="/export/WebSphere/eclipse/plugins/org.eclipse.search/search.jar;/export/WebSphere/eclipse/plugins/org.eclipse.debug.core/dtcore.jar;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.debug/bin;/export/WebSphere/eclipse/plugins/org.apache.xerces/xerces.jar;../CDTCore/bin;/export/WebSphere/eclipse/plugins/org.eclipse.ui/bin;../CMake/cdtmake.jar;/export/WebSphere/eclipse/plugins/org.eclipse.help/help.jar;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.ui/bin;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.launching/bin;/export/WebSphere/eclipse/plugins/org.eclipse.core.boot/boot.jar;/export/WebSphere/eclipse/plugins/org.eclipse.debug.core/bin;/export/WebSphere/eclipse/plugins/org.eclipse.debug.ui/dtui.jar;/export/WebSphere/eclipse/plugins/org.eclipse.help/bin;/export/WebSphere/eclipse/plugins/org.eclipse.core.resources/resources.jar;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.core/bin;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.debug/jdimodel.jar;/export/WebSphere/eclipse/plugins/org.eclipse.compare/bin;../CMake/bin;/export/WebSphere/eclipse/plugins/org.eclipse.compare/compare.jar;../CDTCore/cdt.jar;/export/WebSphere/eclipse/plugins/org.eclipse.core.runtime/bin;/export/WebSphere/eclipse/plugins/org.apache.xerces/bin;/export/WebSphere/eclipse/plugins/org.eclipse.debug.ui/bin;/export/WebSphere/eclipse/plugins/org.eclipse.ui/workbench.jar;/export/WebSphere/eclipse/plugins/org.eclipse.core.resources/bin;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.ui/jdt.jar;/export/WebSphere/eclipse/plugins/org.eclipse.core.runtime/runtime.jar;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.core/jdtcore.jar;/export/WebSphere/eclipse/plugins/org.eclipse.swt/swt.jar;/export/WebSphere/eclipse/plugins/org.eclipse.core.boot/bin;/export/WebSphere/eclipse/plugins/org.eclipse.search/bin;/export/WebSphere/eclipse/plugins/org.eclipse.swt/bin;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.debug/jdi.jar;/export/WebSphere/eclipse/plugins/org.eclipse.jdt.launching/launching.jar"/>
</ant>
<copy todir="${out}">
<fileset dir="src">
<include name="**"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
<property name="dest" value="${destroot}/plugins/${plugin}_${version}"/>
<jar jarfile="cdtui.jar" basedir="${out}"/>
<delete dir="${out}"/>
</target>
<target name="jar" depends="init,cdtui.jar">
</target>
<target name="cdtui.src" depends="init">
<property name="auto.includes" value="src/**/*.java"/>
<property name="auto.excludes" value=""/>
<ant antfile="${template}" target="src">
<property name="includes" value="${auto.includes}"/>
<property name="excludes" value="${auto.excludes}"/>
<property name="dest" value="${destroot}/plugins/${plugin}_${version}"/>
</ant>
</target>
<target name="src" depends="init,cdtui.src">
</target>
<target name="bin" depends="init">
<property name="auto.includes" value="**"/>
<property name="auto.excludes" value="src/"/>
<ant antfile="${template}" target="bin">
<property name="includes" value="${auto.includes}"/>
<property name="excludes" value="${auto.excludes}"/>
<property name="dest" value="${destroot}/plugins/${plugin}_${version}"/>
</ant>
</target>
<target name="log" depends="init">
<ant antfile="${template}" target="log">
<property name="dest" value="${destroot}/plugins/${plugin}_${version}"/>
</ant>
</target>
<target name="clean" depends="init">
<ant antfile="${template}" target="clean">
<property name="jar" value="cdtui.jar"/>
<property name="srczips" value="cdtuisource.jar"/>
</ant>
<delete file="${plugin}_${version}.zip"/>
</target>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 149 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 582 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 182 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 917 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 B

View file

@ -0,0 +1,87 @@
#########################################
# (c) Copyright IBM Corp. 2000, 2001.
# All Rights Reserved.
#########################################
pluginName=C Development Tools UI
elementFiltersName=CElement Filters
textHoversName=Text Hovers
editorActionsName=Editor Actions
editorRulerActionsName=Editor Ruler Actions
completionContributorName=Completion Contribution
nature.name=C Nature
perspective.name=C
viewsCategory.name=&C
BuildConsoleView.name=C-Build
CView.name=C/C++ Projects
MakeView.name=Make Targets
# The Wizard
# C
newCWizardsCategory.name=C
StdCWizard.name =Standard Make C Project
StdCWizard.description=Create a C Project
# C++
newCCWizardsCategory.name=C++
StdCCWizard.name =Standard Make C++ Project
StdCCWizard.description=Create a C++ Project
NewFileWizard.name=File
NewFileCreationWizard.description=Create a file
OpenNewFileWizardAction.label=&File
OpenNewFileWizardAction.tooltip=Create a File
NewFolderWizard.name=Folder
NewFolderCreationWizard.description=Create a folder
OpenNewFolderWizardAction.label=&Folder
OpenNewFolderWizardAction.tooltip=Create a Folder
CEditor.name=C Editor
CPluginPreferencePage.name=C/C++
CPluginEditorPreferencePage.name=C/C++ Editor
CPluginTemplatePreferencePage.name=Code Templates
CProjectPropertyPage.name=C/C++ Project
CLaunchingPropertyPage.executionArguments.name=C Execution Arguments
CApplicationLauncher.label=Executable
CApplicationLauncher.description=Launch a local command
CProblemMarker.name=C Problem
CFolderActionSet.label=C Folder Actions
CFolderActionSet.description=C Folder Action Set
Editors.DefaultTextEditor = Default Text Editor
#VCM
CompareWithMenu.label=Comp&are With
CompareWithEachOtherAction.label=&Each Other
CompareWithEachOtherAction.tooltip=Compare the Selected Resources with Each Other
CompareWithHistoryAction.label= &Local History...
CompareWithHistoryAction.tooltip= Compare the Selected Resource with Local History
ReplaceWithMenu.label=Rep&lace With
ReplaceFromHistoryAction.label=&Local History...
ReplaceFromHistoryAction.tooltip=Replace the Selected Resource with Local History
Editors.DefaultTextEditor = Default Text Editor
#VCM
CompareWithMenu.label=Comp&are With
CompareWithEachOtherAction.label=&Each Other
CompareWithEachOtherAction.tooltip=Compare the Selected Resources with Each Other
CompareWithHistoryAction.label= &Local History...
CompareWithHistoryAction.tooltip= Compare the Selected Resource with Local History
ReplaceWithMenu.label=Rep&lace With
ReplaceFromHistoryAction.label=&Local History...
ReplaceFromHistoryAction.tooltip=Replace the Selected Resource with Local History
# Task Action
DeleteTaskAction.label=Delete C/C++ Markers

View file

@ -0,0 +1,402 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin
id="org.eclipse.cdt.ui"
name="%pluginName"
version="1.0.0"
provider-name="QNX Software Systems Ltd."
class="org.eclipse.cdt.internal.ui.CPlugin">
<runtime>
<library name="cdtui.jar">
<export name="*"/>
</library>
</runtime>
<!-- ======================================================================= -->
<!-- The C Plugin -->
<!-- ======================================================================= -->
<requires>
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.apache.xerces"/>
<import plugin="org.eclipse.search"/>
<import plugin="org.eclipse.compare"/>
<import plugin="org.eclipse.debug.ui"/>
<import plugin="org.eclipse.debug.core"/>
<import plugin="org.eclipse.cdt.core"/>
</requires>
<extension-point id="CCompletionContributor" name="%completionContributorName"/>
<extension-point id="CElementFilters" name="%elementFiltersName"/>
<!-- =========================================================================== -->
<!-- Extension point: org.eclipse.cdt.ui.textHovers -->
<!-- Purpose: Provide a perspective specific text hovering for CEditor files -->
<!-- Extension Implementation: must implement org.eclipse.jface.text.ITextHover -->
<!-- =========================================================================== -->
<extension-point id="textHovers" name="%textHoversName"/>
<!-- =========================================================================== -->
<!-- Extension point: org.eclipse.cdt.ui.editorActions -->
<!-- Purpose: Provide an action for the CEditor's context menu -->
<!-- Extension Implementation: -->
<!-- must implement org.eclipse.cdt.ui.ICEditorContextMenuAction -->
<!-- =========================================================================== -->
<extension-point id="editorActions" name="%editorActionsName"/>
<!-- =========================================================================== -->
<!-- Extension point: org.eclipse.cdt.ui.editorRulerActions -->
<!-- Purpose: Provide an action for the CEditor's ruler -->
<!-- Extension Implementation: -->
<!-- must implement org.eclipse.cdt.ui.ICEditorRulerAction -->
<!-- =========================================================================== -->
<extension-point id="editorRulerActions" name="%editorRulerActionsName"/>
<!-- Implement our filters for C-View. -->
<extension
point="org.eclipse.cdt.ui.CElementFilters">
<filter
selected="true"
pattern=".*">
</filter>
<filter
selected="false"
pattern="*.o">
</filter>
<filter
selected="false"
pattern="*.so">
</filter>
<filter
selected="false"
pattern="*.a">
</filter>
<filter
selected="false"
pattern="Makefile">
</filter>
<filter
selected="false"
pattern="*.h">
</filter>
</extension>
<extension
point="org.eclipse.ui.perspectives">
<perspective
name="%perspective.name"
icon="icons/full/cview16/c_pers.gif"
class="org.eclipse.cdt.internal.ui.CPerspectiveFactory"
id="org.eclipse.cdt.ui.CPerspective">
</perspective>
</extension>
<extension
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.ui.resourcePerspective">
<perspectiveShortcut
id="org.eclipse.cdt.ui.CPerspective">
</perspectiveShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.debug.ui.DebugPerspective">
<perspectiveShortcut
id="org.eclipse.cdt.ui.CPerspective">
</perspectiveShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.cdt.ui.CPerspective">
<perspectiveShortcut
id="org.eclipse.cdt.ui.CPerspective">
</perspectiveShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.cdt.ui.CPerspective">
<perspectiveShortcut
id="org.eclipse.debug.ui.DebugPerspective">
</perspectiveShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.cdt.ui.CPerspective">
<perspectiveShortcut
id="org.eclipse.vcm.ui.vcmPerspective">
</perspectiveShortcut>
</perspectiveExtension>
</extension>
<extension
point="org.eclipse.ui.projectNatureImages">
<image
icon="icons/full/ovr16/c_ovr.gif"
natureId="org.eclipse.cdt.cnature"
id="org.eclipse.cdt.cProjectNatureImage">
</image>
</extension>
<extension
point="org.eclipse.ui.views">
<category
name="%viewsCategory.name"
id="org.eclipse.cdt.ui.views">
</category>
<view
name="%BuildConsoleView.name"
icon="icons/full/cview16/buildconsole.gif"
category="org.eclipse.cdt.ui.views"
class="org.eclipse.cdt.internal.ui.BuildConsoleView"
id="org.eclipse.cdt.ui.BuildConsoleView">
</view>
<view
name="%CView.name"
icon="icons/full/cview16/cview.gif"
category="org.eclipse.cdt.ui.views"
class="org.eclipse.cdt.internal.ui.cview.CView"
id="org.eclipse.cdt.ui.CView">
</view>
</extension>
<!-- For C Wizards -->
<!-- The wizards -->
<extension
point="org.eclipse.ui.newWizards">
<category
name="%newCWizardsCategory.name"
id="org.eclipse.cdt.ui.newCWizards">
</category>
<wizard
name="%StdCWizard.name"
icon="icons/full/ctool16/newc_app.gif"
category="org.eclipse.cdt.ui.newCWizards"
class="org.eclipse.cdt.ui.wizards.StdCWizard"
project="true"
finalPerspective="org.eclipse.cdt.ui.CPerspective"
id="org.eclipse.cdt.ui.wizards.StdCWizard">
<description>
%StdCWizard.description
</description>
</wizard>
<!-- For C++ Wizards -->
<category
name="%newCCWizardsCategory.name"
id="org.eclipse.cdt.ui.newCCWizards">
</category>
<wizard
name="%StdCCWizard.name"
icon="icons/full/ctool16/newcc_app.gif"
category="org.eclipse.cdt.ui.newCCWizards"
class="org.eclipse.cdt.ui.wizards.StdCCWizard"
project="true"
finalPerspective="org.eclipse.cdt.ui.CPerspective"
id="org.eclipse.cdt.ui.wizards.StdCCWizard">
<description>
%StdCCWizard.description
</description>
</wizard>
</extension>
<extension
id="org.eclipse.cdt.ui.ceditor"
point="org.eclipse.ui.editors">
<editor
name="%CEditor.name"
icon="icons/full/obj16/c_file_obj.gif"
extensions="c, h, cc, hh, cpp, cxx"
contributorClass="org.eclipse.cdt.internal.ui.editor.CEditorActionContributor"
class="org.eclipse.cdt.internal.ui.editor.CEditor"
id="org.eclipse.cdt.ui.editor.CEditor">
</editor>
<editor
name="%Editors.DefaultTextEditor"
icon="icons/full/obj16/file_obj.gif"
extensions="mk"
contributorClass="org.eclipse.ui.texteditor.BasicTextEditorActionContributor"
class="org.eclipse.ui.editors.text.TextEditor"
id="org.eclipse.ui.DefaultTextEditor">
</editor>
<editor
name="%AsmEditor.name"
icon="icons/full/obj16/c_file_obj.gif"
extensions="s"
class="org.eclipse.cdt.internal.ui.editor.asm.AsmTextEditor"
id="org.eclipse.cdt.ui.editor.asm.AsmEditor">
</editor>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
<page
name="%CPluginPreferencePage.name"
class="org.eclipse.cdt.internal.ui.preferences.CPluginPreferencePage"
id="org.eclipse.cdt.ui.preferences.CPluginPreferencePage">
</page>
<page
name="%CPluginEditorPreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.CEditorPreferencePage"
id="org.eclipse.cdt.ui.preferences.CEditorPreferencePage">
</page>
<page
name="%CPluginTemplatePreferencePage.name"
category="org.eclipse.cdt.ui.preferences.CPluginPreferencePage"
class="org.eclipse.cdt.internal.ui.preferences.TemplatePreferencePage"
id="org.eclipse.cdt.ui.preferences.TemplatePreferencePage">
</page>
</extension>
<extension
point="org.eclipse.ui.propertyPages">
<page
objectClass="org.eclipse.core.resources.IProject"
name="%CProjectPropertyPage.name"
class="org.eclipse.cdt.internal.ui.preferences.CProjectPropertyPage"
id="org.eclipse.cdt.ui.preferences.CProjectPropertyPage">
<filter
name="nature"
value="org.eclipse.cdt.core.cnature">
</filter>
</page>
</extension>
<!--
<extension
point="org.eclipse.debug.core.launchers">
<launcher
label="%CApplicationLauncher.label"
description="%CApplicationLauncher.description"
wizard="org.eclipse.cdt.internal.ui.wizards.CLaunchWizard"
modes="run"
class="org.eclipse.cdt.internal.core.CApplicationLauncher"
labelProvider="org.eclipse.cdt.internal.ui.CElementLabelProvider"
id="org.eclipse.cdt.core.CApplicationLauncher">
</launcher>
</extension>
-->
<!--
<page
objectClass="org.eclipse.core.resources.IFile"
name="%CLaunchingPropertyPage.executionArguments.name"
class="org.eclipse.cdt.internal.ui.preferences.CLaunchingPropertyPage"
id="org.eclipse.cdt.ui.preferences.CLaunchingPropertyPage">
</page>
-->
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.cdt.core.model.ICElement"
id="org.eclipse.cdt.ui.compare.CElementContributions">
<menu
label="%CompareWithMenu.label"
path="additions"
id="compareWithMenu">
<separator
name="compareWithGroup">
</separator>
</menu>
<action
label="%CompareWithEachOtherAction.label"
tooltip="%CompareWithEachOtherAction.tooltip"
class="org.eclipse.compare.internal.CompareAction"
menubarPath="compareWithMenu/compareWithGroup"
enablesFor="2+"
id="org.eclipse.cdt.ui.actions.CompareWithEachOther">
</action>
</objectContribution>
<objectContribution
objectClass="org.eclipse.cdt.core.model.ICElement"
id="org.eclipse.cdt.ui.compare.CompilationUnitContributions">
<menu
label="%ReplaceWithMenu.label"
path="additions"
id="replaceWithMenu">
<separator
name="replaceWithGroup">
</separator>
</menu>
<action
label="%ReplaceFromHistoryAction.label"
tooltip="%ReplaceFromHistoryAction.tooltip"
class="org.eclipse.compare.internal.ReplaceWithEditionAction"
menubarPath="replaceWithMenu/replaceWithGroup"
enablesFor="1"
id="org.eclipse.cdt.ui.actions.ReplaceFromHistory">
</action>
<action
label="%CompareWithHistoryAction.label"
tooltip="%CompareWithHistoryAction.tooltip"
class="org.eclipse.compare.internal.CompareWithEditionAction"
menubarPath="compareWithMenu/compareWithGroup"
enablesFor="1"
id="compareWithHistory">
</action>
</objectContribution>
</extension>
<extension
point="org.eclipse.compare.structureCreators">
<structureCreator
extensions="c,cc,cpp,cxx,h"
class="org.eclipse.cdt.internal.ui.compare.CStructureCreator">
</structureCreator>
</extension>
<extension
point="org.eclipse.compare.contentMergeViewers">
<viewer
extensions="c,cc,cpp,cxx,h,c2"
class="org.eclipse.cdt.internal.ui.compare.CContentViewerCreator">
</viewer>
</extension>
<extension
point="org.eclipse.ui.actionSets">
<actionSet
label="%CFolderActionSet.label"
description="%CFolderActionSet.description"
visible="false"
id="org.eclipse.cdt.ui.CFolderActionSet">
<action
label="%OpenNewFileWizardAction.label"
icon="icons/full/ctool16/newfile_wiz.gif"
tooltip="%OpenNewFileWizardAction.tooltip"
class="org.eclipse.cdt.internal.ui.wizards.OpenNewFileWizardAction"
toolbarPath="Normal/FolderWizards"
id="org.eclipse.cdt.ui.actions.OpenNewFileWizardAction">
</action>
<action
label="%OpenNewFolderWizardAction.label"
icon="icons/full/ctool16/newfolder_wiz.gif"
tooltip="%OpenNewFolderWizardAction.tooltip"
class="org.eclipse.cdt.internal.ui.wizards.OpenNewFolderWizardAction"
toolbarPath="Normal/FolderWizards"
id="org.eclipse.cdt.ui.actions.OpenNewFolderWizardAction">
</action>
</actionSet>
</extension>
<!-- Wizards ToolBar buttons -->
<extension
point="org.eclipse.ui.views">
<view
name="%MakeView.name"
icon="icons/full/obj16/build_menu.gif"
category="org.eclipse.cdt.ui.views"
class="org.eclipse.cdt.internal.ui.makeview.MakeView"
id="org.eclipse.cdt.ui.MakeView">
</view>
</extension>
<extension
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.resources.IMarker"
id="org.eclipse.cdt.ui.action.DeleteTaskAction">
<filter
name="type"
value="org.eclipse.cdt.core.problem">
</filter>
<action
label="%DeleteTaskAction.label"
icon="icons/full/ovr16/error_co.gif"
class="org.eclipse.cdt.internal.ui.util.DeleteTaskAction"
menubarPath="additions"
enablesFor="+"
id="org.eclipse.cdt.ui.action.DeleteTaskAction">
</action>
</objectContribution>
</extension>
<!-- =========================================================================== -->
<!-- Debug Model Presentation -->
<!-- =========================================================================== -->
<extension
point="org.eclipse.debug.ui.debugModelPresentations">
<debugModelPresentation
class="org.eclipse.cdt.core.debug.ui.CDebugModelPresentation"
id="org.eclipse.cdt.ui">
</debugModelPresentation>
</extension>
</plugin>

View file

@ -0,0 +1,42 @@
package org.eclipse.cdt.internal.core;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
/**
* Input stream which reads from a document
*/
public class DocumentInputStream extends InputStream {
private IDocument fDocument;
private int fCurrPos;
public DocumentInputStream(IDocument document) {
fDocument= document;
fCurrPos= 0;
}
public IDocument getDocument() {
return fDocument;
}
/**
* @see InputStream#read
*/
public int read() throws IOException {
try {
if (fCurrPos < fDocument.getLength()) {
return fDocument.getChar(fCurrPos++);
}
} catch (BadLocationException e) {
}
return -1;
}
}

View file

@ -0,0 +1,167 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.textmanipulation.MultiTextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.NopTextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.SimpleTextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.TextBuffer;
import org.eclipse.cdt.internal.corext.textmanipulation.TextBufferEditor;
import org.eclipse.cdt.internal.corext.textmanipulation.TextEdit;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import org.eclipse.core.runtime.CoreException;
/**
* A context type is a context factory.
*/
public abstract class ContextType implements ITemplateEditor {
/** name of the context type */
private final String fName;
/** variables used by this content type */
private final Map fVariables= new HashMap();
/**
* Creates a context type with a name.
*
* @param name the name of the context. It has to be unique wrt to other context names.
*/
public ContextType(String name) {
fName= name;
}
/**
* Returns the name of the context type.
*/
public String getName() {
return fName;
}
/**
* Adds a template variable to the context type.
*/
public void addVariable(TemplateVariable variable) {
fVariables.put(variable.getName(), variable);
}
/**
* Removes a template variable from the context type.
*/
public void removeVariable(TemplateVariable variable) {
fVariables.remove(variable.getName());
}
/**
* Removes all template variables from the context type.
*/
public void removeAllVariables() {
fVariables.clear();
}
/**
* Returns an iterator for the variables known to the context type.
*/
public Iterator variableIterator() {
return fVariables.values().iterator();
}
/**
* Creates a template context.
*/
public abstract TemplateContext createContext();
/*
* @see ITemplateEditor#edit(TemplateBuffer)
*/
public void edit(TemplateBuffer templateBuffer, TemplateContext context) throws CoreException {
TextBuffer textBuffer= TextBuffer.create(templateBuffer.getString());
TemplatePosition[] variables= templateBuffer.getVariables();
MultiTextEdit positions= variablesToPositions(variables);
MultiTextEdit multiEdit= new MultiTextEdit();
// iterate over all variables and try to resolve them
for (int i= 0; i != variables.length; i++) {
TemplatePosition variable= variables[i];
if (variable.isResolved())
continue;
String name= variable.getName();
int[] offsets= variable.getOffsets();
int length= variable.getLength();
TemplateVariable evaluator= (TemplateVariable) fVariables.get(name);
String value= (evaluator == null)
? null
: evaluator.evaluate(context);
if (value == null)
continue;
variable.setLength(value.length());
variable.setResolved(evaluator.isResolved(context));
for (int k= 0; k != offsets.length; k++)
multiEdit.add(SimpleTextEdit.createReplace(offsets[k], length, value));
}
TextBufferEditor editor= new TextBufferEditor(textBuffer);
editor.add(positions);
editor.add(multiEdit);
editor.performEdits(null);
positionsToVariables(positions, variables);
templateBuffer.setContent(textBuffer.getContent(), variables);
}
private static MultiTextEdit variablesToPositions(TemplatePosition[] variables) {
MultiTextEdit positions= new MultiTextEdit();
for (int i= 0; i != variables.length; i++) {
int[] offsets= variables[i].getOffsets();
for (int j= 0; j != offsets.length; j++)
positions.add(new NopTextEdit(offsets[j], 0));
}
return positions;
}
private static void positionsToVariables(MultiTextEdit positions, TemplatePosition[] variables) {
Iterator iterator= positions.iterator();
for (int i= 0; i != variables.length; i++) {
TemplatePosition variable= variables[i];
int[] offsets= new int[variable.getOffsets().length];
for (int j= 0; j != offsets.length; j++)
offsets[j]= ((TextEdit) iterator.next()).getTextRange().getOffset();
variable.setOffsets(offsets);
}
}
/**
* Returns the templates associated with this context type.
*/
public Template[] getTemplates() {
Template[] templates= Templates.getInstance().getTemplates();
Vector vector= new Vector();
for (int i= 0; i != templates.length; i++)
if (templates[i].getContextTypeName().equals(fName))
vector.add(templates[i]);
return (Template[]) vector.toArray(new Template[vector.size()]);
}
}

View file

@ -0,0 +1,69 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.c.CContextType;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* A singleton to keep track of all known context types.
*/
public class ContextTypeRegistry {
/** the singleton */
private static ContextTypeRegistry fInstance;
/** all known context types */
private final Map fContextTypes= new HashMap();
/**
* Returns the single instance of this class.
*/
public static ContextTypeRegistry getInstance() {
if (fInstance == null)
fInstance= new ContextTypeRegistry();
return fInstance;
}
/**
* Adds a context type to the registry.
*/
public void add(ContextType contextType) {
fContextTypes.put(contextType.getName(), contextType);
}
/**
* Removes a context type from the registry.
*/
public void remove(ContextType contextType) {
fContextTypes.remove(contextType.getName());
}
/**
* Returns the context type if the name is valid, <code>null</code> otherwise.
*/
public ContextType getContextType(String name) {
return (ContextType) fContextTypes.get(name);
}
/**
* Returns an iterator over the registered context type names.
*/
public Iterator iterator() {
return fContextTypes.keySet().iterator();
}
// XXX bootstrap with C and C++ types
private ContextTypeRegistry() {
add(new CContextType());
//add(new CppContextType());
}
}

View file

@ -0,0 +1,70 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.jface.util.Assert;
/**
* A typical text based document template context.
*/
public abstract class DocumentTemplateContext extends TemplateContext {
/** The text of the document. */
private final String fString;
/** The completion position. */
private final int fCompletionPosition;
/**
* Creates a document template context.
*/
protected DocumentTemplateContext(ContextType type, String string, int completionPosition) {
super(type);
Assert.isNotNull(string);
Assert.isTrue(completionPosition >= 0 && completionPosition <= string.length());
fString= string;
fCompletionPosition= completionPosition;
}
/**
* Returns the string of the context.
*/
public String getString() {
return fString;
}
/**
* Returns the completion position within the string of the context.
*/
public int getCompletionPosition() {
return fCompletionPosition;
}
/**
* Returns the keyword which triggered template insertion.
*/
public String getKey() {
return fString.substring(getStart(), getEnd());
}
/**
* Returns the beginning offset of the keyword.
*/
public int getStart() {
return fCompletionPosition;
}
/**
* Returns the end offset of the keyword.
*/
public int getEnd() {
return fCompletionPosition;
}
}

View file

@ -0,0 +1,24 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.core.runtime.CoreException;
/**
* A template editor implements an action to edit a template buffer in its context.
*/
public interface ITemplateEditor {
/**
* Modifies a template buffer.
*
* @param buffer the template buffer
* @param context the template context
* @throws CoreException if the buffer cannot be successfully modified
*/
void edit(TemplateBuffer buffer, TemplateContext context) throws CoreException;
}

View file

@ -0,0 +1,55 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
/**
* A simple template variable, which always evaluates to a defined string.
*/
public class SimpleTemplateVariable extends TemplateVariable {
/** The string to which this variable evaluates. */
private String fEvaluationString;
/** A flag indicating if this variable can be resolved. */
private boolean fResolved;
/*
* @see TemplateVariable#TemplateVariable(String, String)
*/
protected SimpleTemplateVariable(String name, String description) {
super(name, description);
}
/**
* Sets the string to which this variable evaluates.
*
* @param evaluationString the evaluation string, may be <code>null</code>.
*/
public final void setEvaluationString(String evaluationString) {
fEvaluationString= evaluationString;
}
/*
* @see TemplateVariable#evaluate(TemplateContext)
*/
public String evaluate(TemplateContext context) {
return fEvaluationString;
}
/**
* Sets the resolved flag.
*/
public final void setResolved(boolean resolved) {
fResolved= resolved;
}
/*
* @see TemplateVariable#isResolved(TemplateContext)
*/
public boolean isResolved(TemplateContext context) {
return fResolved;
}
}

View file

@ -0,0 +1,160 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
/**
* A template consiting of a name and a pattern.
*/
public class Template {
/** The name of this template */
private String fName;
/** A description of this template */
private String fDescription;
/** The name of the context type of this template */
private String fContextTypeName;
/** The template pattern. */
private String fPattern;
/** A flag indicating if the template is active or not. */
private boolean fEnabled= true;
/**
* Creates an empty template.
*/
public Template() {
this("", "", "", ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
/**
* Creates a copy of a template.
*/
public Template(Template template) {
this(template.getName(), template.getDescription(), template.getContextTypeName(), template.getPattern());
}
/**
* Creates a template.
*
* @param name the name of the template.
* @param description the description of the template.
* @param contextTypeName the name of the context type in which the template can be applied.
* @param pattern the template pattern.
*/
public Template(String name, String description, String contextTypeName, String pattern) {
fName= name;
fDescription= description;
fContextTypeName= contextTypeName;
fPattern= pattern;
}
/*
* @see Object#equals(Object)
*/
public boolean equals(Object object) {
if (!(object instanceof Template))
return false;
Template template= (Template) object;
if (template == this)
return true;
return
template.fName.equals(fName) &&
template.fPattern.equals(fPattern) &&
template.fContextTypeName.equals(fContextTypeName);
}
/*
* @see Object#hashCode()
*/
public int hashCode() {
return fName.hashCode() ^ fPattern.hashCode() ^ fContextTypeName.hashCode();
}
/**
* Sets the description of the template.
*/
public void setDescription(String description) {
fDescription= description;
}
/**
* Returns the description of the template.
*/
public String getDescription() {
return fDescription;
}
/**
* Sets the name of the context type in which the template can be applied.
*/
public void setContext(String contextTypeName) {
fContextTypeName= contextTypeName;
}
/**
* Returns the name of the context type in which the template can be applied.
*/
public String getContextTypeName() {
return fContextTypeName;
}
/**
* Sets the name of the template.
*/
public void setName(String name) {
fName= name;
}
/**
* Returns the name of the template.
*/
public String getName() {
return fName;
}
/**
* Sets the pattern of the template.
*/
public void setPattern(String pattern) {
fPattern= pattern;
}
/**
* Returns the template pattern.
*/
public String getPattern() {
return fPattern;
}
/**
* Sets the enable state of the template.
*/
public void setEnabled(boolean enable) {
fEnabled= enable;
}
/**
* Returns <code>true</code> if template is enabled, <code>false</code> otherwise.
*/
public boolean isEnabled() {
return fEnabled;
}
/**
* Returns <code>true</code> if template matches the prefix and context,
* <code>false</code> otherwise.
*/
public boolean matches(String prefix, String contextTypeName) {
return
fEnabled &&
fContextTypeName.equals(contextTypeName) &&
(prefix.length() != 0) &&
fName.toLowerCase().startsWith(prefix.toLowerCase());
}
}

View file

@ -0,0 +1,64 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.util.Assert;
/**
* A template buffer is a container for a string and variables.
*/
public final class TemplateBuffer {
/** The string of the template buffer */
private String fString;
/** The variable positions of the template buffer */
private TemplatePosition[] fVariables;
/**
* Creates a template buffer.
*
* @param string the string
* @param variables the variable positions
* @throws CoreException for illegal variable positions
*/
public TemplateBuffer(String string, TemplatePosition[] variables) throws CoreException {
setContent(string, variables);
}
/**
* Sets the content of the template buffer.
*
* @param string the string
* @param variables the variable positions
* @throws CoreException for illegal variable positions
*/
public final void setContent(String string, TemplatePosition[] variables) throws CoreException {
Assert.isNotNull(string);
Assert.isNotNull(variables);
// XXX assert non-overlapping variable properties
fString= string;
fVariables= variables;
}
/**
* Returns the string of the template buffer.
*/
public final String getString() {
return fString;
}
/**
* Returns the variable positions of the template buffer.
*/
public final TemplatePosition[] getVariables() {
return fVariables;
}
}

View file

@ -0,0 +1,42 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.core.runtime.CoreException;
/**
* A template context. A template context is associated with a context type.
*/
public abstract class TemplateContext {
/** context type of this context */
private final ContextType fContextType;
/**
* Creates a template context of a particular context type.
*/
protected TemplateContext(ContextType contextType) {
fContextType= contextType;
}
/**
* Returns the context type of this context.
*/
public ContextType getContextType() {
return fContextType;
}
/**
* Evaluates the template and returns a template buffer.
*/
public abstract TemplateBuffer evaluate(Template template) throws CoreException;
/**
* Tests if the specified template can be evaluated in this context.
*/
public abstract boolean canEvaluate(Template template);
}

View file

@ -0,0 +1,44 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class TemplateMessages {
private static final String RESOURCE_BUNDLE= TemplateMessages.class.getName();
private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
private TemplateMessages() {
}
public static String getString(String key) {
try {
return fgResourceBundle.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
/**
* Gets a string from the resource bundle and formats it with the argument
*
* @param key the string used to get the bundle value, must not be null
*/
public static String getFormattedString(String key, Object arg) {
return MessageFormat.format(getString(key), new Object[] { arg });
}
/**
* Gets a string from the resource bundle and formats it with arguments
*/
public static String getFormattedString(String key, Object[] args) {
return MessageFormat.format(getString(key), args);
}
}

View file

@ -0,0 +1,106 @@
#########################################
# (c) Copyright IBM Corp. 2000, 2001.
# All Rights Reserved.
#########################################
# preference page
TemplatePreferencePage.error.import=Failed to import templates.
TemplatePreferencePage.error.export=Failed to export templates.
TemplatePreferencePage.error.read.title=Reading Templates
TemplatePreferencePage.error.write.title=Reading Templates
TemplatePreferencePage.message=&Create, edit or remove templates:
TemplatePreferencePage.title=Templates
TemplatePreferencePage.new=&New...
TemplatePreferencePage.edit=&Edit...
TemplatePreferencePage.import=&Import...
TemplatePreferencePage.export=E&xport...
TemplatePreferencePage.export.all=Ex&port All...
TemplatePreferencePage.remove=&Remove
TemplatePreferencePage.enable.all=Ena&ble All
TemplatePreferencePage.disable.all=Di&sable All
TemplatePreferencePage.editor=Template
TemplatePreferencePage.column.name=Name
TemplatePreferencePage.column.context=Context
TemplatePreferencePage.column.description=Description
TemplatePreferencePage.use.code.formatter=Use Code &Formatter
TemplatePreferencePage.import.title=Importing Templates
TemplatePreferencePage.import.extension=*.xml
TemplatePreferencePage.export.title=Exporting {0} Templates
TemplatePreferencePage.export.filename=templates.xml
TemplatePreferencePage.export.extension=*.xml
TemplatePreferencePage.export.exists.title=Exporting Templates
TemplatePreferencePage.export.message={0} already exists.\nDo you want to replace it?
TemplatePreferencePage.question.create.new.title=Edit Template
TemplatePreferencePage.question.create.new.message=The name of the template was changed.\nDo you want to create a new template?
# edit template dialog
EditTemplateDialog.error.noname=Template name must not be empty.
EditTemplateDialog.error.adjacent.variables=Template pattern has adjacent variables.
EditTemplateDialog.title.new=New Template
EditTemplateDialog.title.edit=Edit Template
EditTemplateDialog.name=&Name:
EditTemplateDialog.description=&Description:
EditTemplateDialog.context=&Context:
EditTemplateDialog.pattern=&Pattern:
EditTemplateDialog.insert.variable=Insert &Variable...
EditTemplateDialog.undo=&Undo@Ctrl+Z
EditTemplateDialog.cut=Cu&t@Ctrl+X
EditTemplateDialog.copy=&Copy@Ctrl+C
EditTemplateDialog.paste=&Paste@Ctrl+V
EditTemplateDialog.select.all=Select &All@Ctrl+A
EditTemplateDialog.content.assist=Insert &Variable...@Ctrl+Space
# template variable dialog
TemplateVariableDialog.title=Select a template variable.
TemplateVariableDialog.column.name=Name
TemplateVariableDialog.column.description=Description
TemplateVariableDialog.insert=&Insert
TemplateVariableProposal.error.title=Error applying template variable proposal
TemplateVariableProcessor.error.title=Error creating template variable proposals
# template set
TemplateSet.error.read=Error occured while reading templates.
TemplateSet.error.write=Error occured while writing templates.
# templates
Templates.error.title=Error accessing templates.
Templates.error.read=Error occured while reading templates.
Templates.error.write=Error occured while writing templates.
# template engine
TemplateEngine.error.title=Could not create template proposals.
# template proposal
TemplateProposal.delimiter=\ -
# template evaluator
TemplateEvaluator.error.title=Template Evaluation Error
# template collector
TemplateCollector.variable.description.file=Filename of compilation unit
TemplateCollector.variable.description.line=Current line number
TemplateCollector.variable.description.date=Current date
TemplateCollector.variable.description.time=Current time
TemplateCollector.variable.description.user=User name
TemplateCollector.variable.description.array=A proposal for an array
TemplateCollector.variable.description.array.type=A proposal for the element type of an array
TemplateCollector.variable.description.array.element=A proposal for the element name of an array
TemplateCollector.variable.description.index=A proposal for an index (int)
TemplateCollector.variable.description.collector=A proposal for a collector (java.util.Collector)
TemplateCollector.variable.description.iterator=A proposal for an iterator (java.util.Iterator)
TemplateCollector.variable.description.return.type=Return type (evaluates to void)
TemplateCollector.variable.description.arguments=Method arguments (evaluates to empty string)
# template translator
TemplateTranslator.error.incomplete.variable=Template has incomplete variables.
TemplateTranslator.error.invalid.identifier=Template has invalid variable identifiers.

View file

@ -0,0 +1,97 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
/**
*
*/
public class TemplatePosition {
/** The name of the template position */
private final String fName;
/** The default value of the template position */
private final String fDefaultValue;
/** The length of the template positions. */
private int fLength;
/** The offsets of the template positions. */
private int[] fOffsets;
/** A flag indicating if the template position has been resolved. */
private boolean fResolved;
/**
* Creates a template position.
*
* @param name the name of the template position.
* @param defaultValue the default value of the position.
* @param offsets the array of offsets of the position.
* @param the length of the position.
*/
public TemplatePosition(String name, String defaultValue, int[] offsets, int length) {
fName= name;
fDefaultValue= defaultValue;
fOffsets= offsets;
fLength= length;
fResolved= false;
}
/**
* Returns the name of the position.
*/
public String getName() {
return fName;
}
/**
* Returns the default value of the position.
*/
public String getDefaultValue() {
return fDefaultValue;
}
/**
* Sets the length of the position.
*/
public void setLength(int length) {
fLength= length;
}
/**
* Returns the length of the position.
*/
public int getLength() {
return fLength;
}
/**
* Sets the offsets of the position.
*/
public void setOffsets(int[] offsets) {
fOffsets= offsets;
}
/**
* Returns the offsets of the position.
*/
public int[] getOffsets() {
return fOffsets;
}
/**
* Sets the resolved flag of the position.
*/
public void setResolved(boolean resolved) {
fResolved= resolved;
}
/**
* Returns <code>true</code> if the position is resolved, <code>false</code> otherwise.
*/
public boolean isResolved() {
return fResolved;
}
}

View file

@ -0,0 +1,295 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.ui.CStatusConstants;
import org.eclipse.cdt.internal.ui.CUIException;
import org.eclipse.cdt.internal.ui.CUIStatus;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.Serializer;
import org.apache.xml.serialize.SerializerFactory;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* <code>TemplateSet</code> manages a collection of templates and makes them
* persistent.
*/
public class TemplateSet {
private static class TemplateComparator implements Comparator {
public int compare(Object arg0, Object arg1) {
if (arg0 == arg1)
return 0;
if (arg0 == null)
return -1;
Template template0= (Template) arg0;
Template template1= (Template) arg1;
return template0.getName().compareTo(template1.getName());
}
}
private static final String TEMPLATE_TAG= "template"; //$NON-NLS-1$
private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
private static final String CONTEXT_ATTRIBUTE= "context"; //$NON-NLS-1$
private static final String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$
private List fTemplates= new ArrayList();
private Comparator fTemplateComparator= new TemplateComparator();
private Template[] fSortedTemplates= new Template[0];
/**
* Convenience method for reading templates from a file.
*
* @see addFromStream(InputStream)
*/
public void addFromFile(File file) throws CoreException {
InputStream stream= null;
try {
stream= new FileInputStream(file);
addFromStream(stream);
} catch (IOException e) {
throwReadException(e);
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException e) {}
}
}
/**
* Reads templates from a XML stream and adds them to the template set.
*/
public void addFromStream(InputStream stream) throws CoreException {
try {
DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
DocumentBuilder parser= factory.newDocumentBuilder();
Document document= parser.parse(new InputSource(stream));
NodeList elements= document.getElementsByTagName(TEMPLATE_TAG);
int count= elements.getLength();
for (int i= 0; i != count; i++) {
Node node= elements.item(i);
NamedNodeMap attributes= node.getAttributes();
if (attributes == null)
continue;
String name= getAttributeValue(attributes, NAME_ATTRIBUTE);
String description= getAttributeValue(attributes, DESCRIPTION_ATTRIBUTE);
String context= getAttributeValue(attributes, CONTEXT_ATTRIBUTE);
Node enabledNode= attributes.getNamedItem(ENABLED_ATTRIBUTE);
if (name == null || description == null || context == null)
throw new SAXException("Missing required attribute");
boolean enabled= (enabledNode == null) || (enabledNode.getNodeValue().equals("true")); //$NON-NLS-1$
StringBuffer buffer= new StringBuffer();
NodeList children= node.getChildNodes();
for (int j= 0; j != children.getLength(); j++) {
String value= children.item(j).getNodeValue();
if (value != null)
buffer.append(value);
}
String pattern= buffer.toString().trim();
Template template= new Template(name, description, context, pattern);
template.setEnabled(enabled);
add(template);
}
sort();
} catch (ParserConfigurationException e) {
throwReadException(e);
} catch (IOException e) {
throwReadException(e);
} catch (SAXException e) {
throwReadException(e);
}
}
private String getAttributeValue(NamedNodeMap attributes, String name) {
Node node= attributes.getNamedItem(name);
return node == null
? null
: node.getNodeValue();
}
/**
* Convenience method for saving to a file.
*
* @see saveToStream(OutputStream)
*/
public void saveToFile(File file) throws CoreException {
OutputStream stream= null;
try {
stream= new FileOutputStream(file);
saveToStream(stream);
} catch (IOException e) {
throwWriteException(e);
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException e) {}
}
}
/**
* Saves the template set as XML.
*/
public void saveToStream(OutputStream stream) throws CoreException {
try {
DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
DocumentBuilder builder= factory.newDocumentBuilder();
Document document= builder.newDocument();
Node root= document.createElement("templates"); // $NON-NLS-1$ //$NON-NLS-1$
document.appendChild(root);
for (int i= 0; i != fTemplates.size(); i++) {
Template template= (Template) fTemplates.get(i);
Node node= document.createElement("template"); // $NON-NLS-1$ //$NON-NLS-1$
root.appendChild(node);
NamedNodeMap attributes= node.getAttributes();
Attr name= document.createAttribute(NAME_ATTRIBUTE);
name.setValue(template.getName());
attributes.setNamedItem(name);
Attr description= document.createAttribute(DESCRIPTION_ATTRIBUTE);
description.setValue(template.getDescription());
attributes.setNamedItem(description);
Attr context= document.createAttribute(CONTEXT_ATTRIBUTE);
context.setValue(template.getContextTypeName());
attributes.setNamedItem(context);
Attr enabled= document.createAttribute(ENABLED_ATTRIBUTE);
enabled.setValue(template.isEnabled() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
attributes.setNamedItem(enabled);
Text pattern= document.createTextNode(template.getPattern());
node.appendChild(pattern);
}
OutputFormat format = new OutputFormat();
format.setPreserveSpace(true);
Serializer serializer = SerializerFactory.getSerializerFactory("xml").makeSerializer(stream, format); //$NON-NLS-1$
serializer.asDOMSerializer().serialize(document);
} catch (ParserConfigurationException e) {
throwWriteException(e);
} catch (IOException e) {
throwWriteException(e);
}
}
private static void throwReadException(Throwable t) throws CoreException {
IStatus status= new CUIStatus(CStatusConstants.TEMPLATE_IO_EXCEPTION,
TemplateMessages.getString("TemplateSet.error.read"), t); //$NON-NLS-1$
throw new CUIException(status);
}
private static void throwWriteException(Throwable t) throws CoreException {
IStatus status= new CUIStatus(CStatusConstants.TEMPLATE_IO_EXCEPTION,
TemplateMessages.getString("TemplateSet.error.write"), t); //$NON-NLS-1$
throw new CUIException(status);
}
/**
* Adds a template to the set.
*/
public void add(Template template) {
if (exists(template))
return; // ignore duplicate
fTemplates.add(template);
sort();
}
private boolean exists(Template template) {
for (Iterator iterator = fTemplates.iterator(); iterator.hasNext();) {
Template anotherTemplate = (Template) iterator.next();
if (template.equals(anotherTemplate))
return true;
}
return false;
}
/**
* Removes a template to the set.
*/
public void remove(Template template) {
fTemplates.remove(template);
sort();
}
/**
* Empties the set.
*/
public void clear() {
fTemplates.clear();
sort();
}
/**
* Returns all templates.
*/
public Template[] getTemplates() {
return (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
}
private void sort() {
fSortedTemplates= (Template[]) fTemplates.toArray(new Template[fTemplates.size()]);
Arrays.sort(fSortedTemplates, fTemplateComparator);
}
}

View file

@ -0,0 +1,215 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import org.eclipse.core.runtime.CoreException;
/**
* The template translator translates a string into a template buffer.
* The EBNF grammer of a valid string is as follows:
*
* <p>
* template := (text | escape)*.<br />
* text := character - dollar.<br />
* escape := dollar ('{' identifier '}' | dollar).<br />
* dollar := '$'.<br />
* </p>
*/
public class TemplateTranslator {
// states
private static final int TEXT= 0;
private static final int ESCAPE= 1;
private static final int IDENTIFIER= 2;
// tokens
private static final char ESCAPE_CHARACTER= '$';
private static final char IDENTIFIER_BEGIN= '{';
private static final char IDENTIFIER_END= '}';
/** a buffer for the translation result string */
private final StringBuffer fBuffer= new StringBuffer();
/** position offsets of variables */
private final Vector fOffsets= new Vector();
/** position lengths of variables */
private final Vector fLengths= new Vector();
/** the current parsing state */
private int fState;
/** the last translation error */
private String fErrorMessage;
/**
* Returns an error message if an error occured for the last translation, <code>null</code>
* otherwise.
*/
public String getErrorMessage() {
return fErrorMessage;
}
/**
* Translates a template string to <code>TemplateBuffer</code>. <code>null</code>
* is returned if there was an error. <code>getErrorMessage()</code> retrieves the
* associated error message.
*
* @param string the string to translate.
* @return returns the template buffer corresponding to the string, <code>null</code>
* if there was an error.
* @see getErrorMessage()
*/
public TemplateBuffer translate(String string) throws CoreException {
fBuffer.setLength(0);
fOffsets.clear();
fLengths.clear();
fState= TEXT;
fErrorMessage= null;
if (!parse(string))
return null;
switch (fState) {
case TEXT:
break;
// illegal, but be tolerant
case ESCAPE:
fErrorMessage= TemplateMessages.getString("TemplateTranslator.error.incomplete.variable"); //$NON-NLS-1$
fBuffer.append(ESCAPE_CHARACTER);
return null;
// illegal, but be tolerant
case IDENTIFIER:
fErrorMessage= TemplateMessages.getString("TemplateTranslator.error.incomplete.variable"); //$NON-NLS-1$
fBuffer.append(ESCAPE_CHARACTER);
return null;
}
int[] offsets= new int[fOffsets.size()];
int[] lengths= new int[fLengths.size()];
for (int i= 0; i < fOffsets.size(); i++) {
offsets[i]= ((Integer) fOffsets.get(i)).intValue();
lengths[i]= ((Integer) fLengths.get(i)).intValue();
}
String translatedString= fBuffer.toString();
TemplatePosition[] variables= findVariables(translatedString, offsets, lengths);
return new TemplateBuffer(translatedString, variables);
}
private static TemplatePosition[] findVariables(String string, int[] offsets, int[] lengths) {
Map map= new HashMap();
for (int i= 0; i != offsets.length; i++) {
int offset= offsets[i];
int length= lengths[i];
String content= string.substring(offset, offset + length);
Vector vector= (Vector) map.get(content);
if (vector == null) {
vector= new Vector();
map.put(content, vector);
}
vector.add(new Integer(offset));
}
TemplatePosition[] variables= new TemplatePosition[map.size()];
int k= 0;
Set keys= map.keySet();
for (Iterator i= keys.iterator(); i.hasNext(); ) {
String name= (String) i.next();
Vector vector= (Vector) map.get(name);
int[] offsets_= new int[vector.size()];
for (int j= 0; j != offsets_.length; j++)
offsets_[j]= ((Integer) vector.get(j)).intValue();
variables[k]= new TemplatePosition(name, name, offsets_, name.length());
k++;
}
return variables;
}
/** internal parser */
private boolean parse(String string) {
for (int i= 0; i != string.length(); i++) {
char ch= string.charAt(i);
switch (fState) {
case TEXT:
switch (ch) {
case ESCAPE_CHARACTER:
fState= ESCAPE;
break;
default:
fBuffer.append(ch);
break;
}
break;
case ESCAPE:
switch (ch) {
case ESCAPE_CHARACTER:
fBuffer.append(ch);
fState= TEXT;
break;
case IDENTIFIER_BEGIN:
fOffsets.add(new Integer(fBuffer.length()));
fState= IDENTIFIER;
break;
default:
// illegal single escape character, but be tolerant
fErrorMessage= TemplateMessages.getString("TemplateTranslator.error.incomplete.variable"); //$NON-NLS-1$
fBuffer.append(ESCAPE_CHARACTER);
fBuffer.append(ch);
fState= TEXT;
return false;
}
break;
case IDENTIFIER:
switch (ch) {
case IDENTIFIER_END:
int offset = ((Integer) fOffsets.get(fOffsets.size() - 1)).intValue();
fLengths.add(new Integer(fBuffer.length() - offset));
fState= TEXT;
break;
default:
if (!Character.isUnicodeIdentifierStart((char) ch) &&
!Character.isUnicodeIdentifierPart((char) ch))
{
// illegal identifier character
fErrorMessage= TemplateMessages.getString("TemplateTranslator.error.invalid.identifier"); //$NON-NLS-1$
return false;
}
fBuffer.append(ch);
break;
}
break;
}
}
return true;
}
}

View file

@ -0,0 +1,65 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
/**
* A template variable.
*/
public abstract class TemplateVariable {
/** name of the variable */
private final String fName;
/** description of the variable */
private final String fDescription;
/**
* Creates an instance of <code>TemplateVariable</code>.
*
* @param name the name of the variable
* @param description the description for the variable
*/
protected TemplateVariable(String name, String description) {
fName= name;
fDescription= description;
}
/**
* Returns the name of the variable.
*/
public String getName() {
return fName;
}
/**
* Returns the description for the variable.
*/
public String getDescription() {
return fDescription;
}
/**
* Tests if this variable can be evaluated.
*/
// public abstract boolean canEvaluate(TemplateContext context);
/**
* Evaluates this variable
*
* @return the evaluated string, or <code>null</code> if not evaluatable.
*/
public abstract String evaluate(TemplateContext context);
/**
* Returns whether this variable is resolved.
* By default, the variable is not resolved.
* Clients can overwrite this method to force resolution of the variable.
*/
public boolean isResolved(TemplateContext context) {
return false;
}
}

View file

@ -0,0 +1,96 @@
package org.eclipse.cdt.internal.corext.template;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.ui.CPlugin;
import java.io.File;
import java.io.InputStream;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.dialogs.ErrorDialog;
/**
* <code>Templates</code> gives access to the available templates.
*/
public class Templates extends TemplateSet {
private static final String DEFAULT_FILE= "default-templates.xml"; //$NON-NLS-1$
private static final String TEMPLATE_FILE= "templates.xml"; //$NON-NLS-1$
/** Singleton. */
private static Templates fgTemplates;
/**
* Returns an instance of templates.
*/
public static Templates getInstance() {
if (fgTemplates == null)
fgTemplates= create();
return fgTemplates;
}
private static Templates create() {
Templates templates= new Templates();
try {
File templateFile= getTemplateFile();
if (templateFile.exists()) {
templates.addFromFile(templateFile);
} else {
templates.addFromStream(getDefaultsAsStream());
templates.saveToFile(templateFile);
}
} catch (CoreException e) {
CPlugin.log(e);
ErrorDialog.openError(null,
TemplateMessages.getString("Templates.error.title"), //$NON-NLS-1$
e.getMessage(), e.getStatus());
templates.clear();
}
return templates;
}
/**
* Resets the template set.
*/
public void reset() throws CoreException {
clear();
addFromFile(getTemplateFile());
}
/**
* Resets the template set with the default templates.
*/
public void restoreDefaults() throws CoreException {
clear();
addFromStream(getDefaultsAsStream());
}
/**
* Saves the template set.
*/
public void save() throws CoreException {
saveToFile(getTemplateFile());
}
private static InputStream getDefaultsAsStream() {
return Templates.class.getResourceAsStream(DEFAULT_FILE);
}
private static File getTemplateFile() {
IPath path= CPlugin.getDefault().getStateLocation();
path= path.append(TEMPLATE_FILE);
return path.toFile();
}
}

View file

@ -0,0 +1,102 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.ITemplateEditor;
import org.eclipse.cdt.internal.corext.template.Template;
import org.eclipse.cdt.internal.corext.template.TemplateBuffer;
import org.eclipse.cdt.internal.corext.template.TemplateTranslator;
import org.eclipse.cdt.internal.corext.textmanipulation.TextBuffer;
import org.eclipse.cdt.internal.corext.textmanipulation.TextUtil;
import org.eclipse.cdt.internal.ui.CPlugin;
import org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration;
import org.eclipse.core.runtime.CoreException;
/**
* A context for c/c++
*/
public class CContext extends CompilationUnitContext {
/**
* Creates a javadoc template context.
*
* @param type the context type.
* @param string the document string.
* @param completionPosition the completion position within the document.
* @param unit the compilation unit (may be <code>null</code>).
*/
public CContext(ContextType type, String string, int completionPosition,
ICompilationUnit compilationUnit)
{
super(type, string, completionPosition, compilationUnit);
}
/*
* @see DocumentTemplateContext#getStart()
*/
public int getStart() {
String string= getString();
int start= getCompletionPosition();
while ((start != 0) && Character.isUnicodeIdentifierPart(string.charAt(start - 1)))
start--;
if ((start != 0) && Character.isUnicodeIdentifierStart(string.charAt(start - 1)))
start--;
return start;
}
/**
* Returns the indentation level at the position of code completion.
*/
public int getIndentationLevel() {
String string= getString();
int start= getStart();
try {
TextBuffer textBuffer= TextBuffer.create(string);
String lineContent= textBuffer.getLineContentOfOffset(start);
return TextUtil.getIndent(lineContent, CPlugin.getDefault().getPreferenceStore().getInt(CSourceViewerConfiguration.PREFERENCE_TAB_WIDTH));
} catch (CoreException e) {
return 0;
}
}
/*
* @see TemplateContext#canEvaluate(Template templates)
*/
public boolean canEvaluate(Template template) {
return template.matches(getKey(), getContextType().getName());
}
/*
* @see TemplateContext#evaluate(Template)
*/
public TemplateBuffer evaluate(Template template) throws CoreException {
if (!canEvaluate(template))
return null;
TemplateTranslator translator= new TemplateTranslator();
TemplateBuffer buffer= translator.translate(template.getPattern());
getContextType().edit(buffer, this);
ITemplateEditor formatter= new CFormatter();
formatter.edit(buffer, this);
return buffer;
}
}

View file

@ -0,0 +1,49 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.TemplateContext;
/**
* A context type for javadoc.
*/
public class CContextType extends CompilationUnitContextType {
/**
* Creates a C context type.
*/
public CContextType() {
super("C");
// global
addVariable(new GlobalVariables.Cursor());
addVariable(new GlobalVariables.Dollar());
addVariable(new GlobalVariables.Date());
addVariable(new GlobalVariables.Time());
addVariable(new GlobalVariables.User());
// compilation unit
addVariable(new File());
/* addVariable(new Method());
addVariable(new ReturnType());
addVariable(new Arguments());
addVariable(new Type());
addVariable(new Package()); */
addVariable(new Project());
// @@@ Need to add some specific C ones
}
/*
* @see ContextType#createContext()
*/
public TemplateContext createContext() {
return new CContext(this, fString, fPosition, fCompilationUnit);
}
}

View file

@ -0,0 +1,197 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.ITemplateEditor;
import org.eclipse.cdt.internal.corext.template.TemplateBuffer;
import org.eclipse.cdt.internal.corext.template.TemplateContext;
import org.eclipse.cdt.internal.corext.template.TemplatePosition;
import org.eclipse.cdt.internal.corext.textmanipulation.MultiTextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.NopTextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.SimpleTextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.TextBuffer;
import org.eclipse.cdt.internal.corext.textmanipulation.TextBufferEditor;
import org.eclipse.cdt.internal.corext.textmanipulation.TextEdit;
import org.eclipse.cdt.internal.corext.textmanipulation.TextRegion;
import org.eclipse.cdt.internal.corext.textmanipulation.TextUtil;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Vector;
import org.eclipse.core.runtime.CoreException;
/**
* A template editor using the Java formatter to format a template buffer.
*/
public class CFormatter implements ITemplateEditor {
private static final String CURSOR= "cursor"; //$NON-NLS-1$
private static final String MARKER= "/*${cursor}*/"; //$NON-NLS-1$
/*
* @see ITemplateEditor#edit(TemplateBuffer, TemplateContext)
*/
public void edit(TemplateBuffer buffer, TemplateContext context) throws CoreException {
int indentationLevel= ((CContext) context).getIndentationLevel();
//if (TemplatePreferencePage.useCodeFormatter())
// format(buffer, indentationLevel);
//else
indentate(buffer, indentationLevel);
trimBegin(buffer);
}
private static int getCaretOffset(TemplatePosition[] variables) {
for (int i= 0; i != variables.length; i++) {
TemplatePosition variable= variables[i];
if (variable.getName().equals(CURSOR))
return variable.getOffsets()[0];
}
return -1;
}
private static void indentate(TemplateBuffer templateBuffer, int indentationLevel) throws CoreException {
String string= templateBuffer.getString();
TemplatePosition[] variables= templateBuffer.getVariables();
String indentation= TextUtil.createIndentString(indentationLevel);
MultiTextEdit positions= variablesToPositions(variables);
MultiTextEdit multiEdit= new MultiTextEdit();
TextBuffer textBuffer= TextBuffer.create(string);
int lineCount= textBuffer.getNumberOfLines();
for (int i= 0; i < lineCount; i++) {
TextRegion region= textBuffer.getLineInformation(i);
multiEdit.add(SimpleTextEdit.createInsert(region.getOffset(), indentation));
}
string= edit(string, positions, multiEdit);
positionsToVariables(positions, variables);
templateBuffer.setContent(string, variables);
}
private static void trimBegin(TemplateBuffer templateBuffer) throws CoreException {
String string= templateBuffer.getString();
TemplatePosition[] variables= templateBuffer.getVariables();
MultiTextEdit positions= variablesToPositions(variables);
int i= 0;
while ((i != string.length()) && Character.isWhitespace(string.charAt(i)))
i++;
string= edit(string, positions, SimpleTextEdit.createDelete(0, i));
positionsToVariables(positions, variables);
templateBuffer.setContent(string, variables);
}
private static String edit(String string, MultiTextEdit positions, MultiTextEdit multiEdit) throws CoreException {
TextBuffer textBuffer= TextBuffer.create(string);
TextBufferEditor editor= new TextBufferEditor(textBuffer);
editor.add(positions);
editor.add(multiEdit);
editor.performEdits(null);
return textBuffer.getContent();
}
private static String edit(String string, MultiTextEdit positions, TextEdit singleEdit) throws CoreException {
TextBuffer textBuffer= TextBuffer.create(string);
TextBufferEditor editor= new TextBufferEditor(textBuffer);
editor.add(positions);
editor.add(singleEdit);
editor.performEdits(null);
return textBuffer.getContent();
}
private static int[] variablesToOffsets(TemplatePosition[] variables) {
Vector vector= new Vector();
for (int i= 0; i != variables.length; i++) {
int[] offsets= variables[i].getOffsets();
for (int j= 0; j != offsets.length; j++)
vector.add(new Integer(offsets[j]));
}
int[] offsets= new int[vector.size()];
for (int i= 0; i != offsets.length; i++)
offsets[i]= ((Integer) vector.get(i)).intValue();
Arrays.sort(offsets);
return offsets;
}
private static void offsetsToVariables(int[] allOffsets, TemplatePosition[] variables) {
int[] currentIndices= new int[variables.length];
for (int i= 0; i != currentIndices.length; i++)
currentIndices[i]= 0;
int[][] offsets= new int[variables.length][];
for (int i= 0; i != variables.length; i++)
offsets[i]= variables[i].getOffsets();
for (int i= 0; i != allOffsets.length; i++) {
int min= Integer.MAX_VALUE;
int minVariableIndex= -1;
for (int j= 0; j != variables.length; j++) {
int currentIndex= currentIndices[j];
// determine minimum
if (currentIndex == offsets[j].length)
continue;
int offset= offsets[j][currentIndex];
if (offset < min) {
min= offset;
minVariableIndex= j;
}
}
offsets[minVariableIndex][currentIndices[minVariableIndex]]= allOffsets[i];
currentIndices[minVariableIndex]++;
}
for (int i= 0; i != variables.length; i++)
variables[i].setOffsets(offsets[i]);
}
private static MultiTextEdit variablesToPositions(TemplatePosition[] variables) {
MultiTextEdit positions= new MultiTextEdit();
for (int i= 0; i != variables.length; i++) {
int[] offsets= variables[i].getOffsets();
for (int j= 0; j != offsets.length; j++)
positions.add(new NopTextEdit(offsets[j], 0));
}
return positions;
}
private static void positionsToVariables(MultiTextEdit positions, TemplatePosition[] variables) {
Iterator iterator= positions.iterator();
for (int i= 0; i != variables.length; i++) {
TemplatePosition variable= variables[i];
int[] offsets= new int[variable.getOffsets().length];
for (int j= 0; j != offsets.length; j++)
offsets[j]= ((TextEdit) iterator.next()).getTextRange().getOffset();
variable.setOffsets(offsets);
}
}
}

View file

@ -0,0 +1,66 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.DocumentTemplateContext;
/**
* A compilation unit context.
*/
public abstract class CompilationUnitContext extends DocumentTemplateContext {
/** The compilation unit, may be <code>null</code>. */
private final ICompilationUnit fCompilationUnit;
/**
* Creates a compilation unit context.
*
* @param type the context type.
* @param string the document string.
* @param completionPosition the completion position within the document.
* @param compilationUnit the compilation unit (may be <code>null</code>).
*/
protected CompilationUnitContext(ContextType type, String string, int completionPosition,
ICompilationUnit compilationUnit)
{
super(type, string, completionPosition);
fCompilationUnit= compilationUnit;
}
/**
* Returns the compilation unit if one is associated with this context, <code>null</code> otherwise.
*/
public final ICompilationUnit getCompilationUnit() {
return fCompilationUnit;
}
/**
* Returns the enclosing element of a particular element type, <code>null</code>
* if no enclosing element of that type exists.
*/
public ICElement findEnclosingElement(int elementType) {
if (fCompilationUnit == null)
return null;
/* try {
ICElement element= fCompilationUnit.getElementAt(getStart());
while (element != null && element.getElementType() != elementType)
element= element.getParent();
return element;
} catch (JavaModelException e) {
return null;
} */
return null;
}
}

View file

@ -0,0 +1,180 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.ContextType;
import org.eclipse.cdt.internal.corext.template.TemplateContext;
import org.eclipse.cdt.internal.corext.template.TemplateVariable;
/**
* Compilation unit context type.
*/
public abstract class CompilationUnitContextType extends ContextType {
/** the document string */
protected String fString;
/** the completion position within the document string */
protected int fPosition;
/** the associated compilation unit, may be <code>null</code> */
protected ICompilationUnit fCompilationUnit;
protected static class ReturnType extends TemplateVariable {
public ReturnType() {
super("return_type", TemplateMessages.getString("JavaContextType.variable.description.return.type"));
}
public String evaluate(TemplateContext context) {
/* IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
if (element == null)
return null;
try {
return Signature.toString(((IMethod) element).getReturnType());
} catch (JavaModelException e) {
return null;
} */
return null;
}
public boolean isResolved(TemplateContext context) {
return evaluate(context) != null;
}
}
protected static class File extends TemplateVariable {
public File() {
super("file", TemplateMessages.getString("JavaContextType.variable.description.file"));
}
public String evaluate(TemplateContext context) {
//ICompilationUnit unit= ((CompilationUnitContext) context).getCompilationUnit();
//return (unit == null) ? null : unit.getElementName();
return null;
}
public boolean isResolved(TemplateContext context) {
return evaluate(context) != null;
}
}
protected static class EnclosingJavaElement extends TemplateVariable {
protected final int fElementType;
public EnclosingJavaElement(String name, String description, int elementType) {
super(name, description);
fElementType= elementType;
}
public String evaluate(TemplateContext context) {
/*IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(fElementType);
return (element == null) ? null : element.getElementName(); */
return null;
}
public boolean isResolved(TemplateContext context) {
return evaluate(context) != null;
}
}
protected static class Method extends EnclosingJavaElement {
public Method() {
//super("enclosing_method", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method"), IJavaElement.METHOD);
super("enclosing_method", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method"), 0);
}
}
protected static class Type extends EnclosingJavaElement {
public Type() {
super("enclosing_type", TemplateMessages.getString("JavaContextType.variable.description.enclosing.type"), 0);
}
}
/*
protected static class SuperClass extends EnclosingJavaElement {
public Type() {
super("super_class", TemplateMessages.getString("JavaContextType.variable.description.type"), IJavaElement.TYPE);
}
}
*/
protected static class Package extends EnclosingJavaElement {
public Package() {
super("enclosing_package", TemplateMessages.getString("JavaContextType.variable.description.enclosing.package"), 0);
}
}
protected static class Project extends EnclosingJavaElement {
public Project() {
super("enclosing_project", TemplateMessages.getString("JavaContextType.variable.description.enclosing.project"), 0);
}
}
/*
protected static class Project2 extends TemplateVariable {
public Project2() {
super("project", TemplateMessages.getString("JavaContextType.variable.description.project"));
}
public String evaluate(TemplateContext context) {
ICompilationUnit unit= ((JavaContext) context).getUnit();
return (unit == null) ? null : unit.getJavaProject().getElementName();
}
}
*/
protected static class Arguments extends TemplateVariable {
public Arguments() {
super("enclosing_method_arguments", TemplateMessages.getString("JavaContextType.variable.description.enclosing.method.arguments"));
}
public String evaluate(TemplateContext context) {
/*IJavaElement element= ((CompilationUnitContext) context).findEnclosingElement(IJavaElement.METHOD);
if (element == null)
return null;
IMethod method= (IMethod) element;
try {
String[] arguments= method.getParameterNames();
StringBuffer buffer= new StringBuffer();
for (int i= 0; i < arguments.length; i++) {
if (i > 0)
buffer.append(", ");
buffer.append(arguments[i]);
}
return buffer.toString();
} catch (JavaModelException e) {
return null;
} */
return null;
}
}
/*
protected static class Line extends TemplateVariable {
public Line() {
super("line", TemplateMessages.getString("CompilationUnitContextType.variable.description.line"));
}
public String evaluate(TemplateContext context) {
return ((JavaTemplateContext) context).guessLineNumber();
}
}
*/
/*
* @see ContextType#ContextType(String)
*/
public CompilationUnitContextType(String name) {
super(name);
}
/**
* Sets context parameters. Needs to be called before createContext().
*/
public void setContextParameters(String string, int position, ICompilationUnit compilationUnit) {
fString= string;
fPosition= position;
fCompilationUnit= compilationUnit;
}
}

View file

@ -0,0 +1,47 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.TemplateContext;
/**
* A context type for javadoc.
*/
public class CppContextType extends CompilationUnitContextType {
/**
* Creates a C context type.
*/
public CppContextType() {
super("C++");
// global
addVariable(new GlobalVariables.Cursor());
addVariable(new GlobalVariables.Dollar());
addVariable(new GlobalVariables.Date());
addVariable(new GlobalVariables.Time());
addVariable(new GlobalVariables.User());
// compilation unit
addVariable(new File());
/* addVariable(new Method());
addVariable(new ReturnType());
addVariable(new Arguments());
addVariable(new Type());
addVariable(new Package()); */
addVariable(new Project());
// @@@ Need to add some specific C ones
}
/*
* @see ContextType#createContext()
*/
public TemplateContext createContext() {
return new CContext(this, fString, fPosition, fCompilationUnit);
}
}

View file

@ -0,0 +1,80 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import org.eclipse.cdt.internal.corext.template.SimpleTemplateVariable;
import org.eclipse.cdt.internal.corext.template.TemplateContext;
import java.text.DateFormat;
/**
* Global variables which are available in any context.
*/
public class GlobalVariables {
/**
* The cursor variable determines the cursor placement after template edition.
*/
static class Cursor extends SimpleTemplateVariable {
public Cursor() {
super("cursor", TemplateMessages.getString("GlobalVariables.variable.description.cursor"));
setEvaluationString("");
setResolved(true);
}
}
/**
* The dollar variable inserts an escaped dollar symbol.
*/
static class Dollar extends SimpleTemplateVariable {
public Dollar() {
super("dollar", TemplateMessages.getString("GlobalVariables.variable.description.dollar"));
setEvaluationString("$");
setResolved(true);
}
}
/**
* The date variable evaluates to the current date.
*/
static class Date extends SimpleTemplateVariable {
public Date() {
super("date", TemplateMessages.getString("GlobalVariables.variable.description.date"));
setResolved(true);
}
public String evaluate(TemplateContext context) {
return DateFormat.getDateInstance().format(new java.util.Date());
}
}
/**
* The time variable evaluates to the current time.
*/
static class Time extends SimpleTemplateVariable {
public Time() {
super("time", TemplateMessages.getString("GlobalVariables.variable.description.time"));
setResolved(true);
}
public String evaluate(TemplateContext context) {
return DateFormat.getTimeInstance().format(new java.util.Date());
}
}
/**
* The user variable evaluates to the current user.
*/
static class User extends SimpleTemplateVariable {
public User() {
super("user", TemplateMessages.getString("GlobalVariables.variable.description.user"));
setResolved(true);
}
public String evaluate(TemplateContext context) {
return System.getProperty("user.name");
}
}
}

View file

@ -0,0 +1,11 @@
package org.eclipse.cdt.internal.corext.template.c;
/*
* (c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*/
public interface ICompilationUnit {
}

Some files were not shown because too many files have changed in this diff Show more