use of org.eclipse.jface.text.templates.TemplateTranslator 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.jface.text.templates.TemplateTranslator in project KaiZen-OpenAPI-Editor by RepreZen.
the class SwaggerTemplateContext method createTemplateTranslator.
protected TemplateTranslator createTemplateTranslator() {
try {
int offset = getStart();
IRegion lineRegion = getDocument().getLineInformationOfOffset(offset);
String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength());
int i = 0;
// support for array items
StringBuilder indentation = new StringBuilder();
while (i < line.length()) {
char indentSymbol = line.charAt(i);
if (Character.isWhitespace(indentSymbol)) {
indentation.append(indentSymbol);
i++;
} else if ('-' == indentSymbol) {
// array item
indentation.append(' ');
i++;
} else {
break;
}
}
if (i != 0)
return new IndentationAwareTemplateTranslator(indentation.toString());
return new TemplateTranslator();
} catch (BadLocationException ex) {
return new TemplateTranslator();
}
}
use of org.eclipse.jface.text.templates.TemplateTranslator in project KaiZen-OpenAPI-Editor by RepreZen.
the class SwaggerTemplateContext method evaluate.
// Unmodified code from
// org.eclipse.xtext.ui.editor.templates.XtextTemplateContext below
@Override
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException {
if (!canEvaluate(template))
return null;
TemplateTranslator translator = createTemplateTranslator();
TemplateBuffer buffer = translator.translate(template);
getContextType().resolve(buffer, this);
return buffer;
}
use of org.eclipse.jface.text.templates.TemplateTranslator in project che by eclipse.
the class CodeTemplateContext method evaluate.
/*
* @see org.eclipse.jdt.internal.corext.template.TemplateContext#evaluate(org.eclipse.jdt.internal.corext.template.Template)
*/
@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) {
//$NON-NLS-1$ //$NON-NLS-2$
Assert.isNotNull(getVariable(var.getType()), "Variable " + var.getType() + "not defined");
}
}
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;
}
use of org.eclipse.jface.text.templates.TemplateTranslator in project che by eclipse.
the class JavaDocContext method evaluate.
/*
* @see TemplateContext#evaluate(Template)
*/
@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();
//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);
return buffer;
}
Aggregations