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; }
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; }
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; }
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 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 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 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 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 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(); }
/** * 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()); }
/** * 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()); }
/** * 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; }
/** * 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; }
/** * 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; }
TemplateVariable[] variables= buffer.getVariables();
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; } }
/** * Creates a new tracker. * * @param buffer the buffer to track * @throws MalformedTreeException * @throws BadLocationException */ public VariableTracker(TemplateBuffer buffer) throws MalformedTreeException, BadLocationException { Assert.isLegal(buffer != null); fBuffer= buffer; fDocument= new Document(fBuffer.getString()); installJavaStuff(fDocument); fDocument.addPositionCategory(CATEGORY); fDocument.addPositionUpdater(new ExclusivePositionUpdater(CATEGORY)); fPositions= createRangeMarkers(fBuffer.getVariables(), fDocument); }
/** * Creates a new tracker. * * @param buffer the buffer to track * @throws MalformedTreeException * @throws BadLocationException */ public VariableTracker(TemplateBuffer buffer) throws MalformedTreeException, BadLocationException { Assert.isLegal(buffer != null); fBuffer= buffer; fDocument= new Document(fBuffer.getString()); installJavaStuff(fDocument); fDocument.addPositionCategory(CATEGORY); fDocument.addPositionUpdater(new ExclusivePositionUpdater(CATEGORY)); fPositions= createRangeMarkers(fBuffer.getVariables(), fDocument); }
/** * Creates a new tracker. * * @param buffer the buffer to track * @throws MalformedTreeException * @throws BadLocationException */ public VariableTracker(TemplateBuffer buffer) throws MalformedTreeException, BadLocationException { Assert.isLegal(buffer != null); fBuffer= buffer; fDocument= new Document(fBuffer.getString()); installJavaStuff(fDocument); fDocument.addPositionCategory(CATEGORY); fDocument.addPositionUpdater(new ExclusivePositionUpdater(CATEGORY)); fPositions= createRangeMarkers(fBuffer.getVariables(), fDocument); }
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); }