Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.text/src/org/eclipse/jface/text/templates')
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java154
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java176
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java60
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java176
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java74
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java118
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java296
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java59
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java260
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java201
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java172
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.java61
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties24
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/templates/package.html113
14 files changed, 0 insertions, 1944 deletions
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java
deleted file mode 100644
index 54c127306..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/DocumentTemplateContext.java
+++ /dev/null
@@ -1,154 +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.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-/**
- * A typical text based document template context.
- * <p>
- * Clients may instantiate and extend this class.
- * </p>
- *
- * @since 3.0
- */
-public class DocumentTemplateContext extends TemplateContext {
-
- /** The text of the document. */
- private final IDocument fDocument;
- /** The completion offset. */
- private int fCompletionOffset;
- /** The completion length. */
- private int fCompletionLength;
-
- /**
- * Creates a document template context.
- *
- * @param type the context type
- * @param document the document this context applies to
- * @param completionOffset the completion offset (for usage in content
- * assist)
- * @param completionLength the completion length
- */
- public DocumentTemplateContext(TemplateContextType type, IDocument document, int completionOffset, int completionLength) {
- super(type);
-
- Assert.isNotNull(document);
- Assert.isTrue(completionOffset >= 0 && completionOffset <= document.getLength());
- Assert.isTrue(completionLength >= 0);
-
- fDocument= document;
- fCompletionOffset= completionOffset;
- fCompletionLength= completionLength;
- }
-
- /**
- * Returns the document.
- *
- * @return the document
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /**
- * Returns the completion offset within the string of the context.
- *
- * @return the completion offset within the string of the context
- */
- public int getCompletionOffset() {
- return fCompletionOffset;
- }
-
- /**
- * Sets the completion offset.
- *
- * @param newOffset the new completion offset
- */
- protected void setCompletionOffset(int newOffset) {
- fCompletionOffset= newOffset;
- }
-
- /**
- * Returns the completion length within the string of the context.
- *
- * @return the completion length within the string of the context
- */
- public int getCompletionLength() {
- return fCompletionLength;
- }
-
- /**
- * Sets the completion length.
- *
- * @param newLength the new completion length
- */
- protected void setCompletionLength(int newLength) {
- fCompletionLength= newLength;
- }
-
- /**
- * Returns the keyword which triggered template insertion.
- *
- * @return the keyword which triggered template insertion
- */
- public String getKey() {
- int offset= getStart();
- int length= getEnd() - offset;
- try {
- return fDocument.get(offset, length);
- } catch (BadLocationException e) {
- return ""; //$NON-NLS-1$
- }
- }
-
- /**
- * Returns the beginning offset of the keyword.
- *
- * @return the beginning offset of the keyword
- */
- public int getStart() {
- return fCompletionOffset;
- }
-
- /**
- * Returns the end offset of the keyword.
- *
- * @return the end offset of the keyword
- */
- public int getEnd() {
- return fCompletionOffset + fCompletionLength;
- }
-
- /*
- * @see org.eclipse.jface.text.templates.TemplateContext#canEvaluate(org.eclipse.jface.text.templates.Template)
- */
- public boolean canEvaluate(Template template) {
- return true;
- }
-
- /*
- * @see org.eclipse.jface.text.templates.TemplateContext#evaluate(org.eclipse.jface.text.templates.Template)
- */
- public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
- if (!canEvaluate(template))
- return null;
-
- TemplateTranslator translator= new TemplateTranslator();
- TemplateBuffer buffer= translator.translate(template);
-
- getContextType().resolve(buffer, this);
-
- return buffer;
- }
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java
deleted file mode 100644
index b35a02aef..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/GlobalTemplateVariables.java
+++ /dev/null
@@ -1,176 +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
- * Sebastian Davids: sdavids@gmx.de - see bug 25376
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-
-
-/**
- * Global variables which are available in any context.
- * <p>
- * Clients may instantiate the classes contained within this class.
- * </p>
- *
- * @since 3.0
- */
-public class GlobalTemplateVariables {
-
- /** The type of the selection variables. */
- public static final String SELECTION= "selection"; //$NON-NLS-1$
-
- /**
- * The cursor variable determines the cursor placement after template edition.
- */
- public static class Cursor extends SimpleTemplateVariableResolver {
-
- /** Name of the cursor variable, value= {@value} */
- public static final String NAME= "cursor"; //$NON-NLS-1$
-
- /**
- * Creates a new cursor variable
- */
- public Cursor() {
- super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$
- setEvaluationString(""); //$NON-NLS-1$
- }
- }
-
- /**
- * The word selection variable determines templates that work on a full
- * lines selection.
- */
- public static class WordSelection extends SimpleTemplateVariableResolver {
-
- /** Name of the word selection variable, value= {@value} */
- public static final String NAME= "word_selection"; //$NON-NLS-1$
-
- /**
- * Creates a new word selection variable
- */
- public WordSelection() {
- super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedWord")); //$NON-NLS-1$
- }
- protected String resolve(TemplateContext context) {
- String selection= context.getVariable(SELECTION); //$NON-NLS-1$
- if (selection == null)
- return ""; //$NON-NLS-1$
- else
- return selection;
- }
- }
-
- /**
- * The line selection variable determines templates that work on selected
- * lines.
- */
- public static class LineSelection extends SimpleTemplateVariableResolver {
-
- /** Name of the line selection variable, value= {@value} */
- public static final String NAME= "line_selection"; //$NON-NLS-1$
-
- /**
- * Creates a new line selection variable
- */
- public LineSelection() {
- super(NAME, TextTemplateMessages.getString("GlobalVariables.variable.description.selectedLines")); //$NON-NLS-1$
- }
- protected String resolve(TemplateContext context) {
- String selection= context.getVariable(SELECTION); //$NON-NLS-1$
- if (selection == null)
- return ""; //$NON-NLS-1$
- else
- return selection;
- }
- }
-
- /**
- * The dollar variable inserts an escaped dollar symbol.
- */
- public static class Dollar extends SimpleTemplateVariableResolver {
- /**
- * Creates a new dollar variable
- */
- public Dollar() {
- super("dollar", TextTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
- setEvaluationString("$"); //$NON-NLS-1$
- }
- }
-
- /**
- * The date variable evaluates to the current date.
- */
- public static class Date extends SimpleTemplateVariableResolver {
- /**
- * Creates a new date variable
- */
- public Date() {
- super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- protected String resolve(TemplateContext context) {
- return DateFormat.getDateInstance().format(new java.util.Date());
- }
- }
-
- /**
- * The year variable evaluates to the current year.
- */
- public static class Year extends SimpleTemplateVariableResolver {
- /**
- * Creates a new year variable
- */
- public Year() {
- super("year", TextTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
- }
- protected String resolve(TemplateContext context) {
- return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
- }
- }
-
- /**
- * The time variable evaluates to the current time.
- */
- public static class Time extends SimpleTemplateVariableResolver {
- /**
- * Creates a new time variable
- */
- public Time() {
- super("time", TextTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * {@inheritDoc}
- */
- protected String resolve(TemplateContext context) {
- return DateFormat.getTimeInstance().format(new java.util.Date());
- }
- }
-
- /**
- * The user variable evaluates to the current user.
- */
- public static class User extends SimpleTemplateVariableResolver {
- /**
- * Creates a new user name variable
- */
- public User() {
- super("user", TextTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * {@inheritDoc}
- */
- protected String resolve(TemplateContext context) {
- return System.getProperty("user.name"); //$NON-NLS-1$
- }
- }
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java
deleted file mode 100644
index 87324983c..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/SimpleTemplateVariableResolver.java
+++ /dev/null
@@ -1,60 +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;
-
-
-/**
- * A simple template variable resolver, which always evaluates to a defined string.
- * <p>
- * Clients may instantiate and extend this class.
- * </p>
- *
- * @since 3.0
- */
-public class SimpleTemplateVariableResolver extends TemplateVariableResolver {
-
- /** The string to which this variable evaluates. */
- private String fEvaluationString;
-
- /*
- * @see TemplateVariableResolver#TemplateVariableResolver(String, String)
- */
- protected SimpleTemplateVariableResolver(String type, String description) {
- super(type, 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 TemplateVariableResolver#evaluate(TemplateContext)
- */
- protected String resolve(TemplateContext context) {
- return fEvaluationString;
- }
-
- /**
- * Returns always <code>true</code>, since simple variables are normally
- * unambiguous.
- *
- * @param context {@inheritDoc}
- * @return <code>true</code>
- */
- protected boolean isUnambiguous(TemplateContext context) {
- return true;
- }
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java
deleted file mode 100644
index 7058ca6d7..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/Template.java
+++ /dev/null
@@ -1,176 +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.Assert;
-
-/**
- * A template consisting of a name and a pattern.
- * <p>
- * Clients may instantiate this class. May become final in the future.
- * </p>
- * @since 3.0
- */
-public class Template {
- /* XXX this class should be final or implement Cloneable, or both. */
-
- /** 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 fContextTypeId;
- /** The template pattern. */
- private String fPattern;
-
- /**
- * 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.
- *
- * @param template the template to copy
- */
- public Template(Template template) {
- this(template.getName(), template.getDescription(), template.getContextTypeId(), template.getPattern());
- }
-
- /**
- * Creates a template.
- *
- * @param name the name of the template
- * @param description the description of the template
- * @param contextTypeId the id of the context type in which the template can be applied
- * @param pattern the template pattern
- */
- public Template(String name, String description, String contextTypeId, String pattern) {
- setDescription(description);
- setName(name);
- setContextTypeId(contextTypeId);
- setPattern(pattern);
- }
-
- /*
- * @see Object#hashCode()
- */
- public int hashCode() {
- return fName.hashCode() ^ fPattern.hashCode() ^ fContextTypeId.hashCode();
- }
-
- /**
- * Sets the description of the template.
- *
- * @param description the new description
- */
- public void setDescription(String description) {
- Assert.isNotNull(description);
- fDescription= description;
- }
-
- /**
- * Returns the description of the template.
- *
- * @return the description of the template
- */
- public String getDescription() {
- return fDescription;
- }
-
- /**
- * Sets the name of the context type in which the template can be applied.
- *
- * @param contextTypeId the new context type name
- */
- public void setContextTypeId(String contextTypeId) {
- Assert.isNotNull(contextTypeId);
- fContextTypeId= contextTypeId;
- }
-
- /**
- * Returns the id of the context type in which the template can be applied.
- *
- * @return the id of the context type in which the template can be applied
- */
- public String getContextTypeId() {
- return fContextTypeId;
- }
-
- /**
- * Sets the name of the template.
- *
- * @param name the name of the template
- */
- public void setName(String name) {
- fName= name;
- }
-
- /**
- * Returns the name of the template.
- *
- * @return the name of the template
- */
- public String getName() {
- return fName;
- }
-
- /**
- * Sets the pattern of the template.
- *
- * @param pattern the new pattern of the template
- */
- public void setPattern(String pattern) {
- fPattern= pattern;
- }
-
- /**
- * Returns the template pattern.
- *
- * @return the template pattern
- */
- public String getPattern() {
- return fPattern;
- }
-
- /**
- * Returns <code>true</code> if template is enabled and matches the context,
- * <code>false</code> otherwise.
- *
- * @param prefix the prefix (e.g. inside a document) to match
- * @param contextTypeName the context type name to match
- * @return <code>true</code> if template is enabled and matches the context,
- * <code>false</code> otherwise
- */
- public boolean matches(String prefix, String contextTypeName) {
- return fContextTypeId.equals(contextTypeName);
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object o) {
- if (!(o instanceof Template))
- return false;
-
- Template t= (Template) o;
- if (t == this)
- return true;
-
- return t.fName.equals(fName)
- && t.fPattern.equals(fPattern)
- && t.fContextTypeId.equals(fContextTypeId)
- && t.fDescription.equals(fDescription);
- }
-
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java
deleted file mode 100644
index cbd00db62..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateBuffer.java
+++ /dev/null
@@ -1,74 +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.Assert;
-
-/**
- * A template buffer is a container for a string and variables.
- * <p>
- * Clients may instantiate this class.
- * </p>
- *
- * @since 3.0
- */
-public final class TemplateBuffer {
-
- /** The string of the template buffer */
- private String fString;
- /** The variable positions of the template buffer */
- private TemplateVariable[] fVariables;
-
- /**
- * Creates a template buffer.
- *
- * @param string the string
- * @param variables the variable positions
- */
- public TemplateBuffer(String string, TemplateVariable[] variables) {
- setContent(string, variables);
- }
-
- /**
- * Sets the content of the template buffer.
- *
- * @param string the string
- * @param variables the variable positions
- */
- public final void setContent(String string, TemplateVariable[] variables) {
- Assert.isNotNull(string);
- Assert.isNotNull(variables);
-
- // XXX assert non-overlapping variable properties
-
- fString= string;
- fVariables= variables;
- }
-
- /**
- * Returns the string of the template buffer.
- *
- * @return the string representation of the template buffer
- */
- public final String getString() {
- return fString;
- }
-
- /**
- * Returns the variable positions of the template buffer.
- *
- * @return the variable positions of the template buffer
- */
- public final TemplateVariable[] getVariables() {
- return fVariables;
- }
-
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java
deleted file mode 100644
index cad34a918..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContext.java
+++ /dev/null
@@ -1,118 +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.Map;
-
-import org.eclipse.jface.text.BadLocationException;
-
-/**
- * Provides the context for a <code>Template</code> being resolved. Keeps track
- * of resolved variables.
- * <p>
- * Clients may extend this class.
- * </p>
- *
- * @since 3.0
- */
-public abstract class TemplateContext {
-
- /** The context type of this context */
- private final TemplateContextType fContextType;
- /** Additional variables. */
- private final Map fVariables= new HashMap();
- /** A flag to indicate that the context should not be modified. */
- private boolean fReadOnly;
-
- /**
- * Creates a template context of a particular context type.
- *
- * @param contextType the context type of this context
- */
- protected TemplateContext(TemplateContextType contextType) {
- fContextType= contextType;
- fReadOnly= true;
- }
-
- /**
- * Returns the context type of this context.
- *
- * @return the context type of this context
- */
- public TemplateContextType getContextType() {
- return fContextType;
- }
-
- /**
- * Sets or clears the read-only flag.
- *
- * @param readOnly the new read-only state
- */
- public void setReadOnly(boolean readOnly) {
- fReadOnly= readOnly;
- }
-
- /**
- * Returns <code>true</code> if the receiver is read-only, <code>false</code> otherwise.
- *
- * @return <code>true</code> if the receiver is read-only, <code>false</code> otherwise
- */
- public boolean isReadOnly() {
- return fReadOnly;
- }
-
- /**
- * Defines the value of a variable.
- *
- * @param name the name of the variable
- * @param value the value of the variable, <code>null</code> to undefine a variable
- */
- public void setVariable(String name, String value) {
- fVariables.put(name, value);
- }
-
- /**
- * Returns the value of a defined variable.
- *
- * @param name the name of the variable
- * @return returns the value of the variable, <code>null</code> if the variable was not defined
- */
- public String getVariable(String name) {
- return (String) fVariables.get(name);
- }
-
- /**
- * Evaluates the template in this context and returns a template buffer.
- * <p>
- * Evaluation means translating the template into a <code>TemplateBuffer</code>,
- * resolving the defined variables in this context and possibly formatting
- * the resolved buffer.</p>
- *
- * @param template the template to evaluate
- * @return returns the buffer with the evaluated template or <code>null</code> if the buffer could not be created
- * @throws BadLocationException if evaluation fails due to concurrently changed documents etc.
- * @throws TemplateException if the template specification is not valid
- */
- public abstract TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException;
-
- /**
- * Tests if the specified template can be evaluated in this context.
- * <p>Examples are templates defined for a different context (e.g. a javadoc
- * template cannot be evaluated in Java context).</p>
- *
- * @param template the <code>Template</code> to check
- * @return <code>true</code> if <code>template</code> can be evaluated
- * in this context, <code>false</code> otherwise
- */
- public abstract boolean canEvaluate(Template template);
-
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java
deleted file mode 100644
index b480a39d5..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateContextType.java
+++ /dev/null
@@ -1,296 +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.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.text.edits.MalformedTreeException;
-import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.text.edits.RangeMarker;
-import org.eclipse.text.edits.ReplaceEdit;
-import org.eclipse.text.edits.TextEdit;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * A context type defines a context within which templates are resolved. It
- * stores a number of <code>TemplateVariableResolver</code>s. A
- * <code>TemplateBuffer</code> can be resolved in a
- * <code>TemplateContext</code> using the
- * {@link #resolve(TemplateBuffer, TemplateContext)} method.
- * <p>
- * Clients may extend this class.
- * </p>
- *
- * @since 3.0
- */
-public class TemplateContextType {
-
- /** Name of the context type. */
- private /* final */ String fId= null;
-
- /** Variable resolvers used by this content type. */
- private final Map fResolvers= new HashMap();
-
- /** The name of the context type. */
- private String fName= null;
-
- /**
- * Creates a context type with an identifier. The identifier must be unique,
- * a qualified name is suggested. The id is also used as name.
- *
- * @param id the unique identifier of the context type
- */
- public TemplateContextType(String id) {
- this(id, id);
- }
-
- /**
- * Creates a context type with an identifier. The identifier must be unique, a qualified name is suggested.
- *
- * @param id the unique identifier of the context type
- * @param name the name of the context type
- */
- public TemplateContextType(String id, String name) {
- Assert.isNotNull(id);
- Assert.isNotNull(name);
- fId= id;
- fName= name;
- }
-
- /**
- * Returns the name of the context type.
- *
- * @return the name of the receiver
- */
- public String getId() {
- return fId;
- }
-
-
- /**
- * Returns the name of the context type.
- *
- * @return the name of the context type
- */
- public String getName() {
- return fName;
- }
-
- /**
- * Creates a context type with a <code>null</code> identifier.
- * <p>
- * This is a framework-only constructor that exists only so that context
- * types can be contributed via an extension point and that should not be
- * called in client code except for subclass constructors; use
- * {@link #TemplateContextType(String)} instead.
- * </p>
- */
- public TemplateContextType() {
- }
-
- /**
- * Sets the id of this context.
- * <p>
- * This is a framework-only method that exists solely so that context types
- * can be contributed via an extension point and that should not be called
- * in client code; use {@link #TemplateContextType(String)} instead.
- * </p>
- *
- * @param id the identifier of this context
- * @throws RuntimeException an unspecified exception if the id has already
- * been set on this context type
- */
- public final void setId(String id) throws RuntimeException {
- Assert.isNotNull(id);
- Assert.isTrue(fId == null); // may only be called once when the context is instantiated
- fId= id;
- }
-
- /**
- * Sets the name of the context type.
- *
- * <p>
- * This is a framework-only method that exists solely so that context types
- * can be contributed via an extension point and that should not be called
- * in client code; use {@link #TemplateContextType(String, String)} instead.
- * </p>
- *
- * @param name the name of the context type
- */
- public final void setName(String name) {
- Assert.isTrue(fName == null); // only initialized by extension code
- fName= name;
- }
-
- /**
- * Adds a variable resolver to the context type. If there already is a resolver
- * for the same type, the previous one gets replaced by <code>resolver</code>.
- *
- * @param resolver the resolver to be added under its name
- */
- public void addResolver(TemplateVariableResolver resolver) {
- Assert.isNotNull(resolver);
- fResolvers.put(resolver.getType(), resolver);
- }
-
- /**
- * Removes a template variable from the context type.
- *
- * @param resolver the variable to be removed
- */
- public void removeResolver(TemplateVariableResolver resolver) {
- Assert.isNotNull(resolver);
- fResolvers.remove(resolver.getType());
- }
-
- /**
- * Removes all template variables from the context type.
- */
- public void removeAllResolvers() {
- fResolvers.clear();
- }
-
- /**
- * Returns an iterator for the variables known to the context type.
- *
- * @return an iterator over the variables in this context type
- */
- public Iterator resolvers() {
- return Collections.unmodifiableMap(fResolvers).values().iterator();
- }
-
- /**
- * Returns the resolver for the given type.
- *
- * @param type the type for which a resolver is needed
- * @return a resolver for the given type, or <code>null</code> if none is registered
- */
- protected TemplateVariableResolver getResolver(String type) {
- return (TemplateVariableResolver) fResolvers.get(type);
- }
-
- /**
- * Validates a pattern, a <code>TemplateException</code> is thrown if
- * validation fails.
- *
- * @param pattern the template pattern to validate
- * @throws TemplateException if the pattern is invalid
- */
- public void validate(String pattern) throws TemplateException {
- TemplateTranslator translator= new TemplateTranslator();
- TemplateBuffer buffer= translator.translate(pattern);
- validateVariables(buffer.getVariables());
- }
-
- /**
- * Validates the variables in this context type. If a variable is not valid,
- * e.g. if its type is not known in this context type, a
- * <code>TemplateException</code> is thrown.
- * <p>
- * The default implementation does nothing.
- * </p>
- *
- * @param variables the variables to validate
- * @throws TemplateException if one of the variables is not valid in this
- * context type
- */
- protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
- }
-
- /**
- * Resolves the variables in <code>buffer</code> within <code>context</code>
- * and edits the template buffer to reflect the resolved variables.
- *
- * @param buffer the template buffer
- * @param context the template context
- * @throws MalformedTreeException if the positions in the buffer overlap
- * @throws BadLocationException if the buffer cannot be successfully modified
- */
- public void resolve(TemplateBuffer buffer, TemplateContext context) throws MalformedTreeException, BadLocationException {
- Assert.isNotNull(context);
- TemplateVariable[] variables= buffer.getVariables();
-
- List positions= variablesToPositions(variables);
- List edits= new ArrayList(5);
-
- // iterate over all variables and try to resolve them
- for (int i= 0; i != variables.length; i++) {
- TemplateVariable variable= variables[i];
-
- if (variable.isUnambiguous())
- continue;
-
- // remember old values
- int[] oldOffsets= variable.getOffsets();
- int oldLength= variable.getLength();
- String oldValue= variable.getDefaultValue();
-
- String type= variable.getType();
- TemplateVariableResolver resolver= (TemplateVariableResolver) fResolvers.get(type);
- if (resolver == null)
- resolver= new TemplateVariableResolver(type, ""); //$NON-NLS-1$
- resolver.resolve(variable, context);
-
- String value= variable.getDefaultValue();
-
- if (!oldValue.equals(value))
- // update buffer to reflect new value
- for (int k= 0; k != oldOffsets.length; k++)
- edits.add(new ReplaceEdit(oldOffsets[k], oldLength, value));
-
- }
-
- IDocument document= new Document(buffer.getString());
- MultiTextEdit edit= new MultiTextEdit(0, document.getLength());
- edit.addChildren((TextEdit[]) positions.toArray(new TextEdit[positions.size()]));
- edit.addChildren((TextEdit[]) edits.toArray(new TextEdit[edits.size()]));
- edit.apply(document, TextEdit.UPDATE_REGIONS);
-
- positionsToVariables(positions, variables);
-
- buffer.setContent(document.get(), variables);
- }
-
- private static List variablesToPositions(TemplateVariable[] variables) {
- List positions= new ArrayList(5);
- for (int i= 0; i != variables.length; i++) {
- int[] offsets= variables[i].getOffsets();
- for (int j= 0; j != offsets.length; j++)
- positions.add(new RangeMarker(offsets[j], 0));
- }
-
- return positions;
- }
-
- private static void positionsToVariables(List positions, TemplateVariable[] variables) {
- Iterator iterator= positions.iterator();
-
- for (int i= 0; i != variables.length; i++) {
- TemplateVariable variable= variables[i];
-
- int[] offsets= new int[variable.getOffsets().length];
- for (int j= 0; j != offsets.length; j++)
- offsets[j]= ((TextEdit) iterator.next()).getOffset();
-
- variable.setOffsets(offsets);
- }
- }
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java
deleted file mode 100644
index dda57ddeb..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateException.java
+++ /dev/null
@@ -1,59 +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;
-
-
-/**
- * Thrown when a template cannot be validated.
- * <p>
- * Clients may instantiate this class.
- * </p>
- *
- * @since 3.0
- */
-public class TemplateException extends Exception {
-
- /**
- * Creates a new template exception.
- */
- public TemplateException() {
- super();
- }
-
- /**
- * Creates a new template exception.
- *
- * @param message the message describing the problem that arised
- */
- public TemplateException(String message) {
- super(message);
- }
-
- /**
- * Creates a new template exception.
- *
- * @param message the message describing the problem that arised
- * @param cause the original exception
- */
- public TemplateException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new template exception.
- *
- * @param cause the original exception
- */
- public TemplateException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java
deleted file mode 100644
index 2703b7671..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateTranslator.java
+++ /dev/null
@@ -1,260 +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;
-import java.util.Set;
-import java.util.Vector;
-
-/**
- * The template translator translates a string into a template buffer. Regions
- * marked as variables are translated into <code>TemplateVariable</code>s.
- * <p>
- * The EBNF grammar of a valid string is as follows:</p>
- * <p>
- * template := (text | escape)*. <br />
- * text := character - dollar. <br />
- * escape := dollar ('{' identifier '}' | dollar). <br />
- * dollar := '$'. <br />
- * </p>
- * <p>
- * Clients may extend the <code>createVariable</code> method of this class.
- * </p>
- *
- * @since 3.0
- */
-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 occurred for the last translation,
- * <code>null</code> otherwise.
- *
- * @return the error message if an error occurred during the most recent
- * translation, <code>null</code> otherwise
- */
- public String getErrorMessage() {
- return fErrorMessage;
- }
-
- /**
- * Translates a template to a <code>TemplateBuffer</code>. <code>null</code>
- * is returned if there was an error. <code>getErrorMessage()</code> retrieves the
- * associated error message.
- *
- * @param template the template to translate.
- * @return returns the template buffer corresponding to the string, <code>null</code>
- * if there was an error.
- * @see #getErrorMessage()
- * @throws TemplateException if translation failed
- */
- public TemplateBuffer translate(Template template) throws TemplateException {
- return translate(template.getPattern());
- }
-
- /**
- * 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()
- * @throws TemplateException if translation failed
- */
- public TemplateBuffer translate(String string) throws TemplateException {
-
- fBuffer.setLength(0);
- fOffsets.clear();
- fLengths.clear();
- fState= TEXT;
- fErrorMessage= null;
-
- if (!parse(string))
- throw new TemplateException(fErrorMessage);
-
- switch (fState) {
- case TEXT:
- break;
-
- // illegal
- case ESCAPE:
- throw new TemplateException(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$
-
- // illegal
- case IDENTIFIER:
- throw new TemplateException(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$
- }
-
- 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();
- TemplateVariable[] variables= findVariables(translatedString, offsets, lengths);
-
- return new TemplateBuffer(translatedString, variables);
- }
-
- private TemplateVariable[] 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));
- }
-
- TemplateVariable[] variables= new TemplateVariable[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]= createVariable(name, name, offsets_);
- k++;
- }
-
- return variables;
- }
-
- /**
- * Hook method to create new variables. Subclasses may override to supply their
- * custom variable type.
- * <p>
- * Clients may replace this method.
- * </p>
- *
- * @param type the type of the new variable.
- * @param name the name of the new variable.
- * @param offsets the offsets where the variable occurs in the template
- * @return a new instance of <code>TemplateVariable</code>
- */
- protected TemplateVariable createVariable(String type, String name, int[] offsets) {
- return new TemplateVariable(type, name, offsets);
- }
-
- /**
- * Internal parser.
- *
- * @param string the string to parse
- * @return <code>true</code> if parsing was successful
- */
- 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= TextTemplateMessages.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(ch) &&
- !Character.isUnicodeIdentifierPart(ch))
- {
- // illegal identifier character
- fErrorMessage= TextTemplateMessages.getString("TemplateTranslator.error.invalid.identifier"); //$NON-NLS-1$
- return false;
- }
-
- fBuffer.append(ch);
- break;
- }
- break;
- }
- }
-
- return true;
- }
-
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java
deleted file mode 100644
index 8d47a2b43..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariable.java
+++ /dev/null
@@ -1,201 +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.Assert;
-
-/**
- * A <code>TemplateVariable</code> represents a set of positions into a
- * <code>TemplateBuffer</code> with identical content each. <code>TemplateVariableResolver</code>s
- * can be used to resolve a template variable to a symbol available from the
- * <code>TemplateContext</code>.
- * <p>
- * Clients may instantiate and extend this class.
- * </p>
- *
- * @see TemplateVariableResolver
- * @see TemplateBuffer
- * @since 3.0
- */
-public class TemplateVariable {
-
- /** The type name of the variable */
- private final String fType;
- /** The name of the variable. */
- private final String fName;
- /** The offsets of the variable. */
- private int[] fOffsets;
- /** Flag indicating if the variable has been resolved unambiguously. */
- private boolean fIsUnambiguous;
- /**
- * The proposal strings available for this variable. The first string is
- * the default value.
- */
- private String[] fValues;
-
- /**
- * Creates a template variable. The type is used as the name of the
- * variable.
- *
- * @param type the type of the variable
- * @param defaultValue the default value of the variable
- * @param offsets the array of offsets of the variable
- */
- public TemplateVariable(String type, String defaultValue, int[] offsets) {
- this(type, new String[] { defaultValue }, offsets);
- }
-
- /**
- * Creates a template variable.
- *
- * @param type the type of the variable
- * @param name the name of the variable
- * @param defaultValue the default value of the variable
- * @param offsets the array of offsets of the variable
- */
- public TemplateVariable(String type, String name, String defaultValue, int[] offsets) {
- this(type, name, new String[] { defaultValue }, offsets);
- }
-
- /**
- * Creates a template variable with multiple possible values. The type is
- * used as the name of the template.
- *
- * @param type the type of the template variable
- * @param values the values available at this variable, non-empty
- * @param offsets the array of offsets of the variable
- */
- public TemplateVariable(String type, String[] values, int[] offsets) {
- this(type, type, values, offsets);
- }
-
- /**
- * Creates a template variable with multiple possible values.
- *
- * @param type the type of the variable
- * @param name the name of the variable
- * @param values the values available at this variable, non-empty
- * @param offsets the array of offsets of the variable
- */
- public TemplateVariable(String type, String name, String[] values, int[] offsets) {
- Assert.isNotNull(type);
- Assert.isNotNull(name);
- fType= type;
- fName= name;
- setValues(values);
- setOffsets(offsets);
- setUnambiguous(false);
- }
-
- /**
- * Returns the type of the variable.
- *
- * @return the type of the variable
- */
- public String getType() {
- return fType;
- }
-
- /**
- * Returns the name of the variable.
- *
- * @return the name of the variable
- */
- public String getName() {
- return fName;
- }
-
- /**
- * Returns the default value of the variable.
- *
- * @return the default value of the variable
- */
- public String getDefaultValue() {
- return getValues()[0];
- }
-
- /**
- * Returns the possible values for this variable. The returned array is
- * owned by this variable and must not be modified.
- *
- * @return the possible values for this variable
- */
- public String[] getValues() {
- return fValues;
- }
-
- /**
- * Returns the length of the variable.
- *
- * @return the length of the variable
- */
- public int getLength() {
- return getDefaultValue().length();
- }
-
- /**
- * Sets the offsets of the variable.
- *
- * @param offsets the new offsets of the variable
- */
- public void setOffsets(int[] offsets) {
- fOffsets= offsets;
- }
-
- /**
- * Returns the offsets of the variable.
- *
- * @return the length of the variable
- */
- public int[] getOffsets() {
- return fOffsets;
- }
-
- /**
- * Sets the default value for this variable. This is a shortcut for
- * <code>setValues(new String[] { value })</code>.
- *
- * @param value the new default value
- */
- public final void setValue(String value) {
- setValues(new String[] { value });
- }
-
- /**
- * Sets the possible values for this variable, with the first being the
- * default value.
- *
- * @param values a non-empty array of values
- */
- public void setValues(String[] values) {
- Assert.isTrue(values.length > 0);
- fValues= values;
- }
-
- /**
- * Sets the isUnambiguous flag of the variable.
- *
- * @param unambiguous the new unambiguous state of the variable
- */
- public void setUnambiguous(boolean unambiguous) {
- fIsUnambiguous= unambiguous;
- }
-
- /**
- * Returns <code>true</code> if the variable is unambiguously resolved, <code>false</code> otherwise.
- *
- * @return <code>true</code> if the variable is unambiguously resolved, <code>false</code> otherwise
- */
- public boolean isUnambiguous() {
- return fIsUnambiguous;
- }
-
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java
deleted file mode 100644
index 1b12fa4f5..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TemplateVariableResolver.java
+++ /dev/null
@@ -1,172 +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.Assert;
-
-/**
- * A <code>TemplateVariableResolver</code> resolves <code>TemplateVariables</code>
- * of a certain type inside a <code>TemplateContext</code>.
- * <p>
- * Clients may instantiate and extend this class.
- * </p>
- *
- * @see TemplateVariable
- * @since 3.0
- */
-public class TemplateVariableResolver {
-
- /** Type of this resolver. */
- private String fType= null;
-
- /** Description of the type resolved by this resolver. */
- private String fDescription= null;
-
- /**
- * Creates an instance of <code>TemplateVariableResolver</code>.
- *
- * @param type the name of the type
- * @param description the description for the type
- */
- protected TemplateVariableResolver(String type, String description) {
- setType(type);
- setDescription(description);
- }
-
- /**
- * Creates an empty instance.
- * <p>
- * This is a framework-only constructor that exists only so that resolvers
- * can be contributed via an extension point and that should not be called
- * in client code except for subclass constructors; use
- * {@link #TemplateVariableResolver(String, String)} instead.
- * </p>
- */
- public TemplateVariableResolver() {
- }
-
- /**
- * Returns the type of this resolver.
- *
- * @return the type
- */
- public String getType() {
- return fType;
- }
-
- /**
- * Returns the description for the resolver.
- *
- * @return the description for the resolver
- */
- public String getDescription() {
- return fDescription;
- }
-
- /**
- * Returns an instance of the type resolved by the receiver available in <code>context</code>.
- * To resolve means to provide a binding to a concrete text object (a
- * <code>String</code>) in the given context.
- * <p>
- * The default implementation looks up the type in the context.</p>
- *
- * @param context the context in which to resolve the type
- * @return the name of the text object of this type, or <code>null</code> if it cannot be determined
- */
- protected String resolve(TemplateContext context) {
- return context.getVariable(getType());
- }
-
- /**
- * Returns all possible bindings available in <code>context</code>. The default
- * implementation simply returns an array which contains the result of
- * {@link #resolve(TemplateContext)}, or an empty array if that call returns
- * <code>null</code>.
- *
- * @param context the context in which to resolve the type
- * @return an array of possible bindings of this type in <code>context</code>
- */
- protected String[] resolveAll(TemplateContext context) {
- String binding= resolve(context);
- if (binding == null)
- return new String[0];
- else
- return new String[] { binding };
- }
-
- /**
- * Resolves <code>variable</code> in <code>context</code>. To resolve
- * means to find a valid binding of the receiver's type in the given <code>TemplateContext</code>.
- * If the variable can be successfully resolved, its value is set using
- * {@link TemplateVariable#setValues(String[])}.
- *
- * @param context the context in which variable is resolved
- * @param variable the variable to resolve
- */
- public void resolve(TemplateVariable variable, TemplateContext context) {
- String[] bindings= resolveAll(context);
- if (bindings.length != 0)
- variable.setValues(bindings);
- if (bindings.length > 1)
- variable.setUnambiguous(false);
- else
- variable.setUnambiguous(isUnambiguous(context));
- }
-
- /**
- * Returns whether this resolver is able to resolve unambiguously. When
- * resolving a <code>TemplateVariable</code>, its <code>isUmambiguous</code>
- * state is set to the one of this resolver. By default, this method
- * returns <code>false</code>. Clients can overwrite this method to give
- * a hint about whether there should be e.g. prompting for input values for
- * ambiguous variables.
- *
- * @param context the context in which the resolved check should be
- * evaluated
- * @return <code>true</code> if the receiver is unambiguously resolvable
- * in <code>context</code>, <code>false</code> otherwise
- */
- protected boolean isUnambiguous(TemplateContext context) {
- return false;
- }
-
- /**
- * Sets the description.
- * <p>
- * This is a framework-only method that exists only so that resolvers
- * can be contributed via an extension point and that should not be called
- * in client code; use {@link #TemplateVariableResolver(String, String)} instead.
- * </p>
- *
- * @param description the description of this resolver
- */
- public final void setDescription(String description) {
- Assert.isNotNull(description);
- Assert.isTrue(fDescription == null); // may only be called once when initialized
- fDescription= description;
- }
-
- /**
- * Sets the type.
- * <p>
- * This is a framework-only method that exists only so that resolvers
- * can be contributed via an extension point and that should not be called
- * in client code; use {@link #TemplateVariableResolver(String, String)} instead.
- * </p>
- *
- * @param type the type of this resolver
- */
- public final void setType(String type) {
- Assert.isNotNull(type);
- Assert.isTrue(fType == null); // may only be called once when initialized
- fType= type;
- }
-}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.java b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.java
deleted file mode 100644
index c300969b5..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.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 TextTemplateMessages {
-
- private static final String RESOURCE_BUNDLE= TextTemplateMessages.class.getName();
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private TextTemplateMessages() {
- }
-
- /**
- * @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.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties b/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties
deleted file mode 100644
index cf0e49e19..000000000
--- a/org.eclipse.text/src/org/eclipse/jface/text/templates/TextTemplateMessages.properties
+++ /dev/null
@@ -1,24 +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 translator
-TemplateTranslator.error.incomplete.variable=Template has incomplete variables. Use '$$' to insert the dollar symbol.
-TemplateTranslator.error.invalid.identifier=Template has invalid variable identifiers.
-
-# global variables
-GlobalVariables.variable.description.cursor=The cursor position after editing template variables
-GlobalVariables.variable.description.dollar=The dollar symbol
-GlobalVariables.variable.description.date=Current date
-GlobalVariables.variable.description.year=Current year
-GlobalVariables.variable.description.time=Current time
-GlobalVariables.variable.description.user=User name
-GlobalVariables.variable.description.selectedWord= The selected word
-GlobalVariables.variable.description.selectedLines= The selected lines
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/templates/package.html b/org.eclipse.text/src/org/eclipse/jface/text/templates/package.html
deleted file mode 100644
index e70145a0f..000000000
--- a/org.eclipse.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>

Back to the top