本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateException类的典型用法代码示例。如果您正苦于以下问题:Java TemplateException类的具体用法?Java TemplateException怎么用?Java TemplateException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TemplateException类属于org.eclipse.jface.text.templates包,在下文中一共展示了TemplateException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的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;
}
示例2: validateVariables
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
ArrayList<String> required = new ArrayList<>(5);
String contextName = getId();
if (NEWTYPE_CONTEXTTYPE.equals(contextName)) {
required.add(PACKAGE_DECLARATION);
required.add(TYPE_DECLARATION);
}
for (int i = 0; i < variables.length; i++) {
String type = variables[i].getType();
if (getResolver(type) == null) {
String unknown = BasicElementLabels.getJavaElementName(type);
throw new TemplateException(Messages
.format(JavaTemplateMessages.CodeTemplateContextType_validate_unknownvariable, unknown));
}
required.remove(type);
}
if (!required.isEmpty()) {
String missing = BasicElementLabels.getJavaElementName(required.get(0));
throw new TemplateException(
Messages.format(JavaTemplateMessages.CodeTemplateContextType_validate_missingvariable, missing));
}
super.validateVariables(variables);
}
示例3: evaluate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的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;
}
示例4: validateVariables
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
ArrayList<String> required = new ArrayList<String>(5);
String contextName = getId();
if (NEWTYPE_CONTEXTTYPE.equals(contextName)) {
required.add(PACKAGE_DECLARATION);
required.add(TYPE_DECLARATION);
}
for (int i = 0; i < variables.length; i++) {
String type = variables[i].getType();
if (getResolver(type) == null) {
String unknown = BasicElementLabels.getJavaElementName(type);
throw new TemplateException(
Messages.format(
JavaTemplateMessages.CodeTemplateContextType_validate_unknownvariable, unknown));
}
required.remove(type);
}
if (!required.isEmpty()) {
String missing = BasicElementLabels.getJavaElementName(required.get(0));
throw new TemplateException(
Messages.format(
JavaTemplateMessages.CodeTemplateContextType_validate_missingvariable, missing));
}
super.validateVariables(variables);
}
示例5: evaluate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的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;
}
示例6: getAdditionalProposalInfo
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
@Override
public String getAdditionalProposalInfo() {
this.getContext().setReadOnly(true);
TemplateBuffer templateBuffer;
try {
templateBuffer= this.getContext().evaluate(this.getTemplate());
}
catch (BadLocationException | TemplateException ex) {
String message = "<b>Error when resolving variables.</b><br>"
+ "Nothing will be inserted<br><br>"
+ escapeHTML(ex.getMessage());
return message;
}
String info = escapeHTML(this.getTemplate().getDescription()) +
"<br><br><b>Inserts:</b><br>" +
escapeHTML(templateBuffer.getString());
return info;
}
示例7: parse
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
final void parse(List<String> params) throws TemplateException {
for (String expression : params) {
try {
if (expression.trim().isEmpty()) {
throw new TemplateException("Empty expression");
}
new ComplexExpression(expression.trim());
}
catch (RuntimeException ex) {
throw new TemplateException("Invalid expression: " + expression + "; " + ex.getMessage(), ex);
}
}
// if (messages.size() > 0) {
// StringBuilder result = new StringBuilder();
// for (String message : messages) {
// result.append(message).append("\n");
// }
// throw new TemplateException(result.toString());
// }
}
示例8: ValueOrVariableExpression
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
ValueOrVariableExpression(String expression) throws TemplateException {
String check = expression;
if (expression.startsWith("-")) {
check = check.substring(1).trim();
this.sign = '-';
}
else {
this.sign = '+';
}
if (check.isEmpty()) {
throw new TemplateException("Invalid variable: " + expression);
}
this.isVariable = Character.isLetter(check.charAt(0));
for (int i = 0; i < check.length(); i++) {
if (!Character.isLetterOrDigit(check.charAt(i)) ||
(!this.isVariable && !Character.isDigit(check.charAt(i)))) {
throw new TemplateException("Invalid value or variable: " + expression);
}
}
if (this.isVariable) {
this.value = check;
}
else {
this.value = expression;
}
}
示例9: parseOperator
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
private Operator parseOperator(String partExp) throws TemplateException {
char operator = partExp.charAt(0);
switch (operator) {
case '*' :
return Operator.MULTPLY;
case '/' :
return Operator.DIVIDE;
case '%' :
return Operator.MODULO;
case '+' :
return Operator.ADD;
case '-' :
return Operator.SUBTRACT;
default :
throw new TemplateException("Illegal operator: " + partExp);
}
}
示例10: evaluate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException
{
if (!canEvaluate(template))
return null;
try
{
this.template = template;
TemplateTranslator translator = new SnippetTemplateTranslator();
TemplateBuffer buffer = translator.translate(template);
getContextType().resolve(buffer, this);
return buffer;
}
finally
{
this.template = null;
}
}
示例11: evaluate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的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;
}
示例12: validateVariables
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
@Override
protected void validateVariables(TemplateVariable[] variables) throws TemplateException {
ArrayList<String> required= new ArrayList<String>(5);
String contextName= getId();
if (NEWTYPE_CONTEXTTYPE.equals(contextName)) {
required.add(PACKAGE_DECLARATION);
required.add(TYPE_DECLARATION);
}
for (int i= 0; i < variables.length; i++) {
String type= variables[i].getType();
if (getResolver(type) == null) {
String unknown= BasicElementLabels.getJavaElementName(type);
throw new TemplateException(Messages.format(JavaTemplateMessages.CodeTemplateContextType_validate_unknownvariable, unknown));
}
required.remove(type);
}
if (!required.isEmpty()) {
String missing= BasicElementLabels.getJavaElementName(required.get(0));
throw new TemplateException(Messages.format(JavaTemplateMessages.CodeTemplateContextType_validate_missingvariable, missing));
}
super.validateVariables(variables);
}
示例13: evaluateTemplate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
/**
* Evaluates a 'java' template in the context of a compilation unit
*
* @param template the template to be evaluated
* @param compilationUnit the compilation unit in which to evaluate the template
* @param position the position inside the compilation unit for which to evaluate the template
* @return the evaluated template
* @throws CoreException in case the template is of an unknown context type
* @throws BadLocationException in case the position is invalid in the compilation unit
* @throws TemplateException in case the evaluation fails
*/
public static String evaluateTemplate(Template template, ICompilationUnit compilationUnit, int position) throws CoreException, BadLocationException, TemplateException {
TemplateContextType contextType= JavaPlugin.getDefault().getTemplateContextRegistry().getContextType(template.getContextTypeId());
if (!(contextType instanceof CompilationUnitContextType))
throw new CoreException(new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, IStatus.ERROR, JavaTemplateMessages.JavaContext_error_message, null));
IDocument document= new Document();
if (compilationUnit != null && compilationUnit.exists())
document.set(compilationUnit.getSource());
CompilationUnitContext context= ((CompilationUnitContextType) contextType).createContext(document, position, 0, compilationUnit);
context.setForceEvaluation(true);
TemplateBuffer buffer= context.evaluate(template);
if (buffer == null)
return null;
return buffer.getString();
}
示例14: evaluate
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的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= 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;
}
示例15: getTemplateString
import org.eclipse.jface.text.templates.TemplateException; //导入依赖的package包/类
/**
* Returns template string to insert.
*
* @param context the context to use when rendering the template
* @return String to insert or null if none is to be inserted
*/
public final String getTemplateString(final TemplateContext context) {
String templateString = null;
if (useTemplateButton.getSelection()) {
Template template = getSelectedTemplate();
if (template != null) {
try {
TemplateBuffer buffer = context.evaluate(template);
templateString = buffer.getString();
} catch (BadLocationException | TemplateException e) {
final String msg = "Unable to create template for new component";
final IStatus status = new Status(IStatus.WARNING, ForceIdeEditorsPlugin.PLUGIN_ID, msg, e);
logger().log(status);
}
}
}
return templateString;
}