/** * Handles the details of the case where a brace is inserted into a gap. Assumes the current * token is a gap! Assumes that read lock and reduced locks are already held. * * @param text text */ void insertBraceToGap(String text) { current().shrink(getBlockOffset()); insert(Brace.MakeBrace(text, getStateAtCurrent())); // add a new gap to account for the remainder from the split gap // if block offset is zero, do NOT add a Gap of size 0. if (getBlockOffset() > 0) { insert(new Gap(getBlockOffset(), getStateAtCurrent())); next(); // now point at new brace } next(); // now pointing at second half of gap setBlockOffset(0); }
/** * Splits the current brace if it is a multiple character brace and fulfills certain conditions. * If the current brace is a // or /*, split it into two braces. Do the same for star-slash (end * comment block) if the parameter splitClose is true. Do the same for \\ and \" if splitEscape * is true. If a split was performed, the first of the two Braces will be the current one when * we're done. The offset is not changed. The two new Braces will have the same quoted/commented * status as the one they were split from. * * @param splitClose true if splitting on star-slash is desired * @param splitEscape true if spliting on escaped characters is desired */ void _splitCurrentIfCommentBlock(boolean splitClose, boolean splitEscape) { String type = current().getType(); if (type.equals("//") || type.equals("/*") || (splitClose && type.equals("*/")) || (splitEscape && type.equals("\\\\")) || (splitEscape && type.equals("\\\"")) || (splitEscape && type.equals("\\'"))) { String first = type.substring(0, 1); String second = type.substring(1, 2); // change current Brace to only be first character current().setType(first); ReducedModelState oldState = current().getState(); // then put a new brace after the current one next(); insert(Brace.MakeBrace(second, oldState)); // Move back to make the first brace we inserted current prev(); } }
/** * Helper function to _insertBrace. Handles the details of the case where brace is inserted * between two reduced tokens. No destructive action is taken. Assume that read lock and reduced * lock are already held. * * @param text text */ void insertNewBrace(String text) { insert(Brace.MakeBrace(text, getStateAtCurrent())); next(); setBlockOffset(0); }