Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jface.text/src/org/eclipse/jface/text/templates')
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java55
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java103
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java61
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties14
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java168
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java228
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java408
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html113
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java173
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java61
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties14
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java345
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java344
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html113
14 files changed, 0 insertions, 2200 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java
deleted file mode 100644
index 6ce4c27a8..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * A registry for context types. Editor implementors will usually instantiate a
- * registry and configure the context types available in their editor.
- *
- * @since 3.0
- */
-public class ContextTypeRegistry {
-
- /** all known context types */
- private final Map fContextTypes= new HashMap();
-
- /**
- * Adds a context type to the registry.
- *
- * @param contextType the context type to add
- */
- public void addContextType(TemplateContextType contextType) {
- fContextTypes.put(contextType.getId(), contextType);
- }
-
- /**
- * Returns the context type if the id is valid, <code>null</code> otherwise.
- *
- * @param id the id of the context type to retrieve
- * @return the context type if <code>name</code> is valid, <code>null</code> otherwise
- */
- public TemplateContextType getContextType(String id) {
- return (TemplateContextType) fContextTypes.get(id);
- }
-
- /**
- * Returns an iterator over all registered context types.
- *
- * @return an iterator over all registered context types
- */
- public Iterator contextTypes() {
- return fContextTypes.values().iterator();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java
deleted file mode 100644
index 6cfc05121..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.Position;
-
-/**
- * Position updater that takes any change in [position.offset, position.offset + position.length] as
- * belonging to the position.
- *
- * @since 3.0
- */
-class InclusivePositionUpdater implements IPositionUpdater {
-
- /** The position category. */
- private final String fCategory;
-
- /**
- * Creates a new updater for the given <code>category</code>.
- *
- * @param category the new category.
- */
- public InclusivePositionUpdater(String category) {
- fCategory= category;
- }
-
- /*
- * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
- */
- public void update(DocumentEvent event) {
-
- int eventOffset= event.getOffset();
- int eventOldLength= event.getLength();
- int eventNewLength= event.getText() == null ? 0 : event.getText().length();
- int deltaLength= eventNewLength - eventOldLength;
-
- try {
- Position[] positions= event.getDocument().getPositions(fCategory);
-
- for (int i= 0; i != positions.length; i++) {
-
- Position position= positions[i];
-
- if (position.isDeleted())
- continue;
-
- int offset= position.getOffset();
- int length= position.getLength();
- int end= offset + length;
-
- if (offset > eventOffset + eventOldLength)
- // position comes way
- // after change - shift
- position.setOffset(offset + deltaLength);
- else if (end < eventOffset) {
- // position comes way before change -
- // leave alone
- } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) {
- // event completely internal to the position - adjust length
- position.setLength(length + deltaLength);
- } else if (offset < eventOffset) {
- // event extends over end of position - adjust length
- int newEnd= eventOffset + eventNewLength;
- position.setLength(newEnd - offset);
- } else if (end > eventOffset + eventOldLength) {
- // event extends from before position into it - adjust offset
- // and length
- // offset becomes end of event, length ajusted acordingly
- // we want to recycle the overlapping part
- position.setOffset(eventOffset);
- int deleted= eventOffset + eventOldLength - offset;
- position.setLength(length - deleted + eventNewLength);
- } else {
- // event consumes the position - delete it
- position.delete();
- }
- }
- } catch (BadPositionCategoryException e) {
- // ignore and return
- }
- }
-
- /**
- * Returns the position category.
- *
- * @return the position category
- */
- public String getCategory() {
- return fCategory;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java
deleted file mode 100644
index 5d63874d1..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @since 3.0
- */
-class JFaceTextTemplateMessages {
-
- private static final String RESOURCE_BUNDLE= JFaceTextTemplateMessages.class.getName();
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private JFaceTextTemplateMessages() {
- }
-
- /**
- * @param key
- * @return
- */
- 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
- * @param arg
- * @return
- */
- 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
- * @param key
- * @param args
- * @return
- */
- public static String getFormattedString(String key, Object[] args) {
- return MessageFormat.format(getString(key), args);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties
deleted file mode 100644
index 6fa3272a6..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-# template proposal
-TemplateProposal.delimiter=\ -
-TemplateProposal.errorDialog.title=Template Evaluation Error
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java
deleted file mode 100644
index 6213f6226..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.jface.text.templates;
-
-
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-
-
-/**
- * An enhanced implementation of the <code>ICompletionProposal</code> interface implementing all the extension interfaces.
- *
- * @since 3.0
- */
-final class PositionBasedCompletionProposal implements ICompletionProposal, ICompletionProposalExtension2 {
-
- /** The string to be displayed in the completion proposal popup */
- private String fDisplayString;
- /** The replacement string */
- private String fReplacementString;
- /** The replacement position. */
- private Position fReplacementPosition;
- /** The cursor position after this proposal has been applied */
- private int fCursorPosition;
- /** The image to be displayed in the completion proposal popup */
- private Image fImage;
- /** The context information of this proposal */
- private IContextInformation fContextInformation;
- /** The additional info of this proposal */
- private String fAdditionalProposalInfo;
-
- /**
- * Creates a new completion proposal based on the provided information. The replacement string is
- * considered being the display string too. All remaining fields are set to <code>null</code>.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementPosition the position of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
- */
- public PositionBasedCompletionProposal(String replacementString, Position replacementPosition, int cursorPosition) {
- this(replacementString, replacementPosition, cursorPosition, null, null, null, null);
- }
-
- /**
- * Creates a new completion proposal. All fields are initialized based on the provided information.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementPosition the position of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal
- * @param contextInformation the context information associated with this proposal
- * @param additionalProposalInfo the additional information associated with this proposal
- */
- public PositionBasedCompletionProposal(String replacementString, Position replacementPosition, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) {
- Assert.isNotNull(replacementString);
- Assert.isTrue(replacementPosition != null);
-
- fReplacementString= replacementString;
- fReplacementPosition= replacementPosition;
- fCursorPosition= cursorPosition;
- fImage= image;
- fDisplayString= displayString;
- fContextInformation= contextInformation;
- fAdditionalProposalInfo= additionalProposalInfo;
- }
-
- /*
- * @see ICompletionProposal#apply(IDocument)
- */
- public void apply(IDocument document) {
- try {
- document.replace(fReplacementPosition.getOffset(), fReplacementPosition.getLength(), fReplacementString);
- } catch (BadLocationException x) {
- // ignore
- }
- }
-
- /*
- * @see ICompletionProposal#getSelection(IDocument)
- */
- public Point getSelection(IDocument document) {
- return new Point(fReplacementPosition.getOffset() + fCursorPosition, 0);
- }
-
- /*
- * @see ICompletionProposal#getContextInformation()
- */
- public IContextInformation getContextInformation() {
- return fContextInformation;
- }
-
- /*
- * @see ICompletionProposal#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
- */
- public String getDisplayString() {
- if (fDisplayString != null)
- return fDisplayString;
- return fReplacementString;
- }
-
- /*
- * @see ICompletionProposal#getAdditionalProposalInfo()
- */
- public String getAdditionalProposalInfo() {
- return fAdditionalProposalInfo;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
- */
- public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
- apply(viewer.getDocument());
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean)
- */
- public void selected(ITextViewer viewer, boolean smartToggle) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer)
- */
- public void unselected(ITextViewer viewer) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
- */
- public boolean validate(IDocument document, int offset, DocumentEvent event) {
- try {
- String content= document.get(fReplacementPosition.getOffset(), fReplacementPosition.getLength());
- if (content.startsWith(fReplacementString))
- return true;
- } catch (BadLocationException e) {
- // ignore concurrently modified document
- }
- return false;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java
deleted file mode 100644
index f247354b0..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.eclipse.swt.graphics.Image;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-
-
-/**
- * A completion processor that computes template proposals.
- *
- * @since 3.0
- */
-public abstract class TemplateCompletionProcessor implements IContentAssistProcessor {
-
- private static final class ProposalComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- return ((TemplateProposal) o2).getRelevance() - ((TemplateProposal) o1).getRelevance();
- }
- }
-
- private static final Comparator fgProposalComparator= new ProposalComparator();
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
-
- ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();
-
- // adjust offset to end of normalized selection
- if (selection.getOffset() == offset)
- offset= selection.getOffset() + selection.getLength();
-
- String prefix= extractPrefix(viewer, offset);
- Region region= new Region(offset - prefix.length(), prefix.length());
- TemplateContext context= createContext(viewer, region);
- if (context == null)
- return new ICompletionProposal[0];
-
- context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$
-
- Template[] templates= getTemplates(context.getContextType().getId());
-
- List matches= new ArrayList();
- for (int i= 0; i < templates.length; i++) {
- Template template= templates[i];
- try {
- context.getContextType().validate(template.getPattern());
- } catch (TemplateException e) {
- continue;
- }
- if (template.matches(prefix, context.getContextType().getId()))
- matches.add(createProposal(template, context, region, getRelevance(template, prefix)));
- }
-
- Collections.sort(matches, fgProposalComparator);
-
- return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
- }
-
- /**
- * Creates a new proposal.
- * <p>
- * The default implementation returns an instance of
- * {@link TemplateProposal}. Subclasses may override to provide their own
- * implementations.
- * </p>
- *
- * @param template the template to be applied by the proposal
- * @param context the context for the proposal
- * @param region the region the proposal applies to
- * @param relevance the relevance of the proposal
- * @return a new <code>ICompletionProposal</code> for <code>template</code>
- */
- protected ICompletionProposal createProposal(Template template, TemplateContext context, Region region, int relevance) {
- return new TemplateProposal(template, context, region, getImage(template), relevance);
- }
-
- /**
- * Returns the templates valid for the context type specified by <code>contextTypeId</code>.
- *
- * @param contextTypeId the context type id
- * @return the templates valid for this context type id
- */
- protected abstract Template[] getTemplates(String contextTypeId);
-
- /**
- * Creates a concrete template context for the given region in the document. This involves finding out which
- * context type is valid at the given location, and then creating a context of this type. The default implementation
- * returns a <code>DocumentTemplateContext</code> for the context type at the given location.
- *
- * @param viewer the viewer for which the context is created
- * @param region the region into <code>document</code> for which the context is created
- * @return a template context that can handle template insertion at the given location, or <code>null</code>
- */
- protected TemplateContext createContext(ITextViewer viewer, IRegion region) {
- TemplateContextType contextType= getContextType(viewer, region);
- if (contextType != null) {
- IDocument document= viewer.getDocument();
- return new DocumentTemplateContext(contextType, document, region.getOffset(), region.getLength());
- }
- return null;
- }
-
- /**
- * Returns the context type that can handle template insertion at the given region
- * in the viewer's document.
- *
- * @param viewer the text viewer
- * @param region the region into the document displayed by viewer
- * @return the context type that can handle template expansion for the given location, or <code>null</code> if none exists
- */
- protected abstract TemplateContextType getContextType(ITextViewer viewer, IRegion region);
-
- /**
- * Returns the relevance of a template given a prefix. The default
- * implementation returns a number greater than zero if the template name
- * starts with the prefix, and zero otherwise.
- *
- * @param template the template to compute the relevance for
- * @param prefix the prefix after which content assist was requested
- * @return the relevance of <code>template</code>
- * @see #extractPrefix(ITextViewer, int)
- */
- protected int getRelevance(Template template, String prefix) {
- if (template.getName().startsWith(prefix))
- return 90;
- return 0;
- }
-
- /**
- * Heuristically extracts the prefix used for determining template relevance
- * from the viewer's document. The default implementation returns the String from
- * offset backwards that forms a java identifier.
- *
- * @param viewer the viewer
- * @param offset offset into document
- * @return the prefix to consider
- * @see #getRelevance(Template, String)
- */
- protected String extractPrefix(ITextViewer viewer, int offset) {
- int i= offset;
- IDocument document= viewer.getDocument();
- if (i > document.getLength())
- return ""; //$NON-NLS-1$
-
- try {
- while (i > 0) {
- char ch= document.getChar(i - 1);
- if (!Character.isJavaIdentifierPart(ch))
- break;
- i--;
- }
-
- return document.get(i, offset - i);
- } catch (BadLocationException e) {
- return ""; //$NON-NLS-1$
- }
- }
-
- /**
- * Returns the image to be used for the proposal for <code>template</code>.
- *
- * @param template the template for which an image should be returned
- * @return the image for <code>template</code>
- */
- protected abstract Image getImage(Template template);
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- public char[] getContextInformationAutoActivationCharacters() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
- */
- public String getErrorMessage() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
- */
- public IContextInformationValidator getContextInformationValidator() {
- return null;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
deleted file mode 100644
index 0ff9f82d3..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.link.ILinkedModeListener;
-import org.eclipse.jface.text.link.LinkedModeModel;
-import org.eclipse.jface.text.link.LinkedModeUI;
-import org.eclipse.jface.text.link.LinkedPosition;
-import org.eclipse.jface.text.link.LinkedPositionGroup;
-import org.eclipse.jface.text.link.ProposalPosition;
-
-
-/**
- * A template proposal.
- *
- * @since 3.0
- */
-public class TemplateProposal implements ICompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, ICompletionProposalExtension3 {
-
- private final Template fTemplate;
- private final TemplateContext fContext;
- private final Image fImage;
- private final IRegion fRegion;
- private int fRelevance;
-
- private IRegion fSelectedRegion; // initialized by apply()
- private String fDisplayString;
- private InclusivePositionUpdater fUpdater;
-
- /**
- * Creates a template proposal with a template and its context.
- * @param template the template
- * @param context the context in which the template was requested.
- * @param region the region this proposal is applied to
- * @param image the icon of the proposal.
- */
- public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image) {
- this(template, context, region, image, 0);
- }
-
- /**
- * Creates a template proposal with a template and its context.
- * @param template the template
- * @param context the context in which the template was requested.
- * @param image the icon of the proposal.
- * @param region the region this proposal is applied to
- * @param relevance the relevance of the proposal
- */
- public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) {
- Assert.isNotNull(template);
- Assert.isNotNull(context);
- Assert.isNotNull(region);
-
- fTemplate= template;
- fContext= context;
- fImage= image;
- fRegion= region;
-
- fDisplayString= null;
-
- fRelevance= relevance;
- }
-
- /*
- * @see ICompletionProposal#apply(IDocument)
- */
- public final void apply(IDocument document) {
- // not called anymore
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
- */
- public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
-
- IDocument document= viewer.getDocument();
- try {
- fContext.setReadOnly(false);
- TemplateBuffer templateBuffer;
- try {
- templateBuffer= fContext.evaluate(fTemplate);
- } catch (TemplateException e1) {
- fSelectedRegion= fRegion;
- return;
- }
-
- int start= getReplaceOffset();
- int end= Math.max(getReplaceEndOffset(), offset);
-
- // insert template string
- String templateString= templateBuffer.getString();
- document.replace(start, end - start, templateString);
-
-
- // translate positions
- LinkedModeModel model= new LinkedModeModel();
- TemplateVariable[] variables= templateBuffer.getVariables();
- boolean hasPositions= false;
- for (int i= 0; i != variables.length; i++) {
- TemplateVariable variable= variables[i];
-
- if (variable.isUnambiguous())
- continue;
-
- LinkedPositionGroup group= new LinkedPositionGroup();
-
- int[] offsets= variable.getOffsets();
- int length= variable.getLength();
-
- String[] values= variable.getValues();
- ICompletionProposal[] proposals= new ICompletionProposal[values.length];
- for (int j= 0; j < values.length; j++) {
- ensurePositionCategoryInstalled(document, model);
- Position pos= new Position(offsets[0] + start, length);
- document.addPosition(getCategory(), pos);
- proposals[j]= new PositionBasedCompletionProposal(values[j], pos, length);
- }
-
- for (int j= 0; j != offsets.length; j++)
- if (j == 0 && proposals.length > 1)
- group.addPosition(new ProposalPosition(document, offsets[j] + start, length, proposals));
- else
- group.addPosition(new LinkedPosition(document, offsets[j] + start, length));
-
- model.addGroup(group);
- hasPositions= true;
- }
-
- if (hasPositions) {
- model.forceInstall();
- LinkedModeUI ui= new LinkedModeUI(model, viewer);
- ui.setExitPosition(viewer, getCaretOffset(templateBuffer) + start, 0, Integer.MAX_VALUE);
- ui.enter();
-
- fSelectedRegion= ui.getSelectedRegion();
- } else {
- ensurePositionCategoryRemoved(document);
- fSelectedRegion= new Region(getCaretOffset(templateBuffer) + start, 0);
- }
-
- } catch (BadLocationException e) {
- openErrorDialog(viewer.getTextWidget().getShell(), e);
- ensurePositionCategoryRemoved(document);
- fSelectedRegion= fRegion;
- } catch (BadPositionCategoryException e) {
- openErrorDialog(viewer.getTextWidget().getShell(), e);
- fSelectedRegion= fRegion;
- }
-
- }
-
- private void ensurePositionCategoryInstalled(final IDocument document, LinkedModeModel model) {
- if (!document.containsPositionCategory(getCategory())) {
- document.addPositionCategory(getCategory());
- fUpdater= new InclusivePositionUpdater(getCategory());
- document.addPositionUpdater(fUpdater);
-
- model.addLinkingListener(new ILinkedModeListener() {
-
- /*
- * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
- */
- public void left(LinkedModeModel environment, int flags) {
- ensurePositionCategoryRemoved(document);
- }
-
- public void suspend(LinkedModeModel environment) {}
- public void resume(LinkedModeModel environment, int flags) {}
- });
- }
- }
-
- private void ensurePositionCategoryRemoved(IDocument document) {
- if (document.containsPositionCategory(getCategory())) {
- try {
- document.removePositionCategory(getCategory());
- } catch (BadPositionCategoryException e) {
- // ignore
- }
- document.removePositionUpdater(fUpdater);
- }
- }
-
- private String getCategory() {
- return "TemplateProposalCategory_" + toString(); //$NON-NLS-1$
- }
-
- private int getCaretOffset(TemplateBuffer buffer) {
-
- TemplateVariable[] variables= buffer.getVariables();
- for (int i= 0; i != variables.length; i++) {
- TemplateVariable variable= variables[i];
- if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
- return variable.getOffsets()[0];
- }
-
- return buffer.getString().length();
- }
-
- /**
- * Returns the offset of the range in the document that will be replaced by
- * applying this template.
- *
- * @return the offset of the range in the document that will be replaced by
- * applying this template
- */
- private int getReplaceOffset() {
- int start;
- if (fContext instanceof DocumentTemplateContext) {
- DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
- start= docContext.getStart();
- } else {
- start= fRegion.getOffset();
- }
- return start;
- }
-
- /**
- * Returns the end offset of the range in the document that will be replaced
- * by applying this template.
- *
- * @return the end offset of the range in the document that will be replaced
- * by applying this template
- */
- private int getReplaceEndOffset() {
- int end;
- if (fContext instanceof DocumentTemplateContext) {
- DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
- end= docContext.getEnd();
- } else {
- end= fRegion.getOffset() + fRegion.getLength();
- }
- return end;
- }
-
- /*
- * @see ICompletionProposal#getSelection(IDocument)
- */
- public Point getSelection(IDocument document) {
- return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
- }
-
- /*
- * @see ICompletionProposal#getAdditionalProposalInfo()
- */
- public String getAdditionalProposalInfo() {
- try {
- fContext.setReadOnly(true);
- TemplateBuffer templateBuffer;
- try {
- templateBuffer= fContext.evaluate(fTemplate);
- } catch (TemplateException e) {
- return null;
- }
-
- return templateBuffer.getString();
-
- } catch (BadLocationException e) {
- return null;
- }
- }
-
- /*
- * @see ICompletionProposal#getDisplayString()
- */
- public String getDisplayString() {
- if (fDisplayString == null) {
- fDisplayString= fTemplate.getName() + JFaceTextTemplateMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); //$NON-NLS-1$
- }
- return fDisplayString;
- }
-
- /*
- * @see ICompletionProposal#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /*
- * @see ICompletionProposal#getContextInformation()
- */
- public IContextInformation getContextInformation() {
- return null;
- }
-
- private void openErrorDialog(Shell shell, Exception e) {
- MessageDialog.openError(shell, JFaceTextTemplateMessages.getString("TemplateProposal.errorDialog.title"), e.getMessage()); //$NON-NLS-1$
- }
-
- /**
- * Returns the relevance.
- *
- * @return the relevance
- */
- public int getRelevance() {
- return fRelevance;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getInformationControlCreator()
- */
- public IInformationControlCreator getInformationControlCreator() {
-// return new TemplateInformationControlCreator();
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean)
- */
- public void selected(ITextViewer viewer, boolean smartToggle) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer)
- */
- public void unselected(ITextViewer viewer) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
- */
- public boolean validate(IDocument document, int offset, DocumentEvent event) {
- try {
- int replaceOffset= getReplaceOffset();
- if (offset >= replaceOffset) {
- String content= document.get(replaceOffset, offset - replaceOffset);
- return fTemplate.getName().startsWith(content);
- }
- } catch (BadLocationException e) {
- // concurrent modification - ignore
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getReplacementString()
- */
- public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
- return fTemplate.getName();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getReplacementOffset()
- */
- public int getPrefixCompletionStart(IDocument document, int completionOffset) {
- return getReplaceOffset();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#apply(org.eclipse.jface.text.IDocument, char, int)
- */
- public void apply(IDocument document, char trigger, int offset) {
- // not called any longer
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#isValidFor(org.eclipse.jface.text.IDocument, int)
- */
- public boolean isValidFor(IDocument document, int offset) {
- // not called any longer
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getTriggerCharacters()
- */
- public char[] getTriggerCharacters() {
- // no triggers
- return new char[0];
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getContextInformationPosition()
- */
- public int getContextInformationPosition() {
- return fRegion.getOffset();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html
deleted file mode 100644
index e70145a0f..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta content="text/html; charset=iso-8859-1"
- http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]"
- name="GENERATOR">
- <title>Templates</title>
- <meta content="Template Infrastructure package description"
- name="description">
-</head>
-<body>
-Application programming interfaces for interaction
-with the Eclipse Java User Interface text support.
-<h2>Templates<br>
-</h2>
-<h3>packages</h3>
-<ul>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.jface.text.templates</span></big></li>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.ui.workbench.texteditor.templates</span><br>
- <span style="font-family: monospace;"></span></big></li>
- <li><big><span style="font-family: monospace; font-weight: bold;">org.eclipse.ui.editors.templates</span></big><br>
- <span style="font-family: monospace;"></span></li>
-</ul>
-<h3><code></code></h3>
-Templates are shortcuts for frequently used fragments of text such as
-code patterns or complex text entities. They may contain variables
-which are only resolved at the time when the template is inserted
-within a context. Together with linked mode, inserting a template can
-create a on-the-fly edit mask within a text viewer.<br>
-<br>
-Templates are specified as text, variables are defined using the <span
- style="font-family: monospace;">${variable}</span> notation known from
-Ant, for example. The following snippet shows an example template for
-an instance check in Java:<br>
-<pre>if (${name} instanceof ${type}) {<br>&nbsp;&nbsp;&nbsp; ${type} ${new_name} = (${type})${name};<br>&nbsp;&nbsp;&nbsp; ${cursor}<br>}<br></pre>
-In this template, the variables (<span style="font-family: monospace;">name,
-type, ...</span><span style="font-family: sans-serif;">) are resolved
-when inserted into java source and changing one variable instance will
-also change the other. When leaving linked mode, the caret is placed at
-the </span><span style="font-family: monospace;">cursor</span><span
- style="font-family: sans-serif;"> variable.<br>
-<br>
-Template functionality can be added to a custom text editor by offering
-</span><span style="font-family: monospace;">TemplateProposal</span><span
- style="font-family: sans-serif;">s as content assist choices, which is
-simplified by using a </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;">subclass of </span></span><span
- style="font-family: monospace;">TemplateCompletionProcessor</span><span
- style="font-family: sans-serif;">. User template management can be
-offered by including a </span><span style="font-family: monospace;">TemplatePreferencePage</span><span
- style="font-family: sans-serif;"> which uses a </span><span
- style="font-family: monospace;">TemplateStore</span><span
- style="font-family: sans-serif;"> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> as the
-underlying model to store templates. The <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point can be used to allow other plug-ins to contribute
-templates to an editor. This is accomplished by using the <span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-subclasses of the above types.<br>
-<br>
-Template variables are resolved by a <span
- style="font-family: monospace;">TemplateVariableResolver.</span> <span
- style="font-family: monospace;">GlobalTemplateVariables</span> offers
-some default variables such as date, user, and selection, but advanced
-features such as resolving to language constructs can be performed in
-subclasses.<br>
-</span>
-<h4>Classes</h4>
-<ul>
- <li><span style="font-family: monospace;">Template</span><span
- style="font-family: sans-serif;"> a template consists of name, context
-type identifier, and a pattern.</span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateTranslator</span> and <span
- style="font-family: monospace;">TemplateBuffer</span> are used to
-parse the template grammar and don't need to be used usually.</span></li>
- <li><span style="font-family: sans-serif;">A <span
- style="font-family: monospace;">TemplateProposal </span>can be
-offered in content assist, possibly created by a subclass of <span
- style="font-family: monospace;">TemplateCompletionProcessor.</span></span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateStore</span> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> manage a
-set of templates within a plug-in and offer ways to store them in the
-preferences or externally in XML streams via a <span
- style="font-family: monospace;">TemplateReaderWriter</span>.<br>
- </span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-add awareness for the </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;"> <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point.</span></span></li>
- <li style="font-family: monospace;"><span
- style="font-family: sans-serif;"><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplatePreferencePage</span> allows
-the user to access the templates within a <span
- style="font-family: monospace;">TemplateStore</span>.</span></span></li>
-</ul>
-<ul>
-</ul>
-<h4>Example</h4>
-<pre><span style="font-family: sans-serif;">See the Template Editor Example in the <span
- style="font-weight: bold;">org.eclipse.ui.examples.javaeditor</span> project.<br></span></pre>
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
deleted file mode 100644
index 560185275..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.templates.Template;
-
-
-/**
- * TemplatePersistenceData stores information about a template. It uniquely
- * references contributed templates via their id. Contributed templates may be
- * deleted or modified. All template may be enabled or not.
- *
- * @since 3.0
- */
-public class TemplatePersistenceData {
- private final Template fOriginalTemplate;
- private final String fId;
- private final boolean fOriginalIsEnabled;
-
- private Template fCustomTemplate= null;
- private boolean fIsDeleted= false;
- private boolean fCustomIsEnabled= true;
-
- /**
- * Creates a new, user-added instance that is not linked to a contributed
- * template.
- *
- * @param template the template which is stored by the new instance
- * @param enabled whether the template is enabled
- */
- public TemplatePersistenceData(Template template, boolean enabled) {
- this(template, enabled, null);
- }
-
- /**
- * Creates a new instance. If <code>id</code> is not <code>null</code>,
- * the instance is represents a template that is contributed and can be
- * identified via its id.
- *
- * @param template the template which is stored by the new instance
- * @param enabled whether the template is enabled
- * @param id the id of the template, or <code>null</code> if a user-added
- * instance should be created
- */
- public TemplatePersistenceData(Template template, boolean enabled, String id) {
- Assert.isNotNull(template);
- fOriginalTemplate= template;
- fCustomTemplate= template;
- fOriginalIsEnabled= enabled;
- fCustomIsEnabled= enabled;
- fId= id;
- }
-
- /**
- * Returs the id of this template store, or <code>null</code> if there is none.
- *
- * @return the id of this template store
- */
- public String getId() {
- return fId;
- }
-
- /**
- * Returns the deletion state of the stored template. This is only relevant
- * of contributed templates.
- *
- * @return the deletion state of the stored template
- */
- public boolean isDeleted() {
- return fIsDeleted;
- }
-
- /**
- * Sets the deletion state of the stored template.
- *
- * @param isDeleted the deletion state of the stored template
- */
- public void setDeleted(boolean isDeleted) {
- fIsDeleted= isDeleted;
- }
-
- /**
- * Returns the template encapsulated by the receiver.
- *
- * @return the template encapsulated by the receiver
- */
- public Template getTemplate() {
- return fCustomTemplate;
- }
-
-
- /**
- * Sets the template encapsulated by the receiver.
- *
- * @param template the new template
- */
- public void setTemplate(Template template) {
- fCustomTemplate= template;
- }
-
- /**
- * Returns whether the receiver represents a custom template, i.e. is either
- * a user-added template or a contributed template that has been modified.
- *
- * @return <code>true</code> if the contained template is a custom
- * template and cannot be reconstructed from the contributed
- * templates
- */
- public boolean isCustom() {
- return fId == null
- || fIsDeleted
- || fOriginalIsEnabled != fCustomIsEnabled
- || !fOriginalTemplate.equals(fCustomTemplate);
- }
-
- /**
- * Returns whether the receiver represents a modified template, i.e. a
- * contributed template that has been changed.
- *
- * @return <code>true</code> if the contained template is contributed but has been modified, <code>false</code> otherwise
- */
- public boolean isModified() {
- return isCustom() && !isUserAdded();
- }
-
- /**
- * Returns <code>true</code> if the contained template was added by a
- * user, i.e. does not reference a contributed template.
- *
- * @return <code>true</code> if the contained template was added by a user, <code>false</code> otherwise
- */
- public boolean isUserAdded() {
- return fId == null;
- }
-
-
- /**
- * Reverts the template to its original setting.
- */
- public void revert() {
- fCustomTemplate= fOriginalTemplate;
- fCustomIsEnabled= fOriginalIsEnabled;
- fIsDeleted= false;
- }
-
-
- /**
- * Returns the enablement state of the contained template.
- *
- * @return the enablement state of the contained template
- */
- public boolean isEnabled() {
- return fCustomIsEnabled;
- }
-
- /**
- * Sets the enablement state of the contained template.
- *
- * @param isEnabled the new enablement state of the contained template
- */
- public void setEnabled(boolean isEnabled) {
- fCustomIsEnabled= isEnabled;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java
deleted file mode 100644
index 064fc83eb..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @since 3.0
- */
-class TemplatePersistenceMessages {
-
- private static final String RESOURCE_BUNDLE= TemplatePersistenceMessages.class.getName();
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private TemplatePersistenceMessages() {
- }
-
- /**
- * @param key
- * @return
- */
- 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
- * @param arg
- * @return
- */
- 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
- * @param key
- * @param args
- * @return
- */
- public static String getFormattedString(String key, Object[] args) {
- return MessageFormat.format(getString(key), args);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties
deleted file mode 100644
index 7d00d3dc5..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-TemplateReaderWriter.duplicate.id= Duplicate template id
-TemplateReaderWriter.error.missing_attribute= Missing required attribute
-TemplateReaderWriter.error.illegal_boolean_attribute= Illegal boolean attribute, must be "true" or "false".
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java
deleted file mode 100644
index e2ec4596e..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-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;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.templates.Template;
-
-/**
- * Serializes templates as character stream and reads the same format back.
- * Clients may instantiate this class, it is not intended to be subclassed.
- *
- * @since 3.0
- */
-public class TemplateReaderWriter {
-
- private static final String TEMPLATE_ROOT = "templates"; //$NON-NLS-1$
- private static final String TEMPLATE_ELEMENT = "template"; //$NON-NLS-1$
- private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
- private static final String ID_ATTRIBUTE= "id"; //$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 static final String DELETED_ATTRIBUTE= "deleted"; //$NON-NLS-1$
-
- /**
- * Create a new instance.
- */
- public TemplateReaderWriter() {
- }
-
- /**
- * Reads templates from a reader and returns them. The reader must present
- * a serialized form as produced by the <code>save</code> method.
- *
- * @param reader the reader to read templates from
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- public TemplatePersistenceData[] read(Reader reader) throws IOException {
- return read(reader, null);
- }
-
- /**
- * Reads templates from a stream and adds them to the templates.
- *
- * @param reader the reader to read templates from
- * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- public TemplatePersistenceData[] read(Reader reader, ResourceBundle bundle) throws IOException {
- return read(new InputSource(reader), bundle);
- }
-
- /**
- * Reads templates from a stream and adds them to the templates.
- *
- * @param stream the byte stream to read templates from
- * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- public TemplatePersistenceData[] read(InputStream stream, ResourceBundle bundle) throws IOException {
- return read(new InputSource(stream), bundle);
- }
-
- /**
- * Reads templates from an InputSource and adds them to the templates.
- *
- * @param source the input source
- * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle) throws IOException {
- try {
- Collection templates= new ArrayList();
- Set ids= new HashSet();
-
- DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
- DocumentBuilder parser= factory.newDocumentBuilder();
- Document document= parser.parse(source);
-
- NodeList elements= document.getElementsByTagName(TEMPLATE_ELEMENT);
-
- 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 id= getStringValue(attributes, ID_ATTRIBUTE, null);
- if (id != null && ids.contains(id))
- throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.duplicate.id")); //$NON-NLS-1$
-
- boolean deleted = getBooleanValue(attributes, DELETED_ATTRIBUTE, false);
-
- String name= getStringValue(attributes, NAME_ATTRIBUTE);
- name= translateString(name, bundle);
-
- String description= getStringValue(attributes, DESCRIPTION_ATTRIBUTE, ""); //$NON-NLS-1$
- description= translateString(description, bundle);
-
- String context= getStringValue(attributes, CONTEXT_ATTRIBUTE);
-
- if (name == null || context == null)
- throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$
-
- boolean enabled = getBooleanValue(attributes, ENABLED_ATTRIBUTE, true);
-
- 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();
- pattern= translateString(pattern, bundle);
-
- Template template= new Template(name, description, context, pattern);
- TemplatePersistenceData data= new TemplatePersistenceData(template, enabled, id);
- data.setDeleted(deleted);
-
- templates.add(data);
- }
-
- return (TemplatePersistenceData[]) templates.toArray(new TemplatePersistenceData[templates.size()]);
-
- } catch (ParserConfigurationException e) {
- Assert.isTrue(false);
- } catch (SAXException e) {
- Throwable t= e.getCause();
- if (t instanceof IOException)
- throw (IOException) t;
- else
- throw new IOException(t.getMessage());
- }
-
- return null; // dummy
- }
-
- /**
- * Saves the templates as XML, encoded as UTF-8 onto the given byte stream.
- *
- * @param templates the templates to save
- * @param stream the byte output to write the templates to in XML
- * @throws IOException if writing the templates fails
- */
- public void save(TemplatePersistenceData[] templates, OutputStream stream) throws IOException {
- save(templates, new StreamResult(stream));
- }
-
- /**
- * Saves the templates as XML.
- *
- * @param templates the templates to save
- * @param writer the writer to write the templates to in XML
- * @throws IOException if writing the templates fails
- */
- public void save(TemplatePersistenceData[] templates, Writer writer) throws IOException {
- save(templates, new StreamResult(writer));
- }
-
- /**
- * Saves the templates as XML.
- *
- * @param templates the templates to save
- * @param result the stream result to write to
- * @throws IOException if writing the templates fails
- */
- private void save(TemplatePersistenceData[] templates, StreamResult result) throws IOException {
- try {
- DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
- DocumentBuilder builder= factory.newDocumentBuilder();
- Document document= builder.newDocument();
-
- Node root= document.createElement(TEMPLATE_ROOT); //$NON-NLS-1$
- document.appendChild(root);
-
- for (int i= 0; i < templates.length; i++) {
- TemplatePersistenceData data= templates[i];
- Template template= data.getTemplate();
-
- Node node= document.createElement(TEMPLATE_ELEMENT);
- root.appendChild(node);
-
- NamedNodeMap attributes= node.getAttributes();
-
- String id= data.getId();
- if (id != null) {
- Attr idAttr= document.createAttribute(ID_ATTRIBUTE);
- idAttr.setValue(id);
- attributes.setNamedItem(idAttr);
- }
-
- if (template != null) {
- Attr name= document.createAttribute(NAME_ATTRIBUTE);
- name.setValue(template.getName());
- attributes.setNamedItem(name);
- }
-
- if (template != null) {
- Attr description= document.createAttribute(DESCRIPTION_ATTRIBUTE);
- description.setValue(template.getDescription());
- attributes.setNamedItem(description);
- }
-
- if (template != null) {
- Attr context= document.createAttribute(CONTEXT_ATTRIBUTE);
- context.setValue(template.getContextTypeId());
- attributes.setNamedItem(context);
- }
-
- Attr enabled= document.createAttribute(ENABLED_ATTRIBUTE);
- enabled.setValue(data.isEnabled() ? Boolean.toString(true) : Boolean.toString(false)); //$NON-NLS-1$ //$NON-NLS-2$
- attributes.setNamedItem(enabled);
-
- Attr deleted= document.createAttribute(DELETED_ATTRIBUTE);
- deleted.setValue(data.isDeleted() ? Boolean.toString(true) : Boolean.toString(false)); //$NON-NLS-1$ //$NON-NLS-2$
- attributes.setNamedItem(deleted);
-
- if (template != null) {
- Text pattern= document.createTextNode(template.getPattern());
- node.appendChild(pattern);
- }
- }
-
-
- Transformer transformer=TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
- DOMSource source = new DOMSource(document);
-
- transformer.transform(source, result);
-
- } catch (ParserConfigurationException e) {
- Assert.isTrue(false);
- } catch (TransformerException e) {
- if (e.getException() instanceof IOException)
- throw (IOException) e.getException();
- Assert.isTrue(false);
- }
- }
-
- private boolean getBooleanValue(NamedNodeMap attributes, String attribute, boolean defaultValue) throws SAXException {
- Node enabledNode= attributes.getNamedItem(attribute);
- if (enabledNode == null)
- return defaultValue;
- else if (enabledNode.getNodeValue().equals(Boolean.toString(true)))
- return true;
- else if (enabledNode.getNodeValue().equals(Boolean.toString(false)))
- return false;
- else
- throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.illegal_boolean_attribute")); //$NON-NLS-1$
- }
-
- private String getStringValue(NamedNodeMap attributes, String name) throws SAXException {
- String val= getStringValue(attributes, name, null);
- if (val == null)
- throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$
- return val;
- }
-
- private String getStringValue(NamedNodeMap attributes, String name, String defaultValue) {
- Node node= attributes.getNamedItem(name);
- return node == null ? defaultValue : node.getNodeValue();
- }
-
- private String translateString(String str, ResourceBundle bundle) {
- if (bundle == null)
- return str;
-
- int idx= str.indexOf('%');
- if (idx == -1) {
- return str;
- }
- StringBuffer buf= new StringBuffer();
- int k= 0;
- while (idx != -1) {
- buf.append(str.substring(k, idx));
- for (k= idx + 1; k < str.length() && !Character.isWhitespace(str.charAt(k)); k++) {
- // loop
- }
- String key= str.substring(idx + 1, k);
- buf.append(getBundleString(key, bundle));
- idx= str.indexOf('%', k);
- }
- buf.append(str.substring(k));
- return buf.toString();
- }
-
- private String getBundleString(String key, ResourceBundle bundle) {
- if (bundle != null) {
- try {
- return bundle.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- } else
- return TemplatePersistenceMessages.getString(key); // default messages
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java
deleted file mode 100644
index fdfde5a26..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.templates.ContextTypeRegistry;
-import org.eclipse.jface.text.templates.Template;
-import org.eclipse.jface.text.templates.TemplateException;
-
-/**
- * A collection of templates. Clients may instantiate this class.
- *
- * @since 3.0
- */
-public class TemplateStore {
- /** The stored templates. */
- private final List fTemplates= new ArrayList();
- /** The preference store. */
- private IPreferenceStore fPreferenceStore;
- /**
- * The key into <code>fPreferenceStore</code> the value of which holds custom templates
- * encoded as XML.
- */
- private String fKey;
- /**
- * The context type registry, or <code>null</code> if all templates regardless
- * of context type should be loaded.
- */
- private ContextTypeRegistry fRegistry;
-
-
- /**
- * Creates a new template store.
- *
- * @param store the preference store in which to store custom templates
- * under <code>key</code>
- * @param key the key into <code>store</code> where to store custom
- * templates
- */
- public TemplateStore(IPreferenceStore store, String key) {
- Assert.isNotNull(store);
- Assert.isNotNull(key);
- fPreferenceStore= store;
- fKey= key;
- }
-
- /**
- * Creates a new template store with a context type registry. Only templates
- * that specify a context type contained in the registry will be loaded by
- * this store if the registry is not <code>null</code>.
- *
- * @param registry a context type registry, or <code>null</code> if all
- * templates should be loaded
- * @param store the preference store in which to store custom templates
- * under <code>key</code>
- * @param key the key into <code>store</code> where to store custom
- * templates
- */
- public TemplateStore(ContextTypeRegistry registry, IPreferenceStore store, String key) {
- this(store, key);
- fRegistry= registry;
- }
-
- /**
- * Loads the templates from contributions and preferences.
- *
- * @throws IOException if loading fails.
- */
- public void load() throws IOException {
- fTemplates.clear();
- loadContributedTemplates();
- loadCustomTemplates();
- }
-
- /**
- * Hook method to load contributed templates. Contributed templates are superseded
- * by customized versions of user added templates stored in the preferences.
- * <p>
- * The default implementation does nothing.</p>
- *
- * @throws IOException if loading fails
- */
- protected void loadContributedTemplates() throws IOException {
- }
-
- /**
- * Adds a template to the internal store. The added templates must have
- * a unique id.
- *
- * @param data the template data to add
- */
- protected void internalAdd(TemplatePersistenceData data) {
- if (!data.isCustom()) {
- // check if the added template is not a duplicate id
- String id= data.getId();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData d2= (TemplatePersistenceData) it.next();
- if (d2.getId() != null && d2.getId().equals(id))
- return;
- }
- fTemplates.add(data);
- }
- }
-
- /**
- * Saves the templates to the preferences.
- *
- * @throws IOException if the templates cannot be written
- */
- public void save() throws IOException {
- ArrayList custom= new ArrayList();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isCustom() && !(data.isUserAdded() && data.isDeleted())) // don't save deleted user-added templates
- custom.add(data);
- }
-
- StringWriter output= new StringWriter();
- TemplateReaderWriter writer= new TemplateReaderWriter();
- writer.save((TemplatePersistenceData[]) custom.toArray(new TemplatePersistenceData[custom.size()]), output);
-
- fPreferenceStore.setValue(fKey, output.toString());
- }
-
- /**
- * Adds a template encapsulated in its persistent form.
- *
- * @param data the template to add
- */
- public void add(TemplatePersistenceData data) {
-
- if (!validateTemplate(data.getTemplate()))
- return;
-
- if (data.isUserAdded()) {
- fTemplates.add(data);
- } else {
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData d2= (TemplatePersistenceData) it.next();
- if (d2.getId() != null && d2.getId().equals(data.getId())) {
- d2.setTemplate(data.getTemplate());
- d2.setDeleted(data.isDeleted());
- d2.setEnabled(data.isEnabled());
- return;
- }
- }
-
- // add an id which is not contributed as add-on
- if (data.getTemplate() != null) {
- TemplatePersistenceData newData= new TemplatePersistenceData(data.getTemplate(), data.isEnabled());
- fTemplates.add(newData);
- }
- }
- }
-
- /**
- * Removes a template from the store.
- *
- * @param data the template to remove
- */
- public void delete(TemplatePersistenceData data) {
- if (data.isUserAdded())
- fTemplates.remove(data);
- else
- data.setDeleted(true);
- }
-
- /**
- * Restores all contributed templates that have been deleted.
- */
- public void restoreDeleted() {
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isDeleted())
- data.setDeleted(false);
- }
- }
-
- /**
- * Deletes all user-added templates and reverts all contributed templates.
- */
- public void restoreDefaults() {
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isUserAdded())
- it.remove();
- else
- data.revert();
- }
- }
-
- /**
- * Returns all enabled templates.
- *
- * @return all enabled templates
- */
- public Template[] getTemplates() {
- return getTemplates(null);
- }
-
- /**
- * Returns all enabled templates for the given context type.
- *
- * @param contextTypeId the id of the context type of the requested templates, or <code>null</code> if all templates should be returned
- * @return all enabled templates for the given context type
- */
- public Template[] getTemplates(String contextTypeId) {
- List templates= new ArrayList();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isEnabled() && !data.isDeleted() && (contextTypeId == null || contextTypeId.equals(data.getTemplate().getContextTypeId())))
- templates.add(data.getTemplate());
- }
-
- return (Template[]) templates.toArray(new Template[templates.size()]);
- }
-
- /**
- * Returns the first enabled template that matches the name.
- *
- * @param name the name of the template searched for
- * @return the first enabled template that matches both name and context type id, or <code>null</code> if none is found
- */
- public Template findTemplate(String name) {
- return findTemplate(name, null);
- }
-
- /**
- * Returns the first enabled template that matches both name and context type id.
- *
- * @param name the name of the template searched for
- * @param contextTypeId the context type id to clip unwanted templates, or <code>null</code> if any context type is ok
- * @return the first enabled template that matches both name and context type id, or <code>null</code> if none is found
- */
- public Template findTemplate(String name, String contextTypeId) {
- Assert.isNotNull(name);
-
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- Template template= data.getTemplate();
- if (data.isEnabled() && !data.isDeleted()
- && (contextTypeId == null || contextTypeId.equals(template.getContextTypeId()))
- && name.equals(template.getName()))
- return template;
- }
-
- return null;
- }
-
- /**
- * Returns all template datas.
- *
- * @param includeDeleted whether to include deleted datas
- * @return all template datas, whether enabled or not
- */
- public TemplatePersistenceData[] getTemplateData(boolean includeDeleted) {
- List datas= new ArrayList();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (includeDeleted || !data.isDeleted())
- datas.add(data);
- }
-
- return (TemplatePersistenceData[]) datas.toArray(new TemplatePersistenceData[datas.size()]);
- }
-
- private void loadCustomTemplates() throws IOException {
- String pref= fPreferenceStore.getString(fKey);
- if (pref != null && pref.trim().length() > 0) {
- Reader input= new StringReader(pref);
- TemplateReaderWriter reader= new TemplateReaderWriter();
- TemplatePersistenceData[] datas= reader.read(input);
- for (int i= 0; i < datas.length; i++) {
- TemplatePersistenceData data= datas[i];
- add(data);
- }
- }
- }
-
- /**
- * Validates a template against the context type registered in the context
- * type registry. Returns always <code>true</code> if no registry is
- * present.
- *
- * @param template the template to validate
- * @return <code>true</code> if validation is successful or no context
- * type registry is specified, <code>false</code> if validation
- * fails
- */
- private boolean validateTemplate(Template template) {
- String contextTypeId= template.getContextTypeId();
- if (contextExists(contextTypeId)) {
- if (fRegistry != null)
- try {
- fRegistry.getContextType(contextTypeId).validate(template.getPattern());
- } catch (TemplateException e) {
- return false;
- }
- return true;
- } else
- return false;
- }
-
- /**
- * Returns <code>true</code> if a context type id specifies a valid context type
- * or if no context type registry is present.
- *
- * @param contextTypeId the context type id to look for
- * @return <code>true</code> if the context type specified by the id
- * is present in the context type registry, or if no registry is
- * specified
- */
- private boolean contextExists(String contextTypeId) {
- return contextTypeId != null && (fRegistry == null || fRegistry.getContextType(contextTypeId) != null);
- }
-
- /**
- * Returns the registry.
- *
- * @return Returns the registry
- */
- protected final ContextTypeRegistry getRegistry() {
- return fRegistry;
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html
deleted file mode 100644
index e70145a0f..000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta content="text/html; charset=iso-8859-1"
- http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]"
- name="GENERATOR">
- <title>Templates</title>
- <meta content="Template Infrastructure package description"
- name="description">
-</head>
-<body>
-Application programming interfaces for interaction
-with the Eclipse Java User Interface text support.
-<h2>Templates<br>
-</h2>
-<h3>packages</h3>
-<ul>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.jface.text.templates</span></big></li>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.ui.workbench.texteditor.templates</span><br>
- <span style="font-family: monospace;"></span></big></li>
- <li><big><span style="font-family: monospace; font-weight: bold;">org.eclipse.ui.editors.templates</span></big><br>
- <span style="font-family: monospace;"></span></li>
-</ul>
-<h3><code></code></h3>
-Templates are shortcuts for frequently used fragments of text such as
-code patterns or complex text entities. They may contain variables
-which are only resolved at the time when the template is inserted
-within a context. Together with linked mode, inserting a template can
-create a on-the-fly edit mask within a text viewer.<br>
-<br>
-Templates are specified as text, variables are defined using the <span
- style="font-family: monospace;">${variable}</span> notation known from
-Ant, for example. The following snippet shows an example template for
-an instance check in Java:<br>
-<pre>if (${name} instanceof ${type}) {<br>&nbsp;&nbsp;&nbsp; ${type} ${new_name} = (${type})${name};<br>&nbsp;&nbsp;&nbsp; ${cursor}<br>}<br></pre>
-In this template, the variables (<span style="font-family: monospace;">name,
-type, ...</span><span style="font-family: sans-serif;">) are resolved
-when inserted into java source and changing one variable instance will
-also change the other. When leaving linked mode, the caret is placed at
-the </span><span style="font-family: monospace;">cursor</span><span
- style="font-family: sans-serif;"> variable.<br>
-<br>
-Template functionality can be added to a custom text editor by offering
-</span><span style="font-family: monospace;">TemplateProposal</span><span
- style="font-family: sans-serif;">s as content assist choices, which is
-simplified by using a </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;">subclass of </span></span><span
- style="font-family: monospace;">TemplateCompletionProcessor</span><span
- style="font-family: sans-serif;">. User template management can be
-offered by including a </span><span style="font-family: monospace;">TemplatePreferencePage</span><span
- style="font-family: sans-serif;"> which uses a </span><span
- style="font-family: monospace;">TemplateStore</span><span
- style="font-family: sans-serif;"> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> as the
-underlying model to store templates. The <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point can be used to allow other plug-ins to contribute
-templates to an editor. This is accomplished by using the <span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-subclasses of the above types.<br>
-<br>
-Template variables are resolved by a <span
- style="font-family: monospace;">TemplateVariableResolver.</span> <span
- style="font-family: monospace;">GlobalTemplateVariables</span> offers
-some default variables such as date, user, and selection, but advanced
-features such as resolving to language constructs can be performed in
-subclasses.<br>
-</span>
-<h4>Classes</h4>
-<ul>
- <li><span style="font-family: monospace;">Template</span><span
- style="font-family: sans-serif;"> a template consists of name, context
-type identifier, and a pattern.</span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateTranslator</span> and <span
- style="font-family: monospace;">TemplateBuffer</span> are used to
-parse the template grammar and don't need to be used usually.</span></li>
- <li><span style="font-family: sans-serif;">A <span
- style="font-family: monospace;">TemplateProposal </span>can be
-offered in content assist, possibly created by a subclass of <span
- style="font-family: monospace;">TemplateCompletionProcessor.</span></span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateStore</span> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> manage a
-set of templates within a plug-in and offer ways to store them in the
-preferences or externally in XML streams via a <span
- style="font-family: monospace;">TemplateReaderWriter</span>.<br>
- </span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-add awareness for the </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;"> <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point.</span></span></li>
- <li style="font-family: monospace;"><span
- style="font-family: sans-serif;"><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplatePreferencePage</span> allows
-the user to access the templates within a <span
- style="font-family: monospace;">TemplateStore</span>.</span></span></li>
-</ul>
-<ul>
-</ul>
-<h4>Example</h4>
-<pre><span style="font-family: sans-serif;">See the Template Editor Example in the <span
- style="font-weight: bold;">org.eclipse.ui.examples.javaeditor</span> project.<br></span></pre>
-</body>
-</html>

Back to the top