/** * Sets the <em>isUnambiguous</em> flag of the variable. * * @param unambiguous the new unambiguous state of the variable */ public void setUnambiguous(boolean unambiguous) { fIsUnambiguous= unambiguous; if (unambiguous) setResolved(true); }
/** * Sets the <em>isUnambiguous</em> flag of the variable. * * @param unambiguous the new unambiguous state of the variable */ public void setUnambiguous(boolean unambiguous) { fIsUnambiguous= unambiguous; if (unambiguous) setResolved(true); }
@Override public void resolve(TemplateVariable variable, TemplateContext context) { List params = variable.getVariableType().getParams(); String[] bindings = new String[params.size()]; for (int i = 0; i < params.size(); i++) { bindings[i] = params.get(i).toString(); } if (bindings.length != 0) variable.setValues(bindings); variable.setResolved(true); }
/** * Resolves the variable to several possible values for this variable, with the first being the * default value. * * @param values a non-empty array of values */ public void setValues(String[] values) { Assert.isTrue(values.length > 0); fValues= TextUtilities.copy(values); setResolved(true); }
/** * Resolves the variable to several possible values for this variable, with the first being the * default value. * * @param values a non-empty array of values */ public void setValues(String[] values) { Assert.isTrue(values.length > 0); fValues= TextUtilities.copy(values); setResolved(true); }
private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) { String selection= context.getVariable(SELECTION); if (selection != null && !selection.isEmpty()) { variable.setValue(selection); } else { String defaultValue= params.get(0); variable.setValue(defaultValue); } variable.setUnambiguous(true); variable.setResolved(true); } }
/** * Creates a template variable with multiple possible values. * * @param type the type of the variable * @param name the name of the variable * @param values the values available at this variable, non-empty * @param offsets the array of offsets of the variable * @since 3.3 */ TemplateVariable(TemplateVariableType type, String name, String[] values, int[] offsets) { Assert.isNotNull(type); Assert.isNotNull(name); fType= type; fName= name; setValues(values); setOffsets(offsets); setUnambiguous(false); setResolved(false); fInitialLength= values[0].length(); }
private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) { String selection= context.getVariable(SELECTION); if (selection != null && !selection.isEmpty()) { variable.setValue(selection); } else { String defaultValue= params.get(0); variable.setValue(defaultValue); } variable.setUnambiguous(true); variable.setResolved(true); } }
/** * Creates a template variable with multiple possible values. * * @param type the type of the variable * @param name the name of the variable * @param values the values available at this variable, non-empty * @param offsets the array of offsets of the variable * @since 3.3 */ TemplateVariable(TemplateVariableType type, String name, String[] values, int[] offsets) { Assert.isNotNull(type); Assert.isNotNull(name); fType= type; fName= name; setValues(values); setOffsets(offsets); setUnambiguous(false); setResolved(false); fInitialLength= values[0].length(); }
@Override public void resolve(TemplateVariable variable, TemplateContext templateContext) { XtextTemplateContext castedContext = (XtextTemplateContext) templateContext; List<String> names = resolveValues(variable, castedContext); String[] bindings = names.toArray(new String[names.size()]); if (bindings.length != 0) variable.setValues(bindings); if (bindings.length > 1) variable.setUnambiguous(false); else variable.setUnambiguous(isUnambiguous(castedContext)); variable.setResolved(true); }
private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) { try { // There is a least one parameter (params.get(0) is not null), set the format depending on second parameter: DateFormat format; if (params.size() >= 2 && params.get(1) != null) { format= new SimpleDateFormat(params.get(0), new ULocale(params.get(1))); } else { format= new SimpleDateFormat(params.get(0)); } variable.setValue(format.format(new java.util.Date())); variable.setUnambiguous(true); variable.setResolved(true); } catch (IllegalArgumentException e) { // Date formating did not work, use default format instead: super.resolve(variable, context); } }
private void resolveWithParams(TemplateVariable variable, TemplateContext context, List<String> params) { try { // There is a least one parameter (params.get(0) is not null), set the format depending on second parameter: DateFormat format; if (params.size() >= 2 && params.get(1) != null) { format= new SimpleDateFormat(params.get(0), new ULocale(params.get(1))); } else { format= new SimpleDateFormat(params.get(0)); } variable.setValue(format.format(new java.util.Date())); variable.setUnambiguous(true); variable.setResolved(true); } catch (IllegalArgumentException e) { // Date formating did not work, use default format instead: super.resolve(variable, context); } }
/** * Resolves <code>variable</code> in <code>context</code>. To resolve * means to find a valid binding of the receiver's type in the given <code>TemplateContext</code>. * If the variable can be successfully resolved, its value is set using * {@link TemplateVariable#setValues(String[])}. * * @param context the context in which variable is resolved * @param variable the variable to resolve */ public void resolve(TemplateVariable variable, TemplateContext context) { String[] bindings= resolveAll(context); if (bindings.length != 0) variable.setValues(bindings); if (bindings.length > 1) variable.setUnambiguous(false); else variable.setUnambiguous(isUnambiguous(context)); variable.setResolved(true); }
/** * Resolves <code>variable</code> in <code>context</code>. To resolve * means to find a valid binding of the receiver's type in the given <code>TemplateContext</code>. * If the variable can be successfully resolved, its value is set using * {@link TemplateVariable#setValues(String[])}. * * @param context the context in which variable is resolved * @param variable the variable to resolve */ public void resolve(TemplateVariable variable, TemplateContext context) { String[] bindings= resolveAll(context); if (bindings.length != 0) variable.setValues(bindings); if (bindings.length > 1) variable.setUnambiguous(false); else variable.setUnambiguous(isUnambiguous(context)); variable.setResolved(true); }