当前位置: 首页>>代码示例>>Java>>正文


Java TemplateException类代码示例

本文整理汇总了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;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:CodeTemplateContext.java

示例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);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:CodeTemplateContextType.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:CodeTemplateContext.java

示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:CodeTemplateContextType.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:JavaDocContext.java

示例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;
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:19,代码来源:BfTemplateProposal.java

示例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());
//		}
	}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:21,代码来源:ExpressionEvaluator.java

示例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;
}
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:27,代码来源:ExpressionEvaluator.java

示例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);
	}
}
 
开发者ID:RichardBirenheide,项目名称:brainfuck,代码行数:18,代码来源:ExpressionEvaluator.java

示例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;
	}
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:22,代码来源:DocumentSnippetTemplateContext.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:CodeTemplateContext.java

示例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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:CodeTemplateContextType.java

示例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();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:JavaContext.java

示例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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:JavaDocContext.java

示例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;
}
 
开发者ID:forcedotcom,项目名称:idecore,代码行数:26,代码来源:AbstractTemplateSelectionPage.java


注:本文中的org.eclipse.jface.text.templates.TemplateException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。