本文整理汇总了Java中org.eclipse.jface.text.templates.Template类的典型用法代码示例。如果您正苦于以下问题:Java Template类的具体用法?Java Template怎么用?Java Template使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Template类属于org.eclipse.jface.text.templates包,在下文中一共展示了Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TweakedTemplateProposal
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
/**
* 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 TweakedTemplateProposal(Template template, TemplateContext context, IRegion region, Image image,
int relevance) {
Assert.isNotNull(template);
Assert.isNotNull(context);
Assert.isNotNull(region);
fTemplate = template;
Check.isTrue(context instanceof FtcDocumentTemplateContext);
fContext = (FtcDocumentTemplateContext) context;
fImage = image;
fRegion = region;
fDisplayString = null;
fRelevance = relevance;
}
示例2: evaluate
import org.eclipse.jface.text.templates.Template; //导入依赖的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;
}
示例3: getSetterMethodBodyContent
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getSetterMethodBodyContent(IJavaProject project, String destTypeName, String methodName, String fieldName, String paramName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERBOY;
Template template = templateSetting.createTemplate(project);
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldName);
context.setVariable(CodeTemplateContextType.PARAM, paramName);
return evaluateTemplate(context, template);
}
示例4: getSetterComment
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getSetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String paramName, String bareFieldName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.SETTERCOMMENT;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);
context.setVariable(CodeTemplateContextType.PARAM, paramName);
return evaluateTemplate(context, template);
}
示例5: getGetterComment
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getGetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String bareFieldName, String lineDelimiter) throws CoreException {
CodeGenerationTemplate templateSetting = CodeGenerationTemplate.GETTERCOMMENT;
Template template = templateSetting.createTemplate(cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, typeName);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldType);
context.setVariable(CodeTemplateContextType.BARE_FIELD_NAME, bareFieldName);
return evaluateTemplate(context, template);
}
示例6: createTemplates
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
@Override
protected void createTemplates(final TemplateContext templateContext, final ContentAssistContext context, final ITemplateAcceptor acceptor) {
if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.ConfiguredCheck")) { //$NON-NLS-1$
addConfiguredCheckTemplates(templateContext, context, acceptor);
return;
} else if (templateContext.getContextType().getId().equals("com.avaloq.tools.ddk.checkcfg.CheckCfg.kw_catalog")) { //$NON-NLS-1$
addCatalogConfigurations(templateContext, context, acceptor);
}
TemplateContextType contextType = templateContext.getContextType();
Template[] templates = templateStore.getTemplates(contextType.getId());
for (Template template : templates) {
if (!acceptor.canAcceptMoreTemplates()) {
return;
}
if (validate(template, templateContext)) {
acceptor.accept(createProposal(template, templateContext, context, getImage(template), getRelevance(template)));
}
}
}
示例7: getColumnText
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public String getColumnText(Object element, int columnIndex) {
TemplatePersistenceData data = (TemplatePersistenceData) element;
Template template= data.getTemplate();
switch (columnIndex) {
case 0:
return template.getName();
case 1:
TemplateContextType type= fContextTypeRegistry.getContextType(template.getContextTypeId());
if (type != null)
return type.getName();
return template.getContextTypeId();
case 2:
return template.getDescription();
case 3:
return template.isAutoInsertable() ? TemplatesMessages.TemplatePreferencePage_on : ""; //$NON-NLS-1$
default:
return ""; //$NON-NLS-1$
}
}
示例8: add
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
private void add() {
Iterator it= fContextTypeRegistry.contextTypes();
if (it.hasNext()) {
Template template= new Template("", "", ((TemplateContextType) it.next()).getId(), "", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Template newTemplate= editTemplate(template, false, true);
if (newTemplate != null) {
TemplatePersistenceData data= new TemplatePersistenceData(newTemplate, true);
fTemplateStore.add(data);
fTableViewer.refresh();
fTableViewer.setChecked(data, true);
fTableViewer.setSelection(new StructuredSelection(data));
}
}
}
示例9: evaluate
import org.eclipse.jface.text.templates.Template; //导入依赖的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;
}
示例10: evaluate
import org.eclipse.jface.text.templates.Template; //导入依赖的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;
}
示例11: getGetterMethodBodyContent
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getGetterMethodBodyContent(
IJavaProject project,
String destTypeName,
String methodName,
String fieldName,
String lineDelimiter)
throws CoreException {
String templateName = CodeTemplateContextType.GETTERSTUB_ID;
Template template = getCodeTemplate(templateName, project);
if (template == null) {
return null;
}
CodeTemplateContext context =
new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
return evaluateTemplate(context, template);
}
示例12: getSetterMethodBodyContent
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getSetterMethodBodyContent(
IJavaProject project,
String destTypeName,
String methodName,
String fieldName,
String paramName,
String lineDelimiter)
throws CoreException {
String templateName = CodeTemplateContextType.SETTERSTUB_ID;
Template template = getCodeTemplate(templateName, project);
if (template == null) {
return null;
}
CodeTemplateContext context =
new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, methodName);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, destTypeName);
context.setVariable(CodeTemplateContextType.FIELD, fieldName);
context.setVariable(CodeTemplateContextType.FIELD_TYPE, fieldName);
context.setVariable(CodeTemplateContextType.PARAM, paramName);
return evaluateTemplate(context, template);
}
示例13: getCatchBodyContent
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getCatchBodyContent(
ICompilationUnit cu,
String exceptionType,
String variableName,
String enclosingType,
String enclosingMethod,
String lineDelimiter)
throws CoreException {
Template template = getCodeTemplate(CodeTemplateContextType.CATCHBLOCK_ID, cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context =
new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelimiter);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, enclosingType);
context.setVariable(CodeTemplateContextType.ENCLOSING_METHOD, enclosingMethod);
context.setVariable(CodeTemplateContextType.EXCEPTION_TYPE, exceptionType);
context.setVariable(CodeTemplateContextType.EXCEPTION_VAR, variableName);
return evaluateTemplate(context, template);
}
示例14: getFileComment
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
public static String getFileComment(ICompilationUnit cu, String lineDelimiter)
throws CoreException {
Template template =
getCodeTemplate(CodeTemplateContextType.FILECOMMENT_ID, cu.getJavaProject());
if (template == null) {
return null;
}
IJavaProject project = cu.getJavaProject();
CodeTemplateContext context =
new CodeTemplateContext(template.getContextTypeId(), project, lineDelimiter);
context.setCompilationUnitVariables(cu);
context.setVariable(
CodeTemplateContextType.TYPENAME, JavaCore.removeJavaLikeExtension(cu.getElementName()));
return evaluateTemplate(context, template);
}
示例15: getTypeBody
import org.eclipse.jface.text.templates.Template; //导入依赖的package包/类
/**
* Don't use this method directly, use CodeGeneration.
*
* @param templateID the template id of the type body to get. Valid id's are {@link
* CodeTemplateContextType#CLASSBODY_ID}, {@link CodeTemplateContextType#INTERFACEBODY_ID},
* {@link CodeTemplateContextType#ENUMBODY_ID}, {@link
* CodeTemplateContextType#ANNOTATIONBODY_ID},
* @param cu the compilation unit to which the template is added
* @param typeName the type name
* @param lineDelim the line delimiter to use
* @return return the type body template or <code>null</code>
* @throws CoreException thrown if the template could not be evaluated
* @see org.eclipse.jdt.ui.CodeGeneration#getTypeBody(String, ICompilationUnit, String, String)
*/
public static String getTypeBody(
String templateID, ICompilationUnit cu, String typeName, String lineDelim)
throws CoreException {
if (!VALID_TYPE_BODY_TEMPLATES.contains(templateID)) {
throw new IllegalArgumentException("Invalid code template ID: " + templateID); // $NON-NLS-1$
}
Template template = getCodeTemplate(templateID, cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context =
new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelim);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.TYPENAME, typeName);
return evaluateTemplate(context, template);
}