private int getCaretOffset(TemplateBuffer buffer) { TemplateVariable[] variables= buffer.getVariables(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME)) return variable.getOffsets()[0]; } return buffer.getString().length(); }
/** * Restores any decorated regions and updates the buffer's variable offsets. * * @return the buffer. * @throws MalformedTreeException * @throws BadLocationException */ public TemplateBuffer updateBuffer() throws MalformedTreeException, BadLocationException { checkState(); TemplateVariable[] variables= fBuffer.getVariables(); try { removeRangeMarkers(fPositions, fDocument, variables); } catch (BadPositionCategoryException x) { Assert.isTrue(false); } fBuffer.setContent(fDocument.get(), variables); fDocument= null; return fBuffer; }
public TemplateBuffer evaluate(Template template) throws BadLocationException, TemplateException { TemplateBuffer buffer = super.evaluate(template); if (buffer != null) { if ((fInsertOffset > -1) && (fInsertOffset > getStart())) { String prefix = getDocument().get(getStart(), fInsertOffset - getStart()); if (!template.getName().startsWith(prefix)) { // generate a new buffer that actually contains the // text that was going to be overwritten buffer = new TemplateBuffer(prefix + buffer.getString(), buffer.getVariables()); } } } return buffer; } }
private static String evaluateTemplate(CodeTemplateContext context, Template template) throws CoreException { TemplateBuffer buffer; try { buffer= context.evaluate(template); } catch (BadLocationException e) { throw new CoreException(Status.CANCEL_STATUS); } catch (TemplateException e) { throw new CoreException(Status.CANCEL_STATUS); } if (buffer == null) return null; String str= buffer.getString(); if (Strings.containsOnlyWhitespaces(str)) { return null; } return str; }
TemplateVariable[] variables= buffer.getVariables(); IDocument document= new Document(buffer.getString()); MultiTextEdit edit= new MultiTextEdit(0, document.getLength()); edit.addChildren(positions.toArray(new TextEdit[positions.size()])); buffer.setContent(document.get(), variables);
private static TemplateVariable findVariable(TemplateBuffer buffer, String variable) { TemplateVariable[] positions= buffer.getVariables(); for (int i= 0; i < positions.length; i++) { TemplateVariable curr= positions[i]; if (variable.equals(curr.getType())) { return curr; } } return null; }
/** * Creates a template buffer. * * @param string the string * @param variables the variable positions */ public TemplateBuffer(String string, TemplateVariable[] variables) { setContent(string, variables); }
return new TemplateBuffer(buffer.toString(), vars);
/** * Sets the content of the template buffer. * * @param string the string * @param variables the variable positions */ public final void setContent(String string, TemplateVariable[] variables) { Assert.isNotNull(string); Assert.isNotNull(variables); // XXX: assert non-overlapping variable properties fString= string; fVariables= copy(variables); }
private static String evaluateTemplate(CodeTemplateContext context, Template template) throws CoreException { TemplateBuffer buffer; try { buffer= context.evaluate(template); } catch (BadLocationException e) { throw new CoreException(Status.CANCEL_STATUS); } catch (TemplateException e) { throw new CoreException(Status.CANCEL_STATUS); } if (buffer == null) return null; String str= buffer.getString(); if (Strings.containsOnlyWhitespaces(str)) { return null; } return str; }
TemplateVariable[] variables= buffer.getVariables(); IDocument document= new Document(buffer.getString()); MultiTextEdit edit= new MultiTextEdit(0, document.getLength()); edit.addChildren(positions.toArray(new TextEdit[positions.size()])); buffer.setContent(document.get(), variables);
private static TemplateVariable findVariable(TemplateBuffer buffer, String variable) { TemplateVariable[] positions= buffer.getVariables(); for (int i= 0; i < positions.length; i++) { TemplateVariable curr= positions[i]; if (variable.equals(curr.getType())) { return curr; } } return null; }
/** * Creates a template buffer. * * @param string the string * @param variables the variable positions */ public TemplateBuffer(String string, TemplateVariable[] variables) { setContent(string, variables); }
return new TemplateBuffer(buffer.toString(), vars);
/** * Sets the content of the template buffer. * * @param string the string * @param variables the variable positions */ public final void setContent(String string, TemplateVariable[] variables) { Assert.isNotNull(string); Assert.isNotNull(variables); // XXX: assert non-overlapping variable properties fString= string; fVariables= copy(variables); }
private int getCaretOffset(TemplateBuffer buffer) { TemplateVariable[] variables= buffer.getVariables(); for (int i= 0; i != variables.length; i++) { TemplateVariable variable= variables[i]; if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME)) return variable.getOffsets()[0]; } return buffer.getString().length(); }
private static String evaluateTemplate(CodeTemplateContext context, Template template) throws CoreException { TemplateBuffer buffer; try { buffer= context.evaluate(template); } catch (BadLocationException e) { throw new CoreException(Status.CANCEL_STATUS); } catch (TemplateException e) { throw new CoreException(Status.CANCEL_STATUS); } if (buffer == null) return null; String str= buffer.getString(); if (Strings.containsOnlyWhitespaces(str)) { return null; } return str; }
private void indent(TemplateBuffer templateBuffer, String indent) throws BadLocationException, MalformedTreeException { TemplateVariable[] variables = templateBuffer.getVariables(); List positions = variablesToPositions(variables); IDocument document = new Document(templateBuffer.getString()); MultiTextEdit root = new MultiTextEdit(0, document.getLength()); root.addChildren((TextEdit[]) positions.toArray(new TextEdit[positions.size()])); // following lines int lineCount = document.getNumberOfLines(); for (int line = 1; line < lineCount; line++) { IRegion region = document.getLineInformation(line); int offset = region.getOffset(); if (indent == null) { continue; } TextEdit edit = new InsertEdit(offset, indent); root.addChild(edit); root.apply(document, TextEdit.UPDATE_REGIONS); root.removeChild(edit); } positionsToVariables(positions, variables); templateBuffer.setContent(document.get(), variables); }
/** * Restores any decorated regions and updates the buffer's variable offsets. * * @return the buffer. * @throws MalformedTreeException * @throws BadLocationException */ public TemplateBuffer updateBuffer() throws MalformedTreeException, BadLocationException { checkState(); TemplateVariable[] variables= fBuffer.getVariables(); try { removeRangeMarkers(fPositions, fDocument, variables); } catch (BadPositionCategoryException x) { Assert.isTrue(false); } fBuffer.setContent(fDocument.get(), variables); fDocument= null; return fBuffer; }
private static TemplateVariable findVariable(TemplateBuffer buffer, String variable) { TemplateVariable[] positions= buffer.getVariables(); for (int i= 0; i < positions.length; i++) { TemplateVariable curr= positions[i]; if (variable.equals(curr.getType())) { return curr; } } return null; }