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


Java TemplateVariable类代码示例

本文整理汇总了Java中org.eclipse.jface.text.templates.TemplateVariable的典型用法代码示例。如果您正苦于以下问题:Java TemplateVariable类的具体用法?Java TemplateVariable怎么用?Java TemplateVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TemplateVariable类属于org.eclipse.jface.text.templates包,在下文中一共展示了TemplateVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateVariables

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的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

示例2: resolveValues

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public List<String> resolveValues(TemplateVariable variable,
		XtextTemplateContext castedContext) {
	String enumerationName = (String) variable.getVariableType()
			.getParams().iterator().next();
	Grammar grammar = getGrammar(castedContext);
	if (grammar == null)
		return Collections.emptyList();
	EEnum enumeration = (EEnum) getEClassifierForGrammar(enumerationName, grammar);
	if (enumeration == null) {
		return Collections.emptyList();
	}
	return Lists.transform(enumeration.getELiterals(), new Function<EEnumLiteral, String>() {
		public String apply(EEnumLiteral enumLiteral) {
			return enumLiteral.getLiteral();
		}
	});
}
 
开发者ID:cplutte,项目名称:bts,代码行数:19,代码来源:EnumTemplateVariableResolver.java

示例3: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
  variable.setUnambiguous(true);
  variable.setValue(""); // $NON-NLS-1$

  if (context instanceof JavaContext) {
    JavaContext jc = (JavaContext) context;
    List<String> params = variable.getVariableType().getParams();
    if (params.size() > 0) {
      for (Iterator<String> iterator = params.iterator(); iterator.hasNext(); ) {
        String typeName = iterator.next();
        jc.addImport(typeName);
      }
    }
  } else {
    super.resolve(variable, context);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:ImportsResolver.java

示例4: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
  variable.setUnambiguous(true);
  variable.setValue(""); // $NON-NLS-1$

  if (context instanceof JavaContext) {
    JavaContext jc = (JavaContext) context;
    List<String> params = variable.getVariableType().getParams();
    if (params.size() > 0) {
      for (Iterator<String> iterator = params.iterator(); iterator.hasNext(); ) {
        String qualifiedMemberName = iterator.next();
        jc.addStaticImport(qualifiedMemberName);
      }
    }
  } else {
    super.resolve(variable, context);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:StaticImportResolver.java

示例5: validateVariables

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的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

示例6: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ElementTypeResolver.java

示例7: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
  if (variable instanceof MultiVariable) {
    JavaContext jc = (JavaContext) context;
    JavaVariable jv = (JavaVariable) variable;
    Variable[] iterables = getVariables(jc);
    if (iterables.length > 0) {
      jv.setChoices(iterables);
      jc.markAsUsed(iterables[0].getName());

      if (iterables.length > 1) variable.setUnambiguous(false);
      else variable.setUnambiguous(isUnambiguous(context));

      return;
    }
  }

  super.resolve(variable, context);
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:AbstractJavaContextType.java

示例8: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void resolve(TemplateVariable variable, TemplateContext context)
{
	if (!variable.getVariableType().getParams().isEmpty())
	{
		String[] values = (String[]) variable.getVariableType().getParams().toArray(new String[0]);
		variable.setValues(values);
		variable.setUnambiguous(false);
		variable.setResolved(true);
	}
	else
	{
		super.resolve(variable, context);
		setEvaluationString(variable.getName());
	}
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:18,代码来源:TabStopVariableResolver.java

示例9: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:TypeResolver.java

示例10: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	variable.setUnambiguous(true);
	variable.setValue(""); //$NON-NLS-1$

	if (context instanceof JavaContext) {
		JavaContext jc= (JavaContext) context;
		List<String> params= variable.getVariableType().getParams();
		if (params.size() > 0) {
			for (Iterator<String> iterator= params.iterator(); iterator.hasNext();) {
				String typeName= iterator.next();
				jc.addImport(typeName);
			}
		}
	} else {
		super.resolve(variable, context);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:ImportsResolver.java

示例11: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	variable.setUnambiguous(true);
	variable.setValue(""); //$NON-NLS-1$

	if (context instanceof JavaContext) {
		JavaContext jc= (JavaContext) context;
		List<String> params= variable.getVariableType().getParams();
		if (params.size() > 0) {
			for (Iterator<String> iterator= params.iterator(); iterator.hasNext();) {
				String qualifiedMemberName= iterator.next();
				jc.addStaticImport(qualifiedMemberName);
			}
		}
	} else {
		super.resolve(variable, context);
	}
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:StaticImportResolver.java

示例12: validateVariables

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的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: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@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);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:ElementTypeResolver.java

示例14: resolve

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
@Override
public void resolve(TemplateVariable variable, TemplateContext context) {
	if (variable instanceof MultiVariable) {
		JavaContext jc= (JavaContext) context;
		JavaVariable jv= (JavaVariable) variable;
        Variable[] iterables= getVariables(jc);
		if (iterables.length > 0) {
			jv.setChoices(iterables);
			jc.markAsUsed(iterables[0].getName());

			if (iterables.length > 1)
				variable.setUnambiguous(false);
			else
				variable.setUnambiguous(isUnambiguous(context));

			return;
		}
	}

	super.resolve(variable, context);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:AbstractJavaContextType.java

示例15: fixEmptyVariables

import org.eclipse.jface.text.templates.TemplateVariable; //导入依赖的package包/类
private static String fixEmptyVariables(TemplateBuffer buffer, String[] variables) throws MalformedTreeException, BadLocationException {
	IDocument doc= new Document(buffer.getString());
	int nLines= doc.getNumberOfLines();
	MultiTextEdit edit= new MultiTextEdit();
	HashSet<Integer> removedLines= new HashSet<Integer>();
	for (int i= 0; i < variables.length; i++) {
		TemplateVariable position= findVariable(buffer, variables[i]); // look if Javadoc tags have to be added
		if (position == null || position.getLength() > 0) {
			continue;
		}
		int[] offsets= position.getOffsets();
		for (int k= 0; k < offsets.length; k++) {
			int line= doc.getLineOfOffset(offsets[k]);
			IRegion lineInfo= doc.getLineInformation(line);
			int offset= lineInfo.getOffset();
			String str= doc.get(offset, lineInfo.getLength());
			if (Strings.containsOnlyWhitespaces(str) && nLines > line + 1 && removedLines.add(new Integer(line))) {
				int nextStart= doc.getLineOffset(line + 1);
				edit.addChild(new DeleteEdit(offset, nextStart - offset));
			}
		}
	}
	edit.apply(doc, 0);
	return doc.get();
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:StubUtility.java


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