1 11 12 package org.eclipse.ant.internal.ui.editor.templates; 13 14 import org.eclipse.ant.internal.ui.AntUIPlugin; 15 import org.eclipse.ant.internal.ui.editor.formatter.FormattingPreferences; 16 import org.eclipse.ant.internal.ui.editor.formatter.XmlFormatter; 17 import org.eclipse.ant.internal.ui.model.IAntModel; 18 import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; 19 import org.eclipse.jface.text.BadLocationException; 20 import org.eclipse.jface.text.IDocument; 21 import org.eclipse.jface.text.Position; 22 import org.eclipse.jface.text.templates.DocumentTemplateContext; 23 import org.eclipse.jface.text.templates.Template; 24 import org.eclipse.jface.text.templates.TemplateBuffer; 25 import org.eclipse.jface.text.templates.TemplateContextType; 26 import org.eclipse.jface.text.templates.TemplateException; 27 28 public class AntContext extends DocumentTemplateContext { 29 30 private IAntModel fAntModel; 31 32 public AntContext(TemplateContextType type, IDocument document, IAntModel model, Position position) { 33 super(type, document, position); 34 fAntModel= model; 35 } 36 37 40 public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { 41 42 TemplateBuffer templateBuffer= super.evaluate(template); 43 44 if (templateBuffer == null) { 45 return null; 46 } 47 if (false && AntUIPlugin.getDefault().getPreferenceStore().getBoolean(AntEditorPreferenceConstants.TEMPLATES_USE_CODEFORMATTER)) { 49 FormattingPreferences prefs = new FormattingPreferences(); 50 XmlFormatter.format(templateBuffer, this, prefs); 51 } 52 return templateBuffer; 53 } 54 55 58 public IAntModel getAntModel() { 59 return fAntModel; 60 } 61 62 65 public int getEnd() { 66 int replacementOffset = getCompletionOffset(); 67 int replacementLength = getCompletionLength(); 68 if (replacementOffset > 0 && getDocument().get().charAt(replacementOffset - 1) == '<' && getDocument().getLength() > 1) { 69 replacementLength++; 70 } 71 return replacementLength + replacementOffset; 72 } 73 74 77 public int getStart() { 78 int replacementOffset= getCompletionOffset(); 79 if (replacementOffset > 0 && getDocument().get().charAt(replacementOffset - 1) == '<') { 80 replacementOffset--; 81 } 82 return replacementOffset; 83 } 84 } 85 | Popular Tags |