本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateBuffer类的典型用法代码示例。如果您正苦于以下问题:Java TemplateBuffer类的具体用法?Java TemplateBuffer怎么用?Java TemplateBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateBuffer类属于org.eclipse.jface.text.templates包,在下文中一共展示了TemplateBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
// test that all variables are defined
Iterator<TemplateVariableResolver> iterator= getContextType().resolvers();
while (iterator.hasNext()) {
TemplateVariableResolver var= iterator.next();
if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
if (!canEvaluate(template)) {
return null;
}
String pattern= changeLineDelimiter(template.getPattern(), fLineDelimiter);
TemplateTranslator translator= new TemplateTranslator();
TemplateBuffer buffer= translator.translate(pattern);
getContextType().resolve(buffer, this);
return buffer;
}
示例2: format
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Formats the template buffer.
*
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
VariableTracker tracker = new VariableTracker(buffer);
IDocument document = tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}
示例3: evaluate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
// test that all variables are defined
Iterator<TemplateVariableResolver> iterator = getContextType().resolvers();
while (iterator.hasNext()) {
TemplateVariableResolver var = iterator.next();
if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
Assert.isNotNull(
getVariable(var.getType()),
"Variable " + var.getType() + "not defined"); // $NON-NLS-1$ //$NON-NLS-2$
}
}
if (!canEvaluate(template)) return null;
String pattern = changeLineDelimiter(template.getPattern(), fLineDelimiter);
TemplateTranslator translator = new TemplateTranslator();
TemplateBuffer buffer = translator.translate(pattern);
getContextType().resolve(buffer, this);
return buffer;
}
示例4: evaluate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
TemplateTranslator translator = new TemplateTranslator();
TemplateBuffer buffer = translator.translate(template);
getContextType().resolve(buffer, this);
// IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
boolean useCodeFormatter =
true; // prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);
IJavaProject project = getJavaProject();
JavaFormatter formatter =
new JavaFormatter(
TextUtilities.getDefaultLineDelimiter(getDocument()),
getIndentation(),
useCodeFormatter,
project);
formatter.format(buffer, this);
return buffer;
}
示例5: getAdditionalProposalInfo
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
@Override
public String getAdditionalProposalInfo() {
this.getContext().setReadOnly(true);
TemplateBuffer templateBuffer;
try {
templateBuffer= this.getContext().evaluate(this.getTemplate());
}
catch (BadLocationException | TemplateException ex) {
String message = "<b>Error when resolving variables.</b><br>"
+ "Nothing will be inserted<br><br>"
+ escapeHTML(ex.getMessage());
return message;
}
String info = escapeHTML(this.getTemplate().getDescription()) +
"<br><br><b>Inserts:</b><br>" +
escapeHTML(templateBuffer.getString());
return info;
}
示例6: evaluate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException
{
if (!canEvaluate(template))
return null;
try
{
this.template = template;
TemplateTranslator translator = new SnippetTemplateTranslator();
TemplateBuffer buffer = translator.translate(template);
getContextType().resolve(buffer, this);
return buffer;
}
finally
{
this.template = null;
}
}
示例7: format
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Formats the template buffer.
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, TemplateContext context) throws BadLocationException {
try {
VariableTracker tracker= new VariableTracker(buffer);
IDocument document= tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}
示例8: evaluate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
// test that all variables are defined
Iterator<TemplateVariableResolver> iterator= getContextType().resolvers();
while (iterator.hasNext()) {
TemplateVariableResolver var= iterator.next();
if (var instanceof CodeTemplateContextType.CodeTemplateVariableResolver) {
Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined"); //$NON-NLS-1$ //$NON-NLS-2$
}
}
if (!canEvaluate(template))
return null;
String pattern= changeLineDelimiter(template.getPattern(), fLineDelimiter);
TemplateTranslator translator= new TemplateTranslator();
TemplateBuffer buffer= translator.translate(pattern);
getContextType().resolve(buffer, this);
return buffer;
}
示例9: evaluateTemplate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Evaluates a 'java' template in the context of a compilation unit
*
* @param template the template to be evaluated
* @param compilationUnit the compilation unit in which to evaluate the template
* @param position the position inside the compilation unit for which to evaluate the template
* @return the evaluated template
* @throws CoreException in case the template is of an unknown context type
* @throws BadLocationException in case the position is invalid in the compilation unit
* @throws TemplateException in case the evaluation fails
*/
public static String evaluateTemplate(Template template, ICompilationUnit compilationUnit, int position) throws CoreException, BadLocationException, TemplateException {
TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId());
if (!(contextType instanceof CompilationUnitContextType))
throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, JavaTemplateMessages.JavaContext_error_message, null));
IDocument document= new Document();
if (compilationUnit != null && compilationUnit.exists())
document.set(compilationUnit.getSource());
CompilationUnitContext context= ((CompilationUnitContextType) contextType).createContext(document, position, 0, compilationUnit);
context.setForceEvaluation(true);
TemplateBuffer buffer= context.evaluate(template);
if (buffer == null)
return null;
return buffer.getString();
}
示例10: evaluate
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
TemplateTranslator translator= new TemplateTranslator();
TemplateBuffer buffer= translator.translate(template);
getContextType().resolve(buffer, this);
IPreferenceStore prefs= JavaPlugin.getDefault().getPreferenceStore();
boolean useCodeFormatter= prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);
IJavaProject project= getJavaProject();
JavaFormatter formatter= new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
formatter.format(buffer, this);
return buffer;
}
示例11: fixEmptyVariables
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
IDocument doc= new Document(buffer.getString());
int nLines= doc.getNumberOfLines();
MultiTextEdit edit= new MultiTextEdit();
HashSet<Integer> removedLines= new HashSet<Integer>();
for (int i= 0; i < variables.length; i++) {
TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
if (position == null || position.getLength() > 0) {
continue;
}
int[] offsets= position.getOffsets();
for (int k= 0; k < offsets.length; k++) {
int line= doc.getLineOfOffset(offsets[k]);
IRegion lineInfo= doc.getLineInformation(line);
int offset= lineInfo.getOffset();
String str= doc.get(offset, lineInfo.getLength());
if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
int nextStart= doc.getLineOffset(line + 1);
edit.addChild(new DeleteEdit(offset, nextStart - offset));
}
}
}
edit.apply(doc, 0);
return doc.get();
}
示例12: getTemplateString
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Returns template string to insert.
*
* @param context the context to use when rendering the template
* @return String to insert or null if none is to be inserted
*/
public final String getTemplateString(final TemplateContext context) {
String templateString = null;
if (useTemplateButton.getSelection()) {
Template template = getSelectedTemplate();
if (template != null) {
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
} catch (BadLocationException | TemplateException e) {
final String msg = "Unable to create template for new component";
final IStatus status = new Status(IStatus.WARNING, ForceIdeEditorsPlugin.PLUGIN_ID, msg, e);
logger().log(status);
}
}
}
return templateString;
}
示例13: getTemplateString
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Returns template string to insert.
*
* @return String to insert or null if none is to be inserted
*/
String getTemplateString() {
String templateString = null;
Template template = getSelectedTemplate();
if (template != null) {
TemplateContextType contextType = GlassmakerUIPlugin.getDefault().getTemplateContextRegistry().getContextType(CardContextType.CONTEXT_TYPE);
IDocument document = new Document();
TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
}
catch (Exception e) {
GlassmakerUIPlugin.logError("Could not create template for new html", e);
}
}
return templateString;
}
示例14: getTemplateString
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Returns template string to insert.
*
* @return String to insert or null if none is to be inserted
*/
public String getTemplateString() {
String templateString = null;
Template template = getSelectedTemplate();
if (template != null) {
TemplateContextType contextType=SilverStripePDTPlugin.getDefault().getTemplateContextRegistry().getContextType(this._languageProvider.getTemplateContext());
IDocument document = new Document();
TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
}
catch (Exception e) {
Logger.log(Logger.WARNING_DEBUG, "Could not create template for new html", e); //$NON-NLS-1$
}
}
return templateString;
}
开发者ID:UndefinedOffset,项目名称:eclipse-silverstripedt,代码行数:25,代码来源:NewSilverStripeTemplatesWizardPage.java
示例15: format
import org.eclipse.jface.text.templates.TemplateBuffer; //导入依赖的package包/类
/**
* Formats the template buffer.
* @param buffer
* @param context
* @throws BadLocationException
*/
public void format(TemplateBuffer buffer, CompilationUnitContext context) throws BadLocationException {
try {
VariableTracker tracker= new VariableTracker(buffer);
IDocument document= tracker.getDocument();
internalFormat(document, context);
convertLineDelimiters(document);
if (!(context instanceof JavaDocContext) && !isReplacedAreaEmpty(context))
trimStart(document);
tracker.updateBuffer();
} catch (MalformedTreeException e) {
throw new BadLocationException();
}
}