@Test public void replacesStartCharacterBeforeCursorIfNotFollowedByCurlyBrace() { IRegion region = c.calculate(new ParsedString("foobar$foobar", ARG_START_POS), ARG_START_POS + 7); assertEquals(ARG_START_POS + 6, region.getOffset()); assertEquals(1, region.getLength()); }
@Override public IRegion calculate(ParsedString argument, int cursorOffsetInDocument) { String arg = argument.getValue(); int cursorOffset = cursorOffsetInDocument - argument.getArgCharPos(); if (cursorOffset == 0) { return new Region(cursorOffsetInDocument, 0); } int startPos = getStartPos(arg, cursorOffset); if (startPos == -1) { return new Region(cursorOffsetInDocument, 0); } int startPosInDocument = argument.getArgCharPos() + startPos; if (!isCharAt(arg, startPos + 1, '{')) { if (cursorOffset == startPos + 1) { return new Region(startPosInDocument, 1); } return new Region(cursorOffsetInDocument, 0); } int closePos = arg.indexOf('}', startPos + 2); if (closePos != -1 && closePos < cursorOffset) { return new Region(cursorOffsetInDocument, 0); } int nextDollarPos = arg.indexOf('$', startPos + 2); int nextAtPos = arg.indexOf('@', startPos + 2); if (closePos == -1 && nextDollarPos == -1 && nextAtPos == -1) { return new Region(startPosInDocument, argument.getArgEndCharPos() - startPosInDocument); } int endPos = getEndPos(closePos, nextDollarPos, nextAtPos); boolean cursorAtVariableStart = cursorOffset == startPos + 1 || cursorOffset == startPos + 2; boolean isClosedVariable = closePos == endPos - 1; if (cursorAtVariableStart && !isClosedVariable) { return new Region(startPosInDocument, 2); } return new Region(startPosInDocument, endPos - startPos); }
VariableReplacementRegionCalculator implements IVariableReplacementRegionCalculator { @Override public IRegion calculate(ParsedString argument, int cursorOffsetInDocument) { String arg = argument.getValue(); int cursorOffset = cursorOffsetInDocument - argument.getArgCharPos(); if (cursorOffset == 0) { return new Region(cursorOffsetInDocument, 0); } int startPos = getStartPos(arg, cursorOffset); if (startPos == -1) { return new Region(cursorOffsetInDocument, 0); } int startPosInDocument = argument.getArgCharPos() + startPos; if (!isCharAt(arg, startPos + 1, '{')) { if (cursorOffset == startPos + 1) { return new Region(startPosInDocument, 1); } return new Region(cursorOffsetInDocument, 0); } int closePos = arg.indexOf('}', startPos + 2); if (closePos != -1 && closePos < cursorOffset) { return new Region(cursorOffsetInDocument, 0); } int nextDollarPos = arg.indexOf('$', startPos + 2); int nextAtPos = arg.indexOf('@', startPos + 2); if (closePos == -1 && nextDollarPos == -1 && nextAtPos == -1) { return new Region(startPosInDocument, argument.getArgEndCharPos() - startPosInDocument); } int endPos = getEndPos(closePos, nextDollarPos, nextAtPos); boolean cursorAtVariableStart = cursorOffset == startPos + 1 || cursorOffset == startPos + 2; boolean isClosedVariable = closePos == endPos - 1; if (cursorAtVariableStart && !isClosedVariable) { return new Region(startPosInDocument, 2); } return new Region(startPosInDocument, endPos - startPos); } }
VariableReplacementRegionCalculator implements IVariableReplacementRegionCalculator { @Override public IRegion calculate(ParsedString argument, int cursorOffsetInDocument) { String arg = argument.getValue(); int cursorOffset = cursorOffsetInDocument - argument.getArgCharPos(); if (cursorOffset == 0) { return new Region(cursorOffsetInDocument, 0); } int startPos = getStartPos(arg, cursorOffset); if (startPos == -1) { return new Region(cursorOffsetInDocument, 0); } int startPosInDocument = argument.getArgCharPos() + startPos; if (!isCharAt(arg, startPos + 1, '{')) { if (cursorOffset == startPos + 1) { return new Region(startPosInDocument, 1); } return new Region(cursorOffsetInDocument, 0); } int closePos = arg.indexOf('}', startPos + 2); if (closePos != -1 && closePos < cursorOffset) { return new Region(cursorOffsetInDocument, 0); } int nextDollarPos = arg.indexOf('$', startPos + 2); int nextAtPos = arg.indexOf('@', startPos + 2); if (closePos == -1 && nextDollarPos == -1 && nextAtPos == -1) { return new Region(startPosInDocument, argument.getArgEndCharPos() - startPosInDocument); } int endPos = getEndPos(closePos, nextDollarPos, nextAtPos); boolean cursorAtVariableStart = cursorOffset == startPos + 1 || cursorOffset == startPos + 2; boolean isClosedVariable = closePos == endPos - 1; if (cursorAtVariableStart && !isClosedVariable) { return new Region(startPosInDocument, 2); } return new Region(startPosInDocument, endPos - startPos); }  }
VariableReplacementRegionCalculator implements IVariableReplacementRegionCalculator { @Override public IRegion calculate(ParsedString argument, int cursorOffsetInDocument) { String arg = argument.getValue(); int cursorOffset = cursorOffsetInDocument - argument.getArgCharPos(); if (cursorOffset == 0) { return new Region(cursorOffsetInDocument, 0); } int startPos = getStartPos(arg, cursorOffset); if (startPos == -1) { return new Region(cursorOffsetInDocument, 0); } int startPosInDocument = argument.getArgCharPos() + startPos; if (!isCharAt(arg, startPos + 1, '{')) { if (cursorOffset == startPos + 1) { return new Region(startPosInDocument, 1); } return new Region(cursorOffsetInDocument, 0); } int closePos = arg.indexOf('}', startPos + 2); if (closePos != -1 && closePos < cursorOffset) { return new Region(cursorOffsetInDocument, 0); } int nextDollarPos = arg.indexOf('$', startPos + 2); int nextAtPos = arg.indexOf('@', startPos + 2); if (closePos == -1 && nextDollarPos == -1 && nextAtPos == -1) { return new Region(startPosInDocument, argument.getArgEndCharPos() - startPosInDocument); } int endPos = getEndPos(closePos, nextDollarPos, nextAtPos); boolean cursorAtVariableStart = cursorOffset == startPos + 1 || cursorOffset == startPos + 2; boolean isClosedVariable = closePos == endPos - 1; if (cursorAtVariableStart && !isClosedVariable) { return new Region(startPosInDocument, 2); } return new Region(startPosInDocument, endPos - startPos); }  @Override IRegion calculate(ParsedString argument, int cursorOffsetInDocument); }
VariableReplacementRegionCalculator implements IVariableReplacementRegionCalculator { @Override public IRegion calculate(ParsedString argument, int cursorOffsetInDocument) { String arg = argument.getValue(); int cursorOffset = cursorOffsetInDocument - argument.getArgCharPos(); if (cursorOffset == 0) { return new Region(cursorOffsetInDocument, 0); } int startPos = getStartPos(arg, cursorOffset); if (startPos == -1) { return new Region(cursorOffsetInDocument, 0); } int startPosInDocument = argument.getArgCharPos() + startPos; if (!isCharAt(arg, startPos + 1, '{')) { if (cursorOffset == startPos + 1) { return new Region(startPosInDocument, 1); } return new Region(cursorOffsetInDocument, 0); } int closePos = arg.indexOf('}', startPos + 2); if (closePos != -1 && closePos < cursorOffset) { return new Region(cursorOffsetInDocument, 0); } int nextDollarPos = arg.indexOf('$', startPos + 2); int nextAtPos = arg.indexOf('@', startPos + 2); if (closePos == -1 && nextDollarPos == -1 && nextAtPos == -1) { return new Region(startPosInDocument, argument.getArgEndCharPos() - startPosInDocument); } int endPos = getEndPos(closePos, nextDollarPos, nextAtPos); boolean cursorAtVariableStart = cursorOffset == startPos + 1 || cursorOffset == startPos + 2; boolean isClosedVariable = closePos == endPos - 1; if (cursorAtVariableStart && !isClosedVariable) { return new Region(startPosInDocument, 2); } return new Region(startPosInDocument, endPos - startPos); }  @Override IRegion calculate(ParsedString argument, int cursorOffsetInDocument);  }