本文整理汇总了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);
}
示例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();
}
});
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}