use of org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable in project che by eclipse.
the class JavaContext method evaluate.
/*
* @see TemplateContext#evaluate(Template template)
*/
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
clear();
if (!canEvaluate(template))
throw new TemplateException(JavaTemplateMessages.Context_error_cannot_evaluate);
TemplateTranslator translator = new TemplateTranslator() {
@Override
protected TemplateVariable createVariable(TemplateVariableType type, String name, int[] offsets) {
// TemplateVariableResolver resolver= getContextType().getResolver(type.getName());
// return resolver.createVariable();
MultiVariable variable = new JavaVariable(type, name, offsets);
fVariables.put(name, variable);
return variable;
}
};
TemplateBuffer buffer = translator.translate(template);
getContextType().resolve(buffer, this);
rewriteImports();
// IPreferenceStore prefs = JavaPlugin.getDefault().getPreferenceStore();
//prefs.getBoolean(PreferenceConstants.TEMPLATES_USE_CODEFORMATTER);
boolean useCodeFormatter = true;
IJavaProject project = getJavaProject();
JavaFormatter formatter = new JavaFormatter(TextUtilities.getDefaultLineDelimiter(getDocument()), getIndentation(), useCodeFormatter, project);
formatter.format(buffer, this);
clear();
return buffer;
}
use of org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable in project che by eclipse.
the class NameResolver method resolve.
/*
* @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
*/
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
List<String> params = variable.getVariableType().getParams();
String param;
if (params.size() == 0)
param = fDefaultType;
else
param = params.get(0);
JavaContext jc = (JavaContext) context;
TemplateVariable ref = jc.getTemplateVariable(param);
MultiVariable mv = (MultiVariable) variable;
if (ref instanceof MultiVariable) {
// reference is another variable
MultiVariable refVar = (MultiVariable) ref;
jc.addDependency(refVar, mv);
refVar.getAllChoices();
Object[] types = flatten(refVar.getAllChoices());
for (int i = 0; i < types.length; i++) {
String[] names = jc.suggestVariableNames(mv.toString(types[i]));
mv.setChoices(types[i], names);
}
mv.setKey(refVar.getCurrentChoice());
jc.markAsUsed(mv.getDefaultValue());
} else {
// reference is a Java type name
jc.addImport(param);
String[] names = jc.suggestVariableNames(param);
mv.setChoices(names);
jc.markAsUsed(names[0]);
}
}
use of org.eclipse.jdt.internal.ui.text.template.contentassist.MultiVariable 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.jdt.internal.ui.text.template.contentassist.MultiVariable 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.jdt.internal.ui.text.template.contentassist.MultiVariable in project che by eclipse.
the class TypeResolver method resolve.
/* (non-Javadoc)
* @see org.eclipse.jface.text.templates.TemplateVariableResolver#resolve(org.eclipse.jface.text.templates.TemplateVariable, org.eclipse.jface.text.templates.TemplateContext)
*/
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
List<String> params = variable.getVariableType().getParams();
String param;
if (params.size() == 0)
param = fDefaultType;
else
param = params.get(0);
JavaContext jc = (JavaContext) context;
MultiVariable mv = (MultiVariable) variable;
String reference = jc.addImport(param);
mv.setValue(reference);
mv.setUnambiguous(true);
}
Aggregations