public org.eclipse.jface.text.rules.IToken nextToken() { boolean isOriginalToken = true; if (!nextTokens.isEmpty()) { currentToken = nextTokens.remove(0); isOriginalToken = false; } else { currentToken = lexer.getNextToken(); } if (currentToken == null || !currentToken.canBeUsedForSyntaxHighlighting()) { return org.eclipse.jface.text.rules.Token.EOF; } if (isOriginalToken) { splitCurrentToken(); } org.eclipse.jface.text.TextAttribute textAttribute = null; String tokenName = currentToken.getName(); if (tokenName != null) { tudresden.ocl20.pivot.language.ocl.resource.ocl.IOclTokenStyle staticStyle = getStaticTokenStyle(); // now call dynamic token styler to allow to apply modifications to the static // style tudresden.ocl20.pivot.language.ocl.resource.ocl.IOclTokenStyle dynamicStyle = getDynamicTokenStyle(staticStyle); if (dynamicStyle != null) { textAttribute = getTextAttribute(dynamicStyle); } } return new org.eclipse.jface.text.rules.Token(textAttribute); }
public String getTokenText() { return currentToken.getText(); }
public int getTokenOffset() { return offset + currentToken.getOffset(); }
public int getTokenLength() { return currentToken.getLength(); }
/** 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; } }
public tudresden.ocl20.pivot.language.ocl.resource.ocl.IOclTokenStyle getStaticTokenStyle() { tudresden.ocl20.pivot.language.ocl.resource.ocl.IOclTokenStyle staticStyle = null; String tokenName = currentToken.getName(); String enableKey = tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper.getPreferenceKey( languageId, tokenName, tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper.StyleProperty .ENABLE); boolean enabled = store.getBoolean(enableKey); if (enabled) { String colorKey = tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .getPreferenceKey( languageId, tokenName, tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .StyleProperty.COLOR); org.eclipse.swt.graphics.RGB foregroundRGB = org.eclipse.jface.preference.PreferenceConverter.getColor(store, colorKey); org.eclipse.swt.graphics.RGB backgroundRGB = null; boolean bold = store.getBoolean( tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .getPreferenceKey( languageId, tokenName, tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .StyleProperty.BOLD)); boolean italic = store.getBoolean( tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .getPreferenceKey( languageId, tokenName, tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .StyleProperty.ITALIC)); boolean strikethrough = store.getBoolean( tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .getPreferenceKey( languageId, tokenName, tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .StyleProperty.STRIKETHROUGH)); boolean underline = store.getBoolean( tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .getPreferenceKey( languageId, tokenName, tudresden.ocl20.pivot.language.ocl.resource.ocl.ui.OclSyntaxColoringHelper .StyleProperty.UNDERLINE)); staticStyle = new tudresden.ocl20.pivot.language.ocl.resource.ocl.mopp.OclTokenStyle( convertToIntArray(foregroundRGB), convertToIntArray(backgroundRGB), bold, italic, strikethrough, underline); } return staticStyle; }