public int getTokenOffset() { return offset + currentToken.getOffset(); }
/** Tries to split the current token if it contains task items. */ public void splitCurrentToken() { final String text = currentToken.getText(); final String name = currentToken.getName(); final int line = currentToken.getLine(); final int charStart = currentToken.getOffset(); final int column = currentToken.getColumn(); java.util.List<tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTaskItem> taskItems = new tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTaskItemDetector() .findTaskItems(text, line, charStart); // this is the offset for the next token to be added int offset = charStart; int itemBeginRelative; java.util.List<tudresden.ocl20.pivot.language.ocl.resource.ocl.IOclTextToken> newItems = new java.util.ArrayList<tudresden.ocl20.pivot.language.ocl.resource.ocl.IOclTextToken>(); for (tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTaskItem taskItem : taskItems) { int itemBegin = taskItem.getCharStart(); int itemLine = taskItem.getLine(); int itemColumn = 0; itemBeginRelative = itemBegin - charStart; // create token before task item (TODO if required) String textBefore = text.substring(offset - charStart, itemBeginRelative); int textBeforeLength = textBefore.length(); newItems.add( new tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTextToken( name, textBefore, offset, textBeforeLength, line, column, true)); // create token for the task item itself offset = offset + textBeforeLength; String itemText = taskItem.getKeyword(); int itemTextLength = itemText.length(); newItems.add( new tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTextToken( tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTokenStyleInformationProvider .TASK_ITEM_TOKEN_NAME, itemText, offset, itemTextLength, itemLine, itemColumn, true)); offset = offset + itemTextLength; } if (!taskItems.isEmpty()) { // create token after last task item (TODO if required) String textAfter = text.substring(offset - charStart); newItems.add( new tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTextToken( name, textAfter, offset, textAfter.length(), line, column, true)); } if (!newItems.isEmpty()) { // replace tokens currentToken = newItems.remove(0); nextTokens = newItems; } }