use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getSetterComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getSetterComment(ICompilationUnit, String, String, String, String, String, String, String)
*/
public static String getSetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String paramName, String bareFieldName, String lineDelimiter) throws CoreException {
String templateName = CodeTemplateContextType.SETTERCOMMENT_ID;
Template template = getCodeTemplate(templateName, 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);
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getTypeComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getTypeComment(ICompilationUnit, String, String[], String)
*/
public static String getTypeComment(ICompilationUnit cu, String typeQualifiedName, String[] typeParameterNames, String lineDelim) throws CoreException {
Template template = getCodeTemplate(CodeTemplateContextType.TYPECOMMENT_ID, cu.getJavaProject());
if (template == null) {
return null;
}
CodeTemplateContext context = new CodeTemplateContext(template.getContextTypeId(), cu.getJavaProject(), lineDelim);
context.setCompilationUnitVariables(cu);
context.setVariable(CodeTemplateContextType.ENCLOSING_TYPE, Signature.getQualifier(typeQualifiedName));
context.setVariable(CodeTemplateContextType.TYPENAME, Signature.getSimpleName(typeQualifiedName));
TemplateBuffer buffer;
try {
buffer = context.evaluate(template);
} catch (BadLocationException e) {
throw new CoreException(Status.CANCEL_STATUS);
} catch (TemplateException e) {
throw new CoreException(Status.CANCEL_STATUS);
}
String str = buffer.getString();
if (Strings.containsOnlyWhitespaces(str)) {
return null;
}
// look if Javadoc tags have to be added
TemplateVariable position = findVariable(buffer, CodeTemplateContextType.TAGS);
if (position == null) {
return str;
}
IDocument document = new Document(str);
int[] tagOffsets = position.getOffsets();
for (int i = tagOffsets.length - 1; i >= 0; i--) {
// from last to first
try {
insertTag(document, tagOffsets[i], position.getLength(), EMPTY, EMPTY, null, typeParameterNames, false, lineDelim);
} catch (BadLocationException e) {
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
}
}
return document.get();
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method getGetterComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getGetterComment(ICompilationUnit, String, String, String, String, String, String)
*/
public static String getGetterComment(ICompilationUnit cu, String typeName, String methodName, String fieldName, String fieldType, String bareFieldName, String lineDelimiter) throws CoreException {
String templateName = CodeTemplateContextType.GETTERCOMMENT_ID;
Template template = getCodeTemplate(templateName, 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);
}
use of org.eclipse.jface.text.templates.Template in project flux by eclipse.
the class StubUtility method setCodeTemplate.
/**
* Only to be used by tests
*
* @param templateId the template id
* @param pattern the new pattern
* @param project not used
*/
public static void setCodeTemplate(String templateId, String pattern, IJavaProject project) {
TemplateStore codeTemplateStore = JavaPlugin.getDefault().getCodeTemplateStore();
TemplatePersistenceData data = codeTemplateStore.getTemplateData(templateId);
Template orig = data.getTemplate();
Template copy = new Template(orig.getName(), orig.getDescription(), orig.getContextTypeId(), pattern, true);
data.setTemplate(copy);
}
use of org.eclipse.jface.text.templates.Template in project dbeaver by serge-rider.
the class SQLCompletionProcessor method makeTemplateProposals.
@NotNull
private ICompletionProposal[] makeTemplateProposals(ITextViewer viewer, SQLCompletionAnalyzer.CompletionRequest request) {
String wordPart = request.wordPart.toLowerCase();
final List<SQLTemplateCompletionProposal> templateProposals = new ArrayList<>();
// Templates
for (Template template : editor.getTemplatesPage().getTemplateStore().getTemplates()) {
if (template.getName().toLowerCase().startsWith(wordPart)) {
templateProposals.add(new SQLTemplateCompletionProposal(template, new SQLContext(SQLTemplatesRegistry.getInstance().getTemplateContextRegistry().getContextType(template.getContextTypeId()), viewer.getDocument(), new Position(request.wordDetector.getStartOffset(), request.wordDetector.getLength()), editor), new Region(request.documentOffset, 0), null));
}
}
Collections.sort(templateProposals, new Comparator<SQLTemplateCompletionProposal>() {
@Override
public int compare(SQLTemplateCompletionProposal o1, SQLTemplateCompletionProposal o2) {
return o1.getDisplayString().compareTo(o2.getDisplayString());
}
});
return templateProposals.toArray(new ICompletionProposal[templateProposals.size()]);
}
Aggregations