use of org.eclipse.jface.text.templates.TemplateVariable in project dbeaver by dbeaver.
the class SQLEntityResolver method resolveTables.
static void resolveTables(DBRProgressMonitor monitor, DBCExecutionContext executionContext, TemplateContext context, List<DBSEntity> entities) throws DBException {
TemplateVariable schemaVariable = ((SQLContext) context).getTemplateVariable(SQLContainerResolver.VAR_NAME_SCHEMA);
TemplateVariable catalogVariable = ((SQLContext) context).getTemplateVariable(SQLContainerResolver.VAR_NAME_CATALOG);
String catalogName = catalogVariable == null ? null : catalogVariable.getDefaultValue();
String schemaName = schemaVariable == null ? null : schemaVariable.getDefaultValue();
DBSObjectContainer objectContainer = DBUtils.getAdapter(DBSObjectContainer.class, executionContext.getDataSource());
if (objectContainer == null) {
return;
}
if (!CommonUtils.isEmpty(catalogName) || !CommonUtils.isEmpty(schemaName)) {
// Find container for specified schema/catalog
objectContainer = (DBSObjectContainer) DBUtils.getObjectByPath(monitor, executionContext, objectContainer, catalogName, schemaName, null);
} else {
objectContainer = DBUtils.getSelectedObject(executionContext, DBSObjectContainer.class);
}
if (objectContainer != null) {
makeProposalsFromChildren(monitor, objectContainer, entities);
}
}
use of org.eclipse.jface.text.templates.TemplateVariable in project che by eclipse.
the class TypeVariableResolver method resolve.
/*
* @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
* @since 3.3
*/
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
if (!(variable instanceof MultiVariable)) {
super.resolve(variable, context);
return;
}
MultiVariable mv = (MultiVariable) variable;
List<String> params = variable.getVariableType().getParams();
if (params.isEmpty()) {
super.resolve(variable, context);
return;
}
JavaContext jc = (JavaContext) context;
String reference = params.get(0);
int index = 0;
if (params.size() > 1) {
String indexParam = params.get(1);
try {
index = Integer.parseInt(indexParam);
} catch (NumberFormatException x) {
}
}
TemplateVariable refVar = jc.getTemplateVariable(reference);
if (refVar instanceof JavaVariable) {
JavaVariable jvar = (JavaVariable) refVar;
resolve(mv, jvar, index, jc);
return;
}
super.resolve(variable, context);
}
use of org.eclipse.jface.text.templates.TemplateVariable in project che by eclipse.
the class ElementTypeResolver method resolve.
/*
* @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
* @since 3.3
*/
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
if (!(variable instanceof MultiVariable)) {
super.resolve(variable, context);
return;
}
MultiVariable mv = (MultiVariable) variable;
List<String> params = variable.getVariableType().getParams();
if (params.isEmpty()) {
super.resolve(variable, context);
return;
}
JavaContext jc = (JavaContext) context;
String reference = params.get(0);
TemplateVariable refVar = jc.getTemplateVariable(reference);
if (refVar instanceof JavaVariable) {
JavaVariable jvar = (JavaVariable) refVar;
resolve(mv, jvar, jc);
return;
}
super.resolve(variable, context);
}
use of org.eclipse.jface.text.templates.TemplateVariable in project che by eclipse.
the class StubUtility method getMethodComment.
/*
* Don't use this method directly, use CodeGeneration.
* @see org.eclipse.jdt.ui.CodeGeneration#getMethodComment(ICompilationUnit, String, String, String[], String[], String, String[], IMethod, String)
*/
public static String getMethodComment(ICompilationUnit cu, String typeName, String methodName, String[] paramNames, String[] excTypeSig, String retTypeSig, String[] typeParameterNames, IMethod target, boolean delegate, String lineDelimiter) throws CoreException {
String templateName = CodeTemplateContextType.METHODCOMMENT_ID;
if (retTypeSig == null) {
templateName = CodeTemplateContextType.CONSTRUCTORCOMMENT_ID;
} else if (target != null) {
if (delegate)
templateName = CodeTemplateContextType.DELEGATECOMMENT_ID;
else
templateName = CodeTemplateContextType.OVERRIDECOMMENT_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);
if (retTypeSig != null) {
context.setVariable(CodeTemplateContextType.RETURN_TYPE, Signature.toString(retTypeSig));
}
if (target != null) {
String targetTypeName = target.getDeclaringType().getFullyQualifiedName('.');
String[] targetParamTypeNames = getParameterTypeNamesForSeeTag(target);
if (delegate)
context.setVariable(CodeTemplateContextType.SEE_TO_TARGET_TAG, getSeeTag(targetTypeName, methodName, targetParamTypeNames));
else
context.setVariable(CodeTemplateContextType.SEE_TO_OVERRIDDEN_TAG, getSeeTag(targetTypeName, methodName, targetParamTypeNames));
}
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);
}
if (buffer == null) {
return null;
}
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);
String[] exceptionNames = new String[excTypeSig.length];
for (int i = 0; i < excTypeSig.length; i++) {
exceptionNames[i] = Signature.toString(excTypeSig[i]);
}
String returnType = retTypeSig != null ? Signature.toString(retTypeSig) : null;
int[] tagOffsets = position.getOffsets();
for (int i = tagOffsets.length - 1; i >= 0; i--) {
// from last to first
try {
insertTag(document, tagOffsets[i], position.getLength(), paramNames, exceptionNames, returnType, typeParameterNames, false, lineDelimiter);
} catch (BadLocationException e) {
throw new CoreException(JavaUIStatus.createError(IStatus.ERROR, e));
}
}
return document.get();
}
use of org.eclipse.jface.text.templates.TemplateVariable in project eclipse.platform.text by eclipse.
the class GlobalTemplateVariablesDateTest method assertBufferStringAndVariables.
/**
* Ensures that {@link TemplateBuffer#getString()} equals the expected String and that all
* {@link TemplateBuffer#getVariables()} are resolved and unambiguous.
*
* @param expected expected result
* @param buffer the template buffer
*/
private static void assertBufferStringAndVariables(String expected, TemplateBuffer buffer) {
assertEquals(expected, buffer.getString());
for (TemplateVariable v : buffer.getVariables()) {
assertTrue(v.isResolved());
assertTrue(v.isUnambiguous());
}
}
Aggregations