/** * Validates a pattern, a <code>TemplateException</code> is thrown if * validation fails. * * @param pattern the template pattern to validate * @throws TemplateException if the pattern is invalid */ public void validate(String pattern) throws TemplateException { TemplateTranslator translator= new TemplateTranslator(); TemplateBuffer buffer= translator.translate(pattern); validateVariables(buffer.getVariables()); }
fail(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$ } else if ("$$".equals(matcher.group())) { //$NON-NLS-1$ String typeName= matcher.group(2); String params= matcher.group(3); TemplateVariableType type= createType(typeName, params); updateOrCreateVariable(variables, name, type, buffer.length()); TemplateVariable[] vars= createVariables(variables); return new TemplateBuffer(buffer.toString(), vars);
/** * Hook method to create new variables. Subclasses may override to supply their custom variable * type. * <p> * Clients may replace this method. * </p> * * @param type the type of the new variable. * @param name the name of the new variable. * @param offsets the offsets where the variable occurs in the template * @return a new instance of <code>TemplateVariable</code> * @deprecated as of 3.3 use {@link #createVariable(TemplateVariableType, String, int[])} instead */ @Deprecated protected TemplateVariable createVariable(String type, String name, int[] offsets) { return createVariable(fCurrentType, name, offsets); }
@Override public TemplateBuffer translate(String string) throws TemplateException { String withIndentation = string.replaceAll("(\r\n?)|(\n)", "$0" + indentation); return super.translate(withIndentation); } }
protected TemplateTranslator createTemplateTranslator() { try { int offset = getStart(); IRegion lineRegion = getDocument().getLineInformationOfOffset(offset); String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength()); int i = 0; while(i < line.length() && Character.isWhitespace(line.charAt(i))) { i++; } if (i != 0) return new IndentationAwareTemplateTranslator(line.substring(0, i)); return new TemplateTranslator(); } catch(BadLocationException ex) { return new TemplateTranslator(); } }
@Override public TemplateBuffer translate(String string) throws TemplateException { String withIndentation = string.replaceAll("(\r\n?)|(\n)", "$0" + indentation); return super.translate(withIndentation); } }
protected TemplateTranslator createTemplateTranslator() { try { int offset = getStart(); IRegion lineRegion = getDocument().getLineInformationOfOffset(offset); String line = getDocument().get(lineRegion.getOffset(), lineRegion.getLength()); int i = 0; // support for array items StringBuilder indentation = new StringBuilder(); while (i < line.length()) { char indentSymbol = line.charAt(i); if (Character.isWhitespace(indentSymbol)) { indentation.append(indentSymbol); i++; } else if ('-' == indentSymbol) {// array item indentation.append(' '); i++; } else { break; } } if (i != 0) return new IndentationAwareTemplateTranslator(indentation.toString()); return new TemplateTranslator(); } catch (BadLocationException ex) { return new TemplateTranslator(); } }
/** * Validates a pattern, a <code>TemplateException</code> is thrown if * validation fails. * * @param pattern the template pattern to validate * @throws TemplateException if the pattern is invalid */ public void validate(String pattern) throws TemplateException { TemplateTranslator translator= new TemplateTranslator(); TemplateBuffer buffer= translator.translate(pattern); validateVariables(buffer.getVariables()); }
@Override public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { if (!canEvaluate(template)) return null; TemplateTranslator translator= createTemplateTranslator(); TemplateBuffer buffer= translator.translate(template); getContextType().resolve(buffer, this); return buffer; }
fail(TextTemplateMessages.getString("TemplateTranslator.error.incomplete.variable")); //$NON-NLS-1$ } else if ("$$".equals(matcher.group())) { //$NON-NLS-1$ String typeName= matcher.group(2); String params= matcher.group(3); TemplateVariableType type= createType(typeName, params); updateOrCreateVariable(variables, name, type, buffer.length()); TemplateVariable[] vars= createVariables(variables); return new TemplateBuffer(buffer.toString(), vars);
/** * Hook method to create new variables. Subclasses may override to supply their custom variable * type. * <p> * Clients may replace this method. * </p> * * @param type the type of the new variable. * @param name the name of the new variable. * @param offsets the offsets where the variable occurs in the template * @return a new instance of <code>TemplateVariable</code> * @deprecated as of 3.3 use {@link #createVariable(TemplateVariableType, String, int[])} instead */ @Deprecated protected TemplateVariable createVariable(String type, String name, int[] offsets) { return createVariable(fCurrentType, name, offsets); }
/** * @since 2.3 */ public TemplateBuffer evaluateForDisplay(Template template) throws BadLocationException, TemplateException { if (!canEvaluate(template)) return null; TemplateTranslator translator = new TemplateTranslator(); TemplateBuffer buffer = translator.translate(template); getContextType().resolve(buffer, this); return buffer; }
@Override public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { if (!canEvaluate(template)) return null; TemplateTranslator translator = createTemplateTranslator(); TemplateBuffer buffer = translator.translate(template); getContextType().resolve(buffer, this); return buffer; }
/** * Creates proper {@link TemplateVariable}s from the variable descriptions. * * @param variables the variable descriptions by variable name * @return the corresponding variables * @since 3.3 */ private TemplateVariable[] createVariables(Map<String, VariableDescription> variables) { TemplateVariable[] result= new TemplateVariable[variables.size()]; int idx= 0; for (Iterator<VariableDescription> it= variables.values().iterator(); it.hasNext(); idx++) { VariableDescription desc= it.next(); TemplateVariableType type= desc.fType == null ? new TemplateVariableType(desc.fName) : desc.fType; int[] offsets= new int[desc.fOffsets.size()]; int i= 0; for (Iterator<Integer> intIt= desc.fOffsets.iterator(); intIt.hasNext(); i++) { Integer offset= intIt.next(); offsets[i]= offset.intValue(); } fCurrentType= type; /* * Call the deprecated version of createVariable. When not overridden, it will delegate * to the new version using fCurrentType. */ TemplateVariable var= createVariable(type.getName(), desc.fName, offsets); result[idx]= var; } fCurrentType= null; // avoid dangling reference return result; }
/** * @since 2.3 */ public TemplateBuffer evaluateForDisplay(Template template) throws BadLocationException, TemplateException { if (!canEvaluate(template)) return null; TemplateTranslator translator= new TemplateTranslator(); TemplateBuffer buffer= translator.translate(template); getContextType().resolve(buffer, this); return buffer; }
TemplateBuffer buffer= translator.translate(template);
/** * Creates proper {@link TemplateVariable}s from the variable descriptions. * * @param variables the variable descriptions by variable name * @return the corresponding variables * @since 3.3 */ private TemplateVariable[] createVariables(Map<String, VariableDescription> variables) { TemplateVariable[] result= new TemplateVariable[variables.size()]; int idx= 0; for (Iterator<VariableDescription> it= variables.values().iterator(); it.hasNext(); idx++) { VariableDescription desc= it.next(); TemplateVariableType type= desc.fType == null ? new TemplateVariableType(desc.fName) : desc.fType; int[] offsets= new int[desc.fOffsets.size()]; int i= 0; for (Iterator<Integer> intIt= desc.fOffsets.iterator(); intIt.hasNext(); i++) { Integer offset= intIt.next(); offsets[i]= offset.intValue(); } fCurrentType= type; /* * Call the deprecated version of createVariable. When not overridden, it will delegate * to the new version using fCurrentType. */ TemplateVariable var= createVariable(type.getName(), desc.fName, offsets); result[idx]= var; } fCurrentType= null; // avoid dangling reference return result; }
@Override public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { if (!canEvaluate(template)) return null; TemplateTranslator translator= new TemplateTranslator(); TemplateBuffer buffer= translator.translate(template); getContextType().resolve(buffer, this); return buffer; } }
TemplateBuffer buffer= translator.translate(template);
@Override public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { if (!canEvaluate(template)) return null; TemplateTranslator translator= new TemplateTranslator(); TemplateBuffer buffer= translator.translate(template); getContextType().resolve(buffer, this); return buffer; } }