本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateBuffer.getString方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateBuffer.getString方法的具体用法?Java TemplateBuffer.getString怎么用?Java TemplateBuffer.getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jface.text.templates.TemplateBuffer
的用法示例。
在下文中一共展示了TemplateBuffer.getString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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;
}
示例4: 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;
}
示例5: 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
示例6: 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,
JavaPlugin.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();
}
示例7: 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();
}
示例8: evaluateSnippet
import org.eclipse.jface.text.templates.TemplateBuffer; //导入方法依赖的package包/类
/**
* Evaluate a snippet by replacing the tab stops with the default values. Note the snippet must have a scope or else
* the evaluation is not done
*
* @param snippet
* @param document
* @param position
* @return
*/
public static String evaluateSnippet(SnippetElement snippet, IDocument document, Position position)
{
String expansion = snippet.getExpansion();
Template template = new SnippetTemplate(snippet, expansion);
String scope = snippet.getScope();
if (scope != null)
{
SnippetTemplateContextType contextType = new SnippetTemplateContextType(scope);
DocumentSnippetTemplateContext context = new DocumentSnippetTemplateContext(contextType, document, position);
try
{
TemplateBuffer buffer = context.evaluate(template);
if (buffer != null)
{
return buffer.getString();
}
}
catch (Exception e)
{
IdeLog.logWarning(
CommonEditorPlugin.getDefault(),
MessageFormat.format("Error in template {0}. {1}", snippet.getDisplayName(), e.getMessage()), IDebugScopes.PRESENTATION); //$NON-NLS-1$
}
}
return expansion;
}